mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-27 06:48:31 +00:00
Show crash reports on SIGSYS
This will help make it easier to troubleshoot ABI breakages with on operating systems that, unlike Linux don't have ironclad guarantees to not break userspace.
This commit is contained in:
parent
a4601a24d3
commit
44da16255a
11 changed files with 83 additions and 19 deletions
|
@ -12,6 +12,7 @@ int __notziposat(int, const char *);
|
||||||
int gethostname_bsd(char *, size_t) hidden;
|
int gethostname_bsd(char *, size_t) hidden;
|
||||||
int gethostname_linux(char *, size_t) hidden;
|
int gethostname_linux(char *, size_t) hidden;
|
||||||
int gethostname_nt(char *, size_t, int) hidden;
|
int gethostname_nt(char *, size_t, int) hidden;
|
||||||
|
long sys_bogus(void);
|
||||||
void *__vdsosym(const char *, const char *) hidden;
|
void *__vdsosym(const char *, const char *) hidden;
|
||||||
void __onfork(void) hidden;
|
void __onfork(void) hidden;
|
||||||
void __restore_rt() hidden;
|
void __restore_rt() hidden;
|
||||||
|
|
|
@ -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/fmt/itoa.h"
|
||||||
#include "libc/log/log.h"
|
#include "libc/log/log.h"
|
||||||
#include "libc/str/str.h"
|
#include "libc/str/str.h"
|
||||||
#include "libc/sysv/consts/sicode.h"
|
#include "libc/sysv/consts/sicode.h"
|
||||||
|
@ -29,13 +30,17 @@ static bool IsSiUser(int si_code) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void NameIt(char p[17], const char *s, int si_code) {
|
||||||
|
p = stpcpy(p, s);
|
||||||
|
FormatInt32(p, si_code);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns symbolic name for siginfo::si_code value.
|
* Returns symbolic name for siginfo::si_code value.
|
||||||
*/
|
*/
|
||||||
const char *GetSiCodeName(int sig, int si_code) {
|
const char *GetSiCodeName(int sig, int si_code) {
|
||||||
static char b[16];
|
static char b[17];
|
||||||
bzero(b, sizeof(b));
|
NameIt(b, "SI_", si_code);
|
||||||
strcpy(b, "SI_???");
|
|
||||||
if (si_code == SI_QUEUE) {
|
if (si_code == SI_QUEUE) {
|
||||||
strcpy(b + 3, "QUEUE"); /* sent by sigqueue(2) */
|
strcpy(b + 3, "QUEUE"); /* sent by sigqueue(2) */
|
||||||
} else if (si_code == SI_TIMER) {
|
} else if (si_code == SI_TIMER) {
|
||||||
|
@ -55,7 +60,7 @@ const char *GetSiCodeName(int sig, int si_code) {
|
||||||
} else if (IsSiUser(si_code)) {
|
} else if (IsSiUser(si_code)) {
|
||||||
strcpy(b + 3, "USER"); /* sent by kill(2) i.e. from userspace */
|
strcpy(b + 3, "USER"); /* sent by kill(2) i.e. from userspace */
|
||||||
} else if (sig == SIGCHLD) {
|
} else if (sig == SIGCHLD) {
|
||||||
strcpy(b, "CLD_???");
|
NameIt(b, "CLD_", si_code);
|
||||||
if (si_code == CLD_EXITED) {
|
if (si_code == CLD_EXITED) {
|
||||||
strcpy(b + 4, "EXITED"); /* child exited */
|
strcpy(b + 4, "EXITED"); /* child exited */
|
||||||
} else if (si_code == CLD_KILLED) {
|
} else if (si_code == CLD_KILLED) {
|
||||||
|
@ -70,14 +75,14 @@ const char *GetSiCodeName(int sig, int si_code) {
|
||||||
strcpy(b + 4, "CONTINUED"); /* stopped child continued */
|
strcpy(b + 4, "CONTINUED"); /* stopped child continued */
|
||||||
}
|
}
|
||||||
} else if (sig == SIGTRAP) {
|
} else if (sig == SIGTRAP) {
|
||||||
strcpy(b, "TRAP_???");
|
NameIt(b, "TRAP_", si_code);
|
||||||
if (si_code == TRAP_BRKPT) {
|
if (si_code == TRAP_BRKPT) {
|
||||||
strcpy(b + 5, "BRKPT"); /* process breakpoint */
|
strcpy(b + 5, "BRKPT"); /* process breakpoint */
|
||||||
} else if (si_code == TRAP_TRACE) {
|
} else if (si_code == TRAP_TRACE) {
|
||||||
strcpy(b + 5, "TRACE"); /* process trace trap */
|
strcpy(b + 5, "TRACE"); /* process trace trap */
|
||||||
}
|
}
|
||||||
} else if (sig == SIGSEGV) {
|
} else if (sig == SIGSEGV) {
|
||||||
strcpy(b, "SEGV_???");
|
NameIt(b, "SEGV_", si_code);
|
||||||
if (si_code == SEGV_MAPERR) {
|
if (si_code == SEGV_MAPERR) {
|
||||||
strcpy(b + 5, "MAPERR"); /* address not mapped to object */
|
strcpy(b + 5, "MAPERR"); /* address not mapped to object */
|
||||||
} else if (si_code == SEGV_ACCERR) {
|
} else if (si_code == SEGV_ACCERR) {
|
||||||
|
@ -86,7 +91,7 @@ const char *GetSiCodeName(int sig, int si_code) {
|
||||||
strcpy(b + 5, "PKUERR"); /* FreeBSD: x86: PKU violation */
|
strcpy(b + 5, "PKUERR"); /* FreeBSD: x86: PKU violation */
|
||||||
}
|
}
|
||||||
} else if (sig == SIGFPE) {
|
} else if (sig == SIGFPE) {
|
||||||
strcpy(b, "FPE_???");
|
NameIt(b, "FPE_???", si_code);
|
||||||
if (si_code == FPE_INTDIV) {
|
if (si_code == FPE_INTDIV) {
|
||||||
strcpy(b + 4, "INTDIV"); /* integer divide by zero */
|
strcpy(b + 4, "INTDIV"); /* integer divide by zero */
|
||||||
} else if (si_code == FPE_INTOVF) {
|
} else if (si_code == FPE_INTOVF) {
|
||||||
|
@ -105,7 +110,7 @@ const char *GetSiCodeName(int sig, int si_code) {
|
||||||
strcpy(b + 4, "FLTSUB"); /* subscript out of range */
|
strcpy(b + 4, "FLTSUB"); /* subscript out of range */
|
||||||
}
|
}
|
||||||
} else if (sig == SIGILL) {
|
} else if (sig == SIGILL) {
|
||||||
strcpy(b, "ILL_???");
|
NameIt(b, "ILL_", si_code);
|
||||||
if (si_code == ILL_ILLOPC) {
|
if (si_code == ILL_ILLOPC) {
|
||||||
strcpy(b + 4, "ILLOPC"); /* illegal opcode */
|
strcpy(b + 4, "ILLOPC"); /* illegal opcode */
|
||||||
} else if (si_code == ILL_ILLOPN) {
|
} else if (si_code == ILL_ILLOPN) {
|
||||||
|
@ -124,7 +129,7 @@ const char *GetSiCodeName(int sig, int si_code) {
|
||||||
strcpy(b + 4, "BADSTK"); /* internal stack error */
|
strcpy(b + 4, "BADSTK"); /* internal stack error */
|
||||||
}
|
}
|
||||||
} else if (sig == SIGBUS) {
|
} else if (sig == SIGBUS) {
|
||||||
strcpy(b, "BUS_???");
|
NameIt(b, "BUS_", si_code);
|
||||||
if (si_code == BUS_ADRALN) {
|
if (si_code == BUS_ADRALN) {
|
||||||
strcpy(b + 4, "ADRALN"); /* invalid address alignment */
|
strcpy(b + 4, "ADRALN"); /* invalid address alignment */
|
||||||
} else if (si_code == BUS_ADRERR) {
|
} else if (si_code == BUS_ADRERR) {
|
||||||
|
@ -139,7 +144,7 @@ const char *GetSiCodeName(int sig, int si_code) {
|
||||||
strcpy(b + 4, "MCEERR_AO"); /* Linux 2.6.32+ */
|
strcpy(b + 4, "MCEERR_AO"); /* Linux 2.6.32+ */
|
||||||
}
|
}
|
||||||
} else if (sig == SIGIO) {
|
} else if (sig == SIGIO) {
|
||||||
strcpy(b, "POLL_???");
|
NameIt(b, "POLL_", si_code);
|
||||||
if (si_code == POLL_IN) {
|
if (si_code == POLL_IN) {
|
||||||
strcpy(b + 5, "IN"); /* data input available */
|
strcpy(b + 5, "IN"); /* data input available */
|
||||||
} else if (si_code == POLL_OUT) {
|
} else if (si_code == POLL_OUT) {
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
COSMOPOLITAN_C_START_
|
COSMOPOLITAN_C_START_
|
||||||
|
|
||||||
extern hidden bool __nocolor;
|
extern hidden bool __nocolor;
|
||||||
extern hidden int kCrashSigs[7];
|
extern hidden int kCrashSigs[8];
|
||||||
extern hidden bool g_isrunningundermake;
|
extern hidden bool g_isrunningundermake;
|
||||||
|
|
||||||
void __start_fatal(const char *, int) hidden;
|
void __start_fatal(const char *, int) hidden;
|
||||||
|
|
|
@ -58,7 +58,7 @@ 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[7];
|
int kCrashSigs[8];
|
||||||
|
|
||||||
relegated static void ShowFunctionCalls(ucontext_t *ctx) {
|
relegated static void ShowFunctionCalls(ucontext_t *ctx) {
|
||||||
struct StackFrame *bp;
|
struct StackFrame *bp;
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
|
|
||||||
__oncrash_thunks:
|
__oncrash_thunks:
|
||||||
|
|
||||||
// <SYNC-LIST>: showcrashreports.c, oncrashthunks.S, oncrash.c
|
// <SYNC-LIST>: showcrashreports.c, oncrashthunks.S, oncrash.c, internal.h
|
||||||
|
|
||||||
.org 11*0
|
.org 11*0
|
||||||
__oncrash_sigquit:
|
__oncrash_sigquit:
|
||||||
|
@ -89,6 +89,15 @@ __oncrash_sigbus:
|
||||||
ret
|
ret
|
||||||
.endfn __oncrash_sigbus,globl
|
.endfn __oncrash_sigbus,globl
|
||||||
|
|
||||||
// </SYNC-LIST>: showcrashreports.c, oncrashthunks.S, oncrash.c
|
.org 11*7
|
||||||
|
__oncrash_sigsys:
|
||||||
|
push %rbp
|
||||||
|
mov %rsp,%rbp
|
||||||
|
call __oncrash
|
||||||
|
pop %rbp
|
||||||
|
ret
|
||||||
|
.endfn __oncrash_sigsys,globl
|
||||||
|
|
||||||
|
// </SYNC-LIST>: showcrashreports.c, oncrashthunks.S, oncrash.c, internal.h
|
||||||
|
|
||||||
.endobj __oncrash_thunks,globl
|
.endobj __oncrash_thunks,globl
|
||||||
|
|
|
@ -39,7 +39,7 @@ STATIC_YOINK("__get_symbol_by_addr"); // for asan memory origin
|
||||||
|
|
||||||
extern const unsigned char __oncrash_thunks[8][11];
|
extern const unsigned char __oncrash_thunks[8][11];
|
||||||
static struct sigaltstack g_oldsigaltstack;
|
static struct sigaltstack g_oldsigaltstack;
|
||||||
static struct sigaction g_oldcrashacts[7];
|
static struct sigaction g_oldcrashacts[8];
|
||||||
|
|
||||||
static void InstallCrashHandlers(int extraflags) {
|
static void InstallCrashHandlers(int extraflags) {
|
||||||
size_t i;
|
size_t i;
|
||||||
|
@ -104,6 +104,7 @@ void ShowCrashReports(void) {
|
||||||
kCrashSigs[4] = SIGTRAP; /* bad system call */
|
kCrashSigs[4] = SIGTRAP; /* bad system call */
|
||||||
kCrashSigs[5] = SIGABRT; /* abort() called */
|
kCrashSigs[5] = SIGABRT; /* abort() called */
|
||||||
kCrashSigs[6] = SIGBUS; /* misaligned, noncanonical ptr, etc. */
|
kCrashSigs[6] = SIGBUS; /* misaligned, noncanonical ptr, etc. */
|
||||||
|
kCrashSigs[7] = SIGSYS; /* bad system call */
|
||||||
/* </SYNC-LIST>: showcrashreports.c, oncrashthunks.S, oncrash.c */
|
/* </SYNC-LIST>: showcrashreports.c, oncrashthunks.S, oncrash.c */
|
||||||
if (!IsWindows()) {
|
if (!IsWindows()) {
|
||||||
bzero(&ss, sizeof(ss));
|
bzero(&ss, sizeof(ss));
|
||||||
|
|
35
libc/log/showcrashreportsearly.S
Normal file
35
libc/log/showcrashreportsearly.S
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
|
||||||
|
│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│
|
||||||
|
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||||
|
│ Copyright 2022 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/macros.internal.h"
|
||||||
|
|
||||||
|
// Normally we call ShowCrashReports() from main, but if
|
||||||
|
// there's a crash in a constructor, this will help with
|
||||||
|
// troubleshooting it. You need to add:
|
||||||
|
//
|
||||||
|
// STATIC_YOINK("ShowCrashReportsEarly");
|
||||||
|
//
|
||||||
|
// To the top of your main module to use this.
|
||||||
|
|
||||||
|
.init.start 400,ShowCrashReportsEarly
|
||||||
|
push %rdi
|
||||||
|
push %rsi
|
||||||
|
call ShowCrashReports
|
||||||
|
pop %rsi
|
||||||
|
pop %rdi
|
||||||
|
.init.end 400,ShowCrashReportsEarly
|
2
libc/sysv/calls/sys_bogus.s
Normal file
2
libc/sysv/calls/sys_bogus.s
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
.include "o/libc/sysv/macros.internal.inc"
|
||||||
|
.scall sys_bogus,0x5005005002500500,globl
|
|
@ -375,6 +375,7 @@ scall io_uring_register 0xfffffffffffff1ab globl
|
||||||
#────────────────────────RHEL CLOUD────────────────────────── # ←┬─ red hat terminates community release of enterprise linux circa 2020
|
#────────────────────────RHEL CLOUD────────────────────────── # ←┬─ red hat terminates community release of enterprise linux circa 2020
|
||||||
scall sys_pledge 0xfff06cffffffffff globl # └─ online linux services ban the president of united states of america
|
scall sys_pledge 0xfff06cffffffffff globl # └─ online linux services ban the president of united states of america
|
||||||
scall msyscall 0xfff025ffffffffff globl
|
scall msyscall 0xfff025ffffffffff globl
|
||||||
|
scall sys_bogus 0x5005005002500500 globl
|
||||||
|
|
||||||
# The Fifth Bell System Interface, Community Edition
|
# The Fifth Bell System Interface, Community Edition
|
||||||
# » besiyata dishmaya
|
# » besiyata dishmaya
|
||||||
|
|
|
@ -164,8 +164,17 @@ systemfive_bsdscrub:
|
||||||
systemfive_bsd:
|
systemfive_bsd:
|
||||||
cmp $0xfff,%ax
|
cmp $0xfff,%ax
|
||||||
je systemfive_enosys
|
je systemfive_enosys
|
||||||
mov %rcx,%r10 # note: we do not create a stack frame
|
mov %rcx,%r10
|
||||||
|
push %rbx
|
||||||
|
push 32(%rsp)
|
||||||
|
push 24(%rsp)
|
||||||
|
push 16(%rsp)
|
||||||
|
mov %rax,%rbx # save ordinal for SIGSYS crash report
|
||||||
syscall # bsd will need arg on stack sometimes
|
syscall # bsd will need arg on stack sometimes
|
||||||
|
pop %rbx
|
||||||
|
pop %rbx
|
||||||
|
pop %rbx
|
||||||
|
pop %rbx
|
||||||
jc systemfive_errno # bsd sets carry flag if %rax is errno
|
jc systemfive_errno # bsd sets carry flag if %rax is errno
|
||||||
ret
|
ret
|
||||||
.endfn systemfive_bsd
|
.endfn systemfive_bsd
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
#include "libc/calls/struct/sigaction.h"
|
#include "libc/calls/struct/sigaction.h"
|
||||||
#include "libc/calls/struct/stat.h"
|
#include "libc/calls/struct/stat.h"
|
||||||
#include "libc/calls/struct/termios.h"
|
#include "libc/calls/struct/termios.h"
|
||||||
|
#include "libc/dce.h"
|
||||||
#include "libc/dns/dns.h"
|
#include "libc/dns/dns.h"
|
||||||
#include "libc/dns/hoststxt.h"
|
#include "libc/dns/hoststxt.h"
|
||||||
#include "libc/dos.h"
|
#include "libc/dos.h"
|
||||||
|
@ -114,6 +115,9 @@
|
||||||
|
|
||||||
STATIC_STACK_SIZE(0x40000);
|
STATIC_STACK_SIZE(0x40000);
|
||||||
STATIC_YOINK("zip_uri_support");
|
STATIC_YOINK("zip_uri_support");
|
||||||
|
#if !IsTiny()
|
||||||
|
STATIC_YOINK("ShowCrashReportsEarly");
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fileoverview redbean - single-file distributable web server
|
* @fileoverview redbean - single-file distributable web server
|
||||||
|
@ -7310,9 +7314,6 @@ void RedBean(int argc, char *argv[]) {
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
LoadZipArgs(&argc, &argv);
|
LoadZipArgs(&argc, &argv);
|
||||||
if (!IsTiny()) {
|
|
||||||
ShowCrashReports();
|
|
||||||
}
|
|
||||||
RedBean(argc, argv);
|
RedBean(argc, argv);
|
||||||
if (IsModeDbg()) {
|
if (IsModeDbg()) {
|
||||||
CheckForMemoryLeaks();
|
CheckForMemoryLeaks();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue