diff options
| author | Zack <zmasi21@gmail.com> | 2026-11-26 02:02:47 -0800 |
|---|---|---|
| committer | Zack <zmasi21@gmail.com> | 2026-11-26 02:02:47 -0800 |
| commit | d088ea79b8394c04a46ec19efb2922a7cd3faae3 (patch) | |
| tree | 47526a94199ce24c66f9436a46886173914628a1 /runtime/test/xmem_test.cpp | |
| parent | a73a57e1339be072baf5522351c8ec7f1482b56b (diff) | |
Sync title texture readability with map journal between refresh passes
Between periodic refresh_title_textures passes, synchronous slot-70 view creation and the async fill worker checked TextureReadability with a constant generation, missing title_memory_map range changes since the last pass. Track the map generation on TextureReadability and consult title_memory_map::changes_since outside refresh passes so unmapped or decommitted pages defer before hashing and newly mapped pages publish immediately without waiting for a submission.
Also mark mix_words and hash_bytes LEONIDA_GUARDED_NO_BUILTIN using an unaligned 64-bit load so clang-cl cannot emit CRT memcpy calls inside the __try frame, and classify non-title read faults over unmapped title pages in xmem::physical_page_fault as FaultExit::passed_guarded.
Diffstat (limited to 'runtime/test/xmem_test.cpp')
| -rw-r--r-- | runtime/test/xmem_test.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/runtime/test/xmem_test.cpp b/runtime/test/xmem_test.cpp index 991388c7f..fca830bf0 100644 --- a/runtime/test/xmem_test.cpp +++ b/runtime/test/xmem_test.cpp | |||
| @@ -1544,6 +1544,38 @@ void test_physical_pages_commit_on_touch(const PhysicalApi& api) { | |||
| 1544 | check(read_ok, "ReadFile fills a page that commit_physical_range committed"); | 1544 | check(read_ok, "ReadFile fills a page that commit_physical_range committed"); |
| 1545 | 1545 | ||
| 1546 | check(api.map(second, 2, nullptr) == second && api.map(window, kMapped, nullptr) == window, "they unmap"); | 1546 | check(api.map(second, 2, nullptr) == second && api.map(window, kMapped, nullptr) == window, "they unmap"); |
| 1547 | { | ||
| 1548 | // A host guarded read (outside the title image at 0x140000000) of an unmapped window page exits as | ||
| 1549 | // passed_guarded without counting as left_to_title; a title read still counts as left_to_title. | ||
| 1550 | void* const stub_page = VirtualAlloc(nullptr, 4096, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); | ||
| 1551 | const uint8_t mov_eax_rcx_ret[] = {0x8b, 0x01, 0xc3}; | ||
| 1552 | DWORD stub_old = 0; | ||
| 1553 | bool stub_ready = false; | ||
| 1554 | if (stub_page) { | ||
| 1555 | std::memcpy(stub_page, mov_eax_rcx_ret, sizeof(mov_eax_rcx_ret)); | ||
| 1556 | stub_ready = VirtualProtect(stub_page, 4096, PAGE_EXECUTE_READ, &stub_old) != FALSE; | ||
| 1557 | FlushInstructionCache(GetCurrentProcess(), stub_page, sizeof(mov_eax_rcx_ret)); | ||
| 1558 | } | ||
| 1559 | const auto host_read_faults = [&](const void* p) { | ||
| 1560 | __try { | ||
| 1561 | reinterpret_cast<uint32_t (*)(const void*)>(stub_page)(p); | ||
| 1562 | return false; | ||
| 1563 | } __except (GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION ? EXCEPTION_EXECUTE_HANDLER | ||
| 1564 | : EXCEPTION_CONTINUE_SEARCH) { | ||
| 1565 | return true; | ||
| 1566 | } | ||
| 1567 | }; | ||
| 1568 | const uint64_t guarded_before = rt::xmem::fault_exits(rt::xmem::FaultExit::passed_guarded); | ||
| 1569 | const uint64_t left_before = rt::xmem::fault_exits(rt::xmem::FaultExit::left_to_title); | ||
| 1570 | check(stub_ready && host_read_faults(second) && | ||
| 1571 | rt::xmem::fault_exits(rt::xmem::FaultExit::passed_guarded) == guarded_before + 1 && | ||
| 1572 | rt::xmem::fault_exits(rt::xmem::FaultExit::left_to_title) == left_before, | ||
| 1573 | "a host guarded read of an unmapped window page exits as passed_guarded"); | ||
| 1574 | check(access_faults(reinterpret_cast<volatile uint32_t*>(second), false) && | ||
| 1575 | rt::xmem::fault_exits(rt::xmem::FaultExit::left_to_title) == left_before + 1, | ||
| 1576 | "a title read of an unmapped window page still exits as left_to_title"); | ||
| 1577 | if (stub_page) VirtualFree(stub_page, 0, MEM_RELEASE); | ||
| 1578 | } | ||
| 1547 | check(api.free_pages(count, pages.data()) == TRUE, "XMemFreePhysicalPages frees them"); | 1579 | check(api.free_pages(count, pages.data()) == TRUE, "XMemFreePhysicalPages frees them"); |
| 1548 | } | 1580 | } |
| 1549 | 1581 | ||