mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-27 14:58:30 +00:00
Add cpu / mem / fsz limits to build system
Thanks to all the refactorings we now have the ability to enforce reasonable limitations on the amount of resources any individual compile or test can consume. Those limits are currently: - `-C 8` seconds of 3.1ghz CPU time - `-M 256mebibytes` of virtual memory - `-F 100megabyte` limit on file size Only one file currently needs to exceed these limits: o/$(MODE)/third_party/python/Objects/unicodeobject.o: \ QUOTA += -C16 # overrides cpu limit to 16 seconds This change introduces a new sizetol() function to LIBC_FMT for parsing byte or bit size strings with Si unit suffixes. Functions like atoi() have been rewritten too.
This commit is contained in:
parent
9b29358511
commit
e963d9c8e3
49 changed files with 1802 additions and 553 deletions
81
libc/log/appendresourcereport.c
Normal file
81
libc/log/appendresourcereport.c
Normal file
|
@ -0,0 +1,81 @@
|
|||
/*-*- 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 2021 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/struct/rusage.h"
|
||||
#include "libc/log/log.h"
|
||||
#include "libc/math.h"
|
||||
#include "libc/runtime/clktck.h"
|
||||
#include "libc/stdio/append.internal.h"
|
||||
|
||||
/**
|
||||
* Generates process resource usage report.
|
||||
*/
|
||||
void AppendResourceReport(char **b, struct rusage *ru, const char *nl) {
|
||||
long utime, stime;
|
||||
long double ticks;
|
||||
if (ru->ru_maxrss) {
|
||||
(appendf)(b, "ballooned to %,ldkb in size%s", ru->ru_maxrss, nl);
|
||||
}
|
||||
if ((utime = ru->ru_utime.tv_sec * 1000000 + ru->ru_utime.tv_usec) |
|
||||
(stime = ru->ru_stime.tv_sec * 1000000 + ru->ru_stime.tv_usec)) {
|
||||
ticks = ceill((long double)(utime + stime) / (1000000.L / CLK_TCK));
|
||||
(appendf)(b, "needed %,ldµs cpu (%d%% kernel)%s", utime + stime,
|
||||
(int)((long double)stime / (utime + stime) * 100), nl);
|
||||
if (ru->ru_idrss) {
|
||||
(appendf)(b, "needed %,ldkb memory on average%s",
|
||||
lroundl(ru->ru_idrss / ticks), nl);
|
||||
}
|
||||
if (ru->ru_isrss) {
|
||||
(appendf)(b, "needed %,ldkb stack on average%s",
|
||||
lroundl(ru->ru_isrss / ticks), nl);
|
||||
}
|
||||
if (ru->ru_ixrss) {
|
||||
(appendf)(b, "mapped %,ldkb shared on average%s",
|
||||
lroundl(ru->ru_ixrss / ticks), nl);
|
||||
}
|
||||
}
|
||||
if (ru->ru_minflt || ru->ru_majflt) {
|
||||
(appendf)(b, "caused %,ld page faults (%d%% memcpy)%s",
|
||||
ru->ru_minflt + ru->ru_majflt,
|
||||
(int)((long double)ru->ru_minflt /
|
||||
(ru->ru_minflt + ru->ru_majflt) * 100),
|
||||
nl);
|
||||
}
|
||||
if (ru->ru_nvcsw + ru->ru_nivcsw > 1) {
|
||||
(appendf)(
|
||||
b, "%,ld context switches (%d%% consensual)%s",
|
||||
ru->ru_nvcsw + ru->ru_nivcsw,
|
||||
(int)((long double)ru->ru_nvcsw / (ru->ru_nvcsw + ru->ru_nivcsw) * 100),
|
||||
nl);
|
||||
}
|
||||
if (ru->ru_msgrcv || ru->ru_msgsnd) {
|
||||
(appendf)(b, "received %,ld message%s and sent %,ld%s", ru->ru_msgrcv,
|
||||
ru->ru_msgrcv == 1 ? "" : "s", ru->ru_msgsnd, nl);
|
||||
}
|
||||
if (ru->ru_inblock || ru->ru_oublock) {
|
||||
(appendf)(b, "performed %,ld read%s and %,ld write i/o operations%s",
|
||||
ru->ru_inblock, ru->ru_inblock == 1 ? "" : "s", ru->ru_oublock,
|
||||
nl);
|
||||
}
|
||||
if (ru->ru_nsignals) {
|
||||
(appendf)(b, "received %,ld signals%s", ru->ru_nsignals, nl);
|
||||
}
|
||||
if (ru->ru_nswap) {
|
||||
(appendf)(b, "got swapped %,ld times%s", ru->ru_nswap, nl);
|
||||
}
|
||||
}
|
|
@ -47,7 +47,8 @@ bool cancolor(void) {
|
|||
static bool once;
|
||||
static bool result;
|
||||
if (!once) {
|
||||
result = !!strcmp(nulltoempty(getenv("DONTANSIMEBRO")), "1");
|
||||
result = !!strcmp(nulltoempty(getenv("DONTANSIMEBRO")), "1") &&
|
||||
!!strcmp(nulltoempty(getenv("TERM")), "dumb");
|
||||
once = true;
|
||||
}
|
||||
return result;
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
void __check_fail_aligned(unsigned bytes, uint64_t ptr) {
|
||||
fflush(stderr);
|
||||
if (!IsTiny()) memsummary(fileno(stderr));
|
||||
(dprintf)(fileno(stderr), "%s%d%s%#p\r\n", "error: pointer not ", bytes,
|
||||
(dprintf)(fileno(stderr), "%s%d%s%#p\n", "error: pointer not ", bytes,
|
||||
"-byte aligned: ", ptr);
|
||||
__die();
|
||||
}
|
||||
|
|
|
@ -53,10 +53,10 @@ relegated void __check_fail(const char *suffix, const char *opstr,
|
|||
gethostname(hostname, sizeof(hostname));
|
||||
|
||||
(dprintf)(STDERR_FILENO,
|
||||
"check failed on %s pid %d\r\n"
|
||||
"\tCHECK_%s(%s, %s);\r\n"
|
||||
"\t\t → %#lx (%s)\r\n"
|
||||
"\t\t%s %#lx (%s)\r\n",
|
||||
"check failed on %s pid %d\n"
|
||||
"\tCHECK_%s(%s, %s);\n"
|
||||
"\t\t → %#lx (%s)\n"
|
||||
"\t\t%s %#lx (%s)\n",
|
||||
hostname, getpid(), sufbuf, wantstr, gotstr, want, wantstr, opstr,
|
||||
got, gotstr);
|
||||
|
||||
|
@ -65,19 +65,19 @@ relegated void __check_fail(const char *suffix, const char *opstr,
|
|||
va_start(va, fmt);
|
||||
(vdprintf)(STDERR_FILENO, fmt, va);
|
||||
va_end(va);
|
||||
(dprintf)(STDERR_FILENO, "\r\n");
|
||||
(dprintf)(STDERR_FILENO, "\n");
|
||||
}
|
||||
|
||||
(dprintf)(STDERR_FILENO, "\t%s\r\n\t%s%s%s%s\r\n", strerror(lasterr), SUBTLE,
|
||||
(dprintf)(STDERR_FILENO, "\t%s\n\t%s%s%s%s\n", strerror(lasterr), SUBTLE,
|
||||
getauxval(AT_EXECFN), __argc > 1 ? " \\" : "", RESET);
|
||||
|
||||
for (i = 1; i < __argc; ++i) {
|
||||
(dprintf)(STDERR_FILENO, "\t\t%s%s\r\n", __argv[i],
|
||||
(dprintf)(STDERR_FILENO, "\t\t%s%s\n", __argv[i],
|
||||
i < __argc - 1 ? " \\" : "");
|
||||
}
|
||||
|
||||
if (!IsTiny() && lasterr == ENOMEM) {
|
||||
(dprintf)(STDERR_FILENO, "\r\n");
|
||||
(dprintf)(STDERR_FILENO, "\n");
|
||||
PrintMemoryIntervals(STDERR_FILENO, &_mmi);
|
||||
}
|
||||
|
||||
|
|
|
@ -46,5 +46,5 @@ relegated void ___check_fail_ndebug(uint64_t want, uint64_t got,
|
|||
__print(bx, uint64toarray_radix16(got, bx));
|
||||
__print_string(" (");
|
||||
__print(bx, int64toarray_radix10(lasterr, bx));
|
||||
__print_string(")\r\n");
|
||||
__print_string(")\n");
|
||||
}
|
||||
|
|
154
libc/log/getsicodename.c
Normal file
154
libc/log/getsicodename.c
Normal file
|
@ -0,0 +1,154 @@
|
|||
/*-*- 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 2021 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/log/log.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/consts/sicode.h"
|
||||
#include "libc/sysv/consts/sig.h"
|
||||
|
||||
static bool IsSiUser(int si_code) {
|
||||
if (!IsOpenbsd()) {
|
||||
return si_code == SI_USER;
|
||||
} else {
|
||||
return si_code <= 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns symbolic name for siginfo::si_code value.
|
||||
*/
|
||||
const char *GetSiCodeName(int sig, int si_code) {
|
||||
static char b[16];
|
||||
memset(b, 0, sizeof(b));
|
||||
strcpy(b, "SI_???");
|
||||
if (si_code == SI_QUEUE) {
|
||||
strcpy(b + 3, "QUEUE"); /* sent by sigqueue(2) */
|
||||
} else if (si_code == SI_TIMER) {
|
||||
strcpy(b + 3, "TIMER"); /* sent by setitimer(2) or clock_settime(2) */
|
||||
} else if (si_code == SI_TKILL) {
|
||||
strcpy(b + 3, "TKILL"); /* sent by tkill(2), etc. */
|
||||
} else if (si_code == SI_MESGQ) {
|
||||
strcpy(b + 3, "MESGQ"); /* sent by mq_notify(2) */
|
||||
} else if (si_code == SI_MESGQ) {
|
||||
strcpy(b + 3, "MESGQ"); /* aio completion */
|
||||
} else if (si_code == SI_ASYNCNL) {
|
||||
strcpy(b + 3, "ASYNCNL"); /* aio completion for dns; the horror */
|
||||
} else if (si_code == SI_NOINFO) {
|
||||
strcpy(b + 3, "NOINFO"); /* no signal specific info available */
|
||||
} else if (si_code == SI_KERNEL) {
|
||||
strcpy(b + 3, "KERNEL"); /* sent by kernel */
|
||||
} else if (IsSiUser(si_code)) {
|
||||
strcpy(b + 3, "USER"); /* sent by kill(2) i.e. from userspace */
|
||||
} else if (sig == SIGCHLD) {
|
||||
strcpy(b, "CLD_???");
|
||||
if (si_code == CLD_EXITED) {
|
||||
strcpy(b + 4, "EXITED"); /* child exited */
|
||||
} else if (si_code == CLD_KILLED) {
|
||||
strcpy(b + 4, "KILLED"); /* child terminated w/o core */
|
||||
} else if (si_code == CLD_DUMPED) {
|
||||
strcpy(b + 4, "DUMPED"); /* child terminated w/ core */
|
||||
} else if (si_code == CLD_TRAPPED) {
|
||||
strcpy(b + 4, "TRAPPED"); /* traced child trapped */
|
||||
} else if (si_code == CLD_STOPPED) {
|
||||
strcpy(b + 4, "STOPPED"); /* child stopped */
|
||||
} else if (si_code == CLD_CONTINUED) {
|
||||
strcpy(b + 4, "CONTINUED"); /* stopped child continued */
|
||||
}
|
||||
} else if (sig == SIGTRAP) {
|
||||
strcpy(b, "TRAP_???");
|
||||
if (si_code == TRAP_BRKPT) {
|
||||
strcpy(b + 5, "BRKPT"); /* process breakpoint */
|
||||
} else if (si_code == TRAP_TRACE) {
|
||||
strcpy(b + 5, "TRACE"); /* process trace trap */
|
||||
}
|
||||
} else if (sig == SIGSEGV) {
|
||||
strcpy(b, "SEGV_???");
|
||||
if (si_code == SEGV_MAPERR) {
|
||||
strcpy(b + 5, "MAPERR"); /* address not mapped to object */
|
||||
} else if (si_code == SEGV_ACCERR) {
|
||||
strcpy(b + 5, "ACCERR"); /* invalid permissions for mapped object */
|
||||
}
|
||||
} else if (sig == SIGFPE) {
|
||||
strcpy(b, "FPE_???");
|
||||
if (si_code == FPE_INTDIV) {
|
||||
strcpy(b + 4, "INTDIV"); /* integer divide by zero */
|
||||
} else if (si_code == FPE_INTOVF) {
|
||||
strcpy(b + 4, "INTOVF"); /* integer overflow */
|
||||
} else if (si_code == FPE_FLTDIV) {
|
||||
strcpy(b + 4, "FLTDIV"); /* floating point divide by zero */
|
||||
} else if (si_code == FPE_FLTOVF) {
|
||||
strcpy(b + 4, "FLTOVF"); /* floating point overflow */
|
||||
} else if (si_code == FPE_FLTUND) {
|
||||
strcpy(b + 4, "FLTUND"); /* floating point underflow */
|
||||
} else if (si_code == FPE_FLTRES) {
|
||||
strcpy(b + 4, "FLTRES"); /* floating point inexact */
|
||||
} else if (si_code == FPE_FLTINV) {
|
||||
strcpy(b + 4, "FLTINV"); /* invalid floating point operation */
|
||||
} else if (si_code == FPE_FLTSUB) {
|
||||
strcpy(b + 4, "FLTSUB"); /* subscript out of range */
|
||||
}
|
||||
} else if (sig == SIGILL) {
|
||||
strcpy(b, "ILL_???");
|
||||
if (si_code == ILL_ILLOPC) {
|
||||
strcpy(b + 4, "ILLOPC"); /* illegal opcode */
|
||||
} else if (si_code == ILL_ILLOPN) {
|
||||
strcpy(b + 4, "ILLOPN"); /* illegal operand */
|
||||
} else if (si_code == ILL_ILLADR) {
|
||||
strcpy(b + 4, "ILLADR"); /* illegal addressing mode */
|
||||
} else if (si_code == ILL_ILLTRP) {
|
||||
strcpy(b + 4, "ILLTRP"); /* illegal trap */
|
||||
} else if (si_code == ILL_PRVOPC) {
|
||||
strcpy(b + 4, "PRVOPC"); /* privileged opcode */
|
||||
} else if (si_code == ILL_PRVREG) {
|
||||
strcpy(b + 4, "PRVREG"); /* privileged register */
|
||||
} else if (si_code == ILL_COPROC) {
|
||||
strcpy(b + 4, "COPROC"); /* coprocessor error */
|
||||
} else if (si_code == ILL_BADSTK) {
|
||||
strcpy(b + 4, "BADSTK"); /* internal stack error */
|
||||
}
|
||||
} else if (sig == SIGBUS) {
|
||||
strcpy(b, "BUS_???");
|
||||
if (si_code == BUS_ADRALN) {
|
||||
strcpy(b + 4, "ADRALN"); /* invalid address alignment */
|
||||
} else if (si_code == BUS_ADRERR) {
|
||||
strcpy(b + 4, "ADRERR"); /* non-existent physical address */
|
||||
} else if (si_code == BUS_OBJERR) {
|
||||
strcpy(b + 4, "OBJERR"); /* object specific hardware error */
|
||||
} else if (si_code == BUS_MCEERR_AR) {
|
||||
strcpy(b + 4, "BUS_AR"); /* Linux 2.6.32+ */
|
||||
} else if (si_code == BUS_MCEERR_AO) {
|
||||
strcpy(b + 4, "BUS_AO"); /* Linux 2.6.32+ */
|
||||
}
|
||||
} else if (sig == SIGIO) {
|
||||
strcpy(b, "POLL_???");
|
||||
if (si_code == POLL_IN) {
|
||||
strcpy(b + 5, "IN"); /* data input available */
|
||||
} else if (si_code == POLL_OUT) {
|
||||
strcpy(b + 5, "OUT"); /* output buffer available */
|
||||
} else if (si_code == POLL_MSG) {
|
||||
strcpy(b + 5, "MSG"); /* input message available */
|
||||
} else if (si_code == POLL_ERR) {
|
||||
strcpy(b + 5, "ERR"); /* i/o error */
|
||||
} else if (si_code == POLL_PRI) {
|
||||
strcpy(b + 5, "PRI"); /* high priority input available */
|
||||
} else if (si_code == POLL_HUP) {
|
||||
strcpy(b + 5, "HUP"); /* device disconnected */
|
||||
}
|
||||
}
|
||||
return b;
|
||||
}
|
|
@ -6,8 +6,8 @@
|
|||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
extern int kCrashSigs[8];
|
||||
extern struct sigaction g_oldcrashacts[8];
|
||||
extern int kCrashSigs[8] hidden;
|
||||
extern struct sigaction g_oldcrashacts[8] hidden;
|
||||
|
||||
void __start_fatal(const char *, int) hidden;
|
||||
void __start_fatal_ndebug(void) hidden;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_LOG_LOG_H_
|
||||
#define COSMOPOLITAN_LIBC_LOG_LOG_H_
|
||||
#include "libc/bits/likely.h"
|
||||
#include "libc/calls/struct/rusage.h"
|
||||
#include "libc/calls/struct/sigset.h"
|
||||
#include "libc/calls/struct/winsize.h"
|
||||
#include "libc/nexgen32e/stackframe.h"
|
||||
|
@ -52,6 +53,8 @@ void showcrashreports(void);
|
|||
void callexitontermination(struct sigset *);
|
||||
bool32 IsDebuggerPresent(bool);
|
||||
bool IsRunningUnderMake(void);
|
||||
const char *GetSiCodeName(int, int);
|
||||
void AppendResourceReport(char **, struct rusage *, const char *);
|
||||
|
||||
/*───────────────────────────────────────────────────────────────────────────│─╗
|
||||
│ cosmopolitan § liblog » logging ─╬─│┼
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
void malloc_stats(void) {
|
||||
struct MallocStats res = dlmalloc_stats(g_dlmalloc);
|
||||
(fprintf)(stderr, "max system bytes = %'10zu\r\n", res.maxfp);
|
||||
(fprintf)(stderr, "system bytes = %'10zu\r\n", res.fp);
|
||||
(fprintf)(stderr, "in use bytes = %'10zu\r\n", res.used);
|
||||
(fprintf)(stderr, "max system bytes = %'10zu\n", res.maxfp);
|
||||
(fprintf)(stderr, "system bytes = %'10zu\n", res.fp);
|
||||
(fprintf)(stderr, "in use bytes = %'10zu\n", res.used);
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
#include "libc/mem/mem.h"
|
||||
|
||||
static void onmemchunk(void *start, void *end, size_t used_bytes, void *arg) {
|
||||
(dprintf)(*(int *)arg, "%p - %p : %08zx / %08lx\r\n", start, end, used_bytes,
|
||||
(dprintf)(*(int *)arg, "%p - %p : %08zx / %08lx\n", start, end, used_bytes,
|
||||
(intptr_t)end - (intptr_t)start);
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,7 @@ static void onmemchunk(void *start, void *end, size_t used_bytes, void *arg) {
|
|||
*/
|
||||
void meminfo(int fd) {
|
||||
memsummary(fd);
|
||||
(dprintf)(fd, "%*s %*s %*s %*s\r\n", POINTER_XDIGITS, "start",
|
||||
(dprintf)(fd, "%*s %*s %*s %*s\n", POINTER_XDIGITS, "start",
|
||||
POINTER_XDIGITS, "end", 8, "used", 8, "size");
|
||||
malloc_inspect_all(onmemchunk, &fd);
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/sigbits.h"
|
||||
#include "libc/calls/struct/sigaction.h"
|
||||
#include "libc/calls/struct/siginfo.h"
|
||||
#include "libc/calls/struct/utsname.h"
|
||||
#include "libc/calls/ucontext.h"
|
||||
|
@ -57,11 +58,21 @@ static const char kGregNames[17][4] forcealign(1) = {
|
|||
|
||||
static const char kCpuFlags[12] forcealign(1) = "CVPRAKZSTIDO";
|
||||
static const char kFpuExceptions[6] forcealign(1) = "IDZOUP";
|
||||
static const char kCrashSigNames[8][5] forcealign(1) = {
|
||||
"QUIT", "FPE", "ILL", "SEGV", "TRAP", "ABRT", "BUS", "PIPE"};
|
||||
|
||||
hidden int kCrashSigs[8];
|
||||
hidden struct sigaction g_oldcrashacts[8];
|
||||
/* <SYNC-LIST>: showcrashreports.c, oncrashthunks.S, oncrash.c */
|
||||
int kCrashSigs[8];
|
||||
struct sigaction g_oldcrashacts[8];
|
||||
static const char kCrashSigNames[8][5] forcealign(1) = {
|
||||
"QUIT", //
|
||||
"FPE", //
|
||||
"ILL", //
|
||||
"SEGV", //
|
||||
"TRAP", //
|
||||
"ABRT", //
|
||||
"BUS", //
|
||||
"PIPE", //
|
||||
};
|
||||
/* </SYNC-LIST>: showcrashreports.c, oncrashthunks.S, oncrash.c */
|
||||
|
||||
relegated static const char *TinyStrSignal(int sig) {
|
||||
size_t i;
|
||||
|
@ -76,7 +87,7 @@ relegated static const char *TinyStrSignal(int sig) {
|
|||
relegated static void ShowFunctionCalls(int fd, ucontext_t *ctx) {
|
||||
struct StackFrame *bp;
|
||||
struct StackFrame goodframe;
|
||||
write(fd, "\r\n", 2);
|
||||
write(fd, "\n", 1);
|
||||
if (ctx && ctx->uc_mcontext.rip && ctx->uc_mcontext.rbp) {
|
||||
goodframe.next = (struct StackFrame *)ctx->uc_mcontext.rbp;
|
||||
goodframe.addr = ctx->uc_mcontext.rip;
|
||||
|
@ -121,7 +132,7 @@ relegated static void DescribeCpuFlags(int fd, int flags, int x87sw,
|
|||
relegated static void ShowGeneralRegisters(int fd, ucontext_t *ctx) {
|
||||
size_t i, j, k;
|
||||
long double st;
|
||||
write(fd, "\r\n", 2);
|
||||
write(fd, "\n", 1);
|
||||
for (i = 0, j = 0, k = 0; i < ARRAYLEN(kGregNames); ++i) {
|
||||
if (j > 0) write(fd, " ", 1);
|
||||
dprintf(fd, "%-3s %016lx", kGregNames[(unsigned)kGregOrder[i]],
|
||||
|
@ -135,7 +146,7 @@ relegated static void ShowGeneralRegisters(int fd, ucontext_t *ctx) {
|
|||
}
|
||||
dprintf(fd, " %s(%zu) %Lg", "ST", k, st);
|
||||
++k;
|
||||
write(fd, "\r\n", 2);
|
||||
write(fd, "\n", 1);
|
||||
}
|
||||
}
|
||||
DescribeCpuFlags(
|
||||
|
@ -147,9 +158,9 @@ relegated static void ShowGeneralRegisters(int fd, ucontext_t *ctx) {
|
|||
relegated static void ShowSseRegisters(int fd, ucontext_t *ctx) {
|
||||
size_t i;
|
||||
if (ctx->uc_mcontext.fpregs) {
|
||||
write(fd, "\r\n\r\n", 4);
|
||||
write(fd, "\n\n", 2);
|
||||
for (i = 0; i < 8; ++i) {
|
||||
dprintf(fd, "%s%-2zu %016lx%016lx %s%-2d %016lx%016lx\r\n", "XMM", i + 0,
|
||||
dprintf(fd, "%s%-2zu %016lx%016lx %s%-2d %016lx%016lx\n", "XMM", i + 0,
|
||||
ctx->uc_mcontext.fpregs->xmm[i + 0].u64[1],
|
||||
ctx->uc_mcontext.fpregs->xmm[i + 0].u64[0], "XMM", i + 8,
|
||||
ctx->uc_mcontext.fpregs->xmm[i + 8].u64[1],
|
||||
|
@ -174,32 +185,37 @@ relegated static void ShowMemoryMappings(int outfd) {
|
|||
}
|
||||
|
||||
relegated static void ShowCrashReport(int err, int fd, int sig,
|
||||
ucontext_t *ctx) {
|
||||
struct siginfo *si, ucontext_t *ctx) {
|
||||
int i;
|
||||
char hostname[64];
|
||||
struct utsname names;
|
||||
strcpy(hostname, "unknown");
|
||||
gethostname(hostname, sizeof(hostname));
|
||||
dprintf(fd, "\r\n%serror%s: Uncaught SIG%s on %s\r\n %s\r\n %s\r\n", RED2,
|
||||
RESET, TinyStrSignal(sig), hostname, getauxval(AT_EXECFN),
|
||||
strerror(err));
|
||||
dprintf(fd,
|
||||
"\n"
|
||||
"%serror%s: Uncaught SIG%s (%s) on %s\n"
|
||||
" %s\n"
|
||||
" %s\n",
|
||||
RED2, RESET, TinyStrSignal(sig),
|
||||
si ? GetSiCodeName(sig, si->si_code) : "???", hostname,
|
||||
getauxval(AT_EXECFN), strerror(err));
|
||||
if (uname(&names) != -1) {
|
||||
dprintf(fd, " %s %s %s %s\r\n", names.sysname, names.nodename,
|
||||
names.release, names.version);
|
||||
dprintf(fd, " %s %s %s %s\n", names.sysname, names.nodename, names.release,
|
||||
names.version);
|
||||
}
|
||||
ShowFunctionCalls(fd, ctx);
|
||||
if (ctx) {
|
||||
ShowGeneralRegisters(fd, ctx);
|
||||
ShowSseRegisters(fd, ctx);
|
||||
}
|
||||
write(fd, "\r\n", 2);
|
||||
write(fd, "\n", 1);
|
||||
ShowMemoryMappings(fd);
|
||||
write(fd, "\r\n", 2);
|
||||
write(fd, "\n", 1);
|
||||
for (i = 0; i < __argc; ++i) {
|
||||
write(fd, __argv[i], strlen(__argv[i]));
|
||||
write(fd, " ", 1);
|
||||
}
|
||||
write(fd, "\r\n", 2);
|
||||
write(fd, "\n", 1);
|
||||
}
|
||||
|
||||
relegated static void RestoreDefaultCrashSignalHandlers(void) {
|
||||
|
@ -246,7 +262,7 @@ relegated void __oncrash(int sig, struct siginfo *si, ucontext_t *ctx) {
|
|||
: 0);
|
||||
}
|
||||
if (gdbpid > 0 && (sig == SIGTRAP || sig == SIGQUIT)) return;
|
||||
ShowCrashReport(err, STDERR_FILENO, sig, ctx);
|
||||
ShowCrashReport(err, STDERR_FILENO, sig, si, ctx);
|
||||
exit(128 + sig);
|
||||
unreachable;
|
||||
}
|
||||
|
|
|
@ -25,6 +25,8 @@
|
|||
|
||||
__oncrash_thunks:
|
||||
|
||||
// <SYNC-LIST>: showcrashreports.c, oncrashthunks.S, oncrash.c
|
||||
|
||||
.org 11*0
|
||||
__oncrash_sigquit:
|
||||
push %rbp
|
||||
|
@ -97,4 +99,6 @@ __oncrash_sigpipe:
|
|||
ret
|
||||
.endfn __oncrash_sigpipe,globl
|
||||
|
||||
// </SYNC-LIST>: showcrashreports.c, oncrashthunks.S, oncrash.c
|
||||
|
||||
.endobj __oncrash_thunks,globl
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
|
||||
STATIC_YOINK("__die");
|
||||
|
||||
extern const unsigned char __oncrash_thunks[7][11];
|
||||
extern const unsigned char __oncrash_thunks[8][11];
|
||||
|
||||
/**
|
||||
* Installs crash signal handlers.
|
||||
|
@ -56,7 +56,7 @@ extern const unsigned char __oncrash_thunks[7][11];
|
|||
void showcrashreports(void) {
|
||||
size_t i;
|
||||
struct sigaction sa;
|
||||
/* <SYNC-LIST>: oncrashthunks.S */
|
||||
/* <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 */
|
||||
|
@ -65,9 +65,9 @@ void showcrashreports(void) {
|
|||
kCrashSigs[5] = SIGABRT; /* abort() called */
|
||||
kCrashSigs[6] = SIGBUS; /* misaligned, noncanonical ptr, etc. */
|
||||
kCrashSigs[7] = SIGPIPE; /* write to closed thing */
|
||||
/* </SYNC-LIST>: oncrashthunks.S */
|
||||
/* </SYNC-LIST>: showcrashreports.c, oncrashthunks.S, oncrash.c */
|
||||
memset(&sa, 0, sizeof(sa));
|
||||
sa.sa_flags = SA_RESETHAND;
|
||||
sa.sa_flags = SA_RESETHAND | SA_SIGINFO;
|
||||
sigfillset(&sa.sa_mask);
|
||||
for (i = 0; i < ARRAYLEN(kCrashSigs); ++i) {
|
||||
sigdelset(&sa.sa_mask, kCrashSigs[i]);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue