HLE: pass data-only LoadLibraryEx mappings outside HostPolicy to the host #1419

Closed
github-bot wants to merge 1 commit from gh-pr/1419/head into gh-pr/1419/base
Owner

@⁠fuzeofficlal on GitHub · 2026-11-24 17:54 UTC · original
fuzeofficlal:fix/hle-load-library-datafile-805 → main · +87 −12 · 1 files · 1 commits · closed without merging

Fixes #805.

Summary

  • Distinguish GetModuleHandle queries (Lookup::Query), executable loads (Lookup::Code), uninitialised image loads (Lookup::NoInit for DONT_RESOLVE_DLL_REFERENCES), and passive data or resource mappings (Lookup::Data when LOAD_LIBRARY_AS_DATAFILE, LOAD_LIBRARY_AS_IMAGE_RESOURCE, or LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE is set without 0x1) in kernel::find_module.
  • Return None on Lookup::Data for modules outside HostPolicy that are neither mapped title images nor pseudo modules so the host maps data/resource handles (whose exports GetProcAddress cannot resolve), while keeping DONT_RESOLVE_DLL_REFERENCES (0x1), executable LoadLibrary* loads, and GetModuleHandle* gated by HostPolicy.

Verification

  • modules::kernel::tests::datafile_loads_outside_host_policy_reach_the_host: verifies 0x2, 0x20, 0x40, and 0x22 succeed on a DLL outside HostPolicy and return null from GetProcAddress, whereas 0x1 (DONT_RESOLVE_DLL_REFERENCES), executable LoadLibrary*, and GetModuleHandle* stay refused with ERROR_MOD_NOT_FOUND.
  • cargo test -p victory-hle --locked, cargo clippy -p victory-hle --tests --locked -- -D warnings, and cargo xtask policy: passed.
**@⁠fuzeofficlal** on GitHub · 2026-11-24 17:54 UTC · [original](https://github.com/Marvisak/VIctory/pull/1419) `fuzeofficlal:fix/hle-load-library-datafile-805` → `main` · +87 −12 · 1 files · 1 commits · closed without merging Fixes #805. ### Summary - Distinguish `GetModuleHandle` queries (`Lookup::Query`), executable loads (`Lookup::Code`), uninitialised image loads (`Lookup::NoInit` for `DONT_RESOLVE_DLL_REFERENCES`), and passive data or resource mappings (`Lookup::Data` when `LOAD_LIBRARY_AS_DATAFILE`, `LOAD_LIBRARY_AS_IMAGE_RESOURCE`, or `LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE` is set without `0x1`) in `kernel::find_module`. - Return `None` on `Lookup::Data` for modules outside `HostPolicy` that are neither mapped title images nor pseudo modules so the host maps data/resource handles (whose exports `GetProcAddress` cannot resolve), while keeping `DONT_RESOLVE_DLL_REFERENCES` (`0x1`), executable `LoadLibrary*` loads, and `GetModuleHandle*` gated by `HostPolicy`. ### Verification - `modules::kernel::tests::datafile_loads_outside_host_policy_reach_the_host`: verifies `0x2`, `0x20`, `0x40`, and `0x22` succeed on a DLL outside `HostPolicy` and return null from `GetProcAddress`, whereas `0x1` (`DONT_RESOLVE_DLL_REFERENCES`), executable `LoadLibrary*`, and `GetModuleHandle*` stay refused with `ERROR_MOD_NOT_FOUND`. - `cargo test -p victory-hle --locked`, `cargo clippy -p victory-hle --tests --locked -- -D warnings`, and `cargo xtask policy`: passed.
Distinguish GetModuleHandle queries, executable loads, and passive data or resource mappings in find_module. When runs_code(flags) is false (LOAD_LIBRARY_AS_DATAFILE, LOAD_LIBRARY_AS_IMAGE_RESOURCE, or LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE) and the name does not match a mapped title image or console pseudo module, return None so the host loader maps the file as data while keeping code loads (including DONT_RESOLVE_DLL_REFERENCES) and GetModuleHandle gated by HostPolicy.

Closes #805
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:31:01 +00:00
github-bot closed this pull request 2026-11-26 04:31:01 +00:00
Author
Owner

@⁠geiyiliyabumo on GitHub · 2026-11-24 18:03 UTC · original

Independent verification of \c8b7a3d\ on Windows 11 / Rust 1.98.1 MSVC:

  • Merge check vs \main\ (\ fe310e): clean
  • \cargo test -p victory-hle --lib kernel: 5 passed, 0 failed (including \datafile_loads_outside_host_policy_reach_the_host)
  • \cargo clippy -p victory-hle --all-targets -- -D warnings\ (default and --all-features): clean
  • \cargo xtask policy: 154 files ok

Code audit looks clean and minimal: introducing \Lookup::{Query, Code, Data}\ keeps code loads and \GetModuleHandle*\ queries outside \HostPolicy\ refused while allowing passive data/resource mappings through to the host.

AI-assisted; synthetic tests only, no game files.

**@⁠geiyiliyabumo** on GitHub · 2026-11-24 18:03 UTC · [original](https://github.com/Marvisak/VIctory/pull/1419#issuecomment-7140103760) Independent verification of \c8b7a3d\ on **Windows 11 / Rust 1.98.1 MSVC**: - Merge check vs \main\ (\ fe310e\): clean - \cargo test -p victory-hle --lib kernel\: **5 passed, 0 failed** (including \datafile_loads_outside_host_policy_reach_the_host\) - \cargo clippy -p victory-hle --all-targets -- -D warnings\ (default and \--all-features\): clean - \cargo xtask policy\: 154 files ok Code audit looks clean and minimal: introducing \Lookup::{Query, Code, Data}\ keeps code loads and \GetModuleHandle*\ queries outside \HostPolicy\ refused while allowing passive data/resource mappings through to the host. *AI-assisted; synthetic tests only, no game files.*
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 01:26 UTC · original · edited 2026-11-25 11:20 UTC

Automated triage for the maintainers.

Needs work. 07326307 fixes the hole from the last triage. In crates/victory-hle/src/modules/kernel.rs, load_lookup sends DONT_RESOLVE_DLL_REFERENCES (0x1) to the new Lookup::NoInit, which find_module still refuses outside HostPolicy and which does not call runtime::load_title_dll. Only pure data/resource loads (0x2, 0x20, 0x40 without 0x1) become Lookup::Data and go to the host. The test asserts all of this, and GetModuleHandle* and code loads stay refused. CI: passing (check).

What remains:

  • Evidence. This PR relaxes the host-DLL guard, so it needs a case where the title actually makes such a load: a "host DLL outside the host policy: refused" log line from a run, together with the flags passed to LoadLibraryEx. #805 shows the behaviour on a synthetic call only. Without a load seen in the title, the guard should stay as it is.
  • A DLL the host process already has loaded. Please check what the host returns for a data load of a DLL outside HostPolicy that the host process has already loaded as an image. If the host hands back the existing image handle, GetProcAddress would resolve real exports through it, which is the case the guard exists for. The test passes for comctl32.dll only because that DLL is not loaded as an image in the test process.

On your reply: the 0x1 change is exactly what was asked, thanks. The verdict stays at needs work only because of the two points above.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 01:26 UTC · [original](https://github.com/Marvisak/VIctory/pull/1419#issuecomment-7149557206) · edited 2026-11-25 11:20 UTC <!-- victory-triage v1 head=07326307b2d7e1e329b908299dfb5acc3d2d0242 verdict=needs-work at=2026-11-25T11:20:08Z --> Automated triage for the maintainers. **Needs work.** `07326307` fixes the hole from the last triage. In `crates/victory-hle/src/modules/kernel.rs`, `load_lookup` sends `DONT_RESOLVE_DLL_REFERENCES` (0x1) to the new `Lookup::NoInit`, which `find_module` still refuses outside `HostPolicy` and which does not call `runtime::load_title_dll`. Only pure data/resource loads (0x2, 0x20, 0x40 without 0x1) become `Lookup::Data` and go to the host. The test asserts all of this, and `GetModuleHandle*` and code loads stay refused. CI: passing (`check`). What remains: - **Evidence.** This PR relaxes the host-DLL guard, so it needs a case where the title actually makes such a load: a "host DLL outside the host policy: refused" log line from a run, together with the flags passed to `LoadLibraryEx`. #805 shows the behaviour on a synthetic call only. Without a load seen in the title, the guard should stay as it is. - **A DLL the host process already has loaded.** Please check what the host returns for a data load of a DLL outside `HostPolicy` that the host process has already loaded as an image. If the host hands back the existing image handle, `GetProcAddress` would resolve real exports through it, which is the case the guard exists for. The test passes for `comctl32.dll` only because that DLL is not loaded as an image in the test process. On your reply: the 0x1 change is exactly what was asked, thanks. The verdict stays at needs work only because of the two points above. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-25 09:48 UTC · original

Updated in 07326307 per triage feedback:

  • Kept DONT_RESOLVE_DLL_REFERENCES (0x1) on a separate Lookup::NoInit path so unmapped title DLLs still avoid load_title_dll (DllMain) as on main, while DLLs outside HostPolicy remain refused (ERROR_MOD_NOT_FOUND).
  • Restricted Lookup::Data to pure data/resource mappings (0x2, 0x20, 0x40 without 0x1), dropped 0x1 from the allowed test list, and added explicit assertions that 0x1 outside HostPolicy is refused and GetProcAddress on mapped data handles returns null.
**@⁠fuzeofficlal** on GitHub · 2026-11-25 09:48 UTC · [original](https://github.com/Marvisak/VIctory/pull/1419#issuecomment-7158830840) Updated in `07326307` per triage feedback: - Kept `DONT_RESOLVE_DLL_REFERENCES` (`0x1`) on a separate `Lookup::NoInit` path so unmapped title DLLs still avoid `load_title_dll` (`DllMain`) as on `main`, while DLLs outside `HostPolicy` remain refused (`ERROR_MOD_NOT_FOUND`). - Restricted `Lookup::Data` to pure data/resource mappings (`0x2`, `0x20`, `0x40` without `0x1`), dropped `0x1` from the allowed test list, and added explicit assertions that `0x1` outside `HostPolicy` is refused and `GetProcAddress` on mapped data handles returns null.
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-25 17:20 UTC · original

Closing this PR: as noted in triage, loosening the HostPolicy gate requires a real title log showing the refused DLL call site, which I do not have locally.

**@⁠fuzeofficlal** on GitHub · 2026-11-25 17:20 UTC · [original](https://github.com/Marvisak/VIctory/pull/1419#issuecomment-7169356470) Closing this PR: as noted in triage, loosening the `HostPolicy` gate requires a real title log showing the refused DLL call site, which I do not have locally.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!1419
No description provided.