diff options
| author | Ada Christine <adachristine18@gmail.com> | 2024-02-11 23:48:04 +0000 |
|---|---|---|
| committer | Ada Christine <adachristine18@gmail.com> | 2024-02-11 23:48:04 +0000 |
| commit | 3f9278b48ff4bc0d2cf1604034b3bba548572f04 (patch) | |
| tree | dbdabed3ff580079d2e21045d2cbc5b274c2e418 /kc/core/memory | |
| parent | 9fbfc6e951e565ef98c49c1dcfc4b6a39514f17d (diff) | |
kjarna initial impl
Diffstat (limited to 'kc/core/memory')
| -rw-r--r-- | kc/core/memory/memory.c | 31 |
1 files changed, 25 insertions, 6 deletions
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( |
