Loader/HLE: run the process-detach notices when a title calls ExitProcess #837

Merged
CwWwWwW merged 1 commit from upstream-pr/837 into main 2026-11-29 08:16:58 +00:00
CwWwWwW commented 2026-11-28 07:34:38 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by CwWwWwW on 2026-11-28T07:34:38Z.


Ported to trustno1-coder/VIctory-NVIDIA from the same change submitted to fxceless/victory-fork as PR #1445 (head f8fb88249b, author CwWwWwW). The fork's own line was dropped when it rebased onto 959dcaf (5dbf5ce), so this is submitted here directly. The description below is the original one; its 'Verification' numbers refer to the fork tree. Rebased onto main 63b902f.

Problem

A title's ExitProcess import was bound to the host's ExitProcess, which ends the process without the loader's process-detach path. Title images are prepared with no entry point and no TLS callbacks, so the only way a title DLL hears DLL_PROCESS_DETACH (and its CRT atexit/flush/static destructors, and the exe's PROCESS_DETACH TLS notice) is victory_loader::threads::detach_all, registered on the host CRT's atexit. The host ExitProcess does not run CRT atexit: a normal exit path silently skipped every detach notice - a data-loss risk for anything flushed or released there.

Fix

  • victory-loader: make detach_all idempotent (an EXITING swap guard) and export it as threads::exit_notices.
  • victory-hle: export ExitProcess from kernel32, kernelbase and api-ms-win-core-processthreads; the override logs, runs exit_notices, then calls the host ExitProcess. TerminateProcess is unchanged (Windows sends no DLL notifications for it).

Tests and evidence

  • Regression: tests::exit_process_resolves_to_our_export classifies ExitProcess as Hle for the three DLLs; it fails before the change (Host).
  • Offline fixture harness (no game): a DLL with a DllMain marker and an export calling its imported ExitProcess; before: attach, quit-called, after: attach, quit-called, detach.
  • cargo test -p victory-hle --lib --locked: 104 passed; -p victory-loader --lib --locked: 28 passed; clippy clean for both.
  • 4 files changed (+59/-2).

Implemented independently from the target tree; no external code was copied. Based on main 9a9091d - it supersedes the old branch fix/exitprocess-detach, which was made on 4245f3.

The PR's Clippy check fails on main already: at 9a9091d cargo clippy --workspace --all-targets fails in victory-shader (wave64_after_loop.rs precedence, valu_tests.rs simplifiable/negated partial-ord comparisons); open PR #1440 fixes exactly those lints. This diff touches none of those files, and the touched crate's own tests and clippy are clean locally.

Verification on this tree (base 63b902f, 2026-11-27)

  • cargo check --workspace --all-targets --locked: pass (Rust 1.98.1, the version pinned in rust-toolchain.toml)
  • cargo check --workspace --all-targets --all-features --locked: pass
  • cargo clippy --workspace --all-targets --locked -- -D warnings (and --all-features): this change adds no clippy finding. The only failures are on unmodified lines of main (clippy::manual_is_multiple_of at crates/victory-gpu/src/shadow.rs:1708 and crates/victory-gpu/src/descriptor.rs:1234, clippy::let_and_return at crates/victory-shader/src/emit/mod.rs:2768); CI run 46104876336 on 63b902f failed on those before this change.
  • cargo test was not run in the author's environment (Windows VM without an MSVC toolchain; test binaries could not be linked there). CI on Windows and a run on the card should confirm.

Hardware verification suggested

  • This changes the exit path (DLL_PROCESS_DETACH and the exe TLS notice now run when a title calls ExitProcess, with a 5 s watchdog). Please try a normal quit and a crash quit.
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5537937122 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/837). Originally posted by [CwWwWwW](https://github.com/CwWwWwW) on 2026-11-28T07:34:38Z. --- Ported to trustno1-coder/VIctory-NVIDIA from the same change submitted to fxceless/victory-fork as PR #1445 (head f8fb88249b6f9ffb92bdc2e97cc7db532c640c60, author CwWwWwW). The fork's own line was dropped when it rebased onto 959dcaf (5dbf5ce), so this is submitted here directly. The description below is the original one; its 'Verification' numbers refer to the fork tree. Rebased onto main 63b902f. ## Problem A title's `ExitProcess` import was bound to the host's `ExitProcess`, which ends the process without the loader's process-detach path. Title images are prepared with no entry point and no TLS callbacks, so the only way a title DLL hears `DLL_PROCESS_DETACH` (and its CRT `atexit`/flush/static destructors, and the exe's `PROCESS_DETACH` TLS notice) is `victory_loader::threads::detach_all`, registered on the host CRT's `atexit`. The host `ExitProcess` does not run CRT `atexit`: a normal exit path silently skipped every detach notice - a data-loss risk for anything flushed or released there. ## Fix - `victory-loader`: make `detach_all` idempotent (an `EXITING` swap guard) and export it as `threads::exit_notices`. - `victory-hle`: export `ExitProcess` from `kernel32`, `kernelbase` and `api-ms-win-core-processthreads`; the override logs, runs `exit_notices`, then calls the host `ExitProcess`. `TerminateProcess` is unchanged (Windows sends no DLL notifications for it). ## Tests and evidence - Regression: `tests::exit_process_resolves_to_our_export` classifies `ExitProcess` as `Hle` for the three DLLs; it fails before the change (`Host`). - Offline fixture harness (no game): a DLL with a `DllMain` marker and an export calling its imported `ExitProcess`; before: `attach, quit-called`, after: `attach, quit-called, detach`. - `cargo test -p victory-hle --lib --locked`: 104 passed; `-p victory-loader --lib --locked`: 28 passed; clippy clean for both. - 4 files changed (+59/-2). Implemented independently from the target tree; no external code was copied. Based on main 9a9091d - it supersedes the old branch `fix/exitprocess-detach`, which was made on 4245f3. The PR's Clippy check fails on main already: at 9a9091d `cargo clippy --workspace --all-targets` fails in `victory-shader` (wave64_after_loop.rs precedence, valu_tests.rs simplifiable/negated partial-ord comparisons); open PR #1440 fixes exactly those lints. This diff touches none of those files, and the touched crate's own tests and clippy are clean locally. ## Verification on this tree (base 63b902f, 2026-11-27) - cargo check --workspace --all-targets --locked: pass (Rust 1.98.1, the version pinned in rust-toolchain.toml) - cargo check --workspace --all-targets --all-features --locked: pass - cargo clippy --workspace --all-targets --locked -- -D warnings (and --all-features): this change adds no clippy finding. The only failures are on unmodified lines of main (clippy::manual_is_multiple_of at crates/victory-gpu/src/shadow.rs:1708 and crates/victory-gpu/src/descriptor.rs:1234, clippy::let_and_return at crates/victory-shader/src/emit/mod.rs:2768); CI run 46104876336 on 63b902f failed on those before this change. - cargo test was not run in the author's environment (Windows VM without an MSVC toolchain; test binaries could not be linked there). CI on Windows and a run on the card should confirm. ## Hardware verification suggested - This changes the exit path (DLL_PROCESS_DETACH and the exe TLS notice now run when a title calls ExitProcess, with a 5 s watchdog). Please try a normal quit and a crash quit.
Dukestar69 commented 2026-11-28 07:48:09 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Dukestar69 on 2026-11-28T07:48:09Z.

Review: APPROVED


Tested locally merged onto main (63b902f).

  • Merge & Policy: Clean merge; cargo xtask policy passed (294 files ok).
  • Tests:
    • cargo test -p victory-loader --lib passed (45 passed; 0 failed, including threads::tests::exit_ends_the_other_threads_first and threads::tests::exit_child).
    • cargo test -p victory-hle --lib process passed (2 passed; 0 failed, including the new tests::exit_process_resolves_to_our_export test).
  • Compiled with 0 warnings.

Clean process-detach lifecycle wiring on ExitProcess. LGTM.

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

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:review:6096616054 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/837#pullrequestreview-6096616054). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-28T07:48:09Z. **Review:** APPROVED --- Tested locally merged onto `main` (`63b902f`). - **Merge & Policy**: Clean merge; `cargo xtask policy` passed (`294 files ok`). - **Tests**: - `cargo test -p victory-loader --lib` passed (`45 passed; 0 failed`, including `threads::tests::exit_ends_the_other_threads_first` and `threads::tests::exit_child`). - `cargo test -p victory-hle --lib process` passed (`2 passed; 0 failed`, including the new `tests::exit_process_resolves_to_our_export` test). - Compiled with 0 warnings. Clean process-detach lifecycle wiring on `ExitProcess`. LGTM. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
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
trustno1-coder/VIctory-NVIDIA!837
No description provided.