diff options
author | Raghuram Subramani <raghus2247@gmail.com> | 2025-02-04 15:31:55 +0530 |
---|---|---|
committer | Raghuram Subramani <raghus2247@gmail.com> | 2025-02-04 15:32:17 +0530 |
commit | 3e20a64df7816d07246073491453cd3bd3583b4f (patch) | |
tree | cfecb7ad2327528379f7035c2612aeec8c096106 /kernel/include/libk/liballoc.h | |
parent | 869d9bcea81b2ad439cd4498eabc1136e945d2ce (diff) |
libk: Finally, a proper kmalloc()!
Diffstat (limited to 'kernel/include/libk/liballoc.h')
-rw-r--r-- | kernel/include/libk/liballoc.h | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/kernel/include/libk/liballoc.h b/kernel/include/libk/liballoc.h index ff40054..b1568e9 100644 --- a/kernel/include/libk/liballoc.h +++ b/kernel/include/libk/liballoc.h @@ -20,25 +20,32 @@ #define __libk_liballoc_h #include <stddef.h> -#include <stdint.h> namespace LibAlloc { -class Block -{ -public: - Block *m_next; - uint32_t m_size; +/** This is a boundary tag which is prepended to the + * page or section of a page which we have allocated. It is + * used to identify valid memory blocks that the + * application is trying to free. + */ +struct boundary_tag { + unsigned int magic; //< It's a kind of ... + unsigned int size; //< Requested size. + unsigned int real_size; //< Actual size. + int index; //< Location in the page table. -public: - void initialize(uint32_t size); + struct boundary_tag *split_left; //< Linked-list info for broken pages. + struct boundary_tag *split_right; //< The same. - void *get_chunk(void); + struct boundary_tag *next; //< Linked list info. + struct boundary_tag *prev; //< Linked list info. }; -bool initialized(void); -void initialize(void); +void *kmalloc(size_t); +void *krealloc(void *, size_t); +void *kcalloc(size_t, size_t); +void kfree(void *); } |