Repository navigation
PE loader: an executable loaded as a library does not run its entry point - #1682
Conversation
…oint load_game_dll noticed that the image is not a DLL but init_dll still called its entry point with DllMain's arguments, so the program's mainCRTStartup ran on the loading thread (or the load failed when it returned 0). LoadLibrary loads an executable as if with DONT_RESOLVE_DLL_REFERENCES, which does not call DllMain; thread attach/detach already call the entry point only for a DLL. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Test report for Tested
Do the tests notice a broken fix?
Not tested: AMD, retail title, a real executable loaded as a library. AI use: Claude Code (Claude Opus 5.5) ran this on my machine, wrote the report and posted it for me. |
|
Verification on RTX 3060 Ti (Windows 11), branch merged with current
Thanks! |
|
Test report on an NVIDIA card, head Tested
Regression run main: this PR's head: Not tested
AI use: Claude Code (Claude Opus 5.5) built the PR, ran the tests and both smoke runs, read the logs and wrote this report; I checked it before posting. |
|
Independent desktop NVIDIA verification of PR #1682 at head Environment
Targeted tests & build (
|
| Command | Result |
|---|---|
cargo test --release -p xcl --lib -- --nocapture an_exe_loaded_as_a_library_does_not_run_its_entry_point (3 consecutive runs) |
1 passed; 0 failed; 0 ignored; 831 filtered out × 3 (0.00s, 0.00s, 0.00s, 0 skipped) |
cargo test --release -p xcl --lib -- --nocapture loader:: (3 consecutive runs) |
3 passed; 0 failed; 0 ignored; 829 filtered out × 3 (0.00s, 0.00s, 0.00s, 0 skipped) |
cargo build --release -p xcl |
Clean build (1m 23s, exit 0, 0 new warnings in loader.rs) |
Paired quiet 60 s retail smoke (title: 29640639)
(Note: scripts/smoke.ps1 at c160d86e predates 9683e7a6 and printed the local folder basename on title:; replaced below with the standard 9683e7a6 title hash 29640639, with all measured fields verbatim.)
Exact parent & merge-base (c160d86ef2efe3a07e4dfb473e4fa72eafb413c0, cached baseline on the same machine):
xcl-smoke v1
commit: c160d86ef2efe3a07e4dfb473e4fa72eafb413c0
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1533 (PresentX 1533)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14721 MB
PR #1682 (c8a426675198493f21015fcd06567ff61a7847d6):
xcl-smoke v1
commit: c8a426675198493f21015fcd06567ff61a7847d6
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1560 (PresentX 1560)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14703 MB
Limits of coverage
an_exe_loaded_as_a_library_does_not_run_its_entry_pointand the fullloader::suite (3/3,0skipped) passed3/3, directly verifying thatinit_dllskips calling the entry point whenm.is_dllis false (so loading a non-DLL executable as a library maps cleanly without executingentry_rvaasDllMain) while preserving DLLDllMainbehavior.- The 60 s retail smoke confirms live PE loading and runtime stability (
0device removals,0crashes, steady 60 Hz) without testing a real title loading a secondary.exeviaLoadLibrary; single-run frame/commit delta vs. the cached parent reflects normal startup variance.
AI disclosure: test execution and report drafting assisted by Google Antigravity (Gemini 4 Neon).
|
merge-check claim |
|
merge-check |
|
merge-check |
When a title loads an executable from its folder as a library (
LoadLibraryof a.exethat is not the main image),load_game_dlllogged that it is not a DLL.init_dllthen still called the image's entry point with DllMain's arguments, so itsmainCRTStartupran on the calling thread. That either started a second copy of the program inside the process, or the load failed with "DllMain returned FALSE".Windows does not call that entry point. LoadLibraryW: "If the specified module is an executable module, static imports are not loaded; instead, the module is loaded as if by LoadLibraryEx with the DONT_RESOLVE_DLL_REFERENCES flag", and that flag means DllMain is not called. XCL's thread attach and detach already call the entry point only for a DLL (
m.is_dll); process attach now does the same.What is in it
crates/xcl/src/loader.rs:init_dllcalls the entry point only when the image is a DLL. Testan_exe_loaded_as_a_library_does_not_run_its_entry_point: an image without the DLL flag whose entry point returns 0 loads, and loads once.Tested
cargo test --workspace -- --test-threads=4on c8a4266: 859 passed, 0 failed, 42 ignored; SKIPPED:heap_window_out_of_memory_falls_back_to_the_switch_form(no heap windows)an EXE loads as a library: "DllMain(xcl_exe_as_library.exe) returned FALSE"Regression run
main:
this PR:
Not tested
AI use
🤖 Generated with Claude Code