2 #include "tests/sys_mman.h"
8 #define SUPERBLOCK_SIZE 100000
10 //-------------------------------------------------------------------------
12 //-------------------------------------------------------------------------
14 void* get_superblock(void)
16 void* p = mmap( 0, SUPERBLOCK_SIZE, PROT_READ|PROT_WRITE|PROT_EXEC,
17 MAP_PRIVATE|MAP_ANONYMOUS, -1, 0 );
19 assert(p != ((void*)(-1)));
25 static void* custom_alloc(int size)
28 static void* hp = 0; // current heap pointer
29 static void* hp_lim = 0; // maximum usable byte in current block
30 int size2 = size + RZ*2;
33 if (hp + size2 > hp_lim) {
34 hp = get_superblock();
35 hp_lim = hp + SUPERBLOCK_SIZE - 1;
41 VALGRIND_MALLOCLIKE_BLOCK( p, size, RZ, /*is_zeroed*/1 );
45 static void custom_free(void* p)
47 // don't actually free any memory... but mark it as freed
48 VALGRIND_FREELIKE_BLOCK( p, RZ );
54 //-------------------------------------------------------------------------
56 //-------------------------------------------------------------------------
60 int* a = custom_alloc(400); // All sizes are divisible by 16 -- no slop.
63 a = custom_alloc(800);