#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; }