xmem: map physical pages without a cache modifier in the view protection, again (RT-XMEM-VIEW-PROTECT) #328
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
missing claim
needs rebase
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/ubiquitarianism--leonida!328
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/328/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@Mumogg on GitHub · 2026-11-24 03:11 UTC · original
Mumogg:xmem-view-protect→main· +37 −1 · 2 files · 3 commits · merged 2026-11-24 04:31 UTCClaimed in #14 as
RT-XMEM-VIEW-PROTECT.What and why
Three of the retail executable's physical-page windows carry
PAGE_WRITECOMBINEnext toPAGE_READWRITE. Onmain,view_protecthands that protection toMapViewOfFile3, which refuses a cache modifier, so the firstXMemMapPhysicalPagesinto such a window fails and the title's device set-up returns false.The fix is two commits by hcristosm, cherry-picked unchanged (
-x, authorship kept):7e8e3c1dbdrops the cache modifiers from the view protection and954fcb106keepsPAGE_GUARD. Both are ancestors ofmain, but the change is not in the tree (finding in #14), so a merge does not bring it back.One commit of mine on top: the test case that came with the fix queried the view right after mapping it.
main's xmem commits a page on first touch, so the case now writes the page first, as the read-write case above it does.Measured
Linux (Nobara 44, kernel 7.3), Wine 11.21 staging, RTX 5070 Ti (driver 615.78.08), clang-cl 22.1.8 + xwin SDK 10.0.26100.
xmem_testunder Wine, the new write-combine case:a page maps into a window reserved with PAGE_WRITECOMBINEmain'sxmem.cppwith the new test casethe page in the write-combine window holds datapasses tooAt boot (own 1.0.2.1 copy, network off), measured in the integration branch of #321 with
main'sxmem.cppswapped in: without the fix the run stops at 1,181 D3D12 calls, on the title's ownint3after the function that creates its device returns false; with it the run goes on to 50,468 pipeline states. It cannot be measured onmainalone yet, becausemainstops earlier (#127, #131, then device slot 26).Two checks that fail under Wine with and without this change
a mapped page is a read-write view with the window's protectionalready fails onmainunder Wine, and the newthe page mapped there is a plain read-write viewfails the same way: after the page has been written, Wine'sVirtualQuerystill reports the view asMEM_RESERVE/MEM_MAPPEDwith protection 0. The data checks around them pass, so the page is there. I do not know what Windows reports for these two; CI will say, and if the new check is wrong for the commit-on-touch design I will change it.This matters beyond the test: any code that decides whether title memory is readable from
VirtualQuery'sState == MEM_COMMITwill see these pages as unreadable under Wine. That may be why #321 fails a submit with an unknown resource when it usesmain's xmem; not confirmed.Not built with MSVC and not run on Windows.
AI-assisted (Claude Code); built and run on the machine above.
🤖 Generated with Claude Code
https://claude.ai/code/session_01HxBQf4pXH8PWpC5oZsM4bt
@moffington on GitHub · 2026-11-24 03:41 UTC · original
Tested
f70ed489against merge base84347bbbon Omarchy Linux with Wine 11.20 and Clang 23.1.3 targeting MinGW. A standalone probe linked against unmodified xmem.cpp and registry.cpp: both XMemMapPhysicalPages and XMemMapPhysicalPagesScatter failed with error 87 on PAGE_WRITECOMBINE and PAGE_NOCACHE windows at the merge base. Both mapped successfully and read back the written data at the PR head.I also reproduced the VirtualQuery discrepancy in an adapted xmem_test. Wine reported MEM_RESERVE and Protect=0 even after a successful write to a commit-on-touch mapping. Precommitting the page before mapping made it report MEM_COMMIT with the expected protection. The adapted test skipped SEH-dependent coverage due to local toolchain limits. The unmodified xmem_test on native Windows is still pending.
@BadgersMC on GitHub · 2026-11-24 03:49 UTC · original
Tested
f70ed489f5c9ed138cf766468a2e2fd5b2855f12on native Windows 11 Home build 26100, MSVC 19.44.35228, Windows SDK 10.0.26100, andRelWithDebInfo. The synthetic test uses the CPU only and requires no game files.ctest --test-dir <build> -C RelWithDebInfo -R '^xmem$' -Vpassed all 217 checks. BothVirtualQueryassertions called out in the PR passed, including the check that the write-combine window has a committedPAGE_READWRITEview after the first write.As a control, I kept the PR's
xmem_test.cpp, replaced onlyruntime/shims/xmem.cppwith the version from merge base84347bbb61ed406db10195f50d5911893b8b9a4b, and rebuilt the same target. All 217 checks still passed, including the mapping, protection, and readback checks. I restored the PR source, rebuilt, and repeated the passing run. This confirms the expected protection on this Windows host. The fixture distinguishes the implementations in the reported Wine run, but did not distinguish them here.AI-assisted review and testing (Codex and Claude Code).
@Mumogg on GitHub · 2026-11-24 03:56 UTC · original
Thank you both. That settles what I could not measure, so to state the scope plainly:
MapViewOfFile3refuses the cache modifier there (error 87, reproduced independently above), and the retail boot stops at 1,181 D3D12 calls without it.VirtualQuerychecks are right for Windows (they pass there) and fail under Wine for commit-on-touch pages, with and without this change. I would leave them as they are.AI-assisted.