diff --git a/kernel/arch/x86_64/MMU.cpp b/kernel/arch/x86_64/MMU.cpp index f8c309e44..67a079ce5 100644 --- a/kernel/arch/x86_64/MMU.cpp +++ b/kernel/arch/x86_64/MMU.cpp @@ -18,6 +18,7 @@ namespace Kernel { static MMU* s_instance = nullptr; + static MMU* s_current = nullptr; void MMU::initialize() { @@ -34,6 +35,12 @@ namespace Kernel return *s_instance; } + MMU& MMU::current() + { + ASSERT(s_current); + return *s_current; + } + static uint64_t* allocate_page_aligned_page() { void* page = kmalloc(PAGE_SIZE, PAGE_SIZE); @@ -130,6 +137,7 @@ namespace Kernel void MMU::load() { asm volatile("movq %0, %%cr3" :: "r"(m_highest_paging_struct)); + s_current = this; } void MMU::identity_map_page(paddr_t address, flags_t flags) diff --git a/kernel/include/kernel/Memory/MMU.h b/kernel/include/kernel/Memory/MMU.h index 17728484d..8e481608e 100644 --- a/kernel/include/kernel/Memory/MMU.h +++ b/kernel/include/kernel/Memory/MMU.h @@ -20,6 +20,8 @@ namespace Kernel static void initialize(); static MMU& get(); + static MMU& current(); + MMU(); ~MMU();