HLE: implement XTaskQueueRegisterWaiter and XTaskQueueUnregisterWaiter slots (0xa0, 0xa8) #888

Open
opened 2026-11-26 04:14:07 +00:00 by github-bot · 3 comments
Owner

@⁠davi713albano-coder on GitHub · 2026-11-24 13:31 UTC · original

Summary

Implements the two missing XTaskQueue waiter vtable slots in crates/victory-hle/src/modules/xasync.rs:

  • Slot 20 (0xa0): XTaskQueueRegisterWaiter
  • Slot 21 (0xa8): XTaskQueueUnregisterWaiter

Because external PR creation is restricted (collaborators_only), the CI-green branch is ready on my fork:

Changes (crates/victory-hle/src/modules/xasync.rs)

  • Validates queue handle, port (WORK/COMPLETION), non-null/non-INVALID_HANDLE_VALUE wait handle, callback, output token, and terminated queue state (E_ABORT).
  • Duplicates the caller's Win32 handle (DuplicateHandle with DUPLICATE_SAME_ACCESS) so the wait stays valid if the caller closes their handle right after unregistering, and pairs it with a per-waiter manual-reset stop_event placed first in WaitForMultipleObjects.
  • Waits for each submitted callback to return before re-arming WaitForMultipleObjects, preventing manual-reset events from flooding the queue before the callback can reset the event or unregister itself.
  • Keeps a Weak<Queue> on the waiter thread (dropping the upgraded Arc<Queue> before waiting on callback completion) and cleans up waiters on XTaskQueueTerminate and Queue::drop, avoiding reference cycles and handle leaks.
  • Non-Windows builds stay clean (E_NOTIMPL).

Tests & Verification

Added 3 synthetic Windows unit tests in xasync::tests:

  • waiter_fires_on_signal_and_stops_after_unregister (exercises slots 0xa0/0xa8 with an auto-reset event across multiple signals and unregister)
  • manual_reset_waiter_rearms_only_after_callback_returns (verifies manual-reset re-arm semantics and safe unregistration from inside the callback itself)
  • waiter_validates_arguments_and_stops_on_terminate (argument validation, E_ABORT after terminate, clean shutdown)

Verified on GitHub Actions (windows-latest) using upstream ci.yml (cargo clippy --workspace --all-targets --locked -- -D warnings, --all-features, and cargo test --workspace --locked including xtask asset-policy check):

Not tested: live title execution.
No game data used. AI-assisted.

**@⁠davi713albano-coder** on GitHub · 2026-11-24 13:31 UTC · [original](https://github.com/Marvisak/VIctory/issues/888) ### Summary Implements the two missing `XTaskQueue` waiter vtable slots in `crates/victory-hle/src/modules/xasync.rs`: - **Slot `20` (`0xa0`)**: `XTaskQueueRegisterWaiter` - **Slot `21` (`0xa8`)**: `XTaskQueueUnregisterWaiter` Because external PR creation is restricted (`collaborators_only`), the CI-green branch is ready on my fork: - **Branch:** https://github.com/davi713albano-coder/VIctory/commits/hle/xasync-waiters - **Commit:** `a576445` (based on `main` `ffe310e`, `crates/victory-hle/src/modules/xasync.rs` +497/-2) - **Compare:** https://github.com/Marvisak/VIctory/compare/main...davi713albano-coder:hle/xasync-waiters ### Changes (`crates/victory-hle/src/modules/xasync.rs`) - Validates queue handle, port (`WORK`/`COMPLETION`), non-null/non-`INVALID_HANDLE_VALUE` wait handle, callback, output token, and terminated queue state (`E_ABORT`). - Duplicates the caller's Win32 handle (`DuplicateHandle` with `DUPLICATE_SAME_ACCESS`) so the wait stays valid if the caller closes their handle right after unregistering, and pairs it with a per-waiter manual-reset `stop_event` placed first in `WaitForMultipleObjects`. - Waits for each submitted callback to return before re-arming `WaitForMultipleObjects`, preventing manual-reset events from flooding the queue before the callback can reset the event or unregister itself. - Keeps a `Weak<Queue>` on the waiter thread (dropping the upgraded `Arc<Queue>` before waiting on callback completion) and cleans up waiters on `XTaskQueueTerminate` and `Queue::drop`, avoiding reference cycles and handle leaks. - Non-Windows builds stay clean (`E_NOTIMPL`). ### Tests & Verification Added 3 synthetic Windows unit tests in `xasync::tests`: - `waiter_fires_on_signal_and_stops_after_unregister` (exercises slots `0xa0`/`0xa8` with an auto-reset event across multiple signals and unregister) - `manual_reset_waiter_rearms_only_after_callback_returns` (verifies manual-reset re-arm semantics and safe unregistration from inside the callback itself) - `waiter_validates_arguments_and_stops_on_terminate` (argument validation, `E_ABORT` after terminate, clean shutdown) Verified on GitHub Actions (`windows-latest`) using upstream `ci.yml` (`cargo clippy --workspace --all-targets --locked -- -D warnings`, `--all-features`, and `cargo test --workspace --locked` including `xtask` asset-policy check): - `victory-hle`: 97 passed, 0 failed (full workspace: 345 passed, 0 failed, 6 ignored) - CI run: https://github.com/davi713albano-coder/VIctory/actions/runs/45402359529 **Not tested:** live title execution. No game data used. AI-assisted.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:14:07 +00:00
Author
Owner

@⁠MichaelSmithAI on GitHub · 2026-11-24 13:39 UTC · original

Melissa checked the interval after a waiter has queued its callback but before the title dispatches the manual completion port. On a576445 the test waited until exactly one entry was queued and the callback count was still zero. Unregistering and then dispatching produced zero callbacks. In a separate run, terminating the queue with the waiter still registered delivered one callback with canceled=true. All 11 focused Win64 xasync tests passed under Wine 11.22.

That establishes the behavior of this branch. The GDK unregister reference says callbacks cease after unregistration. Microsoft’s separate libHttpClient implementation invokes a dequeued callback before releasing its wait registration, so that code alone does not settle what retail xgameruntime does with an already-queued entry. A comparison on the native GDK runtime would resolve that remaining detail. GDK unregister reference · libHttpClient dispatch path

**@⁠MichaelSmithAI** on GitHub · 2026-11-24 13:39 UTC · [original](https://github.com/Marvisak/VIctory/issues/888#issuecomment-7133147134) Melissa checked the interval after a waiter has queued its callback but before the title dispatches the manual completion port. On a576445 the test waited until exactly one entry was queued and the callback count was still zero. Unregistering and then dispatching produced zero callbacks. In a separate run, terminating the queue with the waiter still registered delivered one callback with canceled=true. All 11 focused Win64 xasync tests passed under Wine 11.22. That establishes the behavior of this branch. The GDK unregister reference says callbacks cease after unregistration. Microsoft’s separate libHttpClient implementation invokes a dequeued callback before releasing its wait registration, so that code alone does not settle what retail xgameruntime does with an already-queued entry. A comparison on the native GDK runtime would resolve that remaining detail. [GDK unregister reference](https://learn.microsoft.com/en-us/xbox/gdk/docs/reference/system/xtaskqueue/functions/xtaskqueueunregisterwaiter?view=gdk-2604) · [libHttpClient dispatch path](https://github.com/microsoft/libHttpClient/blob/d940b02301f2ff1a4b3298766827d7d68f88e1f0/Source/Task/TaskQueue.cpp#L776-L814)
Author
Owner

@⁠LAKSHYA-cmd-tech on GitHub · 2026-11-24 13:55 UTC · original

Verified and merged downstream in PR #28. Passing all 3 synthetic waiter tests on Windows 11.

**@⁠LAKSHYA-cmd-tech** on GitHub · 2026-11-24 13:55 UTC · [original](https://github.com/Marvisak/VIctory/issues/888#issuecomment-7133538570) Verified and merged downstream in PR #28. Passing all 3 synthetic waiter tests on Windows 11.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 06:50 UTC · original

Automated triage for the maintainers.

Confirmed that these are unimplemented on current main: in crates/victory-hle/src/modules/xasync.rs the task-queue table still has missing::<20> (0xa0, register a wait handle) and missing::<21> (0xa8, unregister it). Open PR #1435 implements both. Pull requests are open to everyone now; if your branch a576445 differs from #1435 in a way that matters (for example the behaviour of an already-queued callback discussed above), please open it as a PR or comment there so review happens in one place.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 06:50 UTC · [original](https://github.com/Marvisak/VIctory/issues/888#issuecomment-7155215894) <!-- victory-issue-triage v1 verdict=confirmed seen=2026-11-24T13:55:19Z at=2026-11-25T06:50:35Z --> Automated triage for the maintainers. Confirmed that these are unimplemented on current `main`: in `crates/victory-hle/src/modules/xasync.rs` the task-queue table still has `missing::<20>` (0xa0, register a wait handle) and `missing::<21>` (0xa8, unregister it). Open PR #1435 implements both. Pull requests are open to everyone now; if your branch `a576445` differs from #1435 in a way that matters (for example the behaviour of an already-queued callback discussed above), please open it as a PR or comment there so review happens in one place. --- _Generated by [Claude Code](https://claude.ai/code)_
This discussion has been locked. Commenting is limited to contributors.
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/Marvisak--VIctory#888
No description provided.