From 3f9278b48ff4bc0d2cf1604034b3bba548572f04 Mon Sep 17 00:00:00 2001 From: Ada Christine Date: Sun, 11 Feb 2024 23:48:04 +0000 Subject: kjarna initial impl --- kc/core/memory/memory.c | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) (limited to 'kc') diff --git a/kc/core/memory/memory.c b/kc/core/memory/memory.c index 1c6fabb..ee0d9ca 100644 --- a/kc/core/memory/memory.c +++ b/kc/core/memory/memory.c @@ -599,13 +599,32 @@ void *vm_alloc(size_t size, enum vm_alloc_flags flags) // TODO implement a proper allocator here rather than this bump allocator. char *address = vm_state.first_free; - if (address == vm_alloc_at(address, size, flags)) - { - vm_state.first_free = address + size; - return address; - } + while (address != vm_alloc_at(address, size, flags)) + { + address = address + size; + } - return NULL; + if (address != nullptr) + { + vm_state.first_free = address + size; + } + + return address; +} + + +void vm_free(void *address) +{ + struct vm_tree_key key = { (uintptr_t)address, 1 }; + struct vm_tree_node *node; + + if(!(node = vmt_search_key(vm_get_tree(), &key))) + { + return; + } + + // TODO: delete paging structures etc. + vmt_delete(vm_get_tree(), node); } int anonymous_page_handler( -- cgit v1.3.1-1-g115d