Loader & HLE: harden VEH crash handler, PE prep/exports/TLS, and allow oleaut32 #216

Open
wbkepler wants to merge 1 commit from upstream-pr/216 into main
wbkepler commented 2026-11-24 01:30:04 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by wbkepler on 2026-11-24T01:30:04Z.


Summary

  • VEH crash handler hardening:
    • Enforces page-bound checks before reading faulting bytes in emulate_amd_only, clwb_len, and sse4a (fixing page-end clwb emulation in the last 14 bytes of a page).
    • Guards thrown() against C++ rethrows (null ThrowInfo), null object pointers, and out-of-range catchable-type tables.
    • Makes report_crashes() idempotent via Once, serializes crashes.log writes with a Mutex, and reserves overflow stack via SetThreadStackGuarantee on handler install, title main thread, and thread attach.
  • PE preparation, export resolution, and TLS:
    • Strips IMAGE_DLLCHARACTERISTICS_GUARD_CF alongside FORCE_INTEGRITY in prepare.rs.
    • Resolves title DLL direct and forwarded exports via victory-pe ExportInfo and ImportResolver (with recursion depth guard) instead of host GetProcAddress / LdrpResolveForwarder.
    • Wraps _tls_index zeroing in VirtualProtect and calls FlushInstructionCache after emitting TLS thunks.
  • HLE oleaut32.dll support:
    • Allows oleaut32.dll in default HostPolicy so standard OLE Automation/BSTR imports (including ordinals #4 SysAllocStringLen and #6 SysFreeString) resolve to the host.

Verification

  • cargo clippy --workspace --all-targets — passed (zero new warnings)
  • cargo clippy -p victory --features diagnostics --all-targets — passed
  • cargo test --workspace — passed (including new tests for page-end emulation, C++ rethrow/ThrowInfo guards, idempotent report_crashes/stack guarantee, GUARD_CF stripping, forwarded/cyclic export resolution, read-only _tls_index patching, and oleaut32 ordinals)
  • cargo xtask policy — passed (151 files ok)
<!-- greyfinch-sync:Marvisak/VIctory:issue:6572535283 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/216). Originally posted by [wbkepler](https://github.com/wbkepler) on 2026-11-24T01:30:04Z. --- ## Summary - **VEH crash handler hardening**: - Enforces page-bound checks before reading faulting bytes in `emulate_amd_only`, `clwb_len`, and `sse4a` (fixing page-end `clwb` emulation in the last 14 bytes of a page). - Guards `thrown()` against C++ rethrows (null `ThrowInfo`), null object pointers, and out-of-range catchable-type tables. - Makes `report_crashes()` idempotent via `Once`, serializes `crashes.log` writes with a `Mutex`, and reserves overflow stack via `SetThreadStackGuarantee` on handler install, title main thread, and thread attach. - **PE preparation, export resolution, and TLS**: - Strips `IMAGE_DLLCHARACTERISTICS_GUARD_CF` alongside `FORCE_INTEGRITY` in `prepare.rs`. - Resolves title DLL direct and forwarded exports via `victory-pe` `ExportInfo` and `ImportResolver` (with recursion depth guard) instead of host `GetProcAddress` / `LdrpResolveForwarder`. - Wraps `_tls_index` zeroing in `VirtualProtect` and calls `FlushInstructionCache` after emitting TLS thunks. - **HLE `oleaut32.dll` support**: - Allows `oleaut32.dll` in default `HostPolicy` so standard OLE Automation/BSTR imports (including ordinals `#4` `SysAllocStringLen` and `#6` `SysFreeString`) resolve to the host. ## Verification - `cargo clippy --workspace --all-targets` — passed (zero new warnings) - `cargo clippy -p victory --features diagnostics --all-targets` — passed - `cargo test --workspace` — passed (including new tests for page-end emulation, C++ rethrow/`ThrowInfo` guards, idempotent `report_crashes`/stack guarantee, `GUARD_CF` stripping, forwarded/cyclic export resolution, read-only `_tls_index` patching, and `oleaut32` ordinals) - `cargo xtask policy` — passed (151 files ok)
jeremygold02 commented 2026-11-24 06:55:57 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by jeremygold02 on 2026-11-24T05:08:28Z.


Thanks @wbkepler for the broad hardening across the loader’s exception handling, PE preparation, TLS, export resolution, and HLE API lookup.

I tested commit 6269b57090f44a54be9b4b861f2e83b13a20ae73 with:

cargo test --locked -p victory-loader --lib -- --test-threads=1
cargo test --locked -p victory-hle --lib -- --test-threads=1

Both library suites passed: 25 loader tests and 87 HLE tests, with 0 failures.

Representative coverage of the changed paths includes:

  • Crash handling: page-end bounds during instruction emulation, invalid/rethrown exception records, and idempotent crash-handler setup with the stack guarantee.
  • PE preparation: IAT slots when the import-size field excludes its terminator, static TLS preparation, and stripping Guard CF/force-integrity flags.
  • TLS and exports: read-only TLS-index pages have their protection restored; export resolution covers direct, forwarded, and cyclic exports.
  • HLE API lookup: oleaut32 ordinals resolve to the host.

This is unit-test coverage of the affected code paths. It does not launch a full title or validate the complete runtime integration with title binaries.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7122662152 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/216#issuecomment-7122662152). Originally posted by [jeremygold02](https://github.com/jeremygold02) on 2026-11-24T05:08:28Z. --- Thanks @wbkepler for the broad hardening across the loader’s exception handling, PE preparation, TLS, export resolution, and HLE API lookup. I tested commit `6269b57090f44a54be9b4b861f2e83b13a20ae73` with: ``` cargo test --locked -p victory-loader --lib -- --test-threads=1 cargo test --locked -p victory-hle --lib -- --test-threads=1 ``` Both library suites passed: 25 loader tests and 87 HLE tests, with 0 failures. Representative coverage of the changed paths includes: - [Crash handling](https://github.com/Marvisak/VIctory/blob/6269b57090f44a54be9b4b861f2e83b13a20ae73/crates/victory-loader/src/crash.rs#L934): page-end bounds during instruction emulation, invalid/rethrown exception records, and idempotent crash-handler setup with the stack guarantee. - [PE preparation](https://github.com/Marvisak/VIctory/blob/6269b57090f44a54be9b4b861f2e83b13a20ae73/crates/victory-loader/src/prepare.rs#L210): IAT slots when the import-size field excludes its terminator, static TLS preparation, and stripping Guard CF/force-integrity flags. - [TLS and exports](https://github.com/Marvisak/VIctory/blob/6269b57090f44a54be9b4b861f2e83b13a20ae73/crates/victory-loader/src/tls.rs#L251): read-only TLS-index pages have their protection restored; [export resolution](https://github.com/Marvisak/VIctory/blob/6269b57090f44a54be9b4b861f2e83b13a20ae73/crates/victory-loader/src/windows.rs#L586) covers direct, forwarded, and cyclic exports. - [HLE API lookup](https://github.com/Marvisak/VIctory/blob/6269b57090f44a54be9b4b861f2e83b13a20ae73/crates/victory-hle/src/lib.rs#L112): `oleaut32` ordinals resolve to the host. This is unit-test coverage of the affected code paths. It does not launch a full title or validate the complete runtime integration with title binaries.
wbkepler commented 2026-11-24 21:03:35 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by wbkepler on 2026-11-24T20:37:53Z.


Rebased onto current main (ffe310e) as 58e267e; the only conflict was in the crash.rs tests (kept both the upstream page-end test and this PR's tests), no code redesign. Gate (clippy -D warnings, tests, policy) clean.

AI-assisted (Claude Code); checked on Windows 11 / RTX 5090.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7143843338 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/216#issuecomment-7143843338). Originally posted by [wbkepler](https://github.com/wbkepler) on 2026-11-24T20:37:53Z. --- Rebased onto current main (`ffe310e`) as `58e267e`; the only conflict was in the crash.rs tests (kept both the upstream page-end test and this PR's tests), no code redesign. Gate (clippy -D warnings, tests, policy) clean. _AI-assisted (Claude Code); checked on Windows 11 / RTX 5090._
Marvisak commented 2026-11-25 01:07:41 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:20:56Z.


Automated triage for the maintainers.

Needs rebase. This PR does not merge cleanly into current main (ac2525d). Conflicting files: crates/victory-loader/src/crash.rs.

The content has not been reviewed yet; it will be once the branch is rebased onto main.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148415319 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/216#issuecomment-7148415319). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:20:56Z. --- <!-- victory-triage v1 head=58e267e23054c1918cc1d04ae1c9c57c190a4a2f verdict=needs-rebase at=2026-11-25T00:13:20Z --> Automated triage for the maintainers. **Needs rebase.** This PR does not merge cleanly into current `main` (ac2525d). Conflicting files: `crates/victory-loader/src/crash.rs`. The content has not been reviewed yet; it will be once the branch is rebased onto `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/216:upstream-pr/216'
git switch 'upstream-pr/216'

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.

git switch 'main'
git merge --no-ff 'upstream-pr/216'
git switch 'upstream-pr/216'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/216'
git switch 'upstream-pr/216'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/216'
git switch 'main'
git merge --squash 'upstream-pr/216'
git switch 'main'
git merge --ff-only 'upstream-pr/216'
git switch 'main'
git merge 'upstream-pr/216'
git push origin 'main'
Sign in to join this conversation.
No reviewers
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!216
No description provided.