cpu: end the ordinal-package and startup fixture EXEs with their entry result #1376
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1383"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from R0Y00/Xbox2Windows. Originally posted by Maxim-Root on 2026-11-24T10:03:18Z.
Change
cpu_package_ordinal_exeandcpu_startup_exeare 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 code0x0. This is the #281 failure that #589 fixed for theexe_startfixtures. Under a parallel CTest run,cpu_native_package_ordinal_startupandcpu_native_startupfailed withTimeoutExpired ... timed out after 30 seconds. Measurements are in #1375.tests/cpu/exe_exit.haddsexe_finish(code). When Windows started the image as the process EXE (PEB::ImageBaseAddress == &__ImageBase), it ends the process throughntdll!RtlExitUserProcess, resolved from ntdll's export table. In a host mapping it returns the value, likefinish_exeinexe_io.cpp. The helper adds no import, so the ordinal fixture keeps its single#77import, whichimport_fixturestill asserts for both builds.Both entry points end through
exe_finish. Their expected values are unchanged: 13 and 14 for the ordinal providers, and0x103020eplus the two DLL controls for the startup EXE, native and mapped.Deterministic controls, modelled on #589's live-worker control:
cpu_package_ordinal_liveis the provider with amix_argsthat leaves a sleeping thread running;cpu_startup_exe_lingerstarts 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_returnandcpu_startup_exe_linger_returnbuilds (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 thecpu_native_startupbuild command lists the two new targets.Fixes #1375. Refs #281, #589, #1173: #1173 marks only
cpu_native_worker_aliveRUN_SERIALfor--parallel 4, and these two tests would otherwise stay exposed there.Verification
At
098cf79a(one1316e1c). The same change rebased ona34a97dcgave the same results below. Windows 11 Pro 26300.9818, MSVC 14.44.35207, Python 3.12.10, Ryzen 7 7800X3D (16 logical CPUs):--repeat until-fail:5of both tests: 5/5 indev(Debug) and 5/5 inrelease(/O2). In the Release build,cpu_package_ordinal_exe.exestill imports onlycpu_package_ordinal_provider.dllordinal 77 (dumpbin /imports), with nomemcpy/memset/memcmp.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 exit0x0after ~30 s or still alive at 40 s. After it, 0 of 4,000 (cpu_package_ordinal_exe, all0xd) and 0 of 1,600 (cpu_startup_exe, all0x103020e).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 16runs. The remaining failures werecpu_native_load_config_callbackin all three runs, which this host's system CFG setting causes (#1366, fixed by #1367), andcpu_native_worker_alivein one run, which is timing-sensitive (#1173 marks itRUN_SERIAL).ctest --preset pr --no-tests=error -j 16withX2W_REQUIRE_SPIRV_TOOLS=1: 24/24.tests/docs_links_check.pyandtests/bidi_controls_check.pypass.These two tests are not in the
prpreset, so theBuild and test on Windowscheck on this PR does not run them. A fullworkflow_dispatchrun of the Windows workflow on this branch in my fork (Debug and Release suites, hostedwindows-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_finishdecides "native launch" fromPEB::ImageBaseAddress, asfinish_exedoes throughGetModuleHandleW(nullptr). If a mapper starts reporting the mapped EXE as the process image (#1151), both helpers need the same adjustment.Checklist
AI-assisted (Claude Code).
🤖 Generated with Claude Code
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T10:19:37Z.
Review: COMMENTED
Technical review at
098cf79a2d1c13bb710b35252d1af4cc2037aa2a:Checks run
docs_links_check.py,bidi_controls_check.py, andtests/pe_package_ordinal_plan_check.py(3 tests) all passed.--preset dev):ctest -R '^(cpu_native_startup|cpu_native_package_ordinal_startup|pe_package_ordinal_plan)$'3/3 passed (5.09s)./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: resolvesntdll!RtlExitUserProcessviaPEB::Ldr->InLoadOrderModuleListand the PE32+ export directory (with forwarder checkfunction - rva < size) only whenPEB::ImageBaseAddress == &__ImageBaseandRETURN_FROM_ENTRYis not defined, preserving the CRT-free import table (only@77oncpu_package_ordinal_exe) and returning normally underpe_map.tests/cpu/package_ordinal_check.pyandtests/cpu/native_startup_check.py: the_live/_lingerbuilds exit promptly with their expected codes while a background thread sleepsINFINITE, while the_returnnegative controls stay alive past the 3 s deadline as expected.Clean implementation and controls.
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:cpu_package_ordinal_exe0x0after 30.0–30.1 s, one still alive at 40 s (entry thread ended with0xd)0xdcpu_startup_exe0x0after ~30 s, or alive at 40 s (entry thread ended with0x103020e)0x103020eReusing the #589 wrapper. I did not link the
native_startup/finish_exepair directly, because that path importsfinish_exefromcpu_exe_io.dll.package_ordinal_check.pyasserts that the ordinal EXE's import table is exactly[(cpu_package_ordinal_provider.dll, #77, None)], andpe_run_packagechecksexternal_bindings == 0. An addedcpu_exe_io.dllimport would change the property that fixture exists to test.tests/cpu/exe_exit.htherefore applies the same rule asfinish_exe: it ends the process when this image is the process EXE (the PEB image base, whichGetModuleHandleW(nullptr)also reads) and returns the value in a host mapping. It reachesRtlExitUserProcessthrough ntdll's export table instead of an import.cpu_startup_exehas no such constraint. If you prefer, I can switch it to the #589 path: linkcpu_exe_io, end throughfinish_exe, and servecpu_exe_io.dllin the mapped harness and the package-runner case. That would leaveexe_exit.honly for the ordinal fixture. Tell me which you want, and I'll update the PR.AI-assisted (Claude Code).