3 // Dynamic Memory (i.e., heap) Manager
5 #include <lunaix/mm/mm.h>
6 #include <lunaix/process.h>
9 #define M_ALLOCATED 0x1
10 #define M_PREV_FREE 0x2
12 #define M_NOT_ALLOCATED 0x0
13 #define M_PREV_ALLOCATED 0x0
15 #define CHUNK_S(header) ((header) & ~0x3)
16 #define CHUNK_PF(header) ((header)&M_PREV_FREE)
17 #define CHUNK_A(header) ((header)&M_ALLOCATED)
19 #define PACK(size, flags) (((size) & ~0x3) | (flags))
21 #define SW(p, w) (*((uint32_t*)(p)) = w)
22 #define LW(p) (*((uint32_t*)(p)))
24 #define HPTR(bp) ((uint32_t*)(bp)-1)
25 #define BPTR(bp) ((uint8_t*)(bp) + WSIZE)
26 #define FPTR(hp, size) ((uint32_t*)(hp + size - WSIZE))
27 #define NEXT_CHK(hp) ((uint8_t*)(hp) + CHUNK_S(LW(hp)))
32 #define HEAP_INIT_SIZE 4096
35 dmm_init(heap_context_t* heap);
38 lxbrk(heap_context_t* heap, void* addr, int user);
41 lxsbrk(heap_context_t* heap, size_t size, int user);
44 lx_malloc_internal(heap_context_t* heap, size_t size);
47 lx_free_internal(void* ptr);
49 #endif /* __LUNAIX_DMM_H */