startup: refuse null and unknown handles in XDspDeactivate and XDspDisconnect #2253

Merged
roansystemlabs merged 1 commit from upstream-pr/2261 into main 2026-11-25 08:56:15 +00:00
roansystemlabs commented 2026-11-25 08:37:40 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by roansystemlabs on 2026-11-25T08:37:40Z.


Part of #1887.

Change

XDspDeactivate and XDspDisconnect in the chad.dll stand-in returned 0 for any handle with X2W_AUDIO_PERMISSIVE=1, including a null handle (the row "0 for any handle" in #1887). They now refuse a null or unknown handle with E_INVALIDARG and return 0 only for the handle XDspConnectWithMaximumStreamLimit published, the same known-handle rule XDspSubmitCommand uses since #1907.

Neither export writes anything back to the caller: the stand-in reads only the first argument, the handle, so there is no output to clear and the change is the handle rule alone. The two reference pages are behind the developer program, so the handle-only signatures are the stand-in's assumption. Microsoft's error code list has no XDSP code for an invalid handle, so the refusal uses E_INVALIDARG, as #1907 does for submit. XDSP_E_NOT_ALL_HANDLES_DEACTIVATED cannot arise: activation never publishes a stream.

src/startup_stubs/chad.cpp:

  • a shared release_handle() keeps the existing accept() call first, so the strict trap path and the first-six-calls x2w-audio record are unchanged, then checks the handle and logs -> E_INVALIDARG (unknown handle) or -> 0;
  • XDspActivate, XDspSubmitCommand and XDspConnectWithMaximumStreamLimit are unchanged, so #1871's out-handle checks and #1907's failure paths stand.

docs/startup-runtime.md: one sentence added to the X2W_AUDIO_PERMISSIVE=1 row of the switches table.

No change to the permissive switch, to xapu.dll or AcpHal.dll, or to the counters in #2107. The 16-byte second argument of XApuConnect is the next PR under the same reservation.

The stop reported in #1887 after #2242 has xapu.dll on the stack; this PR touches only chad.dll and does not address it. I did not run an application.

Verification

Base main at 540a9615 (includes #2242). Windows 11 build 26200, MSVC 19.44.35230 x64, CMake presets release and dev.

cmake --preset release
cmake --build --preset release --target startup_stub_chad startup_chad_check
ctest --preset release --no-tests=error -R '^startup_chad_check$' -V
startup_chad_check: ok
100% tests passed, 0 tests failed out of 1

The audio-side startup tests, Release and Debug, with the stand-ins and fixtures they need built first:

ctest --preset release --no-tests=error -R '^(startup_(chad_check|xapu_queue|acphal_apu_free|audio_(output|pacing|provider|timeline)|stubs))$'
100% tests passed, 0 tests failed out of 8
ctest --preset dev --no-tests=error -R '^(startup_(chad_check|xapu_queue|acphal_apu_free|audio_(output|pacing|provider|timeline)|stubs))$'
100% tests passed, 0 tests failed out of 8

tests/startup_chad_check.cpp keeps the two known-handle assertions for these exports (now labelled as such) and adds the refusal cases:

case expected
XDspDeactivate(null handle) E_INVALIDARG
XDspDeactivate(unknown handle) E_INVALIDARG
XDspDisconnect(null handle) E_INVALIDARG
XDspDisconnect(unknown handle) E_INVALIDARG
synthetic caller deactivating the stream a failed XDspActivate cleared not 0
XDspDeactivate(known handle), XDspDisconnect(known handle) 0
permissive log XDspDeactivate handle=0x0 -> E_INVALIDARG and XDspDisconnect handle=0x0 -> E_INVALIDARG present

The strict trap children for both exports (0xE2570202, 0xE2570203) are unchanged and pass.

Evidence and follow-up

Fail-first: the new test against the chad.cpp on main (Release) reports 6 failures, the four refusals, the synthetic caller and the log line.

Negative controls, each rebuilt into chad.dll (timestamp checked) and reverted:

mutation result
XDspDeactivate back to return accept(...) (the old behaviour) caught, 4 failures
XDspDisconnect back to return accept(...) caught, 3 failures
refuse only a null handle, accept any other caught, 2 failures (the unknown-handle cases)
refuse every handle, the known one included caught, 2 failures (the known-handle cases)

No new fixture: the existing source-built startup_chad_check gains the cases above. Not run: the pr preset smoke list (it does not include startup_chad_check), Wine, and any application input. Not established: what a real caller passes to these two exports, or audible output. The stand-in keeps no state: as with submit, the known handle is the one connect published (there is no stream), and releasing it twice still returns 0.

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed.
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6600503692 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2261). Originally posted by [roansystemlabs](https://github.com/roansystemlabs) on 2026-11-25T08:37:40Z. --- Part of #1887. ## Change `XDspDeactivate` and `XDspDisconnect` in the `chad.dll` stand-in returned 0 for any handle with `X2W_AUDIO_PERMISSIVE=1`, including a null handle (the row "0 for any handle" in #1887). They now refuse a null or unknown handle with `E_INVALIDARG` and return 0 only for the handle `XDspConnectWithMaximumStreamLimit` published, the same known-handle rule `XDspSubmitCommand` uses since #1907. Neither export writes anything back to the caller: the stand-in reads only the first argument, the handle, so there is no output to clear and the change is the handle rule alone. The two reference pages are behind the developer program, so the handle-only signatures are the stand-in's assumption. [Microsoft's error code list](https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/errorcodes?view=gdk-2604#xdsp) has no XDSP code for an invalid handle, so the refusal uses `E_INVALIDARG`, as #1907 does for submit. `XDSP_E_NOT_ALL_HANDLES_DEACTIVATED` cannot arise: activation never publishes a stream. `src/startup_stubs/chad.cpp`: - a shared `release_handle()` keeps the existing `accept()` call first, so the strict trap path and the first-six-calls `x2w-audio` record are unchanged, then checks the handle and logs `-> E_INVALIDARG (unknown handle)` or `-> 0`; - `XDspActivate`, `XDspSubmitCommand` and `XDspConnectWithMaximumStreamLimit` are unchanged, so #1871's out-handle checks and #1907's failure paths stand. `docs/startup-runtime.md`: one sentence added to the `X2W_AUDIO_PERMISSIVE=1` row of the switches table. No change to the permissive switch, to `xapu.dll` or `AcpHal.dll`, or to the counters in #2107. The 16-byte second argument of `XApuConnect` is the next PR under the same reservation. The stop reported in #1887 after #2242 has `xapu.dll` on the stack; this PR touches only `chad.dll` and does not address it. I did not run an application. ## Verification Base `main` at 540a9615 (includes #2242). Windows 11 build 26200, MSVC 19.44.35230 x64, CMake presets `release` and `dev`. ```powershell cmake --preset release cmake --build --preset release --target startup_stub_chad startup_chad_check ctest --preset release --no-tests=error -R '^startup_chad_check$' -V startup_chad_check: ok 100% tests passed, 0 tests failed out of 1 ``` The audio-side startup tests, Release and Debug, with the stand-ins and fixtures they need built first: ```powershell ctest --preset release --no-tests=error -R '^(startup_(chad_check|xapu_queue|acphal_apu_free|audio_(output|pacing|provider|timeline)|stubs))$' 100% tests passed, 0 tests failed out of 8 ctest --preset dev --no-tests=error -R '^(startup_(chad_check|xapu_queue|acphal_apu_free|audio_(output|pacing|provider|timeline)|stubs))$' 100% tests passed, 0 tests failed out of 8 ``` `tests/startup_chad_check.cpp` keeps the two known-handle assertions for these exports (now labelled as such) and adds the refusal cases: | case | expected | |---|---| | `XDspDeactivate(null handle)` | `E_INVALIDARG` | | `XDspDeactivate(unknown handle)` | `E_INVALIDARG` | | `XDspDisconnect(null handle)` | `E_INVALIDARG` | | `XDspDisconnect(unknown handle)` | `E_INVALIDARG` | | synthetic caller deactivating the stream a failed `XDspActivate` cleared | not 0 | | `XDspDeactivate(known handle)`, `XDspDisconnect(known handle)` | 0 | | permissive log | `XDspDeactivate handle=0x0 -> E_INVALIDARG` and `XDspDisconnect handle=0x0 -> E_INVALIDARG` present | The strict trap children for both exports (`0xE2570202`, `0xE2570203`) are unchanged and pass. ## Evidence and follow-up Fail-first: the new test against the `chad.cpp` on `main` (Release) reports 6 failures, the four refusals, the synthetic caller and the log line. Negative controls, each rebuilt into `chad.dll` (timestamp checked) and reverted: | mutation | result | |---|---| | `XDspDeactivate` back to `return accept(...)` (the old behaviour) | caught, 4 failures | | `XDspDisconnect` back to `return accept(...)` | caught, 3 failures | | refuse only a null handle, accept any other | caught, 2 failures (the unknown-handle cases) | | refuse every handle, the known one included | caught, 2 failures (the known-handle cases) | No new fixture: the existing source-built `startup_chad_check` gains the cases above. Not run: the `pr` preset smoke list (it does not include `startup_chad_check`), Wine, and any application input. Not established: what a real caller passes to these two exports, or audible output. The stand-in keeps no state: as with submit, the known handle is the one connect published (there is no stream), and releasing it twice still returns 0. ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture. - [x] I updated README/docs when a capability or build requirement changed. - [x] I did not include game files, dumps, distribution links or secrets. AI-assisted.
upstream-sync closed this pull request 2026-11-25 09:04:06 +00:00
tedin7 commented 2026-11-25 09:04:06 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T08:40:55Z.

Review: COMMENTED


Review of head a1b55da1d4e60ea67601b0a0cb8160ea99be2402 (comment only).

Scope: src/startup_stubs/chad.cpp, tests/startup_chad_check.cpp, docs/startup-runtime.md (3 files, +41/-6). Mergeable, title neutral, body starts with Part of #1887.

Commands run locally:

  • git diff --check origin/main...HEAD: clean
  • python3 tests/docs_links_check.py: 18 files, 429 links OK
  • python3 tests/bidi_controls_check.py: 1544 files, no bidi controls
  • python3 x2w_pipe.py win2025 2261 --targets startup_chad_check,startup_stub_chad --regex startup_chad --skip-release: build OK, startup_chad_check 1/1 passed (Win2025, MSVC 14.44, dev preset)
  • Mutation: in release_handle() (chad.cpp:40) replaced != &connection with == nullptr, ran the same Win2025 command with --patch: startup_chad_check FAILED with FAIL: XDspDeactivate(unknown handle) -> E_INVALIDARG and FAIL: XDspDisconnect(unknown handle) -> E_INVALIDARG. The new tests kill it. Worktree reverted afterwards.
  • CI at review time: Linux Python checks pass; the two Windows jobs were still pending. I did not run the /O2 or release configs.

Findings:

  • P1: none.
  • P2: none.
  • Nit (chad.cpp:40): &connection is a static, so it is "known" even before XDspConnectWithMaximumStreamLimit published it, and after a later disconnect. XDspSubmitCommand (line 114) uses the same rule, so this is consistent and fine for the stand-in. A one-line comment saying that the handle is never un-published would remove the doubt.
  • Nit (tests): the new log assertion covers handle 0x0 only. Unknown-handle log text is exercised only through the mutation run above. Optional.

What I checked and found correct:

  • accept() still runs first, so the strict trap path and the first-six-calls x2w-audio record are unchanged.
  • Known handle still returns 0. Null and handle+4 return E_INVALIDARG (0x80070057), matching the #1907 submit convention.
  • The "failed activation cleared the stream out-pointer, then caller deactivates it" case is covered and refused.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6054289011 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2261#pullrequestreview-6054289011). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T08:40:55Z. **Review:** COMMENTED --- Review of head `a1b55da1d4e60ea67601b0a0cb8160ea99be2402` (comment only). Scope: `src/startup_stubs/chad.cpp`, `tests/startup_chad_check.cpp`, `docs/startup-runtime.md` (3 files, +41/-6). Mergeable, title neutral, body starts with `Part of #1887`. Commands run locally: - `git diff --check origin/main...HEAD`: clean - `python3 tests/docs_links_check.py`: 18 files, 429 links OK - `python3 tests/bidi_controls_check.py`: 1544 files, no bidi controls - `python3 x2w_pipe.py win2025 2261 --targets startup_chad_check,startup_stub_chad --regex startup_chad --skip-release`: build OK, `startup_chad_check` 1/1 passed (Win2025, MSVC 14.44, dev preset) - Mutation: in `release_handle()` (chad.cpp:40) replaced `!= &connection` with `== nullptr`, ran the same Win2025 command with `--patch`: `startup_chad_check` FAILED with `FAIL: XDspDeactivate(unknown handle) -> E_INVALIDARG` and `FAIL: XDspDisconnect(unknown handle) -> E_INVALIDARG`. The new tests kill it. Worktree reverted afterwards. - CI at review time: Linux Python checks pass; the two Windows jobs were still pending. I did not run the `/O2` or release configs. Findings: - P1: none. - P2: none. - Nit (chad.cpp:40): `&connection` is a static, so it is "known" even before `XDspConnectWithMaximumStreamLimit` published it, and after a later disconnect. `XDspSubmitCommand` (line 114) uses the same rule, so this is consistent and fine for the stand-in. A one-line comment saying that the handle is never un-published would remove the doubt. - Nit (tests): the new log assertion covers handle `0x0` only. Unknown-handle log text is exercised only through the mutation run above. Optional. What I checked and found correct: - `accept()` still runs first, so the strict trap path and the first-six-calls `x2w-audio` record are unchanged. - Known handle still returns 0. Null and `handle+4` return `E_INVALIDARG` (0x80070057), matching the #1907 submit convention. - The "failed activation cleared the stream out-pointer, then caller deactivates it" case is covered and refused. AI-assisted; commands listed were executed locally.
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
R0Y00/Xbox2Windows!2253
No description provided.