HLE: a title's ExitProcess is logged as its exit is #2885

Open
0xkn0wh3r3 wants to merge 2 commits from upstream-pr/2887 into main
0xkn0wh3r3 commented 2026-11-25 23:05:31 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by 0xkn0wh3r3 on 2026-11-25T23:05:31Z.


What

The title's exit, abort, terminate and TerminateProcess (of itself) go through exports of ours that log the call and its caller. ExitProcess was bound to the host's kernel32 one instead, so a title that ended the process that way left no log line.

It now has an HLE export that logs the code and the caller, then does what Windows' ExitProcess does. The other threads end and the title images get DLL_PROCESS_DETACH, through the loader's detach_all, the same step the CRT exit path runs from its exit table. Then the host's ExitProcess ends the process with the title's code. It deliberately doesn't go through the CRT's exit. That would run the exit table on the calling thread while the title's other threads are still alive, and an exit function that wants a lock another thread holds would hang there.

Where it came from

From DexNom's fork, DexNom/VIctory@570a941: the kernel module's ExitProcess and the resolver test. It logs with this tree's tracing::warn!(code, from, …) style, like exit here. Credited with Co-authored-by: DexNom. The detach step and the order test were added in review.

Tested

  • tests::exit_process_resolves_to_hle: ExitProcess from kernel32, kernelbase and the processthreads API set resolves to the HLE export. Without the export the test fails (left: Some(Host), right: Some(Hle)).
  • modules::kernel::tests::a_title_exit_process_detaches_then_ends_with_its_code: stand-ins for the two steps record that the title images detach before the exit, and that the exit gets the title's code. No process is spawned or ended.
  • cargo test -p victory-hle -p victory-loader --lib: all pass. Windows 11.
  • cargo clippy -p victory-hle -p victory-loader --all-targets -- -D warnings, with and without victory-hle/diagnostics: clean.

Not tested

  • Not run with the title, so I haven't checked whether it calls ExitProcess directly.
  • The detach itself isn't run in a test, because it ends every other thread of the process. It's the same detach_all the exit path already uses.
<!-- greyfinch-sync:Marvisak/VIctory:issue:6615571614 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2887). Originally posted by [0xkn0wh3r3](https://github.com/0xkn0wh3r3) on 2026-11-25T23:05:31Z. --- ## What The title's `exit`, `abort`, `terminate` and `TerminateProcess` (of itself) go through exports of ours that log the call and its caller. `ExitProcess` was bound to the host's kernel32 one instead, so a title that ended the process that way left no log line. It now has an HLE export that logs the code and the caller, then does what Windows' `ExitProcess` does. The other threads end and the title images get `DLL_PROCESS_DETACH`, through the loader's `detach_all`, the same step the CRT `exit` path runs from its exit table. Then the host's `ExitProcess` ends the process with the title's code. It deliberately doesn't go through the CRT's `exit`. That would run the exit table on the calling thread while the title's other threads are still alive, and an exit function that wants a lock another thread holds would hang there. ## Where it came from From DexNom's fork, [DexNom/VIctory@570a941](https://github.com/DexNom/VIctory/commit/570a941e9b4e945121c26eb30dfc10c126845207): the kernel module's `ExitProcess` and the resolver test. It logs with this tree's `tracing::warn!(code, from, …)` style, like `exit` here. Credited with `Co-authored-by: DexNom`. The detach step and the order test were added in review. ## Tested - `tests::exit_process_resolves_to_hle`: `ExitProcess` from kernel32, kernelbase and the processthreads API set resolves to the HLE export. Without the export the test fails (`left: Some(Host), right: Some(Hle)`). - `modules::kernel::tests::a_title_exit_process_detaches_then_ends_with_its_code`: stand-ins for the two steps record that the title images detach before the exit, and that the exit gets the title's code. No process is spawned or ended. - `cargo test -p victory-hle -p victory-loader --lib`: all pass. Windows 11. - `cargo clippy -p victory-hle -p victory-loader --all-targets -- -D warnings`, with and without `victory-hle/diagnostics`: clean. ## Not tested - Not run with the title, so I haven't checked whether it calls `ExitProcess` directly. - The detach itself isn't run in a test, because it ends every other thread of the process. It's the same `detach_all` the `exit` path already uses.
fuzeofficlal commented 2026-11-25 23:31:30 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T23:31:30Z.

Review: COMMENTED


Verified head 13422588 cleanly merged onto origin/main (842b0cb7) on Windows 11 x64.

Code Review

  • Intercepting ExitProcess in crates/victory-hle/src/modules/kernel.rs logs both the raw u32 exit code and host::callers() before forwarding directly to Win32 ExitProcess(code) (avoiding CRT exit() / atexit lock hazards when a title exits with other threads active).
  • The child-process test (a_title_exit_process_ends_as_windows_does_with_its_code) is properly gated behind VICTORY_TEST_EXIT_PROCESS_CHILD with --exact and a 30s timeout safeguard (completes in ~0.5s locally) and validates high-bit exit code preservation (0x8765_4321).

Local Verification

  • cargo test --locked -p victory-hle: 154/154 unit tests passed (including tests::exit_process_resolves_to_hle and modules::kernel::tests::a_title_exit_process_ends_as_windows_does_with_its_code), plus fidelityfx (1/1) and no_dll_planting (1/1).
  • cargo clippy --locked -p victory-hle --all-targets -- -D warnings (default and --all-features): clean.
  • cargo xtask policy: 191 files ok.

Looks clean and ready to merge.

<!-- greyfinch-sync:Marvisak/VIctory:review:6066445497 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2887#pullrequestreview-6066445497). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-25T23:31:30Z. **Review:** COMMENTED --- Verified head `13422588` cleanly merged onto `origin/main` (`842b0cb7`) on Windows 11 x64. ### Code Review - Intercepting `ExitProcess` in `crates/victory-hle/src/modules/kernel.rs` logs both the raw `u32` exit code and `host::callers()` before forwarding directly to Win32 `ExitProcess(code)` (avoiding CRT `exit()` / `atexit` lock hazards when a title exits with other threads active). - The child-process test (`a_title_exit_process_ends_as_windows_does_with_its_code`) is properly gated behind `VICTORY_TEST_EXIT_PROCESS_CHILD` with `--exact` and a 30s timeout safeguard (completes in ~0.5s locally) and validates high-bit exit code preservation (`0x8765_4321`). ### Local Verification - `cargo test --locked -p victory-hle`: **154/154** unit tests passed (including `tests::exit_process_resolves_to_hle` and `modules::kernel::tests::a_title_exit_process_ends_as_windows_does_with_its_code`), plus `fidelityfx` (1/1) and `no_dll_planting` (1/1). - `cargo clippy --locked -p victory-hle --all-targets -- -D warnings` (default and `--all-features`): clean. - `cargo xtask policy`: `191 files ok`. Looks clean and ready to merge.
kotekompotek commented 2026-11-25 23:35:44 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T23:35:44Z.

Review: COMMENTED


Right: the title's ExitProcess was bound to the host's silently, losing the exit diagnostic — and deliberately calling host::exit_process rather than CRT exit avoids the exit-table hang when other threads hold locks (Windows itself kills threads before running atexit). The resolver test pins HLE provenance for all three spellings. LGTM.

<!-- greyfinch-sync:Marvisak/VIctory:review:6066484932 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2887#pullrequestreview-6066484932). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-25T23:35:44Z. **Review:** COMMENTED --- Right: the title's ExitProcess was bound to the host's silently, losing the exit diagnostic — and deliberately calling host::exit_process rather than CRT exit avoids the exit-table hang when other threads hold locks (Windows itself kills threads before running atexit). The resolver test pins HLE provenance for all three spellings. LGTM.
cloph-dsp commented 2026-11-26 00:03:21 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by cloph-dsp on 2026-11-25T23:16:16Z.


Local verification on Windows / rustc 1.100.0 / MSVC, no game data, no GPU, no clippy/rustup.

  • git diff --check against merge-base 842b0cb is clean; 2 files, +97/-0.
  • Negative control: both new test names are absent from the base commit.
  • cargo test --locked -p victory-hle --lib -- tests::exit_process_resolves_to_hle --exact --quiet -> 1 passed.
  • cargo test --locked -p victory-hle --lib -- modules::kernel::tests::a_title_exit_process_ends_as_windows_does_with_its_code --exact --quiet -> 1 passed (the child-process test completed in 0.06 s; no hang).
  • Full cargo test --locked -p victory-hle --quiet -> 154 passed, 0 failed, plus doctests.
  • Only a pre-existing deprecation warning in victory-hle/xmem.rs.

AI-assisted (Hy4 flash).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7177340099 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2887#issuecomment-7177340099). Originally posted by [cloph-dsp](https://github.com/cloph-dsp) on 2026-11-25T23:16:16Z. --- Local verification on Windows / rustc 1.100.0 / MSVC, no game data, no GPU, no clippy/rustup. - `git diff --check` against merge-base 842b0cb is clean; 2 files, +97/-0. - Negative control: both new test names are absent from the base commit. - `cargo test --locked -p victory-hle --lib -- tests::exit_process_resolves_to_hle --exact --quiet` -> 1 passed. - `cargo test --locked -p victory-hle --lib -- modules::kernel::tests::a_title_exit_process_ends_as_windows_does_with_its_code --exact --quiet` -> 1 passed (the child-process test completed in 0.06 s; no hang). - Full `cargo test --locked -p victory-hle --quiet` -> 154 passed, 0 failed, plus doctests. - Only a pre-existing deprecation warning in victory-hle/xmem.rs. AI-assisted (Hy4 flash).
Marvisak commented 2026-11-26 05:04:11 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-26T04:27:30Z.


Automated triage for the maintainers.

Thanks for ebd1d10; both points are addressed. The HLE ExitProcess (victory-hle/src/modules/kernel.rs) now logs, then runs the loader's detach_all through the new victory_loader::detach_for_exit_process. That ends the other threads and sends DLL_PROCESS_DETACH to the title images, then the host's ExitProcess ends the process. This follows the documented Windows order and runs no exit table. detach_all clears attached first, so a later run through the CRT's atexit does nothing. The new test checks the order with stand-ins and spawns no process.

CI: passing.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7182612574 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2887#issuecomment-7182612574). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-26T04:27:30Z. --- <!-- victory-triage v1 head=ebd1d10efc464aadcf02c3bc579cb07f6bef99ed verdict=merge-candidate at=2026-11-26T07:23:21Z --> Automated triage for the maintainers. Thanks for `ebd1d10`; both points are addressed. The HLE `ExitProcess` (`victory-hle/src/modules/kernel.rs`) now logs, then runs the loader's `detach_all` through the new `victory_loader::detach_for_exit_process`. That ends the other threads and sends `DLL_PROCESS_DETACH` to the title images, then the host's `ExitProcess` ends the process. This follows the documented Windows order and runs no exit table. `detach_all` clears `attached` first, so a later run through the CRT's `atexit` does nothing. The new test checks the order with stand-ins and spawns no process. CI: passing. --- _Generated by [Claude Code](https://claude.ai/code)_
0xkn0wh3r3 commented 2026-11-26 07:01:57 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by 0xkn0wh3r3 on 2026-11-26T07:00:15Z.


Both points addressed in ebd1d10:

  • Detach: the comment was right to be questioned, and it now does the detach instead of being reworded. ExitProcess runs the loader's detach_all before the host's ExitProcess, exposed as victory_loader::detach_for_exit_process. As on Windows, the other threads end and the title images get DLL_PROCESS_DETACH, in the same order the exit path gives them; then the process ends with the title's code. Still no exit functions run.
  • Test: the child-process test is gone. a_title_exit_process_detaches_then_ends_with_its_code checks the steps with stand-ins (detach first, then exit with the title's code) without spawning or ending a process. The PR description is updated to match.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7184995731 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2887#issuecomment-7184995731). Originally posted by [0xkn0wh3r3](https://github.com/0xkn0wh3r3) on 2026-11-26T07:00:15Z. --- Both points addressed in ebd1d10: - **Detach:** the comment was right to be questioned, and it now does the detach instead of being reworded. `ExitProcess` runs the loader's `detach_all` before the host's `ExitProcess`, exposed as `victory_loader::detach_for_exit_process`. As on Windows, the other threads end and the title images get `DLL_PROCESS_DETACH`, in the same order the `exit` path gives them; then the process ends with the title's code. Still no exit functions run. - **Test:** the child-process test is gone. `a_title_exit_process_detaches_then_ends_with_its_code` checks the steps with stand-ins (detach first, then exit with the title's code) without spawning or ending a process. The PR description is updated to match.
Dukestar69 commented 2026-11-26 17:51:58 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T17:51:58Z.

Review: APPROVED


Reviewed and verified locally on Windows 11 x64:

  • cargo test -p victory-loader --lib threads:: -- --test-threads=1: 2 passed, 0 failed.
  • cargo test -p victory-hle --lib modules::kernel:: -- --test-threads=1: 6 passed, 0 failed (including a_title_exit_process_detaches_then_ends_with_its_code).
  • cargo clippy -p victory-loader -p victory-hle --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6078636841 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2887#pullrequestreview-6078636841). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T17:51:58Z. **Review:** APPROVED --- Reviewed and verified locally on Windows 11 x64: - `cargo test -p victory-loader --lib threads:: -- --test-threads=1`: 2 passed, 0 failed. - `cargo test -p victory-hle --lib modules::kernel:: -- --test-threads=1`: 6 passed, 0 failed (including `a_title_exit_process_detaches_then_ends_with_its_code`). - `cargo clippy -p victory-loader -p victory-hle --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
futurepro62 commented 2026-11-26 18:06:20 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by futurepro62 on 2026-11-26T18:06:20Z.


NVIDIA full-suite run, to go with the reports above by Dukestar69, cloph-dsp, since none of them names a GPU run. Tested exact head ebd1d10 (on its base 842b0cb).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (pinned), dxil.dll from Windows SDK 10.0.26100 (the loader's default), debug.
  • cargo build --workspace --locked, then cargo 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: 868 passed, 0 failed, 10 ignored.
  • The new tests ran and passed: exit_process_resolves_to_hle, a_title_exit_process_detaches_then_ends_with_its_code.
  • --skip leaves out tests that fail on main 63bcca4 on this card too, not because of this PR: heap_direct_texture_reads_mark_their_heap_index ends the victory-shader test process with 0xc0000005 (#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_views and the two stride_tests hit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317); gathers_at_a_level_match_the_hardware fails on lane 0 (#1744).

Not tested

  • AMD (the tests take the default adapter), a release build, the title (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7200058608 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2887#issuecomment-7200058608). Originally posted by [futurepro62](https://github.com/futurepro62) on 2026-11-26T18:06:20Z. --- NVIDIA full-suite run, to go with the reports above by Dukestar69, cloph-dsp, since none of them names a GPU run. Tested exact head `ebd1d10` (on its base `842b0cb`). **Tested** - NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (pinned), `dxil.dll` from Windows SDK 10.0.26100 (the loader's default), debug. - `cargo build --workspace --locked`, then `cargo 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`: **868 passed, 0 failed, 10 ignored**. - The new tests ran and passed: `exit_process_resolves_to_hle`, `a_title_exit_process_detaches_then_ends_with_its_code`. - `--skip` leaves out tests that fail on main `63bcca4` on this card too, not because of this PR: `heap_direct_texture_reads_mark_their_heap_index` ends the `victory-shader` test process with `0xc0000005` (#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_views` and the two `stride_tests` hit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317); `gathers_at_a_level_match_the_hardware` fails on lane 0 (#1744). **Not tested** - AMD (the tests take the default adapter), a release build, the title (test run only). **AI use** - Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
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/2887:upstream-pr/2887'
git switch 'upstream-pr/2887'

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/2887'
git switch 'upstream-pr/2887'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2887'
git switch 'upstream-pr/2887'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2887'
git switch 'main'
git merge --squash 'upstream-pr/2887'
git switch 'main'
git merge --ff-only 'upstream-pr/2887'
git switch 'main'
git merge 'upstream-pr/2887'
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!2885
No description provided.