HLE: GetProcAddress on our pseudo modules returns NULL without setting the last error (fix on a fork) #764

Open
opened 2026-11-26 04:13:56 +00:00 by github-bot · 2 comments
Owner

@⁠Peppacodes on GitHub · 2026-11-24 09:55 UTC · original

What's wrong

GetProcAddress on one of our pseudo modules, such as the handle LoadLibrary("xgameruntime.dll") returns, can return NULL without setting the last error. That happens in two places in crates/victory-hle/src/modules/kernel.rs:158-175:

  • for an ordinal, since we export by name only;
  • for a name the module doesn't export.

Microsoft's docs for GetProcAddress say that on failure it returns NULL and GetLastError gives the reason. Windows sets ERROR_PROC_NOT_FOUND (127). Code that turns the failure into HRESULT_FROM_WIN32(GetLastError()) gets HRESULT_FROM_WIN32(0) here, which is S_OK, and carries on as if the lookup worked. find_module in the same file already sets ERROR_MOD_NOT_FOUND for a missing module.

I haven't seen a title depend on this. It's a small correctness fix.

Repro

Each call below comes after SetLastError(0):

  • GetProcAddress(GetModuleHandleW(L"kernel32.dll"), "NotAnExport"), which goes to the host: NULL, last error 127.
  • GetProcAddress(LoadLibraryA("xgameruntime.dll"), "NotAnExport"): NULL, last error 0.
  • The same with ordinal 9999: NULL, last error 0.

Fix

Both failure paths now call host::set_last_error(ERROR_PROC_NOT_FOUND) before returning NULL.

Related: #512 makes ordinals resolve on pseudo-module handles, and unexported ordinals still return NULL there. This change sets the last error for those as well. The two touch neighbouring lines in the same function.

Test

a_missing_export_of_our_modules_sets_the_last_error, in kernel.rs's tests:

  • It clears the last error before each lookup.
  • First a missing name on the host's kernel32, for comparison.
  • Then a missing name and an ordinal on xgameruntime.dll.
  • It fails on main (left: 0, right: 127) and passes with the fix.

Results on Windows 11 with Rust 1.98.1, using the CI's own commands:

  • cargo test --workspace --locked: 343 passed, 0 failed, 6 ignored.
  • cargo clippy --workspace --all-targets --locked -- -D warnings, with and without --all-features: clean.
  • rustfmt --edition 2024 --check kernel.rs: clean.
  • cargo xtask policy: 154 files ok.

PR creation is limited to collaborators right now, so this is an issue with the branch. I can open a PR when it reopens.

No game files used. AI use: Claude Code (Claude Opus 5.5) found this in an audit of the HLE modules, wrote the fix and the test, and ran everything above.

**@⁠Peppacodes** on GitHub · 2026-11-24 09:55 UTC · [original](https://github.com/Marvisak/VIctory/issues/764) ## What's wrong `GetProcAddress` on one of our pseudo modules, such as the handle `LoadLibrary("xgameruntime.dll")` returns, can return NULL without setting the last error. That happens in two places in `crates/victory-hle/src/modules/kernel.rs:158-175`: - for an ordinal, since we export by name only; - for a name the module doesn't export. Microsoft's docs for `GetProcAddress` say that on failure it returns NULL and `GetLastError` gives the reason. Windows sets `ERROR_PROC_NOT_FOUND` (127). Code that turns the failure into `HRESULT_FROM_WIN32(GetLastError())` gets `HRESULT_FROM_WIN32(0)` here, which is `S_OK`, and carries on as if the lookup worked. `find_module` in the same file already sets `ERROR_MOD_NOT_FOUND` for a missing module. I haven't seen a title depend on this. It's a small correctness fix. ## Repro Each call below comes after `SetLastError(0)`: - `GetProcAddress(GetModuleHandleW(L"kernel32.dll"), "NotAnExport")`, which goes to the host: NULL, last error 127. - `GetProcAddress(LoadLibraryA("xgameruntime.dll"), "NotAnExport")`: NULL, last error **0**. - The same with ordinal 9999: NULL, last error **0**. ## Fix - **Branch:** https://github.com/Peppacodes/VIctory/tree/fix/getprocaddress-last-error - **Compare:** https://github.com/Marvisak/VIctory/compare/main...Peppacodes:VIctory:fix/getprocaddress-last-error - **Commit:** `d0662f4`, rebased on `main` (`ffe310e`), 0 commits behind it. One file, with its test. Both failure paths now call `host::set_last_error(ERROR_PROC_NOT_FOUND)` before returning NULL. Related: #512 makes ordinals resolve on pseudo-module handles, and unexported ordinals still return NULL there. This change sets the last error for those as well. The two touch neighbouring lines in the same function. ## Test `a_missing_export_of_our_modules_sets_the_last_error`, in `kernel.rs`'s tests: - It clears the last error before each lookup. - First a missing name on the host's kernel32, for comparison. - Then a missing name and an ordinal on `xgameruntime.dll`. - It fails on `main` (`left: 0`, `right: 127`) and passes with the fix. Results on Windows 11 with Rust 1.98.1, using the CI's own commands: - `cargo test --workspace --locked`: 343 passed, 0 failed, 6 ignored. - `cargo clippy --workspace --all-targets --locked -- -D warnings`, with and without `--all-features`: clean. - `rustfmt --edition 2024 --check kernel.rs`: clean. - `cargo xtask policy`: 154 files ok. PR creation is limited to collaborators right now, so this is an issue with the branch. I can open a PR when it reopens. No game files used. AI use: Claude Code (Claude Opus 5.5) found this in an audit of the HLE modules, wrote the fix and the test, and ran everything above.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:13:56 +00:00
Author
Owner

@⁠MamaLeVrai on GitHub · 2026-11-24 19:42 UTC · original

@⁠Peppacodes your fix for this issue is now in a pull request, #1603, together with the three others of yours (#762, #764, #765, #832): the branches are merged as they are, with your commits and your name unchanged, onto main ffe310e. Clippy (both runs) and cargo test --workspace pass on the result. If you would rather open your own pull request for this one, say so and I will take it out of #1603. AI-assisted (Claude Code); no game data.

**@⁠MamaLeVrai** on GitHub · 2026-11-24 19:42 UTC · [original](https://github.com/Marvisak/VIctory/issues/764#issuecomment-7142473271) @⁠Peppacodes your fix for this issue is now in a pull request, #1603, together with the three others of yours (#762, #764, #765, #832): the branches are merged as they are, with your commits and your name unchanged, onto `main` `ffe310e`. Clippy (both runs) and `cargo test --workspace` pass on the result. If you would rather open your own pull request for this one, say so and I will take it out of #1603. AI-assisted (Claude Code); no game data.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 03:51 UTC · original

Automated triage for the maintainers.

Confirmed on main: GetProcAddress in crates/victory-hle/src/modules/kernel.rs returns NULL for an ordinal on a pseudo-module handle and for a name the module does not export, without calling host::set_last_error, so GetLastError keeps whatever was there (unlike find_module in the same file, which sets ERROR_MOD_NOT_FOUND).

Open pull request #1432 already sets ERROR_PROC_NOT_FOUND on both paths; please compare your branch with it and comment there, or open your own pull request if yours differs. The bundle #1603 mentioned above is not open.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 03:51 UTC · [original](https://github.com/Marvisak/VIctory/issues/764#issuecomment-7152299825) <!-- victory-issue-triage v1 verdict=confirmed seen=2026-11-24T19:42:21Z at=2026-11-25T03:51:07Z --> Automated triage for the maintainers. Confirmed on `main`: `GetProcAddress` in `crates/victory-hle/src/modules/kernel.rs` returns NULL for an ordinal on a pseudo-module handle and for a name the module does not export, without calling `host::set_last_error`, so `GetLastError` keeps whatever was there (unlike `find_module` in the same file, which sets `ERROR_MOD_NOT_FOUND`). Open pull request #1432 already sets `ERROR_PROC_NOT_FOUND` on both paths; please compare your branch with it and comment there, or open your own pull request if yours differs. The bundle #1603 mentioned above is not open. --- _Generated by [Claude Code](https://claude.ai/code)_
This discussion has been locked. Commenting is limited to contributors.
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#764
No description provided.