HLE: GetModuleHandleEx finds the title's modules, not the host's #2504
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2506"
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 Marvisak/VIctory. Originally posted by cryst4lpepsi on 2026-11-25T14:59:14Z.
What
GetModuleHandleA/W,LoadLibrary*andGetProcAddressgive a title its own modules, butGetModuleHandleExA/Whad no override, so imports of them (andGetProcAddresslookups) were bound to the host:victory.exe, not the title's image.xgameruntime.dll) were looked up under host names, not ours.HostPolicywas found if anything in our process had loaded it.Both now use the same lookup as
GetModuleHandle. Lookups by address (FROM_ADDRESS), allowed host DLLs and invalid arguments still go to the host. No reference is taken on title images or pseudo modules, matchingFreeLibrary, which never drops one.I have no copy of the title, so I haven't checked whether it calls these.
An AI tool (Claude Code) wrote this change.
Tested
Windows 11, Rust 1.98.1, rebased on
940d32f:cargo test -p victory-hle --locked: all pass, three runs (144 unit tests, plus the integration tests). With the two exports removed, the new unit test fails. The no-name case has its own test process, because the main image is process-wide.cargo clippy --workspace --all-targets --locked -- -D warnings, with and without--all-features: clean.cargo test --workspace --locked: passes except invictory-gpu(aborts) andvictory-shader(6 hardware tests), neither of which depends onvictory-hle. Without this change,940d32ffails the same way on this machine (AMD Radeon iGPU + RTX 3050 Ti Laptop): the same 6 shader tests and the samevictory-gpuabort. Onevictory-gputest,null_3d_uav_is_accepted_by_the_device, was reported failed only in the run with the change.cargo xtask policy: asset policy: 183 files ok. Nothing from the game was used.Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T15:56:43Z.
Automated triage for the maintainers. Recommended for a look (not an approval).
Adds
GetModuleHandleExA/Woverrides incrates/victory-hle/src/modules/kernel.rsthat reusefind_module(andruntime::main_imagefor a null name), asGetModuleHandleA/Walready do; previously these went straight to the host, so a null name gave our exe and a DLL outsideHostPolicy(e.g. wininet) could be found if loaded. Address lookups and unsupported flags still go to the host; the unit test and the separate-process integration test cover title images, console modules, the refused-DLL case and the host fallbacks. CI (check) is passing.Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T00:52:46Z.
Code review and Windows 11 verification at head
748efa86bf2emerged cleanly ontomain(63bcca43c6a0):crates/victory-hle/src/modules/kernel.rs:34-73):named_handlecleanly handles name-basedGetModuleHandleExA/Wcalls (flagsin0 | PIN | UNCHANGED_REFCOUNT,!out.is_null()): returnsruntime::main_image()forNULL, resolves title/console modules throughfind_module(&name, false)(rejecting disallowed host DLLs withERROR_MOD_NOT_FOUNDand writing null to*out), and forwards allowed host DLLs,FROM_ADDRESS, invalid flag combinations (PIN | UNCHANGED_REFCOUNT), and nulloutstraight to the host.#2902(does not modifyfind_module, so it inherits the trailing-dot fix automatically). Non-blocking note:GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESSagainst a manually mapped title DLL still delegates to host Ldr (matching existingcrash::module_ofscope).cargo xtask policy:192 files ok;cargo clippy -p victory-hle --all-targets --locked -- -D warnings(default +--all-features): 0 warningscargo test -p victory-hle --locked(default +--all-features): 153/153 lib + 1 subprocess (module_handle_ex_finds_what_module_handle_does) +fidelityfx+main_module_handle+no_dll_plantingall passed.LGTM.
Imported from Marvisak/VIctory. Originally posted by futurepro62 on 2026-11-26T01:44:23Z.
NVIDIA full-suite run, to go with the reports above by fuzeofficlal, since none of them names a GPU run. Tested exact head
748efa8(on its base940d32f).Tested
dxil.dllfrom Windows SDK 10.0.26100 (the loader's default), debug.cargo build --workspace --locked, thencargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware: 698 passed, 0 failed, 10 ignored.module_handle_ex_finds_what_module_handle_does,no_name_is_the_titles_exe.--skipleaves out tests that fail on main63bcca4on this card too, not because of this PR:heap_direct_texture_reads_mark_their_heap_indexends thevictory-shadertest process with0xc0000005(#2571), so without the skip the rest of that crate never reports;dynamic_slots_are_held_until_released,lists_share_a_table_and_copies_keep_their_viewsand the twostride_testshit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317);gathers_at_a_level_match_the_hardwarefails on lane 0 (#1744).Not tested
AI use
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T09:05:16Z.
Review: APPROVED
Checked all
GetModuleHandleExA/Wboundary cases incrates/victory-hle/src/modules/kernel.rs(748efa86):out, invalid flag combinations (e.g.PIN | UNCHANGED_REFCOUNT),FROM_ADDRESS, andHostPolicy-allowed host DLLs cleanly fall through to hostGetModuleHandleExA/W, preserving hostLastErrorand refcount semantics.namewith0 | PIN | UNCHANGED_REFCOUNTreturnsruntime::main_image(), and named lookups sharefind_module(&name, false)withGetModuleHandleA/W(covering title DLLs, console pseudo-modules, empty-string / disallowed host DLL rejection withERROR_MOD_NOT_FOUND+ null*out), while matchingFreeLibrary's no-decrement handling for title images and pseudo-modules.origin/main(63bcca43) viagit merge-tree. (Optional housekeeping: rebasing onto currentmainwould drop the stale base diff warning, and supportingFROM_ADDRESSfor title-mapped virtual ranges can be a separate follow-up if a title needs it.)Verified locally on Windows 11:
cargo clippy -p victory-hle --all-targets -- -D warnings(default and--all-features): cleancargo test -p victory-hle --lib -- modules::kernel::tests::: 6/6 passedcargo test -p victory-hle --test main_module_handle: 1/1 passedcargo xtask policy: cleanLGTM.
Imported from Marvisak/VIctory. Originally posted by cloph-dsp on 2026-11-26T08:50:28Z.
Independent local verification of head
748efa8on Windows 11, Rust 1.100.0/MSVC:cargo test --locked -p victory-hle --lib module_handle_ex_finds_what_module_handle_does— 1 passed, 0 failed.cargo test --locked -p victory-hle --test main_module_handle— 1 passed, 0 failed.One housekeeping issue:
git diff --check origin/main HEADfails because the branch is behind currentmain— it reportscrates/victory-formats/src/xma/tables.rs:410: new blank line at EOF. A rebase onto currentmainshould clear it; the module-handle changes themselves pass.Synthetic tests only; no game assets or DRM material used. AI-assisted (Hy4 flash).
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.