[Zion] Introduce the Kernel VMM to centralize allocs.

This commit is contained in:
Drew Galbraith 2023-11-15 15:14:29 -08:00
parent 0b47e3b7fc
commit 20d6d2aaaf
5 changed files with 55 additions and 15 deletions

View file

@ -0,0 +1,32 @@
#include "memory/kernel_vmm.h"
#include "debug/debug.h"
#include "memory/paging_util.h"
namespace {
KernelVmm* gKernelVmm = nullptr;
}
KernelVmm::KernelVmm() {
if (gKernelVmm) {
panic("KernelVmm double init.");
}
gKernelVmm = this;
}
uint64_t KernelVmm::AcquireSlabHeapRegion(uint64_t slab_size_bytes) {
return gKernelVmm->AcquireSlabHeapRegionInternal(slab_size_bytes);
}
uint64_t KernelVmm::AcquireSlabHeapRegionInternal(uint64_t slab_size_bytes) {
uint64_t next_slab = next_slab_heap_page_;
if (next_slab >= kKernelBuddyHeapEnd) {
panic("Slab heap overrun");
}
next_slab_heap_page_ += slab_size_bytes;
// TODO: Consider handling this as a part of a page-fault handler
// rather than auto mapping all over the place.
EnsureResident(next_slab, slab_size_bytes);
return next_slab;
}