upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime/test/xmem_test.cpp
diff options
context:
space:
mode:
authorJan Trencansky <jan.trencansky@protonmail.com>2026-11-26 09:16:27 -0500
committerJan Trencansky <jan.trencansky@protonmail.com>2026-11-26 09:16:27 -0500
commitf5f67b4a9daae13d5a8a68358c1167e6866ec293 (patch)
treee9462d71f8ceabc75ff562e9c728df8a614637cf /runtime/test/xmem_test.cpp
parentf5113e3da53f278873b473f1db7b1b08dbc8ceb6 (diff)
parentd088ea79b8394c04a46ec19efb2922a7cd3faae3 (diff)
Merge #2240 from zmasi: sync TitleTexture readability against title_memory_map between passes (RT-TITLE-TEXTURE-MAP-GEN)
Head d088ea79b. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'runtime/test/xmem_test.cpp')
-rw-r--r--runtime/test/xmem_test.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/runtime/test/xmem_test.cpp b/runtime/test/xmem_test.cpp
index c65ac257a..f78f09c77 100644
--- a/runtime/test/xmem_test.cpp
+++ b/runtime/test/xmem_test.cpp
@@ -1617,6 +1617,38 @@ void test_physical_pages_commit_on_touch(const PhysicalApi& api) {
1617 check(read_ok, "ReadFile fills a page that commit_physical_range committed"); 1617 check(read_ok, "ReadFile fills a page that commit_physical_range committed");
1618 1618
1619 check(api.map(second, 2, nullptr) == second && api.map(window, kMapped, nullptr) == window, "they unmap"); 1619 check(api.map(second, 2, nullptr) == second && api.map(window, kMapped, nullptr) == window, "they unmap");
1620 {
1621 // A host guarded read (outside the title image at 0x140000000) of an unmapped window page exits as
1622 // passed_guarded without counting as left_to_title; a title read still counts as left_to_title.
1623 void* const stub_page = VirtualAlloc(nullptr, 4096, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
1624 const uint8_t mov_eax_rcx_ret[] = {0x8b, 0x01, 0xc3};
1625 DWORD stub_old = 0;
1626 bool stub_ready = false;
1627 if (stub_page) {
1628 std::memcpy(stub_page, mov_eax_rcx_ret, sizeof(mov_eax_rcx_ret));
1629 stub_ready = VirtualProtect(stub_page, 4096, PAGE_EXECUTE_READ, &stub_old) != FALSE;
1630 FlushInstructionCache(GetCurrentProcess(), stub_page, sizeof(mov_eax_rcx_ret));
1631 }
1632 const auto host_read_faults = [&](const void* p) {
1633 __try {
1634 reinterpret_cast<uint32_t (*)(const void*)>(stub_page)(p);
1635 return false;
1636 } __except (GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION ? EXCEPTION_EXECUTE_HANDLER
1637 : EXCEPTION_CONTINUE_SEARCH) {
1638 return true;
1639 }
1640 };
1641 const uint64_t guarded_before = rt::xmem::fault_exits(rt::xmem::FaultExit::passed_guarded);
1642 const uint64_t left_before = rt::xmem::fault_exits(rt::xmem::FaultExit::left_to_title);
1643 check(stub_ready && host_read_faults(second) &&
1644 rt::xmem::fault_exits(rt::xmem::FaultExit::passed_guarded) == guarded_before + 1 &&
1645 rt::xmem::fault_exits(rt::xmem::FaultExit::left_to_title) == left_before,
1646 "a host guarded read of an unmapped window page exits as passed_guarded");
1647 check(access_faults(reinterpret_cast<volatile uint32_t*>(second), false) &&
1648 rt::xmem::fault_exits(rt::xmem::FaultExit::left_to_title) == left_before + 1,
1649 "a title read of an unmapped window page still exits as left_to_title");
1650 if (stub_page) VirtualFree(stub_page, 0, MEM_RELEASE);
1651 }
1620 check(api.free_pages(count, pages.data()) == TRUE, "XMemFreePhysicalPages frees them"); 1652 check(api.free_pages(count, pages.data()) == TRUE, "XMemFreePhysicalPages frees them");
1621} 1653}
1622 1654