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:
Diffstat (limited to 'runtime/test/xmem_test.cpp')
-rw-r--r--runtime/test/xmem_test.cpp46
1 files changed, 45 insertions, 1 deletions
diff --git a/runtime/test/xmem_test.cpp b/runtime/test/xmem_test.cpp
index 991388c7f..79f655412 100644
--- a/runtime/test/xmem_test.cpp
+++ b/runtime/test/xmem_test.cpp
@@ -741,7 +741,19 @@ void test_copy_page_mappings_cpu_view(const PhysicalApi& api) {
741 check(readable(other) && page_holds(other, 0x7300u), 741 check(readable(other) && page_holds(other, 0x7300u),
742 "a GPU-only source page unmapped there is looked up at its CPU range"); 742 "a GPU-only source page unmapped there is looked up at its CPU range");
743 743
744 // A null source unmaps both ranges. 744 // A CPU page the title mapped itself is the title's: a copy onto its GPU-only page, or an unmap of it, changes the
745 // GPU-only page alone (the console's CopyPageMappingsBatchX edits only that range's page table).
746 check(copy(gpu + 2 * kPage64k, pool + kPage64k, 1, false), "a copy onto a GPU-only page whose CPU page is the title's");
747 check(readable(gpu + 2 * kPage64k) && page_holds(gpu + 2 * kPage64k, 0x7301u),
748 "the GPU-only page shows the copied pool page");
749 check(readable(cpu + 2 * kPage64k) && page_holds(cpu + 2 * kPage64k, 0x7300u),
750 "the title's own mapping at the paired CPU page is kept, not replaced by the copy");
751 check(copy(gpu + 2 * kPage64k, nullptr, 1, false), "a null source unmaps a GPU-only page whose CPU page is the title's");
752 check(!readable(gpu + 2 * kPage64k), "the GPU-only page is unmapped");
753 check(readable(cpu + 2 * kPage64k) && page_holds(cpu + 2 * kPage64k, 0x7300u),
754 "the title's own mapping at the paired CPU page survives the unmap");
755
756 // A null source unmaps both ranges where the CPU pages are the copy's own.
745 check(copy(gpu, nullptr, kPool, false), "a null source unmaps the GPU-only range"); 757 check(copy(gpu, nullptr, kPool, false), "a null source unmaps the GPU-only range");
746 check(!readable(gpu) && !readable(cpu) && !readable(cpu + kPage64k), "the paired CPU range is unmapped with it"); 758 check(!readable(gpu) && !readable(cpu) && !readable(cpu + kPage64k), "the paired CPU range is unmapped with it");
747 759
@@ -1544,6 +1556,38 @@ void test_physical_pages_commit_on_touch(const PhysicalApi& api) {
1544 check(read_ok, "ReadFile fills a page that commit_physical_range committed"); 1556 check(read_ok, "ReadFile fills a page that commit_physical_range committed");
1545 1557
1546 check(api.map(second, 2, nullptr) == second && api.map(window, kMapped, nullptr) == window, "they unmap"); 1558 check(api.map(second, 2, nullptr) == second && api.map(window, kMapped, nullptr) == window, "they unmap");
1559 {
1560 // A host guarded read (outside the title image at 0x140000000) of an unmapped window page exits as
1561 // passed_guarded without counting as left_to_title; a title read still counts as left_to_title.
1562 void* const stub_page = VirtualAlloc(nullptr, 4096, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
1563 const uint8_t mov_eax_rcx_ret[] = {0x8b, 0x01, 0xc3};
1564 DWORD stub_old = 0;
1565 bool stub_ready = false;
1566 if (stub_page) {
1567 std::memcpy(stub_page, mov_eax_rcx_ret, sizeof(mov_eax_rcx_ret));
1568 stub_ready = VirtualProtect(stub_page, 4096, PAGE_EXECUTE_READ, &stub_old) != FALSE;
1569 FlushInstructionCache(GetCurrentProcess(), stub_page, sizeof(mov_eax_rcx_ret));
1570 }
1571 const auto host_read_faults = [&](const void* p) {
1572 __try {
1573 reinterpret_cast<uint32_t (*)(const void*)>(stub_page)(p);
1574 return false;
1575 } __except (GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION ? EXCEPTION_EXECUTE_HANDLER
1576 : EXCEPTION_CONTINUE_SEARCH) {
1577 return true;
1578 }
1579 };
1580 const uint64_t guarded_before = rt::xmem::fault_exits(rt::xmem::FaultExit::passed_guarded);
1581 const uint64_t left_before = rt::xmem::fault_exits(rt::xmem::FaultExit::left_to_title);
1582 check(stub_ready && host_read_faults(second) &&
1583 rt::xmem::fault_exits(rt::xmem::FaultExit::passed_guarded) == guarded_before + 1 &&
1584 rt::xmem::fault_exits(rt::xmem::FaultExit::left_to_title) == left_before,
1585 "a host guarded read of an unmapped window page exits as passed_guarded");
1586 check(access_faults(reinterpret_cast<volatile uint32_t*>(second), false) &&
1587 rt::xmem::fault_exits(rt::xmem::FaultExit::left_to_title) == left_before + 1,
1588 "a title read of an unmapped window page still exits as left_to_title");
1589 if (stub_page) VirtualFree(stub_page, 0, MEM_RELEASE);
1590 }
1547 check(api.free_pages(count, pages.data()) == TRUE, "XMemFreePhysicalPages frees them"); 1591 check(api.free_pages(count, pages.data()) == TRUE, "XMemFreePhysicalPages frees them");
1548} 1592}
1549 1593