Repository navigation
Description
Static read of crates/xcl/src/hle/xgameruntime/xasync.rs on main (508a0c7), compared with libHttpClient Source/Task/AsyncLib.cpp (the contract the file's header names). It concerns XCL's own XAsync, not the PC runtime's (pc()).
Points 1–3 share one cause: the raw XAsyncBlock* is the task-queue callback context, and b.queue / b.callback are read again later. The reference passes a refcounted AsyncState as the context, and that state owns a queue handle duplicated at Begin.
-
A stale work item runs, and can complete, a later call on the same block (
xasync.rs:198-218, scheduled at:273)do_work_cbgets only the block address and callslookup(b), which returns whichever call is registered at that address now. Theidcheck inlookupdoes not help, because the item carries no id.- Trigger (manual work port):
XAsyncBegin(&b, P1)where P1 callsXAsyncSchedule;XAsyncComplete(&b, E_ABORT, 0);XAsyncBegin(&b, P2)where P2 never schedules;XTaskQueueDispatch(q, Work, 0). - Result: P2 receives
OP_DO_WORK, and since it returnsS_OKthe "finished synchronously" path at:211-216completes the second call. Expected: P2 gets no DoWork and staysE_PENDING. If the block was freed instead of reused,read_header(b)reads freed memory. - Reference:
WorkerCallbackreturns early onif (!state->valid). - Suggested fix: pass the
Arc<State>(Arc::into_raw) as the item's context, keep the block address inState, and return when that state is no longerPending.
-
Closing the queue handle during a call silently drops the completion callback (
xasync.rs:322, also:269)XAsyncCompleteresolves(*b).queuethroughtaskqueue::queue_fromat completion time, andqueue_fromaccepts only handles still inHANDLES. AfterXTaskQueueCloseHandle(q)it returnsNoneand theif let Some(q)skips the callback without an error.- Trigger:
XAsyncBegin(&b, ..)with a callback set;XTaskQueueCloseHandle(q);XAsyncComplete(&b, S_OK, 0). The callback never runs. Expected: it runs once on the completion port. - Reference:
XTaskQueueDuplicateHandleWithOptions(queue, Reference, &state->queue)at Begin, so the title may close its own handle. - Suggested fix: store
taskqueue::queue_from((*b).queue)inStateatXAsyncBegin/XAsyncRun, and use it inXAsyncScheduleandXAsyncComplete.
-
XAsyncGetStatus(b, true)returns before the completion callback has run (xasync.rs:338,:319-326,:220-226)- The waiter is released as soon as the status is published. The reference waiter waits for
waitSatisfied, which is set only after the callback returns. - A title that sets a callback and also waits can free a stack block while
completion_cb(b)is still queued. That item then reads(*b).callbackfrom dead memory. The comment above the snapshot inXAsyncCompletecoversXAsyncCompleteitself, but notcompletion_cb. - Trigger: manual completion port, block with a callback; thread A calls
XAsyncGetStatus(b, true);XAsyncComplete(b, S_OK, 4)with no dispatch. A returns at once. Expected: A blocks until the completion port is dispatched. - Suggested fix: give
completion_cbthe state, with the callback pointer snapshotted, and have the wait cover the callback. The paths with no callback, no queue or a refused submit must satisfy the wait themselves, otherwiseterminate_manual_completion_port_with_delayed_async_does_not_deadlockhangs.
- The waiter is released as soon as the status is published. The reference waiter waits for
-
XAsyncGetResultSizeleaves*sizeunwritten while pending and after a failed call (xasync.rs:357-359,:366), low severity- The reference writes it in every case:
*bufferSize = state == nullptr ? 0 : state->providerData.bufferSize;. - Suggested fix: write
*size = 0before returningE_PENDING, and drop&& h.status >= 0in theFinishedarm.
- The reference writes it in every case:
Each trigger can be a deterministic unit test in the file's mod tests (manual ports, a counter). Open PR #197 rewrites parts of the same functions without changing these behaviours, so a fix would conflict with it textually.
Not tested: nothing was built or run (read on Linux; no game files). The triggers are traced through the code by hand. Not checked: whether a retail title does any of this.
AI use: found and written with Claude Code (Claude Fable 5.2), static code review only, under human review.
Activity
WebIdentity1 commentedon Nov 24, 2026
Draft #641, head
8d0bbc8, addresses item 2 only by retaining the operation's queue. Native controls: 0/3 before, 3/0 after; XGameRuntime 76/0/0. Full four-thread workspace on base18c105a: 691 passed / 1 known CLAMP failure / 41 ignored, four explicit skips. No paired retail smoke; remains draft.Item 1 follow-up: reproduced and patched on a dependency integration
Top commit
06198fecontains only the stale-work fix, three tests and README change (105 additions / 4 deletions). Its parent86bbd00integrates maindd2ae9awith Michael-Glaser's #315 (04b8042) and #641 (8d0bbc8). This is a fork-only validation branch, not a competing implementation or a merge-ready PR. Separate #315 validation.Queued work now owns its original
Arc<State>and discards non-pending operations before reading their block; refused submission releases that reference. #315 is needed for accepted timer callbacks to be delivered during termination, and #641 retains the queue. The tests cover normal/canceled stale dispatch after block reuse, dispatch after a completed block's page becomes inaccessible, and immediate/delayed submission refusal.Tested
Windows 10 build 19045, Ryzen 7 7800X3D, RTX 3090 driver 591.74 and AMD integrated graphics driver 32.0.21030.2001, Rust 1.98.1 MSVC, SDK DXC 1.8.2502.11, Agility 1.620.2, debug.
cargo test --locked -p xcl --lib stale_queued_work_does_not_run_reused_block -- --test-threads=1 --show-output: 0 passed / 1 failed / 0 ignored, replacement provider wrongly invoked. The correspondingstale_queued_work_does_not_read_completed_blockfilter exited with access violation 0xc0000005 on an owned synthetic PAGE_NOACCESS page; no timeout. This is a crash reproduction, not a passing test.cargo test --locked -p xcl --lib queued_work -- --test-threads=1 --show-output: 3/0/0.hle::xgameruntime::filter: 81/0/0, no skips. These focused runs preceded adding the canceled-dispatch case to the reuse fixture.06198fe:cargo build --locked --workspacesucceeds;cargo test --locked --workspace --no-fail-fast -- --test-threads=4 --show-output: 697 passed / 1 failed / 41 ignored, no timeout. All three new tests pass, including canceled reuse. Onlygpu_clamp_and_omod_per_instructionfails, as previously reproduced on main. Presentation tests ran in desktop session 1;XCL_ADAPTER=3090, with some fixtures selecting AMD directly.gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware(no native wave64 on NVIDIA),test_title_draws_with_a_root_signature_under_the_debug_layer,uploads_start_from_each_subresources_state(debug layer unavailable). Sample variables unset; no installed system XGameRuntime.Not tested
Retail smoke/gameplay, release builds, Wine, installed PC runtime, or concurrent completion/disposal after work has already started. This does not fix item 3's completion callback/wait ordering or item 4. #197 overlaps the same functions and still needs reconciliation; not tested together. #235 fallback selection is separate.
AI use: Codex (GPT-6), public-source inspection, focused implementation, synthetic reproduction, native validation and this report. No proprietary inputs.
XGameRuntime: XAsync work items carry their call, and waits cover the…
XGameRuntime: retain an async operation's queue after handle close