kernelx: the title's LoadLibrary of a system DLL takes its own reference #1209
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/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?
Imported from ivall/xcl. Originally posted by emirduran707 on 2026-11-24T13:19:06Z.
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=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
Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T13:47:05Z.
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:29Z.
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:36Z.
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:09:14Z.
Triage (#1607) – head
8200da8The 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 (GetModuleHandleExWwithout UNCHANGED_REFCOUNT) for a bare-name load of a real system module whose handlesystem_modulecaches, so the title'sFreeLibraryno longer drops XCL's only reference. Related: #1235 (GetModuleHandleEx refcounts on name lookups) is a different change. 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.
Imported from ivall/xcl. Originally posted by fromthemoonx on 2026-12-03T09:03:28Z.
merge-check
base:
16c2fd082ahead:
8200da864emerge: clean (the first commit, #1151, is on main already; only the top one is new)
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 3013 passed, 0 failed, 56 ignored (base: 3012 passed, 0 failed, 56 ignored, counted on
395405e4; only docs and scripts changed since); SKIPPED: 25, the same as base (22 no wave64, 2 no heap windows, 1 no GPU_UPLOAD heaps); failing: nonereview: read the whole diff as it merges (1 file, +25). No finding.
loadperf.dllby name, 3 loads: still loaded after each of 3 frees?pdhui.dllby path, 2 loads: still loaded after each of 2 frees?So a load by name leaves XCL its own reference, and a load by path does not gain an extra one. A title that frees more often than it loads can still take XCL's reference, as before.
3) The condition for "cached" in
load_library_implis the same as inresolver::system_module(a name with no slash, backslash or colon). Modules XCL mapped and its own modules are left out, andFreeLibraryleaves out the same ones.4) Not tested: a retail title (none on this machine), AMD.
performance: none expected: one
GetModuleHandleExWfor eachLoadLibraryof a system DLL by name.verdict: safe to merge
hardware / tool and model: RTX 3060 12 GB (610.88), Ryzen 7 5700X, Windows 11 Pro 26300 / Claude Code (Claude Opus 5.5)
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.