Loader: fix thread shutdown targeting, registry lifetime, and CRT detach ordering #1304
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1304"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from Marvisak/VIctory. Originally posted by geiyiliyabumo on 2026-11-24T17:17:36Z.
Summary
Audits \crates/victory-loader/src/threads.rs\ (with a minimal companion registration call in \windows.rs) and fixes real lifecycle/shutdown bugs:
Verification
AI-assisted; synthetic tests only, no game files.
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T02:34:35Z.
Automated triage for the maintainers.
This PR rewrites most of
crates/victory-loader/src/threads.rsand bundles several separate changes: earlieratexitregistration (register_process_detach, called fromLoadedImage::attachandspawn_main), load reference counting inmapped/unmapped, atomic per-image notice state, a reworkedend_other_threads/end_thread, andMaybeUninitTLS snapshots. The registration-order point is plausible: on main,attached()registersdetach_allonly after the firstDllMainreturns, so a handler the title registers with the host CRT during that attach runs after ours. But the bundle also changes exit behaviour.end_other_threadsnow returnsErrwhenOpenThreadfails for any reason other thanERROR_INVALID_PARAMETER(for example access denied), when the start address cannot be read on a live thread, or when the snapshot is short.detach_allthen callsend_process(), which skips every titleDLL_PROCESS_DETACH. On main, such threads are skipped and detach still runs. AfterTerminateThreadthe code also waits withINFINITEand relies on the watchdog.To move this forward, please split it: the
atexitordering fix as a small PR of its own, and the thread-ending and registry changes separately, each with a short note on the failure it fixes. Please also say whether title images actually register exit handlers in the host CRT's table rather than in their own (the new test assumes they do). No CI ran on this head.Generated by Claude Code
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.