cpu: compare an EXE and two dependent DLLs under Windows and pe_map #259
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/262"
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-21T19:38:50Z.
Refs #165
Change
Adds a source-built, CRT-free fixture of three images and a differential test, using
pe_map_run(#238) and no newpe_mapcode:cpu_startup_a.dllhas no imports. It keeps an event log and a value set by its initializer (7).cpu_startup_b.dllimports A. Its initializer publishesa_value() * 2, so it reads 0 if it runs before A's.cpu_startup_exe.exeimports both. Its TLS callback and entry point log events, then it runs two worker threads in turn. Each thread keeps its own value in aTlsAllocslot (1, 2, 3). It writes the log to stdout and returnsb_value | worker1 << 8 | worker2 << 16 | main << 24.What this does and does not exercise. The DLL "initializers" are code in each DLL's
DllMain(DLL_PROCESS_ATTACH), called by the loader or bype_map. They are not C++ static constructors: there is no C runtime, so no_DllMainCRTStartupand no dynamic initializers run. The per-thread values use explicit TLS throughTlsAlloc/TlsSetValue/TlsGetValue, not implicit__declspec(thread)data, whichpe_mapstill refuses. No thread is created insideDllMain: the DLLs create none, and the EXE creates its two workers from its entry point.What the test (
cpu_native_startup) doespe_map_exporton the mapped images (kernel32 from the host) and starts the EXE withpe_map_run. The harness does the dependency ordering;pe_mapdoes not.a_loganda_valuefrom A, the EXE imports from A and B.Windows 11 Pro build 26300, VS Build Tools 17.14 (MSVC 19.44), CMake 3.31.6, Python 3.13, base
7233cec:Under both loaders
aandbran once and in dependency order, the TLS callback ran after the DLL initializers and before the entry point, and the entry point ran once. stderr was empty on both sides. One-off manual check, not in CI (made before rebasing;pe_map_runis unchanged): with the TLS callback loop removed frompe_map_run, the test failed onmapped launch differs from native.Full suite (
ctest --preset dev --no-tests=error): 122 tests, 0 failures, 3 capability skips reported separately (bvh_wave64_hardware,bvh_wave64_warp,wave_shuffle_warp).Not covered
DLL_THREAD_ATTACH/DETACHfor mapped images (Windows delivers them,pe_mapdoes not; see #139). The fixture does not count them, so this PR neither depends on #139 nor hides the difference.pe_maprefuses as "TLS data".DLL_PROCESS_DETACHorder at exit andGetModuleHandle(NULL).This shows one EXE and two DLLs starting in the same order with the same log under both loaders; it does not show that any title starts. Docs:
docs/experiments.md, "Starting an EXE with two DLLs".AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-21T19:59:46Z.
In the new
exe_entryfixture the return values ofCreateThreadandWaitForSingleObjectare ignored. If a wait times out, the code closes the handle, readsg_worker_value, and starts the next iteration while the prior worker could still be updating the shared log. Please requireWAIT_OBJECT_0and a valid worker handle before consuming the result, and make worker setup or timeout fail the isolated child deterministically. Keep the normal and reversed-initializer comparisons.Imported from R0Y00/Xbox2Windows. Originally posted by yummancito on 2026-11-21T20:12:48Z.
Thanks, good catch. Fixed in
aa7edaf(same branch, no force push).The flaw. In
startup_exe.cpp,exe_entryignored the results ofCreateThreadandWaitForSingleObject. I reproduced it with the previous source, a 1 ms wait and a worker that sleeps 300 ms: the EXE did not fail. It printedLOG:abtem1(no worker event) and exited with 0, having read a worker that had not finished and started the next one.The fix. The entry point now checks
TlsAllocand the thread handle, and requiresWAIT_OBJECT_0before it readsg_worker_valueor starts the next worker. Otherwise it callsExitProcess, which stops every other thread.CloseHandlewould only release the handle and leave the thread running. Exit codes:0xE0000001TlsAllocfailed0xE0000002CreateThreadfailed0xE0000003wait timed out0xE0000004wait failed0xE0000005unexpected wait resultThe wait inside the EXE is now 10 s, below the harness's 30 s process limit, so the code is observed before the external timeout.
Tests.
cpu_native_startupkeeps the normal comparison, the reversed-order check and the two initializer controls, and adds two controls that must end both the native process and thepe_mapchild with the expected code and no output:0xe0000003under both loaders (about 1 s of wall time);0xe0000002under both loaders. It fails withERROR_INVALID_PARAMETER(87) because the size exceeds the address space, not because memory ran out. 100 of 100 runs gave the same code.As a one-off manual check, not in CI, ignoring the timeout made the timeout control fail. Full suite on Windows 11 build 26300: 122 tests, 0 failures, 3 capability skips (
bvh_wave64_hardware,bvh_wave64_warp,wave_shuffle_warp).AI-assisted.