PE loader: thread callbacks wait for a DLL to be initialised #1119
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl!1119
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1119"
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?
@emirduran707 on GitHub · 2026-11-24 12:00 UTC · original
emirduran707:loader-tls-ready→main· +65 −14 · 1 files · 1 commits · openloader::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=4atdf36761: 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
github-bot referenced this pull request2026-11-26 04:59:09 +00:00
@thehollowedone on GitHub · 2026-11-24 12:08 UTC · original
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.
@fromthemoonx on GitHub · 2026-11-24 12:39 UTC · original
NVIDIA run with the whole suite, since Not tested lists NVIDIA; the earlier check here ran the loader tests and a fixture.
Tested
stable-x86_64-pc-windows-msvc; DXC 1.9.2602.17; debugdf3676101e0a3f03f5ae35575bdbffc39c40d1ce, which is on currentmain47efa2e(so also the merged result):cargo build --workspace, thencargo test --workspace --no-fail-fast -- --test-threads=4: 742 passed, 0 failed, 41 ignored. The newloader::tests::thread_callbacks_wait_for_a_dll_to_be_initialisedpassed.thread_event, so I kept this PR's file and changed onlyreadyback to "every module" (|_m| true, DllMain keeping its owninitializedcheck, as before). The test fails withcallbacks of a DLL not initialised yet,left: 5, right: 0.loader::+tls::tests, 10 runs: 10 of 10 passede2e, 3 runs: 3 of 3 passed. The test title loadstestgame_mw.dllwith a TLS block through this loader (TLS: testgame_mw.dll: … threads initialized: 1in its log) and starts threads afterwards.XCL_D3D12_DEBUG=1run logs the same set of debug-layer errors and warnings as onmain.gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardwareNot tested
LoadLibrarying a DLL with TLS callbacks while another thread starts); a retail title; release build.AI use
@JoaoPauluu on GitHub · 2026-11-24 14:34 UTC · original
A run on Linux under Wine.
Tested
x86_64-pc-windows-gnu.df36761as it is (based on47efa2e), no uncommitted changes. The lib test binary runs under Wine, one test per process (--exact). Thread creation and the loader lock are Wine's here.loader::tests::thread_callbacks_wait_for_a_dll_to_be_initialised: ok, no SKIPPED.Not tested
AI use
@wanchudao on GitHub · 2026-11-24 15:42 UTC · original
Tested —
df36761on Windows 11 Pro build 26300, Ryzen 5 5500, MSVC 14.44.35207,and rustc 1.100.0.
cargo test -p xcl --lib thread_callbacks_wait_for_a_dll_to_be_initialised -- --nocaptureResult: 1 passed, 0 failed, 0 ignored, 719 filtered out. This test exercises the
loader ordering on the CPU.
Not tested — Application behaviour beyond this synthetic unit test. The run
provides CPU-side coverage only.
AI use — DeepSeek Harness (DeepSeek V4.1 Flash) ran the test and drafted this report.
OpenAI Codex (GPT-6.2 Sol) checked the archived result and revised it.
@DavidM1911 on GitHub · 2026-11-25 08:15 UTC · original
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.)Thanks!
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.