startup: return the shared buffer from XApuConnect #2280
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2288"
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 NiiRoZz on 2026-11-25T10:12:43Z.
Refs #1887, #1145.
In one title's calls, the caller of
XApuConnect(input*, output*, handle*)reads one pointer from output+0x00. Its later decode commands point into that buffer. The size comes from the 32-bit value at input+0x0C(0x104000in those calls). The permissive stand-in never wrote the pointer.#1887 reports a 160-byte copy to a null destination after the first typed result. In the same calls, each decode command copies a 160-byte packet. A local matched replay below reproduces that stop without this change and does not stop with it. I have not traced the copy instruction itself beyond the faulting call stack.
Change (
X2W_AUDIO_PERMISSIVE=1only)XApuConnectallocates a zeroed buffer of the requested size, writes its address to output+0x00and leaves output+0x08onward untouched.XApuDisconnectfrees the buffer.E_INVALIDARG). The cap guards against a bad size and is not a measured limit.E_POINTER). This is a defensive choice, not an observed contract.X2W_XAPU_TYPED_COMPLETIONS=1). The default and trap paths are unchanged.Tests
Windows 11 build 26300, MSVC Release, head
a854f21d(base342d3fa9):All passed. The new checks cover:
+0x00with+0x08onward untouched;Negative control: the same test executable against
xapu.dllbuilt from unmodified342d3fa9exits 1 with 6 failures. The first isFAIL: XApuConnect(null input) -> E_POINTER, followed by:XApuConnect writes the shared buffer to output +0 and leaves +8 alone;each connection gets its own shared buffer.Matched replay (local observation, one title, one run each)
Same machine (Windows 11 build 26300) and replay path. The only difference between the builds is
xapu.dll. Both runs usedX2W_AUDIO_PERMISSIVE=1andX2W_XAPU_TYPED_COMPLETIONS=1.xapu.dll342d3fa9(no buffer)S_OK0xC0000005. It is a write to address 0 insidevcruntime140.dll(memcpy), called from the title's audio decode path about 80 s after launch. No screen after the first.342d3fa9+ this PRS_OKXApuConnect ... buffer 0x... (0x104000 bytes), S_OK. No exception. The run then slowed and stalled at an early screen.The stall with typed completions looks like a separate decode contract. 23 of the first 24 logged commands were decodes (type 3) on one slot. My hypothesis is that a typed decode result reporting zero decoded bytes makes the caller request the next decode at once. Decoding stays unimplemented here and typed completions stay opt-in, so that is out of scope.
With typed completions unset, this PR also returned the buffer and raised no exception. That run shared the machine with other load and stalled at a later screen, so I don't attribute any timing to this change.
I'm not claiming anything audible. #2107 also touches
xapu.cppanddocs/startup-runtime.md; whichever lands second will need a merge.🤖 Generated with Claude Code
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T10:15:41Z.
Review: COMMENTED
Review of head
a854f21d74b3132ea5c18181b4883c573b2c076e.Scope:
XApuConnectnow allocates a zeroed buffer (size from input+0x0C), writes it to output+0x00, andXApuDisconnectfrees it. Permissive mode only.Commands run locally (Linux, in a worktree of the PR head):
git diff --stat origin/main...HEAD: 3 files, +68/-9 (docs,xapu.cpp,startup_xapu_queue_check.cpp).python3 tests/docs_links_check.py: self-test passed, 18 Markdown files and 435 links.python3 tests/bidi_controls_check.py: 1576 files, no bidirectional controls.git diff --check origin/main...HEAD: clean.git merge-treeof this head with current main: clean. Against open #2107 (also editsxapu.cpp,xapu.def,docs/startup-runtime.md): also clean, no textual conflict.gh pr checks: Linux Python checks pass; the Windows build/test jobs were still pending when I looked.Not run: the C++ test is Windows-only (
VirtualAlloc,xapu.dll), so I could not run it or do a logic mutation on Linux. I did not queue the Windows VM. The Windows CI jobs and the PR's own negative control are the evidence for the test.Findings
tests/startup_xapu_queue_check.cpp): no check covers thatXApuDisconnectreleases the buffer. A regression that drops theVirtualFree(src/startup_stubs/xapu.cpp, inXApuDisconnect) would leak up to 64 MiB per connection and no test would fail. A connect/disconnect loop that watches the private bytes or commit charge would guard it. Not blocking.src/startup_stubs/xapu.cpp,XApuConnect): the buffer pointer is written tordxonly after the connection is published and the lock is released. The handle is not yet returned to the caller at that point, so this is safe. A short comment would keep a later edit from moving the publish earlier.8131b6f9toa854f21d: hedged comments and docs, full-buffer zero check, null-pointer reset in the test). I re-read that delta and re-ran the docs and diff checks on the new head; no new findings.Overlap check: #2268 (merged) made typed completions opt-in, and this PR does not change that default. #2107 (open) adds XMA/XApu activity counters in the same files. There is no textual conflict, but whichever lands second should rebase and re-run the xapu CTest targets, because both touch
XApuConnect/XApuDisconnect.Clean-room and wording: title and body are neutral, with no private-source or local-probe references. The PR's claims are limited to what the diff does. The unverified decode-stall observation is clearly marked out of scope.
Correctness: the size bounds (0 and over 64 MiB give
E_INVALIDARG), the pointer checks (E_POINTERwith output untouched), the cleanup of the buffer when theConnectionallocation fails, and theVirtualAlloczero-fill all match the PR description.AI-assisted; commands listed were executed locally.
upstream-sync referenced this pull request2026-11-25 15:01:50 +00:00