Use KernelVM in kmalloc() and friends

Much better now!!
This commit is contained in:
apio 2022-12-05 21:02:05 +01:00
parent ba758bcef8
commit 1d0dd8fa93
Signed by: apio
GPG Key ID: B8A7D06E42258954

View File

@ -2,6 +2,7 @@
#include "Log.h"
#include "arch/MMU.h"
#include "arch/Serial.h"
#include "memory/KernelVM.h"
#include "memory/MemoryManager.h"
#include <luna/Alignment.h>
#include <luna/String.h>
@ -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<HeapBlock*> 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<void> release_pages(void* ptr, usize count)
{
TRY(KernelVM::free_several_pages((u64)ptr, count));
return MemoryManager::unmap_owned((u64)ptr, count);
}