1/* 2 * malloc.h 3 * 4 * Internals for the memory allocator 5 */ 6 7#include <stdint.h> 8#include <stddef.h> 9 10/* 11 * This is the minimum chunk size we will ask the kernel for; this should 12 * be a multiple of the page size on all architectures. 13 */ 14#define MALLOC_CHUNK_SIZE 65536 15#define MALLOC_CHUNK_MASK (MALLOC_CHUNK_SIZE-1) 16 17/* 18 * This structure should be a power of two. This becomes the 19 * alignment unit. 20 */ 21struct free_arena_header; 22 23struct arena_header { 24 size_t type; 25 size_t size; /* Also gives the location of the next entry */ 26 struct free_arena_header *next, *prev; 27}; 28 29#ifdef DEBUG_MALLOC 30#define ARENA_TYPE_USED 0x64e69c70 31#define ARENA_TYPE_FREE 0x012d610a 32#define ARENA_TYPE_HEAD 0x971676b5 33#define ARENA_TYPE_DEAD 0xeeeeeeee 34#else 35#define ARENA_TYPE_USED 0 36#define ARENA_TYPE_FREE 1 37#define ARENA_TYPE_HEAD 2 38#endif 39 40#define ARENA_SIZE_MASK (~(uintptr_t)(sizeof(struct arena_header)-1)) 41 42#define ARENA_ALIGN_UP(p) ((char *)(((uintptr_t)(p) + ~ARENA_SIZE_MASK) & ARENA_SIZE_MASK)) 43#define ARENA_ALIGN_DOWN(p) ((char *)((uintptr_t)(p) & ARENA_SIZE_MASK)) 44 45/* 46 * This structure should be no more than twice the size of the 47 * previous structure. 48 */ 49struct free_arena_header { 50 struct arena_header a; 51 struct free_arena_header *next_free, *prev_free; 52}; 53 54extern struct free_arena_header __malloc_head; 55void __inject_free_block(struct free_arena_header *ah); 56

