Loader: a game DLL that failed to load is not left registered (#106) #139
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/141"
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 tiagonleal on 2026-11-23T15:02:38Z.
#106 item 3, the loader part: "
loader.rsregisters mapped modules beforepe.imports()/tls_install()without unregistering (or freeing on TLS error) on failure, and caches DLLs whoseDllMain(PROCESS_ATTACH)returnedFALSEinMAPPEDso a secondload_game_dllreturnsOk(m)".map_image_exregisters the module before resolving its imports, so that cyclic game-DLL imports terminate. A failure after that left it in the registry:load_game_dllreturned it (use after free)DllMainreturns FALSEOkwithoutDllMainever having succeededDllMainagain, as Windows' loader doesmodules::unregister_mapped(base)takes the module out of the name / base / address lookups (it also clears its slot in the lock-free range table). After a TLS orDllMainfailure the memory stays mapped: codeDllMainran, or game DLLs loaded while its imports were resolved, may point into it. A leak on a failure path is safer than a dangling pointer.Tests
loader::testsbuilds a PE32+ DLL in the test: one.textsection, relocatable with an empty block, entry pointxor eax, eax; retormov eax, 1; ret.a_dll_whose_dllmain_fails_is_not_loaded: both loads fail with "returned FALSE" and nothing is left registered. The second load is relocated, since the first copy's memory stays, and runsDllMainagain. The TRUE variant loads, and a second load returns the same module.a_dll_with_a_broken_import_table_is_not_left_registered: an import descriptor whose name RVA lies outside the image. Both loads fail with "import table" and nothing is left registered.Both tests failed without the change (
attempt 0: still registered).cargo test --workspace --no-fail-fast -- --test-threads=4onmain484dd57(RTX 5070 Ti): 562 passed, 0 failed, 39 ignored. No game run (only failure paths changed).AI-assisted.
🤖 Generated with Claude Code
Imported from ivall/xcl. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-23T15:02:48Z.
Review: COMMENTED
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
Imported from ivall/xcl. Originally posted by ivall on 2026-11-23T21:08:59Z.
Merged (main
6da33fa). Checked on an RX 9070 (RDNA4) with the 22 PRs merged together on maineaa36b6:cargo build --workspace && cargo test --workspace -- --test-threads=4- 582 unit tests passed, 0 failed (20 ignored), the integration and e2e tests passed too; and the retail game still reaches its first menu (646 frames in 30 s, no device removal).upstream-sync referenced this pull request2026-11-24 21:07:02 +00:00