summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar liamwhite2023-07-22 11:17:36 -0400
committerGravatar GitHub2023-07-22 11:17:36 -0400
commitb1aed2c5b79dc8c3ba858e21308312a5dc10dd2f (patch)
tree14f41563aac7e5513bad341805afb164f1bf2f4f
parentMerge pull request #11098 from GPUCode/texel-buffers (diff)
parentkernel: reduce page table region checking (diff)
downloadyuzu-b1aed2c5b79dc8c3ba858e21308312a5dc10dd2f.tar.gz
yuzu-b1aed2c5b79dc8c3ba858e21308312a5dc10dd2f.tar.xz
yuzu-b1aed2c5b79dc8c3ba858e21308312a5dc10dd2f.zip
Merge pull request #11094 from liamwhite/get
kernel: misc cleanup of page table accessors
-rw-r--r--src/core/debugger/gdbstub.cpp4
-rw-r--r--src/core/hle/kernel/k_code_memory.cpp17
-rw-r--r--src/core/hle/kernel/k_page_table.h41
-rw-r--r--src/core/hle/kernel/k_process.cpp2
-rw-r--r--src/core/hle/kernel/k_process.h10
-rw-r--r--src/core/hle/kernel/k_shared_memory.cpp6
-rw-r--r--src/core/hle/kernel/k_thread_local_page.cpp10
-rw-r--r--src/core/hle/kernel/svc/svc_cache.cpp2
-rw-r--r--src/core/hle/kernel/svc/svc_code_memory.cpp14
-rw-r--r--src/core/hle/kernel/svc/svc_device_address_space.cpp6
-rw-r--r--src/core/hle/kernel/svc/svc_info.cpp16
-rw-r--r--src/core/hle/kernel/svc/svc_memory.cpp33
-rw-r--r--src/core/hle/kernel/svc/svc_physical_memory.cpp14
-rw-r--r--src/core/hle/kernel/svc/svc_process.cpp4
-rw-r--r--src/core/hle/kernel/svc/svc_process_memory.cpp34
-rw-r--r--src/core/hle/kernel/svc/svc_query_memory.cpp2
-rw-r--r--src/core/hle/kernel/svc/svc_shared_memory.cpp4
-rw-r--r--src/core/hle/kernel/svc/svc_thread.cpp2
-rw-r--r--src/core/hle/kernel/svc/svc_transfer_memory.cpp2
-rw-r--r--src/core/hle/service/ldr/ldr.cpp20
-rw-r--r--src/core/hle/service/nvdrv/devices/nvmap.cpp4
-rw-r--r--src/core/loader/deconstructed_rom_directory.cpp2
-rw-r--r--src/core/loader/kip.cpp2
-rw-r--r--src/core/loader/nro.cpp2
-rw-r--r--src/core/loader/nso.cpp2
-rw-r--r--src/core/memory.cpp8
-rw-r--r--src/core/memory/cheat_engine.cpp2
-rw-r--r--src/core/reporter.cpp4
28 files changed, 98 insertions, 171 deletions
diff --git a/src/core/debugger/gdbstub.cpp b/src/core/debugger/gdbstub.cpp
index e2a13bbd2..da6078372 100644
--- a/src/core/debugger/gdbstub.cpp
+++ b/src/core/debugger/gdbstub.cpp
@@ -556,7 +556,7 @@ void GDBStub::HandleQuery(std::string_view command) {
556 } else { 556 } else {
557 SendReply(fmt::format( 557 SendReply(fmt::format(
558 "TextSeg={:x}", 558 "TextSeg={:x}",
559 GetInteger(system.ApplicationProcess()->PageTable().GetCodeRegionStart()))); 559 GetInteger(system.ApplicationProcess()->GetPageTable().GetCodeRegionStart())));
560 } 560 }
561 } else if (command.starts_with("Xfer:libraries:read::")) { 561 } else if (command.starts_with("Xfer:libraries:read::")) {
562 Loader::AppLoader::Modules modules; 562 Loader::AppLoader::Modules modules;
@@ -731,7 +731,7 @@ void GDBStub::HandleRcmd(const std::vector<u8>& command) {
731 std::string reply; 731 std::string reply;
732 732
733 auto* process = system.ApplicationProcess(); 733 auto* process = system.ApplicationProcess();
734 auto& page_table = process->PageTable(); 734 auto& page_table = process->GetPageTable();
735 735
736 const char* commands = "Commands:\n" 736 const char* commands = "Commands:\n"
737 " get fastmem\n" 737 " get fastmem\n"
diff --git a/src/core/hle/kernel/k_code_memory.cpp b/src/core/hle/kernel/k_code_memory.cpp
index 3583bee44..7454be55c 100644
--- a/src/core/hle/kernel/k_code_memory.cpp
+++ b/src/core/hle/kernel/k_code_memory.cpp
@@ -25,7 +25,7 @@ Result KCodeMemory::Initialize(Core::DeviceMemory& device_memory, KProcessAddres
25 m_owner = GetCurrentProcessPointer(m_kernel); 25 m_owner = GetCurrentProcessPointer(m_kernel);
26 26
27 // Get the owner page table. 27 // Get the owner page table.
28 auto& page_table = m_owner->PageTable(); 28 auto& page_table = m_owner->GetPageTable();
29 29
30 // Construct the page group. 30 // Construct the page group.
31 m_page_group.emplace(m_kernel, page_table.GetBlockInfoManager()); 31 m_page_group.emplace(m_kernel, page_table.GetBlockInfoManager());
@@ -53,7 +53,7 @@ void KCodeMemory::Finalize() {
53 // Unlock. 53 // Unlock.
54 if (!m_is_mapped && !m_is_owner_mapped) { 54 if (!m_is_mapped && !m_is_owner_mapped) {
55 const size_t size = m_page_group->GetNumPages() * PageSize; 55 const size_t size = m_page_group->GetNumPages() * PageSize;
56 m_owner->PageTable().UnlockForCodeMemory(m_address, size, *m_page_group); 56 m_owner->GetPageTable().UnlockForCodeMemory(m_address, size, *m_page_group);
57 } 57 }
58 58
59 // Close the page group. 59 // Close the page group.
@@ -75,7 +75,7 @@ Result KCodeMemory::Map(KProcessAddress address, size_t size) {
75 R_UNLESS(!m_is_mapped, ResultInvalidState); 75 R_UNLESS(!m_is_mapped, ResultInvalidState);
76 76
77 // Map the memory. 77 // Map the memory.
78 R_TRY(GetCurrentProcess(m_kernel).PageTable().MapPageGroup( 78 R_TRY(GetCurrentProcess(m_kernel).GetPageTable().MapPageGroup(
79 address, *m_page_group, KMemoryState::CodeOut, KMemoryPermission::UserReadWrite)); 79 address, *m_page_group, KMemoryState::CodeOut, KMemoryPermission::UserReadWrite));
80 80
81 // Mark ourselves as mapped. 81 // Mark ourselves as mapped.
@@ -92,8 +92,8 @@ Result KCodeMemory::Unmap(KProcessAddress address, size_t size) {
92 KScopedLightLock lk(m_lock); 92 KScopedLightLock lk(m_lock);
93 93
94 // Unmap the memory. 94 // Unmap the memory.
95 R_TRY(GetCurrentProcess(m_kernel).PageTable().UnmapPageGroup(address, *m_page_group, 95 R_TRY(GetCurrentProcess(m_kernel).GetPageTable().UnmapPageGroup(address, *m_page_group,
96 KMemoryState::CodeOut)); 96 KMemoryState::CodeOut));
97 97
98 // Mark ourselves as unmapped. 98 // Mark ourselves as unmapped.
99 m_is_mapped = false; 99 m_is_mapped = false;
@@ -126,8 +126,8 @@ Result KCodeMemory::MapToOwner(KProcessAddress address, size_t size, Svc::Memory
126 } 126 }
127 127
128 // Map the memory. 128 // Map the memory.
129 R_TRY(m_owner->PageTable().MapPageGroup(address, *m_page_group, KMemoryState::GeneratedCode, 129 R_TRY(m_owner->GetPageTable().MapPageGroup(address, *m_page_group, KMemoryState::GeneratedCode,
130 k_perm)); 130 k_perm));
131 131
132 // Mark ourselves as mapped. 132 // Mark ourselves as mapped.
133 m_is_owner_mapped = true; 133 m_is_owner_mapped = true;
@@ -143,7 +143,8 @@ Result KCodeMemory::UnmapFromOwner(KProcessAddress address, size_t size) {
143 KScopedLightLock lk(m_lock); 143 KScopedLightLock lk(m_lock);
144 144
145 // Unmap the memory. 145 // Unmap the memory.
146 R_TRY(m_owner->PageTable().UnmapPageGroup(address, *m_page_group, KMemoryState::GeneratedCode)); 146 R_TRY(m_owner->GetPageTable().UnmapPageGroup(address, *m_page_group,
147 KMemoryState::GeneratedCode));
147 148
148 // Mark ourselves as unmapped. 149 // Mark ourselves as unmapped.
149 m_is_owner_mapped = false; 150 m_is_owner_mapped = false;
diff --git a/src/core/hle/kernel/k_page_table.h b/src/core/hle/kernel/k_page_table.h
index 022d15f35..b9e8c6042 100644
--- a/src/core/hle/kernel/k_page_table.h
+++ b/src/core/hle/kernel/k_page_table.h
@@ -388,39 +388,6 @@ public:
388 constexpr size_t GetHeapSize() const { 388 constexpr size_t GetHeapSize() const {
389 return m_current_heap_end - m_heap_region_start; 389 return m_current_heap_end - m_heap_region_start;
390 } 390 }
391 constexpr bool IsInsideAddressSpace(KProcessAddress address, size_t size) const {
392 return m_address_space_start <= address && address + size - 1 <= m_address_space_end - 1;
393 }
394 constexpr bool IsOutsideAliasRegion(KProcessAddress address, size_t size) const {
395 return m_alias_region_start > address || address + size - 1 > m_alias_region_end - 1;
396 }
397 constexpr bool IsOutsideStackRegion(KProcessAddress address, size_t size) const {
398 return m_stack_region_start > address || address + size - 1 > m_stack_region_end - 1;
399 }
400 constexpr bool IsInvalidRegion(KProcessAddress address, size_t size) const {
401 return address + size - 1 > GetAliasCodeRegionStart() + GetAliasCodeRegionSize() - 1;
402 }
403 constexpr bool IsInsideHeapRegion(KProcessAddress address, size_t size) const {
404 return address + size > m_heap_region_start && m_heap_region_end > address;
405 }
406 constexpr bool IsInsideAliasRegion(KProcessAddress address, size_t size) const {
407 return address + size > m_alias_region_start && m_alias_region_end > address;
408 }
409 constexpr bool IsOutsideASLRRegion(KProcessAddress address, size_t size) const {
410 if (IsInvalidRegion(address, size)) {
411 return true;
412 }
413 if (IsInsideHeapRegion(address, size)) {
414 return true;
415 }
416 if (IsInsideAliasRegion(address, size)) {
417 return true;
418 }
419 return {};
420 }
421 constexpr bool IsInsideASLRRegion(KProcessAddress address, size_t size) const {
422 return !IsOutsideASLRRegion(address, size);
423 }
424 constexpr size_t GetNumGuardPages() const { 391 constexpr size_t GetNumGuardPages() const {
425 return IsKernel() ? 1 : 4; 392 return IsKernel() ? 1 : 4;
426 } 393 }
@@ -436,6 +403,14 @@ public:
436 return m_address_space_start <= addr && addr < addr + size && 403 return m_address_space_start <= addr && addr < addr + size &&
437 addr + size - 1 <= m_address_space_end - 1; 404 addr + size - 1 <= m_address_space_end - 1;
438 } 405 }
406 constexpr bool IsInAliasRegion(KProcessAddress addr, size_t size) const {
407 return this->Contains(addr, size) && m_alias_region_start <= addr &&
408 addr + size - 1 <= m_alias_region_end - 1;
409 }
410 constexpr bool IsInHeapRegion(KProcessAddress addr, size_t size) const {
411 return this->Contains(addr, size) && m_heap_region_start <= addr &&
412 addr + size - 1 <= m_heap_region_end - 1;
413 }
439 414
440public: 415public:
441 static KVirtualAddress GetLinearMappedVirtualAddress(const KMemoryLayout& layout, 416 static KVirtualAddress GetLinearMappedVirtualAddress(const KMemoryLayout& layout,
diff --git a/src/core/hle/kernel/k_process.cpp b/src/core/hle/kernel/k_process.cpp
index efe86ad27..44c7cb22f 100644
--- a/src/core/hle/kernel/k_process.cpp
+++ b/src/core/hle/kernel/k_process.cpp
@@ -38,7 +38,7 @@ namespace {
38 */ 38 */
39void SetupMainThread(Core::System& system, KProcess& owner_process, u32 priority, 39void SetupMainThread(Core::System& system, KProcess& owner_process, u32 priority,
40 KProcessAddress stack_top) { 40 KProcessAddress stack_top) {
41 const KProcessAddress entry_point = owner_process.PageTable().GetCodeRegionStart(); 41 const KProcessAddress entry_point = owner_process.GetPageTable().GetCodeRegionStart();
42 ASSERT(owner_process.GetResourceLimit()->Reserve(LimitableResource::ThreadCountMax, 1)); 42 ASSERT(owner_process.GetResourceLimit()->Reserve(LimitableResource::ThreadCountMax, 1));
43 43
44 KThread* thread = KThread::Create(system.Kernel()); 44 KThread* thread = KThread::Create(system.Kernel());
diff --git a/src/core/hle/kernel/k_process.h b/src/core/hle/kernel/k_process.h
index 925981d06..c9b37e138 100644
--- a/src/core/hle/kernel/k_process.h
+++ b/src/core/hle/kernel/k_process.h
@@ -110,16 +110,6 @@ public:
110 ProcessType type, KResourceLimit* res_limit); 110 ProcessType type, KResourceLimit* res_limit);
111 111
112 /// Gets a reference to the process' page table. 112 /// Gets a reference to the process' page table.
113 KPageTable& PageTable() {
114 return m_page_table;
115 }
116
117 /// Gets const a reference to the process' page table.
118 const KPageTable& PageTable() const {
119 return m_page_table;
120 }
121
122 /// Gets a reference to the process' page table.
123 KPageTable& GetPageTable() { 113 KPageTable& GetPageTable() {
124 return m_page_table; 114 return m_page_table;
125 } 115 }
diff --git a/src/core/hle/kernel/k_shared_memory.cpp b/src/core/hle/kernel/k_shared_memory.cpp
index efb5699de..f713968f6 100644
--- a/src/core/hle/kernel/k_shared_memory.cpp
+++ b/src/core/hle/kernel/k_shared_memory.cpp
@@ -90,8 +90,8 @@ Result KSharedMemory::Map(KProcess& target_process, KProcessAddress address, std
90 R_UNLESS(map_perm == test_perm, ResultInvalidNewMemoryPermission); 90 R_UNLESS(map_perm == test_perm, ResultInvalidNewMemoryPermission);
91 } 91 }
92 92
93 R_RETURN(target_process.PageTable().MapPageGroup(address, *m_page_group, KMemoryState::Shared, 93 R_RETURN(target_process.GetPageTable().MapPageGroup(
94 ConvertToKMemoryPermission(map_perm))); 94 address, *m_page_group, KMemoryState::Shared, ConvertToKMemoryPermission(map_perm)));
95} 95}
96 96
97Result KSharedMemory::Unmap(KProcess& target_process, KProcessAddress address, 97Result KSharedMemory::Unmap(KProcess& target_process, KProcessAddress address,
@@ -100,7 +100,7 @@ Result KSharedMemory::Unmap(KProcess& target_process, KProcessAddress address,
100 R_UNLESS(m_size == unmap_size, ResultInvalidSize); 100 R_UNLESS(m_size == unmap_size, ResultInvalidSize);
101 101
102 R_RETURN( 102 R_RETURN(
103 target_process.PageTable().UnmapPageGroup(address, *m_page_group, KMemoryState::Shared)); 103 target_process.GetPageTable().UnmapPageGroup(address, *m_page_group, KMemoryState::Shared));
104} 104}
105 105
106} // namespace Kernel 106} // namespace Kernel
diff --git a/src/core/hle/kernel/k_thread_local_page.cpp b/src/core/hle/kernel/k_thread_local_page.cpp
index b4a1e3cdb..2c45b4232 100644
--- a/src/core/hle/kernel/k_thread_local_page.cpp
+++ b/src/core/hle/kernel/k_thread_local_page.cpp
@@ -25,9 +25,9 @@ Result KThreadLocalPage::Initialize(KernelCore& kernel, KProcess* process) {
25 25
26 // Map the address in. 26 // Map the address in.
27 const auto phys_addr = kernel.System().DeviceMemory().GetPhysicalAddr(page_buf); 27 const auto phys_addr = kernel.System().DeviceMemory().GetPhysicalAddr(page_buf);
28 R_TRY(m_owner->PageTable().MapPages(std::addressof(m_virt_addr), 1, PageSize, phys_addr, 28 R_TRY(m_owner->GetPageTable().MapPages(std::addressof(m_virt_addr), 1, PageSize, phys_addr,
29 KMemoryState::ThreadLocal, 29 KMemoryState::ThreadLocal,
30 KMemoryPermission::UserReadWrite)); 30 KMemoryPermission::UserReadWrite));
31 31
32 // We succeeded. 32 // We succeeded.
33 page_buf_guard.Cancel(); 33 page_buf_guard.Cancel();
@@ -37,11 +37,11 @@ Result KThreadLocalPage::Initialize(KernelCore& kernel, KProcess* process) {
37 37
38Result KThreadLocalPage::Finalize() { 38Result KThreadLocalPage::Finalize() {
39 // Get the physical address of the page. 39 // Get the physical address of the page.
40 const KPhysicalAddress phys_addr = m_owner->PageTable().GetPhysicalAddr(m_virt_addr); 40 const KPhysicalAddress phys_addr = m_owner->GetPageTable().GetPhysicalAddr(m_virt_addr);
41 ASSERT(phys_addr); 41 ASSERT(phys_addr);
42 42
43 // Unmap the page. 43 // Unmap the page.
44 R_TRY(m_owner->PageTable().UnmapPages(this->GetAddress(), 1, KMemoryState::ThreadLocal)); 44 R_TRY(m_owner->GetPageTable().UnmapPages(this->GetAddress(), 1, KMemoryState::ThreadLocal));
45 45
46 // Free the page. 46 // Free the page.
47 KPageBuffer::Free(*m_kernel, KPageBuffer::FromPhysicalAddress(m_kernel->System(), phys_addr)); 47 KPageBuffer::Free(*m_kernel, KPageBuffer::FromPhysicalAddress(m_kernel->System(), phys_addr));
diff --git a/src/core/hle/kernel/svc/svc_cache.cpp b/src/core/hle/kernel/svc/svc_cache.cpp
index 082942dab..c2c8be10f 100644
--- a/src/core/hle/kernel/svc/svc_cache.cpp
+++ b/src/core/hle/kernel/svc/svc_cache.cpp
@@ -42,7 +42,7 @@ Result FlushProcessDataCache(Core::System& system, Handle process_handle, u64 ad
42 R_UNLESS(process.IsNotNull(), ResultInvalidHandle); 42 R_UNLESS(process.IsNotNull(), ResultInvalidHandle);
43 43
44 // Verify the region is within range. 44 // Verify the region is within range.
45 auto& page_table = process->PageTable(); 45 auto& page_table = process->GetPageTable();
46 R_UNLESS(page_table.Contains(address, size), ResultInvalidCurrentMemory); 46 R_UNLESS(page_table.Contains(address, size), ResultInvalidCurrentMemory);
47 47
48 // Perform the operation. 48 // Perform the operation.
diff --git a/src/core/hle/kernel/svc/svc_code_memory.cpp b/src/core/hle/kernel/svc/svc_code_memory.cpp
index 687baff82..bae4cb0cd 100644
--- a/src/core/hle/kernel/svc/svc_code_memory.cpp
+++ b/src/core/hle/kernel/svc/svc_code_memory.cpp
@@ -48,7 +48,7 @@ Result CreateCodeMemory(Core::System& system, Handle* out, u64 address, uint64_t
48 SCOPE_EXIT({ code_mem->Close(); }); 48 SCOPE_EXIT({ code_mem->Close(); });
49 49
50 // Verify that the region is in range. 50 // Verify that the region is in range.
51 R_UNLESS(GetCurrentProcess(system.Kernel()).PageTable().Contains(address, size), 51 R_UNLESS(GetCurrentProcess(system.Kernel()).GetPageTable().Contains(address, size),
52 ResultInvalidCurrentMemory); 52 ResultInvalidCurrentMemory);
53 53
54 // Initialize the code memory. 54 // Initialize the code memory.
@@ -92,7 +92,7 @@ Result ControlCodeMemory(Core::System& system, Handle code_memory_handle,
92 case CodeMemoryOperation::Map: { 92 case CodeMemoryOperation::Map: {
93 // Check that the region is in range. 93 // Check that the region is in range.
94 R_UNLESS(GetCurrentProcess(system.Kernel()) 94 R_UNLESS(GetCurrentProcess(system.Kernel())
95 .PageTable() 95 .GetPageTable()
96 .CanContain(address, size, KMemoryState::CodeOut), 96 .CanContain(address, size, KMemoryState::CodeOut),
97 ResultInvalidMemoryRegion); 97 ResultInvalidMemoryRegion);
98 98
@@ -105,7 +105,7 @@ Result ControlCodeMemory(Core::System& system, Handle code_memory_handle,
105 case CodeMemoryOperation::Unmap: { 105 case CodeMemoryOperation::Unmap: {
106 // Check that the region is in range. 106 // Check that the region is in range.
107 R_UNLESS(GetCurrentProcess(system.Kernel()) 107 R_UNLESS(GetCurrentProcess(system.Kernel())
108 .PageTable() 108 .GetPageTable()
109 .CanContain(address, size, KMemoryState::CodeOut), 109 .CanContain(address, size, KMemoryState::CodeOut),
110 ResultInvalidMemoryRegion); 110 ResultInvalidMemoryRegion);
111 111
@@ -117,8 +117,8 @@ Result ControlCodeMemory(Core::System& system, Handle code_memory_handle,
117 } break; 117 } break;
118 case CodeMemoryOperation::MapToOwner: { 118 case CodeMemoryOperation::MapToOwner: {
119 // Check that the region is in range. 119 // Check that the region is in range.
120 R_UNLESS(code_mem->GetOwner()->PageTable().CanContain(address, size, 120 R_UNLESS(code_mem->GetOwner()->GetPageTable().CanContain(address, size,
121 KMemoryState::GeneratedCode), 121 KMemoryState::GeneratedCode),
122 ResultInvalidMemoryRegion); 122 ResultInvalidMemoryRegion);
123 123
124 // Check the memory permission. 124 // Check the memory permission.
@@ -129,8 +129,8 @@ Result ControlCodeMemory(Core::System& system, Handle code_memory_handle,
129 } break; 129 } break;
130 case CodeMemoryOperation::UnmapFromOwner: { 130 case CodeMemoryOperation::UnmapFromOwner: {
131 // Check that the region is in range. 131 // Check that the region is in range.
132 R_UNLESS(code_mem->GetOwner()->PageTable().CanContain(address, size, 132 R_UNLESS(code_mem->GetOwner()->GetPageTable().CanContain(address, size,
133 KMemoryState::GeneratedCode), 133 KMemoryState::GeneratedCode),
134 ResultInvalidMemoryRegion); 134 ResultInvalidMemoryRegion);
135 135
136 // Check the memory permission. 136 // Check the memory permission.
diff --git a/src/core/hle/kernel/svc/svc_device_address_space.cpp b/src/core/hle/kernel/svc/svc_device_address_space.cpp
index ec3143e67..42add9473 100644
--- a/src/core/hle/kernel/svc/svc_device_address_space.cpp
+++ b/src/core/hle/kernel/svc/svc_device_address_space.cpp
@@ -107,7 +107,7 @@ Result MapDeviceAddressSpaceByForce(Core::System& system, Handle das_handle, Han
107 R_UNLESS(process.IsNotNull(), ResultInvalidHandle); 107 R_UNLESS(process.IsNotNull(), ResultInvalidHandle);
108 108
109 // Validate that the process address is within range. 109 // Validate that the process address is within range.
110 auto& page_table = process->PageTable(); 110 auto& page_table = process->GetPageTable();
111 R_UNLESS(page_table.Contains(process_address, size), ResultInvalidCurrentMemory); 111 R_UNLESS(page_table.Contains(process_address, size), ResultInvalidCurrentMemory);
112 112
113 // Map. 113 // Map.
@@ -148,7 +148,7 @@ Result MapDeviceAddressSpaceAligned(Core::System& system, Handle das_handle, Han
148 R_UNLESS(process.IsNotNull(), ResultInvalidHandle); 148 R_UNLESS(process.IsNotNull(), ResultInvalidHandle);
149 149
150 // Validate that the process address is within range. 150 // Validate that the process address is within range.
151 auto& page_table = process->PageTable(); 151 auto& page_table = process->GetPageTable();
152 R_UNLESS(page_table.Contains(process_address, size), ResultInvalidCurrentMemory); 152 R_UNLESS(page_table.Contains(process_address, size), ResultInvalidCurrentMemory);
153 153
154 // Map. 154 // Map.
@@ -180,7 +180,7 @@ Result UnmapDeviceAddressSpace(Core::System& system, Handle das_handle, Handle p
180 R_UNLESS(process.IsNotNull(), ResultInvalidHandle); 180 R_UNLESS(process.IsNotNull(), ResultInvalidHandle);
181 181
182 // Validate that the process address is within range. 182 // Validate that the process address is within range.
183 auto& page_table = process->PageTable(); 183 auto& page_table = process->GetPageTable();
184 R_UNLESS(page_table.Contains(process_address, size), ResultInvalidCurrentMemory); 184 R_UNLESS(page_table.Contains(process_address, size), ResultInvalidCurrentMemory);
185 185
186 R_RETURN(das->Unmap(std::addressof(page_table), process_address, size, device_address)); 186 R_RETURN(das->Unmap(std::addressof(page_table), process_address, size, device_address));
diff --git a/src/core/hle/kernel/svc/svc_info.cpp b/src/core/hle/kernel/svc/svc_info.cpp
index 445cdd87b..f99964028 100644
--- a/src/core/hle/kernel/svc/svc_info.cpp
+++ b/src/core/hle/kernel/svc/svc_info.cpp
@@ -54,35 +54,35 @@ Result GetInfo(Core::System& system, u64* result, InfoType info_id_type, Handle
54 R_SUCCEED(); 54 R_SUCCEED();
55 55
56 case InfoType::AliasRegionAddress: 56 case InfoType::AliasRegionAddress:
57 *result = GetInteger(process->PageTable().GetAliasRegionStart()); 57 *result = GetInteger(process->GetPageTable().GetAliasRegionStart());
58 R_SUCCEED(); 58 R_SUCCEED();
59 59
60 case InfoType::AliasRegionSize: 60 case InfoType::AliasRegionSize:
61 *result = process->PageTable().GetAliasRegionSize(); 61 *result = process->GetPageTable().GetAliasRegionSize();
62 R_SUCCEED(); 62 R_SUCCEED();
63 63
64 case InfoType::HeapRegionAddress: 64 case InfoType::HeapRegionAddress:
65 *result = GetInteger(process->PageTable().GetHeapRegionStart()); 65 *result = GetInteger(process->GetPageTable().GetHeapRegionStart());
66 R_SUCCEED(); 66 R_SUCCEED();
67 67
68 case InfoType::HeapRegionSize: 68 case InfoType::HeapRegionSize:
69 *result = process->PageTable().GetHeapRegionSize(); 69 *result = process->GetPageTable().GetHeapRegionSize();
70 R_SUCCEED(); 70 R_SUCCEED();
71 71
72 case InfoType::AslrRegionAddress: 72 case InfoType::AslrRegionAddress:
73 *result = GetInteger(process->PageTable().GetAliasCodeRegionStart()); 73 *result = GetInteger(process->GetPageTable().GetAliasCodeRegionStart());
74 R_SUCCEED(); 74 R_SUCCEED();
75 75
76 case InfoType::AslrRegionSize: 76 case InfoType::AslrRegionSize:
77 *result = process->PageTable().GetAliasCodeRegionSize(); 77 *result = process->GetPageTable().GetAliasCodeRegionSize();
78 R_SUCCEED(); 78 R_SUCCEED();
79 79
80 case InfoType::StackRegionAddress: 80 case InfoType::StackRegionAddress:
81 *result = GetInteger(process->PageTable().GetStackRegionStart()); 81 *result = GetInteger(process->GetPageTable().GetStackRegionStart());
82 R_SUCCEED(); 82 R_SUCCEED();
83 83
84 case InfoType::StackRegionSize: 84 case InfoType::StackRegionSize:
85 *result = process->PageTable().GetStackRegionSize(); 85 *result = process->GetPageTable().GetStackRegionSize();
86 R_SUCCEED(); 86 R_SUCCEED();
87 87
88 case InfoType::TotalMemorySize: 88 case InfoType::TotalMemorySize:
diff --git a/src/core/hle/kernel/svc/svc_memory.cpp b/src/core/hle/kernel/svc/svc_memory.cpp
index 5dcb7f045..2cab74127 100644
--- a/src/core/hle/kernel/svc/svc_memory.cpp
+++ b/src/core/hle/kernel/svc/svc_memory.cpp
@@ -63,36 +63,13 @@ Result MapUnmapMemorySanityChecks(const KPageTable& manager, u64 dst_addr, u64 s
63 R_THROW(ResultInvalidCurrentMemory); 63 R_THROW(ResultInvalidCurrentMemory);
64 } 64 }
65 65
66 if (!manager.IsInsideAddressSpace(src_addr, size)) { 66 if (!manager.Contains(src_addr, size)) {
67 LOG_ERROR(Kernel_SVC, 67 LOG_ERROR(Kernel_SVC,
68 "Source is not within the address space, addr=0x{:016X}, size=0x{:016X}", 68 "Source is not within the address space, addr=0x{:016X}, size=0x{:016X}",
69 src_addr, size); 69 src_addr, size);
70 R_THROW(ResultInvalidCurrentMemory); 70 R_THROW(ResultInvalidCurrentMemory);
71 } 71 }
72 72
73 if (manager.IsOutsideStackRegion(dst_addr, size)) {
74 LOG_ERROR(Kernel_SVC,
75 "Destination is not within the stack region, addr=0x{:016X}, size=0x{:016X}",
76 dst_addr, size);
77 R_THROW(ResultInvalidMemoryRegion);
78 }
79
80 if (manager.IsInsideHeapRegion(dst_addr, size)) {
81 LOG_ERROR(Kernel_SVC,
82 "Destination does not fit within the heap region, addr=0x{:016X}, "
83 "size=0x{:016X}",
84 dst_addr, size);
85 R_THROW(ResultInvalidMemoryRegion);
86 }
87
88 if (manager.IsInsideAliasRegion(dst_addr, size)) {
89 LOG_ERROR(Kernel_SVC,
90 "Destination does not fit within the map region, addr=0x{:016X}, "
91 "size=0x{:016X}",
92 dst_addr, size);
93 R_THROW(ResultInvalidMemoryRegion);
94 }
95
96 R_SUCCEED(); 73 R_SUCCEED();
97} 74}
98 75
@@ -112,7 +89,7 @@ Result SetMemoryPermission(Core::System& system, u64 address, u64 size, MemoryPe
112 R_UNLESS(IsValidSetMemoryPermission(perm), ResultInvalidNewMemoryPermission); 89 R_UNLESS(IsValidSetMemoryPermission(perm), ResultInvalidNewMemoryPermission);
113 90
114 // Validate that the region is in range for the current process. 91 // Validate that the region is in range for the current process.
115 auto& page_table = GetCurrentProcess(system.Kernel()).PageTable(); 92 auto& page_table = GetCurrentProcess(system.Kernel()).GetPageTable();
116 R_UNLESS(page_table.Contains(address, size), ResultInvalidCurrentMemory); 93 R_UNLESS(page_table.Contains(address, size), ResultInvalidCurrentMemory);
117 94
118 // Set the memory attribute. 95 // Set the memory attribute.
@@ -136,7 +113,7 @@ Result SetMemoryAttribute(Core::System& system, u64 address, u64 size, u32 mask,
136 R_UNLESS((mask | attr | SupportedMask) == SupportedMask, ResultInvalidCombination); 113 R_UNLESS((mask | attr | SupportedMask) == SupportedMask, ResultInvalidCombination);
137 114
138 // Validate that the region is in range for the current process. 115 // Validate that the region is in range for the current process.
139 auto& page_table{GetCurrentProcess(system.Kernel()).PageTable()}; 116 auto& page_table{GetCurrentProcess(system.Kernel()).GetPageTable()};
140 R_UNLESS(page_table.Contains(address, size), ResultInvalidCurrentMemory); 117 R_UNLESS(page_table.Contains(address, size), ResultInvalidCurrentMemory);
141 118
142 // Set the memory attribute. 119 // Set the memory attribute.
@@ -148,7 +125,7 @@ Result MapMemory(Core::System& system, u64 dst_addr, u64 src_addr, u64 size) {
148 LOG_TRACE(Kernel_SVC, "called, dst_addr=0x{:X}, src_addr=0x{:X}, size=0x{:X}", dst_addr, 125 LOG_TRACE(Kernel_SVC, "called, dst_addr=0x{:X}, src_addr=0x{:X}, size=0x{:X}", dst_addr,
149 src_addr, size); 126 src_addr, size);
150 127
151 auto& page_table{GetCurrentProcess(system.Kernel()).PageTable()}; 128 auto& page_table{GetCurrentProcess(system.Kernel()).GetPageTable()};
152 129
153 if (const Result result{MapUnmapMemorySanityChecks(page_table, dst_addr, src_addr, size)}; 130 if (const Result result{MapUnmapMemorySanityChecks(page_table, dst_addr, src_addr, size)};
154 result.IsError()) { 131 result.IsError()) {
@@ -163,7 +140,7 @@ Result UnmapMemory(Core::System& system, u64 dst_addr, u64 src_addr, u64 size) {
163 LOG_TRACE(Kernel_SVC, "called, dst_addr=0x{:X}, src_addr=0x{:X}, size=0x{:X}", dst_addr, 140 LOG_TRACE(Kernel_SVC, "called, dst_addr=0x{:X}, src_addr=0x{:X}, size=0x{:X}", dst_addr,
164 src_addr, size); 141 src_addr, size);
165 142
166 auto& page_table{GetCurrentProcess(system.Kernel()).PageTable()}; 143 auto& page_table{GetCurrentProcess(system.Kernel()).GetPageTable()};
167 144
168 if (const Result result{MapUnmapMemorySanityChecks(page_table, dst_addr, src_addr, size)}; 145 if (const Result result{MapUnmapMemorySanityChecks(page_table, dst_addr, src_addr, size)};
169 result.IsError()) { 146 result.IsError()) {
diff --git a/src/core/hle/kernel/svc/svc_physical_memory.cpp b/src/core/hle/kernel/svc/svc_physical_memory.cpp
index c2fbfb59a..d3545f232 100644
--- a/src/core/hle/kernel/svc/svc_physical_memory.cpp
+++ b/src/core/hle/kernel/svc/svc_physical_memory.cpp
@@ -16,7 +16,7 @@ Result SetHeapSize(Core::System& system, u64* out_address, u64 size) {
16 R_UNLESS(size < MainMemorySizeMax, ResultInvalidSize); 16 R_UNLESS(size < MainMemorySizeMax, ResultInvalidSize);
17 17
18 // Set the heap size. 18 // Set the heap size.
19 R_RETURN(GetCurrentProcess(system.Kernel()).PageTable().SetHeapSize(out_address, size)); 19 R_RETURN(GetCurrentProcess(system.Kernel()).GetPageTable().SetHeapSize(out_address, size));
20} 20}
21 21
22/// Maps memory at a desired address 22/// Maps memory at a desired address
@@ -44,21 +44,21 @@ Result MapPhysicalMemory(Core::System& system, u64 addr, u64 size) {
44 } 44 }
45 45
46 KProcess* const current_process{GetCurrentProcessPointer(system.Kernel())}; 46 KProcess* const current_process{GetCurrentProcessPointer(system.Kernel())};
47 auto& page_table{current_process->PageTable()}; 47 auto& page_table{current_process->GetPageTable()};
48 48
49 if (current_process->GetSystemResourceSize() == 0) { 49 if (current_process->GetSystemResourceSize() == 0) {
50 LOG_ERROR(Kernel_SVC, "System Resource Size is zero"); 50 LOG_ERROR(Kernel_SVC, "System Resource Size is zero");
51 R_THROW(ResultInvalidState); 51 R_THROW(ResultInvalidState);
52 } 52 }
53 53
54 if (!page_table.IsInsideAddressSpace(addr, size)) { 54 if (!page_table.Contains(addr, size)) {
55 LOG_ERROR(Kernel_SVC, 55 LOG_ERROR(Kernel_SVC,
56 "Address is not within the address space, addr=0x{:016X}, size=0x{:016X}", addr, 56 "Address is not within the address space, addr=0x{:016X}, size=0x{:016X}", addr,
57 size); 57 size);
58 R_THROW(ResultInvalidMemoryRegion); 58 R_THROW(ResultInvalidMemoryRegion);
59 } 59 }
60 60
61 if (page_table.IsOutsideAliasRegion(addr, size)) { 61 if (!page_table.IsInAliasRegion(addr, size)) {
62 LOG_ERROR(Kernel_SVC, 62 LOG_ERROR(Kernel_SVC,
63 "Address is not within the alias region, addr=0x{:016X}, size=0x{:016X}", addr, 63 "Address is not within the alias region, addr=0x{:016X}, size=0x{:016X}", addr,
64 size); 64 size);
@@ -93,21 +93,21 @@ Result UnmapPhysicalMemory(Core::System& system, u64 addr, u64 size) {
93 } 93 }
94 94
95 KProcess* const current_process{GetCurrentProcessPointer(system.Kernel())}; 95 KProcess* const current_process{GetCurrentProcessPointer(system.Kernel())};
96 auto& page_table{current_process->PageTable()}; 96 auto& page_table{current_process->GetPageTable()};
97 97
98 if (current_process->GetSystemResourceSize() == 0) { 98 if (current_process->GetSystemResourceSize() == 0) {
99 LOG_ERROR(Kernel_SVC, "System Resource Size is zero"); 99 LOG_ERROR(Kernel_SVC, "System Resource Size is zero");
100 R_THROW(ResultInvalidState); 100 R_THROW(ResultInvalidState);
101 } 101 }
102 102
103 if (!page_table.IsInsideAddressSpace(addr, size)) { 103 if (!page_table.Contains(addr, size)) {
104 LOG_ERROR(Kernel_SVC, 104 LOG_ERROR(Kernel_SVC,
105 "Address is not within the address space, addr=0x{:016X}, size=0x{:016X}", addr, 105 "Address is not within the address space, addr=0x{:016X}, size=0x{:016X}", addr,
106 size); 106 size);
107 R_THROW(ResultInvalidMemoryRegion); 107 R_THROW(ResultInvalidMemoryRegion);
108 } 108 }
109 109
110 if (page_table.IsOutsideAliasRegion(addr, size)) { 110 if (!page_table.IsInAliasRegion(addr, size)) {
111 LOG_ERROR(Kernel_SVC, 111 LOG_ERROR(Kernel_SVC,
112 "Address is not within the alias region, addr=0x{:016X}, size=0x{:016X}", addr, 112 "Address is not within the alias region, addr=0x{:016X}, size=0x{:016X}", addr,
113 size); 113 size);
diff --git a/src/core/hle/kernel/svc/svc_process.cpp b/src/core/hle/kernel/svc/svc_process.cpp
index 619ed16a3..caa8bee9a 100644
--- a/src/core/hle/kernel/svc/svc_process.cpp
+++ b/src/core/hle/kernel/svc/svc_process.cpp
@@ -66,8 +66,8 @@ Result GetProcessList(Core::System& system, s32* out_num_processes, u64 out_proc
66 auto& kernel = system.Kernel(); 66 auto& kernel = system.Kernel();
67 const auto total_copy_size = out_process_ids_size * sizeof(u64); 67 const auto total_copy_size = out_process_ids_size * sizeof(u64);
68 68
69 if (out_process_ids_size > 0 && !GetCurrentProcess(kernel).PageTable().IsInsideAddressSpace( 69 if (out_process_ids_size > 0 &&
70 out_process_ids, total_copy_size)) { 70 !GetCurrentProcess(kernel).GetPageTable().Contains(out_process_ids, total_copy_size)) {
71 LOG_ERROR(Kernel_SVC, "Address range outside address space. begin=0x{:016X}, end=0x{:016X}", 71 LOG_ERROR(Kernel_SVC, "Address range outside address space. begin=0x{:016X}, end=0x{:016X}",
72 out_process_ids, out_process_ids + total_copy_size); 72 out_process_ids, out_process_ids + total_copy_size);
73 R_THROW(ResultInvalidCurrentMemory); 73 R_THROW(ResultInvalidCurrentMemory);
diff --git a/src/core/hle/kernel/svc/svc_process_memory.cpp b/src/core/hle/kernel/svc/svc_process_memory.cpp
index aee0f2f36..07cd48175 100644
--- a/src/core/hle/kernel/svc/svc_process_memory.cpp
+++ b/src/core/hle/kernel/svc/svc_process_memory.cpp
@@ -49,7 +49,7 @@ Result SetProcessMemoryPermission(Core::System& system, Handle process_handle, u
49 R_UNLESS(process.IsNotNull(), ResultInvalidHandle); 49 R_UNLESS(process.IsNotNull(), ResultInvalidHandle);
50 50
51 // Validate that the address is in range. 51 // Validate that the address is in range.
52 auto& page_table = process->PageTable(); 52 auto& page_table = process->GetPageTable();
53 R_UNLESS(page_table.Contains(address, size), ResultInvalidCurrentMemory); 53 R_UNLESS(page_table.Contains(address, size), ResultInvalidCurrentMemory);
54 54
55 // Set the memory permission. 55 // Set the memory permission.
@@ -77,8 +77,8 @@ Result MapProcessMemory(Core::System& system, u64 dst_address, Handle process_ha
77 R_UNLESS(src_process.IsNotNull(), ResultInvalidHandle); 77 R_UNLESS(src_process.IsNotNull(), ResultInvalidHandle);
78 78
79 // Get the page tables. 79 // Get the page tables.
80 auto& dst_pt = dst_process->PageTable(); 80 auto& dst_pt = dst_process->GetPageTable();
81 auto& src_pt = src_process->PageTable(); 81 auto& src_pt = src_process->GetPageTable();
82 82
83 // Validate that the mapping is in range. 83 // Validate that the mapping is in range.
84 R_UNLESS(src_pt.Contains(src_address, size), ResultInvalidCurrentMemory); 84 R_UNLESS(src_pt.Contains(src_address, size), ResultInvalidCurrentMemory);
@@ -118,8 +118,8 @@ Result UnmapProcessMemory(Core::System& system, u64 dst_address, Handle process_
118 R_UNLESS(src_process.IsNotNull(), ResultInvalidHandle); 118 R_UNLESS(src_process.IsNotNull(), ResultInvalidHandle);
119 119
120 // Get the page tables. 120 // Get the page tables.
121 auto& dst_pt = dst_process->PageTable(); 121 auto& dst_pt = dst_process->GetPageTable();
122 auto& src_pt = src_process->PageTable(); 122 auto& src_pt = src_process->GetPageTable();
123 123
124 // Validate that the mapping is in range. 124 // Validate that the mapping is in range.
125 R_UNLESS(src_pt.Contains(src_address, size), ResultInvalidCurrentMemory); 125 R_UNLESS(src_pt.Contains(src_address, size), ResultInvalidCurrentMemory);
@@ -178,8 +178,8 @@ Result MapProcessCodeMemory(Core::System& system, Handle process_handle, u64 dst
178 R_THROW(ResultInvalidHandle); 178 R_THROW(ResultInvalidHandle);
179 } 179 }
180 180
181 auto& page_table = process->PageTable(); 181 auto& page_table = process->GetPageTable();
182 if (!page_table.IsInsideAddressSpace(src_address, size)) { 182 if (!page_table.Contains(src_address, size)) {
183 LOG_ERROR(Kernel_SVC, 183 LOG_ERROR(Kernel_SVC,
184 "Source address range is not within the address space (src_address=0x{:016X}, " 184 "Source address range is not within the address space (src_address=0x{:016X}, "
185 "size=0x{:016X}).", 185 "size=0x{:016X}).",
@@ -187,14 +187,6 @@ Result MapProcessCodeMemory(Core::System& system, Handle process_handle, u64 dst
187 R_THROW(ResultInvalidCurrentMemory); 187 R_THROW(ResultInvalidCurrentMemory);
188 } 188 }
189 189
190 if (!page_table.IsInsideASLRRegion(dst_address, size)) {
191 LOG_ERROR(Kernel_SVC,
192 "Destination address range is not within the ASLR region (dst_address=0x{:016X}, "
193 "size=0x{:016X}).",
194 dst_address, size);
195 R_THROW(ResultInvalidMemoryRegion);
196 }
197
198 R_RETURN(page_table.MapCodeMemory(dst_address, src_address, size)); 190 R_RETURN(page_table.MapCodeMemory(dst_address, src_address, size));
199} 191}
200 192
@@ -246,8 +238,8 @@ Result UnmapProcessCodeMemory(Core::System& system, Handle process_handle, u64 d
246 R_THROW(ResultInvalidHandle); 238 R_THROW(ResultInvalidHandle);
247 } 239 }
248 240
249 auto& page_table = process->PageTable(); 241 auto& page_table = process->GetPageTable();
250 if (!page_table.IsInsideAddressSpace(src_address, size)) { 242 if (!page_table.Contains(src_address, size)) {
251 LOG_ERROR(Kernel_SVC, 243 LOG_ERROR(Kernel_SVC,
252 "Source address range is not within the address space (src_address=0x{:016X}, " 244 "Source address range is not within the address space (src_address=0x{:016X}, "
253 "size=0x{:016X}).", 245 "size=0x{:016X}).",
@@ -255,14 +247,6 @@ Result UnmapProcessCodeMemory(Core::System& system, Handle process_handle, u64 d
255 R_THROW(ResultInvalidCurrentMemory); 247 R_THROW(ResultInvalidCurrentMemory);
256 } 248 }
257 249
258 if (!page_table.IsInsideASLRRegion(dst_address, size)) {
259 LOG_ERROR(Kernel_SVC,
260 "Destination address range is not within the ASLR region (dst_address=0x{:016X}, "
261 "size=0x{:016X}).",
262 dst_address, size);
263 R_THROW(ResultInvalidMemoryRegion);
264 }
265
266 R_RETURN(page_table.UnmapCodeMemory(dst_address, src_address, size, 250 R_RETURN(page_table.UnmapCodeMemory(dst_address, src_address, size,
267 KPageTable::ICacheInvalidationStrategy::InvalidateAll)); 251 KPageTable::ICacheInvalidationStrategy::InvalidateAll));
268} 252}
diff --git a/src/core/hle/kernel/svc/svc_query_memory.cpp b/src/core/hle/kernel/svc/svc_query_memory.cpp
index 4d9fcd25f..51af06e97 100644
--- a/src/core/hle/kernel/svc/svc_query_memory.cpp
+++ b/src/core/hle/kernel/svc/svc_query_memory.cpp
@@ -31,7 +31,7 @@ Result QueryProcessMemory(Core::System& system, uint64_t out_memory_info, PageIn
31 } 31 }
32 32
33 auto& current_memory{GetCurrentMemory(system.Kernel())}; 33 auto& current_memory{GetCurrentMemory(system.Kernel())};
34 const auto memory_info{process->PageTable().QueryInfo(address).GetSvcMemoryInfo()}; 34 const auto memory_info{process->GetPageTable().QueryInfo(address).GetSvcMemoryInfo()};
35 35
36 current_memory.WriteBlock(out_memory_info, std::addressof(memory_info), sizeof(memory_info)); 36 current_memory.WriteBlock(out_memory_info, std::addressof(memory_info), sizeof(memory_info));
37 37
diff --git a/src/core/hle/kernel/svc/svc_shared_memory.cpp b/src/core/hle/kernel/svc/svc_shared_memory.cpp
index a698596aa..012b1ae2b 100644
--- a/src/core/hle/kernel/svc/svc_shared_memory.cpp
+++ b/src/core/hle/kernel/svc/svc_shared_memory.cpp
@@ -43,7 +43,7 @@ Result MapSharedMemory(Core::System& system, Handle shmem_handle, u64 address, u
43 43
44 // Get the current process. 44 // Get the current process.
45 auto& process = GetCurrentProcess(system.Kernel()); 45 auto& process = GetCurrentProcess(system.Kernel());
46 auto& page_table = process.PageTable(); 46 auto& page_table = process.GetPageTable();
47 47
48 // Get the shared memory. 48 // Get the shared memory.
49 KScopedAutoObject shmem = process.GetHandleTable().GetObject<KSharedMemory>(shmem_handle); 49 KScopedAutoObject shmem = process.GetHandleTable().GetObject<KSharedMemory>(shmem_handle);
@@ -73,7 +73,7 @@ Result UnmapSharedMemory(Core::System& system, Handle shmem_handle, u64 address,
73 73
74 // Get the current process. 74 // Get the current process.
75 auto& process = GetCurrentProcess(system.Kernel()); 75 auto& process = GetCurrentProcess(system.Kernel());
76 auto& page_table = process.PageTable(); 76 auto& page_table = process.GetPageTable();
77 77
78 // Get the shared memory. 78 // Get the shared memory.
79 KScopedAutoObject shmem = process.GetHandleTable().GetObject<KSharedMemory>(shmem_handle); 79 KScopedAutoObject shmem = process.GetHandleTable().GetObject<KSharedMemory>(shmem_handle);
diff --git a/src/core/hle/kernel/svc/svc_thread.cpp b/src/core/hle/kernel/svc/svc_thread.cpp
index 36b94e6bf..92bcea72b 100644
--- a/src/core/hle/kernel/svc/svc_thread.cpp
+++ b/src/core/hle/kernel/svc/svc_thread.cpp
@@ -236,7 +236,7 @@ Result GetThreadList(Core::System& system, s32* out_num_threads, u64 out_thread_
236 const auto total_copy_size = out_thread_ids_size * sizeof(u64); 236 const auto total_copy_size = out_thread_ids_size * sizeof(u64);
237 237
238 if (out_thread_ids_size > 0 && 238 if (out_thread_ids_size > 0 &&
239 !current_process->PageTable().IsInsideAddressSpace(out_thread_ids, total_copy_size)) { 239 !current_process->GetPageTable().Contains(out_thread_ids, total_copy_size)) {
240 LOG_ERROR(Kernel_SVC, "Address range outside address space. begin=0x{:016X}, end=0x{:016X}", 240 LOG_ERROR(Kernel_SVC, "Address range outside address space. begin=0x{:016X}, end=0x{:016X}",
241 out_thread_ids, out_thread_ids + total_copy_size); 241 out_thread_ids, out_thread_ids + total_copy_size);
242 R_THROW(ResultInvalidCurrentMemory); 242 R_THROW(ResultInvalidCurrentMemory);
diff --git a/src/core/hle/kernel/svc/svc_transfer_memory.cpp b/src/core/hle/kernel/svc/svc_transfer_memory.cpp
index 82d469a37..7d94e7f09 100644
--- a/src/core/hle/kernel/svc/svc_transfer_memory.cpp
+++ b/src/core/hle/kernel/svc/svc_transfer_memory.cpp
@@ -55,7 +55,7 @@ Result CreateTransferMemory(Core::System& system, Handle* out, u64 address, u64
55 SCOPE_EXIT({ trmem->Close(); }); 55 SCOPE_EXIT({ trmem->Close(); });
56 56
57 // Ensure that the region is in range. 57 // Ensure that the region is in range.
58 R_UNLESS(process.PageTable().Contains(address, size), ResultInvalidCurrentMemory); 58 R_UNLESS(process.GetPageTable().Contains(address, size), ResultInvalidCurrentMemory);
59 59
60 // Initialize the transfer memory. 60 // Initialize the transfer memory.
61 R_TRY(trmem->Initialize(address, size, map_perm)); 61 R_TRY(trmem->Initialize(address, size, map_perm));
diff --git a/src/core/hle/service/ldr/ldr.cpp b/src/core/hle/service/ldr/ldr.cpp
index c42489ff9..055c0a2db 100644
--- a/src/core/hle/service/ldr/ldr.cpp
+++ b/src/core/hle/service/ldr/ldr.cpp
@@ -318,15 +318,15 @@ public:
318 return false; 318 return false;
319 } 319 }
320 320
321 if (!page_table.IsInsideAddressSpace(out_addr, size)) { 321 if (!page_table.Contains(out_addr, size)) {
322 return false; 322 return false;
323 } 323 }
324 324
325 if (page_table.IsInsideHeapRegion(out_addr, size)) { 325 if (page_table.IsInHeapRegion(out_addr, size)) {
326 return false; 326 return false;
327 } 327 }
328 328
329 if (page_table.IsInsideAliasRegion(out_addr, size)) { 329 if (page_table.IsInAliasRegion(out_addr, size)) {
330 return false; 330 return false;
331 } 331 }
332 332
@@ -358,7 +358,7 @@ public:
358 } 358 }
359 359
360 ResultVal<VAddr> MapProcessCodeMemory(Kernel::KProcess* process, VAddr base_addr, u64 size) { 360 ResultVal<VAddr> MapProcessCodeMemory(Kernel::KProcess* process, VAddr base_addr, u64 size) {
361 auto& page_table{process->PageTable()}; 361 auto& page_table{process->GetPageTable()};
362 VAddr addr{}; 362 VAddr addr{};
363 363
364 for (std::size_t retry = 0; retry < MAXIMUM_MAP_RETRIES; retry++) { 364 for (std::size_t retry = 0; retry < MAXIMUM_MAP_RETRIES; retry++) {
@@ -382,7 +382,7 @@ public:
382 ResultVal<VAddr> MapNro(Kernel::KProcess* process, VAddr nro_addr, std::size_t nro_size, 382 ResultVal<VAddr> MapNro(Kernel::KProcess* process, VAddr nro_addr, std::size_t nro_size,
383 VAddr bss_addr, std::size_t bss_size, std::size_t size) { 383 VAddr bss_addr, std::size_t bss_size, std::size_t size) {
384 for (std::size_t retry = 0; retry < MAXIMUM_MAP_RETRIES; retry++) { 384 for (std::size_t retry = 0; retry < MAXIMUM_MAP_RETRIES; retry++) {
385 auto& page_table{process->PageTable()}; 385 auto& page_table{process->GetPageTable()};
386 VAddr addr{}; 386 VAddr addr{};
387 387
388 CASCADE_RESULT(addr, MapProcessCodeMemory(process, nro_addr, nro_size)); 388 CASCADE_RESULT(addr, MapProcessCodeMemory(process, nro_addr, nro_size));
@@ -437,12 +437,12 @@ public:
437 CopyCode(nro_addr + nro_header.segment_headers[DATA_INDEX].memory_offset, data_start, 437 CopyCode(nro_addr + nro_header.segment_headers[DATA_INDEX].memory_offset, data_start,
438 nro_header.segment_headers[DATA_INDEX].memory_size); 438 nro_header.segment_headers[DATA_INDEX].memory_size);
439 439
440 CASCADE_CODE(process->PageTable().SetProcessMemoryPermission( 440 CASCADE_CODE(process->GetPageTable().SetProcessMemoryPermission(
441 text_start, ro_start - text_start, Kernel::Svc::MemoryPermission::ReadExecute)); 441 text_start, ro_start - text_start, Kernel::Svc::MemoryPermission::ReadExecute));
442 CASCADE_CODE(process->PageTable().SetProcessMemoryPermission( 442 CASCADE_CODE(process->GetPageTable().SetProcessMemoryPermission(
443 ro_start, data_start - ro_start, Kernel::Svc::MemoryPermission::Read)); 443 ro_start, data_start - ro_start, Kernel::Svc::MemoryPermission::Read));
444 444
445 return process->PageTable().SetProcessMemoryPermission( 445 return process->GetPageTable().SetProcessMemoryPermission(
446 data_start, bss_end_addr - data_start, Kernel::Svc::MemoryPermission::ReadWrite); 446 data_start, bss_end_addr - data_start, Kernel::Svc::MemoryPermission::ReadWrite);
447 } 447 }
448 448
@@ -571,7 +571,7 @@ public:
571 571
572 Result UnmapNro(const NROInfo& info) { 572 Result UnmapNro(const NROInfo& info) {
573 // Each region must be unmapped separately to validate memory state 573 // Each region must be unmapped separately to validate memory state
574 auto& page_table{system.ApplicationProcess()->PageTable()}; 574 auto& page_table{system.ApplicationProcess()->GetPageTable()};
575 575
576 if (info.bss_size != 0) { 576 if (info.bss_size != 0) {
577 CASCADE_CODE(page_table.UnmapCodeMemory( 577 CASCADE_CODE(page_table.UnmapCodeMemory(
@@ -643,7 +643,7 @@ public:
643 643
644 initialized = true; 644 initialized = true;
645 current_map_addr = 645 current_map_addr =
646 GetInteger(system.ApplicationProcess()->PageTable().GetAliasCodeRegionStart()); 646 GetInteger(system.ApplicationProcess()->GetPageTable().GetAliasCodeRegionStart());
647 647
648 IPC::ResponseBuilder rb{ctx, 2}; 648 IPC::ResponseBuilder rb{ctx, 2};
649 rb.Push(ResultSuccess); 649 rb.Push(ResultSuccess);
diff --git a/src/core/hle/service/nvdrv/devices/nvmap.cpp b/src/core/hle/service/nvdrv/devices/nvmap.cpp
index e7f7e273b..968eaa175 100644
--- a/src/core/hle/service/nvdrv/devices/nvmap.cpp
+++ b/src/core/hle/service/nvdrv/devices/nvmap.cpp
@@ -128,7 +128,7 @@ NvResult nvmap::IocAlloc(std::span<const u8> input, std::span<u8> output) {
128 } 128 }
129 bool is_out_io{}; 129 bool is_out_io{};
130 ASSERT(system.ApplicationProcess() 130 ASSERT(system.ApplicationProcess()
131 ->PageTable() 131 ->GetPageTable()
132 .LockForMapDeviceAddressSpace(&is_out_io, handle_description->address, 132 .LockForMapDeviceAddressSpace(&is_out_io, handle_description->address,
133 handle_description->size, 133 handle_description->size,
134 Kernel::KMemoryPermission::None, true, false) 134 Kernel::KMemoryPermission::None, true, false)
@@ -255,7 +255,7 @@ NvResult nvmap::IocFree(std::span<const u8> input, std::span<u8> output) {
255 if (auto freeInfo{file.FreeHandle(params.handle, false)}) { 255 if (auto freeInfo{file.FreeHandle(params.handle, false)}) {
256 if (freeInfo->can_unlock) { 256 if (freeInfo->can_unlock) {
257 ASSERT(system.ApplicationProcess() 257 ASSERT(system.ApplicationProcess()
258 ->PageTable() 258 ->GetPageTable()
259 .UnlockForDeviceAddressSpace(freeInfo->address, freeInfo->size) 259 .UnlockForDeviceAddressSpace(freeInfo->address, freeInfo->size)
260 .IsSuccess()); 260 .IsSuccess());
261 } 261 }
diff --git a/src/core/loader/deconstructed_rom_directory.cpp b/src/core/loader/deconstructed_rom_directory.cpp
index 3be9b71cf..e04ad19db 100644
--- a/src/core/loader/deconstructed_rom_directory.cpp
+++ b/src/core/loader/deconstructed_rom_directory.cpp
@@ -153,7 +153,7 @@ AppLoader_DeconstructedRomDirectory::LoadResult AppLoader_DeconstructedRomDirect
153 153
154 // Load NSO modules 154 // Load NSO modules
155 modules.clear(); 155 modules.clear();
156 const VAddr base_address{GetInteger(process.PageTable().GetCodeRegionStart())}; 156 const VAddr base_address{GetInteger(process.GetPageTable().GetCodeRegionStart())};
157 VAddr next_load_addr{base_address}; 157 VAddr next_load_addr{base_address};
158 const FileSys::PatchManager pm{metadata.GetTitleID(), system.GetFileSystemController(), 158 const FileSys::PatchManager pm{metadata.GetTitleID(), system.GetFileSystemController(),
159 system.GetContentProvider()}; 159 system.GetContentProvider()};
diff --git a/src/core/loader/kip.cpp b/src/core/loader/kip.cpp
index 709e2564f..ffe976b94 100644
--- a/src/core/loader/kip.cpp
+++ b/src/core/loader/kip.cpp
@@ -96,7 +96,7 @@ AppLoader::LoadResult AppLoader_KIP::Load(Kernel::KProcess& process,
96 } 96 }
97 97
98 codeset.memory = std::move(program_image); 98 codeset.memory = std::move(program_image);
99 const VAddr base_address = GetInteger(process.PageTable().GetCodeRegionStart()); 99 const VAddr base_address = GetInteger(process.GetPageTable().GetCodeRegionStart());
100 process.LoadModule(std::move(codeset), base_address); 100 process.LoadModule(std::move(codeset), base_address);
101 101
102 LOG_DEBUG(Loader, "loaded module {} @ 0x{:X}", kip->GetName(), base_address); 102 LOG_DEBUG(Loader, "loaded module {} @ 0x{:X}", kip->GetName(), base_address);
diff --git a/src/core/loader/nro.cpp b/src/core/loader/nro.cpp
index 7be6cf5f3..506808b5d 100644
--- a/src/core/loader/nro.cpp
+++ b/src/core/loader/nro.cpp
@@ -203,7 +203,7 @@ static bool LoadNroImpl(Kernel::KProcess& process, const std::vector<u8>& data)
203 203
204 // Load codeset for current process 204 // Load codeset for current process
205 codeset.memory = std::move(program_image); 205 codeset.memory = std::move(program_image);
206 process.LoadModule(std::move(codeset), process.PageTable().GetCodeRegionStart()); 206 process.LoadModule(std::move(codeset), process.GetPageTable().GetCodeRegionStart());
207 207
208 return true; 208 return true;
209} 209}
diff --git a/src/core/loader/nso.cpp b/src/core/loader/nso.cpp
index 79639f5e4..74cc9579f 100644
--- a/src/core/loader/nso.cpp
+++ b/src/core/loader/nso.cpp
@@ -167,7 +167,7 @@ AppLoader_NSO::LoadResult AppLoader_NSO::Load(Kernel::KProcess& process, Core::S
167 modules.clear(); 167 modules.clear();
168 168
169 // Load module 169 // Load module
170 const VAddr base_address = GetInteger(process.PageTable().GetCodeRegionStart()); 170 const VAddr base_address = GetInteger(process.GetPageTable().GetCodeRegionStart());
171 if (!LoadModule(process, system, *file, base_address, true, true)) { 171 if (!LoadModule(process, system, *file, base_address, true, true)) {
172 return {ResultStatus::ErrorLoadingNSO, {}}; 172 return {ResultStatus::ErrorLoadingNSO, {}};
173 } 173 }
diff --git a/src/core/memory.cpp b/src/core/memory.cpp
index 805963178..e1fbe8e00 100644
--- a/src/core/memory.cpp
+++ b/src/core/memory.cpp
@@ -31,10 +31,10 @@ struct Memory::Impl {
31 explicit Impl(Core::System& system_) : system{system_} {} 31 explicit Impl(Core::System& system_) : system{system_} {}
32 32
33 void SetCurrentPageTable(Kernel::KProcess& process, u32 core_id) { 33 void SetCurrentPageTable(Kernel::KProcess& process, u32 core_id) {
34 current_page_table = &process.PageTable().PageTableImpl(); 34 current_page_table = &process.GetPageTable().PageTableImpl();
35 current_page_table->fastmem_arena = system.DeviceMemory().buffer.VirtualBasePointer(); 35 current_page_table->fastmem_arena = system.DeviceMemory().buffer.VirtualBasePointer();
36 36
37 const std::size_t address_space_width = process.PageTable().GetAddressSpaceWidth(); 37 const std::size_t address_space_width = process.GetPageTable().GetAddressSpaceWidth();
38 38
39 system.ArmInterface(core_id).PageTableChanged(*current_page_table, address_space_width); 39 system.ArmInterface(core_id).PageTableChanged(*current_page_table, address_space_width);
40 } 40 }
@@ -186,7 +186,7 @@ struct Memory::Impl {
186 void WalkBlock(const Kernel::KProcess& process, const Common::ProcessAddress addr, 186 void WalkBlock(const Kernel::KProcess& process, const Common::ProcessAddress addr,
187 const std::size_t size, auto on_unmapped, auto on_memory, auto on_rasterizer, 187 const std::size_t size, auto on_unmapped, auto on_memory, auto on_rasterizer,
188 auto increment) { 188 auto increment) {
189 const auto& page_table = process.PageTable().PageTableImpl(); 189 const auto& page_table = process.GetPageTable().PageTableImpl();
190 std::size_t remaining_size = size; 190 std::size_t remaining_size = size;
191 std::size_t page_index = addr >> YUZU_PAGEBITS; 191 std::size_t page_index = addr >> YUZU_PAGEBITS;
192 std::size_t page_offset = addr & YUZU_PAGEMASK; 192 std::size_t page_offset = addr & YUZU_PAGEMASK;
@@ -808,7 +808,7 @@ void Memory::UnmapRegion(Common::PageTable& page_table, Common::ProcessAddress b
808 808
809bool Memory::IsValidVirtualAddress(const Common::ProcessAddress vaddr) const { 809bool Memory::IsValidVirtualAddress(const Common::ProcessAddress vaddr) const {
810 const Kernel::KProcess& process = *system.ApplicationProcess(); 810 const Kernel::KProcess& process = *system.ApplicationProcess();
811 const auto& page_table = process.PageTable().PageTableImpl(); 811 const auto& page_table = process.GetPageTable().PageTableImpl();
812 const size_t page = vaddr >> YUZU_PAGEBITS; 812 const size_t page = vaddr >> YUZU_PAGEBITS;
813 if (page >= page_table.pointers.size()) { 813 if (page >= page_table.pointers.size()) {
814 return false; 814 return false;
diff --git a/src/core/memory/cheat_engine.cpp b/src/core/memory/cheat_engine.cpp
index 8742dd164..7b52f61a7 100644
--- a/src/core/memory/cheat_engine.cpp
+++ b/src/core/memory/cheat_engine.cpp
@@ -199,7 +199,7 @@ void CheatEngine::Initialize() {
199 metadata.process_id = system.ApplicationProcess()->GetProcessId(); 199 metadata.process_id = system.ApplicationProcess()->GetProcessId();
200 metadata.title_id = system.GetApplicationProcessProgramID(); 200 metadata.title_id = system.GetApplicationProcessProgramID();
201 201
202 const auto& page_table = system.ApplicationProcess()->PageTable(); 202 const auto& page_table = system.ApplicationProcess()->GetPageTable();
203 metadata.heap_extents = { 203 metadata.heap_extents = {
204 .base = GetInteger(page_table.GetHeapRegionStart()), 204 .base = GetInteger(page_table.GetHeapRegionStart()),
205 .size = page_table.GetHeapRegionSize(), 205 .size = page_table.GetHeapRegionSize(),
diff --git a/src/core/reporter.cpp b/src/core/reporter.cpp
index 6c3dc7369..b5b3e7eda 100644
--- a/src/core/reporter.cpp
+++ b/src/core/reporter.cpp
@@ -117,8 +117,8 @@ json GetProcessorStateDataAuto(Core::System& system) {
117 arm.SaveContext(context); 117 arm.SaveContext(context);
118 118
119 return GetProcessorStateData(process->Is64BitProcess() ? "AArch64" : "AArch32", 119 return GetProcessorStateData(process->Is64BitProcess() ? "AArch64" : "AArch32",
120 GetInteger(process->PageTable().GetCodeRegionStart()), context.sp, 120 GetInteger(process->GetPageTable().GetCodeRegionStart()),
121 context.pc, context.pstate, context.cpu_registers); 121 context.sp, context.pc, context.pstate, context.cpu_registers);
122} 122}
123 123
124json GetBacktraceData(Core::System& system) { 124json GetBacktraceData(Core::System& system) {