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

Open
opened 2026-11-24 09:55:09 +00:00 by Peppacodes · 2 comments
Peppacodes commented 2026-11-24 09:55:09 +00:00 (Migrated from github.com)
Contributor

Imported from Marvisak/VIctory. Originally posted by Peppacodes on 2026-11-24T09:55:09Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6579157278 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/issues/764). Originally posted by [Peppacodes](https://github.com/Peppacodes) on 2026-11-24T09:55:09Z. --- ## 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.
MamaLeVrai commented 2026-11-24 20:03:17 +00:00 (Migrated from github.com)
Author
Contributor

Imported from Marvisak/VIctory. Originally posted by MamaLeVrai on 2026-11-24T19:42:21Z.


@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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7142473271 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/issues/764#issuecomment-7142473271). Originally posted by [MamaLeVrai](https://github.com/MamaLeVrai) on 2026-11-24T19:42:21Z. --- @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.
Marvisak commented 2026-11-25 04:07:07 +00:00 (Migrated from github.com)
Author
Contributor

Imported from Marvisak/VIctory. Originally posted by Marvisak on 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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7152299825 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/issues/764#issuecomment-7152299825). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T03:51:07Z. --- <!-- 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)_
Sign in to join this conversation.
No labels
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.

Reference
Marvisak/VIctory#764
No description provided.