aboutsummaryrefslogtreecommitdiffstats
path: root/dos/malloc.h
diff options
context:
space:
mode:
authorhpa <hpa>2004-12-15 12:34:42 +0000
committerhpa <hpa>2004-12-15 12:34:42 +0000
commite5b229c776a5de62121a18a981119484d367ad90 (patch)
tree9995adbc26ca4f19be997e82c77dec5859fefe1b /dos/malloc.h
parent883466394bb699dfbae62fcf025586c43a77e481 (diff)
downloadsyslinux.git-e5b229c776a5de62121a18a981119484d367ad90.tar.gz
syslinux.git-e5b229c776a5de62121a18a981119484d367ad90.tar.xz
syslinux.git-e5b229c776a5de62121a18a981119484d367ad90.zip
Convert the DOS installer to C like everything else.
Diffstat (limited to 'dos/malloc.h')
-rw-r--r--dos/malloc.h54
1 files changed, 54 insertions, 0 deletions
diff --git a/dos/malloc.h b/dos/malloc.h
new file mode 100644
index 00000000..57b76526
--- /dev/null
+++ b/dos/malloc.h
@@ -0,0 +1,54 @@
+/*
+ * malloc.h
+ *
+ * Internals for the memory allocator
+ */
+
+#include <stdint.h>
+#include <stddef.h>
+
+/*
+ * This is the minimum chunk size we will ask the kernel for; this should
+ * be a multiple of the page size on all architectures.
+ */
+#define MALLOC_CHUNK_SIZE 65536
+#define MALLOC_CHUNK_MASK (MALLOC_CHUNK_SIZE-1)
+
+/*
+ * This structure should be a power of two. This becomes the
+ * alignment unit.
+ */
+struct free_arena_header;
+
+struct arena_header {
+ size_t type;
+ size_t size; /* Also gives the location of the next entry */
+ struct free_arena_header *next, *prev;
+};
+
+#ifdef DEBUG_MALLOC
+#define ARENA_TYPE_USED 0x64e69c70
+#define ARENA_TYPE_FREE 0x012d610a
+#define ARENA_TYPE_HEAD 0x971676b5
+#define ARENA_TYPE_DEAD 0xeeeeeeee
+#else
+#define ARENA_TYPE_USED 0
+#define ARENA_TYPE_FREE 1
+#define ARENA_TYPE_HEAD 2
+#endif
+
+#define ARENA_SIZE_MASK (~(sizeof(struct arena_header)-1))
+
+#define ARENA_ALIGN_UP(p) ((char *)(((uintptr_t)(p) + ARENA_SIZE_MASK) & ARENA_SIZE_MASK))
+#define ARENA_ALIGN_DOWN(p) ((char *)((uintptr_t)(p) & ARENA_SIZE_MASK))
+
+/*
+ * This structure should be no more than twice the size of the
+ * previous structure.
+ */
+struct free_arena_header {
+ struct arena_header a;
+ struct free_arena_header *next_free, *prev_free;
+};
+
+extern struct free_arena_header __malloc_head;