summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar liamwhite2023-07-28 09:29:21 -0400
committerGravatar GitHub2023-07-28 09:29:21 -0400
commit689dc4a17bb5f849b644705b54c3667db03d8f5d (patch)
tree85a33c90ee2a363b8540d97448b209db3ab33363 /src
parentMerge pull request #11156 from 8bitDream/localize (diff)
parentmemory: check page against address space size (diff)
downloadyuzu-689dc4a17bb5f849b644705b54c3667db03d8f5d.tar.gz
yuzu-689dc4a17bb5f849b644705b54c3667db03d8f5d.tar.xz
yuzu-689dc4a17bb5f849b644705b54c3667db03d8f5d.zip
Merge pull request #11155 from liamwhite/memory3
memory: check page against address space size
Diffstat (limited to 'src')
-rw-r--r--src/core/memory.cpp21
1 files changed, 18 insertions, 3 deletions
diff --git a/src/core/memory.cpp b/src/core/memory.cpp
index 513bc4edb..fa5273402 100644
--- a/src/core/memory.cpp
+++ b/src/core/memory.cpp
@@ -24,6 +24,16 @@
24 24
25namespace Core::Memory { 25namespace Core::Memory {
26 26
27namespace {
28
29bool AddressSpaceContains(const Common::PageTable& table, const Common::ProcessAddress addr,
30 const std::size_t size) {
31 const Common::ProcessAddress max_addr = 1ULL << table.GetAddressSpaceBits();
32 return addr + size >= addr && addr + size <= max_addr;
33}
34
35} // namespace
36
27// Implementation class used to keep the specifics of the memory subsystem hidden 37// Implementation class used to keep the specifics of the memory subsystem hidden
28// from outside classes. This also allows modification to the internals of the memory 38// from outside classes. This also allows modification to the internals of the memory
29// subsystem without needing to rebuild all files that make use of the memory interface. 39// subsystem without needing to rebuild all files that make use of the memory interface.
@@ -191,6 +201,11 @@ struct Memory::Impl {
191 std::size_t page_offset = addr & YUZU_PAGEMASK; 201 std::size_t page_offset = addr & YUZU_PAGEMASK;
192 bool user_accessible = true; 202 bool user_accessible = true;
193 203
204 if (!AddressSpaceContains(page_table, addr, size)) [[unlikely]] {
205 on_unmapped(size, addr);
206 return false;
207 }
208
194 while (remaining_size) { 209 while (remaining_size) {
195 const std::size_t copy_amount = 210 const std::size_t copy_amount =
196 std::min(static_cast<std::size_t>(YUZU_PAGESIZE) - page_offset, remaining_size); 211 std::min(static_cast<std::size_t>(YUZU_PAGESIZE) - page_offset, remaining_size);
@@ -421,7 +436,7 @@ struct Memory::Impl {
421 } 436 }
422 437
423 void MarkRegionDebug(u64 vaddr, u64 size, bool debug) { 438 void MarkRegionDebug(u64 vaddr, u64 size, bool debug) {
424 if (vaddr == 0) { 439 if (vaddr == 0 || !AddressSpaceContains(*current_page_table, vaddr, size)) {
425 return; 440 return;
426 } 441 }
427 442
@@ -478,7 +493,7 @@ struct Memory::Impl {
478 } 493 }
479 494
480 void RasterizerMarkRegionCached(u64 vaddr, u64 size, bool cached) { 495 void RasterizerMarkRegionCached(u64 vaddr, u64 size, bool cached) {
481 if (vaddr == 0) { 496 if (vaddr == 0 || !AddressSpaceContains(*current_page_table, vaddr, size)) {
482 return; 497 return;
483 } 498 }
484 499
@@ -615,7 +630,7 @@ struct Memory::Impl {
615 // AARCH64 masks the upper 16 bit of all memory accesses 630 // AARCH64 masks the upper 16 bit of all memory accesses
616 vaddr = vaddr & 0xffffffffffffULL; 631 vaddr = vaddr & 0xffffffffffffULL;
617 632
618 if (vaddr >= 1uLL << current_page_table->GetAddressSpaceBits()) { 633 if (!AddressSpaceContains(*current_page_table, vaddr, 1)) [[unlikely]] {
619 on_unmapped(); 634 on_unmapped();
620 return nullptr; 635 return nullptr;
621 } 636 }