runtime: test memory transfer prerequisite and failure chain #955

Manually merged
github merged 3 commits from gh-pr/955/head into gh-pr/955/base 2026-11-26 22:31:02 +00:00
Owner

@⁠Holastor on GitHub · 2026-11-23 18:35 UTC · original
Holastor:xmem/transfer-prerequisite-chain → main · +553 −0 · 6 files · 3 commits · merged 2026-11-23 19:10 UTC

Summary

Adds a companion source-built caller (tests/cpu/transfer_chain_caller.asm) and controlled provider (tests/cpu/transfer_chain_provider.cpp) for testing the prerequisite query, working-set statistics evaluation, and transfer memory sequence under both the Windows native loader and pe_map.

The caller starts through tests/cpu/exe_startup.asm, imports XMemIsToolsMemAvailable, XMemGetWorkingSetStatistics, and XMemTransferMemory by name from xmem.dll, and exits cleanly via cpu_exe_io!finish_exe.

Verified cases

  1. Case 1 (Success reaches transfer): Tools-memory query returns TRUE, XMemGetWorkingSetStatistics with selector 0x2000000A reports budget (32 MiB total, 16 MiB used), and memory transfer executes a 16 MiB transfer under test-provider policy partition 1. Returns milestone exit code 0x870.
  2. Case 2 (Tools-memory unavailable): When tools-memory query returns FALSE (the no-tools desktop policy established in #896), sequence is blocked immediately. XMemTransferMemory is never called (transfer_calls == 0), returning exit code 0x101.
  3. Case 3 (Working-set statistics failure): When XMemGetWorkingSetStatistics returns FALSE or fails, sequence is aborted immediately. XMemTransferMemory is never called (transfer_calls == 0), returning exit code 0x102.
  4. Case 4 (Zero available budget): When working-set statistics reports zero available budget (total <= used), transfer is skipped. XMemTransferMemory is never called (transfer_calls == 0), returning exit code 0x103.
  5. Case 5 (Transfer failure isolation): When XMemTransferMemory returns FALSE, the failure is isolated and prior state remains intact. The provider records the transfer attempt (transfer_calls == 1) without reporting successful ownership transfer, returning exit code 0x104.
  6. Changed-selector patch control: Altering 0x2000000A to 0x2000000B in the caller binary causes the query to fail under both loaders, aborting with exit code 0x102 and leaving transfer uncalled.
  7. Negative withholding controls: Withholding any of XMemIsToolsMemAvailable, XMemGetWorkingSetStatistics, or XMemTransferMemory stops pe_map at import resolution before entry with STATUS["unresolved"] naming the missing export.
  8. Clean exit with live worker: With CPU_CRC_TEST_LIVE_WORKER=1, a live worker thread outlives the body under the Windows loader, and finish_exe terminates the process cleanly with code 0x870.

Tested commands and environment

  • Environment: Windows 11 x64 (build 26100), MSVC 19.51, CMake/Ninja, Python 3.11 (out/pe-env).
  • Tested commit: 06831af
  • Commands:
    cmake --preset dev
    cmake --build --preset dev --target cpu_transfer_chain_caller cpu_transfer_chain_provider
    ctest --preset dev --no-tests=error -R '^cpu_native_transfer_chain$' -V
    cmake --preset release
    cmake --build --preset release --target cpu_transfer_chain_caller cpu_transfer_chain_provider
    ctest --preset release --no-tests=error -R '^cpu_native_transfer_chain$' -V
    .\out\pe-env\Scripts\python.exe -B tests/docs_links_check.py
    .\out\pe-env\Scripts\python.exe -B tests/bidi_controls_check.py
    .\out\pe-env\Scripts\python.exe -B tests/form_coverage_check.py
    .\out\pe-env\Scripts\python.exe -B tests/hardware_reports_check.py
    
  • All checks passed 100%.

Refs #870.

**@⁠Holastor** on GitHub · 2026-11-23 18:35 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/955) `Holastor:xmem/transfer-prerequisite-chain` → `main` · +553 −0 · 6 files · 3 commits · merged 2026-11-23 19:10 UTC ### Summary Adds a companion source-built caller (`tests/cpu/transfer_chain_caller.asm`) and controlled provider (`tests/cpu/transfer_chain_provider.cpp`) for testing the prerequisite query, working-set statistics evaluation, and transfer memory sequence under both the Windows native loader and `pe_map`. The caller starts through `tests/cpu/exe_startup.asm`, imports `XMemIsToolsMemAvailable`, `XMemGetWorkingSetStatistics`, and `XMemTransferMemory` by name from `xmem.dll`, and exits cleanly via `cpu_exe_io!finish_exe`. ### Verified cases 1. **Case 1 (Success reaches transfer)**: Tools-memory query returns `TRUE`, `XMemGetWorkingSetStatistics` with selector `0x2000000A` reports budget (32 MiB total, 16 MiB used), and memory transfer executes a 16 MiB transfer under test-provider policy partition 1. Returns milestone exit code `0x870`. 2. **Case 2 (Tools-memory unavailable)**: When tools-memory query returns `FALSE` (the no-tools desktop policy established in #896), sequence is blocked immediately. `XMemTransferMemory` is never called (`transfer_calls == 0`), returning exit code `0x101`. 3. **Case 3 (Working-set statistics failure)**: When `XMemGetWorkingSetStatistics` returns `FALSE` or fails, sequence is aborted immediately. `XMemTransferMemory` is never called (`transfer_calls == 0`), returning exit code `0x102`. 4. **Case 4 (Zero available budget)**: When working-set statistics reports zero available budget (`total <= used`), transfer is skipped. `XMemTransferMemory` is never called (`transfer_calls == 0`), returning exit code `0x103`. 5. **Case 5 (Transfer failure isolation)**: When `XMemTransferMemory` returns `FALSE`, the failure is isolated and prior state remains intact. The provider records the transfer attempt (`transfer_calls == 1`) without reporting successful ownership transfer, returning exit code `0x104`. 6. **Changed-selector patch control**: Altering `0x2000000A` to `0x2000000B` in the caller binary causes the query to fail under both loaders, aborting with exit code `0x102` and leaving transfer uncalled. 7. **Negative withholding controls**: Withholding any of `XMemIsToolsMemAvailable`, `XMemGetWorkingSetStatistics`, or `XMemTransferMemory` stops `pe_map` at import resolution before entry with `STATUS["unresolved"]` naming the missing export. 8. **Clean exit with live worker**: With `CPU_CRC_TEST_LIVE_WORKER=1`, a live worker thread outlives the body under the Windows loader, and `finish_exe` terminates the process cleanly with code `0x870`. ### Tested commands and environment - Environment: Windows 11 x64 (build 26100), MSVC 19.51, CMake/Ninja, Python 3.11 (`out/pe-env`). - Tested commit: `06831af` - Commands: ```powershell cmake --preset dev cmake --build --preset dev --target cpu_transfer_chain_caller cpu_transfer_chain_provider ctest --preset dev --no-tests=error -R '^cpu_native_transfer_chain$' -V cmake --preset release cmake --build --preset release --target cpu_transfer_chain_caller cpu_transfer_chain_provider ctest --preset release --no-tests=error -R '^cpu_native_transfer_chain$' -V .\out\pe-env\Scripts\python.exe -B tests/docs_links_check.py .\out\pe-env\Scripts\python.exe -B tests/bidi_controls_check.py .\out\pe-env\Scripts\python.exe -B tests/form_coverage_check.py .\out\pe-env\Scripts\python.exe -B tests/hardware_reports_check.py ``` - All checks passed 100%. Refs #870.
Add a source-built caller (tests/cpu/transfer_chain_caller.asm) and controlled test provider (tests/cpu/transfer_chain_provider.cpp) exercising the memory transfer sequence:

1. Case 1 (Success reaches transfer): tools-memory available, working-set statistics returns budget, reaches transfer (exit 0x870, 16 MiB transferred).
2. Case 2 (Tools-memory unavailable): tools-memory query returns FALSE (no-tools desktop policy), transfer is never called (exit 0x101).
3. Case 3 (Working-set statistics failure): statistics query fails, transfer is never called (exit 0x102).
4. Case 4 (Zero available budget): total budget <= used budget, transfer is skipped (exit 0x103).
5. Case 5 (Transfer failure isolation): transfer fails, prior state remains intact and no unbacked ownership transfer is reported (exit 0x104).
6. Changed-selector patch control: altering selector 0x2000000a to 0x2000000b fails statistics query and aborts with exit code 0x102.
7. Withholding negative controls: withholding any prerequisite export stops pe_map before entry with STATUS['unresolved'].

Refs #870.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 22:31:01 +00:00
github manually merged commit e1b0930fb3 into gh-pr/955/base 2026-11-26 22:31:02 +00:00
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-23 18:46 UTC · original

The independent Windows Release run passed cpu_native_transfer_chain and cpu_native_transfer_mem. I tightened the controls on this branch. The failed transfer records the requested 16 MiB, all three missing imports leave an empty trace, and the child fixture ignores inherited test switches unless a case selects them. The run also passed with conflicting switches set in the parent environment. The fixture records a provider result and requested bytes; it has no backing pages or ownership state.

**@⁠R0Y00** on GitHub · 2026-11-23 18:46 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/955#issuecomment-7110644870) The independent Windows Release run passed cpu_native_transfer_chain and cpu_native_transfer_mem. I tightened the controls on this branch. The failed transfer records the requested 16 MiB, all three missing imports leave an empty trace, and the child fixture ignores inherited test switches unless a case selects them. The run also passed with conflicting switches set in the parent environment. The fixture records a provider result and requested bytes; it has no backing pages or ownership state.
This discussion has been locked. Commenting is limited to contributors.
No description provided.