tests: make the xmem second-commit refusals reach the path they claim #1026

Manually merged
github merged 2 commits from gh-pr/1026/head into gh-pr/1026/base 2026-11-26 22:35:54 +00:00
Owner

@⁠rasptum on GitHub · 2026-11-23 22:06 UTC · original
rasptum:tests/xmem-second-commit-review-fixes → main · +336 −47 · 3 files · 2 commits · merged 2026-11-23 23:11 UTC

Follow-up to #981, fixing the review from Leyukaka. Refs #981 #870

Which claims in #981 were tautological

  1. The two XMemVirtualAlloc "second commit" refusals never reached a second commit. The desktop XMemVirtualAlloc (src/xmem_mapped_pages.cpp) refuses with ERROR_INVALID_PARAMETER any non-null address, any size other than 16/24 GiB, any type other than 0x20402000, and any attribute/protection pair other than 0x21/PAGE_READWRITE or 3/0x801, before it looks at memory. Both calls in #981 (nullptr, 64 KiB, MEM_RESERVE|MEM_COMMIT, 0x21, PAGE_READWRITE and view1, 64 KiB, MEM_COMMIT, 0x21, PAGE_READONLY) failed on those arguments. So "leaves both live views intact" was true by construction.
  2. "Ordinary committed pages cannot alias a second VA" was in the docs, but no code tried it.
  3. The first_observable_discrepancy line was fixed text apart from the decommit error code, and it printed even when a check had failed.

The remap-over-live-view and free-while-mapped checks did exercise shim state. They are kept, and the docs now point out that the same calls succeed once the views are unmapped.

What changed

  • XMemVirtualAlloc second commit: recorded as not reachable through the current shim. Each case starts from the accepted #888 reserve-only call (null, 16 GiB, 0x20402000, 0x21, PAGE_READWRITE), which must reserve address space in the same run, and changes one variable:

    • MEM_COMMIT added to the type: refused 87
    • protection PAGE_READONLY: refused 87
    • address = a live reservation from the accepted call, then the same address after it is released: refused 87 both times

    Since the paired accepted call succeeds and the live and free targets are refused the same way, each refusal comes from argument validation, so none is reported as a second-commit result. The output line says NOT REACHABLE through the current shim.

  • Second private commit at another VA (placeholder replaced with VirtualAlloc2(..., MEM_REPLACE_PLACEHOLDER)): zero-filled, does not show page 0's bytes, and writes through it do not reach page 0. The fixture does not try to map page 0 itself at a second VA, because Win32 aliases memory only through section objects and no call takes an existing MEM_PRIVATE range as a mapping source. The docs now say this as a statement about the API surface rather than as a measurement.

  • first_observable_discrepancy is built from measured values: the private and mapped VirtualQuery type, the private decommit result, second-VA independence, the mapped decommit error, alias visibility, per-view isolation and unmap/remap persistence. It prints only when every check behind those fields passed. Otherwise it prints not printed; failing_fields=....

  • Seven mutation controls (xmem_commit_protection_mutate_*). Each one runs the same binary with --mutate <name>, which flips one expected value. A control passes only if the check that owns that expectation prints check_failed: <check> and the run does not print PASS. The three that feed the discrepancy line also require failing_fields=<field>. An unknown mutation name fails.

    Mutation Caught by
    xva_positive_refused xva_accepted_pair
    xva_commit_accepted xva_commit_bit
    xva_readonly_accepted xva_protection
    xva_state_dependent xva_address_state_independent
    private_second_va_aliases private_second_va_independent + failing_fields=private_second_va
    private_type_mapped private_type + failing_fields=private_type
    mapped_decommit_succeeds mapped_decommit + failing_fields=mapped_decommit

No change to src/. Only the fixture, its CMake registration and the docs section changed.

Evidence

Environment: Windows 10 Pro 19045, MSVC VS2022 x64, no GPU involved.

Commands (dev and release presets):

cmake --build --preset dev
ctest --preset dev --no-tests=error -R "xmem_commit_protection|xmem|era_heap|desktop_memory"
cmake --build --preset release
ctest --preset release --no-tests=error -R "xmem_commit_protection|xmem|era_heap|desktop_memory"
python -B tests/docs_links_check.py; python -B tests/bidi_controls_check.py
python -B tests/xmem_attribute_scan_check.py; python -B tests/hardware_reports_check.py
  • Full build plus that filter: 33/33 passed in dev and 33/33 in release on base cd879076 (the main run plus 7 mutation controls are among the 33). No skips. All four Python checks passed.
  • main then moved to ee04692c, adding only unrelated CMakeLists lines (no src/ or fixture changes). After rebasing onto it, -R xmem_commit_protection (main run plus 7 mutations) passed 8/8 in dev and 8/8 in release. The full filter was not rerun on this final base.

Measured output (dev):

private_second_va: PASS (zero_filled=1 sees_page0=0 page0_sees_second=0 page0_unchanged=1)
ordinary_commit_protection: PASS (bad_zero=87 bad_conflict=87 bad_span=487 over_commit=487)
shared_view_protection: PASS (bad_zero=87 bad_span=487 mapped_decommit=87 remap=87 free=87)
xmem_virtual_alloc_second_commit: NOT REACHABLE through the current shim (accepted=reserved commit_bit_err=87 readonly_err=87 address_live_err=87 address_free_err=87; each refusal is argument validation, not memory state)
first_observable_discrepancy: ordinary_commit=type 0x20000, MEM_DECOMMIT succeeded, second-VA commit independent vs live_shared_view=type 0x40000, MEM_DECOMMIT refused err=87, second view aliased live, per-view VirtualProtect isolation observed, bytes persisted across unmap/remap
xmem_commit_protection: PASS

Still a hypothesis: whether a console caller needs a live shared-page view or ordinary committed pages at any given second-commit site. This fixture does not establish full-game startup.

🤖 Generated with Claude Code

**@⁠rasptum** on GitHub · 2026-11-23 22:06 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1026) `rasptum:tests/xmem-second-commit-review-fixes` → `main` · +336 −47 · 3 files · 2 commits · merged 2026-11-23 23:11 UTC Follow-up to #981, fixing the review from Leyukaka. Refs #981 #870 ## Which claims in #981 were tautological 1. **The two `XMemVirtualAlloc` "second commit" refusals never reached a second commit.** The desktop `XMemVirtualAlloc` (`src/xmem_mapped_pages.cpp`) refuses with `ERROR_INVALID_PARAMETER` any non-null address, any size other than 16/24 GiB, any type other than `0x20402000`, and any attribute/protection pair other than `0x21`/`PAGE_READWRITE` or `3`/`0x801`, before it looks at memory. Both calls in #981 (`nullptr, 64 KiB, MEM_RESERVE|MEM_COMMIT, 0x21, PAGE_READWRITE` and `view1, 64 KiB, MEM_COMMIT, 0x21, PAGE_READONLY`) failed on those arguments. So "leaves both live views intact" was true by construction. 2. **"Ordinary committed pages cannot alias a second VA"** was in the docs, but no code tried it. 3. **The `first_observable_discrepancy` line** was fixed text apart from the decommit error code, and it printed even when a check had failed. The remap-over-live-view and free-while-mapped checks did exercise shim state. They are kept, and the docs now point out that the same calls succeed once the views are unmapped. ## What changed - **XMemVirtualAlloc second commit: recorded as not reachable through the current shim.** Each case starts from the accepted #888 reserve-only call (null, 16 GiB, `0x20402000`, `0x21`, `PAGE_READWRITE`), which must reserve address space in the same run, and changes one variable: - `MEM_COMMIT` added to the type: refused `87` - protection `PAGE_READONLY`: refused `87` - address = a live reservation from the accepted call, then the same address after it is released: refused `87` both times Since the paired accepted call succeeds and the live and free targets are refused the same way, each refusal comes from argument validation, so none is reported as a second-commit result. The output line says `NOT REACHABLE through the current shim`. - **Second private commit at another VA** (placeholder replaced with `VirtualAlloc2(..., MEM_REPLACE_PLACEHOLDER)`): zero-filled, does not show page 0's bytes, and writes through it do not reach page 0. The fixture does not try to map page 0 itself at a second VA, because Win32 aliases memory only through section objects and no call takes an existing `MEM_PRIVATE` range as a mapping source. The docs now say this as a statement about the API surface rather than as a measurement. - **`first_observable_discrepancy`** is built from measured values: the private and mapped `VirtualQuery` type, the private decommit result, second-VA independence, the mapped decommit error, alias visibility, per-view isolation and unmap/remap persistence. It prints only when every check behind those fields passed. Otherwise it prints `not printed; failing_fields=...`. - **Seven mutation controls** (`xmem_commit_protection_mutate_*`). Each one runs the same binary with `--mutate <name>`, which flips one expected value. A control passes only if the check that owns that expectation prints `check_failed: <check>` and the run does not print `PASS`. The three that feed the discrepancy line also require `failing_fields=<field>`. An unknown mutation name fails. | Mutation | Caught by | |---|---| | `xva_positive_refused` | `xva_accepted_pair` | | `xva_commit_accepted` | `xva_commit_bit` | | `xva_readonly_accepted` | `xva_protection` | | `xva_state_dependent` | `xva_address_state_independent` | | `private_second_va_aliases` | `private_second_va_independent` + `failing_fields=private_second_va` | | `private_type_mapped` | `private_type` + `failing_fields=private_type` | | `mapped_decommit_succeeds` | `mapped_decommit` + `failing_fields=mapped_decommit` | No change to `src/`. Only the fixture, its CMake registration and the docs section changed. ## Evidence Environment: Windows 10 Pro 19045, MSVC VS2022 x64, no GPU involved. Commands (dev and release presets): ```powershell cmake --build --preset dev ctest --preset dev --no-tests=error -R "xmem_commit_protection|xmem|era_heap|desktop_memory" cmake --build --preset release ctest --preset release --no-tests=error -R "xmem_commit_protection|xmem|era_heap|desktop_memory" python -B tests/docs_links_check.py; python -B tests/bidi_controls_check.py python -B tests/xmem_attribute_scan_check.py; python -B tests/hardware_reports_check.py ``` - Full build plus that filter: 33/33 passed in dev and 33/33 in release on base `cd879076` (the main run plus 7 mutation controls are among the 33). No skips. All four Python checks passed. - main then moved to `ee04692c`, adding only unrelated CMakeLists lines (no `src/` or fixture changes). After rebasing onto it, `-R xmem_commit_protection` (main run plus 7 mutations) passed 8/8 in dev and 8/8 in release. The full filter was not rerun on this final base. Measured output (dev): ``` private_second_va: PASS (zero_filled=1 sees_page0=0 page0_sees_second=0 page0_unchanged=1) ordinary_commit_protection: PASS (bad_zero=87 bad_conflict=87 bad_span=487 over_commit=487) shared_view_protection: PASS (bad_zero=87 bad_span=487 mapped_decommit=87 remap=87 free=87) xmem_virtual_alloc_second_commit: NOT REACHABLE through the current shim (accepted=reserved commit_bit_err=87 readonly_err=87 address_live_err=87 address_free_err=87; each refusal is argument validation, not memory state) first_observable_discrepancy: ordinary_commit=type 0x20000, MEM_DECOMMIT succeeded, second-VA commit independent vs live_shared_view=type 0x40000, MEM_DECOMMIT refused err=87, second view aliased live, per-view VirtualProtect isolation observed, bytes persisted across unmap/remap xmem_commit_protection: PASS ``` Still a hypothesis: whether a console caller needs a live shared-page view or ordinary committed pages at any given second-commit site. This fixture does not establish full-game startup. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
The two XMemVirtualAlloc "second commit" refusals from #981 failed on
argument validation alone, so "leaves both live views intact" held by
construction. Replace them with cases that start from the accepted
reserve-only call and change one variable each (MEM_COMMIT bit,
PAGE_READONLY, live vs released target address). The accepted call must
succeed in the same run, and the live and released targets must be
refused the same way. The verdict is recorded as "not reachable through
the current shim" instead of a refusal.

Measure a second private commit at another VA instead of claiming that
ordinary pages cannot alias. Print first_observable_discrepancy only from
measured fields whose checks passed, otherwise list the failing fields.
Add seven --mutate controls, one per reworked expectation, each passing
only when its owning check reports check_failed.

Refs #981 #870

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 22:35:53 +00:00
github manually merged commit ee2d05ebd7 into gh-pr/1026/base 2026-11-26 22:35:54 +00:00
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-23 22:29 UTC · original

I reproduced all eight xmem commit-protection CTests in local Windows Release. The /O2 job failed earlier in the independent cpu_native_reloc_free fixture: its fixed preferred address was already occupied and the setup returned Win32 487. The xmem checks passed there. I am investigating the shared fixture separately. This PR is held until both Windows checks are green.

**@⁠R0Y00** on GitHub · 2026-11-23 22:29 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1026#issuecomment-7115816302) I reproduced all eight xmem commit-protection CTests in local Windows Release. The /O2 job failed earlier in the independent `cpu_native_reloc_free` fixture: its fixed preferred address was already occupied and the setup returned Win32 487. The xmem checks passed there. I am investigating the shared fixture separately. This PR is held until both Windows checks are green.
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-23 22:54 UTC · original

The shared preferred-address fixture fix #1040 is on main. The updated candidate ee2d05eb passed all nine targeted Windows Release tests (eight xmem controls and the native relocation fixture). Fresh CI is running on this head.

**@⁠R0Y00** on GitHub · 2026-11-23 22:54 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1026#issuecomment-7116321496) The shared preferred-address fixture fix #1040 is on main. The updated candidate ee2d05eb passed all nine targeted Windows Release tests (eight xmem controls and the native relocation fixture). Fresh CI is running on this head.
This discussion has been locked. Commenting is limited to contributors.
No description provided.