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

Merged
rasptum merged 2 commits from upstream-pr/1026 into main 2026-11-23 23:11:20 +00:00
rasptum commented 2026-11-23 22:06:48 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by rasptum on 2026-11-23T22:06:48Z.


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

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6569800200 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1026). Originally posted by [rasptum](https://github.com/rasptum) on 2026-11-23T22:06:48Z. --- 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)
upstream-sync closed this pull request 2026-11-24 06:45:54 +00:00
R0Y00 commented 2026-11-24 06:49:47 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T22:29:17Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7115816302 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1026#issuecomment-7115816302). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-23T22:29:17Z. --- 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 commented 2026-11-24 06:49:50 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T22:54:26Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7116321496 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1026#issuecomment-7116321496). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-23T22:54:26Z. --- 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.
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!1019
No description provided.