summaryrefslogtreecommitdiff
path: root/src/core/memory.cpp
diff options
context:
space:
mode:
authorGravatar Lioncash2019-11-26 13:46:41 -0500
committerGravatar Lioncash2019-11-26 21:53:34 -0500
commite58748fd802dc069e90928d12d4db9ff994a869d (patch)
tree152c306a9a51f0ba49e2a34d1dc0db9eb2923013 /src/core/memory.cpp
parentcore/memory: Migrate over memory mapping functions to the new Memory class (diff)
downloadyuzu-e58748fd802dc069e90928d12d4db9ff994a869d.tar.gz
yuzu-e58748fd802dc069e90928d12d4db9ff994a869d.tar.xz
yuzu-e58748fd802dc069e90928d12d4db9ff994a869d.zip
core/memory: Migrate over address checking functions to the new Memory class
A fairly straightforward migration. These member functions can just be mostly moved verbatim with minor changes. We already have the necessary plumbing in places that they're used. IsKernelVirtualAddress() can remain a non-member function, since it doesn't rely on class state in any form.
Diffstat (limited to 'src/core/memory.cpp')
-rw-r--r--src/core/memory.cpp51
1 files changed, 31 insertions, 20 deletions
diff --git a/src/core/memory.cpp b/src/core/memory.cpp
index 28b65ca5e..4c13ea1e7 100644
--- a/src/core/memory.cpp
+++ b/src/core/memory.cpp
@@ -75,6 +75,29 @@ struct Memory::Impl {
75 std::make_pair(interval, std::set<Common::SpecialRegion>{region})); 75 std::make_pair(interval, std::set<Common::SpecialRegion>{region}));
76 } 76 }
77 77
78 bool IsValidVirtualAddress(const Kernel::Process& process, const VAddr vaddr) const {
79 const auto& page_table = process.VMManager().page_table;
80
81 const u8* const page_pointer = page_table.pointers[vaddr >> PAGE_BITS];
82 if (page_pointer != nullptr) {
83 return true;
84 }
85
86 if (page_table.attributes[vaddr >> PAGE_BITS] == Common::PageType::RasterizerCachedMemory) {
87 return true;
88 }
89
90 if (page_table.attributes[vaddr >> PAGE_BITS] != Common::PageType::Special) {
91 return false;
92 }
93
94 return false;
95 }
96
97 bool IsValidVirtualAddress(VAddr vaddr) const {
98 return IsValidVirtualAddress(*system.CurrentProcess(), vaddr);
99 }
100
78 /** 101 /**
79 * Maps a region of pages as a specific type. 102 * Maps a region of pages as a specific type.
80 * 103 *
@@ -148,6 +171,14 @@ void Memory::RemoveDebugHook(Common::PageTable& page_table, VAddr base, u64 size
148 impl->RemoveDebugHook(page_table, base, size, std::move(hook)); 171 impl->RemoveDebugHook(page_table, base, size, std::move(hook));
149} 172}
150 173
174bool Memory::IsValidVirtualAddress(const Kernel::Process& process, const VAddr vaddr) const {
175 return impl->IsValidVirtualAddress(process, vaddr);
176}
177
178bool Memory::IsValidVirtualAddress(const VAddr vaddr) const {
179 return impl->IsValidVirtualAddress(vaddr);
180}
181
151void SetCurrentPageTable(Kernel::Process& process) { 182void SetCurrentPageTable(Kernel::Process& process) {
152 current_page_table = &process.VMManager().page_table; 183 current_page_table = &process.VMManager().page_table;
153 184
@@ -256,26 +287,6 @@ void Write(const VAddr vaddr, const T data) {
256 } 287 }
257} 288}
258 289
259bool IsValidVirtualAddress(const Kernel::Process& process, const VAddr vaddr) {
260 const auto& page_table = process.VMManager().page_table;
261
262 const u8* page_pointer = page_table.pointers[vaddr >> PAGE_BITS];
263 if (page_pointer)
264 return true;
265
266 if (page_table.attributes[vaddr >> PAGE_BITS] == Common::PageType::RasterizerCachedMemory)
267 return true;
268
269 if (page_table.attributes[vaddr >> PAGE_BITS] != Common::PageType::Special)
270 return false;
271
272 return false;
273}
274
275bool IsValidVirtualAddress(const VAddr vaddr) {
276 return IsValidVirtualAddress(*Core::System::GetInstance().CurrentProcess(), vaddr);
277}
278
279bool IsKernelVirtualAddress(const VAddr vaddr) { 290bool IsKernelVirtualAddress(const VAddr vaddr) {
280 return KERNEL_REGION_VADDR <= vaddr && vaddr < KERNEL_REGION_END; 291 return KERNEL_REGION_VADDR <= vaddr && vaddr < KERNEL_REGION_END;
281} 292}