runtime: check the XMemVirtualQuery tail flag when it is clear #1532

Merged
Asimmimx merged 1 commit from upstream-pr/1539 into main 2026-11-24 14:24:08 +00:00
Asimmimx commented 2026-11-24 13:46:52 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Asimmimx on 2026-11-24T13:46:52Z.


Change

era_query (src/era_query.{h,cpp}) answers XMemVirtualQuery with the desktop VirtualQueryEx result plus a tail byte at +0x30. The byte is 0x01 when the address lies in a registered GPU region of the current process, and 0x00 otherwise. The header and docs/experiments.md make two promises about it:

  • the byte is written as 0x00 when the address is not registered;
  • registration counts only for queries of the current process.

Every existing check (era_query_{fields,tail,registry,short}, era_title_gpu_alloc, xmem_shim_query) queries this process into a zeroed buffer, so neither promise is tested. Three mutants left all of them passing:

  • dropping the current-process test;
  • leaving the byte untouched when the flag is clear;
  • testing GetProcessId(process) != 0 instead of == GetCurrentProcessId().

XMemVirtualQuery passes the caller's process handle and buffer straight through, so both rules are reachable from real callers.

The new era_query_clear scenario fills the 64-byte buffer with 0xff before each query. Its expected values are hand-written:

  • an unregistered committed page in this process reads 0x00 at +0x30;
  • a registered address in this process reads 0x01;
  • +0x31 stays 0xff in both cases;
  • a committed read/write page at the registered address in a suspended child (a second copy of the test program) returns 0x30, MEM_COMMIT, PAGE_READWRITE and tail 0x00, so the callers' tail check rejects it.

The child never runs. It is terminated and waited for, and its handles are closed on every path. The memory is released and the region unregistered. era_query_clear_foreign_control (clear --mutate foreign) expects 0x01 for the child and must fail (WILL_FAIL).

The change touches tests/era_query_check.cpp (the clear scenario), two add_test lines after the era_query_* foreach in CMakeLists.txt, and a new era_query_clear row in the docs/experiments.md era_query table.

Verification

Commit 309cfede (main) plus this change, dev preset (Debug), Windows 11 Pro build 26300.9974, MSVC 19.51.36260, Windows SDK 10.0.26100.0.

ctest --preset dev --no-tests=error -R '^(era_query_|xmem_shim_query$|era_title_gpu_alloc$)' -V
#   8/8 passed, 3 of 3 runs, including era_query_clear and the control; no era_query process left afterwards

tests/docs_links_check.py, tests/bidi_controls_check.py and git diff --check passed.

Mutation probe

I applied each mutation to src/era_query.{h,cpp} alone, rebuilt, ran the tests, then reverted. None of this is committed.

Mutant Existing era_query_clear
control: tail byte always 0 killed (tail, gpu_alloc, xmem_shim_query) fails
current-process test dropped survived fails
byte left untouched when the flag is clear survived fails
GetProcessId(process) != 0 survived fails
tail written at length 0x30 (>=) killed (short) n/a
region end inclusive killed (tail) n/a
back-adjacent region refused killed (registry) n/a
VirtualQueryEx failure ignored killed (only xmem_shim_query) n/a
wrap check dropped killed (registry) n/a
null-buffer check dropped killed (crash) n/a

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed.
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6583222388 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1539). Originally posted by [Asimmimx](https://github.com/Asimmimx) on 2026-11-24T13:46:52Z. --- ## Change `era_query` (`src/era_query.{h,cpp}`) answers `XMemVirtualQuery` with the desktop `VirtualQueryEx` result plus a tail byte at +0x30. The byte is 0x01 when the address lies in a registered GPU region of the current process, and 0x00 otherwise. The header and `docs/experiments.md` make two promises about it: - the byte is written as 0x00 when the address is not registered; - registration counts only for queries of the current process. Every existing check (`era_query_{fields,tail,registry,short}`, `era_title_gpu_alloc`, `xmem_shim_query`) queries this process into a zeroed buffer, so neither promise is tested. Three mutants left all of them passing: - dropping the current-process test; - leaving the byte untouched when the flag is clear; - testing `GetProcessId(process) != 0` instead of `== GetCurrentProcessId()`. `XMemVirtualQuery` passes the caller's process handle and buffer straight through, so both rules are reachable from real callers. The new `era_query_clear` scenario fills the 64-byte buffer with 0xff before each query. Its expected values are hand-written: - an unregistered committed page in this process reads 0x00 at +0x30; - a registered address in this process reads 0x01; - +0x31 stays 0xff in both cases; - a committed read/write page at the registered address in a suspended child (a second copy of the test program) returns 0x30, `MEM_COMMIT`, `PAGE_READWRITE` and tail 0x00, so the callers' tail check rejects it. The child never runs. It is terminated and waited for, and its handles are closed on every path. The memory is released and the region unregistered. `era_query_clear_foreign_control` (`clear --mutate foreign`) expects 0x01 for the child and must fail (`WILL_FAIL`). The change touches `tests/era_query_check.cpp` (the `clear` scenario), two `add_test` lines after the `era_query_*` foreach in `CMakeLists.txt`, and a new `era_query_clear` row in the `docs/experiments.md` era_query table. ## Verification Commit `309cfede` (`main`) plus this change, `dev` preset (Debug), Windows 11 Pro build 26300.9974, MSVC 19.51.36260, Windows SDK 10.0.26100.0. ```powershell ctest --preset dev --no-tests=error -R '^(era_query_|xmem_shim_query$|era_title_gpu_alloc$)' -V # 8/8 passed, 3 of 3 runs, including era_query_clear and the control; no era_query process left afterwards ``` `tests/docs_links_check.py`, `tests/bidi_controls_check.py` and `git diff --check` passed. ## Mutation probe I applied each mutation to `src/era_query.{h,cpp}` alone, rebuilt, ran the tests, then reverted. None of this is committed. | Mutant | Existing | `era_query_clear` | |---|---|---| | control: tail byte always 0 | killed (tail, gpu_alloc, xmem_shim_query) | fails | | current-process test dropped | **survived** | fails | | byte left untouched when the flag is clear | **survived** | fails | | `GetProcessId(process) != 0` | **survived** | fails | | tail written at length 0x30 (`>=`) | killed (short) | n/a | | region end inclusive | killed (tail) | n/a | | back-adjacent region refused | killed (registry) | n/a | | `VirtualQueryEx` failure ignored | killed (only `xmem_shim_query`) | n/a | | wrap check dropped | killed (registry) | n/a | | null-buffer check dropped | killed (crash) | n/a | ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture. - [x] I updated README/docs when a capability or build requirement changed. - [x] I did not include game files, dumps, distribution links or secrets. AI-assisted (Claude Code).
upstream-sync closed this pull request 2026-11-24 15:01:56 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
R0Y00/Xbox2Windows!1532
No description provided.