mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-28 15:28:30 +00:00
Pay off more technical debt
This makes breaking changes to add underscores to many non-standard function names provided by the c library. MODE=tiny is now tinier and we now use smaller locks that are better for tiny apps in this mode. Some headers have been renamed to be in the same folder as the build package, so it'll be easier to know which build dependency is needed. Certain old misguided interfaces have been removed. Intel intrinsics headers are now listed in libc/isystem (but not in the amalgamation) to help further improve open source compatibility. Header complexity has also been reduced. Lastly, more shell scripts are now available.
This commit is contained in:
parent
b69f3d2488
commit
6f7d0cb1c3
960 changed files with 4072 additions and 4873 deletions
|
@ -16,13 +16,13 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/intrin/bits.h"
|
||||
#include "libc/calls/struct/rusage.h"
|
||||
#include "libc/fmt/itoa.h"
|
||||
#include "libc/intrin/bits.h"
|
||||
#include "libc/log/log.h"
|
||||
#include "libc/math.h"
|
||||
#include "libc/runtime/clktck.h"
|
||||
#include "libc/stdio/append.internal.h"
|
||||
#include "libc/stdio/append.h"
|
||||
|
||||
struct State {
|
||||
char **b;
|
||||
|
|
11
libc/log/appendresourcereport.internal.h
Normal file
11
libc/log/appendresourcereport.internal.h
Normal file
|
@ -0,0 +1,11 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_LOG_APPENDRESOURCEREPORT_INTERNAL_H_
|
||||
#define COSMOPOLITAN_LIBC_LOG_APPENDRESOURCEREPORT_INTERNAL_H_
|
||||
#include "libc/calls/struct/rusage.h"
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
void AppendResourceReport(char **, struct rusage *, const char *);
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_LOG_APPENDRESOURCEREPORT_INTERNAL_H_ */
|
|
@ -18,7 +18,6 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/calls/strace.internal.h"
|
||||
#include "libc/calls/struct/rusage.internal.h"
|
||||
#include "libc/calls/syscall-sysv.internal.h"
|
||||
#include "libc/calls/syscall_support-sysv.internal.h"
|
||||
|
@ -30,18 +29,19 @@
|
|||
#include "libc/intrin/kprintf.h"
|
||||
#include "libc/intrin/promises.internal.h"
|
||||
#include "libc/intrin/safemacros.internal.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
#include "libc/intrin/weaken.h"
|
||||
#include "libc/log/backtrace.internal.h"
|
||||
#include "libc/log/color.internal.h"
|
||||
#include "libc/log/log.h"
|
||||
#include "libc/mem/alg.h"
|
||||
#include "libc/mem/bisectcarleft.internal.h"
|
||||
#include "libc/mem/gc.internal.h"
|
||||
#include "libc/nexgen32e/gc.internal.h"
|
||||
#include "libc/runtime/gc.internal.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/runtime/stack.h"
|
||||
#include "libc/runtime/symbols.internal.h"
|
||||
#include "libc/stdio/append.internal.h"
|
||||
#include "libc/stdio/append.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/consts/fileno.h"
|
||||
|
@ -111,10 +111,10 @@ static int PrintBacktraceUsingAddr2line(int fd, const struct StackFrame *bp) {
|
|||
gi = garbage ? garbage->i : 0;
|
||||
for (frame = bp; frame && i < kBacktraceMaxFrames - 1; frame = frame->next) {
|
||||
addr = frame->addr;
|
||||
if (addr == weakaddr("__gc")) {
|
||||
if (addr == _weakaddr("__gc")) {
|
||||
do {
|
||||
--gi;
|
||||
} while ((addr = garbage->p[gi].ret) == weakaddr("__gc"));
|
||||
} while ((addr = garbage->p[gi].ret) == _weakaddr("__gc"));
|
||||
}
|
||||
argv[i++] = buf + j;
|
||||
buf[j++] = '0';
|
||||
|
|
|
@ -63,10 +63,10 @@ noinstrument noasan int PrintBacktraceUsingSymbols(int fd,
|
|||
break;
|
||||
}
|
||||
addr = frame->addr;
|
||||
if (addr == weakaddr("__gc")) {
|
||||
if (addr == _weakaddr("__gc")) {
|
||||
do {
|
||||
--gi;
|
||||
} while ((addr = garbage->p[gi].ret) == weakaddr("__gc"));
|
||||
} while ((addr = garbage->p[gi].ret) == _weakaddr("__gc"));
|
||||
}
|
||||
/*
|
||||
* we subtract one to handle the case of noreturn functions with a
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
void __check_fail_aligned(unsigned bytes, uint64_t ptr, const char *file,
|
||||
int line, const char *fmt, ...) {
|
||||
fflush(stderr);
|
||||
if (!IsTiny()) memsummary(fileno(stderr));
|
||||
if (!IsTiny()) _memsummary(fileno(stderr));
|
||||
kprintf("%s:%d: error: pointer not %d-byte aligned: %p\n", file, line, bytes,
|
||||
ptr);
|
||||
__die();
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/intrin/safemacros.internal.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/strace.internal.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/intrin/kprintf.h"
|
||||
|
|
|
@ -16,8 +16,8 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/intrin/weaken.h"
|
||||
#include "libc/intrin/kprintf.h"
|
||||
#include "libc/intrin/weaken.h"
|
||||
#include "libc/log/internal.h"
|
||||
#include "libc/log/log.h"
|
||||
#include "libc/runtime/internal.h"
|
||||
|
@ -48,7 +48,6 @@ relegated wontreturn void __check_fail_ndebug(uint64_t want, uint64_t got,
|
|||
va_end(va);
|
||||
}
|
||||
kprintf("\n");
|
||||
if (weaken(__die)) weaken(__die)();
|
||||
__restorewintty();
|
||||
_Exit(68);
|
||||
if (_weaken(__die)) _weaken(__die)();
|
||||
_Exitr(68);
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
#define COSMOPOLITAN_LIBC_LOG_COUNTEXPR_H_
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/nexgen32e/bench.h"
|
||||
#include "libc/nexgen32e/bsr.h"
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
|
|
|
@ -17,9 +17,9 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/intrin/bsf.h"
|
||||
#include "libc/intrin/cxaatexit.internal.h"
|
||||
#include "libc/log/log.h"
|
||||
#include "libc/nexgen32e/bsf.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
|
||||
|
@ -42,10 +42,10 @@ void __cxa_printexits(FILE *f, void *pred) {
|
|||
do {
|
||||
mask = b->mask;
|
||||
while (mask) {
|
||||
i = bsf(mask);
|
||||
i = _bsf(mask);
|
||||
mask &= ~(1u << i);
|
||||
if (!pred || pred == b->p[i].pred) {
|
||||
symbol = __get_symbol_by_addr((intptr_t)b->p[i].fp);
|
||||
symbol = GetSymbolByAddr((intptr_t)b->p[i].fp);
|
||||
if (symbol) {
|
||||
snprintf(name, sizeof(name), "%s", symbol);
|
||||
} else {
|
||||
|
|
|
@ -45,12 +45,10 @@ relegated wontreturn void __die(void) {
|
|||
DebugBreak();
|
||||
}
|
||||
ShowBacktrace(2, __builtin_frame_address(0));
|
||||
__restorewintty();
|
||||
_Exit(77);
|
||||
_Exitr(77);
|
||||
} else if (owner == me) {
|
||||
kprintf("die failed while dying\n");
|
||||
__restorewintty();
|
||||
_Exit(78);
|
||||
_Exitr(78);
|
||||
} else {
|
||||
_Exit1(79);
|
||||
}
|
||||
|
|
|
@ -26,6 +26,6 @@
|
|||
const char *GetCallerName(const struct StackFrame *bp) {
|
||||
struct SymbolTable *st;
|
||||
if (!bp && (bp = __builtin_frame_address(0))) bp = bp->next;
|
||||
if (bp) return __get_symbol_by_addr(bp->addr);
|
||||
if (bp) return GetSymbolByAddr(bp->addr);
|
||||
return 0;
|
||||
}
|
||||
|
|
11
libc/log/getcallername.internal.h
Normal file
11
libc/log/getcallername.internal.h
Normal file
|
@ -0,0 +1,11 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_LOG_GETCALLERNAME_INTERNAL_H_
|
||||
#define COSMOPOLITAN_LIBC_LOG_GETCALLERNAME_INTERNAL_H_
|
||||
#include "libc/nexgen32e/stackframe.h"
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
const char *GetCallerName(const struct StackFrame *);
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_LOG_GETCALLERNAME_INTERNAL_H_ */
|
|
@ -23,7 +23,7 @@
|
|||
/**
|
||||
* Returns name of symbol at address.
|
||||
*/
|
||||
noasan char *__get_symbol_by_addr(int64_t addr) {
|
||||
noasan char *GetSymbolByAddr(int64_t addr) {
|
||||
/* asan runtime depends on this function */
|
||||
int i;
|
||||
struct SymbolTable *st;
|
||||
|
|
|
@ -16,19 +16,19 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/strace.internal.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/intrin/asan.internal.h"
|
||||
#include "libc/intrin/bits.h"
|
||||
#include "libc/intrin/kprintf.h"
|
||||
#include "libc/intrin/lockcmpxchg.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/runtime/internal.h"
|
||||
#include "libc/runtime/memtrack.internal.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
|
||||
STATIC_YOINK("__get_symbol_by_addr");
|
||||
STATIC_YOINK("GetSymbolByAddr");
|
||||
|
||||
#define MAXLEAKS 1000
|
||||
|
||||
|
@ -115,7 +115,6 @@ noasan void CheckForMemoryLeaks(void) {
|
|||
/* __print_maps(); */
|
||||
/* PrintSystemMappings(2); */
|
||||
/* PrintGarbage(); */
|
||||
__restorewintty();
|
||||
_Exit(78);
|
||||
_Exitr(78);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,8 +10,6 @@ COSMOPOLITAN_C_START_
|
|||
|
||||
#define __ToUpper(c) ((c) >= 'a' && (c) <= 'z' ? (c) - 'a' + 'A' : (c))
|
||||
|
||||
extern char __fatalbuf[];
|
||||
|
||||
forceinline long __sysv_exit(long rc) {
|
||||
long ax;
|
||||
#if defined(__MNO_RED_ZONE__) && defined(__GNUC__) && !defined(__STRICT_ANSI__)
|
||||
|
|
123
libc/log/log.h
123
libc/log/log.h
|
@ -1,13 +1,5 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_LOG_LOG_H_
|
||||
#define COSMOPOLITAN_LIBC_LOG_LOG_H_
|
||||
#include "libc/calls/struct/rusage.h"
|
||||
#include "libc/calls/struct/sigset.h"
|
||||
#include "libc/calls/struct/winsize.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/intrin/likely.h"
|
||||
#include "libc/nexgen32e/stackframe.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
|
||||
#define kLogFatal 0
|
||||
|
@ -31,6 +23,12 @@
|
|||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef TINY
|
||||
#define _LOG_TINY 1
|
||||
#else
|
||||
#define _LOG_TINY 0
|
||||
#endif
|
||||
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
|
@ -38,31 +36,25 @@ extern FILE *__log_file;
|
|||
|
||||
int __watch(void *, size_t);
|
||||
void __die(void) relegated wontreturn; /* print backtrace and abort() */
|
||||
void meminfo(int); /* shows malloc statistics &c. */
|
||||
void memsummary(int); /* light version of same thing */
|
||||
uint16_t getttycols(uint16_t);
|
||||
int getttysize(int, struct winsize *) paramsnonnull();
|
||||
void _meminfo(int); /* shows malloc statistics &c. */
|
||||
void _memsummary(int); /* light version of same thing */
|
||||
bool IsTerminalInarticulate(void) nosideeffect;
|
||||
const char *commandvenv(const char *, const char *);
|
||||
const char *GetAddr2linePath(void);
|
||||
const char *GetGdbPath(void);
|
||||
const char *GetCallerName(const struct StackFrame *);
|
||||
|
||||
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 *);
|
||||
char *__get_symbol_by_addr(int64_t);
|
||||
char *GetSymbolByAddr(int64_t);
|
||||
void PrintGarbage(void);
|
||||
void PrintGarbageNumeric(FILE *);
|
||||
void CheckForMemoryLeaks(void);
|
||||
|
||||
#define showcrashreports() ShowCrashReports()
|
||||
|
||||
#ifndef __STRICT_ANSI__
|
||||
|
||||
#define _LOG_UNLIKELY(x) __builtin_expect(!!(x), 0)
|
||||
|
||||
extern unsigned __log_level; /* log level for runtime check */
|
||||
|
||||
#define LOGGABLE(LEVEL) \
|
||||
|
@ -72,24 +64,22 @@ extern unsigned __log_level; /* log level for runtime check */
|
|||
// log a message with the specified log level (not checking if LOGGABLE)
|
||||
#define LOGF(LEVEL, FMT, ...) \
|
||||
do { \
|
||||
if (!IsTiny()) --__ftrace; \
|
||||
if (!_LOG_TINY) _log_untrace(); \
|
||||
flogf(LEVEL, __FILE__, __LINE__, NULL, FMT, ##__VA_ARGS__); \
|
||||
if (!IsTiny()) ++__ftrace; \
|
||||
if (!_LOG_TINY) _log_retrace(); \
|
||||
} while (0)
|
||||
|
||||
// report an error without backtrace and debugger invocation
|
||||
#define FATALF(FMT, ...) \
|
||||
do { \
|
||||
if (!IsTiny()) --__ftrace; \
|
||||
if (!_LOG_TINY) _log_untrace(); \
|
||||
flogf(kLogError, __FILE__, __LINE__, NULL, FMT, ##__VA_ARGS__); \
|
||||
__restorewintty(); \
|
||||
_Exit(1); \
|
||||
unreachable; \
|
||||
_log_exit(1); \
|
||||
} while (0)
|
||||
|
||||
#define DIEF(FMT, ...) \
|
||||
do { \
|
||||
if (!IsTiny()) --__ftrace; \
|
||||
if (!_LOG_TINY) _log_untrace(); \
|
||||
ffatalf(kLogFatal, __FILE__, __LINE__, NULL, FMT, ##__VA_ARGS__); \
|
||||
unreachable; \
|
||||
} while (0)
|
||||
|
@ -118,102 +108,105 @@ extern unsigned __log_level; /* log level for runtime check */
|
|||
#define VERBOSEF(FMT, ...) \
|
||||
do { \
|
||||
if (LOGGABLE(kLogVerbose)) { \
|
||||
if (!IsTiny()) --__ftrace; \
|
||||
if (!_LOG_TINY) _log_untrace(); \
|
||||
fverbosef(kLogVerbose, __FILE__, __LINE__, NULL, FMT, ##__VA_ARGS__); \
|
||||
if (!IsTiny()) ++__ftrace; \
|
||||
if (!_LOG_TINY) _log_retrace(); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define DEBUGF(FMT, ...) \
|
||||
do { \
|
||||
if (UNLIKELY(LOGGABLE(kLogDebug))) { \
|
||||
if (!IsTiny()) --__ftrace; \
|
||||
if (_LOG_UNLIKELY(LOGGABLE(kLogDebug))) { \
|
||||
if (!_LOG_TINY) _log_untrace(); \
|
||||
fdebugf(kLogDebug, __FILE__, __LINE__, NULL, FMT, ##__VA_ARGS__); \
|
||||
if (!IsTiny()) ++__ftrace; \
|
||||
if (!_LOG_TINY) _log_retrace(); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define NOISEF(FMT, ...) \
|
||||
do { \
|
||||
if (UNLIKELY(LOGGABLE(kLogNoise))) { \
|
||||
if (!IsTiny()) --__ftrace; \
|
||||
if (_LOG_UNLIKELY(LOGGABLE(kLogNoise))) { \
|
||||
if (!_LOG_TINY) _log_untrace(); \
|
||||
fnoisef(kLogNoise, __FILE__, __LINE__, NULL, FMT, ##__VA_ARGS__); \
|
||||
if (!IsTiny()) ++__ftrace; \
|
||||
if (!_LOG_TINY) _log_retrace(); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define FLOGF(F, FMT, ...) \
|
||||
do { \
|
||||
if (LOGGABLE(kLogInfo)) { \
|
||||
if (!IsTiny()) --__ftrace; \
|
||||
if (!_LOG_TINY) _log_untrace(); \
|
||||
flogf(kLogInfo, __FILE__, __LINE__, F, FMT, ##__VA_ARGS__); \
|
||||
if (!IsTiny()) ++__ftrace; \
|
||||
if (!_LOG_TINY) _log_retrace(); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define FWARNF(F, FMT, ...) \
|
||||
do { \
|
||||
if (LOGGABLE(kLogWarn)) { \
|
||||
if (!IsTiny()) --__ftrace; \
|
||||
if (!_LOG_TINY) _log_untrace(); \
|
||||
flogf(kLogWarn, __FILE__, __LINE__, F, FMT, ##__VA_ARGS__); \
|
||||
if (!IsTiny()) ++__ftrace; \
|
||||
if (!_LOG_TINY) _log_retrace(); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define FFATALF(F, FMT, ...) \
|
||||
do { \
|
||||
if (!IsTiny()) --__ftrace; \
|
||||
if (!_LOG_TINY) _log_untrace(); \
|
||||
flogf(kLogError, __FILE__, __LINE__, F, FMT, ##__VA_ARGS__); \
|
||||
__restorewintty(); \
|
||||
_Exit(1); \
|
||||
unreachable; \
|
||||
_log_exit(1); \
|
||||
} while (0)
|
||||
|
||||
#define FDEBUGF(F, FMT, ...) \
|
||||
do { \
|
||||
if (UNLIKELY(LOGGABLE(kLogDebug))) { \
|
||||
if (!IsTiny()) --__ftrace; \
|
||||
if (_LOG_UNLIKELY(LOGGABLE(kLogDebug))) { \
|
||||
if (!_LOG_TINY) _log_untrace(); \
|
||||
fdebugf(kLogDebug, __FILE__, __LINE__, F, FMT, ##__VA_ARGS__); \
|
||||
if (!IsTiny()) ++__ftrace; \
|
||||
if (!_LOG_TINY) _log_retrace(); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define FNOISEF(F, FMT, ...) \
|
||||
do { \
|
||||
if (UNLIKELY(LOGGABLE(kLogNoise))) { \
|
||||
if (!IsTiny()) --__ftrace; \
|
||||
if (_LOG_UNLIKELY(LOGGABLE(kLogNoise))) { \
|
||||
if (!_LOG_TINY) _log_untrace(); \
|
||||
fnoisef(kLogNoise, __FILE__, __LINE__, F, FMT, ##__VA_ARGS__); \
|
||||
if (!IsTiny()) ++__ftrace; \
|
||||
if (!_LOG_TINY) _log_retrace(); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define LOGIFNEG1(FORM) \
|
||||
({ \
|
||||
int e = errno; \
|
||||
autotype(FORM) Ax = (FORM); \
|
||||
if (UNLIKELY(Ax == (typeof(Ax))(-1)) && LOGGABLE(kLogWarn)) { \
|
||||
if (!IsTiny()) --__ftrace; \
|
||||
__logerrno(__FILE__, __LINE__, #FORM); \
|
||||
if (!IsTiny()) ++__ftrace; \
|
||||
errno = e; \
|
||||
} \
|
||||
Ax; \
|
||||
#define LOGIFNEG1(FORM) \
|
||||
({ \
|
||||
int e = _log_get_errno(); \
|
||||
autotype(FORM) Ax = (FORM); \
|
||||
if (_LOG_UNLIKELY(Ax == (typeof(Ax))(-1)) && LOGGABLE(kLogWarn)) { \
|
||||
if (!_LOG_TINY) _log_untrace(); \
|
||||
_log_errno(__FILE__, __LINE__, #FORM); \
|
||||
if (!_LOG_TINY) _log_retrace(); \
|
||||
_log_set_errno(e); \
|
||||
} \
|
||||
Ax; \
|
||||
})
|
||||
|
||||
#define LOGIFNULL(FORM) \
|
||||
({ \
|
||||
int e = errno; \
|
||||
int e = _log_get_errno(); \
|
||||
autotype(FORM) Ax = (FORM); \
|
||||
if (Ax == NULL && LOGGABLE(kLogWarn)) { \
|
||||
if (!IsTiny()) --__ftrace; \
|
||||
__logerrno(__FILE__, __LINE__, #FORM); \
|
||||
if (!IsTiny()) ++__ftrace; \
|
||||
errno = e; \
|
||||
if (!_LOG_TINY) _log_untrace(); \
|
||||
_log_errno(__FILE__, __LINE__, #FORM); \
|
||||
if (!_LOG_TINY) _log_retrace(); \
|
||||
_log_set_errno(e); \
|
||||
} \
|
||||
Ax; \
|
||||
})
|
||||
|
||||
void __logerrno(const char *, int, const char *) relegated;
|
||||
void _log_errno(const char *, int, const char *) relegated;
|
||||
int _log_get_errno(void);
|
||||
void _log_set_errno(int);
|
||||
void _log_untrace(void);
|
||||
void _log_retrace(void);
|
||||
void _log_exit(int) wontreturn;
|
||||
|
||||
#define ARGS unsigned, const char *, int, FILE *, const char *
|
||||
#define ATTR paramsnonnull((5)) printfesque(5)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*-*- 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 2020 Justine Alexandra Roberts Tunney │
|
||||
│ 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 │
|
||||
|
@ -17,23 +17,8 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/log/log.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/termios.h"
|
||||
#include "libc/sysv/consts/fileno.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
|
||||
/**
|
||||
* Shorthand for getting ws_col from getttysize().
|
||||
*
|
||||
* It is recommended that programs err on the side of showing more
|
||||
* information, if this value can't be obtained with certainty.
|
||||
*
|
||||
* @return terminal width or defaultcols on error
|
||||
*/
|
||||
uint16_t getttycols(uint16_t defaultcols) {
|
||||
struct winsize wsize;
|
||||
if (getttysize(STDIN_FILENO, &wsize) != -1) {
|
||||
return wsize.ws_col;
|
||||
} else {
|
||||
return defaultcols;
|
||||
}
|
||||
privileged wontreturn void _log_exit(int exitcode) {
|
||||
_Exitr(exitcode);
|
||||
}
|
24
libc/log/log_get_errno.c
Normal file
24
libc/log/log_get_errno.c
Normal file
|
@ -0,0 +1,24 @@
|
|||
/*-*- 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 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/errno.h"
|
||||
#include "libc/log/log.h"
|
||||
|
||||
noinstrument int _log_get_errno(void) {
|
||||
return errno;
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
/*-*- 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 2020 Justine Alexandra Roberts Tunney │
|
||||
│ 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 │
|
||||
|
@ -16,50 +16,9 @@
|
|||
│ 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/sigaction.h"
|
||||
#include "libc/calls/struct/siginfo.h"
|
||||
#include "libc/calls/ucontext.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/intrin/bits.h"
|
||||
#include "libc/log/log.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/consts/sa.h"
|
||||
#include "libc/sysv/consts/sig.h"
|
||||
|
||||
/**
|
||||
* @fileoverview Default handlers for normal termination signals.
|
||||
* @note This gets linked when __cxa_atexit() is linked.
|
||||
* @see also libc/oncrash.c
|
||||
*/
|
||||
|
||||
static const int sigs[] = {
|
||||
SIGHUP, /* hangup aka ctrl_close_event */
|
||||
SIGINT, /* ctrl+c aka ^C aka ETX aka \003 aka ♥ */
|
||||
SIGTERM /* kill (default signal) */
|
||||
};
|
||||
|
||||
textexit static void __onkill(int sig, struct siginfo *si, void *context) {
|
||||
/* https://www.tldp.org/LDP/abs/html/exitcodes.html */
|
||||
exit(128 + sig);
|
||||
unreachable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Installs default handlers for friendly kill signals.
|
||||
* @see ShowCrashReports()
|
||||
*/
|
||||
void callexitontermination(sigset_t *opt_out_exitsigs) {
|
||||
struct sigaction sa;
|
||||
if (opt_out_exitsigs) sigemptyset(opt_out_exitsigs);
|
||||
bzero(&sa, sizeof(sa));
|
||||
sa.sa_sigaction = __onkill;
|
||||
sa.sa_flags = SA_RESETHAND;
|
||||
for (unsigned i = 0; i < ARRAYLEN(sigs); ++i) {
|
||||
if (!sigs[i]) continue;
|
||||
if (opt_out_exitsigs) sigaddset(opt_out_exitsigs, sigs[i]);
|
||||
sigaction(sigs[i], &sa, NULL);
|
||||
}
|
||||
noinstrument void _log_retrace(void) {
|
||||
++__ftrace;
|
||||
}
|
24
libc/log/log_set_errno.c
Normal file
24
libc/log/log_set_errno.c
Normal file
|
@ -0,0 +1,24 @@
|
|||
/*-*- 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 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/errno.h"
|
||||
#include "libc/log/log.h"
|
||||
|
||||
noinstrument void _log_set_errno(int e) {
|
||||
errno = e;
|
||||
}
|
24
libc/log/log_untrace.c
Normal file
24
libc/log/log_untrace.c
Normal file
|
@ -0,0 +1,24 @@
|
|||
/*-*- 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 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/log/log.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
|
||||
noinstrument void _log_untrace(void) {
|
||||
--__ftrace;
|
||||
}
|
|
@ -22,6 +22,6 @@
|
|||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
void __logerrno(const char *file, int line, const char *form) {
|
||||
noinstrument void _log_errno(const char *file, int line, const char *form) {
|
||||
flogf(kLogWarn, file, line, NULL, PFLINK("%s → %s"), form, strerror(errno));
|
||||
}
|
||||
|
|
|
@ -30,8 +30,8 @@ static void onmemchunk(void *start, void *end, size_t used_bytes, void *arg) {
|
|||
/**
|
||||
* Prints memory mappings.
|
||||
*/
|
||||
void meminfo(int fd) {
|
||||
memsummary(fd);
|
||||
void _meminfo(int fd) {
|
||||
_memsummary(fd);
|
||||
(dprintf)(fd, "%*s %*s %*s %*s\n", POINTER_XDIGITS, "start",
|
||||
POINTER_XDIGITS, "end", 8, "used", 8, "size");
|
||||
malloc_inspect_all(onmemchunk, &fd);
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/assert.h"
|
||||
#include "libc/intrin/atomic.h"
|
||||
#include "libc/intrin/weaken.h"
|
||||
#include "libc/intrin/kprintf.h"
|
||||
#include "libc/log/backtrace.internal.h"
|
||||
#include "libc/log/log.h"
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
#include "libc/log/log.h"
|
||||
#include "libc/mem/mem.h"
|
||||
|
||||
void memsummary(int fd) {
|
||||
void _memsummary(int fd) {
|
||||
struct mallinfo mi;
|
||||
mi = mallinfo();
|
||||
(dprintf)(fd,
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/state.internal.h"
|
||||
#include "libc/calls/strace.internal.h"
|
||||
#include "libc/calls/struct/sigaction.h"
|
||||
#include "libc/calls/struct/utsname.h"
|
||||
#include "libc/calls/syscall-sysv.internal.h"
|
||||
|
@ -28,6 +27,7 @@
|
|||
#include "libc/intrin/kprintf.h"
|
||||
#include "libc/intrin/lockcmpxchg.h"
|
||||
#include "libc/intrin/lockcmpxchgp.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
#include "libc/intrin/weaken.h"
|
||||
#include "libc/log/backtrace.internal.h"
|
||||
#include "libc/log/gdb.h"
|
||||
|
@ -35,11 +35,11 @@
|
|||
#include "libc/log/log.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/nexgen32e/stackframe.h"
|
||||
#include "libc/thread/tls.h"
|
||||
#include "libc/runtime/internal.h"
|
||||
#include "libc/runtime/pc.internal.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/thread/tls.h"
|
||||
|
||||
/**
|
||||
* @fileoverview Abnormal termination handling & GUI debugging.
|
||||
|
@ -199,7 +199,7 @@ relegated void ShowCrashReport(int err, int sig, struct siginfo *si,
|
|||
char host[64];
|
||||
struct utsname names;
|
||||
static char buf[4096];
|
||||
if (weaken(ShowCrashReportHook)) {
|
||||
if (_weaken(ShowCrashReportHook)) {
|
||||
ShowCrashReportHook(2, err, sig, si, ctx);
|
||||
}
|
||||
names.sysname[0] = 0;
|
||||
|
@ -258,8 +258,7 @@ static wontreturn relegated noinstrument void __minicrash(int sig,
|
|||
kind, sig, __argv[0], ctx ? ctx->uc_mcontext.rip : 0,
|
||||
ctx ? ctx->uc_mcontext.rsp : 0, ctx ? ctx->uc_mcontext.rbp : 0, __pid,
|
||||
sys_gettid());
|
||||
__restorewintty();
|
||||
_Exit(119);
|
||||
_Exitr(119);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -309,8 +308,7 @@ relegated void __oncrash(int sig, struct siginfo *si, ucontext_t *ctx) {
|
|||
if (!(gdbpid > 0 && (sig == SIGTRAP || sig == SIGQUIT))) {
|
||||
__restore_tty();
|
||||
ShowCrashReport(err, sig, si, ctx);
|
||||
__restorewintty();
|
||||
_Exit(128 + sig);
|
||||
_Exitr(128 + sig);
|
||||
}
|
||||
sync = 0;
|
||||
} else {
|
||||
|
|
|
@ -38,7 +38,7 @@ void PrintGarbage(void) {
|
|||
kprintf("------------ ------------ ------------------ ------------------ ------------------\n");
|
||||
if ((g = __tls_enabled ? __get_tls()->tib_garbages:0) && g->i) {
|
||||
for (i = g->i; i--;) {
|
||||
symbol = __get_symbol_by_addr(g->p[i].ret);
|
||||
symbol = GetSymbolByAddr(g->p[i].ret);
|
||||
if (symbol) {
|
||||
ksnprintf(name, sizeof(name), "%s", symbol);
|
||||
} else {
|
||||
|
@ -48,7 +48,7 @@ void PrintGarbage(void) {
|
|||
g->p + i,
|
||||
g->p[i].frame,
|
||||
name,
|
||||
__get_symbol_by_addr(g->p[i].fn),
|
||||
GetSymbolByAddr(g->p[i].fn),
|
||||
g->p[i].arg);
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -37,7 +37,7 @@ STATIC_YOINK("ShowBacktrace"); // for backtracing
|
|||
STATIC_YOINK("GetSymbolTable"); // for backtracing
|
||||
STATIC_YOINK("PrintBacktraceUsingSymbols"); // for backtracing
|
||||
STATIC_YOINK("malloc_inspect_all"); // for asan memory origin
|
||||
STATIC_YOINK("__get_symbol_by_addr"); // for asan memory origin
|
||||
STATIC_YOINK("GetSymbolByAddr"); // for asan memory origin
|
||||
|
||||
extern const unsigned char __oncrash_thunks[8][11];
|
||||
static struct sigaltstack g_oldsigaltstack;
|
||||
|
@ -99,8 +99,6 @@ static void FreeSigAltStack(void *p) {
|
|||
* Another trick this function enables, is you can press CTRL+\ to open
|
||||
* the debugger GUI at any point while the program is running. It can be
|
||||
* useful, for example, if a program is caught in an infinite loop.
|
||||
*
|
||||
* @see callexitontermination()
|
||||
*/
|
||||
void ShowCrashReports(void) {
|
||||
char *sp;
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/dprintf.h"
|
||||
#include "libc/calls/strace.internal.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
#include "libc/calls/struct/stat.h"
|
||||
#include "libc/calls/struct/timeval.h"
|
||||
#include "libc/dce.h"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue