XAsync: a new block where a result was left behind begins a call #247

Merged
Maraco91 merged 1 commit from upstream-pr/247 into main 2026-11-25 00:10:21 +00:00
Maraco91 commented 2026-11-24 01:46:10 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Maraco91 on 2026-11-24T01:46:10Z.


What

After a title leaves one result unfetched, every later async call whose block lands on that address fails with E_INVALIDARG.

Calls are filed in CALLS by their block's address. A call that fails, or succeeds with nothing to fetch, is removed when it completes; one that succeeds with a result stays filed until XAsyncGetResult takes it. XAsyncBegin refuses a block if any call is filed under its address:

if block.is_null() || call(block).is_some() {
    return E_INVALIDARG;
}

A title that does not fetch a result (it only wanted the status, it gave up, its fetch failed with too small a buffer) and then frees the block leaves that entry behind for good. Blocks are small heap objects of one size, so the allocator hands the same address out again soon, and from then on a new, zeroed block there cannot begin any call: not the title's own providers', and not ours (finished_with/pending_with go through XAsyncBegin too, so users, saves, the store). The old call's provider never gets its cleanup either.

On the console the state of a call lives in the block's own system area, not in a table by address (as I remember the open-source implementation of this API: it refuses a block whose system area is not zero, and a zeroed block is always a new one). The same test works here: the block of a result left behind holds the result's size in that area, so it never reads zero.

XAsyncBegin now, when a call is filed under the block's address:

  • finished call and a zeroed block: ends the call left behind (its provider gets Cleanup) and begins the new one;
  • call still in flight: E_INVALIDARG, as before, whatever the block holds;
  • block still holding the result (not zeroed): E_INVALIDARG, as before.

I have not seen which results the title leaves unfetched (I have no game files).

Tested

Windows 11 Pro 10.0.26200, rustc 1.98.1 (x86_64-pc-windows-msvc), no game data, no GPU involved.

New unit test a_new_block_where_a_result_was_left_begins_a_call: a provider that completes with one byte to fetch and counts its cleanups.

  1. Control: beginning again on the block as the call left it is refused (E_INVALIDARG), no cleanup.
  2. The block is replaced by a zeroed one at the same address; a call through finished_with begins (S_OK), the call left behind got exactly one cleanup, and the new call's result (9) is fetched and the call ends.
  3. Control: a call that never completes, its block replaced by a zeroed one: beginning there is still refused.

Results:

  • main (d2a4bae) + the test only: cargo test -p victory-hle --lib a_new_block_where fails at step 2: left: -2147024809 (E_INVALIDARG), right: 0. Step 1 passes.
  • with the fix: cargo test -p victory-hle --lib: 87 passed, 0 failed (xasync: 6).
  • cargo clippy -p victory-hle --tests: nothing in xasync.rs. rustfmt --check: nothing in the lines changed (existing differences at pending_with and near it).
  • cargo xtask policy: 151 files ok.
  • Trial merges (git merge-tree) with the open PRs on this file, #114, #122, #132, #236 and #239: all clean. #122 and #236 are about a block reused while a call's work or completion is still on its way; this is the entry a fetched-never call leaves filed, which they do not touch.

Not tested: a title run.

AI-assisted (Claude Code); the tests above were run on the machine described.

🤖 Generated with Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:issue:6572721080 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/247). Originally posted by [Maraco91](https://github.com/Maraco91) on 2026-11-24T01:46:10Z. --- ## What After a title leaves one result unfetched, every later async call whose block lands on that address fails with `E_INVALIDARG`. Calls are filed in `CALLS` by their block's address. A call that fails, or succeeds with nothing to fetch, is removed when it completes; one that succeeds with a result stays filed until `XAsyncGetResult` takes it. `XAsyncBegin` refuses a block if any call is filed under its address: ```rust if block.is_null() || call(block).is_some() { return E_INVALIDARG; } ``` A title that does not fetch a result (it only wanted the status, it gave up, its fetch failed with too small a buffer) and then frees the block leaves that entry behind for good. Blocks are small heap objects of one size, so the allocator hands the same address out again soon, and from then on a new, zeroed block there cannot begin any call: not the title's own providers', and not ours (`finished_with`/`pending_with` go through `XAsyncBegin` too, so users, saves, the store). The old call's provider never gets its cleanup either. On the console the state of a call lives in the block's own system area, not in a table by address (as I remember the open-source implementation of this API: it refuses a block whose system area is not zero, and a zeroed block is always a new one). The same test works here: the block of a result left behind holds the result's size in that area, so it never reads zero. `XAsyncBegin` now, when a call is filed under the block's address: - finished call and a zeroed block: ends the call left behind (its provider gets `Cleanup`) and begins the new one; - call still in flight: `E_INVALIDARG`, as before, whatever the block holds; - block still holding the result (not zeroed): `E_INVALIDARG`, as before. I have not seen which results the title leaves unfetched (I have no game files). ## Tested Windows 11 Pro 10.0.26200, rustc 1.98.1 (`x86_64-pc-windows-msvc`), no game data, no GPU involved. New unit test `a_new_block_where_a_result_was_left_begins_a_call`: a provider that completes with one byte to fetch and counts its cleanups. 1. Control: beginning again on the block as the call left it is refused (`E_INVALIDARG`), no cleanup. 2. The block is replaced by a zeroed one at the same address; a call through `finished_with` begins (`S_OK`), the call left behind got exactly one cleanup, and the new call's result (9) is fetched and the call ends. 3. Control: a call that never completes, its block replaced by a zeroed one: beginning there is still refused. Results: - `main` (d2a4bae) + the test only: `cargo test -p victory-hle --lib a_new_block_where` **fails** at step 2: `left: -2147024809` (`E_INVALIDARG`), `right: 0`. Step 1 passes. - with the fix: `cargo test -p victory-hle --lib`: **87 passed, 0 failed** (xasync: 6). - `cargo clippy -p victory-hle --tests`: nothing in `xasync.rs`. `rustfmt --check`: nothing in the lines changed (existing differences at `pending_with` and near it). - `cargo xtask policy`: 151 files ok. - Trial merges (`git merge-tree`) with the open PRs on this file, #114, #122, #132, #236 and #239: all clean. #122 and #236 are about a block reused while a call's work or completion is still on its way; this is the entry a fetched-never call leaves filed, which they do not touch. Not tested: a title run. AI-assisted (Claude Code); the tests above were run on the machine described. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
jeremygold02 commented 2026-11-24 06:56:02 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by jeremygold02 on 2026-11-24T05:28:09Z.


Tested current PR head 5cff0007a525b83f5c69912d7a38f53c6dafcfef.

  • cargo test --locked -p victory-hle --lib xasync -- --test-threads=1: 6 passed. The new a_new_block_where_a_result_was_left_begins_a_call test covers the prior completed call whose result was never fetched, same-address reuse with a zeroed new block, preservation of a result-bearing block, and rejection while a call is still in flight. The same target also passed normal result completion, manual and pool callback dispatch, work-result return, and queued cancellation (XAsyncBegin logic, regression test).
  • git diff --check d2a4bae1f49533ef5cb512fd1b1ba1513f2e1989 HEAD: passed.

These are unit tests using synthetic providers and async blocks; they do not exercise a real title or runtime integration.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7122976208 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/247#issuecomment-7122976208). Originally posted by [jeremygold02](https://github.com/jeremygold02) on 2026-11-24T05:28:09Z. --- Tested current PR head `5cff0007a525b83f5c69912d7a38f53c6dafcfef`. - `cargo test --locked -p victory-hle --lib xasync -- --test-threads=1`: 6 passed. The new `a_new_block_where_a_result_was_left_begins_a_call` test covers the prior completed call whose result was never fetched, same-address reuse with a zeroed new block, preservation of a result-bearing block, and rejection while a call is still in flight. The same target also passed normal result completion, manual and pool callback dispatch, work-result return, and queued cancellation ([XAsyncBegin logic](https://github.com/Marvisak/VIctory/blob/5cff0007a525b83f5c69912d7a38f53c6dafcfef/crates/victory-hle/src/modules/xasync.rs#L509-L564), [regression test](https://github.com/Marvisak/VIctory/blob/5cff0007a525b83f5c69912d7a38f53c6dafcfef/crates/victory-hle/src/modules/xasync.rs#L1099-L1153)). - `git diff --check d2a4bae1f49533ef5cb512fd1b1ba1513f2e1989 HEAD`: passed. These are unit tests using synthetic providers and async blocks; they do not exercise a real title or runtime integration.
mercuryVM commented 2026-11-24 09:55:09 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T09:55:09Z.

Review: APPROVED


Tested 5cff000 on Windows 11, RTX 5070, MSVC: the workspace passes (196 outside victory-shader), including a_new_block_where_a_result_was_left_begins_a_call.

  • The failure mode is real. A completed call with an unfetched result stays in CALLS by address, and a fresh, zeroed block the allocator places at the same address can then never begin a call.
  • The test distinguishing "abandoned result" from "block in use" is sound. A finished call (done) whose block is all-zero again can only be a new block, because a block holding a result has its size word set. An in-flight call (!done) is always refused, as the test's last part shows.
  • release runs the left-behind call's cleanup, which was never run before.
  • This also merges cleanly with #114, which is in our fork. done still means "status published" there.

No issues found.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:review:6037073508 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/247#pullrequestreview-6037073508). Originally posted by [mercuryVM](https://github.com/mercuryVM) on 2026-11-24T09:55:09Z. **Review:** APPROVED --- Tested 5cff000 on Windows 11, RTX 5070, MSVC: the workspace passes (196 outside `victory-shader`), including `a_new_block_where_a_result_was_left_begins_a_call`. - The failure mode is real. A completed call with an unfetched result stays in `CALLS` by address, and a fresh, zeroed block the allocator places at the same address can then never begin a call. - The test distinguishing "abandoned result" from "block in use" is sound. A finished call (`done`) whose block is all-zero again can only be a new block, because a block holding a result has its size word set. An in-flight call (`!done`) is always refused, as the test's last part shows. - `release` runs the left-behind call's cleanup, which was never run before. - This also merges cleanly with #114, which is in our fork. `done` still means "status published" there. No issues found. AI-assisted (Claude Code).
upstream-sync closed this pull request 2026-11-25 01:03:11 +00:00
Sign in to join this conversation.
No reviewers
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!247
No description provided.