mirror of
				https://git.zaroz.cloud/nintendo-back-up/yuzu/yuzu.git
				synced 2025-05-12 00:45:25 +00:00 
			
		
		
		
	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
					
				| @ -110,8 +110,8 @@ static u8* GetPointerFromVMA(VAddr vaddr) { | |||||||
| /**
 | /**
 | ||||||
|  * This function should only be called for virtual addreses with attribute `PageType::Special`. |  * This function should only be called for virtual addreses with attribute `PageType::Special`. | ||||||
|  */ |  */ | ||||||
| static MMIORegionPointer GetMMIOHandler(VAddr vaddr) { | static MMIORegionPointer GetMMIOHandler(const PageTable& page_table, VAddr vaddr) { | ||||||
|     for (const auto& region : current_page_table->special_regions) { |     for (const auto& region : page_table.special_regions) { | ||||||
|         if (vaddr >= region.base && vaddr < (region.base + region.size)) { |         if (vaddr >= region.base && vaddr < (region.base + region.size)) { | ||||||
|             return region.handler; |             return region.handler; | ||||||
|         } |         } | ||||||
| @ -120,6 +120,11 @@ static MMIORegionPointer GetMMIOHandler(VAddr vaddr) { | |||||||
|     return nullptr; // Should never happen
 |     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> | template <typename T> | ||||||
| T ReadMMIO(MMIORegionPointer mmio_handler, VAddr addr); | T ReadMMIO(MMIORegionPointer mmio_handler, VAddr addr); | ||||||
| 
 | 
 | ||||||
| @ -204,18 +209,20 @@ void Write(const VAddr vaddr, const T data) { | |||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| bool IsValidVirtualAddress(const VAddr vaddr) { | bool IsValidVirtualAddress(const Kernel::Process& process, const VAddr vaddr) { | ||||||
|     const u8* page_pointer = current_page_table->pointers[vaddr >> PAGE_BITS]; |     auto& page_table = process.vm_manager.page_table; | ||||||
|  | 
 | ||||||
|  |     const u8* page_pointer = page_table.pointers[vaddr >> PAGE_BITS]; | ||||||
|     if (page_pointer) |     if (page_pointer) | ||||||
|         return true; |         return true; | ||||||
| 
 | 
 | ||||||
|     if (current_page_table->attributes[vaddr >> PAGE_BITS] == PageType::RasterizerCachedMemory) |     if (page_table.attributes[vaddr >> PAGE_BITS] == PageType::RasterizerCachedMemory) | ||||||
|         return true; |         return true; | ||||||
| 
 | 
 | ||||||
|     if (current_page_table->attributes[vaddr >> PAGE_BITS] != PageType::Special) |     if (page_table.attributes[vaddr >> PAGE_BITS] != PageType::Special) | ||||||
|         return false; |         return false; | ||||||
| 
 | 
 | ||||||
|     MMIORegionPointer mmio_region = GetMMIOHandler(vaddr); |     MMIORegionPointer mmio_region = GetMMIOHandler(page_table, vaddr); | ||||||
|     if (mmio_region) { |     if (mmio_region) { | ||||||
|         return mmio_region->IsValidAddress(vaddr); |         return mmio_region->IsValidAddress(vaddr); | ||||||
|     } |     } | ||||||
| @ -223,6 +230,10 @@ bool IsValidVirtualAddress(const VAddr vaddr) { | |||||||
|     return false; |     return false; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | bool IsValidVirtualAddress(const VAddr vaddr) { | ||||||
|  |     return IsValidVirtualAddress(*Kernel::g_current_process, vaddr); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| bool IsValidPhysicalAddress(const PAddr paddr) { | bool IsValidPhysicalAddress(const PAddr paddr) { | ||||||
|     return GetPhysicalPointer(paddr) != nullptr; |     return GetPhysicalPointer(paddr) != nullptr; | ||||||
| } | } | ||||||
|  | |||||||
| @ -12,6 +12,10 @@ | |||||||
| #include "common/common_types.h" | #include "common/common_types.h" | ||||||
| #include "core/mmio.h" | #include "core/mmio.h" | ||||||
| 
 | 
 | ||||||
|  | namespace Kernel { | ||||||
|  | class Process; | ||||||
|  | } | ||||||
|  | 
 | ||||||
| namespace Memory { | namespace Memory { | ||||||
| 
 | 
 | ||||||
| /**
 | /**
 | ||||||
| @ -185,7 +189,10 @@ enum : VAddr { | |||||||
| void SetCurrentPageTable(PageTable* page_table); | void SetCurrentPageTable(PageTable* page_table); | ||||||
| PageTable* GetCurrentPageTable(); | 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 IsValidVirtualAddress(const VAddr addr); | ||||||
|  | 
 | ||||||
| bool IsValidPhysicalAddress(const PAddr addr); | bool IsValidPhysicalAddress(const PAddr addr); | ||||||
| 
 | 
 | ||||||
| u8 Read8(VAddr addr); | u8 Read8(VAddr addr); | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Subv
						Subv