diff options
author | Marvin Borner | 2020-04-26 20:12:05 +0200 |
---|---|---|
committer | Marvin Borner | 2020-04-26 20:12:05 +0200 |
commit | 31f671f2137bc09e62de09142bea232c1975c76b (patch) | |
tree | 60729693e4a70d2b3d449ed396ba860d3fa33071 /src/kernel/memory/alloc.h | |
parent | d3047efc1085d3e2f5524f629e55dc456a2f5065 (diff) |
Complete rewrite of paging and allocation libs
-> This was REALLY needed.
Diffstat (limited to 'src/kernel/memory/alloc.h')
-rw-r--r-- | src/kernel/memory/alloc.h | 61 |
1 files changed, 41 insertions, 20 deletions
diff --git a/src/kernel/memory/alloc.h b/src/kernel/memory/alloc.h index 3ddc8d8..16d61f5 100644 --- a/src/kernel/memory/alloc.h +++ b/src/kernel/memory/alloc.h @@ -2,23 +2,44 @@ #define MELVIX_ALLOC_H #include <stddef.h> - -#define PREFIX(func) k##func - -int liballoc_lock(); - -int liballoc_unlock(); - -void *liballoc_alloc(size_t); - -int liballoc_free(void *, size_t); - -void *PREFIX(malloc)(size_t); - -void *PREFIX(realloc)(void *, size_t); - -void *PREFIX(calloc)(size_t, size_t); - -void PREFIX(free)(void *); - -#endif
\ No newline at end of file +#include <stdint.h> +#include <stdbool.h> + +#define KHEAP_MAGIC 0x04206969 +#define KHEAP_MAGIC2 0xDEADBEEF +#define KHEAP_END 0xFFFFDEAD +#define MEM_END 0x8000000 + +struct heap_header { + uint32_t magic; + bool free; + uint32_t size; + uint32_t magic2; +}; + +struct heap_footer { + uint32_t magic; + uint32_t size; + uint32_t magic2; +}; + +void kheap_init(); + +void *fmalloc(uint32_t size); +void *kmalloc(uint32_t size); +void *kmalloc_a(uint32_t size); +void kfree(void *ptr); + +void *umalloc(size_t size); +void ufree(void *address); + +void init_heap(struct heap_header *heap, size_t size); + +#define KHEAP_SIZE 0xFFFFF +#define UHEAP_SIZE 0xFFFFF +#define HEAP_S (sizeof(struct heap_header)) +#define HEAP_TOTAL (sizeof(struct heap_footer) + HEAP_S) +#define HEAP_MINIMUM 1 +#define HEAP_FIND_SIZE (HEAP_TOTAL + HEAP_MINIMUM) + +#endif |