[PR #417] xmem: commits into placeholder windows, title page-size bits, window release (RT-XMEM-WINDOWS) #468

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

📋 Pull Request Information

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

Base: main ← Head: pr/xmem-window-commit-free


📝 Commits (2)

  • f2de415 xmem: commits into placeholder windows, title page-size bits, window release (RT-XMEM-WINDOWS)
  • ba26fe9 xmem: releasing a window frees the whole original reservation, committed parts included (review of #417)

📊 Changes

2 files changed (+268 additions, -6 deletions)

View changed files

📝 runtime/shims/xmem.cpp (+125 -3)
📝 runtime/test/xmem_test.cpp (+143 -3)

📄 Description

Claim: RT-XMEM-WINDOWS (#14).

Three ways the title's memory calls fail on the host with the current window model (reserve-only 64 KiB windows kept as placeholders, physical pages mapped into them):

  1. Commit inside a window. A commit without MEM_RESERVE (the measured 0x20401000 shape) into a placeholder range fails with ERROR_INVALID_ADDRESS: the host cannot commit a placeholder. When the host refuses such a commit, each placeholder piece is now replaced by committed memory (VirtualAlloc2 with MEM_REPLACE_PLACEHOLDER), plain reserved or committed pieces are committed in place, and a range with a page mapped or a free piece fails before anything changes. The committed part leaves the window map; the rest of the window still takes physical pages.
  2. Console page-size bits through kernel32!VirtualAlloc. The title's own VirtualAlloc passed MEM_LARGE_PAGES (needs SeLockMemoryPrivilege on the host) and 64 KiB pages (MEM_LARGE_PAGES | MEM_PHYSICAL, invalid on the host) straight through. Both now take XMemVirtualAlloc's path (guest page size as alignment and rounding, 4 KiB host pages); MEM_PHYSICAL alone is dropped.
  3. Releasing a window with pages mapped. Once pages are mapped, a window is many host allocations, so the title's VirtualFree(base, 0, MEM_RELEASE) freed only the first piece and left g_mapped naming views at addresses the host hands out again. VirtualFree is now shimmed next to VirtualAlloc for the title's memory DLLs: a release at a window's base unmaps its pages, releases every piece and forgets the window; every other call passes through.

Tests (xmem_test, new checks): commit into a window, including a piece that had a page mapped and unmapped, and the rest of the window still maps; title VirtualAlloc with each page mode, aligned and writable, and a plain commit into a 64 KiB title reservation; a window with two pages mapped released whole (every 64 KiB free afterwards), taking no pages after, and the same pages mapping into a new window and holding data.

The existing check "writing to 512 of them charges about those 512 pages" reads the system-wide commit charge, so another process allocating or freeing tens of MB in the window fails it; it now measures up to two more windows of untouched pages before failing. The neighbouring "mapping them does not charge them" check has the same weakness and still fails about one run in fifteen while builds run beside it; left as is here.

Tested on Windows 10, i7-11800H, RTX 3080 Laptop (no GPU needed), on main d2cd6c0d9: xmem and d3d12_xmem_placed pass; xmem_test run 15 times, the new checks never failed.

🤖 Generated with Claude Code


🔄 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/417 **Author:** [@Kokonotcu](https://github.com/Kokonotcu) **Created:** 11/24/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `pr/xmem-window-commit-free` --- ### 📝 Commits (2) - [`f2de415`](https://github.com/ubiquitarianism/leonida/commit/f2de4152237ae6de3de799fce2a57c58ddc85e59) xmem: commits into placeholder windows, title page-size bits, window release (RT-XMEM-WINDOWS) - [`ba26fe9`](https://github.com/ubiquitarianism/leonida/commit/ba26fe91f068e51ac9c1cfc230f2e00c2d611e04) xmem: releasing a window frees the whole original reservation, committed parts included (review of #417) ### 📊 Changes **2 files changed** (+268 additions, -6 deletions) <details> <summary>View changed files</summary> 📝 `runtime/shims/xmem.cpp` (+125 -3) 📝 `runtime/test/xmem_test.cpp` (+143 -3) </details> ### 📄 Description Claim: RT-XMEM-WINDOWS (#14). Three ways the title's memory calls fail on the host with the current window model (reserve-only 64 KiB windows kept as placeholders, physical pages mapped into them): 1. **Commit inside a window.** A commit without `MEM_RESERVE` (the measured `0x20401000` shape) into a placeholder range fails with `ERROR_INVALID_ADDRESS`: the host cannot commit a placeholder. When the host refuses such a commit, each placeholder piece is now replaced by committed memory (`VirtualAlloc2` with `MEM_REPLACE_PLACEHOLDER`), plain reserved or committed pieces are committed in place, and a range with a page mapped or a free piece fails before anything changes. The committed part leaves the window map; the rest of the window still takes physical pages. 2. **Console page-size bits through `kernel32!VirtualAlloc`.** The title's own `VirtualAlloc` passed `MEM_LARGE_PAGES` (needs `SeLockMemoryPrivilege` on the host) and 64 KiB pages (`MEM_LARGE_PAGES | MEM_PHYSICAL`, invalid on the host) straight through. Both now take `XMemVirtualAlloc`'s path (guest page size as alignment and rounding, 4 KiB host pages); `MEM_PHYSICAL` alone is dropped. 3. **Releasing a window with pages mapped.** Once pages are mapped, a window is many host allocations, so the title's `VirtualFree(base, 0, MEM_RELEASE)` freed only the first piece and left `g_mapped` naming views at addresses the host hands out again. `VirtualFree` is now shimmed next to `VirtualAlloc` for the title's memory DLLs: a release at a window's base unmaps its pages, releases every piece and forgets the window; every other call passes through. **Tests (`xmem_test`, new checks):** commit into a window, including a piece that had a page mapped and unmapped, and the rest of the window still maps; title `VirtualAlloc` with each page mode, aligned and writable, and a plain commit into a 64 KiB title reservation; a window with two pages mapped released whole (every 64 KiB free afterwards), taking no pages after, and the same pages mapping into a new window and holding data. The existing check "writing to 512 of them charges about those 512 pages" reads the system-wide commit charge, so another process allocating or freeing tens of MB in the window fails it; it now measures up to two more windows of untouched pages before failing. The neighbouring "mapping them does not charge them" check has the same weakness and still fails about one run in fifteen while builds run beside it; left as is here. Tested on Windows 10, i7-11800H, RTX 3080 Laptop (no GPU needed), on `main` `d2cd6c0d9`: `xmem` and `d3d12_xmem_placed` pass; `xmem_test` run 15 times, the new checks never failed. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <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#468
No description provided.