// We only use a custom allocator on linux (for now) // The allocator we chose is 'dlmalloc' (doug lea's malloc). // It's a good allocator for single-threaded programs. // It needs to be configured by setting a bunch of defines. // #ifdef __linux__ // We need this to define dlmalloc, not malloc. #define USE_DL_PREFIX 1 // We don't need mspaces. #define ONLY_MSPACES 0 #define MSPACES 0 // We don't need mallinfo #define NO_MALLINFO 1 // We don't need dlmalloc_inspect_all #define MALLOC_INSPECT_ALL 0 // We don't need dlmalloc_stats. #define NO_MALLOC_STATS 1 // Disable locking. The entire engine is single-threaded. #define USE_LOCKS 0 // For now, we'll let the allocator use mmap to get memory. // It's not clear if this is going to be deterministic. #define HAVE_MMAP 1 // One way to force determinism would be to emulate sbrk // using mmap and mremap, always putting the heap at a fixed // address. For now, we're not doing that, we're just // using mmap and relying on that being deterministic (we hope). #define HAVE_MORECORE 0 #define MORECORE emulate_sbrk // The properties of mmap under linux #define MMAP_CLEARS 1 #define HAVE_MREMAP 1 // Don't generate random seeds, or time-based seeds. #define USE_DEV_RANDOM 0 #define LACKS_TIME_H 1 #include "dlmalloc/dlmalloc.c" #endif int dlmalloc_hash() { void *blocks[15]; int hash = 0; for (int i = 0; i < 15; i++) { void *blk = dlmalloc(1 << i); blocks[i] = blk; hash = (hash * 17) + (int)(intptr_t)(blk); } for (int i = 0; i < 15; i++) { free(blocks[i]); } return (hash & 0x7FFFFFFF) | (0x40000000); }