tests: start the XMem default pair EXE natively and under pe_map #906

Merged
rasptum merged 1 commit from upstream-pr/913 into main 2026-11-23 17:13:08 +00:00
rasptum commented 2026-11-23 16:57:51 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by rasptum on 2026-11-23T16:57:51Z.


Refs #875, #879 and #870.

This is a test and evidence follow-up to #879, as R0Y00 asked on #875. It changes only tests, CMake and docs; src/ and tools/pe_map.cpp are untouched.

cpu_native_xmem_default_pair builds tests/cpu/xmem_default_pair.asm into four x64 EXEs. Each imports XMemAllocDefault/XMemFreeDefault by name from the desktop xmem.dll and starts through exe_startup.asm/finish_exe. Each EXE is launched normally, then mapped and started with pe_map_run. The body returns 0x875, or 0xF00 plus the first failing step.

Named checks (each prints its own line)

Check What it requires
pe_import_names pefile finds xmem.dll imported for exactly XMemAllocDefault and XMemFreeDefault, by name, in all four EXEs.
mapped_resolver_names The pe_map resolver callback records its requests. It must be asked for both names plus the five other imports, and nothing else. The existing Mapper hook is reused, with no pe_map.cpp change.
heap_block (steps 1–5) The Bink-style heap word gives a 32-byte-aligned, zero-filled, writable block that a busy heap entry contains.
graphics_block (6–9) The AMD-style graphics word gives a 64 KiB-aligned, zero-filled, writable block.
rejected_inputs (10–14) Reserved bit 33, zero size, page size 3 and memory type 15 each return null, and the last error is still the 0 set beforehand.
induced_failure (15–18) Valid words with 2^46 bytes return null. For the graphics word the last error is nonzero, coming from VirtualAlloc. A control allocation with the same word then succeeds and is freed.
graphics_release_virtualquery (19–20) VirtualQuery reports the graphics VA as MEM_FREE after XMemFreeDefault.
heap_release_ownership (21) A separate ownership check, not VirtualQuery. The new tests/cpu/heap_probe.cpp locks and HeapWalks every process heap. Before free, a busy entry must contain the block; after free, none may.

Negative controls

Variant Windows launch pe_map First failing check
original 0x875 0x875 none
skip_gpu_free 0xf14 0xf14 graphics_release_virtualquery
skip_heap_free 0xf15 0xf15 heap_release_ownership
uninduced (4096 bytes at step 15) 0xf0f 0xf0f induced_failure

A provider missing XMemAllocDefault or XMemFreeDefault stops the mapping before the entry point with unresolved import xmem.dll!<name>.

Results

Windows 10 Pro 10.0.19045.6466, MSVC 19.44.35207.1 x64, CMake/Ninja, commit 24f4297 on origin/main 02db28b. CPU-only tests, so no adapter or debug layer is involved.

cmake --preset dev
cmake --build --preset dev --target xmem_shim xmem_shim_check era_heap_check memory_query_check era_physical_check pe_map cpu_exe_io cpu_heap_probe cpu_xmem_default_original cpu_xmem_default_skip_gpu_free cpu_xmem_default_skip_heap_free cpu_xmem_default_uninduced cpu_xmem_physical_original cpu_xmem_physical_full_count cpu_xmem_physical_skip_release
ctest --preset dev --no-tests=error -R 'era_heap|era_physical|desktop_memory_query|^xmem_shim_(exports|allocation|default_allocation|physical_pages|query|working_set|working_set_aggregation)$|^cpu_native_xmem_(default|physical)_pair$'
ctest --preset dev --no-tests=error -R '^cpu_native_xmem_default_pair$' --repeat until-fail:5
  • dev: 20/20 passed, including the merged #892 physical-page tests,, and cpu_native_xmem_default_pair passed 5/5 repeats.
  • release (same commands with release): 20/20 passed, with 5/5 repeats.
  • tests/form_coverage_check.py, tests/docs_links_check.py and tests/bidi_controls_check.py pass.
  • No capability skips.
  • The CTest name is distinct from #892's cpu_native_xmem_physical_pair and #887's cpu_native_xmem_physical. The docs block sits at the end of the "Desktop xmem.dll" section.

ABI evidence vs desktop behavior

  • ABI candidate: SlimEra era.h at 912bb11 declares PVOID WINAPI XMemAllocDefault(SIZE_T, ULONGLONG) and void WINAPI XMemFreeDefault(PVOID, ULONGLONG). That is an independent reimplementation's declaration, not console evidence.
  • Measured here: only what the Windows shim does: alignment, zero fill, null for rejected inputs and for an induced allocation failure, and release with the matching word. The last-error split between rejected input and induced failure is observed desktop behavior, not a contract.
  • Still open: console failure behavior and error codes, heap alignment and zero fill on the console, and release behavior when allocation hooks are installed.

No game files, dumps or binaries. All attribute words and sizes are synthetic.

🤖 Generated with Claude Code

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6564409105 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/913). Originally posted by [rasptum](https://github.com/rasptum) on 2026-11-23T16:57:51Z. --- Refs #875, #879 and #870. This is a test and evidence follow-up to #879, as R0Y00 asked on #875. It changes only tests, CMake and docs; `src/` and `tools/pe_map.cpp` are untouched. `cpu_native_xmem_default_pair` builds `tests/cpu/xmem_default_pair.asm` into four x64 EXEs. Each imports `XMemAllocDefault`/`XMemFreeDefault` by name from the desktop `xmem.dll` and starts through `exe_startup.asm`/`finish_exe`. Each EXE is launched normally, then mapped and started with `pe_map_run`. The body returns `0x875`, or `0xF00` plus the first failing step. ## Named checks (each prints its own line) | Check | What it requires | |---|---| | `pe_import_names` | `pefile` finds `xmem.dll` imported for exactly `XMemAllocDefault` and `XMemFreeDefault`, by name, in all four EXEs. | | `mapped_resolver_names` | The `pe_map` resolver callback records its requests. It must be asked for both names plus the five other imports, and nothing else. The existing `Mapper` hook is reused, with no `pe_map.cpp` change. | | `heap_block` (steps 1–5) | The Bink-style heap word gives a 32-byte-aligned, zero-filled, writable block that a busy heap entry contains. | | `graphics_block` (6–9) | The AMD-style graphics word gives a 64 KiB-aligned, zero-filled, writable block. | | `rejected_inputs` (10–14) | Reserved bit 33, zero size, page size 3 and memory type 15 each return null, and the last error is still the 0 set beforehand. | | `induced_failure` (15–18) | Valid words with 2^46 bytes return null. For the graphics word the last error is nonzero, coming from `VirtualAlloc`. A control allocation with the same word then succeeds and is freed. | | `graphics_release_virtualquery` (19–20) | `VirtualQuery` reports the graphics VA as `MEM_FREE` after `XMemFreeDefault`. | | `heap_release_ownership` (21) | A separate ownership check, not `VirtualQuery`. The new `tests/cpu/heap_probe.cpp` locks and `HeapWalk`s every process heap. Before free, a busy entry must contain the block; after free, none may. | ## Negative controls | Variant | Windows launch | `pe_map` | First failing check | |---|---|---|---| | `original` | `0x875` | `0x875` | none | | `skip_gpu_free` | `0xf14` | `0xf14` | `graphics_release_virtualquery` | | `skip_heap_free` | `0xf15` | `0xf15` | `heap_release_ownership` | | `uninduced` (4096 bytes at step 15) | `0xf0f` | `0xf0f` | `induced_failure` | A provider missing `XMemAllocDefault` or `XMemFreeDefault` stops the mapping before the entry point with `unresolved import xmem.dll!<name>`. ## Results Windows 10 Pro 10.0.19045.6466, MSVC 19.44.35207.1 x64, CMake/Ninja, commit `24f4297` on `origin/main` `02db28b`. CPU-only tests, so no adapter or debug layer is involved. ```powershell cmake --preset dev cmake --build --preset dev --target xmem_shim xmem_shim_check era_heap_check memory_query_check era_physical_check pe_map cpu_exe_io cpu_heap_probe cpu_xmem_default_original cpu_xmem_default_skip_gpu_free cpu_xmem_default_skip_heap_free cpu_xmem_default_uninduced cpu_xmem_physical_original cpu_xmem_physical_full_count cpu_xmem_physical_skip_release ctest --preset dev --no-tests=error -R 'era_heap|era_physical|desktop_memory_query|^xmem_shim_(exports|allocation|default_allocation|physical_pages|query|working_set|working_set_aggregation)$|^cpu_native_xmem_(default|physical)_pair$' ctest --preset dev --no-tests=error -R '^cpu_native_xmem_default_pair$' --repeat until-fail:5 ``` - dev: 20/20 passed, including the merged #892 physical-page tests,, and `cpu_native_xmem_default_pair` passed 5/5 repeats. - release (same commands with `release`): 20/20 passed, with 5/5 repeats. - `tests/form_coverage_check.py`, `tests/docs_links_check.py` and `tests/bidi_controls_check.py` pass. - No capability skips. - The CTest name is distinct from #892's `cpu_native_xmem_physical_pair` and #887's `cpu_native_xmem_physical`. The docs block sits at the end of the "Desktop xmem.dll" section. ## ABI evidence vs desktop behavior - **ABI candidate:** [SlimEra `era.h` at 912bb11](https://github.com/XWine1/SlimEra/blob/912bb1123e84f32023af6685989ac5d6747d767a/era.h) declares `PVOID WINAPI XMemAllocDefault(SIZE_T, ULONGLONG)` and `void WINAPI XMemFreeDefault(PVOID, ULONGLONG)`. That is an independent reimplementation's declaration, not console evidence. - **Measured here:** only what the Windows shim does: alignment, zero fill, null for rejected inputs and for an induced allocation failure, and release with the matching word. The last-error split between rejected input and induced failure is observed desktop behavior, not a contract. - **Still open:** console failure behavior and error codes, heap alignment and zero fill on the console, and release behavior when allocation hooks are installed. No game files, dumps or binaries. All attribute words and sizes are synthetic. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
upstream-sync closed this pull request 2026-11-24 06:45:22 +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!906
No description provided.