diff --git a/kernel/src/memory/Heap.cpp b/kernel/src/memory/Heap.cpp index dc172a83..d3c87ac6 100644 --- a/kernel/src/memory/Heap.cpp +++ b/kernel/src/memory/Heap.cpp @@ -2,6 +2,7 @@ #include "Log.h" #include "arch/MMU.h" #include "arch/Serial.h" +#include "memory/KernelVM.h" #include "memory/MemoryManager.h" #include #include @@ -31,20 +32,19 @@ static_assert(sizeof(HeapBlock) == 48UL); static HeapBlock* heap_start = nullptr; static HeapBlock* heap_end = nullptr; -static usize start_addr = 0xffffffff80000000; - static Result allocate_pages( usize count) // FIXME: Keep track of virtual address space usage. For now, since the address // space is so huge, we can just start at a fairly large address and assume // we'll never run into anything, but this will probably bite us in the future. { - void* const ptr = (void*)TRY(MemoryManager::alloc_at(start_addr, count, MMU::ReadWrite | MMU::NoExecute)); - if (ptr) start_addr += (count * ARCH_PAGE_SIZE); + u64 virt = TRY(KernelVM::alloc_several_pages(count)); + void* const ptr = (void*)TRY(MemoryManager::alloc_at(virt, count, MMU::ReadWrite | MMU::NoExecute)); return (HeapBlock*)ptr; } static Result release_pages(void* ptr, usize count) { + TRY(KernelVM::free_several_pages((u64)ptr, count)); return MemoryManager::unmap_owned((u64)ptr, count); }