runtime: test memory transfer prerequisite and failure chain #948

Merged
Holastor merged 3 commits from upstream-pr/955 into main 2026-11-23 19:10:11 +00:00
Holastor commented 2026-11-23 18:35:51 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Holastor on 2026-11-23T18:35:51Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6566225436 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/955). Originally posted by [Holastor](https://github.com/Holastor) on 2026-11-23T18:35:51Z. --- ### 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.
upstream-sync closed this pull request 2026-11-24 06:45:34 +00:00
R0Y00 commented 2026-11-24 06:49:29 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T18:46:59Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7110644870 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/955#issuecomment-7110644870). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-23T18:46:59Z. --- 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.
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!948
No description provided.