PE loader: LoadLibrary waits for a game DLL another thread is loading #1208
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1217"
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 ivall/xcl. Originally posted by emirduran707 on 2026-11-24T13:18:56Z.
The loader registers a game DLL early (
loader.rs,modules::register_mapped): before its imports are resolved, before its pages get their protections, and beforeDllMainruns. The loader's lock serialises callers ofload_game_dll. Butresolver::load_libraryreturns a DLL it finds by name at once, outside that lock. So thread B callingLoadLibraryfor a DLL that thread A is still loading got its base immediately, while the DLL's pages were still read-write, its import slots unresolved and itsDllMainnot run. If A'sDllMainthen failed, B held a handle to a DLL that was unloaded. Windows'LoadLibraryreturns a handle only onceDllMainhas returned TRUE, and NULL when it returns FALSE.A DLL that is found but not yet initialised is now loaded through
load_game_dll. On another thread that waits for the loader's lock, so B gets the module once A's load has finished, or NULL if it failed. The loading thread itself is re-entrant and still gets it at once, as when aDllMainloads its own DLL.What is in it
crates/xcl/src/resolver.rs: the wait inload_library.crates/xcl/src/loader.rs: testload_library_waits_for_a_dll_another_thread_is_loading. It holds the loader lock and maps a DLL without running itsDllMain, then callsload_libraryon another thread. The call must not return untilinit_dllhas run and the lock is released.Tested
cargo test --workspace -- --test-threads=4on8933d64: 742 passed, 0 failed, 41 ignored; no SKIPPED GPU testsresolver.rsfails (load_libraryreturned the base before the DLL was initialised); with it it passesRegression run
main:
this PR:
Not tested
AI use
🤖 Generated with Claude Code
Imported from ivall/xcl. Originally posted by thehollowedone on 2026-11-24T13:22:44Z.
Independent Windows check of the failed-attach path on
47efa2eand8933d64. Windows 11 build 26300, Ryzen 7 9800X3D, Rust 1.99.1 MSVC, debug.A scratch fixture paused the first load after registering a synthetic DLL and before its
DllMainreturned FALSE. A second thread calledLoadLibraryfor the same name during that pause. On main it returned a handle before initialization finished. On the PR it waited, then returned no handle once initialization failed. The failed DLL was absent from the loaded-module registry. The probe checked the returned status only.cargo test --offline --locked -p xcl --lib scratch_second_load_waits_then_reports_failed_attach -- --test-threads=1failed on main and passed on the PR. Theloader::testsfilter passed 4/4 on the PR, including the scratch case and the stock successful-attach case. Synthetic DLLs only.AI-assisted. Codex (GPT-6, exact variant unavailable) wrote and ran the scratch test and drafted this report.
Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T13:47:11Z.
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:Note: the full
d3d12xlib filter currently aborts with 0xc0000005 on unmodifiedmaintoo (pre-existing, unrelated to this PR); the PR's own tests were run by name and pass.Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-26T04:05:27Z.
Re-verification on RTX 3060 Ti (Windows 11), new head merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved.Thanks!
— Devin
Imported from ivall/xcl. Originally posted by github-actions[bot] on 2026-11-30T08:42:34Z.
Nothing has happened on this PR for 3 days, so it is marked
staleand will be closed in 4 days. A push or a comment takes the mark off: rebase it ontomainif it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T05:08:58Z.
Triage (#1607) – head
8933d64No open or merged PR makes the same change; main's
resolver::load_librarystill returns a registered but uninitialised game DLL at once. When the module is not initialised yet, this PR goes throughload_game_dll, which waits on the loader lock (re-entrant on the loading thread). If that DllMain failed, the module is unregistered and gets mapped again, as on Windows. The branch conflicts with main and needs a rebase. No problems found in the diff.Recommendation: keep open.
AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
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.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.