mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-03-03 07:29:23 +00:00
Implement crash reporting for AARCH64
The ShowCrashReports() feature for aarch64 should work even better than the x86 crash reports. Thanks to the benefit of hindsight these reports should be rock solid reliable and beautiful to read. This change also improves the syscall polyfills for aarch64. Some of the sys_foo() functions have been removed, usually because they're legacy or downright footguns not worth building.
This commit is contained in:
parent
285e8a2348
commit
1f2a5a8fc1
42 changed files with 540 additions and 247 deletions
|
@ -51,8 +51,14 @@ int dup2(int oldfd, int newfd) {
|
||||||
int rc;
|
int rc;
|
||||||
if (__isfdkind(oldfd, kFdZip)) {
|
if (__isfdkind(oldfd, kFdZip)) {
|
||||||
rc = enotsup();
|
rc = enotsup();
|
||||||
|
#ifdef __aarch64__
|
||||||
|
} else if (oldfd == newfd) {
|
||||||
|
// linux aarch64 defines dup3() but not dup2(), which wasn't such a
|
||||||
|
// great decision, since the two syscalls don't behave the same way
|
||||||
|
if (!(rc = read(oldfd, 0, 0))) rc = oldfd;
|
||||||
|
#endif
|
||||||
} else if (!IsWindows()) {
|
} else if (!IsWindows()) {
|
||||||
rc = sys_dup2(oldfd, newfd);
|
rc = sys_dup2(oldfd, newfd, 0);
|
||||||
} else if (newfd < 0) {
|
} else if (newfd < 0) {
|
||||||
rc = ebadf();
|
rc = ebadf();
|
||||||
} else if (oldfd == newfd) {
|
} else if (oldfd == newfd) {
|
||||||
|
|
|
@ -63,6 +63,6 @@ int32_t sys_dup3(int32_t oldfd, int32_t newfd, int flags) {
|
||||||
if (!g_dup3.demodernize) {
|
if (!g_dup3.demodernize) {
|
||||||
return __sys_dup3(oldfd, newfd, flags);
|
return __sys_dup3(oldfd, newfd, flags);
|
||||||
} else {
|
} else {
|
||||||
return __fixupnewfd(sys_dup2(oldfd, newfd), flags);
|
return __fixupnewfd(sys_dup2(oldfd, newfd, 0), flags);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
int getpgrp(void) {
|
int getpgrp(void) {
|
||||||
int rc;
|
int rc;
|
||||||
if (!IsWindows()) {
|
if (!IsWindows()) {
|
||||||
rc = sys_getpgrp();
|
rc = sys_getpgid(0);
|
||||||
} else {
|
} else {
|
||||||
rc = getpid();
|
rc = getpid();
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,9 +19,11 @@
|
||||||
#include "libc/calls/calls.h"
|
#include "libc/calls/calls.h"
|
||||||
#include "libc/calls/syscall-sysv.internal.h"
|
#include "libc/calls/syscall-sysv.internal.h"
|
||||||
#include "libc/dce.h"
|
#include "libc/dce.h"
|
||||||
|
#include "libc/errno.h"
|
||||||
#include "libc/intrin/asan.internal.h"
|
#include "libc/intrin/asan.internal.h"
|
||||||
#include "libc/intrin/strace.internal.h"
|
#include "libc/intrin/strace.internal.h"
|
||||||
#include "libc/nt/ipc.h"
|
#include "libc/nt/ipc.h"
|
||||||
|
#include "libc/sysv/consts/at.h"
|
||||||
#include "libc/sysv/consts/s.h"
|
#include "libc/sysv/consts/s.h"
|
||||||
#include "libc/sysv/errfuns.h"
|
#include "libc/sysv/errfuns.h"
|
||||||
|
|
||||||
|
@ -35,13 +37,20 @@
|
||||||
*/
|
*/
|
||||||
int mkfifo(const char *pathname, unsigned mode) {
|
int mkfifo(const char *pathname, unsigned mode) {
|
||||||
// TODO(jart): Windows?
|
// TODO(jart): Windows?
|
||||||
int rc;
|
int e, rc;
|
||||||
if (IsAsan() && !__asan_is_valid_str(pathname)) {
|
if (IsAsan() && !__asan_is_valid_str(pathname)) {
|
||||||
rc = efault();
|
rc = efault();
|
||||||
} else if (IsLinux()) {
|
|
||||||
rc = sys_mknod(pathname, mode | S_IFIFO, 0);
|
|
||||||
} else {
|
} else {
|
||||||
|
e = errno;
|
||||||
rc = sys_mkfifo(pathname, mode);
|
rc = sys_mkfifo(pathname, mode);
|
||||||
|
if (rc == -1 && rc == ENOSYS) {
|
||||||
|
errno = e;
|
||||||
|
rc = sys_mknod(pathname, mode | S_IFIFO, 0);
|
||||||
|
if (rc == -1 && rc == ENOSYS) {
|
||||||
|
errno = e;
|
||||||
|
rc = sys_mknodat(AT_FDCWD, pathname, mode | S_IFIFO, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
STRACE("mkfifo(%#s, %#o) → %d% m", pathname, mode, rc);
|
STRACE("mkfifo(%#s, %#o) → %d% m", pathname, mode, rc);
|
||||||
return rc;
|
return rc;
|
||||||
|
|
|
@ -19,8 +19,10 @@
|
||||||
#include "libc/calls/calls.h"
|
#include "libc/calls/calls.h"
|
||||||
#include "libc/calls/syscall-sysv.internal.h"
|
#include "libc/calls/syscall-sysv.internal.h"
|
||||||
#include "libc/dce.h"
|
#include "libc/dce.h"
|
||||||
|
#include "libc/errno.h"
|
||||||
#include "libc/intrin/asan.internal.h"
|
#include "libc/intrin/asan.internal.h"
|
||||||
#include "libc/intrin/strace.internal.h"
|
#include "libc/intrin/strace.internal.h"
|
||||||
|
#include "libc/sysv/consts/at.h"
|
||||||
#include "libc/sysv/consts/s.h"
|
#include "libc/sysv/consts/s.h"
|
||||||
#include "libc/sysv/errfuns.h"
|
#include "libc/sysv/errfuns.h"
|
||||||
|
|
||||||
|
@ -39,14 +41,19 @@
|
||||||
* @asyncsignalsafe
|
* @asyncsignalsafe
|
||||||
*/
|
*/
|
||||||
int mknod(const char *path, uint32_t mode, uint64_t dev) {
|
int mknod(const char *path, uint32_t mode, uint64_t dev) {
|
||||||
int rc;
|
int e, rc;
|
||||||
if (IsAsan() && !__asan_is_valid_str(path)) return efault();
|
if (IsAsan() && !__asan_is_valid_str(path)) return efault();
|
||||||
if (mode & S_IFREG) return creat(path, mode & ~S_IFREG);
|
if (mode & S_IFREG) return creat(path, mode & ~S_IFREG);
|
||||||
if (mode & S_IFDIR) return mkdir(path, mode & ~S_IFDIR);
|
if (mode & S_IFDIR) return mkdir(path, mode & ~S_IFDIR);
|
||||||
if (mode & S_IFIFO) return mkfifo(path, mode & ~S_IFIFO);
|
if (mode & S_IFIFO) return mkfifo(path, mode & ~S_IFIFO);
|
||||||
if (!IsWindows()) {
|
if (!IsWindows()) {
|
||||||
/* TODO(jart): Whys there code out there w/ S_xxx passed via dev? */
|
/* TODO(jart): Whys there code out there w/ S_xxx passed via dev? */
|
||||||
|
e = errno;
|
||||||
rc = sys_mknod(path, mode, dev);
|
rc = sys_mknod(path, mode, dev);
|
||||||
|
if (rc == -1 && rc == ENOSYS) {
|
||||||
|
errno = e;
|
||||||
|
rc = sys_mknodat(AT_FDCWD, path, mode, dev);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
rc = enosys();
|
rc = enosys();
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,11 @@ int pause(void) {
|
||||||
// function shall block until interrupted by a signal." ──Quoth
|
// function shall block until interrupted by a signal." ──Quoth
|
||||||
// IEEE 1003.1-2017 §functions/select
|
// IEEE 1003.1-2017 §functions/select
|
||||||
//
|
//
|
||||||
|
#ifdef __aarch64__
|
||||||
|
rc = sys_pselect(0, 0, 0, 0, 0, 0);
|
||||||
|
#else
|
||||||
rc = sys_select(0, 0, 0, 0, 0);
|
rc = sys_select(0, 0, 0, 0, 0);
|
||||||
|
#endif
|
||||||
} else {
|
} else {
|
||||||
rc = sys_pause_nt();
|
rc = sys_pause_nt();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
|
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||||
│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│
|
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||||
│ Copyright 2020 Justine Alexandra Roberts Tunney │
|
│ Copyright 2023 Justine Alexandra Roberts Tunney │
|
||||||
│ │
|
│ │
|
||||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||||
│ any purpose with or without fee is hereby granted, provided that the │
|
│ any purpose with or without fee is hereby granted, provided that the │
|
||||||
|
@ -16,88 +16,25 @@
|
||||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/calls/calls.h"
|
||||||
|
#include "libc/calls/struct/timespec.h"
|
||||||
|
#include "libc/errno.h"
|
||||||
|
#include "libc/sock/struct/pollfd.internal.h"
|
||||||
|
|
||||||
// These function names make it a bit more obvious which signal
|
int sys_poll(struct pollfd *fds, size_t nfds, int timeout_ms) {
|
||||||
// caused the crash, particularly in the GDB GUI. They're coded
|
int e, rc;
|
||||||
// into an array to pinch pennies on code size registering them.
|
struct timespec ts, *tp;
|
||||||
|
if (timeout_ms >= 0) {
|
||||||
__oncrash_thunks:
|
ts = timespec_frommillis(timeout_ms);
|
||||||
|
tp = &ts;
|
||||||
// <SYNC-LIST>: showcrashreports.c, oncrashthunks.S, oncrash.c, internal.h
|
} else {
|
||||||
|
tp = 0;
|
||||||
.org 11*0
|
}
|
||||||
__oncrash_sigquit:
|
e = errno;
|
||||||
push %rbp
|
rc = sys_ppoll(fds, nfds, tp, 0, 0);
|
||||||
mov %rsp,%rbp
|
if (rc == -1 && errno == ENOSYS) {
|
||||||
call __oncrash
|
errno = e;
|
||||||
pop %rbp
|
rc = __sys_poll(fds, nfds, timeout_ms);
|
||||||
ret
|
}
|
||||||
.endfn __oncrash_sigquit,globl
|
return rc;
|
||||||
|
}
|
||||||
.org 11*1
|
|
||||||
__oncrash_sigfpe:
|
|
||||||
push %rbp
|
|
||||||
mov %rsp,%rbp
|
|
||||||
call __oncrash
|
|
||||||
pop %rbp
|
|
||||||
ret
|
|
||||||
.endfn __oncrash_sigfpe,globl
|
|
||||||
|
|
||||||
.org 11*2
|
|
||||||
__oncrash_sigill:
|
|
||||||
push %rbp
|
|
||||||
mov %rsp,%rbp
|
|
||||||
call __oncrash
|
|
||||||
pop %rbp
|
|
||||||
ret
|
|
||||||
.endfn __oncrash_sigill,globl
|
|
||||||
|
|
||||||
.org 11*3
|
|
||||||
__oncrash_sigsegv:
|
|
||||||
push %rbp
|
|
||||||
mov %rsp,%rbp
|
|
||||||
call __oncrash
|
|
||||||
pop %rbp
|
|
||||||
ret
|
|
||||||
.endfn __oncrash_sigsegv,globl
|
|
||||||
|
|
||||||
.org 11*4
|
|
||||||
__oncrash_sigtrap:
|
|
||||||
push %rbp
|
|
||||||
mov %rsp,%rbp
|
|
||||||
call __oncrash
|
|
||||||
pop %rbp
|
|
||||||
ret
|
|
||||||
.endfn __oncrash_sigtrap,globl
|
|
||||||
|
|
||||||
.org 11*5
|
|
||||||
__oncrash_sigabrt:
|
|
||||||
push %rbp
|
|
||||||
mov %rsp,%rbp
|
|
||||||
call __oncrash
|
|
||||||
pop %rbp
|
|
||||||
ret
|
|
||||||
.endfn __oncrash_sigabrt,globl
|
|
||||||
|
|
||||||
.org 11*6
|
|
||||||
__oncrash_sigbus:
|
|
||||||
push %rbp
|
|
||||||
mov %rsp,%rbp
|
|
||||||
call __oncrash
|
|
||||||
pop %rbp
|
|
||||||
ret
|
|
||||||
.endfn __oncrash_sigbus,globl
|
|
||||||
|
|
||||||
.org 11*7
|
|
||||||
__oncrash_sigurg:
|
|
||||||
push %rbp
|
|
||||||
mov %rsp,%rbp
|
|
||||||
call __oncrash
|
|
||||||
pop %rbp
|
|
||||||
ret
|
|
||||||
.endfn __oncrash_sigurg,globl
|
|
||||||
|
|
||||||
// </SYNC-LIST>: showcrashreports.c, oncrashthunks.S, oncrash.c, internal.h
|
|
||||||
|
|
||||||
.endobj __oncrash_thunks,globl
|
|
|
@ -7,7 +7,6 @@ COSMOPOLITAN_C_START_
|
||||||
|
|
||||||
axdx_t sys_gettimeofday(struct timeval *, struct timezone *, void *) _Hide;
|
axdx_t sys_gettimeofday(struct timeval *, struct timezone *, void *) _Hide;
|
||||||
int sys_futimes(int, const struct timeval *) _Hide;
|
int sys_futimes(int, const struct timeval *) _Hide;
|
||||||
int sys_futimesat(int, const char *, const struct timeval *) _Hide;
|
|
||||||
int sys_lutimes(const char *, const struct timeval *) _Hide;
|
int sys_lutimes(const char *, const struct timeval *) _Hide;
|
||||||
int sys_utimes(const char *, const struct timeval *) _Hide;
|
int sys_utimes(const char *, const struct timeval *) _Hide;
|
||||||
axdx_t sys_gettimeofday_xnu(struct timeval *, struct timezone *, void *) _Hide;
|
axdx_t sys_gettimeofday_xnu(struct timeval *, struct timezone *, void *) _Hide;
|
||||||
|
|
|
@ -32,9 +32,8 @@ i32 sys_chroot(const char *) _Hide;
|
||||||
i32 sys_close(i32) _Hide;
|
i32 sys_close(i32) _Hide;
|
||||||
i32 sys_close_range(u32, u32, u32) _Hide;
|
i32 sys_close_range(u32, u32, u32) _Hide;
|
||||||
i32 sys_closefrom(i32) _Hide;
|
i32 sys_closefrom(i32) _Hide;
|
||||||
i32 sys_creat(const char *, u32) _Hide;
|
|
||||||
i32 sys_dup(i32) _Hide;
|
i32 sys_dup(i32) _Hide;
|
||||||
i32 sys_dup2(i32, i32) _Hide;
|
i32 sys_dup2(i32, i32, i32) _Hide;
|
||||||
i32 sys_dup3(i32, i32, i32) _Hide;
|
i32 sys_dup3(i32, i32, i32) _Hide;
|
||||||
i32 sys_execve(const char *, char *const[], char *const[]) _Hide;
|
i32 sys_execve(const char *, char *const[], char *const[]) _Hide;
|
||||||
i32 sys_execveat(i32, const char *, char *const[], char *const[], i32) _Hide;
|
i32 sys_execveat(i32, const char *, char *const[], char *const[], i32) _Hide;
|
||||||
|
@ -55,7 +54,6 @@ i32 sys_fsync(i32) _Hide;
|
||||||
i32 sys_ftruncate(i32, i64, i64) _Hide;
|
i32 sys_ftruncate(i32, i64, i64) _Hide;
|
||||||
i32 sys_getcontext(void *) _Hide;
|
i32 sys_getcontext(void *) _Hide;
|
||||||
i32 sys_getpgid(i32) _Hide;
|
i32 sys_getpgid(i32) _Hide;
|
||||||
i32 sys_getpgrp(void) _Hide;
|
|
||||||
i32 sys_getppid(void) _Hide;
|
i32 sys_getppid(void) _Hide;
|
||||||
i32 sys_getpriority(i32, u32) _Hide;
|
i32 sys_getpriority(i32, u32) _Hide;
|
||||||
i32 sys_getresgid(u32 *, u32 *, u32 *) _Hide;
|
i32 sys_getresgid(u32 *, u32 *, u32 *) _Hide;
|
||||||
|
@ -73,6 +71,7 @@ i32 sys_mincore(void *, u64, unsigned char *) _Hide;
|
||||||
i32 sys_mkdirat(i32, const char *, u32) _Hide;
|
i32 sys_mkdirat(i32, const char *, u32) _Hide;
|
||||||
i32 sys_mkfifo(const char *, u32) _Hide;
|
i32 sys_mkfifo(const char *, u32) _Hide;
|
||||||
i32 sys_mknod(const char *, u32, u64) _Hide;
|
i32 sys_mknod(const char *, u32, u64) _Hide;
|
||||||
|
i32 sys_mknodat(i32, const char *, u32, u64) _Hide;
|
||||||
i32 sys_mprotect(void *, u64, i32) _Hide;
|
i32 sys_mprotect(void *, u64, i32) _Hide;
|
||||||
i32 sys_msync(void *, u64, i32) _Hide;
|
i32 sys_msync(void *, u64, i32) _Hide;
|
||||||
i32 sys_munmap(void *, u64) _Hide;
|
i32 sys_munmap(void *, u64) _Hide;
|
||||||
|
@ -127,7 +126,6 @@ i64 sys_lseek(i32, i64, i64, i64) _Hide;
|
||||||
i64 sys_pread(i32, void *, u64, i64, i64) _Hide;
|
i64 sys_pread(i32, void *, u64, i64, i64) _Hide;
|
||||||
i64 sys_pwrite(i32, const void *, u64, i64, i64) _Hide;
|
i64 sys_pwrite(i32, const void *, u64, i64, i64) _Hide;
|
||||||
i64 sys_read(i32, void *, u64) _Hide;
|
i64 sys_read(i32, void *, u64) _Hide;
|
||||||
i64 sys_readlink(const char *, char *, u64) _Hide;
|
|
||||||
i64 sys_readlinkat(i32, const char *, char *, u64) _Hide;
|
i64 sys_readlinkat(i32, const char *, char *, u64) _Hide;
|
||||||
i64 sys_sendfile(i32, i32, i64 *, u64) _Hide;
|
i64 sys_sendfile(i32, i32, i64 *, u64) _Hide;
|
||||||
i64 sys_splice(i32, i64 *, i32, i64 *, u64, u32) _Hide;
|
i64 sys_splice(i32, i64 *, i32, i64 *, u64, u32) _Hide;
|
||||||
|
|
|
@ -48,19 +48,7 @@ int getpid(void) {
|
||||||
} else if (!__vforked) {
|
} else if (!__vforked) {
|
||||||
rc = __pid;
|
rc = __pid;
|
||||||
} else {
|
} else {
|
||||||
#ifdef __x86_64__
|
|
||||||
rc = sys_getpid().ax;
|
rc = sys_getpid().ax;
|
||||||
#elif defined(__aarch64__)
|
|
||||||
register long res_x0 asm("x0");
|
|
||||||
asm volatile("mov\tx8,%1\n\t"
|
|
||||||
"svc\t0"
|
|
||||||
: "=r"(res_x0)
|
|
||||||
: "i"(172)
|
|
||||||
: "x8", "memory");
|
|
||||||
rc = res_x0;
|
|
||||||
#else
|
|
||||||
#error "arch unsupported"
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,8 +16,34 @@
|
||||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
|
#include "libc/calls/calls.h"
|
||||||
#include "libc/log/log.h"
|
#include "libc/log/log.h"
|
||||||
|
#include "libc/runtime/runtime.h"
|
||||||
|
#include "libc/str/str.h"
|
||||||
|
|
||||||
|
static const char *TryMonoRepoPath(const char *var, const char *path) {
|
||||||
|
const char buf[PATH_MAX];
|
||||||
|
if (getenv(var)) return 0;
|
||||||
|
if (!isexecutable(path)) return 0;
|
||||||
|
if (*path != '/') {
|
||||||
|
if (getcwd(buf, sizeof(buf)) <= 0) return 0;
|
||||||
|
strlcat(buf, "/", sizeof(buf));
|
||||||
|
strlcat(buf, path, sizeof(buf));
|
||||||
|
path = buf;
|
||||||
|
}
|
||||||
|
setenv(var, path, false);
|
||||||
|
return getenv(var);
|
||||||
|
}
|
||||||
|
|
||||||
const char *GetAddr2linePath(void) {
|
const char *GetAddr2linePath(void) {
|
||||||
return commandvenv("ADDR2LINE", "addr2line");
|
const char *s = 0;
|
||||||
|
#ifdef __x86_64__
|
||||||
|
s = TryMonoRepoPath("ADDR2LINE",
|
||||||
|
"o/third_party/gcc/bin/x86_64-linux-musl-addr2line");
|
||||||
|
#elif defined(__aarch64__)
|
||||||
|
s = TryMonoRepoPath("ADDR2LINE",
|
||||||
|
"o/third_party/gcc/bin/aarch64-linux-musl-addr2line");
|
||||||
|
#endif
|
||||||
|
if (!s) s = commandvenv("ADDR2LINE", "addr2line");
|
||||||
|
return s;
|
||||||
}
|
}
|
||||||
|
|
|
@ -117,13 +117,13 @@ static int PrintBacktraceUsingAddr2line(int fd, const struct StackFrame *bp) {
|
||||||
if (sys_pipe2(pipefds, O_CLOEXEC) == -1) {
|
if (sys_pipe2(pipefds, O_CLOEXEC) == -1) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if ((pid = __sys_fork().ax) == -1) {
|
if ((pid = sys_fork()) == -1) {
|
||||||
sys_close(pipefds[0]);
|
sys_close(pipefds[0]);
|
||||||
sys_close(pipefds[1]);
|
sys_close(pipefds[1]);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (!pid) {
|
if (!pid) {
|
||||||
sys_dup2(pipefds[1], 1);
|
sys_dup2(pipefds[1], 1, 0);
|
||||||
sys_execve(addr2line, argv, environ);
|
sys_execve(addr2line, argv, environ);
|
||||||
_Exit(127);
|
_Exit(127);
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,25 +67,33 @@ noinstrument noasan int PrintBacktraceUsingSymbols(int fd,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
addr = frame->addr;
|
addr = frame->addr;
|
||||||
if (!addr) break;
|
|
||||||
if (addr == (intptr_t)_weaken(__gc)) {
|
if (addr == (intptr_t)_weaken(__gc)) {
|
||||||
do {
|
do {
|
||||||
--gi;
|
--gi;
|
||||||
} while ((addr = garbage->p[gi].ret) == (intptr_t)_weaken(__gc));
|
} while ((addr = garbage->p[gi].ret) == (intptr_t)_weaken(__gc));
|
||||||
}
|
}
|
||||||
/*
|
if (addr) {
|
||||||
* we subtract one to handle the case of noreturn functions with a
|
if (
|
||||||
* call instruction at the end, since %rip in such cases will point
|
#ifdef __x86_64__
|
||||||
* to the start of the next function. generally %rip always points
|
/*
|
||||||
* to the byte after the instruction. one exception is in case like
|
* we subtract one to handle the case of noreturn functions
|
||||||
* __restore_rt where the kernel creates a stack frame that points
|
* with a call instruction at the end, since %rip in such
|
||||||
* to the beginning of the function.
|
* cases will point to the start of the next function.
|
||||||
*/
|
* generally %rip always points to the byte after the
|
||||||
if ((symbol = __get_symbol(st, addr - 1)) != -1 ||
|
* instruction. one exception is in case like __restore_rt
|
||||||
(symbol = __get_symbol(st, addr - 0)) != -1) {
|
* where the kernel creates a stack frame that points to the
|
||||||
addend = addr - st->addr_base;
|
* beginning of the function.
|
||||||
addend -= st->symbols[symbol].x;
|
*/
|
||||||
|
(symbol = __get_symbol(st, addr - 1)) != -1 ||
|
||||||
|
#endif
|
||||||
|
(symbol = __get_symbol(st, addr)) != -1) {
|
||||||
|
addend = addr - st->addr_base;
|
||||||
|
addend -= st->symbols[symbol].x;
|
||||||
|
} else {
|
||||||
|
addend = 0;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
|
symbol = 0;
|
||||||
addend = 0;
|
addend = 0;
|
||||||
}
|
}
|
||||||
kprintf("%012lx %lx %s%+d\n", frame, addr, __get_symbol_name(st, symbol),
|
kprintf("%012lx %lx %s%+d\n", frame, addr, __get_symbol_name(st, symbol),
|
||||||
|
|
|
@ -1,19 +1,18 @@
|
||||||
#ifndef COSMOPOLITAN_LIBC_LOG_INTERNAL_H_
|
#ifndef COSMOPOLITAN_LIBC_LOG_INTERNAL_H_
|
||||||
#define COSMOPOLITAN_LIBC_LOG_INTERNAL_H_
|
#define COSMOPOLITAN_LIBC_LOG_INTERNAL_H_
|
||||||
#include "libc/calls/struct/siginfo.h"
|
#include "libc/calls/struct/siginfo.h"
|
||||||
#include "libc/calls/ucontext.h"
|
|
||||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||||
COSMOPOLITAN_C_START_
|
COSMOPOLITAN_C_START_
|
||||||
|
|
||||||
extern _Hide bool __nocolor;
|
extern _Hide bool __nocolor;
|
||||||
extern _Hide int kCrashSigs[8];
|
|
||||||
extern _Hide bool _wantcrashreports;
|
extern _Hide bool _wantcrashreports;
|
||||||
extern _Hide bool g_isrunningundermake;
|
extern _Hide bool g_isrunningundermake;
|
||||||
|
|
||||||
void __start_fatal(const char *, int) _Hide;
|
void __start_fatal(const char *, int) _Hide;
|
||||||
void __oncrash(int, struct siginfo *, struct ucontext *) relegated;
|
|
||||||
void __restore_tty(void);
|
void __restore_tty(void);
|
||||||
void RestoreDefaultCrashSignalHandlers(void);
|
void RestoreDefaultCrashSignalHandlers(void);
|
||||||
|
void __oncrash_amd64(int, struct siginfo *, void *) relegated;
|
||||||
|
void __oncrash_arm64(int, struct siginfo *, void *) relegated;
|
||||||
|
|
||||||
COSMOPOLITAN_C_END_
|
COSMOPOLITAN_C_END_
|
||||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||||
|
|
|
@ -77,7 +77,8 @@ o/$(MODE)/libc/log/checkaligned.o \
|
||||||
o/$(MODE)/libc/log/checkfail.o \
|
o/$(MODE)/libc/log/checkfail.o \
|
||||||
o/$(MODE)/libc/log/checkfail_ndebug.o \
|
o/$(MODE)/libc/log/checkfail_ndebug.o \
|
||||||
o/$(MODE)/libc/log/restoretty.o \
|
o/$(MODE)/libc/log/restoretty.o \
|
||||||
o/$(MODE)/libc/log/oncrash.o \
|
o/$(MODE)/libc/log/oncrash_amd64.o \
|
||||||
|
o/$(MODE)/libc/log/oncrash_arm64.o \
|
||||||
o/$(MODE)/libc/log/onkill.o \
|
o/$(MODE)/libc/log/onkill.o \
|
||||||
o/$(MODE)/libc/log/startfatal.o \
|
o/$(MODE)/libc/log/startfatal.o \
|
||||||
o/$(MODE)/libc/log/startfatal_ndebug.o \
|
o/$(MODE)/libc/log/startfatal_ndebug.o \
|
||||||
|
|
|
@ -46,16 +46,10 @@
|
||||||
#include "libc/thread/thread.h"
|
#include "libc/thread/thread.h"
|
||||||
#include "libc/thread/tls.h"
|
#include "libc/thread/tls.h"
|
||||||
#include "third_party/libcxx/math.h"
|
#include "third_party/libcxx/math.h"
|
||||||
|
|
||||||
#ifdef __x86_64__
|
#ifdef __x86_64__
|
||||||
|
|
||||||
/**
|
STATIC_YOINK("strerror_wr"); // for kprintf %m
|
||||||
* @fileoverview Abnormal termination handling & GUI debugging.
|
STATIC_YOINK("strsignal_r"); // for kprintf %G
|
||||||
* @see libc/onkill.c
|
|
||||||
*/
|
|
||||||
|
|
||||||
STATIC_YOINK("strerror_wr"); /* for kprintf %m */
|
|
||||||
STATIC_YOINK("strsignal"); /* for kprintf %G */
|
|
||||||
|
|
||||||
static const char kGregOrder[17] forcealign(1) = {
|
static const char kGregOrder[17] forcealign(1) = {
|
||||||
13, 11, 8, 14, 12, 9, 10, 15, 16, 0, 1, 2, 3, 4, 5, 6, 7,
|
13, 11, 8, 14, 12, 9, 10, 15, 16, 0, 1, 2, 3, 4, 5, 6, 7,
|
||||||
|
@ -69,8 +63,6 @@ static const char kGregNames[17][4] forcealign(1) = {
|
||||||
static const char kCpuFlags[12] forcealign(1) = "CVPRAKZSTIDO";
|
static const char kCpuFlags[12] forcealign(1) = "CVPRAKZSTIDO";
|
||||||
static const char kFpuExceptions[6] forcealign(1) = "IDZOUP";
|
static const char kFpuExceptions[6] forcealign(1) = "IDZOUP";
|
||||||
|
|
||||||
int kCrashSigs[8];
|
|
||||||
|
|
||||||
relegated static void ShowFunctionCalls(ucontext_t *ctx) {
|
relegated static void ShowFunctionCalls(ucontext_t *ctx) {
|
||||||
struct StackFrame *bp;
|
struct StackFrame *bp;
|
||||||
struct StackFrame goodframe;
|
struct StackFrame goodframe;
|
||||||
|
@ -298,11 +290,12 @@ static wontreturn relegated noinstrument void __minicrash(int sig,
|
||||||
* @threadsafe
|
* @threadsafe
|
||||||
* @vforksafe
|
* @vforksafe
|
||||||
*/
|
*/
|
||||||
relegated void __oncrash(int sig, struct siginfo *si, ucontext_t *ctx) {
|
relegated void __oncrash_amd64(int sig, struct siginfo *si, void *arg) {
|
||||||
int bZero;
|
int bZero;
|
||||||
intptr_t rip;
|
intptr_t rip;
|
||||||
int me, owner;
|
int me, owner;
|
||||||
int gdbpid, err;
|
int gdbpid, err;
|
||||||
|
ucontext_t *ctx = arg;
|
||||||
static atomic_int once;
|
static atomic_int once;
|
||||||
static atomic_int once2;
|
static atomic_int once2;
|
||||||
STRACE("__oncrash rip %x", ctx->uc_mcontext.rip);
|
STRACE("__oncrash rip %x", ctx->uc_mcontext.rip);
|
||||||
|
@ -321,7 +314,7 @@ relegated void __oncrash(int sig, struct siginfo *si, ucontext_t *ctx) {
|
||||||
} else if (__nocolor || g_isrunningundermake) {
|
} else if (__nocolor || g_isrunningundermake) {
|
||||||
gdbpid = -1;
|
gdbpid = -1;
|
||||||
} else if (!IsTiny() && IsLinux() && FindDebugBinary() && !__isworker) {
|
} else if (!IsTiny() && IsLinux() && FindDebugBinary() && !__isworker) {
|
||||||
RestoreDefaultCrashSignalHandlers();
|
// RestoreDefaultCrashSignalHandlers();
|
||||||
gdbpid = AttachDebugger(
|
gdbpid = AttachDebugger(
|
||||||
((sig == SIGTRAP || sig == SIGQUIT) &&
|
((sig == SIGTRAP || sig == SIGQUIT) &&
|
||||||
(rip >= (intptr_t)&_base && rip < (intptr_t)&_etext))
|
(rip >= (intptr_t)&_base && rip < (intptr_t)&_etext))
|
277
libc/log/oncrash_arm64.c
Normal file
277
libc/log/oncrash_arm64.c
Normal file
|
@ -0,0 +1,277 @@
|
||||||
|
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||||
|
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||||
|
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||||
|
│ Copyright 2023 Justine Alexandra Roberts Tunney │
|
||||||
|
│ │
|
||||||
|
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||||
|
│ any purpose with or without fee is hereby granted, provided that the │
|
||||||
|
│ above copyright notice and this permission notice appear in all copies. │
|
||||||
|
│ │
|
||||||
|
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||||
|
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||||
|
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||||
|
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||||
|
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||||
|
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||||
|
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||||
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
|
#include "libc/calls/calls.h"
|
||||||
|
#include "libc/calls/struct/rusage.internal.h"
|
||||||
|
#include "libc/calls/struct/siginfo.h"
|
||||||
|
#include "libc/calls/struct/sigset.h"
|
||||||
|
#include "libc/calls/struct/sigset.internal.h"
|
||||||
|
#include "libc/calls/struct/utsname.h"
|
||||||
|
#include "libc/calls/syscall-sysv.internal.h"
|
||||||
|
#include "libc/calls/ucontext.h"
|
||||||
|
#include "libc/errno.h"
|
||||||
|
#include "libc/intrin/kprintf.h"
|
||||||
|
#include "libc/log/internal.h"
|
||||||
|
#include "libc/log/log.h"
|
||||||
|
#include "libc/macros.internal.h"
|
||||||
|
#include "libc/nexgen32e/stackframe.h"
|
||||||
|
#include "libc/runtime/runtime.h"
|
||||||
|
#include "libc/runtime/stack.h"
|
||||||
|
#include "libc/runtime/symbols.internal.h"
|
||||||
|
#include "libc/str/str.h"
|
||||||
|
#include "libc/sysv/consts/sig.h"
|
||||||
|
#include "libc/thread/thread.h"
|
||||||
|
#ifdef __aarch64__
|
||||||
|
|
||||||
|
STATIC_YOINK("strerror_wr"); // for kprintf %m
|
||||||
|
STATIC_YOINK("strsignal_r"); // for kprintf %G
|
||||||
|
|
||||||
|
#define RESET "\e[0m"
|
||||||
|
#define STRONG "\e[30;101m"
|
||||||
|
#define RED "\e[31;1m"
|
||||||
|
#define GREEN "\e[32;1m"
|
||||||
|
#define BLUE "\e[34;1m"
|
||||||
|
#define YELLOW "\e[33;1m"
|
||||||
|
#define MAGENTA "\e[35;1m"
|
||||||
|
|
||||||
|
struct Buffer {
|
||||||
|
char *p;
|
||||||
|
int n;
|
||||||
|
int i;
|
||||||
|
};
|
||||||
|
|
||||||
|
static void Append(struct Buffer *b, const char *fmt, ...) {
|
||||||
|
va_list va;
|
||||||
|
va_start(va, fmt);
|
||||||
|
b->i += kvsnprintf(b->p + b->i, b->n - b->i, fmt, va);
|
||||||
|
va_end(va);
|
||||||
|
}
|
||||||
|
|
||||||
|
static const char *ColorRegister(int r) {
|
||||||
|
if (__nocolor) return "";
|
||||||
|
switch (r) {
|
||||||
|
case 0: // arg / res
|
||||||
|
case 1: // arg / res
|
||||||
|
case 2: // arg / res
|
||||||
|
case 3: // arg / res
|
||||||
|
case 4: // arg / res
|
||||||
|
case 5: // arg / res
|
||||||
|
case 6: // arg / res
|
||||||
|
case 7: // arg / res
|
||||||
|
return GREEN;
|
||||||
|
case 9: // volatile
|
||||||
|
case 10: // volatile
|
||||||
|
case 11: // volatile
|
||||||
|
case 12: // volatile
|
||||||
|
case 13: // volatile
|
||||||
|
case 14: // volatile
|
||||||
|
case 15: // volatile
|
||||||
|
return BLUE;
|
||||||
|
case 19: // saved
|
||||||
|
case 20: // saved
|
||||||
|
case 21: // saved
|
||||||
|
case 22: // saved
|
||||||
|
case 23: // saved
|
||||||
|
case 24: // saved
|
||||||
|
case 25: // saved
|
||||||
|
case 26: // saved
|
||||||
|
case 27: // saved
|
||||||
|
case 28: // saved
|
||||||
|
return MAGENTA;
|
||||||
|
case 29: // frame pointer
|
||||||
|
case 30: // return pointer
|
||||||
|
case 31: // stack pointer
|
||||||
|
return RED;
|
||||||
|
default: // miscellaneous registers
|
||||||
|
return YELLOW;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool AppendFileLine(struct Buffer *b, const char *addr2line,
|
||||||
|
const char *debugbin, long addr) {
|
||||||
|
ssize_t rc;
|
||||||
|
char buf[128];
|
||||||
|
int j, k, ws, pid, pfd[2];
|
||||||
|
if (!debugbin || !*debugbin) return false;
|
||||||
|
if (!addr2line || !*addr2line) return false;
|
||||||
|
if (sys_pipe(pfd)) return false;
|
||||||
|
ksnprintf(buf, sizeof(buf), "%lx", addr);
|
||||||
|
if ((pid = vfork()) == -1) {
|
||||||
|
sys_close(pfd[1]);
|
||||||
|
sys_close(pfd[0]);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!pid) {
|
||||||
|
sys_close(pfd[0]);
|
||||||
|
sys_dup2(pfd[1], 1, 0);
|
||||||
|
sys_close(2);
|
||||||
|
__sys_execve(addr2line,
|
||||||
|
(char *const[]){addr2line, "-pifCe", debugbin, buf, 0},
|
||||||
|
(char *const[]){0});
|
||||||
|
_Exit(127);
|
||||||
|
}
|
||||||
|
sys_close(pfd[1]);
|
||||||
|
// copy addr2line stdout to buffer. normally it is "file:line\n".
|
||||||
|
// however additional lines can get created for inline functions.
|
||||||
|
j = b->i;
|
||||||
|
Append(b, "in ");
|
||||||
|
k = b->i;
|
||||||
|
while ((rc = sys_read(pfd[0], buf, sizeof(buf))) > 0) {
|
||||||
|
Append(b, "%.*s", (int)rc, buf);
|
||||||
|
}
|
||||||
|
sys_close(pfd[0]);
|
||||||
|
if (sys_wait4(pid, &ws, 0, 0) != -1 && !ws && b->p[k] != ':' &&
|
||||||
|
b->p[k] != '?' && b->p[b->i - 1] == '\n') {
|
||||||
|
--b->i; // chomp last newline
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
b->i = j; // otherwise reset the buffer
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
relegated void __oncrash_arm64(int sig, struct siginfo *si, void *arg) {
|
||||||
|
char buf[10000];
|
||||||
|
static _Thread_local bool once;
|
||||||
|
struct Buffer b[1] = {{buf, sizeof(buf)}};
|
||||||
|
b->p[b->i++] = '\n';
|
||||||
|
if (!once) {
|
||||||
|
int i, j;
|
||||||
|
const char *kind;
|
||||||
|
const char *reset;
|
||||||
|
const char *strong;
|
||||||
|
ucontext_t *ctx = arg;
|
||||||
|
char host[64] = "unknown";
|
||||||
|
struct utsname names = {0};
|
||||||
|
once = true;
|
||||||
|
ftrace_enabled(-1);
|
||||||
|
strace_enabled(-1);
|
||||||
|
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, 0);
|
||||||
|
__restore_tty();
|
||||||
|
uname(&names);
|
||||||
|
gethostname(host, sizeof(host));
|
||||||
|
reset = !__nocolor ? RESET : "";
|
||||||
|
strong = !__nocolor ? STRONG : "";
|
||||||
|
if (ctx && (ctx->uc_mcontext.sp & (GetStackSize() - 1)) <= GUARDSIZE) {
|
||||||
|
kind = "Stack Overflow";
|
||||||
|
} else {
|
||||||
|
kind = GetSiCodeName(sig, si->si_code);
|
||||||
|
}
|
||||||
|
Append(b,
|
||||||
|
"%serror%s: Uncaught %G (%s) on %s pid %d tid %d\n"
|
||||||
|
" %s\n"
|
||||||
|
" %m\n"
|
||||||
|
" %s %s %s %s\n",
|
||||||
|
strong, reset, sig, kind, host, getpid(), gettid(),
|
||||||
|
program_invocation_name, names.sysname, names.version,
|
||||||
|
names.nodename, names.release, "yo");
|
||||||
|
if (ctx) {
|
||||||
|
long pc;
|
||||||
|
char line[256];
|
||||||
|
int addend, symbol;
|
||||||
|
const char *debugbin;
|
||||||
|
const char *addr2line;
|
||||||
|
struct StackFrame *fp;
|
||||||
|
struct SymbolTable *st;
|
||||||
|
st = GetSymbolTable();
|
||||||
|
debugbin = FindDebugBinary();
|
||||||
|
addr2line = GetAddr2linePath();
|
||||||
|
|
||||||
|
if (ctx->uc_mcontext.fault_address) {
|
||||||
|
Append(b, " fault_address = %#lx\n", ctx->uc_mcontext.fault_address);
|
||||||
|
}
|
||||||
|
|
||||||
|
// PRINT REGISTERS
|
||||||
|
for (i = 0; i < 8; ++i) {
|
||||||
|
Append(b, " ");
|
||||||
|
for (j = 0; j < 4; ++j) {
|
||||||
|
int r = 8 * j + i;
|
||||||
|
if (j) Append(b, " ");
|
||||||
|
Append(b, "%s%016lx%s %sr%d", ColorRegister(r),
|
||||||
|
ctx->uc_mcontext.regs[r], reset, r == 8 || r == 9 ? " " : "",
|
||||||
|
r);
|
||||||
|
}
|
||||||
|
Append(b, "\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
// PRINT CURRENT LOCATION
|
||||||
|
pc = ctx->uc_mcontext.pc;
|
||||||
|
Append(b, " %016lx sp %lx pc", ctx->uc_mcontext.sp, pc);
|
||||||
|
if (pc && (symbol = __get_symbol(st, pc))) {
|
||||||
|
addend = pc - st->addr_base;
|
||||||
|
addend -= st->symbols[symbol].x;
|
||||||
|
Append(b, " ");
|
||||||
|
if (!AppendFileLine(b, addr2line, debugbin, pc)) {
|
||||||
|
Append(b, "%s", __get_symbol_name(st, symbol));
|
||||||
|
if (addend) Append(b, "%+d", addend);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Append(b, "\n");
|
||||||
|
|
||||||
|
// PRINT LINKED LOCATION
|
||||||
|
pc = ctx->uc_mcontext.regs[30];
|
||||||
|
Append(b, " %016lx sp %lx lr", ctx->uc_mcontext.sp, pc);
|
||||||
|
if (pc && (symbol = __get_symbol(st, pc))) {
|
||||||
|
addend = pc - st->addr_base;
|
||||||
|
addend -= st->symbols[symbol].x;
|
||||||
|
Append(b, " ");
|
||||||
|
if (!AppendFileLine(b, addr2line, debugbin, pc)) {
|
||||||
|
Append(b, "%s", __get_symbol_name(st, symbol));
|
||||||
|
if (addend) Append(b, "%+d", addend);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Append(b, "\n");
|
||||||
|
|
||||||
|
// PRINT FRAME POINTERS
|
||||||
|
fp = (struct StackFrame *)ctx->uc_mcontext.regs[29];
|
||||||
|
for (i = 0; fp; fp = fp->next) {
|
||||||
|
if (kisdangerous(fp)) {
|
||||||
|
Append(b, " %016lx <dangerous fp>\n", fp);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (++i == 100) {
|
||||||
|
Append(b, " <truncated backtrace>\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if ((pc = fp->addr)) {
|
||||||
|
if ((symbol = __get_symbol(st, pc))) {
|
||||||
|
addend = pc - st->addr_base;
|
||||||
|
addend -= st->symbols[symbol].x;
|
||||||
|
} else {
|
||||||
|
addend = 0;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
symbol = 0;
|
||||||
|
addend = 0;
|
||||||
|
}
|
||||||
|
Append(b, " %016lx fp %lx lr ", fp, pc);
|
||||||
|
if (!AppendFileLine(b, addr2line, debugbin, pc)) {
|
||||||
|
Append(b, "%s", __get_symbol_name(st, symbol));
|
||||||
|
if (addend) Append(b, "%+d", addend);
|
||||||
|
}
|
||||||
|
Append(b, "\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Append(b, "got %G while crashing!\n");
|
||||||
|
}
|
||||||
|
sys_write(2, b->p, MIN(b->i, b->n));
|
||||||
|
_Exit(128 + sig);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* __aarch64__ */
|
|
@ -25,6 +25,8 @@
|
||||||
#include "libc/log/internal.h"
|
#include "libc/log/internal.h"
|
||||||
#include "libc/log/log.h"
|
#include "libc/log/log.h"
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.internal.h"
|
||||||
|
#include "libc/mem/mem.h"
|
||||||
|
#include "libc/runtime/runtime.h"
|
||||||
#include "libc/runtime/stack.h"
|
#include "libc/runtime/stack.h"
|
||||||
#include "libc/runtime/symbols.internal.h"
|
#include "libc/runtime/symbols.internal.h"
|
||||||
#include "libc/str/str.h"
|
#include "libc/str/str.h"
|
||||||
|
@ -34,8 +36,6 @@
|
||||||
#include "libc/sysv/consts/sig.h"
|
#include "libc/sysv/consts/sig.h"
|
||||||
#include "libc/sysv/consts/ss.h"
|
#include "libc/sysv/consts/ss.h"
|
||||||
|
|
||||||
#ifdef __x86_64__
|
|
||||||
|
|
||||||
STATIC_YOINK("zipos"); // for symtab
|
STATIC_YOINK("zipos"); // for symtab
|
||||||
STATIC_YOINK("__die"); // for backtracing
|
STATIC_YOINK("__die"); // for backtracing
|
||||||
STATIC_YOINK("ShowBacktrace"); // for backtracing
|
STATIC_YOINK("ShowBacktrace"); // for backtracing
|
||||||
|
@ -44,44 +44,80 @@ STATIC_YOINK("PrintBacktraceUsingSymbols"); // for backtracing
|
||||||
STATIC_YOINK("malloc_inspect_all"); // for asan memory origin
|
STATIC_YOINK("malloc_inspect_all"); // for asan memory origin
|
||||||
STATIC_YOINK("GetSymbolByAddr"); // for asan memory origin
|
STATIC_YOINK("GetSymbolByAddr"); // for asan memory origin
|
||||||
|
|
||||||
static struct sigaction g_oldcrashacts[8];
|
struct CrashHandler {
|
||||||
extern const unsigned char __oncrash_thunks[8][11];
|
int sig;
|
||||||
|
struct sigaction old;
|
||||||
|
};
|
||||||
|
|
||||||
static void InstallCrashHandlers(int extraflags) {
|
static inline void __oncrash(int sig, struct siginfo *si, void *arg) {
|
||||||
int e;
|
#ifdef __x86_64__
|
||||||
size_t i;
|
__oncrash_amd64(sig, si, arg);
|
||||||
struct sigaction sa;
|
#elif defined(__aarch64__)
|
||||||
bzero(&sa, sizeof(sa));
|
__oncrash_arm64(sig, si, arg);
|
||||||
sigfillset(&sa.sa_mask);
|
#else
|
||||||
sa.sa_flags = SA_SIGINFO | SA_NODEFER | extraflags;
|
abort();
|
||||||
for (i = 0; i < ARRAYLEN(kCrashSigs); ++i) {
|
#endif
|
||||||
sigdelset(&sa.sa_mask, kCrashSigs[i]);
|
|
||||||
}
|
|
||||||
for (i = 0; i < ARRAYLEN(kCrashSigs); ++i) {
|
|
||||||
if (kCrashSigs[i]) {
|
|
||||||
sa.sa_sigaction = (sigaction_f)__oncrash_thunks[i];
|
|
||||||
e = errno;
|
|
||||||
sigaction(kCrashSigs[i], &sa, &g_oldcrashacts[i]);
|
|
||||||
errno = e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
relegated void RestoreDefaultCrashSignalHandlers(void) {
|
static void __got_sigquit(int sig, struct siginfo *si, void *arg) {
|
||||||
|
__oncrash(sig, si, arg);
|
||||||
|
}
|
||||||
|
static void __got_sigfpe(int sig, struct siginfo *si, void *arg) {
|
||||||
|
__oncrash(sig, si, arg);
|
||||||
|
}
|
||||||
|
static void __got_sigill(int sig, struct siginfo *si, void *arg) {
|
||||||
|
__oncrash(sig, si, arg);
|
||||||
|
}
|
||||||
|
static void __got_sigsegv(int sig, struct siginfo *si, void *arg) {
|
||||||
|
__oncrash(sig, si, arg);
|
||||||
|
}
|
||||||
|
static void __got_sigtrap(int sig, struct siginfo *si, void *arg) {
|
||||||
|
__oncrash(sig, si, arg);
|
||||||
|
}
|
||||||
|
static void __got_sigabrt(int sig, struct siginfo *si, void *arg) {
|
||||||
|
__oncrash(sig, si, arg);
|
||||||
|
}
|
||||||
|
static void __got_sigbus(int sig, struct siginfo *si, void *arg) {
|
||||||
|
__oncrash(sig, si, arg);
|
||||||
|
}
|
||||||
|
static void __got_sigurg(int sig, struct siginfo *si, void *arg) {
|
||||||
|
__oncrash(sig, si, arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void RemoveCrashHandler(void *arg) {
|
||||||
int e;
|
int e;
|
||||||
size_t i;
|
struct CrashHandler *ch = arg;
|
||||||
sigset_t ss;
|
|
||||||
strace_enabled(-1);
|
strace_enabled(-1);
|
||||||
sigemptyset(&ss);
|
e = errno;
|
||||||
sigprocmask(SIG_SETMASK, &ss, NULL);
|
sigaction(ch->sig, &ch->old, NULL);
|
||||||
for (i = 0; i < ARRAYLEN(kCrashSigs); ++i) {
|
errno = e;
|
||||||
if (kCrashSigs[i]) {
|
free(ch);
|
||||||
e = errno;
|
strace_enabled(+1);
|
||||||
sigaction(kCrashSigs[i], &g_oldcrashacts[i], NULL);
|
}
|
||||||
errno = e;
|
|
||||||
|
static void InstallCrashHandler(int sig, sigaction_f thunk, int extraflags) {
|
||||||
|
int e;
|
||||||
|
struct sigaction sa;
|
||||||
|
struct CrashHandler *ch;
|
||||||
|
e = errno;
|
||||||
|
if ((ch = malloc(sizeof(*ch)))) {
|
||||||
|
ch->sig = sig;
|
||||||
|
sa.sa_sigaction = thunk;
|
||||||
|
sigfillset(&sa.sa_mask);
|
||||||
|
sigdelset(&sa.sa_mask, SIGQUIT);
|
||||||
|
sigdelset(&sa.sa_mask, SIGFPE);
|
||||||
|
sigdelset(&sa.sa_mask, SIGILL);
|
||||||
|
sigdelset(&sa.sa_mask, SIGSEGV);
|
||||||
|
sigdelset(&sa.sa_mask, SIGTRAP);
|
||||||
|
sigdelset(&sa.sa_mask, SIGABRT);
|
||||||
|
sigdelset(&sa.sa_mask, SIGBUS);
|
||||||
|
sigdelset(&sa.sa_mask, SIGURG);
|
||||||
|
sa.sa_flags = SA_SIGINFO | SA_NODEFER | extraflags;
|
||||||
|
if (!sigaction(sig, &sa, &ch->old)) {
|
||||||
|
__cxa_atexit(RemoveCrashHandler, ch, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
strace_enabled(+1);
|
errno = e;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -100,33 +136,25 @@ relegated void RestoreDefaultCrashSignalHandlers(void) {
|
||||||
* useful, for example, if a program is caught in an infinite loop.
|
* useful, for example, if a program is caught in an infinite loop.
|
||||||
*/
|
*/
|
||||||
void ShowCrashReports(void) {
|
void ShowCrashReports(void) {
|
||||||
|
int ef = 0;
|
||||||
struct sigaltstack ss;
|
struct sigaltstack ss;
|
||||||
_wantcrashreports = true;
|
_wantcrashreports = true;
|
||||||
/* <SYNC-LIST>: showcrashreports.c, oncrashthunks.S, oncrash.c */
|
|
||||||
kCrashSigs[0] = SIGQUIT; /* ctrl+\ aka ctrl+break */
|
|
||||||
kCrashSigs[1] = SIGFPE; /* 1 / 0 */
|
|
||||||
kCrashSigs[2] = SIGILL; /* illegal instruction */
|
|
||||||
kCrashSigs[3] = SIGSEGV; /* bad memory access */
|
|
||||||
kCrashSigs[4] = SIGTRAP; /* bad system call */
|
|
||||||
kCrashSigs[5] = SIGABRT; /* abort() called */
|
|
||||||
kCrashSigs[6] = SIGBUS; /* misaligned, noncanonical ptr, etc. */
|
|
||||||
kCrashSigs[7] = SIGURG; /* placeholder */
|
|
||||||
/* </SYNC-LIST>: showcrashreports.c, oncrashthunks.S, oncrash.c */
|
|
||||||
if (!IsWindows()) {
|
if (!IsWindows()) {
|
||||||
|
ef = SA_ONSTACK;
|
||||||
ss.ss_flags = 0;
|
ss.ss_flags = 0;
|
||||||
ss.ss_size = GetStackSize();
|
ss.ss_size = GetStackSize();
|
||||||
// FreeBSD sigaltstack() will EFAULT if we use MAP_STACK here
|
// FreeBSD sigaltstack() will EFAULT if we use MAP_STACK here
|
||||||
// OpenBSD sigaltstack() auto-applies MAP_STACK to the memory
|
// OpenBSD sigaltstack() auto-applies MAP_STACK to the memory
|
||||||
_npassert((ss.ss_sp = _mapanon(GetStackSize())));
|
_npassert((ss.ss_sp = _mapanon(GetStackSize())));
|
||||||
_npassert(!sigaltstack(&ss, 0));
|
_npassert(!sigaltstack(&ss, 0));
|
||||||
InstallCrashHandlers(SA_ONSTACK);
|
|
||||||
} else {
|
|
||||||
InstallCrashHandlers(0);
|
|
||||||
}
|
}
|
||||||
|
InstallCrashHandler(SIGQUIT, __got_sigquit, ef); // ctrl+\ aka ctrl+break
|
||||||
|
InstallCrashHandler(SIGFPE, __got_sigfpe, ef); // 1 / 0
|
||||||
|
InstallCrashHandler(SIGILL, __got_sigill, ef); // illegal instruction
|
||||||
|
InstallCrashHandler(SIGSEGV, __got_sigsegv, ef); // bad memory access
|
||||||
|
InstallCrashHandler(SIGTRAP, __got_sigtrap, ef); // bad system call
|
||||||
|
InstallCrashHandler(SIGABRT, __got_sigabrt, ef); // abort() called
|
||||||
|
InstallCrashHandler(SIGBUS, __got_sigbus, ef); // misalign, mmap i/o failed
|
||||||
|
InstallCrashHandler(SIGURG, __got_sigurg, ef); // placeholder
|
||||||
GetSymbolTable();
|
GetSymbolTable();
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
|
||||||
void ShowCrashReports(void) {
|
|
||||||
}
|
|
||||||
#endif /* __x86_64__ */
|
|
||||||
|
|
|
@ -255,11 +255,11 @@ static int Cd(void) {
|
||||||
if (!chdir(s)) {
|
if (!chdir(s)) {
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
Log("chdir: ", s, ": ", _strerdoc(errno), 0);
|
Log("chdir: ", s, ": ", _strerdoc(errno), NULL);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Log("chdir: missing argument", 0);
|
Log("chdir: missing argument", NULL);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -270,7 +270,7 @@ static int Mkdir(void) {
|
||||||
if (n >= 3 && !strcmp(args[1], "-p")) ++i, f = makedirs;
|
if (n >= 3 && !strcmp(args[1], "-p")) ++i, f = makedirs;
|
||||||
for (; i < n; ++i) {
|
for (; i < n; ++i) {
|
||||||
if (f(args[i], 0755)) {
|
if (f(args[i], 0755)) {
|
||||||
Log("mkdir: ", args[i], ": ", _strerdoc(errno), 0);
|
Log("mkdir: ", args[i], ": ", _strerdoc(errno), NULL);
|
||||||
return errno;
|
return errno;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -287,7 +287,7 @@ static int Kill(void) {
|
||||||
}
|
}
|
||||||
for (; i < n; ++i) {
|
for (; i < n; ++i) {
|
||||||
if (kill(atoi(args[i]), sig)) {
|
if (kill(atoi(args[i]), sig)) {
|
||||||
Log("kill: ", args[i], ": ", _strerdoc(errno), 0);
|
Log("kill: ", args[i], ": ", _strerdoc(errno), NULL);
|
||||||
rc = 1;
|
rc = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -345,7 +345,7 @@ static int Rm(void) {
|
||||||
if (n > 1 && args[1][0] != '-') {
|
if (n > 1 && args[1][0] != '-') {
|
||||||
for (i = 1; i < n; ++i) {
|
for (i = 1; i < n; ++i) {
|
||||||
if (unlink(args[i])) {
|
if (unlink(args[i])) {
|
||||||
Log("rm: ", args[i], ": ", _strerdoc(errno), 0);
|
Log("rm: ", args[i], ": ", _strerdoc(errno), NULL);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -360,7 +360,7 @@ static int Rmdir(void) {
|
||||||
if (n > 1 && args[1][0] != '-') {
|
if (n > 1 && args[1][0] != '-') {
|
||||||
for (i = 1; i < n; ++i) {
|
for (i = 1; i < n; ++i) {
|
||||||
if (rmdir(args[i])) {
|
if (rmdir(args[i])) {
|
||||||
Log("rmdir: ", args[i], ": ", _strerdoc(errno), 0);
|
Log("rmdir: ", args[i], ": ", _strerdoc(errno), NULL);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -375,7 +375,7 @@ static int Touch(void) {
|
||||||
if (n > 1 && args[1][0] != '-') {
|
if (n > 1 && args[1][0] != '-') {
|
||||||
for (i = 1; i < n; ++i) {
|
for (i = 1; i < n; ++i) {
|
||||||
if (touch(args[i], 0644)) {
|
if (touch(args[i], 0644)) {
|
||||||
Log("touch: ", args[i], ": ", _strerdoc(errno), 0);
|
Log("touch: ", args[i], ": ", _strerdoc(errno), NULL);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
|
#include "libc/calls/syscall-sysv.internal.h"
|
||||||
#include "libc/dce.h"
|
#include "libc/dce.h"
|
||||||
#include "libc/intrin/kprintf.h"
|
#include "libc/intrin/kprintf.h"
|
||||||
#include "libc/intrin/strace.internal.h"
|
#include "libc/intrin/strace.internal.h"
|
||||||
|
@ -70,6 +71,7 @@ textstartup void cosmo(long *sp) {
|
||||||
|
|
||||||
// needed by kisdangerous()
|
// needed by kisdangerous()
|
||||||
__oldstack = (intptr_t)sp;
|
__oldstack = (intptr_t)sp;
|
||||||
|
__pid = sys_getpid().ax;
|
||||||
|
|
||||||
// initialize mmap() manager extremely early
|
// initialize mmap() manager extremely early
|
||||||
_mmi.n = ARRAYLEN(_mmi.s);
|
_mmi.n = ARRAYLEN(_mmi.s);
|
||||||
|
|
|
@ -18,8 +18,11 @@
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/calls/syscall-sysv.internal.h"
|
#include "libc/calls/syscall-sysv.internal.h"
|
||||||
#include "libc/dce.h"
|
#include "libc/dce.h"
|
||||||
|
#include "libc/sysv/consts/sig.h"
|
||||||
|
|
||||||
int sys_fork(void) {
|
int sys_fork(void) {
|
||||||
|
#ifdef __x86_64__
|
||||||
|
|
||||||
axdx_t ad;
|
axdx_t ad;
|
||||||
int ax, dx;
|
int ax, dx;
|
||||||
ad = __sys_fork();
|
ad = __sys_fork();
|
||||||
|
@ -31,4 +34,26 @@ int sys_fork(void) {
|
||||||
ax &= dx - 1;
|
ax &= dx - 1;
|
||||||
}
|
}
|
||||||
return ax;
|
return ax;
|
||||||
|
|
||||||
|
#elif defined(__aarch64__)
|
||||||
|
|
||||||
|
int flags = 17; // SIGCHLD;
|
||||||
|
void *child_stack = 0;
|
||||||
|
void *parent_tidptr = 0;
|
||||||
|
void *newtls = 0;
|
||||||
|
void *child_tidptr = 0;
|
||||||
|
register long r0 asm("x0") = (long)flags;
|
||||||
|
register long r1 asm("x1") = (long)child_stack;
|
||||||
|
register long r2 asm("x2") = (long)parent_tidptr;
|
||||||
|
register long r3 asm("x3") = (long)newtls;
|
||||||
|
register long r4 asm("x4") = (long)child_tidptr;
|
||||||
|
register long res_x0 asm("x0");
|
||||||
|
asm volatile("mov\tx8,%1\n\t"
|
||||||
|
"svc\t0"
|
||||||
|
: "=r"(res_x0)
|
||||||
|
: "i"(220), "r"(r0), "r"(r1), "r"(r2), "r"(r3), "r"(r4)
|
||||||
|
: "x8", "memory");
|
||||||
|
return _sysret(res_x0);
|
||||||
|
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -126,8 +126,11 @@ forceinline pureconst bool IsOldStackFrame(int x) {
|
||||||
/* openbsd uses 4mb stack by default */
|
/* openbsd uses 4mb stack by default */
|
||||||
/* freebsd uses 512mb stack by default */
|
/* freebsd uses 512mb stack by default */
|
||||||
/* most systems use 8mb stack by default */
|
/* most systems use 8mb stack by default */
|
||||||
intptr_t old = ROUNDDOWN(__oldstack, GetStackSize());
|
size_t foss_stack_size = 4ul * 1024 * 1024;
|
||||||
return (old >> 16) <= x && x <= ((old + (GetStackSize() - FRAMESIZE)) >> 16);
|
uintptr_t top = ROUNDUP(__oldstack, FRAMESIZE);
|
||||||
|
uintptr_t bot = top - foss_stack_size;
|
||||||
|
uintptr_t old = ROUNDDOWN(__oldstack, foss_stack_size);
|
||||||
|
return (int)(bot >> 16) <= x && x <= (int)((top >> 16) - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
forceinline pureconst bool IsFixedFrame(int x) {
|
forceinline pureconst bool IsFixedFrame(int x) {
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/sock/select.h"
|
#include "libc/sock/select.h"
|
||||||
#include "libc/calls/cp.internal.h"
|
#include "libc/calls/cp.internal.h"
|
||||||
|
#include "libc/calls/struct/timespec.h"
|
||||||
#include "libc/calls/struct/timeval.h"
|
#include "libc/calls/struct/timeval.h"
|
||||||
#include "libc/dce.h"
|
#include "libc/dce.h"
|
||||||
#include "libc/intrin/asan.internal.h"
|
#include "libc/intrin/asan.internal.h"
|
||||||
|
@ -67,7 +68,19 @@ int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
|
||||||
(exceptfds && !__asan_is_valid(exceptfds, FD_SIZE(nfds))))) {
|
(exceptfds && !__asan_is_valid(exceptfds, FD_SIZE(nfds))))) {
|
||||||
rc = efault();
|
rc = efault();
|
||||||
} else if (!IsWindows()) {
|
} else if (!IsWindows()) {
|
||||||
|
#ifdef __aarch64__
|
||||||
|
struct timespec ts, *tsp;
|
||||||
|
if (timeout) {
|
||||||
|
ts.tv_sec = timeout->tv_sec;
|
||||||
|
ts.tv_nsec = timeout->tv_usec * 1000;
|
||||||
|
tsp = &ts;
|
||||||
|
} else {
|
||||||
|
tsp = 0;
|
||||||
|
}
|
||||||
|
rc = sys_pselect(nfds, readfds, writefds, exceptfds, tsp, 0);
|
||||||
|
#else
|
||||||
rc = sys_select(nfds, readfds, writefds, exceptfds, tvp);
|
rc = sys_select(nfds, readfds, writefds, exceptfds, tvp);
|
||||||
|
#endif
|
||||||
} else {
|
} else {
|
||||||
rc = sys_select_nt(nfds, readfds, writefds, exceptfds, tvp, 0);
|
rc = sys_select_nt(nfds, readfds, writefds, exceptfds, tvp, 0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
COSMOPOLITAN_C_START_
|
COSMOPOLITAN_C_START_
|
||||||
|
|
||||||
int32_t sys_poll(struct pollfd *, uint64_t, signed) _Hide;
|
int32_t sys_poll(struct pollfd *, uint64_t, signed) _Hide;
|
||||||
|
int32_t __sys_poll(struct pollfd *, uint64_t, signed) _Hide;
|
||||||
int sys_ppoll(struct pollfd *, size_t, const struct timespec *,
|
int sys_ppoll(struct pollfd *, size_t, const struct timespec *,
|
||||||
const sigset_t *, size_t);
|
const sigset_t *, size_t);
|
||||||
int sys_poll_metal(struct pollfd *, size_t, unsigned);
|
int sys_poll_metal(struct pollfd *, size_t, unsigned);
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
#include "libc/sysv/macros.internal.h"
|
#include "libc/sysv/macros.internal.h"
|
||||||
.scall __sys_pipe,0x02a10721e202a016,0xfff,globl,hidden
|
.scall __sys_pipe,0x02a10721e202a016,0x03b,globl,hidden
|
||||||
|
|
2
libc/sysv/calls/__sys_poll.S
Normal file
2
libc/sysv/calls/__sys_poll.S
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
#include "libc/sysv/macros.internal.h"
|
||||||
|
.scall __sys_poll,0x8d18fc8d128e6807,0xfff,globl,hidden
|
|
@ -1,2 +0,0 @@
|
||||||
#include "libc/sysv/macros.internal.h"
|
|
||||||
.scall sys_chmod,0x00f00f00f200f05a,0xfff,globl,hidden
|
|
|
@ -1,2 +0,0 @@
|
||||||
#include "libc/sysv/macros.internal.h"
|
|
||||||
.scall sys_chown,0x010010010201005c,0xfff,globl,hidden
|
|
|
@ -1,2 +0,0 @@
|
||||||
#include "libc/sysv/macros.internal.h"
|
|
||||||
.scall sys_creat,0x008fff008ffff055,0xfff,globl,hidden
|
|
|
@ -1,2 +1,2 @@
|
||||||
#include "libc/sysv/macros.internal.h"
|
#include "libc/sysv/macros.internal.h"
|
||||||
.scall sys_dup2,0x05a05a05a205a021,0xfff,globl,hidden
|
.scall sys_dup2,0x05a05a05a205a021,0x018,globl,hidden
|
||||||
|
|
|
@ -1,2 +0,0 @@
|
||||||
#include "libc/sysv/macros.internal.h"
|
|
||||||
.scall sys_futimesat,0xffffff1eeffff105,0xfff,globl,hidden
|
|
|
@ -1,2 +0,0 @@
|
||||||
#include "libc/sysv/macros.internal.h"
|
|
||||||
.scall sys_getpgrp,0x051051051205106f,0xfff,globl,hidden
|
|
|
@ -1,2 +0,0 @@
|
||||||
#include "libc/sysv/macros.internal.h"
|
|
||||||
.scall sys_lchown,0x1130fe0fe216c05e,0xfff,globl,hidden
|
|
|
@ -1,2 +0,0 @@
|
||||||
#include "libc/sysv/macros.internal.h"
|
|
||||||
.scall sys_link,0x0090090092009056,0xfff,globl,hidden
|
|
|
@ -1,2 +0,0 @@
|
||||||
#include "libc/sysv/macros.internal.h"
|
|
||||||
.scall sys_mkdir,0x0880880882088053,0xfff,globl,hidden
|
|
|
@ -1,2 +0,0 @@
|
||||||
#include "libc/sysv/macros.internal.h"
|
|
||||||
.scall sys_poll,0x8d18fc8d128e6807,0xfff,globl,hidden
|
|
|
@ -1,2 +0,0 @@
|
||||||
#include "libc/sysv/macros.internal.h"
|
|
||||||
.scall sys_readlink,0x03a03a03a203a059,0xfff,globl,hidden
|
|
|
@ -1,2 +0,0 @@
|
||||||
#include "libc/sysv/macros.internal.h"
|
|
||||||
.scall sys_rename,0x0800800802080052,0xfff,globl,hidden
|
|
|
@ -1,2 +0,0 @@
|
||||||
#include "libc/sysv/macros.internal.h"
|
|
||||||
.scall sys_rmdir,0x0890890892089054,0xfff,globl,hidden
|
|
|
@ -1,2 +0,0 @@
|
||||||
#include "libc/sysv/macros.internal.h"
|
|
||||||
.scall sys_symlink,0x0390390392039058,0xfff,globl,hidden
|
|
|
@ -32,8 +32,13 @@
|
||||||
ret
|
ret
|
||||||
.endif
|
.endif
|
||||||
#elif defined(__aarch64__)
|
#elif defined(__aarch64__)
|
||||||
\name: mov x8,#\arm
|
\name:
|
||||||
|
.ifc \arm,0xfff
|
||||||
|
mov x0,#-38 // -ENOSYS
|
||||||
|
.else
|
||||||
|
mov x8,#\arm
|
||||||
svc #0
|
svc #0
|
||||||
|
.endif
|
||||||
b _sysret
|
b _sysret
|
||||||
.hidden _sysret
|
.hidden _sysret
|
||||||
#else
|
#else
|
||||||
|
|
|
@ -41,7 +41,7 @@ scall sys_close 0x0060060062006003 0x039 globl hidden
|
||||||
scall __sys_stat 0x1b7026fff2152004 0x04f globl hidden # FreeBSD 11→12 fumble; use sys_fstatat(); blocked on Android
|
scall __sys_stat 0x1b7026fff2152004 0x04f globl hidden # FreeBSD 11→12 fumble; use sys_fstatat(); blocked on Android
|
||||||
scall __sys_fstat 0x1b80352272153005 0x050 globl hidden # needs __stat2linux()
|
scall __sys_fstat 0x1b80352272153005 0x050 globl hidden # needs __stat2linux()
|
||||||
scall __sys_lstat 0x1b90280282154006 0xfff globl hidden # needs __stat2linux(); blocked on Android
|
scall __sys_lstat 0x1b90280282154006 0xfff globl hidden # needs __stat2linux(); blocked on Android
|
||||||
scall sys_poll 0x8d18fc8d128e6807 0xfff globl hidden
|
scall __sys_poll 0x8d18fc8d128e6807 0xfff globl hidden
|
||||||
scall sys_ppoll 0xfff86da21ffff90f 0x049 globl hidden # consider INTON/INTOFF tutorial in examples/unbourne.c
|
scall sys_ppoll 0xfff86da21ffff90f 0x049 globl hidden # consider INTON/INTOFF tutorial in examples/unbourne.c
|
||||||
scall sys_lseek 0x0c70c71de20c7008 0x03e globl hidden # netbsd+openbsd:evilpad
|
scall sys_lseek 0x0c70c71de20c7008 0x03e globl hidden # netbsd+openbsd:evilpad
|
||||||
scall __sys_mmap 0x0c50c51dd20c5009 0x0de globl hidden # netbsd+openbsd:pad
|
scall __sys_mmap 0x0c50c51dd20c5009 0x0de globl hidden # netbsd+openbsd:pad
|
||||||
|
@ -57,7 +57,7 @@ scall sys_pwrite 0x8ae8ae9dc289a812 0x044 globl hidden # a.k.a. pwrite64; netbs
|
||||||
scall sys_readv 0x8788788782878813 0x041 globl hidden
|
scall sys_readv 0x8788788782878813 0x041 globl hidden
|
||||||
scall sys_writev 0x8798798792879814 0x042 globl hidden
|
scall sys_writev 0x8798798792879814 0x042 globl hidden
|
||||||
scall sys_access 0x0210210212021015 0xfff globl hidden
|
scall sys_access 0x0210210212021015 0xfff globl hidden
|
||||||
scall __sys_pipe 0x02a10721e202a016 0xfff globl hidden # NOTE: pipe2() on FreeBSD; XNU is pipe(void)→eax:edx
|
scall __sys_pipe 0x02a10721e202a016 0x03b globl hidden # NOTE: pipe2() on FreeBSD and Linux Aarch64; XNU is pipe(void)→eax:edx
|
||||||
scall sys_select 0x9a184785d285d817 0xfff globl hidden
|
scall sys_select 0x9a184785d285d817 0xfff globl hidden
|
||||||
scall sys_pselect 0x9b486ea0a298a90e 0x048 globl hidden # pselect6() on gnu/systemd
|
scall sys_pselect 0x9b486ea0a298a90e 0x048 globl hidden # pselect6() on gnu/systemd
|
||||||
scall sys_sched_yield 0x15e12a14bf25d018 0x07c globl hidden # select() on XNU (previously swtch() but removed in 12.4)
|
scall sys_sched_yield 0x15e12a14bf25d018 0x07c globl hidden # select() on XNU (previously swtch() but removed in 12.4)
|
||||||
|
@ -68,7 +68,7 @@ scall sys_shmget 0x0e71210e7210901d 0x0c2 globl # no wrapper
|
||||||
scall sys_shmat 0x0e40e40e4210601e 0x0c4 globl # no wrapper
|
scall sys_shmat 0x0e40e40e4210601e 0x0c4 globl # no wrapper
|
||||||
scall sys_shmctl 0x1bb128200210701f 0x0c3 globl # no wrapper
|
scall sys_shmctl 0x1bb128200210701f 0x0c3 globl # no wrapper
|
||||||
scall sys_dup 0x0290290292029020 0x017 globl hidden
|
scall sys_dup 0x0290290292029020 0x017 globl hidden
|
||||||
scall sys_dup2 0x05a05a05a205a021 0xfff globl hidden
|
scall sys_dup2 0x05a05a05a205a021 0x018 globl hidden # dup3() on linux aarch64 (doesn't behave same if oldfd==newfd)
|
||||||
scall sys_pause 0xfffffffffffff022 0xfff globl hidden
|
scall sys_pause 0xfffffffffffff022 0xfff globl hidden
|
||||||
scall sys_nanosleep 0x9ae85b8f0ffff823 0x065 globl hidden
|
scall sys_nanosleep 0x9ae85b8f0ffff823 0x065 globl hidden
|
||||||
scall __sys_clock_nanosleep 0x9ddfff8f4ffff8e6 0x073 globl hidden
|
scall __sys_clock_nanosleep 0x9ddfff8f4ffff8e6 0x073 globl hidden
|
||||||
|
@ -125,19 +125,9 @@ scall sys_ftruncate 0x8c98c99e028c984d 0x02e globl hidden # netbsd+openbsd:pad
|
||||||
scall sys_getcwd 0x128130146ffff04f 0x011 globl hidden
|
scall sys_getcwd 0x128130146ffff04f 0x011 globl hidden
|
||||||
scall sys_chdir 0x00c00c00c200c050 0x031 globl hidden
|
scall sys_chdir 0x00c00c00c200c050 0x031 globl hidden
|
||||||
scall sys_fchdir 0x00d00d00d200d051 0x032 globl hidden
|
scall sys_fchdir 0x00d00d00d200d051 0x032 globl hidden
|
||||||
scall sys_rename 0x0800800802080052 0xfff globl hidden
|
|
||||||
scall sys_mkdir 0x0880880882088053 0xfff globl hidden
|
|
||||||
scall sys_rmdir 0x0890890892089054 0xfff globl hidden
|
|
||||||
scall sys_creat 0x008fff008ffff055 0xfff globl hidden
|
|
||||||
scall sys_link 0x0090090092009056 0xfff globl hidden
|
|
||||||
scall sys_unlink 0x00a00a00a200a057 0x0b5 globl hidden
|
scall sys_unlink 0x00a00a00a200a057 0x0b5 globl hidden
|
||||||
scall sys_symlink 0x0390390392039058 0xfff globl hidden
|
|
||||||
scall sys_readlink 0x03a03a03a203a059 0xfff globl hidden # usually an anti-pattern
|
|
||||||
scall sys_chmod 0x00f00f00f200f05a 0xfff globl hidden
|
|
||||||
scall sys_fchmod 0x07c07c07c207c05b 0x034 globl hidden
|
scall sys_fchmod 0x07c07c07c207c05b 0x034 globl hidden
|
||||||
scall sys_chown 0x010010010201005c 0xfff globl hidden # impl. w/ fchownat() @asyncsignalsafe
|
|
||||||
scall sys_fchown 0x07b07b07b207b05d 0x037 globl hidden # @asyncsignalsafe
|
scall sys_fchown 0x07b07b07b207b05d 0x037 globl hidden # @asyncsignalsafe
|
||||||
scall sys_lchown 0x1130fe0fe216c05e 0xfff globl hidden # impl. w/ fchownat()
|
|
||||||
scall sys_umask 0x03c03c03c203c05f 0x0a6 globl hidden
|
scall sys_umask 0x03c03c03c203c05f 0x0a6 globl hidden
|
||||||
scall sys_gettimeofday 0x1a20430742074060 0x0a9 globl hidden # xnu esi/edx=0
|
scall sys_gettimeofday 0x1a20430742074060 0x0a9 globl hidden # xnu esi/edx=0
|
||||||
scall sys_getrlimit 0x0c20c20c220c2061 0x0a3 globl hidden
|
scall sys_getrlimit 0x0c20c20c220c2061 0x0a3 globl hidden
|
||||||
|
@ -149,7 +139,6 @@ scall sys_syslog 0xfffffffffffff067 0x074 globl hidden
|
||||||
scall sys_getuid 0x0180180182018066 0x0ae globl hidden
|
scall sys_getuid 0x0180180182018066 0x0ae globl hidden
|
||||||
scall sys_getgid 0x02f02f02f202f068 0x0b0 globl hidden
|
scall sys_getgid 0x02f02f02f202f068 0x0b0 globl hidden
|
||||||
scall sys_getppid 0xfff027027202706e 0x0ad globl hidden # see sys_getpid()→edx for netbsd
|
scall sys_getppid 0xfff027027202706e 0x0ad globl hidden # see sys_getpid()→edx for netbsd
|
||||||
scall sys_getpgrp 0x051051051205106f 0xfff globl hidden
|
|
||||||
scall sys_setsid 0x0930930932093070 0x09d globl hidden
|
scall sys_setsid 0x0930930932093070 0x09d globl hidden
|
||||||
scall sys_getsid 0x11e0ff136213607c 0x09c globl hidden
|
scall sys_getsid 0x11e0ff136213607c 0x09c globl hidden
|
||||||
scall sys_getpgid 0x0cf0cf0cf2097079 0x09b globl hidden
|
scall sys_getpgid 0x0cf0cf0cf2097079 0x09b globl hidden
|
||||||
|
@ -291,7 +280,6 @@ scall sys_mkdirat 0x1cd13e1f021db102 0x022 globl hidden
|
||||||
scall sys_fchownat 0x1d013b1eb21d4104 0x036 globl hidden # @asyncsignalsafe
|
scall sys_fchownat 0x1d013b1eb21d4104 0x036 globl hidden # @asyncsignalsafe
|
||||||
scall sys_utime 0xfffffffffffff084 0x062 globl hidden
|
scall sys_utime 0xfffffffffffff084 0x062 globl hidden
|
||||||
scall sys_utimes 0x1a404c08a208a0eb 0x058 globl hidden
|
scall sys_utimes 0x1a404c08a208a0eb 0x058 globl hidden
|
||||||
scall sys_futimesat 0xffffff1eeffff105 0xfff globl hidden # @asyncsignalsafe
|
|
||||||
scall sys_futimes 0x1a704d0ce208bfff 0xfff globl hidden
|
scall sys_futimes 0x1a704d0ce208bfff 0xfff globl hidden
|
||||||
scall sys_futimens 0x1d8055222fffffff 0xfff globl hidden
|
scall sys_futimens 0x1d8055222fffffff 0xfff globl hidden
|
||||||
scall __sys_fstatat 0x1d202a22821d6106 0x04f globl hidden # a.k.a. newfstatat(); FreeBSD 12+; needs __stat2linux()
|
scall __sys_fstatat 0x1d202a22821d6106 0x04f globl hidden # a.k.a. newfstatat(); FreeBSD 12+; needs __stat2linux()
|
||||||
|
|
Loading…
Add table
Reference in a new issue