diff options
| author | Thomas Ulmer <thomasmulmer02@gmail.com> | 2026-03-02 19:39:44 -0800 |
|---|---|---|
| committer | Thomas Ulmer <thomasmulmer02@gmail.com> | 2026-03-02 19:39:44 -0800 |
| commit | 54de1d6ca94bc0f7ffac6ad721933caf4db46ed5 (patch) | |
| tree | f4b73f06509db5ad9312fe6095b91a10f38e1f33 /brk_shim.c | |
| parent | af7a7377241af78c70c7badf8ddfc79e55325899 (diff) | |
changes to compile with musl (avoid sbrk)
Diffstat (limited to 'brk_shim.c')
| -rw-r--r-- | brk_shim.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/brk_shim.c b/brk_shim.c new file mode 100644 index 0000000..1680a18 --- /dev/null +++ b/brk_shim.c @@ -0,0 +1,44 @@ +#include "brk_shim.h" + +#include <errno.h> + +/* + * The idea is to just allocate a large buffer and rely on lazy page + * loading to not use more physical memory than necessary. + */ + +#ifdef LARGEF +#define SHIMSIZE 0x4000000 +/* 64MB */ +#else +#define SHIMSIZE 0x200000 +/* 2MB */ +#endif + +static char shim_space[SHIMSIZE]; +static intptr_t shim_size = 0; + +void *shim_sbrk(intptr_t increment) { + void* current = (void*)(shim_space + shim_size); + shim_size += increment; + if (shim_size < 0) { + shim_size = 0; + return (void*)-1; + } else if (shim_size > SHIMSIZE) { + shim_size = SHIMSIZE; + return (void*)-1; + } + return current; +} + +int shim_brk(void* addr) { + if (addr < (void*)shim_space || + addr > (void*)(shim_space + SHIMSIZE)) { + errno = EINVAL; + return -1; + } + shim_size = ((void*)shim_space) - addr; + return 0; +} + + |
