summaryrefslogtreecommitdiff
path: root/src/malloc/oldmalloc/malloc_impl.h
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2020-06-03 19:22:12 -0400
committerRich Felker <dalias@aerifal.cx>2020-06-03 19:23:02 -0400
commit384c0131ccda2656dec23a0416ad3f14101151a7 (patch)
tree0561f403dafc58c8e29de0f0105fc9d69e095550 /src/malloc/oldmalloc/malloc_impl.h
parenteaa0f2496700c238e7e3c112d36445f3aee06ff1 (diff)
downloadmusl-384c0131ccda2656dec23a0416ad3f14101151a7.tar.gz
move oldmalloc to its own directory under src/malloc
this sets the stage for replacement, and makes it practical to keep oldmalloc around as a build option for a while if that ends up being useful. only the files which are actually part of the implementation are moved. memalign and posix_memalign are entirely generic. in theory calloc could be pulled out too, but it's useful to have it tied to the implementation so as to optimize out unnecessary memset when implementation details make it possible to know the memory is already clear.
Diffstat (limited to 'src/malloc/oldmalloc/malloc_impl.h')
-rw-r--r--src/malloc/oldmalloc/malloc_impl.h39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/malloc/oldmalloc/malloc_impl.h b/src/malloc/oldmalloc/malloc_impl.h
new file mode 100644
index 00000000..e1cf4774
--- /dev/null
+++ b/src/malloc/oldmalloc/malloc_impl.h
@@ -0,0 +1,39 @@
+#ifndef MALLOC_IMPL_H
+#define MALLOC_IMPL_H
+
+#include <sys/mman.h>
+#include "dynlink.h"
+
+struct chunk {
+ size_t psize, csize;
+ struct chunk *next, *prev;
+};
+
+struct bin {
+ volatile int lock[2];
+ struct chunk *head;
+ struct chunk *tail;
+};
+
+#define SIZE_ALIGN (4*sizeof(size_t))
+#define SIZE_MASK (-SIZE_ALIGN)
+#define OVERHEAD (2*sizeof(size_t))
+#define MMAP_THRESHOLD (0x1c00*SIZE_ALIGN)
+#define DONTCARE 16
+#define RECLAIM 163840
+
+#define CHUNK_SIZE(c) ((c)->csize & -2)
+#define CHUNK_PSIZE(c) ((c)->psize & -2)
+#define PREV_CHUNK(c) ((struct chunk *)((char *)(c) - CHUNK_PSIZE(c)))
+#define NEXT_CHUNK(c) ((struct chunk *)((char *)(c) + CHUNK_SIZE(c)))
+#define MEM_TO_CHUNK(p) (struct chunk *)((char *)(p) - OVERHEAD)
+#define CHUNK_TO_MEM(c) (void *)((char *)(c) + OVERHEAD)
+#define BIN_TO_CHUNK(i) (MEM_TO_CHUNK(&mal.bins[i].head))
+
+#define C_INUSE ((size_t)1)
+
+#define IS_MMAPPED(c) !((c)->csize & (C_INUSE))
+
+hidden void __bin_chunk(struct chunk *);
+
+#endif