Add a source-built process-startup fixture for pe_map #164

Closed
opened 2026-11-21 17:50:35 +00:00 by raulmoracode · 18 comments
raulmoracode commented 2026-11-21 17:50:35 +00:00 (Migrated from github.com)
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by raulmoracode on 2026-11-21T17:50:35Z.


Question

Can pe_map start a source-built image the way a normal Windows launch does: static initializers in dependency order, a TLS value read on two threads, and the entry point reached once?

Today pe_map never calls an EXE entry point. notify() returns early for a non-DLL image (tools/pe_map.cpp, IMAGE_FILE_DLL check), which is correct for LoadLibrary but means the repository has no test where "startup" means more than "a DLL export returned". This is step 4 of the first-steps list in #132.

Evidence so far

  • pe_map already reproduces DIR64 relocations, ordinary imports, section protections, .pdata, DLL TLS callbacks and the DLL entry point (docs/experiments.md, "Mapping an image without LoadLibrary" and "TLS callbacks and the entry point").
  • cpu_native_tls compares callback and entry-point order with LoadLibrary/FreeLibrary for a DLL. It does not run an EXE.
  • Implicit TLS data templates are rejected, because they need a slot in ntdll's per-thread array (tools/pe_map.cpp). A startup fixture must either use callbacks only or state the limitation.
  • IMAGE_FILE_DLL cleared: measured on Windows 11 build 26300, LoadLibraryW loads and frees the copy without calling the callback or the entry point.

What a fixture would contain

  1. An EXE with main/WinMain that returns a known exit code and writes an ordered marker log.
  2. Two DLLs with static initializers, imported in a known order.
  3. A TLS callback that reads a thread-local value on the main thread and on one worker thread.
  4. A negative control: the same image with one initializer removed, so the log differs.

Completion condition

A source-built EXE, mapped by pe_map, produces the same initialization log and exit code as a normal Windows launch of the same EXE, and the negative control differs. The test records the log, not a claim that a title starts.

Required environment

x64 Windows, MSVC with MASM, CMake/Ninja, Python 3.11 or newer. No game files, console or package DLLs.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6532352583 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/165). Originally posted by [raulmoracode](https://github.com/raulmoracode) on 2026-11-21T17:50:35Z. --- ## Question Can `pe_map` start a source-built image the way a normal Windows launch does: static initializers in dependency order, a TLS value read on two threads, and the entry point reached once? Today `pe_map` never calls an EXE entry point. `notify()` returns early for a non-DLL image (`tools/pe_map.cpp`, `IMAGE_FILE_DLL` check), which is correct for `LoadLibrary` but means the repository has no test where "startup" means more than "a DLL export returned". This is step 4 of the first-steps list in #132. ## Evidence so far - `pe_map` already reproduces DIR64 relocations, ordinary imports, section protections, `.pdata`, DLL TLS callbacks and the DLL entry point (`docs/experiments.md`, "Mapping an image without LoadLibrary" and "TLS callbacks and the entry point"). - `cpu_native_tls` compares callback and entry-point order with `LoadLibrary`/`FreeLibrary` for a DLL. It does not run an EXE. - Implicit TLS data templates are rejected, because they need a slot in ntdll's per-thread array (`tools/pe_map.cpp`). A startup fixture must either use callbacks only or state the limitation. - `IMAGE_FILE_DLL` cleared: measured on Windows 11 build 26300, `LoadLibraryW` loads and frees the copy without calling the callback or the entry point. ## What a fixture would contain 1. An EXE with `main`/`WinMain` that returns a known exit code and writes an ordered marker log. 2. Two DLLs with static initializers, imported in a known order. 3. A TLS callback that reads a thread-local value on the main thread and on one worker thread. 4. A negative control: the same image with one initializer removed, so the log differs. ## Completion condition A source-built EXE, mapped by `pe_map`, produces the same initialization log and exit code as a normal Windows launch of the same EXE, and the negative control differs. The test records the log, not a claim that a title starts. ## Required environment x64 Windows, MSVC with MASM, CMake/Ninja, Python 3.11 or newer. No game files, console or package DLLs. _AI-assisted._
yummancito commented 2026-11-24 06:47:49 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by yummancito on 2026-11-21T18:34:04Z.


Hey, I've been working on a small proof of concept for #165.

I have a local, source-built CRT-free EXE fixture that runs through pe_map, including a TLS callback and a resolved import. The mapped execution matches the native exit code (0x60d), and the negative controls detect the expected differences.

It doesn't cover the full startup contract yet — particularly two-DLL initialization order, TLS data across threads, or CRT startup.

Would a smaller incremental PR for the EXE entry-point path be useful, or would you prefer waiting until the full fixture is implemented?

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7067349692 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/165#issuecomment-7067349692). Originally posted by [yummancito](https://github.com/yummancito) on 2026-11-21T18:34:04Z. --- Hey, I've been working on a small proof of concept for #165. I have a local, source-built CRT-free EXE fixture that runs through `pe_map`, including a TLS callback and a resolved import. The mapped execution matches the native exit code (`0x60d`), and the negative controls detect the expected differences. It doesn't cover the full startup contract yet — particularly two-DLL initialization order, TLS data across threads, or CRT startup. Would a smaller incremental PR for the EXE entry-point path be useful, or would you prefer waiting until the full fixture is implemented? AI-assisted.
raulmoracode commented 2026-11-24 06:47:50 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by raulmoracode on 2026-11-21T18:36:35Z.


An incremental PR for the entry-point path would be useful. The repository's rule is one reviewable behavior per PR, and the entry point is independently testable: a CRT-free EXE with a known exit code, a TLS callback and one resolved import is already a complete differential case. Waiting for two-DLL order, TLS data across threads and CRT startup would make the first PR much harder to review, and would delay the first measured startup result.

A few details would make it easy to review:

  • Which API invokes the entry point: a new export, or a change to pe_map_image for non-DLL images? The measured Windows behavior is that LoadLibrary runs nothing for an EXE, so the opt-in path matters.
  • How is the native comparison made: launching the EXE as a child process and comparing exit codes? Did 0x60d come from both sides?
  • What are the negative controls? For example an entry point moved out of an executable section, or a callback that returns FALSE.
  • Does the PR record the measured Windows build in docs/experiments.md?

I had planned the same fixture and will not open a competing branch. Once yours is up I can verify it on Windows 10 19045 with a full MSVC/SDK toolchain, and then take the two-DLL initialization order or the TLS-across-threads piece, whichever you prefer.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7067380378 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/165#issuecomment-7067380378). Originally posted by [raulmoracode](https://github.com/raulmoracode) on 2026-11-21T18:36:35Z. --- An incremental PR for the entry-point path would be useful. The repository's rule is one reviewable behavior per PR, and the entry point is independently testable: a CRT-free EXE with a known exit code, a TLS callback and one resolved import is already a complete differential case. Waiting for two-DLL order, TLS data across threads and CRT startup would make the first PR much harder to review, and would delay the first measured startup result. A few details would make it easy to review: - Which API invokes the entry point: a new export, or a change to `pe_map_image` for non-DLL images? The measured Windows behavior is that `LoadLibrary` runs nothing for an EXE, so the opt-in path matters. - How is the native comparison made: launching the EXE as a child process and comparing exit codes? Did `0x60d` come from both sides? - What are the negative controls? For example an entry point moved out of an executable section, or a callback that returns FALSE. - Does the PR record the measured Windows build in `docs/experiments.md`? I had planned the same fixture and will not open a competing branch. Once yours is up I can verify it on Windows 10 19045 with a full MSVC/SDK toolchain, and then take the two-DLL initialization order or the TLS-across-threads piece, whichever you prefer. _AI-assisted._
R0Y00 commented 2026-11-24 06:47:50 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-21T18:39:15Z.


@yummancito, please send the incremental PR with your CRT-free source fixture and native/mapped comparison. The source, captured child-process output and exit-code check would also be useful for #210, which compares native and statically recompiled execution. We can share those pieces now while the two-DLL initialization order and cross-thread TLS checks proceed separately under #165.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7067412183 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/165#issuecomment-7067412183). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-21T18:39:15Z. --- @yummancito, please send the incremental PR with your CRT-free source fixture and native/mapped comparison. The source, captured child-process output and exit-code check would also be useful for #210, which compares native and statically recompiled execution. We can share those pieces now while the two-DLL initialization order and cross-thread TLS checks proceed separately under #165.
raulmoracode commented 2026-11-24 06:47:50 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by raulmoracode on 2026-11-21T18:42:20Z.


Thanks. I will verify the incremental PR on Windows 10 19045 (MSVC 14.44.35207, Windows SDK 10.0.26100) as soon as it is up, comparing the mapped run with the native child-process result. I will not open a competing branch.

After it lands I can take either the cross-thread TLS value or the two-DLL initialization order, whichever is unclaimed, and keep each as a separate PR so the first entry-point change stays reviewable.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7067450624 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/165#issuecomment-7067450624). Originally posted by [raulmoracode](https://github.com/raulmoracode) on 2026-11-21T18:42:20Z. --- Thanks. I will verify the incremental PR on Windows 10 19045 (MSVC 14.44.35207, Windows SDK 10.0.26100) as soon as it is up, comparing the mapped run with the native child-process result. I will not open a competing branch. After it lands I can take either the cross-thread TLS value or the two-DLL initialization order, whichever is unclaimed, and keep each as a separate PR so the first entry-point change stays reviewable. _AI-assisted._
yummancito commented 2026-11-24 06:47:50 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by yummancito on 2026-11-21T18:45:10Z.


Thanks @R0Y00 and @raulmoracode!

I'll prepare the incremental CRT-free EXE PR first, with the source fixture, captured native child-process output, mapped comparison, exit-code checks and negative controls.

I've also started working on the two-DLL initialization fixture locally, so I'll keep that in a separate branch to avoid mixing the two changes.

@raulmoracode, the cross-thread TLS piece might be a good follow-up for you after the first PR lands.

I'll share the PR link here once it's ready. Appreciate the help!

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7067486332 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/165#issuecomment-7067486332). Originally posted by [yummancito](https://github.com/yummancito) on 2026-11-21T18:45:10Z. --- Thanks @R0Y00 and @raulmoracode! I'll prepare the incremental CRT-free EXE PR first, with the source fixture, captured native child-process output, mapped comparison, exit-code checks and negative controls. I've also started working on the two-DLL initialization fixture locally, so I'll keep that in a separate branch to avoid mixing the two changes. @raulmoracode, the cross-thread TLS piece might be a good follow-up for you after the first PR lands. I'll share the PR link here once it's ready. Appreciate the help! *AI-assisted.*
yummancito commented 2026-11-24 06:47:51 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by yummancito on 2026-11-21T18:58:22Z.


Hey @R0Y00 and @raulmoracode!

The incremental CRT-free EXE PR is now up: #238.

It includes the opt-in pe_map_run entry-point path, a source-built EXE fixture, native/mapped exit-code comparisons, TLS callback and import checks, negative controls, and reproducible documentation.

The two-DLL initialization experiment remains separate.

Thanks again for the feedback and the offer to verify it on Windows 10!

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7067658220 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/165#issuecomment-7067658220). Originally posted by [yummancito](https://github.com/yummancito) on 2026-11-21T18:58:22Z. --- Hey @R0Y00 and @raulmoracode! The incremental CRT-free EXE PR is now up: #238. It includes the opt-in `pe_map_run` entry-point path, a source-built EXE fixture, native/mapped exit-code comparisons, TLS callback and import checks, negative controls, and reproducible documentation. The two-DLL initialization experiment remains separate. Thanks again for the feedback and the offer to verify it on Windows 10! *AI-assisted.*
R0Y00 commented 2026-11-24 06:47:53 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-21T19:14:08Z.


@yummancito, thanks for #238. I’m taking the integration with #228: run its existing EXE unchanged via your pe_map_run and the two existing provider DLLs, then compare both inputs against the native and translated child processes. I’ll exercise the first missing binding as a control and report any earlier mapping prerequisite. This uses your startup API and leaves the two-DLL initialization fixture to you.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7067866474 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/165#issuecomment-7067866474). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-21T19:14:08Z. --- @yummancito, thanks for #238. I’m taking the integration with #228: run its existing EXE unchanged via your pe_map_run and the two existing provider DLLs, then compare both inputs against the native and translated child processes. I’ll exercise the first missing binding as a control and report any earlier mapping prerequisite. This uses your startup API and leaves the two-DLL initialization fixture to you.
yummancito commented 2026-11-24 06:47:54 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by yummancito on 2026-11-21T19:22:07Z.


Thanks for the update!

Sounds good. I'll leave the #228 integration to you and continue working on the separate two-DLL initialization fixture.

We've already reproduced the native initialization order and exit code with a source-built EXE and two dependent DLLs. I'm now refining the CRT initialization and thread-notification tests.

I'll keep the changes isolated and avoid overlapping with your integration work.

Looking forward to seeing the results!

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7067969240 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/165#issuecomment-7067969240). Originally posted by [yummancito](https://github.com/yummancito) on 2026-11-21T19:22:07Z. --- Thanks for the update! Sounds good. I'll leave the #228 integration to you and continue working on the separate two-DLL initialization fixture. We've already reproduced the native initialization order and exit code with a source-built EXE and two dependent DLLs. I'm now refining the CRT initialization and thread-notification tests. I'll keep the changes isolated and avoid overlapping with your integration work. Looking forward to seeing the results! *AI-assisted.*
R0Y00 commented 2026-11-24 06:47:59 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-21T20:27:09Z.


#262 has landed. The native and mapped three-image fixture now compares the initialization log and exit status, including the reversed initialization control and explicit TLS values on worker threads. The DLL initializers in that fixture run from DllMain. The remaining evidence here is the requested C++ static-constructor ordering and TLS callback observations on main and worker threads. Please build any follow-up on the merged fixture so its existing controls stay reusable.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7068762273 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/165#issuecomment-7068762273). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-21T20:27:09Z. --- #262 has landed. The native and mapped three-image fixture now compares the initialization log and exit status, including the reversed initialization control and explicit TLS values on worker threads. The DLL initializers in that fixture run from `DllMain`. The remaining evidence here is the requested C++ static-constructor ordering and TLS callback observations on main and worker threads. Please build any follow-up on the merged fixture so its existing controls stay reusable.
R0Y00 commented 2026-11-24 06:48:03 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-21T21:28:02Z.


#296 has landed (2fa9be83). Its /MT DLLs use the real CRT entry and compare constructor, process attach/detach and destructor order between native and mapped loads. That covers the static-constructor evidence requested above. The remaining comparison is a TLS callback reading a thread-local value on the main thread and on a worker, with the observed thread identities and values under both loaders. #262 already supplies the EXE/worker and initialization controls.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7069493778 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/165#issuecomment-7069493778). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-21T21:28:02Z. --- #296 has landed (`2fa9be83`). Its `/MT` DLLs use the real CRT entry and compare constructor, process attach/detach and destructor order between native and mapped loads. That covers the static-constructor evidence requested above. The remaining comparison is a TLS callback reading a thread-local value on the main thread and on a worker, with the observed thread identities and values under both loaders. #262 already supplies the EXE/worker and initialization controls.
rasptum commented 2026-11-24 06:48:44 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by rasptum on 2026-11-22T20:51:59Z.


I took the implicit TLS data gap noted above: pe_map_image rejected every image with a non-empty TLS data template (MAP_UNSUPPORTED, "TLS data"), which #523 pinned. #698 makes pe_map accept such images.

Approach: pe_map does not write to the thread's ThreadLocalStoragePointer array, which ntdll owns. It generates a small carrier DLL holding a copy of the relocated template, loads it with LoadLibraryExW so that Windows assigns the index and manages one block per thread, and stores that index at the image's AddressOfIndex. The PR body lists the alternatives I ruled out and the known differences from a native load.

Environment: Windows 10 Pro 22H2 build 19045, MSVC 2022 x64, dev preset. A source-built fixture compares LoadLibraryW with pe_map on the loading thread, a thread that existed before the load and a new thread. Windows 11 is not measured; a run there would be welcome.

No open pull request touched tools/pe_map.cpp when I checked. If someone already has work in this area, say so and I will coordinate.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7085605141 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/165#issuecomment-7085605141). Originally posted by [rasptum](https://github.com/rasptum) on 2026-11-22T20:51:59Z. --- I took the implicit TLS data gap noted above: `pe_map_image` rejected every image with a non-empty TLS data template (`MAP_UNSUPPORTED`, "TLS data"), which #523 pinned. #698 makes `pe_map` accept such images. Approach: `pe_map` does not write to the thread's `ThreadLocalStoragePointer` array, which ntdll owns. It generates a small carrier DLL holding a copy of the relocated template, loads it with `LoadLibraryExW` so that Windows assigns the index and manages one block per thread, and stores that index at the image's `AddressOfIndex`. The PR body lists the alternatives I ruled out and the known differences from a native load. Environment: Windows 10 Pro 22H2 build 19045, MSVC 2022 x64, `dev` preset. A source-built fixture compares `LoadLibraryW` with `pe_map` on the loading thread, a thread that existed before the load and a new thread. Windows 11 is not measured; a run there would be welcome. No open pull request touched `tools/pe_map.cpp` when I checked. If someone already has work in this area, say so and I will coordinate. _AI-assisted._
R0Y00 commented 2026-11-24 06:48:59 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T04:20:11Z.


#698 merged as 00860ec. The mapper now serves source-built DLL TLS data through a Windows-assigned carrier index, with separate loading-thread, existing-thread and new-thread comparisons, plus failure and cleanup controls. Both Windows configurations and both Linux CI checks passed. Keeping this issue open for the standalone EXE startup fixture and its remaining acceptance checks.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7091494081 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/165#issuecomment-7091494081). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-23T04:20:11Z. --- #698 merged as `00860ec`. The mapper now serves source-built DLL TLS data through a Windows-assigned carrier index, with separate loading-thread, existing-thread and new-thread comparisons, plus failure and cleanup controls. Both Windows configurations and both Linux CI checks passed. Keeping this issue open for the standalone EXE startup fixture and its remaining acceptance checks.
R0Y00 commented 2026-11-24 06:49:13 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T15:14:48Z.


Startup follow-up for #870, available to claim. Please check the existing loader TLS tests and extend the closest one with an initialized static TLS template spanning a page boundary and two callbacks. The callbacks should observe the initialized values in table order. Compare native and mapped execution on the initial thread and workers, and verify that a write on one thread does not change another thread's template. Include a negative control that detects swapped callback order or failed template initialization. Link related work before adding a fixture. Use source-built inputs and report the tested commit, commands, and Windows version here.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7105261113 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/165#issuecomment-7105261113). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-23T15:14:48Z. --- Startup follow-up for #870, available to claim. Please check the existing loader TLS tests and extend the closest one with an initialized static TLS template spanning a page boundary and two callbacks. The callbacks should observe the initialized values in table order. Compare native and mapped execution on the initial thread and workers, and verify that a write on one thread does not change another thread's template. Include a negative control that detects swapped callback order or failed template initialization. Link related work before adding a fixture. Use source-built inputs and report the tested commit, commands, and Windows version here.
R0Y00 commented 2026-11-24 06:49:16 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T16:09:10Z.


The cross-page DLL TLS slice landed in #883 (406e14a). On both loaders, the two callbacks ran in table order on the initial thread and both concurrent workers, with each thread seeing its own writes. Both presets detected a swapped callback table and a damaged later page. The separate source-built EXE comparison remains open here, including the worker-thread TLS notifications and startup log for the EXE itself.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7106688772 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/165#issuecomment-7106688772). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-23T16:09:10Z. --- The cross-page DLL TLS slice landed in #883 (`406e14a`). On both loaders, the two callbacks ran in table order on the initial thread and both concurrent workers, with each thread seeing its own writes. Both presets detected a swapped callback table and a damaged later page. The separate source-built EXE comparison remains open here, including the worker-thread TLS notifications and startup log for the EXE itself.
rasptum commented 2026-11-24 06:49:18 +00:00 (Migrated from github.com)
Author
Contributor

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


Claiming the source-built EXE TLS comparison that is still open here (milestone #870).

  • Stage: EXE startup: the EXE's own initialized TLS template and two TLS callbacks, on process attach and on thread attach and detach of two workers.
  • Interface: pe_map_run / thread notifications in tools/pe_map.cpp, compared with a normal Windows launch. Today notify() returns early for a non-DLL image, so a started EXE's callbacks never see thread attach or detach under pe_map. A minimal pe_map.cpp change is in scope: once pe_map_run starts an EXE, forward thread attach and detach to its TLS callbacks only, never to its entry point.
  • Fixture: a CRT-free, source-built EXE (MSVC) with a page-spanning initialized template and callbacks in table order. It writes an ordered startup log (callbacks, entry, per-thread notifications, exit code), and the log and exit code must match between loaders. Negative controls: a swapped callback table and a zeroed template page.
  • Environment: Windows 10 Pro 10.0.19045, MSVC x64, dev and release.
  • Related: #262, #296, #698, #883. #899 also touches pe_map.cpp (security cookie); I'll keep my change outside that path.

AI-assisted (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7107389355 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/165#issuecomment-7107389355). Originally posted by [rasptum](https://github.com/rasptum) on 2026-11-23T16:36:15Z. --- Claiming the source-built EXE TLS comparison that is still open here (milestone #870). - **Stage:** EXE startup: the EXE's own initialized TLS template and two TLS callbacks, on process attach and on thread attach and detach of two workers. - **Interface:** `pe_map_run` / thread notifications in `tools/pe_map.cpp`, compared with a normal Windows launch. Today `notify()` returns early for a non-DLL image, so a started EXE's callbacks never see thread attach or detach under `pe_map`. A minimal `pe_map.cpp` change is in scope: once `pe_map_run` starts an EXE, forward thread attach and detach to its TLS callbacks only, never to its entry point. - **Fixture:** a CRT-free, source-built EXE (MSVC) with a page-spanning initialized template and callbacks in table order. It writes an ordered startup log (callbacks, entry, per-thread notifications, exit code), and the log and exit code must match between loaders. Negative controls: a swapped callback table and a zeroed template page. - **Environment:** Windows 10 Pro 10.0.19045, MSVC x64, `dev` and `release`. - **Related:** #262, #296, #698, #883. #899 also touches `pe_map.cpp` (security cookie); I'll keep my change outside that path. AI-assisted (Claude Code).
rasptum commented 2026-11-24 06:49:22 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by rasptum on 2026-11-23T17:10:37Z.


EXE TLS result: #920.

Tested: commit 41b1de6 (and ef15a16 before the last rebase). Windows 10 Pro 10.0.19045.6466, MSVC 19.44.35207.1 x64, dev and release. The fixture is source-built and CRT-free.

Commands: cmake --build --preset <dev|release> --target pe_map cpu_exe_tls, then ctest --preset <dev|release> --no-tests=error -R '^cpu_native_exe_tls$' -V.

Expected and observed (identical under a Windows launch and under pe_map_run, both presets):

LOG:m11=7 m13=7 E mf=7 mw=20014 a21=7 a23=7 af=7 aw=20032 b21=7 b23=7 bf=7 bw=2003c al=20032 a31=20032 a33=20032 bl=2003c b31=2003c b33=2003c ml=20014 X=20014
exit 0x20014
  • The EXE's two callbacks run in table order on process attach (main thread), then on thread attach and detach of two concurrent workers.
  • Every thread starts from the page-spanning template (7), and its writes (20/50/60) stay in its own copy.
  • Negative controls are rejected under both loaders: a swapped callback table (callback order: m1 ran callers ['3', '1']) and a template zeroed from its page boundary (template mismatch on the first callback).

Blocker found and fixed in the same PR: pe_map_run did not forward thread notifications to an EXE, because notify() skips non-DLL images. With the unmodified mapper, the test fails with notifications for ['m1']. #920 forwards thread attach and detach to a started EXE's TLS callbacks only, never its entry point.

Regressions: cpu_native_{exe_start,startup,tls,tls_value,tls_data,lifetime,load_cookie} pass with the change on both presets.

Scope: this checks the stage ahead of the current #870 import-binding boundary and does not move it. Process detach at exit and C-runtime startup are not covered.

AI-assisted (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7108264857 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/165#issuecomment-7108264857). Originally posted by [rasptum](https://github.com/rasptum) on 2026-11-23T17:10:37Z. --- EXE TLS result: #920. **Tested:** commit `41b1de6` (and `ef15a16` before the last rebase). Windows 10 Pro 10.0.19045.6466, MSVC 19.44.35207.1 x64, `dev` and `release`. The fixture is source-built and CRT-free. **Commands:** `cmake --build --preset <dev|release> --target pe_map cpu_exe_tls`, then `ctest --preset <dev|release> --no-tests=error -R '^cpu_native_exe_tls$' -V`. **Expected and observed (identical under a Windows launch and under `pe_map_run`, both presets):** ```text LOG:m11=7 m13=7 E mf=7 mw=20014 a21=7 a23=7 af=7 aw=20032 b21=7 b23=7 bf=7 bw=2003c al=20032 a31=20032 a33=20032 bl=2003c b31=2003c b33=2003c ml=20014 X=20014 exit 0x20014 ``` - The EXE's two callbacks run in table order on process attach (main thread), then on thread attach and detach of two concurrent workers. - Every thread starts from the page-spanning template (7), and its writes (20/50/60) stay in its own copy. - Negative controls are rejected under both loaders: a swapped callback table (`callback order: m1 ran callers ['3', '1']`) and a template zeroed from its page boundary (template mismatch on the first callback). **Blocker found and fixed in the same PR:** `pe_map_run` did not forward thread notifications to an EXE, because `notify()` skips non-DLL images. With the unmodified mapper, the test fails with `notifications for ['m1']`. #920 forwards thread attach and detach to a started EXE's TLS callbacks only, never its entry point. **Regressions:** `cpu_native_{exe_start,startup,tls,tls_value,tls_data,lifetime,load_cookie}` pass with the change on both presets. **Scope:** this checks the stage ahead of the current #870 import-binding boundary and does not move it. Process detach at exit and C-runtime startup are not covered. AI-assisted (Claude Code).
R0Y00 commented 2026-11-24 06:49:25 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T17:42:20Z.


#920 merged at af8fcba. On Windows and pe_map the EXE read the page-spanning template, ran both callbacks in table order, kept distinct values on the initial thread and two workers, and returned 0x20014 with identical logs. Both loaders detected a swapped callback table and a zeroed template page. This covers the EXE TLS slice; the issue stays open for the two DLL initializers in dependency order and the missing-initializer control. The source-built package work on #870 can supply that part.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7109055977 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/165#issuecomment-7109055977). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-23T17:42:20Z. --- #920 merged at af8fcba. On Windows and pe_map the EXE read the page-spanning template, ran both callbacks in table order, kept distinct values on the initial thread and two workers, and returned 0x20014 with identical logs. Both loaders detected a swapped callback table and a zeroed template page. This covers the EXE TLS slice; the issue stays open for the two DLL initializers in dependency order and the missing-initializer control. The source-built package work on #870 can supply that part.
R0Y00 commented 2026-11-24 06:49:26 +00:00 (Migrated from github.com)
Author
Contributor

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


Completed by #920 and #930, alongside the existing two-DLL negative control. The source-built package runner matches the normal Windows launch in dependency order, startup trace and exit status. The separate EXE TLS comparison checks per-thread data. Removing B's initializer gives atew2w3m1 and 0x1030200 where the normal package gives abtew2w3m1 and 0x103020e. Both Windows CI builds passed on the package runner.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7109478627 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/165#issuecomment-7109478627). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-23T17:59:19Z. --- Completed by #920 and #930, alongside the existing two-DLL negative control. The source-built package runner matches the normal Windows launch in dependency order, startup trace and exit status. The separate EXE TLS comparison checks per-thread data. Removing B's initializer gives atew2w3m1 and 0x1030200 where the normal package gives abtew2w3m1 and 0x103020e. Both Windows CI builds passed on the package runner.
Sign in to join this conversation.
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#164
No description provided.