Repository navigation
PE loader: thread callbacks wait for a DLL to be initialised - #1119
emirduran707 wants to merge 1 commit into
Conversation
on_tls_event ran the TLS callbacks of every registered module on each DLL_THREAD_ATTACH / DETACH, and checked `initialized` only before DllMain. A game DLL is registered, and its TLS callbacks read, before its pages get their protections and before its PROCESS_ATTACH (init_dll). So when the title LoadLibrary's a game DLL while another of its threads starts or ends, that DLL's callback can run on code that is not executable yet (a DEP fault) or before the DLL's runtime has set itself up. Windows' loader sends thread notifications only to modules whose process attach has run. The module loop is now thread_event, which skips DLLs that are not initialised for both callbacks and DllMain; the executable, which never sets the flag, still gets its callbacks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Independent Windows 11 check at df36761 with Rust 1.99.1 MSVC. The offline workspace build and all three stock loader tests passed. A scratch fixture using ordinary compiled callbacks verified both sides of initialization. While one DLL was still in process attach, it received no thread attach or detach callback. Already initialized modules kept their callback order. After initialization returned, the DLL joined the next thread notification in the expected position, with TLS before DllMain on attach and the reverse on detach. The executable kept its TLS notifications throughout. The fixture passed in three separate processes. Synthetic coverage only. AI-assisted. Codex (GPT-6) added and ran the scratch fixture. |
|
NVIDIA run with the whole suite, since Not tested lists NVIDIA; the earlier check here ran the loader tests and a fixture. Tested
Not tested
AI use
|
|
A run on Linux under Wine. Tested
Not tested
AI use
|
|
Tested — df36761 on Windows 11 Pro build 26300, Ryzen 5 5500, MSVC 14.44.35207,
Result: 1 passed, 0 failed, 0 ignored, 719 filtered out. This test exercises the Not tested — Application behaviour beyond this synthetic unit test. The run AI use — DeepSeek Harness (DeepSeek V4.1 Flash) ran the test and drafted this report. |
|
Verification on RTX 3060 Ti (Windows 11), branch merged with current
Thanks! |
loader::on_tls_eventran the TLS callbacks of every registered module on eachDLL_THREAD_ATTACH/DETACH, and checkedinitializedonly before calling DllMain. A game DLL is registered, and its TLS callbacks are read (map_image_exstep 5), before its pages get their protections (step 6) and before its PROCESS_ATTACH (init_dll).So if the title
LoadLibrarys a game DLL with TLS callbacks while another of its threads starts or ends, that DLL's callback can run:0xc0000005);Windows' loader sends thread notifications only to modules whose process attach has run.
What is in it
crates/xcl/src/loader.rs:on_tls_eventis nowthread_event;initialized, still gets its callbacks;thread_callbacks_wait_for_a_dll_to_be_initialised:left: 5, right: 0(both callbacks ran).Tested
x86_64-pc-windows-msvc; DXC 1.9.2602.17; debug for the suite, release for the runs.cargo test --workspace -- --test-threads=4at df36761: 742 passed, 0 failed, 41 ignored; noSKIPPEDlines.Regression run
The
gpu:line names a virtual display adapter of this machine (what #281 / #282 / #285 fix); XCL's log namesbackend 'real' – AMD Radeon RX 9060 XT (16188 MiB VRAM).main:
PR:
Not tested
AI use
map_image_ex/init_dll/on_tls_event;🤖 Generated with Claude Code