pe: start the pe_run_package entry as the main image #1085

Manually merged
github merged 2 commits from gh-pr/1085/head into gh-pr/1085/base 2026-11-26 22:40:29 +00:00
Owner

@⁠mumba17 on GitHub · 2026-11-24 00:32 UTC · original
mumba17:pe/run-package-main-image → main · +128 −2 · 4 files · 2 commits · merged 2026-11-24 01:11 UTC

Change

tools/pe_run_package.py started the entry EXE with pe_map_run. An EXE built with /GA reads its thread-locals through TLS slot 0 without loading _tls_index, so under the runner it read and wrote whatever block the host Python process keeps in slot 0. #988 added pe_map_run_main for this case, but nothing in tools/ called it.

  • The runner now starts the entry with pe_map_run_main. Per #988, an image without a TLS template simply starts, so other entries behave as before.
  • The entry's host CreateThread imports (kernel32.dll, kernelbase.dll or an api-ms-win-core-processthreads-* contract) are bound to pe_map_main_create_thread, so the threads it starts are enrolled. Bundled DLLs keep their own imports, the same scope #988 documents for other thread routes.
  • A mapper without pe_map_run_main is refused with the entry EXE requires a mapper with pe_map_run_main.
  • No change to preflight, plan(), provider resolution or release order.

Test

tests/cpu/package_main_image_check.py, registered as cpu_package_main_image, reuses #988's /GA EXE cpu_exe_tls_slot0 and its expected strings:

  • Precondition: the fixture has a TLS directory and imports kernel32!CreateThread.
  • Windows launch: LOG:m1=yy m:yyyy a2=yy a:yyyy a3=y- b2=yy b:yyyy b3=y- X=0, exit 0.
  • Runner without --system kernel32.dll: refused before mapping, with no guest log.
  • Runner with --system kernel32.dll: the same guest log, exit code 0 and {"image_order": ["cpu_exe_tls_slot0.exe"], "entry_executed": true, "exit_code": 0}.

Negative controls (local mutations, not committed):

Mutation Result
start with pe_map_run (current main) guest log m1=n- m:n--- a2=n- a:n--- a3=n- b2=n- b:n--- b3=n- X=8, which is #988's PLAIN; the check fails
keep pe_map_run_main, do not bind CreateThread m1=yy m:yyyy a:n--- b:n--- X=2: the main thread passes and both workers fail; the check fails

Verification

Environment: Windows 11 Pro build 26300, MSVC 19.44.35207.1 x64, Python 3.13.1 (out/pe-env), branch on 110e186.

ctest --preset dev --no-tests=error -R '^cpu_package_main_image$' -V
ctest --preset dev --no-tests=error -R 'cpu_package_main_image|cpu_native_exe_tls_slot0|cpu_native_startup|cpu_package_ordinal|cpu_package_shim_lifetime|xgameruntime_preflight|pe_package|import_forms|static_exe_intake|cpu_native_acphal_hal'
  • The related set passes 11/11 in dev and 11/11 in release, including every existing pe_run_package.py user and the three slot-0 tests from #988.
  • pe_package_preflight_check.py, pe_package_ordinal_plan_check.py, docs_links_check.py, bidi_controls_check.py and git diff --check are clean.
  • Not run: the full CTest suite and Windows CI for this branch.

Local observation (no image or log attached): I ran the main executable from the #870 checkpoints through the runner with the two shims and System32 providers. With the previous start, it crashed right after its memory setup on a write whose index register held ASCII text, where the Windows loader carried on. With this change it reaches the same next boundary as the Windows loader: the executable's runtime services initialize and the first call into a missing module follows. That made the gap visible. The fixture above is the evidence.

docs/experiments.md records the start mode next to the other runner options.

Refs #870, #988.

🤖 Generated with Claude Code

**@⁠mumba17** on GitHub · 2026-11-24 00:32 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1085) `mumba17:pe/run-package-main-image` → `main` · +128 −2 · 4 files · 2 commits · merged 2026-11-24 01:11 UTC ## Change `tools/pe_run_package.py` started the entry EXE with `pe_map_run`. An EXE built with `/GA` reads its thread-locals through TLS slot 0 without loading `_tls_index`, so under the runner it read and wrote whatever block the host Python process keeps in slot 0. #988 added `pe_map_run_main` for this case, but nothing in `tools/` called it. - The runner now starts the entry with `pe_map_run_main`. Per #988, an image without a TLS template simply starts, so other entries behave as before. - The entry's host `CreateThread` imports (`kernel32.dll`, `kernelbase.dll` or an `api-ms-win-core-processthreads-*` contract) are bound to `pe_map_main_create_thread`, so the threads it starts are enrolled. Bundled DLLs keep their own imports, the same scope #988 documents for other thread routes. - A mapper without `pe_map_run_main` is refused with `the entry EXE requires a mapper with pe_map_run_main`. - No change to preflight, `plan()`, provider resolution or release order. ## Test `tests/cpu/package_main_image_check.py`, registered as `cpu_package_main_image`, reuses #988's `/GA` EXE `cpu_exe_tls_slot0` and its expected strings: - **Precondition:** the fixture has a TLS directory and imports `kernel32!CreateThread`. - **Windows launch:** `LOG:m1=yy m:yyyy a2=yy a:yyyy a3=y- b2=yy b:yyyy b3=y- X=0`, exit 0. - **Runner without `--system kernel32.dll`:** refused before mapping, with no guest log. - **Runner with `--system kernel32.dll`:** the same guest log, exit code 0 and `{"image_order": ["cpu_exe_tls_slot0.exe"], "entry_executed": true, "exit_code": 0}`. Negative controls (local mutations, not committed): | Mutation | Result | | --- | --- | | start with `pe_map_run` (current `main`) | guest log `m1=n- m:n--- a2=n- a:n--- a3=n- b2=n- b:n--- b3=n- X=8`, which is #988's `PLAIN`; the check fails | | keep `pe_map_run_main`, do not bind `CreateThread` | `m1=yy m:yyyy a:n--- b:n--- X=2`: the main thread passes and both workers fail; the check fails | ## Verification Environment: Windows 11 Pro build 26300, MSVC 19.44.35207.1 x64, Python 3.13.1 (`out/pe-env`), branch on `110e186`. ```powershell ctest --preset dev --no-tests=error -R '^cpu_package_main_image$' -V ctest --preset dev --no-tests=error -R 'cpu_package_main_image|cpu_native_exe_tls_slot0|cpu_native_startup|cpu_package_ordinal|cpu_package_shim_lifetime|xgameruntime_preflight|pe_package|import_forms|static_exe_intake|cpu_native_acphal_hal' ``` - The related set passes 11/11 in `dev` and 11/11 in `release`, including every existing `pe_run_package.py` user and the three slot-0 tests from #988. - `pe_package_preflight_check.py`, `pe_package_ordinal_plan_check.py`, `docs_links_check.py`, `bidi_controls_check.py` and `git diff --check` are clean. - Not run: the full CTest suite and Windows CI for this branch. **Local observation (no image or log attached):** I ran the main executable from the #870 checkpoints through the runner with the two shims and System32 providers. With the previous start, it crashed right after its memory setup on a write whose index register held ASCII text, where the Windows loader carried on. With this change it reaches the same next boundary as the Windows loader: the executable's runtime services initialize and the first call into a missing module follows. That made the gap visible. The fixture above is the evidence. `docs/experiments.md` records the start mode next to the other runner options. Refs #870, #988. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
pe_run_package started the entry EXE with pe_map_run, so an EXE whose
code reads its thread-locals through TLS slot 0 (/GA) read and wrote the
host's slot-0 block instead. #988 added pe_map_run_main for this, but
the runner did not use it.

Start the entry with pe_map_run_main and bind its host CreateThread
imports (kernel32, kernelbase or a processthreads API-set contract) to
pe_map_main_create_thread, so its workers participate too. DLLs in the
package keep their imports. A mapper without pe_map_run_main is refused
with a named error.

cpu_package_main_image runs the /GA slot-0 EXE from #988 under a Windows
launch and through the runner, and requires the same guest log, exit
code and JSON result. It also checks that the package is still refused
without a kernel32 provider. Locally, a pe_map_run start failed every
slot-0 check (exit 8), and dropping the CreateThread binding failed both
workers.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 22:40:29 +00:00
github manually merged commit 0cfb44ceb9 into gh-pr/1085/base 2026-11-26 22:40:29 +00:00
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-24 00:45 UTC · original

I pushed a narrow provider-precedence fix. The ordinary System32 route still enrolls both workers and matches the native /GA fixture. The prior candidate silently replaced CreateThread even when the caller supplied that DLL through --shim. The new control sets both options and verifies the explicitly selected provider stays in effect. The main thread owns slot 0 and both unwrapped workers give their expected refusal markers. Windows Release cpu_package_main_image passed, including refusal before mapping with neither provider configured.
Candidate: 0cfb44ceb9

**@⁠R0Y00** on GitHub · 2026-11-24 00:45 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1085#issuecomment-7118394182) I pushed a narrow provider-precedence fix. The ordinary System32 route still enrolls both workers and matches the native /GA fixture. The prior candidate silently replaced CreateThread even when the caller supplied that DLL through --shim. The new control sets both options and verifies the explicitly selected provider stays in effect. The main thread owns slot 0 and both unwrapped workers give their expected refusal markers. Windows Release cpu_package_main_image passed, including refusal before mapping with neither provider configured. Candidate: 0cfb44ceb9944ef15d2d62baca6966d5bd467bdd
This discussion has been locked. Commenting is limited to contributors.
No description provided.