Skip to content

startup: refuse null and unknown handles in XDspDeactivate and XDspDisconnect - #2261

Merged
R0Y00 merged 1 commit into
R0Y00:mainfrom
roansystemlabs:runtime/1887-xdsp-deactivate-disconnect
Nov 25, 2026
Merged

R0Y00 merged 1 commit into
R0Y00:mainfrom
roansystemlabs:runtime/1887-xdsp-deactivate-disconnect

Conversation

@roansystemlabs

Copy link
Copy Markdown
Contributor

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:

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 540a961 (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.

@tedin7 tedin7 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@R0Y00
R0Y00 merged commit 1a713de into R0Y00:main Nov 25, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants