diff options
| author | Thomas Ulmer <thomasmulmer02@gmail.com> | 2026-06-23 21:49:31 -0700 |
|---|---|---|
| committer | Thomas Ulmer <thomasmulmer02@gmail.com> | 2026-06-23 21:49:31 -0700 |
| commit | 23e0502dcc958cea4d195eb8c8a28a5c362ab69f (patch) | |
| tree | a758ea1c4a6e524b45fb108afa4ebaab7c1db36e /brk_shim.c | |
| parent | 874d317334fae1ddce316f9b6f4d0ce4e434bf52 (diff) | |
| parent | 9855bed0869ace4665e2776ec4d489847a0781b4 (diff) | |
combine sbrk spoof with heirloom fix for line numbers
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; +} + + |
