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

Open
opened 2026-11-24 13:31:17 +00:00 by davi713albano-coder · 3 comments
davi713albano-coder commented 2026-11-24 13:31:17 +00:00 (Migrated from github.com)
Contributor

Imported from Marvisak/VIctory. Originally posted by davi713albano-coder on 2026-11-24T13:31:17Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6582918301 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/issues/888). Originally posted by [davi713albano-coder](https://github.com/davi713albano-coder) on 2026-11-24T13:31:17Z. --- ### 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.
MichaelSmithAI commented 2026-11-24 14:04:50 +00:00 (Migrated from github.com)
Author
Contributor

Imported from Marvisak/VIctory. Originally posted by MichaelSmithAI on 2026-11-24T13:39:30Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7133147134 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/issues/888#issuecomment-7133147134). Originally posted by [MichaelSmithAI](https://github.com/MichaelSmithAI) on 2026-11-24T13:39:30Z. --- 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)
LAKSHYA-cmd-tech commented 2026-11-24 14:04:56 +00:00 (Migrated from github.com)
Author
Contributor

Imported from Marvisak/VIctory. Originally posted by LAKSHYA-cmd-tech on 2026-11-24T13:55:19Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7133538570 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/issues/888#issuecomment-7133538570). Originally posted by [LAKSHYA-cmd-tech](https://github.com/LAKSHYA-cmd-tech) on 2026-11-24T13:55:19Z. --- Verified and merged downstream in PR #28. Passing all 3 synthetic waiter tests on Windows 11.
Marvisak commented 2026-11-25 07:03:23 +00:00 (Migrated from github.com)
Author
Contributor

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T06:50:36Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7155215894 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/issues/888#issuecomment-7155215894). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T06:50:36Z. --- <!-- 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)_
Sign in to join this conversation.
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
Marvisak/VIctory#888
No description provided.