Repository navigation
kernelx: the title's LoadLibrary of a system DLL takes its own reference - #1218
emirduran707 wants to merge 2 commits into
Conversation
|
Verification on RTX 3060 Ti (Windows 11), branch merged with current
Note: the full |
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 <noreply@anthropic.com>
resolver::system_module caches one LoadLibraryW handle per system DLL, and the title's LoadLibrary of such a DLL handed that cached handle back without a reference of its own. Its FreeLibrary goes to the real FreeLibrary, so LoadLibrary + FreeLibrary by the title dropped XCL's only reference and unloaded a DLL that the cache and the imports resolved into it still point at. On Windows every LoadLibrary takes a reference and every FreeLibrary gives one back. The title-facing LoadLibrary (load_library_impl) now takes a reference on the real module it returns (GetModuleHandleExW from its address, which names exactly that module); HLE pseudo handles and modules XCL mapped are left alone, as FreeLibrary leaves them. Import resolution and XCL's own callers of resolver::load_library are unchanged. Test: LoadLibraryW + FreeLibrary of dciman32.dll (System32, used by no other test) leaves it loaded, and a second load finds DCIOpenProvider. Before the fix GetModuleHandleW returned NULL after the FreeLibrary. Only a bare name takes the extra reference: those come from the resolver's cache. A name with a directory is loaded by system_module itself on every call, so that load is already the title's own reference. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
61d406a to
8200da8
Compare
|
Re-verification on RTX 3060 Ti (Windows 11), new head merged with current
Thanks! — Devin |
…pstream xcl-dev#1218 + xcl-dev#1151, resolver verbatim reference-only) Windows resolver.rs hunk verbatim reference-only (cfg(windows)-only): system_module by-path early-load + name-keyed cache + failures-never-cached rewrite + module_path helper + 2 tests. The xcl-dev#1218 resolver hunk is byte-identical to xcl-dev#1151 (git diff pr1151head pr1218head -- resolver.rs empty) — landed once, xcl-dev#1151 triage-closes as CONTAINED. Windows hle/kernelx.rs hunks verbatim reference-only (cfg(windows)-only): load_library_impl title-owned GetModuleHandleExW(FROM_ADDRESS) self-reference block + free_library_of_a_system_dll test. NO Linux twin change: resolver_linux::system_module (resolver_linux.rs) is a stub returning None always — no LoadLibrary twin on Linux, same category as xcl-dev#1667 no-hook-point. Both live heads re-verified pre-commit (pr1218head=8200da86 +72/-7 2 files, pr1151head=5157a51c +47/-7 1 file, both still OPEN, merge-base false, same hashes as plan pin, no force-push).
|
Nothing has happened on this PR for 3 days, so it is marked |
|
The first commit on the branch (5157a51) is already on main through #1151. Only the kernelx.rs commit is new, and main does not have it. kernelx.rs:load_library_impl takes an extra reference ( AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human. |
Stacked 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=4on 8200da8 (this commit on top of PE loader: load system DLLs by path as given and do not cache failures #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