summaryrefslogtreecommitdiff
path: root/src/kernel/mem/heap.basic.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/kernel/mem/heap.basic.h')
-rw-r--r--src/kernel/mem/heap.basic.h30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/kernel/mem/heap.basic.h b/src/kernel/mem/heap.basic.h
new file mode 100644
index 0000000..c752750
--- /dev/null
+++ b/src/kernel/mem/heap.basic.h
@@ -0,0 +1,30 @@
+#ifndef DEF_HEAP_H
+#define DEF_HEAP_H
+
+/* This heap implementation is extra-simple and extra-slow. */
+
+#include "types.h"
+
+#define HH_FREE_MAGIC 0xFEE0FEE0
+#define HH_ALLOC_MAGIC 0xA110A110
+
+#define HEAP_EXTEND_QUANTITY 0x00080000 // each time we extend the heap, extend it 512 k
+
+#define MIN_BLK_SIZE 0x20 // 32 bytes
+
+struct heap_header {
+ uint32_t magic;
+ struct heap_header *prev, *next;
+};
+
+struct heap {
+ struct heap_header *first, *first_free; // first_free is not necessarily free, it's just an indication
+ size_t start_addr, end_addr, max_end;
+ uint32_t mutex;
+};
+
+void heap_create(struct heap *heap, size_t start, size_t datasize, size_t maxdatasize);
+void *heap_alloc(struct heap *heap, size_t sz);
+void heap_free(struct heap *heap, void *ptr);
+
+#endif