Use KernelVM in kmalloc() and friends
Much better now!!
This commit is contained in:
parent
ba758bcef8
commit
1d0dd8fa93
@ -2,6 +2,7 @@
|
|||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
#include "arch/MMU.h"
|
#include "arch/MMU.h"
|
||||||
#include "arch/Serial.h"
|
#include "arch/Serial.h"
|
||||||
|
#include "memory/KernelVM.h"
|
||||||
#include "memory/MemoryManager.h"
|
#include "memory/MemoryManager.h"
|
||||||
#include <luna/Alignment.h>
|
#include <luna/Alignment.h>
|
||||||
#include <luna/String.h>
|
#include <luna/String.h>
|
||||||
@ -31,20 +32,19 @@ static_assert(sizeof(HeapBlock) == 48UL);
|
|||||||
static HeapBlock* heap_start = nullptr;
|
static HeapBlock* heap_start = nullptr;
|
||||||
static HeapBlock* heap_end = nullptr;
|
static HeapBlock* heap_end = nullptr;
|
||||||
|
|
||||||
static usize start_addr = 0xffffffff80000000;
|
|
||||||
|
|
||||||
static Result<HeapBlock*> allocate_pages(
|
static Result<HeapBlock*> allocate_pages(
|
||||||
usize count) // FIXME: Keep track of virtual address space usage. For now, since the address
|
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
|
// 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.
|
// 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));
|
u64 virt = TRY(KernelVM::alloc_several_pages(count));
|
||||||
if (ptr) start_addr += (count * ARCH_PAGE_SIZE);
|
void* const ptr = (void*)TRY(MemoryManager::alloc_at(virt, count, MMU::ReadWrite | MMU::NoExecute));
|
||||||
return (HeapBlock*)ptr;
|
return (HeapBlock*)ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Result<void> release_pages(void* ptr, usize count)
|
static Result<void> release_pages(void* ptr, usize count)
|
||||||
{
|
{
|
||||||
|
TRY(KernelVM::free_several_pages((u64)ptr, count));
|
||||||
return MemoryManager::unmap_owned((u64)ptr, count);
|
return MemoryManager::unmap_owned((u64)ptr, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user