Improve crash backtrace reliability

We're now able to pretty print a C++ backtrace upon crashing in pretty
much any runtime execution scenario. The default pledge sandbox policy
on Linux is now to return EPERM. If you call pledge and have debugging
functions linked (e.g. GetSymbolTable) then the symbol table shall get
loaded before any security policy is put in place. This change updates
build/bootstrap/fixupobj too and fixes some other sneaky build errors.
This commit is contained in:
Justine Tunney 2024-05-07 17:36:17 -07:00
parent 7d31fc311a
commit 19c81863a3
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
17 changed files with 103 additions and 64 deletions

View file

@ -19,10 +19,18 @@
#include "libc/stdckdint.h"
#include "libc/str/str.h"
#ifndef TINYMALLOC_MAX_BYTES
#define TINYMALLOC_MAX_BYTES 1073741824
#endif
#ifndef TINYMALLOC_MAX_ALIGN
#define TINYMALLOC_MAX_ALIGN 4096
#endif
#ifndef MODE_DBG /* don't interfere with asan dlmalloc hooking */
_Alignas(65536) static struct {
char memory[1024 * 1024 * 1024];
_Alignas(TINYMALLOC_MAX_ALIGN) static struct {
char memory[TINYMALLOC_MAX_BYTES];
unsigned used, last, free;
} heap;
@ -59,7 +67,7 @@ void *memalign(size_t align, size_t need) {
need = sizeof(unsigned);
if (align < sizeof(unsigned))
align = sizeof(unsigned);
if (align > 65536)
if (align > TINYMALLOC_MAX_ALIGN)
goto InvalidArgument;
if (ckd_add(&need, need, sizeof(unsigned) - 1))
goto OutOfMemory;
@ -86,7 +94,7 @@ void *memalign(size_t align, size_t need) {
base &= -align;
if (ckd_add(&toto, base, need))
goto OutOfMemory;
if (toto > sizeof(heap.memory))
if (toto > TINYMALLOC_MAX_BYTES)
goto OutOfMemory;
res = heap.memory + base;
((unsigned *)res)[-1] = need;
@ -139,7 +147,7 @@ void *realloc(void *ptr, size_t need) {
need &= -sizeof(unsigned);
if (ckd_add(&toto, base, need))
goto OutOfMemory;
if (toto > sizeof(heap.memory))
if (toto > TINYMALLOC_MAX_BYTES)
goto OutOfMemory;
((unsigned *)mem)[-1] = need;
heap.used = toto;