3 // Dynamic Memory (i.e., heap) Manager
7 #define M_ALLOCATED 0x1
8 #define M_PREV_FREE 0x2
10 #define M_NOT_ALLOCATED 0x0
11 #define M_PREV_ALLOCATED 0x0
13 #define CHUNK_S(header) ((header) & ~0x3)
14 #define CHUNK_PF(header) ((header)&M_PREV_FREE)
15 #define CHUNK_A(header) ((header)&M_ALLOCATED)
17 #define PACK(size, flags) (((size) & ~0x3) | (flags))
19 #define SW(p, w) (*((uint32_t*)(p)) = w)
20 #define LW(p) (*((uint32_t*)(p)))
22 #define HPTR(bp) ((uint32_t*)(bp)-1)
23 #define BPTR(bp) ((uint8_t*)(bp) + WSIZE)
24 #define FPTR(hp, size) ((uint32_t*)(hp + size - WSIZE))
25 #define NEXT_CHK(hp) ((uint8_t*)(hp) + CHUNK_S(LW(hp)))
30 #define HEAP_INIT_SIZE 4096
41 dmm_init(heap_context_t* heap);
44 lxsbrk(heap_context_t* heap, void* addr);
46 lxbrk(heap_context_t* heap, size_t size);
49 lx_malloc_internal(heap_context_t* heap, size_t size);
52 lx_free_internal(void* ptr);
54 #endif /* __LUNAIX_DMM_H */