[PR #826] cpu: handle reserved XMem backing during CLZERO emulation #863

Open
opened 2026-11-26 20:19:18 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/826
Author: @moffington
Created: 11/24/2026
Status: 🔄 Open

Base: main ← Head: submit/xmem-clzero-first-touch


📝 Commits (2)

  • 44f4dc3 Commit XMem backing for emulated CLZERO writes
  • d62aa5b Cover batched XMem CLZERO across a protected boundary

📊 Changes

5 files changed (+235 additions, -15 deletions)

View changed files

📝 runtime/CMakeLists.txt (+5 -1)
📝 runtime/shims/xmem.cpp (+20 -2)
📝 runtime/shims/xmem.h (+4 -0)
📝 runtime/src/cpu_emulation.h (+11 -2)
📝 runtime/test/cpu_emulation_test.cpp (+195 -10)

📄 Description

Claimed in the coordination issue as: RT-CLZERO-XMEM

What and why

Emulated CLZERO raised a false write access violation on XMem pages that were untouched or that Wine still reported as reserved after a successful CPU write. The handler now checks the exact faulting subpage, commits its XMem backing when eligible, then rechecks live protection before zeroing the cache line. Initially read-only and unrelated mappings stay reserved. Read-only, no-access, and one-shot guard protections still apply.

Tested

  • The original synthetic regression failed on d0da7dade and passed with this change, including 20 repeat runs. It covers concurrent first touches and partially committed XMem pages.
  • d3d12_xmem_placed passed on an NVIDIA GeForce RTX 3060 with driver 615.78.08. Stock xmem reproduced the same five Wine failures before and after: two metadata checks, one commit-accounting check, and two protection-setup checks.
  • Omarchy, Wine 11.20, clang-cl 23.1.3, Windows SDK 10.0.26100. Native Windows and MSVC remain untested.
  • The batched CLZERO regression starts in reserved XMem and verifies that the emulation zeroes the writable prefix, reports a write fault at the exact read-only boundary, and leaves every byte from that boundary through the end of the requested span untouched.
  • The test target links the real XMem shim. The fixture runs in separate processes for SEC_RESERVE and Wine’s default SEC_COMMIT mode. Both CPU test cases passed three consecutive runs each on the rebased branch.
  • As a negative control, the new batch assertions failed as expected in SEC_RESERVE mode when built against the CPU-emulation header from either main or #2035.

AI-assisted with OpenAI Codex.

Known limitation

The protection check and the zeroing write are separate operations, so there is no atomicity guarantee against a concurrent remap or protection change.

Overlap with other open PRs

  • #2035: its region scan rejects reserved XMem pages and its header conflicts with the writable() change here. Whichever lands second needs the XMem first-touch check carried into writable_region().
  • #1499: its MSVC single-line SEH path bypasses writable(); clang-cl keeps the check. The test entry points conflict. A clang-cl/Wine control with its SEH write helper still passed the batch checks. Native MSVC is untested.
  • #1707: its XMem helper and test changes already conflict with main. If its fault-ahead commit is applied to emulated writes, the adjacent-page reservation assertion may need updating; the protected-boundary and byte-preservation assertions should still hold.

CI

CI pending on the rebased commit


🔄 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/826 **Author:** [@moffington](https://github.com/moffington) **Created:** 11/24/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `submit/xmem-clzero-first-touch` --- ### 📝 Commits (2) - [`44f4dc3`](https://github.com/ubiquitarianism/leonida/commit/44f4dc34dfaebf836ec2c57d210289a12417f99e) Commit XMem backing for emulated CLZERO writes - [`d62aa5b`](https://github.com/ubiquitarianism/leonida/commit/d62aa5b75e1245cd2735eb76b274b0c8804abcb4) Cover batched XMem CLZERO across a protected boundary ### 📊 Changes **5 files changed** (+235 additions, -15 deletions) <details> <summary>View changed files</summary> 📝 `runtime/CMakeLists.txt` (+5 -1) 📝 `runtime/shims/xmem.cpp` (+20 -2) 📝 `runtime/shims/xmem.h` (+4 -0) 📝 `runtime/src/cpu_emulation.h` (+11 -2) 📝 `runtime/test/cpu_emulation_test.cpp` (+195 -10) </details> ### 📄 Description Claimed in the coordination issue as: RT-CLZERO-XMEM ### What and why Emulated CLZERO raised a false write access violation on XMem pages that were untouched or that Wine still reported as reserved after a successful CPU write. The handler now checks the exact faulting subpage, commits its XMem backing when eligible, then rechecks live protection before zeroing the cache line. Initially read-only and unrelated mappings stay reserved. Read-only, no-access, and one-shot guard protections still apply. ### Tested - The original synthetic regression failed on `d0da7dade` and passed with this change, including 20 repeat runs. It covers concurrent first touches and partially committed XMem pages. - `d3d12_xmem_placed` passed on an NVIDIA GeForce RTX 3060 with driver 615.78.08. Stock `xmem` reproduced the same five Wine failures before and after: two metadata checks, one commit-accounting check, and two protection-setup checks. - Omarchy, Wine 11.20, clang-cl 23.1.3, Windows SDK 10.0.26100. Native Windows and MSVC remain untested. - The batched CLZERO regression starts in reserved XMem and verifies that the emulation zeroes the writable prefix, reports a write fault at the exact read-only boundary, and leaves every byte from that boundary through the end of the requested span untouched. - The test target links the real XMem shim. The fixture runs in separate processes for `SEC_RESERVE` and Wine’s default `SEC_COMMIT` mode. Both CPU test cases passed three consecutive runs each on the rebased branch. - As a negative control, the new batch assertions failed as expected in `SEC_RESERVE` mode when built against the CPU-emulation header from either `main` or #2035. AI-assisted with OpenAI Codex. ## Known limitation The protection check and the zeroing write are separate operations, so there is no atomicity guarantee against a concurrent remap or protection change. ## Overlap with other open PRs - #2035: its region scan rejects reserved XMem pages and its header conflicts with the `writable()` change here. Whichever lands second needs the XMem first-touch check carried into `writable_region()`. - #1499: its MSVC single-line SEH path bypasses `writable()`; clang-cl keeps the check. The test entry points conflict. A clang-cl/Wine control with its SEH write helper still passed the batch checks. Native MSVC is untested. - #1707: its XMem helper and test changes already conflict with `main`. If its fault-ahead commit is applied to emulated writes, the adjacent-page reservation assertion may need updating; the protected-boundary and byte-preservation assertions should still hold. ## CI CI pending on the rebased commit --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
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#863
No description provided.