kernelx: the title's LoadLibrary of a system DLL takes its own reference #1218
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!1218
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1218"
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 13:19 UTC · original
emirduran707:loadlibrary-own-reference→main· +72 −7 · 2 files · 2 commits · openStacked on #1151; only the top commit (
kernelx: the title's LoadLibrary of a system DLL takes its own reference) belongs here.resolver::system_modulecaches one host module handle per DLL name; XCL resolves imports into it and keeps it. The title'sLoadLibraryof such a DLL returned that cached handle without taking a reference of its own, while the title'sFreeLibrarygoes to the realFreeLibrary. So a title that callsLoadLibrary("foo.dll"), thenFreeLibraryon the result, dropped XCL's only reference. Windows unloaded the DLL under XCL's cached handle and under every import resolved into it, and the next call through one of them crashed. Microsoft's documentation ofLoadLibrary: "Calling LoadLibrary increments the reference count."load_library_impl(the title'sLoadLibraryW/A/ExW/ExA) now takes a reference for the title, withGetModuleHandleExW(FROM_ADDRESS)on the returned module, when the handle is a real host module (not one XCL mapped, not an HLE handle) and the name is bare. Bare names come from the cache. With #1151, a name with a directory is loaded bysystem_moduleon every call, and that load is already the title's reference. Other callers ofresolver::load_library(delay-load handles) are unchanged.What is in it
crates/xcl/src/hle/kernelx.rs: the reference inload_library_impl; testfree_library_of_a_system_dll_leaves_xcl_its_reference. It runsLoadLibraryW+FreeLibraryofdciman32.dll, a System32 DLL no other test uses, and checks that the DLL is still loaded. A second load then findsDCIOpenProvider.Tested
cargo test --workspace -- --test-threads=4on8200da8(this commit on top of #1151): 744 passed, 0 failed, 41 ignored; no SKIPPED GPU testsGetModuleHandleW("dciman32.dll")is NULL after the title'sFreeLibrary(left: 0); with it it passesRegression run
main:
this PR:
Not tested
AI use
🤖 Generated with Claude Code
system_module cached host module handles in SYS_CACHE keyed by dll_key, which drops the directory, and it cached failures (0) too. So after LoadLibrary("C:\Missing\foo.dll") failed, a later LoadLibrary("foo.dll") returned NULL without trying, and once version.dll was cached, LoadLibrary("C:\Mods\version.dll") returned the System32 copy. Windows loads the path it is given. A name with a directory component is now loaded as given with LoadLibraryW and not cached; bare names (import resolution, the HLE modules' system_module("x.dll") calls) still use the name-keyed cache, which now only holds successful loads. Under Wine, a copy of version.dll is a Wine builtin and is mapped to the module already loaded under that name whatever path is given, so the test checks the load by path only on Windows (found in a test run under Wine). Co-Authored-By: Claude Opus 5.5 <[email protected]>@DavidM1911 on GitHub · 2026-11-24 13:47 UTC · original
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.@DavidM1911 on GitHub · 2026-11-26 04:05 UTC · original
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
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.