move declaration of interfaces between malloc and ldso to dynlink.h
[oweals/musl.git] / src / internal / 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 hidden void *__memalign(size_t, size_t);
10
11 struct chunk {
12         size_t psize, csize;
13         struct chunk *next, *prev;
14 };
15
16 struct bin {
17         volatile int lock[2];
18         struct chunk *head;
19         struct chunk *tail;
20 };
21
22 #define SIZE_ALIGN (4*sizeof(size_t))
23 #define SIZE_MASK (-SIZE_ALIGN)
24 #define OVERHEAD (2*sizeof(size_t))
25 #define MMAP_THRESHOLD (0x1c00*SIZE_ALIGN)
26 #define DONTCARE 16
27 #define RECLAIM 163840
28
29 #define CHUNK_SIZE(c) ((c)->csize & -2)
30 #define CHUNK_PSIZE(c) ((c)->psize & -2)
31 #define PREV_CHUNK(c) ((struct chunk *)((char *)(c) - CHUNK_PSIZE(c)))
32 #define NEXT_CHUNK(c) ((struct chunk *)((char *)(c) + CHUNK_SIZE(c)))
33 #define MEM_TO_CHUNK(p) (struct chunk *)((char *)(p) - OVERHEAD)
34 #define CHUNK_TO_MEM(c) (void *)((char *)(c) + OVERHEAD)
35 #define BIN_TO_CHUNK(i) (MEM_TO_CHUNK(&mal.bins[i].head))
36
37 #define C_INUSE  ((size_t)1)
38
39 #define IS_MMAPPED(c) !((c)->csize & (C_INUSE))
40
41 hidden void __bin_chunk(struct chunk *);
42
43 #endif