HLE: wait for in-flight lifecycle callbacks on unregister #3272
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!3272
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3272"
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?
@fuzeofficlal on GitHub · 2026-11-26 15:21 UTC · original
fuzeofficlal:fix/hle-lifecycle-unregister-sync→main· +442 −47 · 1 files · 1 commits · openSummary
UnregisterAppStateChangeNotificationandUnregisterAppConstrainedChangeNotificationwithend_title/constrain_then_suspendso unregistering waits until any in-flight invocation of that registration on another thread has returned.CONSTRAINEDandROUTINESupfront inend_title; dispatch each phase from live registrations and re-check membership before every callback so routines unregistered mid-dispatch (including suspend routines unregistered during the constrained phase) are skipped.(id, ThreadId)invocations with an unwind-safe RAII guard so same-thread self-unregistration never deadlocks while another thread concurrently unregistering the same registration still waits until the callback returns, and unregistering unrelated or zero registrations does not block behind other active callbacks.*registrationbefore publishing the entry inNotifications::register.Root Cause
Under Windows Process State Manager (
api-ms-win-core-psm-appnotify-*), returning fromUnregisterAppStateChangeNotificationorUnregisterAppConstrainedChangeNotificationguarantees that the callback is neither executing on another thread nor will be invoked again, allowing the title to destroy the callback'scontextimmediately afterward.Previously,
end_titlecloned both callback vectors before spawning the suspend thread,constrain_then_suspenditerated those stale snapshots without re-checking registration state, and bothUnregister*exports only removed the entry from theVecand returned immediately. This left two use-after-free paths during shutdown/teardown:context.context.Verification
origin/main(63bcca43) before the fix (returned_early=true, saw_destroyed=trueandunregistered sibling constrained callback must not run).cargo test -p victory-hle --locked(155 unit + 2 integration tests passed)cargo test -p victory-hle --all-features --locked(passed)cargo clippy --workspace --all-targets --locked -- -D warnings(passed)cargo clippy --workspace --all-targets --all-features --locked -- -D warnings(passed)cargo test -p xtask --locked policy::tests::repository_passes_policy(passed)@Dukestar69 on GitHub · 2026-11-26 15:27 UTC · original · approved these changes
Reviewed the diff and verified locally on Windows 11 x64:
Notifications(Mutex+Condvar+ active(id, ThreadId)tracking), writing the registration handle before publishing, waiting for in-flight external callbacks onunregister, and avoiding self-deadlock on reentrant self-unregistration cleanly matches Windows PSM semantics.cargo test -p victory-hle --lib modules::lifecycle:: -- --test-threads=1: 15 passed, 0 failed (includingunregister_waits_for_in_flight_lifecycle_callbacks,unregister_skips_unstarted_sibling_and_suspend_callbacks, andself_unregister_does_not_deadlock_while_other_thread_waits_and_unrelated_returns).cargo clippy -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).
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.