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