refactor: simplify the vmm design, single responsibility. But using it should with...
[lunaix-os.git] / lunaix-os / includes / lunaix / mm / dmm.h
index cfe15b3bfdce3d5578624c34d8ce4484238eba6e..0a79cdc07ba75d7a5c4a25c5972905a84481ad6e 100644 (file)
@@ -2,29 +2,48 @@
 #define __LUNAIX_DMM_H
 // Dynamic Memory (i.e., heap) Manager
 
+#include <lunaix/mm/mm.h>
+#include <lunaix/process.h>
 #include <stddef.h>
 
-#define HEAP_INIT_SIZE 4096
+#define M_ALLOCATED 0x1
+#define M_PREV_FREE 0x2
+
+#define M_NOT_ALLOCATED 0x0
+#define M_PREV_ALLOCATED 0x0
+
+#define CHUNK_S(header) ((header) & ~0x3)
+#define CHUNK_PF(header) ((header)&M_PREV_FREE)
+#define CHUNK_A(header) ((header)&M_ALLOCATED)
+
+#define PACK(size, flags) (((size) & ~0x3) | (flags))
 
-typedef struct 
-{
-    void* start;
-    void* brk;
-} heap_context_t;
+#define SW(p, w) (*((uint32_t*)(p)) = w)
+#define LW(p) (*((uint32_t*)(p)))
 
+#define HPTR(bp) ((uint32_t*)(bp)-1)
+#define BPTR(bp) ((uint8_t*)(bp) + WSIZE)
+#define FPTR(hp, size) ((uint32_t*)(hp + size - WSIZE))
+#define NEXT_CHK(hp) ((uint8_t*)(hp) + CHUNK_S(LW(hp)))
+
+#define BOUNDARY 4
+#define WSIZE 4
+
+#define HEAP_INIT_SIZE 4096
 
 int
 dmm_init(heap_context_t* heap);
 
 int
-lxsbrk(heap_context_t* heap, void* addr);
+lxbrk(heap_context_t* heap, void* addr, int user);
+
 void*
-lxbrk(heap_context_t* heap, size_t size);
+lxsbrk(heap_context_t* heap, size_t size, int user);
 
 void*
-lx_malloc(heap_context_t* heap, size_t size);
+lx_malloc_internal(heap_context_t* heap, size_t size);
 
 void
-lx_free(void* ptr);
+lx_free_internal(void* ptr);
 
 #endif /* __LUNAIX_DMM_H */