diff options
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/memory.cpp | 25 | ||||
-rw-r--r-- | src/core/memory.h | 7 |
2 files changed, 25 insertions, 7 deletions
diff --git a/src/core/memory.cpp b/src/core/memory.cpp index a6b5f6c99..c42f4326b 100644 --- a/src/core/memory.cpp +++ b/src/core/memory.cpp @@ -110,8 +110,8 @@ static u8* GetPointerFromVMA(VAddr vaddr) { /** * This function should only be called for virtual addreses with attribute `PageType::Special`. */ -static MMIORegionPointer GetMMIOHandler(VAddr vaddr) { - for (const auto& region : current_page_table->special_regions) { +static MMIORegionPointer GetMMIOHandler(const PageTable& page_table, VAddr vaddr) { + for (const auto& region : page_table.special_regions) { if (vaddr >= region.base && vaddr < (region.base + region.size)) { return region.handler; } @@ -120,6 +120,11 @@ static MMIORegionPointer GetMMIOHandler(VAddr vaddr) { return nullptr; // Should never happen } +static MMIORegionPointer GetMMIOHandler(VAddr vaddr) { + const PageTable& page_table = Kernel::g_current_process->vm_manager.page_table; + return GetMMIOHandler(page_table, vaddr); +} + template <typename T> T ReadMMIO(MMIORegionPointer mmio_handler, VAddr addr); @@ -204,18 +209,20 @@ void Write(const VAddr vaddr, const T data) { } } -bool IsValidVirtualAddress(const VAddr vaddr) { - const u8* page_pointer = current_page_table->pointers[vaddr >> PAGE_BITS]; +bool IsValidVirtualAddress(const Kernel::Process& process, const VAddr vaddr) { + auto& page_table = process.vm_manager.page_table; + + const u8* page_pointer = page_table.pointers[vaddr >> PAGE_BITS]; if (page_pointer) return true; - if (current_page_table->attributes[vaddr >> PAGE_BITS] == PageType::RasterizerCachedMemory) + if (page_table.attributes[vaddr >> PAGE_BITS] == PageType::RasterizerCachedMemory) return true; - if (current_page_table->attributes[vaddr >> PAGE_BITS] != PageType::Special) + if (page_table.attributes[vaddr >> PAGE_BITS] != PageType::Special) return false; - MMIORegionPointer mmio_region = GetMMIOHandler(vaddr); + MMIORegionPointer mmio_region = GetMMIOHandler(page_table, vaddr); if (mmio_region) { return mmio_region->IsValidAddress(vaddr); } @@ -223,6 +230,10 @@ bool IsValidVirtualAddress(const VAddr vaddr) { return false; } +bool IsValidVirtualAddress(const VAddr vaddr) { + return IsValidVirtualAddress(*Kernel::g_current_process, vaddr); +} + bool IsValidPhysicalAddress(const PAddr paddr) { return GetPhysicalPointer(paddr) != nullptr; } diff --git a/src/core/memory.h b/src/core/memory.h index 1865bfea0..347c08c78 100644 --- a/src/core/memory.h +++ b/src/core/memory.h @@ -12,6 +12,10 @@ #include "common/common_types.h" #include "core/mmio.h" +namespace Kernel { +class Process; +} + namespace Memory { /** @@ -185,7 +189,10 @@ enum : VAddr { void SetCurrentPageTable(PageTable* page_table); PageTable* GetCurrentPageTable(); +/// Determines if the given VAddr is valid for the specified process. +bool IsValidVirtualAddress(const Kernel::Process& process, const VAddr vaddr); bool IsValidVirtualAddress(const VAddr addr); + bool IsValidPhysicalAddress(const PAddr addr); u8 Read8(VAddr addr); |