Add a source-built process-startup fixture for pe_map #165
Labels
No labels
accessibility
awaiting author
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
priority: P0
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/R0Y00--Xbox2Windows#165
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
@raulmoracode on GitHub · 2026-11-21 17:50 UTC · original
Question
Can
pe_mapstart 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_mapnever calls an EXE entry point.notify()returns early for a non-DLL image (tools/pe_map.cpp,IMAGE_FILE_DLLcheck), which is correct forLoadLibrarybut 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_mapalready 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_tlscompares callback and entry-point order withLoadLibrary/FreeLibraryfor a DLL. It does not run an EXE.tools/pe_map.cpp). A startup fixture must either use callbacks only or state the limitation.IMAGE_FILE_DLLcleared: measured on Windows 11 build 26300,LoadLibraryWloads and frees the copy without calling the callback or the entry point.What a fixture would contain
main/WinMainthat returns a known exit code and writes an ordered marker log.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 on GitHub · 2026-11-21 18:34 UTC · original
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 on GitHub · 2026-11-21 18:36 UTC · original
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:
pe_map_imagefor non-DLL images? The measured Windows behavior is thatLoadLibraryruns nothing for an EXE, so the opt-in path matters.0x60dcome from both sides?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 on GitHub · 2026-11-21 18:39 UTC · original
@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 on GitHub · 2026-11-21 18:42 UTC · original
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 on GitHub · 2026-11-21 18:45 UTC · original
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 on GitHub · 2026-11-21 18:58 UTC · original
Hey @R0Y00 and @raulmoracode!
The incremental CRT-free EXE PR is now up: #238.
It includes the opt-in
pe_map_runentry-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 on GitHub · 2026-11-21 19:14 UTC · original
@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 on GitHub · 2026-11-21 19:22 UTC · original
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 on GitHub · 2026-11-21 20:27 UTC · original
#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 on GitHub · 2026-11-21 21:28 UTC · original
#296 has landed (
2fa9be83). Its/MTDLLs 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 on GitHub · 2026-11-22 20:51 UTC · original
I took the implicit TLS data gap noted above:
pe_map_imagerejected every image with a non-empty TLS data template (MAP_UNSUPPORTED, "TLS data"), which #523 pinned. #698 makespe_mapaccept such images.Approach:
pe_mapdoes not write to the thread'sThreadLocalStoragePointerarray, which ntdll owns. It generates a small carrier DLL holding a copy of the relocated template, loads it withLoadLibraryExWso that Windows assigns the index and manages one block per thread, and stores that index at the image'sAddressOfIndex. 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,
devpreset. A source-built fixture comparesLoadLibraryWwithpe_mapon 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.cppwhen I checked. If someone already has work in this area, say so and I will coordinate.AI-assisted.
@R0Y00 on GitHub · 2026-11-23 04:20 UTC · original
#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 on GitHub · 2026-11-23 15:14 UTC · original
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 on GitHub · 2026-11-23 16:09 UTC · original
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 on GitHub · 2026-11-23 16:36 UTC · original
Claiming the source-built EXE TLS comparison that is still open here (milestone #870).
pe_map_run/ thread notifications intools/pe_map.cpp, compared with a normal Windows launch. Todaynotify()returns early for a non-DLL image, so a started EXE's callbacks never see thread attach or detach underpe_map. A minimalpe_map.cppchange is in scope: oncepe_map_runstarts an EXE, forward thread attach and detach to its TLS callbacks only, never to its entry point.devandrelease.pe_map.cpp(security cookie); I'll keep my change outside that path.AI-assisted (Claude Code).
@rasptum on GitHub · 2026-11-23 17:10 UTC · original
EXE TLS result: #920.
Tested: commit
41b1de6(andef15a16before the last rebase). Windows 10 Pro 10.0.19045.6466, MSVC 19.44.35207.1 x64,devandrelease. The fixture is source-built and CRT-free.Commands:
cmake --build --preset <dev|release> --target pe_map cpu_exe_tls, thenctest --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):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_rundid not forward thread notifications to an EXE, becausenotify()skips non-DLL images. With the unmodified mapper, the test fails withnotifications 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 on GitHub · 2026-11-23 17:42 UTC · original
#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 on GitHub · 2026-11-23 17:59 UTC · original
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.