startup: refuse null and unknown handles in XDspDeactivate and XDspDisconnect #2253
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2261"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from R0Y00/Xbox2Windows. Originally posted by roansystemlabs on 2026-11-25T08:37:40Z.
Part of #1887.
Change
XDspDeactivateandXDspDisconnectin thechad.dllstand-in returned 0 for any handle withX2W_AUDIO_PERMISSIVE=1, including a null handle (the row "0 for any handle" in #1887). They now refuse a null or unknown handle withE_INVALIDARGand return 0 only for the handleXDspConnectWithMaximumStreamLimitpublished, the same known-handle ruleXDspSubmitCommanduses 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_DEACTIVATEDcannot arise: activation never publishes a stream.src/startup_stubs/chad.cpp:release_handle()keeps the existingaccept()call first, so the strict trap path and the first-six-callsx2w-audiorecord are unchanged, then checks the handle and logs-> E_INVALIDARG (unknown handle)or-> 0;XDspActivate,XDspSubmitCommandandXDspConnectWithMaximumStreamLimitare unchanged, so #1871's out-handle checks and #1907's failure paths stand.docs/startup-runtime.md: one sentence added to theX2W_AUDIO_PERMISSIVE=1row of the switches table.No change to the permissive switch, to
xapu.dllorAcpHal.dll, or to the counters in #2107. The 16-byte second argument ofXApuConnectis the next PR under the same reservation.The stop reported in #1887 after #2242 has
xapu.dllon the stack; this PR touches onlychad.dlland does not address it. I did not run an application.Verification
Base
mainat540a9615(includes #2242). Windows 11 build 26200, MSVC 19.44.35230 x64, CMake presetsreleaseanddev.The audio-side startup tests, Release and Debug, with the stand-ins and fixtures they need built first:
tests/startup_chad_check.cppkeeps the two known-handle assertions for these exports (now labelled as such) and adds the refusal cases:XDspDeactivate(null handle)E_INVALIDARGXDspDeactivate(unknown handle)E_INVALIDARGXDspDisconnect(null handle)E_INVALIDARGXDspDisconnect(unknown handle)E_INVALIDARGXDspActivateclearedXDspDeactivate(known handle),XDspDisconnect(known handle)XDspDeactivate handle=0x0 -> E_INVALIDARGandXDspDisconnect handle=0x0 -> E_INVALIDARGpresentThe strict trap children for both exports (
0xE2570202,0xE2570203) are unchanged and pass.Evidence and follow-up
Fail-first: the new test against the
chad.cpponmain(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:XDspDeactivateback toreturn accept(...)(the old behaviour)XDspDisconnectback toreturn accept(...)No new fixture: the existing source-built
startup_chad_checkgains the cases above. Not run: theprpreset smoke list (it does not includestartup_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
AI-assisted.
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 withPart of #1887.Commands run locally:
git diff --check origin/main...HEAD: cleanpython3 tests/docs_links_check.py: 18 files, 429 links OKpython3 tests/bidi_controls_check.py: 1544 files, no bidi controlspython3 x2w_pipe.py win2025 2261 --targets startup_chad_check,startup_stub_chad --regex startup_chad --skip-release: build OK,startup_chad_check1/1 passed (Win2025, MSVC 14.44, dev preset)release_handle()(chad.cpp:40) replaced!= &connectionwith== nullptr, ran the same Win2025 command with--patch:startup_chad_checkFAILED withFAIL: XDspDeactivate(unknown handle) -> E_INVALIDARGandFAIL: XDspDisconnect(unknown handle) -> E_INVALIDARG. The new tests kill it. Worktree reverted afterwards./O2or release configs.Findings:
&connectionis a static, so it is "known" even beforeXDspConnectWithMaximumStreamLimitpublished 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.0x0only. 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-callsx2w-audiorecord are unchanged.handle+4returnE_INVALIDARG(0x80070057), matching the #1907 submit convention.AI-assisted; commands listed were executed locally.