Skip to content

xmem: map physical pages without the window's cache modifiers (Wine refuses PAGE_WRITECOMBINE views) - #7852

Closed
gkissel wants to merge 1 commit into
ProjectLeonida:mainfrom
gkissel:fix/xmem-view-no-writecombine
Closed

gkissel wants to merge 1 commit into
ProjectLeonida:mainfrom
gkissel:fix/xmem-view-no-writecombine

Conversation

@gkissel

@gkissel gkissel commented Nov 23, 2026

Copy link
Copy Markdown

What and why

The retail executable reserves its descriptor pool's physical windows as PAGE_READWRITE | PAGE_WRITECOMBINE. XMemMapPhysicalPages gave each view that protection, and under Wine MapViewOfFile3 refuses any cache modifier with ERROR_INVALID_PARAMETER. So the first page failed to map, the call returned NULL and the title's device init returned false. Windows accepts the modifier, which is why this only shows under Wine.

view_protect now drops PAGE_WRITECOMBINE | PAGE_NOCACHE. The comment above it already says the D3D12 layer reads these pages on the CPU, and CPU reads of write-combined memory are uncached on Windows too.

I reported this on #6919 before it merged (#6919 (comment)); the merged version doesn't include it. This PR is the same commit, rebased on main.

Test

xmem_test gains the pool's measured shape:

  • 0x2c60 physical pages allocated first;
  • a 185 MiB MEM_RESERVE_PLACEHOLDER region, split by VirtualFree(MEM_PRESERVE_PLACEHOLDER) into five windows made with MEM_RESERVE | MEM_REPLACE_PLACEHOLDER | MEM_PHYSICAL | MEM_LARGE_PAGES, attribute 0x27 and PAGE_READWRITE | PAGE_WRITECOMBINE;
  • 0x5c80 more pages, and 0x2f0 of them mapped into the fourth window.

Wine 11.21, clang-cl + xwin cross build, on main dde82f27e:

  • without the change: retail pool: page 0 of 752 failed to map, error 87, xmem_test: FAILED (179 checks, 1 failure);
  • with it: xmem_test: OK (179 checks).

scripts/check_no_game_data.py: exit 0.

Boot

Under Wine with a stack of open PRs (listed in #6982 (comment)), this is step 7 of that table. With the change the run goes past the descriptor pool. #7584 (consecutive pages as one view) is independent of this and touches a different part of xmem.cpp.

AI-assisted (Claude Code). No game files, bytes or code addresses in this PR.

…efuses PAGE_WRITECOMBINE views)

The retail executable's descriptor pool reserves its physical windows PAGE_READWRITE | PAGE_WRITECOMBINE. The views
XMemMapPhysicalPages makes in them took that protection, and Wine's MapViewOfFile3 refuses any cache modifier with
ERROR_INVALID_PARAMETER, so the first page failed and the title stopped on the NULL result. view_protect now drops
PAGE_WRITECOMBINE and PAGE_NOCACHE; the D3D12 layer reads these pages on the CPU, where write-combined memory is
uncached on Windows too.

xmem_test gains the pool's measured shape: a 185 MiB placeholder split into five windows with
MEM_RESERVE | MEM_REPLACE_PLACEHOLDER | MEM_PHYSICAL | MEM_LARGE_PAGES, 0x2c60 + 0x5c80 physical pages, and 0x2f0
pages mapped into the fourth window. Under Wine 11.21 it fails at page 0 with error 87 before the change and passes
after it.
Copilot AI balanced review requested due to automatic review settings November 23, 2026 17:39

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@skorex

skorex commented Nov 23, 2026

Copy link
Copy Markdown

Duplicate of #7492

#7492 makes the same change and was opened earlier. Topic: xmem: a physical-page view drops PAGE_WRITECOMBINE and PAGE_NOCACHE from the window protection.

Suggest closing this PR in favour of #7492, and porting anything this one adds that #7492 lacks there.

@gkissel

gkissel commented Nov 23, 2026

Copy link
Copy Markdown
Author

Closing as a duplicate of #7492, which makes the same change and was opened earlier (thanks @skorex). I'll add my Wine confirmation there. The extra test here (the pool's full measured shape) adds no coverage beyond #7492's single-page case for this bug, so I'm not porting it. AI-assisted (Claude Code).

@tupacfan04 tupacfan04 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Real defect: the Wine workaround clears cache modifiers unconditionally on native Windows.

runtime/shims/xmem.cpp:464-467:

DWORD view_protect(const Window& window) {
    const DWORD protect = window.protect & ~static_cast<DWORD>(PAGE_WRITECOMBINE | PAGE_NOCACHE);
    return protect == PAGE_NOACCESS ? PAGE_READWRITE : protect;
}

That result is passed to MapViewOfFile3 from map_page (:452-455), XMemMapPhysicalPages (:587-590) and XMemMapPhysicalPagesScatter (:624). The PR body says Windows accepts the modifiers and only Wine rejects them; a synthetic host probe confirms native Windows maps 0x404 and 0x204 successfully and reports them, while 0x604 fails with error 87. The change therefore drops the title’s requested write-combined/uncached semantics on Windows.

Expected: try the window’s original protection first and retry without PAGE_WRITECOMBINE | PAGE_NOCACHE only when MapViewOfFile3 returns ERROR_INVALID_PARAMETER (Wine), or gate the fallback explicitly on Wine.

The test (runtime/test/xmem_test.cpp:479-528) only checks that each map is non-null; it never queries the mapped view’s protection or contents, and it maps one page per call rather than the measured 0x2f0-page batch. Add a VirtualQuery/protection assertion for native Windows and the batch shape.

Synthetic host probe only; no game files. AI-assisted (OpenCode).

@DeSunShine

Copy link
Copy Markdown
Contributor

Tested 1b1f0cff1 merged into main dde82f27e on NVIDIA GeForce RTX 4090 (driver 621.24), Windows 11 Pro 26200, MSVC (VS Build Tools 18) + Ninja, Vulkan SDK 1.4.363: pass.

  • ctest -R "xmem|tiny_game" --output-on-failure: 100% passed out of 11 (xmem and the run_tiny_game* tests). Native Windows only; the Wine refusal the PR targets was not exercised.

AI-assisted (Claude Code).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants