HLE: wait for in-flight monitor callbacks in XTaskQueueUnregisterMonitor #2416

Manually merged
github merged 1 commit from github-bot/gh-2416 into main 2026-11-30 14:17:00 +00:00 AGit
Owner

@⁠fuzeofficlal on GitHub · 2026-11-29 12:51 UTC · original
fuzeofficlal:fix/hle-xtaskqueue-unregister-monitor-sync → main · +422 −11 · 1 files · 1 commits · merged 2026-11-30 14:12 UTC

Summary

Ported from Marvisak/VIctory#3263 (9659e3a726).

Queue::deliver previously cloned self.monitors out of the mutex and invoked callbacks without tracking active invocations, while XTaskQueueUnregisterMonitor only removed the token from the vector and returned immediately. Because callers may free a monitor's context as soon as XTaskQueueUnregisterMonitor returns, this left two UAF races (an in-flight callback on another thread, and a sibling monitor unregistered mid-notification still invoked from the stale snapshot), plus a token-publish race in XTaskQueueRegisterMonitor.

Changes

  • Replace Queue::monitors with Monitors { entries: Mutex<Vec<Monitor>>, done: Condvar } in crates/victory-hle/src/modules/xasync.rs:
    • notify() snapshots active tokens (zero-allocation fast path when empty), re-checks registration before each callback, and clears active thread frames via an unwind-safe Drop guard.
    • unregister() marks the entry removed, skips blocking on reentrant self-unregister (preventing single- and dual-thread self-deadlock), and otherwise blocks on Condvar until every in-flight invocation returns.
    • XTaskQueueRegisterMonitor writes *token before registering the entry under the mutex.
  • Add unregister_monitor_waits_for_in_flight_callbacks and unregister_monitor_skips_unstarted_siblings_and_handles_reentrant_self_unregister.

Verification

  • cargo test --locked -p victory-hle --lib modules::xasync:: (plus 5 consecutive stress runs of the new concurrency tests): all passing.
  • cargo test --locked -p victory-hle -- --test-threads=1: all passing.
  • cargo clippy --locked -p victory-hle --all-targets: 0 new warnings.
  • cargo xtask policy --staged: passed.
**@⁠fuzeofficlal** on GitHub · 2026-11-29 12:51 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2416) `fuzeofficlal:fix/hle-xtaskqueue-unregister-monitor-sync` → `main` · +422 −11 · 1 files · 1 commits · merged 2026-11-30 14:12 UTC ## Summary Ported from `Marvisak/VIctory#3263` (`9659e3a726`). `Queue::deliver` previously cloned `self.monitors` out of the mutex and invoked callbacks without tracking active invocations, while `XTaskQueueUnregisterMonitor` only removed the token from the vector and returned immediately. Because callers may free a monitor's context as soon as `XTaskQueueUnregisterMonitor` returns, this left two UAF races (an in-flight callback on another thread, and a sibling monitor unregistered mid-notification still invoked from the stale snapshot), plus a token-publish race in `XTaskQueueRegisterMonitor`. ## Changes - Replace `Queue::monitors` with `Monitors { entries: Mutex<Vec<Monitor>>, done: Condvar }` in `crates/victory-hle/src/modules/xasync.rs`: - `notify()` snapshots active tokens (zero-allocation fast path when empty), re-checks registration before each callback, and clears active thread frames via an unwind-safe `Drop` guard. - `unregister()` marks the entry removed, skips blocking on reentrant self-unregister (preventing single- and dual-thread self-deadlock), and otherwise blocks on `Condvar` until every in-flight invocation returns. - `XTaskQueueRegisterMonitor` writes `*token` before registering the entry under the mutex. - Add `unregister_monitor_waits_for_in_flight_callbacks` and `unregister_monitor_skips_unstarted_siblings_and_handles_reentrant_self_unregister`. ## Verification - `cargo test --locked -p victory-hle --lib modules::xasync::` (plus 5 consecutive stress runs of the new concurrency tests): all passing. - `cargo test --locked -p victory-hle -- --test-threads=1`: all passing. - `cargo clippy --locked -p victory-hle --all-targets`: 0 new warnings. - `cargo xtask policy --staged`: passed.
Ported from Marvisak/VIctory#3263 (9659e3a7265a49a792734d92cfa7917d1b98874d).

Track per-monitor removal and active calling ThreadIds behind Monitors
{ entries, done } so XTaskQueueUnregisterMonitor waits for any in-flight
invocation on another thread to return, skips sibling monitors unregistered
mid-notification, avoids self-deadlock on reentrant self-unregister, and
publishes *token before registering the monitor.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-29 12:54:56 +00:00
github manually merged commit 78ecc797bb into main 2026-11-30 14:17:00 +00:00
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/trustno1-coder--VIctory-NVIDIA!2416
No description provided.