cpu: end the ordinal-package and startup fixture EXEs with their entry result #1376

Merged
Maxim-Root merged 1 commit from upstream-pr/1383 into main 2026-11-24 10:13:15 +00:00
Maxim-Root commented 2026-11-24 10:03:18 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Maxim-Root on 2026-11-24T10:03:18Z.


Change

cpu_package_ordinal_exe and cpu_startup_exe are CRT-free EXEs whose entry point returned its value. When the entry thread returns, nothing ends the process while another thread is alive. Under CPU load, an idle loader or thread-pool worker kept some launches running for about 30 s and ended them with exit code 0x0. This is the #281 failure that #589 fixed for the exe_start fixtures. Under a parallel CTest run, cpu_native_package_ordinal_startup and cpu_native_startup failed with TimeoutExpired ... timed out after 30 seconds. Measurements are in #1375.

  • tests/cpu/exe_exit.h adds exe_finish(code). When Windows started the image as the process EXE (PEB::ImageBaseAddress == &__ImageBase), it ends the process through ntdll!RtlExitUserProcess, resolved from ntdll's export table. In a host mapping it returns the value, like finish_exe in exe_io.cpp. The helper adds no import, so the ordinal fixture keeps its single #77 import, which import_fixture still asserts for both builds.

  • Both entry points end through exe_finish. Their expected values are unchanged: 13 and 14 for the ordinal providers, and 0x103020e plus the two DLL controls for the startup EXE, native and mapped.

  • Deterministic controls, modelled on #589's live-worker control:

    • cpu_package_ordinal_live is the provider with a mix_args that leaves a sleeping thread running;
    • cpu_startup_exe_linger starts one before its entry ends.

    With that thread alive, the native EXE must still exit with its result within 10 s. The cpu_package_ordinal_exe_return and cpu_startup_exe_linger_return builds (RETURN_FROM_ENTRY) return from the entry as before and must still be alive after 3 s, which shows the control can see a lingering process. The lingering builds run natively only, because in a host mapping the thread would run unmapped code after the release.

  • docs/experiments.md: both fixture sections describe the change and the controls, and the cpu_native_startup build command lists the two new targets.

Fixes #1375. Refs #281, #589, #1173: #1173 marks only cpu_native_worker_alive RUN_SERIAL for --parallel 4, and these two tests would otherwise stay exposed there.

Verification

At 098cf79a (on e1316e1c). The same change rebased on a34a97dc gave the same results below. Windows 11 Pro 26300.9818, MSVC 14.44.35207, Python 3.12.10, Ryzen 7 7800X3D (16 logical CPUs):

ctest --preset dev --no-tests=error -R '^cpu_native_(package_ordinal_startup|startup)$' -V
ordinal @77: native and pe_map package startup exited 13, correct dependency order
ordinal @77: native and pe_map package startup exited 14, correct dependency order
lingering thread: native EXE exited 13 while the provider's thread was alive; the returning control was still alive after 3 s
native: LOG:abtew2w3m1 exit 0x103020e
mapped: LOG:abtew2w3m1 exit 0x103020e; mapped in order ['cpu_startup_a.dll', 'cpu_startup_b.dll', 'cpu_startup_exe.exe']
lingering thread: native EXE exited 0x103020e with the full log while its thread was alive; the returning control was still alive after 3 s
100% tests passed, 0 tests failed out of 2
  • --repeat until-fail:5 of both tests: 5/5 in dev (Debug) and 5/5 in release (/O2). In the Release build, cpu_package_ordinal_exe.exe still imports only cpu_package_ordinal_provider.dll ordinal 77 (dumpbin /imports), with no memcpy/memset/memcmp.
  • Load test from #1375: 16 launcher processes calling exe_process.launch() with a 40 s deadline, while 16 busy loops saturate the CPU. Before the change, 78 of 7,500 and 9 of 2,400 launches were slow, with exit 0x0 after ~30 s or still alive at 40 s. After it, 0 of 4,000 (cpu_package_ordinal_exe, all 0xd) and 0 of 1,600 (cpu_startup_exe, all 0x103020e).
  • ctest --preset dev --no-tests=error -E '_hardware$' -j 16, three runs: both tests passed in all three. Before the change, at least one of them failed in most -j 16 runs. The remaining failures were cpu_native_load_config_callback in all three runs, which this host's system CFG setting causes (#1366, fixed by #1367), and cpu_native_worker_alive in one run, which is timing-sensitive (#1173 marks it RUN_SERIAL).
  • ctest --preset pr --no-tests=error -j 16 with X2W_REQUIRE_SPIRV_TOOLS=1: 24/24. tests/docs_links_check.py and tests/bidi_controls_check.py pass.

These two tests are not in the pr preset, so the Build and test on Windows check on this PR does not run them. A full workflow_dispatch run of the Windows workflow on this branch in my fork (Debug and Release suites, hosted windows-2025) is here: https://github.com/Maxim-Root/Xbox2Windows/actions/runs/45370885886. I will add its result in a comment.

Evidence and follow-up

No binaries are added: all fixtures are built from the sources in this PR. As in #589, the identity of the thread that kept the unpatched process alive is inferred, not proven. It was the only live thread after the entry thread ended with the correct value, and its start address was not resolved.

Interaction to note: exe_finish decides "native launch" from PEB::ImageBaseAddress, as finish_exe does through GetModuleHandleW(nullptr). If a mapper starts reporting the mapped EXE as the process image (#1151), both helpers need the same adjustment.

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed.
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted (Claude Code).

🤖 Generated with Claude Code

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6579302789 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1383). Originally posted by [Maxim-Root](https://github.com/Maxim-Root) on 2026-11-24T10:03:18Z. --- ## Change `cpu_package_ordinal_exe` and `cpu_startup_exe` are CRT-free EXEs whose entry point returned its value. When the entry thread returns, nothing ends the process while another thread is alive. Under CPU load, an idle loader or thread-pool worker kept some launches running for about 30 s and ended them with exit code `0x0`. This is the #281 failure that #589 fixed for the `exe_start` fixtures. Under a parallel CTest run, `cpu_native_package_ordinal_startup` and `cpu_native_startup` failed with `TimeoutExpired ... timed out after 30 seconds`. Measurements are in #1375. - **`tests/cpu/exe_exit.h`** adds `exe_finish(code)`. When Windows started the image as the process EXE (`PEB::ImageBaseAddress == &__ImageBase`), it ends the process through `ntdll!RtlExitUserProcess`, resolved from ntdll's export table. In a host mapping it returns the value, like `finish_exe` in `exe_io.cpp`. The helper adds **no import**, so the ordinal fixture keeps its single `#77` import, which `import_fixture` still asserts for both builds. - Both entry points end through `exe_finish`. Their expected values are unchanged: 13 and 14 for the ordinal providers, and `0x103020e` plus the two DLL controls for the startup EXE, native and mapped. - **Deterministic controls**, modelled on #589's live-worker control: - `cpu_package_ordinal_live` is the provider with a `mix_args` that leaves a sleeping thread running; - `cpu_startup_exe_linger` starts one before its entry ends. With that thread alive, the native EXE must still exit with its result within 10 s. The `cpu_package_ordinal_exe_return` and `cpu_startup_exe_linger_return` builds (`RETURN_FROM_ENTRY`) return from the entry as before and must still be alive after 3 s, which shows the control can see a lingering process. The lingering builds run natively only, because in a host mapping the thread would run unmapped code after the release. - `docs/experiments.md`: both fixture sections describe the change and the controls, and the `cpu_native_startup` build command lists the two new targets. Fixes #1375. Refs #281, #589, #1173: #1173 marks only `cpu_native_worker_alive` `RUN_SERIAL` for `--parallel 4`, and these two tests would otherwise stay exposed there. ## Verification At `098cf79a` (on `e1316e1c`). The same change rebased on `a34a97dc` gave the same results below. Windows 11 Pro 26300.9818, MSVC 14.44.35207, Python 3.12.10, Ryzen 7 7800X3D (16 logical CPUs): ```powershell ctest --preset dev --no-tests=error -R '^cpu_native_(package_ordinal_startup|startup)$' -V ``` ```text ordinal @77: native and pe_map package startup exited 13, correct dependency order ordinal @77: native and pe_map package startup exited 14, correct dependency order lingering thread: native EXE exited 13 while the provider's thread was alive; the returning control was still alive after 3 s native: LOG:abtew2w3m1 exit 0x103020e mapped: LOG:abtew2w3m1 exit 0x103020e; mapped in order ['cpu_startup_a.dll', 'cpu_startup_b.dll', 'cpu_startup_exe.exe'] lingering thread: native EXE exited 0x103020e with the full log while its thread was alive; the returning control was still alive after 3 s 100% tests passed, 0 tests failed out of 2 ``` - `--repeat until-fail:5` of both tests: 5/5 in `dev` (Debug) and 5/5 in `release` (`/O2`). In the Release build, `cpu_package_ordinal_exe.exe` still imports only `cpu_package_ordinal_provider.dll` ordinal 77 (`dumpbin /imports`), with no `memcpy`/`memset`/`memcmp`. - **Load test** from #1375: 16 launcher processes calling `exe_process.launch()` with a 40 s deadline, while 16 busy loops saturate the CPU. Before the change, 78 of 7,500 and 9 of 2,400 launches were slow, with exit `0x0` after ~30 s or still alive at 40 s. After it, 0 of 4,000 (`cpu_package_ordinal_exe`, all `0xd`) and 0 of 1,600 (`cpu_startup_exe`, all `0x103020e`). - `ctest --preset dev --no-tests=error -E '_hardware$' -j 16`, three runs: both tests passed in all three. Before the change, at least one of them failed in most `-j 16` runs. The remaining failures were `cpu_native_load_config_callback` in all three runs, which this host's system CFG setting causes (#1366, fixed by #1367), and `cpu_native_worker_alive` in one run, which is timing-sensitive (#1173 marks it `RUN_SERIAL`). - `ctest --preset pr --no-tests=error -j 16` with `X2W_REQUIRE_SPIRV_TOOLS=1`: 24/24. `tests/docs_links_check.py` and `tests/bidi_controls_check.py` pass. **These two tests are not in the `pr` preset**, so the `Build and test on Windows` check on this PR does not run them. A full `workflow_dispatch` run of the Windows workflow on this branch in my fork (Debug and Release suites, hosted `windows-2025`) is here: https://github.com/Maxim-Root/Xbox2Windows/actions/runs/45370885886. I will add its result in a comment. ## Evidence and follow-up No binaries are added: all fixtures are built from the sources in this PR. As in #589, the identity of the thread that kept the unpatched process alive is inferred, not proven. It was the only live thread after the entry thread ended with the correct value, and its start address was not resolved. Interaction to note: `exe_finish` decides "native launch" from `PEB::ImageBaseAddress`, as `finish_exe` does through `GetModuleHandleW(nullptr)`. If a mapper starts reporting the mapped EXE as the process image (#1151), both helpers need the same adjustment. ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture. - [x] I updated README/docs when a capability or build requirement changed. - [x] I did not include game files, dumps, distribution links or secrets. AI-assisted (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
upstream-sync closed this pull request 2026-11-24 11:02:43 +00:00
tedin7 commented 2026-11-24 11:02:43 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T10:19:37Z.

Review: COMMENTED


Technical review at 098cf79a2d1c13bb710b35252d1af4cc2037aa2a:

Checks run

  • Linux: docs_links_check.py, bidi_controls_check.py, and tests/pe_package_ordinal_plan_check.py (3 tests) all passed.
  • Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP):
    • Debug (--preset dev): ctest -R '^(cpu_native_startup|cpu_native_package_ordinal_startup|pe_package_ordinal_plan)$' 3/3 passed (5.09s).
    • Release /O2 (--preset release): ctest -R '^(cpu_native_startup|cpu_native_package_ordinal_startup|pe_package_ordinal_plan)$' 3/3 passed (4.47s).

Code audit

  • tests/cpu/exe_exit.h: resolves ntdll!RtlExitUserProcess via PEB::Ldr->InLoadOrderModuleList and the PE32+ export directory (with forwarder check function - rva < size) only when PEB::ImageBaseAddress == &__ImageBase and RETURN_FROM_ENTRY is not defined, preserving the CRT-free import table (only @77 on cpu_package_ordinal_exe) and returning normally under pe_map.
  • tests/cpu/package_ordinal_check.py and tests/cpu/native_startup_check.py: the _live / _linger builds exit promptly with their expected codes while a background thread sleeps INFINITE, while the _return negative controls stay alive past the 3 s deadline as expected.

Clean implementation and controls.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6037422240 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1383#pullrequestreview-6037422240). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T10:19:37Z. **Review:** COMMENTED --- Technical review at `098cf79a2d1c13bb710b35252d1af4cc2037aa2a`: **Checks run** - **Linux**: `docs_links_check.py`, `bidi_controls_check.py`, and `tests/pe_package_ordinal_plan_check.py` (3 tests) all passed. - **Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP)**: - Debug (`--preset dev`): `ctest -R '^(cpu_native_startup|cpu_native_package_ordinal_startup|pe_package_ordinal_plan)$'` **3/3 passed** (`5.09s`). - Release `/O2` (`--preset release`): `ctest -R '^(cpu_native_startup|cpu_native_package_ordinal_startup|pe_package_ordinal_plan)$'` **3/3 passed** (`4.47s`). **Code audit** - `tests/cpu/exe_exit.h`: resolves `ntdll!RtlExitUserProcess` via `PEB::Ldr->InLoadOrderModuleList` and the PE32+ export directory (with forwarder check `function - rva < size`) only when `PEB::ImageBaseAddress == &__ImageBase` and `RETURN_FROM_ENTRY` is not defined, preserving the CRT-free import table (only `@77` on `cpu_package_ordinal_exe`) and returning normally under `pe_map`. - `tests/cpu/package_ordinal_check.py` and `tests/cpu/native_startup_check.py`: the `_live` / `_linger` builds exit promptly with their expected codes while a background thread sleeps `INFINITE`, while the `_return` negative controls stay alive past the 3 s deadline as expected. Clean implementation and controls.
Maxim-Root commented 2026-11-24 11:02:58 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Maxim-Root on 2026-11-24T10:08:34Z.


Thanks. Here is how the PR maps to the three points.

Existing tests and timeouts. These are unchanged. Every existing assertion and expected value stays as it was: TIMEOUT = 30, the 10 s worker wait, 13/14, 0x103020e, and the B-initializer and alternate-A controls. The lingering-thread controls are added next to them with their own deadlines (10 s positive, 3 s for the returning build).

Loaded-host comparison. It is in the PR body, with the exit code and the deadline overruns for every slow run. Sixteen launchers each call exe_process.launch() with a 40 s deadline, while 16 busy loops saturate a 16-thread CPU:

Fixture Before After
cpu_package_ordinal_exe 78 / 7,500 slow: exit 0x0 after 30.0–30.1 s, one still alive at 40 s (entry thread ended with 0xd) 0 / 4,000, all 0xd
cpu_startup_exe 9 / 2,400 slow: exit 0x0 after ~30 s, or alive at 40 s (entry thread ended with 0x103020e) 0 / 1,600, all 0x103020e

Reusing the #589 wrapper. I did not link the native_startup / finish_exe pair directly, because that path imports finish_exe from cpu_exe_io.dll. package_ordinal_check.py asserts that the ordinal EXE's import table is exactly [(cpu_package_ordinal_provider.dll, #77, None)], and pe_run_package checks external_bindings == 0. An added cpu_exe_io.dll import would change the property that fixture exists to test. tests/cpu/exe_exit.h therefore applies the same rule as finish_exe: it ends the process when this image is the process EXE (the PEB image base, which GetModuleHandleW(nullptr) also reads) and returns the value in a host mapping. It reaches RtlExitUserProcess through ntdll's export table instead of an import.

cpu_startup_exe has no such constraint. If you prefer, I can switch it to the #589 path: link cpu_exe_io, end through finish_exe, and serve cpu_exe_io.dll in the mapped harness and the package-runner case. That would leave exe_exit.h only for the ordinal fixture. Tell me which you want, and I'll update the PR.

AI-assisted (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7128372734 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1383#issuecomment-7128372734). Originally posted by [Maxim-Root](https://github.com/Maxim-Root) on 2026-11-24T10:08:34Z. --- Thanks. Here is how the PR maps to the three points. **Existing tests and timeouts.** These are unchanged. Every existing assertion and expected value stays as it was: `TIMEOUT = 30`, the 10 s worker wait, 13/14, `0x103020e`, and the B-initializer and alternate-A controls. The lingering-thread controls are added next to them with their own deadlines (10 s positive, 3 s for the returning build). **Loaded-host comparison.** It is in the PR body, with the exit code and the deadline overruns for every slow run. Sixteen launchers each call `exe_process.launch()` with a 40 s deadline, while 16 busy loops saturate a 16-thread CPU: | Fixture | Before | After | |---|---|---| | `cpu_package_ordinal_exe` | 78 / 7,500 slow: exit `0x0` after 30.0–30.1 s, one still alive at 40 s (entry thread ended with `0xd`) | 0 / 4,000, all `0xd` | | `cpu_startup_exe` | 9 / 2,400 slow: exit `0x0` after ~30 s, or alive at 40 s (entry thread ended with `0x103020e`) | 0 / 1,600, all `0x103020e` | **Reusing the #589 wrapper.** I did not link the `native_startup` / `finish_exe` pair directly, because that path imports `finish_exe` from `cpu_exe_io.dll`. `package_ordinal_check.py` asserts that the ordinal EXE's import table is exactly `[(cpu_package_ordinal_provider.dll, #77, None)]`, and `pe_run_package` checks `external_bindings == 0`. An added `cpu_exe_io.dll` import would change the property that fixture exists to test. `tests/cpu/exe_exit.h` therefore applies the same rule as `finish_exe`: it ends the process when this image is the process EXE (the PEB image base, which `GetModuleHandleW(nullptr)` also reads) and returns the value in a host mapping. It reaches `RtlExitUserProcess` through ntdll's export table instead of an import. `cpu_startup_exe` has no such constraint. If you prefer, I can switch it to the #589 path: link `cpu_exe_io`, end through `finish_exe`, and serve `cpu_exe_io.dll` in the mapped harness and the package-runner case. That would leave `exe_exit.h` only for the ordinal fixture. Tell me which you want, and I'll update the PR. AI-assisted (Claude Code).
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!1376
No description provided.