pe: start a mapped EXE with pe_map_run #235
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/238"
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 yummancito on 2026-11-21T18:56:28Z.
Refs #165
Change
pe_map_imagemaps an EXE without notifying it, asLoadLibrarydoes. This adds an opt-in export,pe_map_run(mapped, &exit_code), that starts a mapped EXE on the calling thread: TLS callbacks in table order withDLL_PROCESS_ATTACHand a null reserved argument, then the entry point, whose return value is stored inexit_code.pe_map_imageandpe_map_releaseare unchanged. Preconditions, documented at the function and indocs/experiments.mdand not checked:mappedmust be a live base returned bype_map_image(the headers are read directly, as inpe_map_export), the image is trusted, because its callbacks and entry point are arbitrary code on the calling thread that can crash, hang or callExitProcessin the host, and the call should happen once per image.pe_map_runreturns 0 and runs nothing for an image withIMAGE_FILE_DLLset, for an image without an entry point and for an unreadable TLS callback list. The PEB argument Windows passes to an EXE's entry point is not forwarded, and no process-detach notification follows, because the host process keeps running. The API question from the issue: a new export, so theLoadLibrary-equivalent behavior ofpe_map_imagestays as measured.Fixture
tests/cpu/exe_start.asmis a source-built EXE with no C runtime. A TLS callback and the entry point each append one base-4 digit to a log in.data; the entry point then calls the named importcpu_import_provider!mix_args(5, 3, out)(13) and returns(log << 8) | 13.cpu_exe_start_no_tlsis the same source without a TLS directory.Native comparison and controls (
cpu_native_exe_start)pe_mapchild process are captured withsubprocess.run(capture_output=True). They are empty by design, because the fixture writes nothing, and the test fails with the captured text if either stream is not empty; the child's only stdout is its own JSON result line.pe_map_imagepluspe_map_runin a child process. Both give0x60d: the callback ran (null reserved) before the entry point, and the import returned 13.0x20d, so the log reflects the callback.cpu_import_altered) bound under the imported name:0x60e, so the import is live.IMAGE_FILE_DLLset in a copy:pe_map_runreturns 0 and leaves the exit code untouched..datain a copy: the Windows launch faults with0xc0000005;pe_map_imagerefuses it as "entry point outside executable section" and nothing runs.pe_map_run, the test failed withmapped original 0x20d != native 0x60d.Verification
Windows 11 Pro build 26300, VS Build Tools 17.14 (MSVC 19.44), CMake 3.31.6, Python 3.13, base
c04e65a:Full suite (
ctest --preset dev --no-tests=error): 116 tests, 0 failures, 3 capability skips reported separately (bvh_wave64_hardware,bvh_wave64_warp,wave_shuffle_warp: the adapters do not offer the forced wave widths). Checked earlier ate8895ad, the patch also applied and passed together with #228 (116 tests at that base, 0 failures); the two PRs share no fixture, target or test names, and edit different places inCMakeLists.txtanddocs/experiments.md.Not covered
CRT startup (it would call
ExitProcessin the host), implicit TLS data, a second thread's TLS notifications,DLL_PROCESS_DETACHfor an EXE,GetModuleHandle(NULL)and the PEB. This shows one EXE with an ordered start log and one resolved import; it does not show that any title starts. It touches the end ofpe_map.cpp, like open #139 and #208, so a later rebase may need a small hand merge. Docs:docs/experiments.md, "Starting a mapped EXE".AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-21T19:13:10Z.
The explicit synchronous
pe_map_runAPI is approved for this PR. In the function comment anddocs/experiments.md, please specify that the caller keeps the EXE mapping alive for the whole call, starts it at most once, and prevents any thread, TLS callback or entry point from re-enteringrunor releasing that mapping during startup. Repeated calls are outside the contract; please remove the promise about what a second call does. This requires no registry or dependency on #139.Keep the current-thread order (TLS process attach in table order with null reserved, then entry with a null argument), DWORD output on success, and the existing DLL/EXE distinction. No PEB setup or EXE process detach is required. The
0x60d,0x20d,0x60econtrols and DLL refusal are in the current fixture. Please also verify refusal for a missing entry, a null output pointer and an unreadable callback table: return 0 before guest code runs and preserve any supplied output sentinel. Reportcpu_native_exe_starton the updated Windows SHA. The two-DLL experiment remains separate.Imported from R0Y00/Xbox2Windows. Originally posted by sof9816 on 2026-11-21T19:14:00Z.
Independent Windows verification for
e238a6537ae8c71d6173db549bee728497990e0e. This is the revision before the additional refusal checks requested in the review above.Windows 11 build 26200.9711, x64 MSVC 19.44.35229 and Python 3.13.3. Build completed with
cmake --build --preset dev --parallel 5.0x60d. Both returned0x20dwithout TLS, and substituting the bound provider changed the mapped result to0x60e.bvh_wave64_hardware,bvh_wave64_warpandwave_shuffle_warp.Built and tested entirely from the repository's fixtures. AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-21T19:19:20Z.
@yummancito, your
e238a653fixture also runs the unchanged #228 chain successfully on my Windows machine (#249). To finish the requested startup checks I appended a maintainer edit,d9ac3b4, preserving your implementation. In an isolated Windows x64 build, cpu_native_exe_start passed the no-entry, null-output and unreadable-callback-table cases. Each refused before changing the fixture data and preserved the supplied sentinel. Original/no-TLS/changed-import results remained 0x60d/0x20d/0x60e. Thanks for the startup API.ctest --test-dir out/start-contract/out/build/dev --no-tests=error -R '^cpu_native_exe_start$' -V