From 54de1d6ca94bc0f7ffac6ad721933caf4db46ed5 Mon Sep 17 00:00:00 2001 From: Thomas Ulmer Date: Mon, 2 Mar 2026 19:39:44 -0800 Subject: changes to compile with musl (avoid sbrk) --- brk_shim.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 brk_shim.c (limited to 'brk_shim.c') 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 + +/* + * 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; +} + + -- cgit v1.2.3