From 24ac72db9322277e25df56839963f19f0796fdb7 Mon Sep 17 00:00:00 2001 From: Raghuram Subramani Date: Sat, 1 Feb 2025 08:49:14 -0500 Subject: libk: Minimal (barely) working implementation of kmalloc --- kernel/include/libk/kmalloc.h | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) (limited to 'kernel/include') diff --git a/kernel/include/libk/kmalloc.h b/kernel/include/libk/kmalloc.h index 2817aff..7a9ff81 100644 --- a/kernel/include/libk/kmalloc.h +++ b/kernel/include/libk/kmalloc.h @@ -19,17 +19,32 @@ #ifndef __libk_kmalloc_h #define __libk_kmalloc_h +#include +#include #include -typedef struct memory_chunk_t { - struct memory_chunk_t *next; - struct memory_chunk_t *prev; +/** 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. + + struct boundary_tag *split_left; //< Linked-list info for broken pages. + struct boundary_tag *split_right; //< The same. + + struct boundary_tag *next; //< Linked list info. + struct boundary_tag *prev; //< Linked list info. +}; - uint32_t size; -} memory_chunk_t; +#define liballoc_alloc VirtualMM::alloc_pages +#define liballoc_free VirtualMM::free_pages bool kmalloc_initialized(void); -void kmalloc_initialize(void); -void *kmalloc(uint32_t size); +void *kmalloc(size_t); #endif -- cgit v1.2.3