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

Open
github-bot wants to merge 2 commits from github-bot/gh-2887 into main AGit
Owner

@⁠0xkn0wh3r3 on GitHub · 2026-11-25 23:05 UTC · original
0xkn0wh3r3:hle/exit-process-logged-like-exit → main · +82 −1 · 4 files · 2 commits · open

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.
**@⁠0xkn0wh3r3** on GitHub · 2026-11-25 23:05 UTC · [original](https://github.com/Marvisak/VIctory/pull/2887) `0xkn0wh3r3:hle/exit-process-logged-like-exit` → `main` · +82 −1 · 4 files · 2 commits · open ## 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.
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, so a title ending the process that
way left no line saying so. It now has an export that logs the code and
the caller, then calls the host's ExitProcess with the title's code
(not the CRT's exit, whose exit table would run on the calling thread
while the title's other threads live).

Tests: exit_process_resolves_to_hle (kernel32, kernelbase and the
processthreads API set resolve to it) and
a_title_exit_process_ends_as_windows_does_with_its_code (a child process
holding a lock an atexit function wants, with another thread alive,
ends with the title's code).

From DexNom/VIctory@570a941e9b (the
kernel module's ExitProcess and both tests).

Co-authored-by: DexNom <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:16:45 +00:00
ExitProcess went straight to the host's: the other threads ended, but
the title images, which Windows' loader does not know, got no
DLL_PROCESS_DETACH. The CRT exit path gives them one (the loader's
detach_all, from its exit table). Windows' ExitProcess ends the other
threads and detaches every DLL before the process ends, so ExitProcess
now runs the loader's detach_all (victory_loader::detach_for_exit_process)
and then the host's ExitProcess with the title's code. It still runs
no exit function.

The test that spawned a child copy of the test binary is replaced by
a_title_exit_process_detaches_then_ends_with_its_code. Stand-ins for
the two steps check that the detach comes before the exit and that the
exit gets the title's code, without ending or spawning a process.
Author
Owner

@⁠cloph-dsp on GitHub · 2026-11-25 23:16 UTC · original

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

**@⁠cloph-dsp** on GitHub · 2026-11-25 23:16 UTC · [original](https://github.com/Marvisak/VIctory/pull/2887#issuecomment-7177340099) 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).
Author
Owner

@⁠Marvisak on GitHub · 2026-11-26 04:27 UTC · original · edited 2026-11-26 07:23 UTC

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

**@⁠Marvisak** on GitHub · 2026-11-26 04:27 UTC · [original](https://github.com/Marvisak/VIctory/pull/2887#issuecomment-7182612574) · edited 2026-11-26 07:23 UTC <!-- 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)_
Author
Owner

@⁠0xkn0wh3r3 on GitHub · 2026-11-26 07:00 UTC · original

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.
**@⁠0xkn0wh3r3** on GitHub · 2026-11-26 07:00 UTC · [original](https://github.com/Marvisak/VIctory/pull/2887#issuecomment-7184995731) 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.
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-25 23:31 UTC · original · reviewed

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.

**@⁠fuzeofficlal** on GitHub · 2026-11-25 23:31 UTC · [original](https://github.com/Marvisak/VIctory/pull/2887#pullrequestreview-6066445497) · **reviewed** 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.
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-25 23:35 UTC · original · reviewed

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.

**@⁠kotekompotek** on GitHub · 2026-11-25 23:35 UTC · [original](https://github.com/Marvisak/VIctory/pull/2887#pullrequestreview-6066484932) · **reviewed** 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.
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-26 17:51 UTC · original · approved these changes

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

**@⁠Dukestar69** on GitHub · 2026-11-26 17:51 UTC · [original](https://github.com/Marvisak/VIctory/pull/2887#pullrequestreview-6078636841) · **approved these changes** 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).
Author
Owner

@⁠futurepro62 on GitHub · 2026-11-26 18:06 UTC · original

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.
**@⁠futurepro62** on GitHub · 2026-11-26 18:06 UTC · [original](https://github.com/Marvisak/VIctory/pull/2887#issuecomment-7200058608) 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 can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2887/head:github-bot/gh-2887'
git switch 'github-bot/gh-2887'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2887'
git switch 'github-bot/gh-2887'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2887'
git switch 'github-bot/gh-2887'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2887'
git switch 'main'
git merge --squash 'github-bot/gh-2887'
git switch 'main'
git merge --ff-only 'github-bot/gh-2887'
git switch 'main'
git merge 'github-bot/gh-2887'
git push origin 'main'
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!2887
No description provided.