Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/startup-runtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -1070,7 +1070,7 @@ ctest --preset dev --no-tests=error -R '^startup_trap_header(_prefix_control|_pr
| `X2W_PRESENT_SIGNATURE_EVERY=<n>` | in render mode, samples a coarse signature of the presented picture every `n` presents from the start, without a script request (`0` off). Unset, sampling starts, every 4 presents, only once a script with a `wait` asks for it: see [Waiting for the presented picture](#waiting-for-the-presented-picture) |
| `X2W_D3D12_DUMP_SURFACE=<bmp>` | writes the last presented surface |
| `X2W_DRAW_DUMP_FRAME=<n>`, `X2W_DRAW_DUMP_DIR` | Full-resolution RGB snapshots of single-sample RGBA8/BGRA8 UNORM or sRGB targets after translated draws. A later present writes completed queue-fenced copies. At most 48 copies are pending or written; a copy whose fence reports device removal (`UINT64_MAX`) is released unwritten and frees its slot (`src/startup_stubs/draw_dump_tracking.h`, `ctest --preset dev --no-tests=error -R '^startup_dump_fence_(removed_control_)?warp$' -V`; the control must fail). |
| `X2W_AUDIO_PERMISSIVE=1` | enables the audio stand-ins. Without a DSP provider, `XDspActivate` clears valid outputs and reports unavailable resources, and failed `XDspSubmitCommand` calls leave the sequence unchanged. |
| `X2W_AUDIO_PERMISSIVE=1` | enables the audio stand-ins. Without a DSP provider, `XDspActivate` clears valid outputs and reports unavailable resources, and failed `XDspSubmitCommand` calls leave the sequence unchanged. `XDspDeactivate` and `XDspDisconnect` refuse null and unknown handles with `E_INVALIDARG`. |
| `X2W_RUNTIME_PROXY=1` | proxies the gaming runtime and logs every call. Rewrites regular-IAT `GetProcAddress` and a direct `xgameruntime.dll!QueryApiImpl` import on the main EXE and on DLLs that share its directory (package helpers). Dynamic `QueryApiImpl` / `InitializeApiImpl*` are wrapped only when the provider module's basename is `xgameruntime.dll`. `LdrRegisterDllNotification` only flags that another scan is needed. A worker holds each matching module live while rewriting after linking. Loading a helper and immediately calling it can precede the scan. The enabled proxy stays loaded until process exit. Delay-import IAT slots are not rewritten. Skips this stand-in's own `GetProcAddress` IAT so the hook does not recurse (`src/startup_stubs/runtime_gpa_patch.h`, `ctest --preset dev --no-tests=error -R '^startup_runtime_gpa_patch(_name_only_control)?$'`, and the control must print `FAIL:`; Windows also runs `startup_runtime_proxy_scope` for a late-loaded helper through the real loader) |
| `X2W_FAKE_USER=1` | answers the user, gamertag and save APIs for one local user, and creates one offline store context for that user |
| `X2W_RUNTIME_LOCAL=1` | with `X2W_RUNTIME_PROXY` and `X2W_FAKE_USER`, for a host where the system gaming runtime cannot initialize (no Gaming Services). The first failed `InitializeApiImpl*` is reported as `S_OK`, and every later initialization call returns `S_OK` without calling the real export. Once initialization failure is latched, a failed real `QueryApiImpl` call can fall back only with an exact match of both GUIDs to a supported provider/interface pair for user (including gamertag), game save, package, title, connectivity or store. Persistent local storage uses its existing fake-user gate and requires its exact provider GUID and IID. Unmatched failed queries keep the real HRESULT. The proxy clears a writable output on failure only when fake user is enabled and the initialization failure is latched. A local object's `QueryInterface` accepts only `IID_IUnknown` and the IID it was created for. The local answers above apply, calls that carry the local user or store handle fail as before, and other unanswered methods return `E_NOTIMPL`. `XUserAddAsync` and async operations completed on behalf of a local answer require the real runtime's `QueryApiImpl` to return the XAsync provider (`073b7dcb`). Those operations complete with `S_OK` through XAsync, or return the query failure if XAsync is unavailable (`ctest --preset dev --no-tests=error -R '^startup_runtime_local(_control)?$'`, and the control must print `FAIL:`). |
Expand Down
23 changes: 20 additions & 3 deletions src/startup_stubs/chad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
// XDspConnectWithMaximumStreamLimit(queue memory, 0x60000, 30, 0x80, 1, &handle) -> 0 on success,
// E_POINTER when handle is null or unwritable.
// No stream is processed: activation and submission fail with the documented XDSP code instead of
// returning success with their outputs untouched (issue #1887).
// returning success with their outputs untouched, and deactivation and disconnection refuse null and
// unknown handles (issue #1887).
namespace {
using u64 = std::uint64_t;
constexpr long hr_ok = 0;
Expand All @@ -28,6 +29,22 @@ long accept(const char* name, unsigned index, u64 rcx, u64 rdx, u64 r8, u64 r9,
x2w_trap::record("x2w-audio", X2W_TRAP_MODULE, X2W_TRAP_MODULE_ID, name, index, rcx, rdx, r8, r9, return_address);
return hr_ok;
}

// XDspDeactivate(stream) and XDspDisconnect(client) take a handle and write nothing back. As in
// XDspSubmitCommand, only the handle XDspConnectWithMaximumStreamLimit published is known: a null or
// unknown handle is refused instead of being reported as released.
long release_handle(const char* name, unsigned index, u64 rcx, u64 rdx, u64 r8, u64 r9, void* return_address,
LONG& calls)
{
const long result = accept(name, index, rcx, rdx, r8, r9, return_address, calls);
if (reinterpret_cast<void*>(static_cast<std::uintptr_t>(rcx)) != &connection) {
x2w_local::logf("x2w-audio %s handle=0x%llx -> E_INVALIDARG (unknown handle)", name,
static_cast<unsigned long long>(rcx));
return hr_invalidarg;
}
x2w_local::logf("x2w-audio %s handle=0x%llx -> 0", name, static_cast<unsigned long long>(rcx));
return result;
}
} // namespace

extern "C" __declspec(noinline) long XDspActivate(u64 rcx, u64 rdx, u64 r8, u64 r9)
Expand Down Expand Up @@ -77,13 +94,13 @@ extern "C" __declspec(noinline) long XDspConnectWithMaximumStreamLimit(u64 rcx,
extern "C" __declspec(noinline) long XDspDeactivate(u64 rcx, u64 rdx, u64 r8, u64 r9)
{
static LONG calls;
return accept("XDspDeactivate", 2, rcx, rdx, r8, r9, _ReturnAddress(), calls);
return release_handle("XDspDeactivate", 2, rcx, rdx, r8, r9, _ReturnAddress(), calls);
}

extern "C" __declspec(noinline) long XDspDisconnect(u64 rcx, u64 rdx, u64 r8, u64 r9)
{
static LONG calls;
return accept("XDspDisconnect", 3, rcx, rdx, r8, r9, _ReturnAddress(), calls);
return release_handle("XDspDisconnect", 3, rcx, rdx, r8, r9, _ReturnAddress(), calls);
}

extern "C" __declspec(noinline) long XDspSubmitCommand(u64 rcx, u64 rdx, u64 r8, u64 r9)
Expand Down
22 changes: 20 additions & 2 deletions tests/startup_chad_check.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,23 @@ int main(int argc, char** argv)
submit(reinterpret_cast<u64>(handle), 0x1234, reinterpret_cast<u64>(&gated_sequence), 0);
check(gated_sequence == 0, "caller gated on activation success never submits");

check(deactivate(reinterpret_cast<u64>(handle), 0, 0, 0) == hr_ok, "XDspDeactivate returns S_OK");
check(disconnect(reinterpret_cast<u64>(handle), 0, 0, 0) == hr_ok, "XDspDisconnect returns S_OK");
// Deactivate and disconnect write nothing back; they refuse null and unknown handles instead of
// reporting them as released, and release only the handle connect published.
check(deactivate(0, 0, 0, 0) == hr_invalidarg, "XDspDeactivate(null handle) -> E_INVALIDARG");
check(deactivate(reinterpret_cast<u64>(handle) + 4, 0, 0, 0) == hr_invalidarg,
"XDspDeactivate(unknown handle) -> E_INVALIDARG");
check(disconnect(0, 0, 0, 0) == hr_invalidarg, "XDspDisconnect(null handle) -> E_INVALIDARG");
check(disconnect(reinterpret_cast<u64>(handle) + 4, 0, 0, 0) == hr_invalidarg,
"XDspDisconnect(unknown handle) -> E_INVALIDARG");

// Synthetic caller: teardown of the stream that the failed activation cleared is not reported as done.
stream_out = reinterpret_cast<void*>(0x2);
activate(0x11, 0x22, reinterpret_cast<u64>(&status_out), reinterpret_cast<u64>(&stream_out));
check(deactivate(reinterpret_cast<u64>(stream_out), 0, 0, 0) != hr_ok,
"caller deactivating the stream a failed activation cleared is refused");

check(deactivate(reinterpret_cast<u64>(handle), 0, 0, 0) == hr_ok, "XDspDeactivate(known handle) returns S_OK");
check(disconnect(reinterpret_cast<u64>(handle), 0, 0, 0) == hr_ok, "XDspDisconnect(known handle) returns S_OK");

if (!log_path.empty()) {
const std::string log_text = read_file_bytes(log_path.c_str());
Expand All @@ -243,6 +258,9 @@ int main(int argc, char** argv)
log_text.find("XDspDeactivate") != std::string::npos &&
log_text.find("XDspDisconnect") != std::string::npos,
"permissive lifecycle exports logged");
check(log_text.find("x2w-audio XDspDeactivate handle=0x0 -> E_INVALIDARG") != std::string::npos &&
log_text.find("x2w-audio XDspDisconnect handle=0x0 -> E_INVALIDARG") != std::string::npos,
"permissive deactivate and disconnect refusals logged");
DeleteFileW(log_path.c_str());
}

Expand Down
Loading