Skip to content

xgameruntime: serve XNetworkingImpl offline through QueryApiImpl - #2169

Closed
Dom-in wants to merge 2 commits into
ItsNotRexed:mainfrom
Dom-in:xgameruntime-networking
Closed

Dom-in wants to merge 2 commits into
ItsNotRexed:mainfrom
Dom-in:xgameruntime-networking

Conversation

@Dom-in

@Dom-in Dom-in commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Claimed on #2078: #2078 (comment). A follow-up of #1877 (merged).

What and why

XCurl.dll asks QueryApiImpl for XNetworkingImpl (class 37e56907-…) with IXNetworkingImpl2's interface id (bf2346b2-…). It then calls slots 11–17, measured with the same thunk disassembly as #1877 (docs/runtime_imports.md, "Class layouts, measured"):

  • the UTF-16 URL security-information async trio;
  • XNetworkingVerifyServerCertificate;
  • XNetworkingGetConnectivityHint;
  • XNetworkingRegister/UnregisterConnectivityHintChanged.

QueryApiImpl refused the class, so every one of those calls failed with "class not provided" instead of the answer an offline console gives.

The change (runtime/shims/xgameruntime.cpp)

A 21-slot vtable: IUnknown, IXNetworkingImpl's 15 methods in the documented order, then IXNetworkingImpl2's 3. The signatures follow Microsoft's public XNetworking docs. It answers as a console with no network:

  • Connectivity hint: networkInitialized = true, level None (1), cost unknown, no data-limit or roaming flags.
  • Failing queries: the preferred-UDP-port query and the URL security-info queries (UTF-8 and UTF-16) fail with HRESULT_FROM_WIN32(ERROR_NETWORK_UNREACHABLE). The *Async ones start normally and complete their XAsyncBlock with that error through XAsyncRun, so a caller waiting on the block gets it; *ResultSize/*Result return it with zeroed outputs. VerifyServerCertificate fails the same way.
  • Change registrations: they return non-zero tokens whose callbacks never fire (nothing changes offline). Unregister returns true.
  • IXNetworkingImpl2 additions: configuration query/set and statistics return E_NOTIMPL.

RuntimeObject gains an optional newer interface id, so QueryInterface answers IXNetworkingImpl2 as well as the class id. The threading and error objects are unchanged.

Tests

  • xgameruntime_test: 8 new checks, 69 total. They cover both interface ids giving one object, the hint values, the slot-11 async call completing with no network (XAsyncGetStatus(…, true)) and slot 12's result size, slot 14, register/unregister via slots 16/17, the slot-3 port query, and slot 20 = E_NOTIMPL.
  • run_tiny_gdk_load: its refused-class check now uses an id no runtime class has, since XNetworkingImpl is served.
  • ctest -R "xgameruntime|tiny_gdk|loader": 6/6 on Windows 11 / MSVC.

Disclosure: written with an AI assistant (Claude Code). I reviewed it and ran the tests above.

🤖 Generated with Claude Code

@Dom-in

Dom-in commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

Further confirmation of the layout: libHttpClient.GDK.dll calls every XNetworkingImpl slot from 3 to 20 (18 thunks, same IXNetworkingImpl2 id), each in the argument shape of the documented method at that position. For example, 3: uint16*; 6/16: queue, context, callback, token pointer; 7/17: token and a bool; 10/13: five arguments; 18-20: an enum with a u64*, a u64, a pointer. So all 18 methods here are in the right slots, not only XCurl's 11-17.

@Flyander Flyander left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Slot 13 has an ABI mismatch that can corrupt the caller buffer. The documented result signature after the callback context is (XAsyncBlock*, size_t bufferByteCount, size_t* bufferByteCountUsed, uint8_t* buffer, XNetworkingSecurityInformation** information), but net_security_result currently orders the last three as buffer, information, used. See Microsoft's ANSI and UTF-16 contracts: https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/networking/xnetworking/functions/xnetworkingquerysecurityinformationforurlasyncresult?view=gdk-2604 and https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/networking/xnetworking/functions/xnetworkingquerysecurityinformationforurlutf16asyncresult?view=gdk-2510 .

With a conforming call that passes a non-null buffer and separate output pointers, the current body writes nullptr into the first pointer-sized bytes of the caller buffer, writes zero through the information output, and never initializes bufferByteCountUsed. This happens before XAsyncGetStatus returns the offline error. Please correct the thunk signature and test slot 13 with a sentinel buffer and distinct output values; slot 10 uses the same helper and needs the matching ANSI ABI too.

@itsonlysimbo

Copy link
Copy Markdown
Contributor

Tested e583b284 on RTX 4070, NVIDIA 621.14, Windows 11 (10.0.26300), MSVC 19.44, Vulkan SDK 1.4.363: pass.

AI-assisted (Claude Code).

@Dom-in

Dom-in commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

@Flyander thanks, you're right. Fixed in 14391ff: slots 10 and 13 now take (XAsyncBlock*, size_t bufferByteCount, size_t* bufferByteCountUsed, uint8_t* buffer, XNetworkingSecurityInformation** information), in the order of the two reference pages. The test calls both slots with a 0xA5 sentinel buffer and distinct output values. The buffer stays untouched, and used and information are zeroed where they are. Negative control: with the old helper, both checks fail. xgameruntime_test 71/71 here, and the stacked #2203/#2218 are rebased on it (82/82).

@Flyander Flyander left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The ABI correction is present in the current head: slots 10 and 13 now follow the documented argument order, and the added sentinel checks verify that the caller buffer remains untouched while both output parameters are initialized. The reported xgameruntime test and independent Windows run cover the fix. I found no remaining blocker.

Dom-in and others added 2 commits November 22, 2026 16:43
XCurl.dll asks QueryApiImpl for XNetworkingImpl with IXNetworkingImpl2's
interface id and calls slots 11-17 (measured with the ItsNotRexed#1877 thunk
disassembly, docs/runtime_imports.md): the UTF-16 URL security-information
async trio, the server certificate check, the connectivity hint and its
change registration. QueryApiImpl refused the class, so each of those
calls failed with class-not-provided.

The class answers as a console without a network: the connectivity hint is
initialized with level None; the preferred-port and URL security-info
queries fail with HRESULT_FROM_WIN32(ERROR_NETWORK_UNREACHABLE), the *Async
ones by completing their XAsyncBlock with it through XAsyncRun; the
certificate check fails the same way; change registrations return tokens
whose callbacks never fire; IXNetworkingImpl2's three additions are
E_NOTIMPL. RuntimeObject gains an optional newer interface id so
QueryInterface answers IXNetworkingImpl2 too.

xgameruntime_test (+8 checks, 69): both interface ids, the hint, the async
call completing with no network and its result size, the certificate
check, register/unregister, the port query and slot 20. tiny_gdk_load's
refused-class check uses an id no class has.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review (@Flyander): XNetworkingQuerySecurityInformationForUrl[Utf16]AsyncResult
is (XAsyncBlock*, size_t bufferByteCount, size_t* bufferByteCountUsed,
uint8_t* buffer, XNetworkingSecurityInformation** information); slots 10 and 13
had the last three as buffer, information, used, so a conforming caller got
nullptr written into its buffer and its used count left unset.

xgameruntime_test: both slots with a sentinel buffer and distinct outputs;
the buffer stays untouched, used and information are zeroed in place (both
checks fail with the old order).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Dom-in

Dom-in commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

Closing: XNetworkingImpl was served on main by 5f5d6d1 in the meantime. One thing from this PR still matters there: XCurl asks with IXNetworkingImpl2's id, which main refuses. That fix is now its own PR, stacked on #2203. The system (#2203) and package (#2218) PRs are rebased onto main without the networking commits.

@Dom-in Dom-in closed this Nov 22, 2026
ItsNotRexed added a commit that referenced this pull request Nov 22, 2026
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