diff options
| author | Jadiac <jadiac@web.de> | 2026-11-23 16:30:34 +0100 |
|---|---|---|
| committer | Jadiac <jadiac@web.de> | 2026-11-23 16:45:35 +0100 |
| commit | e6515ea41d8ead3a7ece1307efa5002d8dd647fe (patch) | |
| tree | efb160d4dd532d17ca909c682baa78217db8dde3 /runtime/shims/xapu_chad.cpp | |
| parent | 5f47ed2b393f53be295138b5bd1832a43cbce952 (diff) | |
runtime: xapu.dll and chad.dll shims, connections that succeed with an empty result queue
The executable's ten APU and audio DSP imports (one call site each, four for XApuEnqueueCommand) now bind to runtime/shims/xapu_chad.cpp instead of the unimplemented thunk. Both connects return a handle; the APU connect also returns a zeroed shared buffer. Commands are accepted and dropped, the result count is 0 and dequeuing fails. xapu_chad_test calls all ten in the call-site shapes.
Diffstat (limited to 'runtime/shims/xapu_chad.cpp')
| -rw-r--r-- | runtime/shims/xapu_chad.cpp | 162 |
1 files changed, 162 insertions, 0 deletions
diff --git a/runtime/shims/xapu_chad.cpp b/runtime/shims/xapu_chad.cpp new file mode 100644 index 000000000..070aa2d1d --- /dev/null +++ b/runtime/shims/xapu_chad.cpp | |||
| @@ -0,0 +1,162 @@ | |||
| 1 | // xapu.dll and chad.dll: the console's audio processing unit (APU) and audio DSP command queues. No PC has either, | ||
| 2 | // so these give the title connections whose calls succeed, a zeroed shared buffer and an always-empty result queue: | ||
| 3 | // the audio the APU would render stays silent, and nothing the title submits is processed. | ||
| 4 | // | ||
| 5 | // Read from the executable's call sites (counts in docs/runtime_imports.md), statically, never run: | ||
| 6 | // XApuConnect(out24*, out16*, handle*) 1 site; success is SUCCEEDED(hr). The first qword of the 16-byte | ||
| 7 | // output is read later as the base of a CPU-visible buffer: per-stream | ||
| 8 | // input at base + slot * 0x280 and output at base + 0x14000 + | ||
| 9 | // slot * 0x1E00. The 24-byte output is never read. | ||
| 10 | // XApuEnqueueCommand(handle, cmd*, 0) 4 sites; the return value is never read. cmd's first dword is a type | ||
| 11 | // (1, 2 and 3 seen), the second a stream slot. | ||
| 12 | // XApuGetResultCount(handle, 0) 1 site; 0 skips the loop that dequeues. | ||
| 13 | // XApuDequeueResult(handle, out*) 1 site, called count times into a zeroed 0x50-byte local; a negative | ||
| 14 | // HRESULT ends the loop. | ||
| 15 | // XApuDisconnect(handle) 1 site; the return value is never read. | ||
| 16 | // XDspConnectWithMaximumStreamLimit(buffer, u32, u32, 0x80, 1, handle*) 1 site; success is a return of 0. The | ||
| 17 | // buffer comes from the title's XMemAlloc and stays the title's. | ||
| 18 | // XDspActivate(handle, ...4 more) 1 site; success is a return of 0, else the caller returns -1. | ||
| 19 | // XDspSubmitCommand(a, b) 1 site; success is a return of 0. | ||
| 20 | // XDspDeactivate, XDspDisconnect 1 site each, tail calls: the caller returns what they return. | ||
| 21 | // | ||
| 22 | // HYPOTHESIS: the shared buffer is 0x14000 + 128 * 0x1E00 bytes. 128 slots is what fits 0x14000 at the 0x280 input | ||
| 23 | // stride, and the DSP connect passes 0x80 as its stream limit; no call site shows a bound. The 16-byte output is | ||
| 24 | // written as {base, size}; only the base is measured. The result queue stays empty because no result layout is | ||
| 25 | // known beyond the first two dwords, so XApuDequeueResult returns E_FAIL (a negative HRESULT, which the caller | ||
| 26 | // handles) without writing. Every command is accepted with S_OK and dropped. | ||
| 27 | #include <windows.h> | ||
| 28 | #include <intrin.h> | ||
| 29 | |||
| 30 | #include <cstdint> | ||
| 31 | #include <cstring> | ||
| 32 | #include <mutex> | ||
| 33 | #include <set> | ||
| 34 | #include <string> | ||
| 35 | |||
| 36 | #include "shims.h" | ||
| 37 | #include "startup_trace.h" | ||
| 38 | |||
| 39 | namespace { | ||
| 40 | |||
| 41 | constexpr size_t kApuBufferSize = 0x14000 + 128 * 0x1E00; | ||
| 42 | |||
| 43 | struct ApuConnection { | ||
| 44 | void* buffer; | ||
| 45 | }; | ||
| 46 | |||
| 47 | struct DspConnection { | ||
| 48 | int unused; | ||
| 49 | }; | ||
| 50 | |||
| 51 | // gta6rt --trace FILE: the first call of each function and the first XApuEnqueueCommand of each command type, with | ||
| 52 | // the caller, so the first boot shows what the title sends without a line per call. | ||
| 53 | void note(const char* api, uint64_t value, const void* caller) { | ||
| 54 | if (!rt::startup_trace::enabled()) return; | ||
| 55 | static std::mutex mutex; | ||
| 56 | static std::set<std::pair<std::string, uint64_t>> seen; | ||
| 57 | { | ||
| 58 | const std::lock_guard lock(mutex); | ||
| 59 | if (!seen.insert({api, value}).second) return; | ||
| 60 | } | ||
| 61 | rt::startup_trace::event( | ||
| 62 | "audio_queue", std::string("\"api\":") + rt::startup_trace::quote(api) + | ||
| 63 | ",\"value\":" + rt::startup_trace::quote(rt::startup_trace::hex(value)) + ",\"caller\":" + | ||
| 64 | rt::startup_trace::quote(rt::startup_trace::where(reinterpret_cast<uint64_t>(caller)))); | ||
| 65 | } | ||
| 66 | |||
| 67 | HRESULT __stdcall XApuConnect(void* out24, void* out16, void** handle) { | ||
| 68 | note("XApuConnect", 0, _ReturnAddress()); | ||
| 69 | if (!handle) return E_INVALIDARG; | ||
| 70 | *handle = nullptr; | ||
| 71 | void* buffer = VirtualAlloc(nullptr, kApuBufferSize, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); // zeroed | ||
| 72 | if (!buffer) return E_OUTOFMEMORY; | ||
| 73 | if (out24) std::memset(out24, 0, 24); | ||
| 74 | if (out16) { | ||
| 75 | const uint64_t info[2] = {reinterpret_cast<uint64_t>(buffer), kApuBufferSize}; | ||
| 76 | std::memcpy(out16, info, sizeof info); | ||
| 77 | } | ||
| 78 | *handle = new ApuConnection{buffer}; | ||
| 79 | return S_OK; | ||
| 80 | } | ||
| 81 | |||
| 82 | HRESULT __stdcall XApuDisconnect(void* handle) { | ||
| 83 | note("XApuDisconnect", 0, _ReturnAddress()); | ||
| 84 | auto* c = static_cast<ApuConnection*>(handle); | ||
| 85 | if (!c) return E_INVALIDARG; | ||
| 86 | VirtualFree(c->buffer, 0, MEM_RELEASE); | ||
| 87 | delete c; | ||
| 88 | return S_OK; | ||
| 89 | } | ||
| 90 | |||
| 91 | HRESULT __stdcall XApuEnqueueCommand(void* handle, const uint32_t* command, uint64_t flags) { | ||
| 92 | note("XApuEnqueueCommand", command ? command[0] : ~0ull, _ReturnAddress()); | ||
| 93 | (void)flags; | ||
| 94 | return handle && command ? S_OK : E_INVALIDARG; | ||
| 95 | } | ||
| 96 | |||
| 97 | uint32_t __stdcall XApuGetResultCount(void* handle, uint64_t flags) { | ||
| 98 | note("XApuGetResultCount", 0, _ReturnAddress()); | ||
| 99 | (void)handle; | ||
| 100 | (void)flags; | ||
| 101 | return 0; | ||
| 102 | } | ||
| 103 | |||
| 104 | HRESULT __stdcall XApuDequeueResult(void* handle, void* result) { | ||
| 105 | note("XApuDequeueResult", 0, _ReturnAddress()); | ||
| 106 | (void)handle; | ||
| 107 | (void)result; | ||
| 108 | return E_FAIL; // the queue is always empty | ||
| 109 | } | ||
| 110 | |||
| 111 | HRESULT __stdcall XDspConnectWithMaximumStreamLimit(void* buffer, uint32_t a, uint32_t b, uint32_t max_streams, | ||
| 112 | uint32_t flags, void** handle) { | ||
| 113 | note("XDspConnectWithMaximumStreamLimit", max_streams, _ReturnAddress()); | ||
| 114 | (void)buffer; | ||
| 115 | (void)a; | ||
| 116 | (void)b; | ||
| 117 | (void)flags; | ||
| 118 | if (!handle) return E_INVALIDARG; | ||
| 119 | *handle = new DspConnection{}; | ||
| 120 | return S_OK; | ||
| 121 | } | ||
| 122 | |||
| 123 | HRESULT __stdcall XDspDisconnect(void* handle) { | ||
| 124 | note("XDspDisconnect", 0, _ReturnAddress()); | ||
| 125 | delete static_cast<DspConnection*>(handle); | ||
| 126 | return S_OK; | ||
| 127 | } | ||
| 128 | |||
| 129 | HRESULT __stdcall XDspActivate(void* handle, uint64_t, uint64_t, uint64_t, uint64_t) { | ||
| 130 | note("XDspActivate", 0, _ReturnAddress()); | ||
| 131 | return handle ? S_OK : E_INVALIDARG; | ||
| 132 | } | ||
| 133 | |||
| 134 | HRESULT __stdcall XDspDeactivate(void* handle, uint64_t, uint64_t, uint64_t) { | ||
| 135 | note("XDspDeactivate", 0, _ReturnAddress()); | ||
| 136 | (void)handle; | ||
| 137 | return S_OK; | ||
| 138 | } | ||
| 139 | |||
| 140 | // Which of the two arguments is the connection is not known (the wrapper swaps them), so neither is checked. | ||
| 141 | HRESULT __stdcall XDspSubmitCommand(void*, void*) { | ||
| 142 | note("XDspSubmitCommand", 0, _ReturnAddress()); | ||
| 143 | return S_OK; | ||
| 144 | } | ||
| 145 | |||
| 146 | } // namespace | ||
| 147 | |||
| 148 | SHIM_TABLE(xapu, | ||
| 149 | {"xapu.dll", "XApuConnect", reinterpret_cast<void*>(&XApuConnect)}, | ||
| 150 | {"xapu.dll", "XApuDequeueResult", reinterpret_cast<void*>(&XApuDequeueResult)}, | ||
| 151 | {"xapu.dll", "XApuDisconnect", reinterpret_cast<void*>(&XApuDisconnect)}, | ||
| 152 | {"xapu.dll", "XApuEnqueueCommand", reinterpret_cast<void*>(&XApuEnqueueCommand)}, | ||
| 153 | {"xapu.dll", "XApuGetResultCount", reinterpret_cast<void*>(&XApuGetResultCount)}, | ||
| 154 | ); | ||
| 155 | |||
| 156 | SHIM_TABLE(chad, | ||
| 157 | {"chad.dll", "XDspActivate", reinterpret_cast<void*>(&XDspActivate)}, | ||
| 158 | {"chad.dll", "XDspConnectWithMaximumStreamLimit", reinterpret_cast<void*>(&XDspConnectWithMaximumStreamLimit)}, | ||
| 159 | {"chad.dll", "XDspDeactivate", reinterpret_cast<void*>(&XDspDeactivate)}, | ||
| 160 | {"chad.dll", "XDspDisconnect", reinterpret_cast<void*>(&XDspDisconnect)}, | ||
| 161 | {"chad.dll", "XDspSubmitCommand", reinterpret_cast<void*>(&XDspSubmitCommand)}, | ||
| 162 | ); | ||