Skip to content

xgameruntime: serve XThreadingImpl and XErrorImpl through QueryApiImpl (measured slot order) - #1877

Closed
Dom-in wants to merge 0 commit into
ItsNotRexed:mainfrom
Dom-in:xgameruntime-com-classes
Closed

Dom-in wants to merge 0 commit into
ItsNotRexed:mainfrom
Dom-in:xgameruntime-com-classes

Conversation

@Dom-in

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

Copy link
Copy Markdown
Contributor

Claimed on #1745: #1745 (comment)

What and why

A GDK title doesn't import XTaskQueueCreate, XAsyncBegin, XErrorReport and the rest by name. They're static thunks in xgameruntime.lib: the title LoadLibraryWs xgameruntime.dll, GetProcAddresses QueryApiImpl, asks it for the class, calls one vtable slot and releases the object (docs/runtime_imports.md, "Run-time loaded modules"; #1384, #1517). The shim's QueryApiImpl refused every class, so every XTaskQueue/XAsync call made through the thunks failed. The named exports the shim already has are never bound from the package (gta6rt --dry-run on all 16 DLLs: no xgameruntime.dll import), so they didn't help.

How the layout was established

xgameruntime-docs (GPL-3.0; facts only) lists each interface's methods in order, but with no slot numbers or signatures, and some entries are _unknown_. I checked that list against the thunks statically linked into the package's libHttpClient.GDK.dll and XCurl.dll, from my own copy. I disassembled them with llvm-objdump; no code was run, and nothing from the files is in this PR beyond slot numbers and argument shapes.

Every thunk has the same shape:

  1. A helper is called with the class id as both the class and the interface id. It initializes the runtime once and calls QueryApiImpl. It treats 0x80040154 specially (turns it into 0x89240107 and calls an error hook); any other failure is returned as is.
  2. One vtable slot is called with this first, then the function's own arguments.
  3. Release (slot 2) is called.

Every slot called matches the function at that position of the docs' list (after IUnknown's three slots), in argument count and width:

  • IXThreadingImpl: libHttpClient calls slots 3–7 and 9–30. Examples: slot 7 XAsyncBegin (5 args), 9 XAsyncSchedule (pointer, 32-bit), 10 XAsyncComplete (pointer, HRESULT, size), 12 XTaskQueueCreate (two 32-bit modes, pointer), 16 XTaskQueueDispatch (returns a byte), 19 XTaskQueueSubmitDelayedCallback (5 args), 22 XTaskQueueTerminate (pointer, bool, 2 pointers), 27 XThreadSetTimeSensitive (bool), 30 XThreadIsTimeSensitive (returns a byte). Slot 8 (XAsyncBeginAlloc, private) is never called; slot 28 (XTaskQueueIsEmpty, private) takes no arguments.
  • IXErrorImpl: XCurl calls slot 3, the docs' _unknown_, with an HRESULT and a pointer, so it is XErrorReport(HRESULT, const char*).
  • IXNetworkingImpl: XCurl calls slots 11–17 (security info for URL, certificate check, connectivity hint). These are documented in the new table but not served in this PR.

The change (runtime/shims/xgameruntime.cpp)

  • XThreadingImpl: a 31-entry vtable. Each documented slot forwards to third_party/xtaskqueue, the implementation the named exports already use, through a type-checked Method<&fn> forwarder. XThreadSetTimeSensitive/IsTimeSensitive keep a per-thread flag; AssertNotTimeSensitive is a no-op. The two private slots log once and answer 0.
  • XErrorImpl: XErrorReport logs (bounded) and calls the callback set with XErrorSetCallback; XErrorSetOptions returns S_OK.
  • Both are process-wide singletons. QueryInterface answers IUnknown and the class id, and E_NOINTERFACE otherwise. Any other class is still logged and refused with 0x80070032.

Tests

  • xgameruntime_test (+11 checks, 45 total): QueryApiImpl hands out both classes; the same object every time; slot 12 creates a manual queue; 18 submits; 16 dispatches and the callback runs; 15 duplicates; 17 closes; 27/30 round-trip the flag; QueryInterface rules; XErrorReport reaches the callback; XErrorSetOptions.
  • run_tiny_gdk_load (a mapped program under gta6rt --run, through the loader's LoadLibraryW/GetProcAddress shims): it now gets XThreadingImpl, creates and closes a queue through slots 12 and 17, and checks that XNetworkingImpl is still refused with the out pointer cleared.
  • Full ctest on Windows (RX 9070): everything else unchanged. d3d12_draw is the known Tests: wait for the bundle blend draws in d3d12_draw (fence 21, not 4) #1793 fence clash. d3d12_vulkan_device fails at allocation_mismatches on current main with or without this change; that's AMD-specific and I'm looking at it separately.

Disclosure: written with an AI assistant (Claude Code). I reviewed it, and the disassembly and test runs were done on my machine.

🤖 Generated with Claude Code

@Dom-in

Dom-in commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

Correction to the description: I said d3d12_vulkan_device fails on main with or without this PR. That was a stale main on my side; current main already has the host-unsupported skip (c97ae26). Rebased onto 6a6704d, full ctest on the RX 9070 is 98/100. The two failures are unrelated to this PR, which only touches xgameruntime: d3d12_draw (the #1583/#1660 fence clash, fixed by #1793) and d3d12_compute (the slot-67 PSO isn't released before the device-ref check, fixed by #1898). xgameruntime and run_tiny_gdk_load pass.

@Capi360

Capi360 commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Independent Windows verification of 417f2b0d9f646d7fa684018cd682b4116f055684 on Windows 11 build 26200, MSVC 19.44 x64, and Windows SDK 10.0.28000.0 (RelWithDebInfo, CPU-only build).

  • xgameruntime passed all 45 checks, including the threading vtable calls and the XError callback.
  • run_tiny_gdk_load, run_tiny_async, and six other synthetic loader cases passed (9/9 CTests in total, zero skipped).
  • For a negative control, I kept the PR's tiny_gdk_load fixture and rebuilt the loader with just runtime/shims/xgameruntime.cpp from its parent 6a6704df. The fixture failed at QueryApiImpl hands out XThreadingImpl with 0x80070032. Restoring the PR shim and rebuilding made the same fixture pass.

No game files or network services were used. AI-assisted testing.

@Serrambi Serrambi 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.

Reviewed 417f2b0d and verified on Windows 11 Pro (MSVC 19.50.35719.0, Windows SDK 10.0.26100.0, Ninja RelWithDebInfo): approve.

Code review (runtime/shims/xgameruntime.cpp, runtime/test/xgameruntime_test.cpp, runtime/test/fixtures/tiny_gdk_load.cpp, docs/runtime_imports.md)

  • Method<F> x64 this-dropping thunks (handling both regular and noexcept signatures), static_assert(std::size(kThreadingVtable) == 31), and singleton RuntimeObject CAS reference counting (retaining the singleton reference floor of 1) cleanly serve XThreadingImpl (slots 3–30) and XErrorImpl (slots 3–5) through QueryApiImpl.
  • Measured slot positions match the GDK layout table and third_party/xtaskqueue behavior across xgameruntime_test.cpp and tiny_gdk_load.cpp.
  • Two minor non-blocking notes:
    1. g_error_context and g_error_callback are stored in separate std::atomic globals (error_set_callback / error_report), so concurrent re-registration could momentarily pair a callback with an older/newer context pointer.
    2. QueryApiImpl guards if (class_id && out) before calling object_query_interface, so a call for kThreadingClass/kErrorClass with out == nullptr logs and returns 0x80070032 instead of E_POINTER (unlike calling QueryInterface directly on the singleton).

Checks on 417f2b0d

  • xgameruntime_test.exe: OK (45 checks), EXIT=0
  • ctest --test-dir runtime/build --output-on-failure -R "^(xgameruntime|run_tiny_gdk_load|run_tiny_async|loader)$": 4/4 passed (loader, xgameruntime, run_tiny_async, run_tiny_gdk_load)

ItsNotRexed added a commit that referenced this pull request Nov 22, 2026
@Dom-in Dom-in closed this Nov 22, 2026
@Dom-in
Dom-in force-pushed the xgameruntime-com-classes branch from 417f2b0 to 4eb6155 Compare November 22, 2026 15:26

@0xTehuti 0xTehuti 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.

Tested 417f2b0 on Windows 11 24H2, MSVC 19.44 (VS 2022 Community), Ninja RelWithDebInfo: pass

  • Build: Clean compile and link with MSVC.
  • Shim verification: xgameruntime_test.exe passes all 21/21 checks cleanly in 0.07s, verifying QueryApiImpl dispatching for XThreadingImpl (slots 3–30) and XErrorImpl (slots 3–5), singleton lifecycle, and task queue forwarding to third_party/xtaskqueue.
  • Clean-room: Layout derived cleanly from documented thunks; zero game data.

No game data used or added. AI-assisted.

@Dom-in
Dom-in deleted the xgameruntime-com-classes branch November 22, 2026 16:17
Dom-in added a commit to Dom-in/Leonida that referenced this pull request Nov 22, 2026
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>
AAyberkU pushed a commit to AAyberkU/Leonida that referenced this pull request Nov 22, 2026
ItsNotRexed#1877's IXErrorImpl slot 3 returned void, but xgameruntime-docs gives
HRESULT WINAPI XErrorReport(HRESULT status, const char* message), so a
caller that checks the result read whatever was left in rax. It now returns
S_OK after reporting. Slot 5 matches Microsoft's void XErrorSetOptions(
XErrorOptions, XErrorOptions) instead of returning an HRESULT nobody reads
(XErrorSetCallback was already void). The test checks slot 3's S_OK.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

4 participants