forked from suyu/suyu
Memory: Allow IsValidVirtualAddress to be called with a specific process parameter.
There is still an overload of IsValidVirtualAddress that only takes the VAddr and will default to the current process.
This commit is contained in:
parent
0c20da7fde
commit
35da7f57ef
2 changed files with 25 additions and 7 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue