1 #ifndef MALLOC_IMPL_H 2 #define MALLOC_IMPL_H 3 4 #include <sys/mman.h> 5 #include "dynlink.h" 6 7 struct chunk { 8 size_t psize, csize; 9 struct chunk *next, *prev; 10 }; 11 12 struct bin { 13 volatile int lock[2]; 14 struct chunk *head; 15 struct chunk *tail; 16 }; 17 18 #define SIZE_ALIGN (4*sizeof(size_t)) 19 #define SIZE_MASK (-SIZE_ALIGN) 20 #define OVERHEAD (2*sizeof(size_t)) 21 #define MMAP_THRESHOLD (0x1c00*SIZE_ALIGN) 22 #define DONTCARE 16 23 #define RECLAIM 163840 24 25 #define CHUNK_SIZE(c) ((c)->csize & -2) 26 #define CHUNK_PSIZE(c) ((c)->psize & -2) 27 #define PREV_CHUNK(c) ((struct chunk *)((char *)(c) - CHUNK_PSIZE(c))) 28 #define NEXT_CHUNK(c) ((struct chunk *)((char *)(c) + CHUNK_SIZE(c))) 29 #define MEM_TO_CHUNK(p) (struct chunk *)((char *)(p) - OVERHEAD) 30 #define CHUNK_TO_MEM(c) (void *)((char *)(c) + OVERHEAD) 31 #define BIN_TO_CHUNK(i) (MEM_TO_CHUNK(&mal.bins[i].head)) 32 33 #define C_INUSE ((size_t)1) 34 35 #define IS_MMAPPED(c) !((c)->csize & (C_INUSE)) 36 37 hidden void __bin_chunk(struct chunk *); 38 39 #endif 40