kernelx: honour GetModuleHandleEx flags and refcounts on name lookups #1226
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1235"
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 b3IKK on 2026-11-24T13:30:43Z.
When
GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESSwas not set,module_handle_exdelegated tomodule_handle_impl(GetModuleHandleW), ignoringflags. Real Windows DLLs were returned without incrementing or pinning their reference count, so a matchingFreeLibraryprematurely unloaded the DLL. Invalid flag combinations (such asPIN | UNCHANGED_REFCOUNTor unknown bits) were also accepted.This validates
GetModuleHandleExflags (rejecting unknown bits andPIN | UNCHANGED_REFCOUNTwithERROR_INVALID_PARAMETER) and forwards real Windows DLL lookups toll::GetModuleHandleExW(flags, ...).What is in it
crates/xcl/src/hle/kernelx.rs: addwin_module_handleandmodule_handle_in_ex, validate flags inmodule_handle_ex, and forward real Windows DLL name lookups toll::GetModuleHandleExW; add unit testget_module_handle_ex_honours_refcount_and_rejects_invalid_flags(verified failing before the fix).Tested
stable-x86_64-pc-windows-msvc), DXC 1.9.2609.5, debug (scripts/test.ps1) and release (scripts/smoke.ps1).\scripts\test.ps1(cargo build --workspace+cargo test --workspace -- --test-threads=4): 742 passed, 0 failed, 41 ignored (SKIPPED GPU tests: 2no wave64—gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask,gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware)cargo test -p xcl --lib get_module_handle_ex_honours_refcount_and_rejects_invalid_flags: 1 passed, 0 failed (failed before the fix)Regression run
main:
PR:
Not tested
AI use
kernelx.rs, wrote the fix and regression test, ran the test suite andscripts/smoke.ps1regression runs, and drafted this PR description.Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T13:47:29Z.
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:17:24Z.
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:49Z.
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:11:55Z.
Triage (#1607) – head
33f9d51Not on main:
module_handle_exin kernelx.rs still resolves names throughmodule_handle_impl(plainGetModuleHandleW), soGetModuleHandleExW(0, name)takes no reference, and flags are never validated. #1218 fixes a related refcount problem, but inLoadLibrary(the title's own reference to a cached system DLL). It does not touch GetModuleHandleEx, so it is not a duplicate.The flag validation (only PIN/UNCHANGED_REFCOUNT/FROM_ADDRESS, PIN together with UNCHANGED_REFCOUNT refused,
*out = 0, ERROR_INVALID_PARAMETER) matches Windows. Modules XCL maps and HLE pseudo handles still take no reference, which matchesFreeLibraryignoring them. The test fails without the fix, sinceFreeLibrarywould drop cabinet.dll's only reference, unless something else in the test process has loaded cabinet.dll.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-02T21:46:38Z.
merge-check
base:
5ad98adbc3head:
33f9d51f19merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 3006 passed, 0 failed, 52 ignored; SKIPPED: 25 (22 no wave64, 2 no heap windows, 1 no GPU_UPLOAD heaps); failing: none
review: read the whole diff (1 file, +63 -14). No problem found.
GetModuleHandleExWof XCL and of Windows with flags 0 to 15, for a loaded DLL's name, a missing name, NULL, an address in the DLL and a bad address (40 cases). I compared the return value, the output handle, the error code and how many references the DLL has afterwards.FreeLibraryunloads the DLL, and invalid flags are accepted or give the wrong error.FreeLibraryignores them, so that is consistent.GetModuleHandleExAshares the code; I only ran the W form. No title was run here.Build and test (Windows, no GPU)run. It needs one before a merge.performance: none expected, one flag check per call.
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.