[PR #328] [MERGED] xmem: map physical pages without a cache modifier in the view protection, again (RT-XMEM-VIEW-PROTECT) #382

Closed
opened 2026-11-26 20:17:42 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/328
Author: @Mumogg
Created: 11/24/2026
Status: ✅ Merged
Merged: 11/24/2026
Merged by: @ubiquitarianism

Base: main ← Head: xmem-view-protect


📝 Commits (3)

  • 80ed5dd xmem: map physical pages without a cache modifier in the view protection
  • 8d4dd7a xmem: keep PAGE_GUARD in the view protection; only the cache modifiers are dropped
  • f70ed48 xmem_test: the write-combine window's page is written before its view is queried

📊 Changes

2 files changed (+37 additions, -1 deletions)

View changed files

📝 runtime/shims/xmem.cpp (+6 -1)
📝 runtime/test/xmem_test.cpp (+31 -0)

📄 Description

Claimed in #14 as RT-XMEM-VIEW-PROTECT.

What and why

Three of the retail executable's physical-page windows carry PAGE_WRITECOMBINE next to PAGE_READWRITE. On main, view_protect hands that protection to MapViewOfFile3, which refuses a cache modifier, so the first XMemMapPhysicalPages into 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): 7e8e3c1db drops the cache modifiers from the view protection and 954fcb106 keeps PAGE_GUARD. Both are ancestors of main, 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_test under Wine, the new write-combine case:

a page maps into a window reserved with PAGE_WRITECOMBINE
main's xmem.cpp with the new test case FAIL
this branch PASS, and the page in the write-combine window holds data passes too

At boot (own 1.0.2.1 copy, network off), measured in the integration branch of #321 with main's xmem.cpp swapped in: without the fix the run stops at 1,181 D3D12 calls, on the title's own int3 after the function that creates its device returns false; with it the run goes on to 50,468 pipeline states. It cannot be measured on main alone yet, because main stops 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 protection already fails on main under Wine, and the new the page mapped there is a plain read-write view fails the same way: after the page has been written, Wine's VirtualQuery still reports the view as MEM_RESERVE / MEM_MAPPED with 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's State == MEM_COMMIT will see these pages as unreadable under Wine. That may be why #321 fails a submit with an unknown resource when it uses main'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


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/328 **Author:** [@Mumogg](https://github.com/Mumogg) **Created:** 11/24/2026 **Status:** ✅ Merged **Merged:** 11/24/2026 **Merged by:** [@ubiquitarianism](https://github.com/ubiquitarianism) **Base:** `main` ← **Head:** `xmem-view-protect` --- ### 📝 Commits (3) - [`80ed5dd`](https://github.com/ubiquitarianism/leonida/commit/80ed5dd30438b507a03c6bb10e0adf0a0a403dea) xmem: map physical pages without a cache modifier in the view protection - [`8d4dd7a`](https://github.com/ubiquitarianism/leonida/commit/8d4dd7a80cbd55f8cbf1a89ef7780d806e04f401) xmem: keep PAGE_GUARD in the view protection; only the cache modifiers are dropped - [`f70ed48`](https://github.com/ubiquitarianism/leonida/commit/f70ed489f5c9ed138cf766468a2e2fd5b2855f12) xmem_test: the write-combine window's page is written before its view is queried ### 📊 Changes **2 files changed** (+37 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `runtime/shims/xmem.cpp` (+6 -1) 📝 `runtime/test/xmem_test.cpp` (+31 -0) </details> ### 📄 Description Claimed in #14 as `RT-XMEM-VIEW-PROTECT`. ### What and why Three of the retail executable's physical-page windows carry `PAGE_WRITECOMBINE` next to `PAGE_READWRITE`. On `main`, `view_protect` hands that protection to `MapViewOfFile3`, which refuses a cache modifier, so the first `XMemMapPhysicalPages` into 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): `7e8e3c1db` drops the cache modifiers from the view protection and `954fcb106` keeps `PAGE_GUARD`. Both are ancestors of `main`, 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_test` under Wine, the new write-combine case: | | `a page maps into a window reserved with PAGE_WRITECOMBINE` | |---|---| | `main`'s `xmem.cpp` with the new test case | **FAIL** | | this branch | PASS, and `the page in the write-combine window holds data` passes too | At boot (own 1.0.2.1 copy, network off), measured in the integration branch of #321 with `main`'s `xmem.cpp` swapped in: without the fix the run stops at 1,181 D3D12 calls, on the title's own `int3` after the function that creates its device returns false; with it the run goes on to 50,468 pipeline states. It cannot be measured on `main` alone yet, because `main` stops 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 protection` already fails on `main` under Wine, and the new `the page mapped there is a plain read-write view` fails the same way: after the page has been written, Wine's `VirtualQuery` still reports the view as `MEM_RESERVE` / `MEM_MAPPED` with 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`'s `State == MEM_COMMIT` will see these pages as unreadable under Wine. That may be why #321 fails a submit with an unknown resource when it uses `main`'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.com/claude-code) https://claude.ai/code/session_01HxBQf4pXH8PWpC5oZsM4bt --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
4ld0 2026-11-26 20:17:42 +01:00
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starred/leonida#382
No description provided.