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

Open
CwWwWwW wants to merge 1 commit from upstream-pr/1445 into main
CwWwWwW commented 2026-11-27 08:39:24 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by CwWwWwW on 2026-11-27T08:39:24Z.


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.

<!-- greyfinch-sync:fxceless/victory-fork:issue:5523689164 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1445). Originally posted by [CwWwWwW](https://github.com/CwWwWwW) on 2026-11-27T08:39:24Z. --- ## 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.
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/1445:upstream-pr/1445'
git switch 'upstream-pr/1445'

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