Restructure the interrupt vector distribution for better matching of their inherit...
[lunaix-os.git] / lunaix-os / includes / lunaix / mm / dmm.h
1 #ifndef __LUNAIX_DMM_H
2 #define __LUNAIX_DMM_H
3 // Dynamic Memory (i.e., heap) Manager
4
5 #include <stddef.h>
6
7 #define M_ALLOCATED 0x1
8 #define M_PREV_FREE 0x2
9
10 #define M_NOT_ALLOCATED 0x0
11 #define M_PREV_ALLOCATED 0x0
12
13 #define CHUNK_S(header) ((header) & ~0x3)
14 #define CHUNK_PF(header) ((header)&M_PREV_FREE)
15 #define CHUNK_A(header) ((header)&M_ALLOCATED)
16
17 #define PACK(size, flags) (((size) & ~0x3) | (flags))
18
19 #define SW(p, w) (*((uint32_t*)(p)) = w)
20 #define LW(p) (*((uint32_t*)(p)))
21
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)))
26
27 #define BOUNDARY 4
28 #define WSIZE 4
29
30 #define HEAP_INIT_SIZE 4096
31
32 typedef struct 
33 {
34     void* start;
35     void* brk;
36     void* max_addr;
37 } heap_context_t;
38
39
40 int
41 dmm_init(heap_context_t* heap);
42
43 int
44 lxsbrk(heap_context_t* heap, void* addr);
45 void*
46 lxbrk(heap_context_t* heap, size_t size);
47
48 void*
49 lx_malloc_internal(heap_context_t* heap, size_t size);
50
51 void
52 lx_free_internal(void* ptr);
53
54 #endif /* __LUNAIX_DMM_H */