startup-runtime: answer the gaming runtime locally when it cannot initialize (X2W_RUNTIME_LOCAL) #1846
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1853"
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 Leyukaka on 2026-11-24T19:38:11Z.
Change
The runtime proxy (
src/startup_stubs/runtime_proxy.cpp) wraps the system gaming runtime. UnderX2W_FAKE_USER, its local answers live on proxy objects that are created only after a successful realQueryApiImpl; the one exception is persistent local storage (f4faf4d4), which already gets a local object when the real query fails. When the system runtime cannot initialize, for example on a Windows host without Gaming Services,InitializeApiImpl*fails, the realQueryApiImplfails for the providers below, and none of their local answers is reachable.This adds an opt-in switch,
X2W_RUNTIME_LOCAL=1, effective only together withX2W_RUNTIME_PROXY=1andX2W_FAKE_USER=1:InitializeApiImpl,InitializeApiImplExandInitializeApiImplEx2are wrapped. The real export runs first; a success passes through unchanged. The first failure is logged once and answered withS_OK, and later initialization calls returnS_OKwithout the real export for the rest of the process.QueryApiImplfor the user (01acd177, gamertag interface included), game-save (704c3f58), package (af406016), title (973a344e), connectivity (37e56907) and store (0dd112ac) providers returns a local object with no runtime object behind it. The existing local answers apply; calls that carry the local user or store handle fail as before; any other method returnsE_NOTIMPL, logged once per provider and slot, instead of dereferencing a missing object.QueryInterfacereturns the same object (E_POINTERfor a null out pointer);AddRefandReleasereturn 1.XUserAddAsync(user slot 7), and the async blocks the stand-in already completes on behalf of a local answer (complete_async), complete withS_OKthrough the XAsync provider (073b7dcb). That path needs the realQueryApiImplto still return the XAsync provider; if it does not, orBeginfails, the call returns that failure.XUserAddResultalready returns the local user.GetProcAddressreturns the same pointers as before and every existing path is unchanged.The switch is documented in the
docs/startup-runtime.mdswitch table.Verification
On
b067a954(based onmainat8e2923ae), Windows 11 build 26300, MSVC 14.44.35207:Both pass.
tests/startup_runtime_local.cppincludesruntime_proxy.cppin-process with fake runtime exports (known return codes and call counts) and a fake XAsync service that invokes the caller's completion callback. It checks the switch-off behaviour, theX2W_FAKE_USERgate, the latch and its single log line, the provider allow-list, an unlisted provider, the null-object guard,XUserAddAsyncthrough toXUserAddResultin the completion callback, andcomplete_asyncfor a local user object.startup_runtime_local_controlruns the same binary with--control, which leaves the switch off where the test enables it; it must printFAIL:.Each of these edits to
runtime_proxy.cppwas applied one at a time; the test passed without them and failed or crashed under each:forward<N>disabled;XUserAddAsyncremoved;E_FAILinstead ofS_OK;X2W_FAKE_USERgate removed from the wrapper selection;QueryApiImplpath;complete_asyncremoved;E_POINTERfor a nullQueryInterfaceout pointer replaced byS_OK.The whole
ctest --preset dev --no-tests=error -R '^startup_' -j 8run passes 233 of 239 tests; four are skipped (startup_view_heap_warp,startup_logical_view_warp,startup_root_heap_warp,startup_root_heap_hardware). The two others,startup_list_resubmit_hardwareandstartup_list_resubmit_untracked_hardware, crash (SegFault, afterx2w-render list Close failed 0x80004005) on an NVIDIA GeForce RTX 5080, driver 32.0.16.2101, with the test'sX2W_D3D12_DEBUG=1; they crash the same way without this change (measured at813045b3), and their executable linksd3d12_xs_shim,d3d12anddxgi, none of which containsruntime_proxy.cpp. Their_warpvariants pass.Evidence and follow-up
tests/startup_runtime_local.cpp, MIT); it uses no title, package or runtime binary.Checklist
AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T19:44:56Z.
Review: CHANGES_REQUESTED
The fallback returns a vtable for an unknown IID. proxy_query matches only the provider GUID's Data1 and does not validate the requested IID, and the local QueryInterface returns the same object for every IID whenever the output pointer is writable. That lets a caller interpret one provider's slots as an unrelated interface and treats a GUID with the same prefix as a supported provider.
Please validate full provider and IID pairs for the local fallback, and only report IUnknown and the exact interfaces each local object implements from QueryInterface. Refuse an unknown IID without publishing an object. Add controls for a known provider with an unknown IID, a different provider GUID with the same Data1, and QueryInterface on a supported local object with an unknown IID. The existing known-provider success and fake-user-off checks should remain.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T19:45:06Z.
Review: COMMENTED
Review of
b067a954(based on8e2923ae;origin/mainis now8a61ae06). Comment only, not an approval.Verdict
Careful and well fenced (opt-in, three-way gate, latch, one log line per event). I found no P1. Two P2 points and two P3 notes below. Clean-room and title-neutral: provider ids are hex prefixes only and the fixture is source-built.
P2: the headline case is not exercised
The feature is for a host where the system runtime cannot initialize.
XUserAddAsync(andcomplete_asyncfor a local user) then needsreal_queryto still return the XAsync provider (073b7dcb), and the PR says so. The fixture supplies its own XAsync service, and the description admits what a real host does after a failed init is an assumption. If the XAsync provider lives in the same runtime that failed to initialize,local_user_addreturns the failure and the user never signs in, which is the case the switch exists for. I could not measure this. A short note indocs/startup-runtime.md(it says "must still return", not that this was seen on a host without Gaming Services) or a measurement on such a host would settle it.P2: QueryInterface on a local user object ignores the iid
In
forward<0>for a local object,QueryInterfacestoresselffor any iid and returns S_OK. For the user provider, the gamertag interface (cef4fac0) is a separate proxy entry whose slot 3 isGetGamertag. AQueryInterfacefrom the local user object for that iid returns the user object, whose slot 3 isXUserDuplicateHandle(user_call, case 3). A caller would get a duplicate-handle answer where it expects a name. DirectQueryApiImplfor the gamertag interface is fine (the key is swapped), so this only affects the QI route. Either refuse unknown iids withE_NOINTERFACEor route the gamertag iid to its own local object. The fixture has no case for it (grep gamertag tests/startup_runtime_local.cppfinds nothing).P3: silent success paths (all logged once, none rejected)
InitializeApiImplEx*when only the plain one failed. Documented, and the latch is shared across the three exports.AddRef/Releasealways return 1, so a local object is never freed. Fine for a process-lifetime stand-in; worth a comment.proxy_queryreplacesproxies[index]whenrealchanges, as before, so a provider that succeeded earlier and fails later leaks the old proxy. Existing pattern, not new.Thread safety
local_activeis read withInterlockedCompareExchangeand set withInterlockedExchange, the log fires once, and the unanswered counters useInterlockedIncrement. Two threads can both call the real init and both fail before the latch is set; both then return S_OK, so the result is the same.real_init[k]is written without a lock inhooked_get_proc_addressbefore the wrapper is returned, which is the same pattern asreal_query. I found no data race that changes behaviour.Commands run (Linux)
git diff --check origin/main...HEAD: clean.python -B tests/docs_links_check.py: Self-test passed. Checked 18 Markdown files and 370 links.python -B tests/bidi_controls_check.py: Self-test passed. Checked 1325 tracked source, script and build/CI files: no bidirectional controls.x86_64-w64-mingw32-g++ -std=c++17 -Isrc tests/startup_runtime_local.cpp: does not build here.local_log.huses MSVC__try/__except, which this compiler does not accept, so I could not run the fixture or any mutation. Everything above about the C++ is from reading the diff, not from running it.Not run
startup_runtime_localandstartup_runtime_local_control(Windows/MSVC only), and the author's nine mutations. I did not check them and cannot confirm or dispute them.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-25T00:33:13Z.
Review: APPROVED
Reviewed the updated pair allowlist, QueryInterface boundaries, and the local fallback guards at
0bd04f44. The Windows Release fallback and control passed 2/2. The opt-in still requires an actual initialization failure and the real runtime remains the only XAsync provider.Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-24T23:27:14Z.
Pushed
0cd4978aand69d40272for the change request.Full pairs. The local fallback now compares the whole provider GUID and the whole IID against eight exact pairs: user, gamertag, both Store interfaces, connectivity, game save, title and package. The persistent-storage pair is a separate constant and keeps its fake-user gate. An unlisted pair keeps the real HRESULT and publishes nothing:
provider_countis unchanged. XAsync has no local answer.QueryInterface on a local object. It returns
S_OKforIID_IUnknownand for the IID the object was created for. Any other IID gives*out = nullptrandE_NOINTERFACE, logged once per object; a nulloutgivesE_POINTER. The two Store IIDs get separate local objects. The storage object follows the same rule.Gamertag (tedin7, P2).
QueryInterfaceon the local user object for the gamertag IID now returnsE_NOINTERFACE. A directQueryApiImplfor the exact gamertag pair still returns its own object.Outside the opt-in. A failed query's output is cleared only when fake user is on and the initialization failure is latched, and only if
outis writable. WithX2W_FAKE_USERoff, a failed real query returns exactly what the real query returned,*outincluded, for all nine pairs. With fake user on andX2W_RUNTIME_LOCALoff, the same holds except for the storage pair, which keeps its existing fake-user-only answer. The fixture asserts this in the switch-off and fake-user-off phases.Controls added to
startup_runtime_local:Data1, for the user and storage providers;QueryInterfacewith an IID other than the object's own on the user and storage objects (an unknown IID), the gamertag object (the user IID) and the first Store object (the second Store IID);QueryInterfaceon the user object.QueryInterfaceoutputs are preset to a sentinel before each checked call, and the fixture's real query leaves a non-null output on failure. The existing known-provider success checks, fake-user-off checks and--controlremain.Docs. The
X2W_RUNTIME_LOCALrow now states:QueryInterfacelimits;That last point is a requirement, not a measurement on a host without Gaming Services; I have not measured it (tedin7's first P2).
Tests (Windows 11, MSVC,
cmake --preset dev):Each mutation below makes
startup_runtime_localfail with the message shown:runtime_proxy.cppData1of provider and IIDstorage provider with matching Data1 returned a local objectQueryInterfaceaccepts any IIDgamertag QueryInterface did not refuse the user IIDunlisted provider did not keep the real failureswitch off activated the fallbackKnown limits, unchanged by this push:
area_call) is per provider, not per IID.Data1: the gamertag key swap and the user/save provider indices.AddRef/Releasereturn 1; local objects live for the process. This is now commented in the code.AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-25T00:28:48Z.
The full GUID/IID pairs and QueryInterface restrictions address the previous review. I also added a fallback boundary check for inaccessible query arguments: a real failure returns without dereferencing an unreadable GUID or publishing through an unwritable output. The Windows Release fixture and its control passed 2/2. The provider and XAsync service in this test are synthetic. This PR still only activates after a real initialization failure.