feat(xgameruntime): serve the GDK threading API table from measured slots #71

Manually merged
github merged 1 commit from gh-pr/71/head into gh-pr/71/base 2026-11-26 19:17:32 +00:00
Owner

@⁠Dark3581 on GitHub · 2026-11-23 05:13 UTC · original
Dark3581:feat/threading-api-table → main · +221 −14 · 6 files · 1 commits · merged 2026-11-23 05:17 UTC

What

QueryApiImpl (#70) now serves its first method table, for the XAsync and XTaskQueue interface. With it, a bundled GDK module's initialization completes on AnyBox's runtime.

How the table was mapped (measured from the title package's own HTTP client module; no SDK material used):

  • GDK thunks are COM-style: QueryApiImpl(&provider, &interface, &obj), then obj->vtable[slot](args), then vtable[2] (Release). Methods start at slot 3.
  • The module links all 404 thunks across 21 interfaces, but its own code calls only a few of them, all in interface {073b7dcb-1fcf-4030-94be-e3c9eb623428} (provider and interface GUID are the same).
  • For each called slot I read the argument shape (registers and stack slots passed) and the number of call sites, and matched them against the calls in libHttpClient's MIT-licensed source:
Slot Shape Call sites Function
3 ptr, bool 5 XAsyncGetStatus
5 ptr 2 XAsyncCancel
7 5 args 11 XAsyncBegin
9 ptr, u32 7 XAsyncSchedule
10 ptr, u32, u64, no result used 43 XAsyncComplete
11 5 args 2 XAsyncGetResult
12 u32, u32, ptr 2 XTaskQueueCreate
13 ptr, ptr, ptr 3 XTaskQueueCreateComposite
14 ptr, u32, ptr 2 XTaskQueueGetPort
15 ptr, ptr 2 XTaskQueueDuplicateHandle
17 ptr 12 XTaskQueueCloseHandle
19 ptr, u32, u32, ptr, ptr 4 XTaskQueueSubmitDelayedCallback
22 ptr, bool, ptr, ptr 1 XTaskQueueTerminate
29 none, result ignored 162, at the start of every other thunk XThreadAssertNotTimeSensitive
  • Slot 29 is mapped from where it's called, not from the source: every API thunk calls it first. AnyBox's implementation acts only on threads marked time-sensitive, and the table can't mark one (slot 27 is unmapped).
  • Every other slot (4, 6, 8, 16, 18, 20, 21, 23 to 28, 30) stops and names its slot and interface. That includes slots whose function the order suggests (for example 16 as XTaskQueueDispatch), because no call site confirms them.

Code (xgameruntime/ApiImpl.cpp):

  • A static object per interface, with QueryInterface (answers its own GUID and IUnknown), AddRef/Release (a singleton) and the method slots, which forward to the existing XAsync*/XTaskQueue*/XThread* implementations.
  • QueryApiImpl returns it for the matching GUID pair; any other pair still stops with both GUIDs.
  • InitializeApiImpl* now log their values and return S_OK, so the module's XGameRuntimeInitialize completes. InitializeApiImplEx2 still stops if its fourth argument isn't null, because that might be an output.

The README row and the debt entry describe the table and how it was mapped.

Tested

Windows 10, MinGW (GCC) and MSVC 2022.

  • New e2e_api_threading: the relinked fake title loads the runtime at run time and does the handshake. Through table slots only, it calls slot 29, creates a thread-pool queue (12), runs a delayed callback (19), runs an XAsync operation whose provider schedules (9) and completes (10) while the title waits on it (3), terminates (22) and closes (17) the queue, checks that QueryInterface refuses another IID, and releases.
  • New e2e_api_unmapped: calling slot 16 stops as unsupported, naming the slot and the interface.
  • With the package's own HTTP client module (scratch harness, not in the repository), HCInitialize(nullptr) now returns S_OK:
    [anybox] loader: LoadLibraryExW(xgameruntime.dll) from libHttpClient.GDK.dll+0x5d8d8 loads ab_xgameruntime.dll
    [xgameruntime] InitializeApiImplEx2(0x633600002712, 0x65f400001832, flags 0x3)
    HCInitialize returned 0x00000000
    
    Before slot 29 was mapped, the run stopped there, naming slot 29.
  • MinGW ctest: 77 of 77. With MSVC, the four API and loader e2e tests pass, and every target builds except ab_gameinput, which needs gameinput.lib, which this machine doesn't have. python tools/check_conventions.py and debt_fold.py --check: ok.
  • The harness run with the MSVC-built libraries crashes in the package's msvcp140.dll. That's an older, separate bug: the MSVC build links AnyBox's libraries against the dynamic C++ runtime, so they load a title's console copy. A follow-up PR fixes it.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • python tools/check_conventions.py passes (no comments in code, one declaration per export, Conventional Commit subjects)
  • Unimplemented paths stop (AbxNotImplemented / AbxUnsupported); silent stubs are listed under Silent stubs through a debt fragment
  • Known gaps added, changed or removed through docs/dev/debt/changes/<branch>.md
  • Generic behaviour, not specific to one title
  • No game files, keys, notes or logs added to the repository
  • Depends on: #69, #70 (merged)
  • Fixes: none
  • Unblocks: none
  • Source of behaviour: call sites in a bundled GDK module (argument shapes, call counts, call order) matched against libHttpClient's MIT-licensed source
  • AI-assisted: yes
**@⁠Dark3581** on GitHub · 2026-11-23 05:13 UTC · [original](https://github.com/Dark3581/AnyBox/pull/71) `Dark3581:feat/threading-api-table` → `main` · +221 −14 · 6 files · 1 commits · merged 2026-11-23 05:17 UTC ### What `QueryApiImpl` (#70) now serves its first method table, for the XAsync and XTaskQueue interface. With it, a bundled GDK module's initialization completes on AnyBox's runtime. **How the table was mapped** (measured from the title package's own HTTP client module; no SDK material used): - GDK thunks are COM-style: `QueryApiImpl(&provider, &interface, &obj)`, then `obj->vtable[slot](args)`, then `vtable[2]` (`Release`). Methods start at slot 3. - The module links all 404 thunks across 21 interfaces, but its own code calls only a few of them, all in interface `{073b7dcb-1fcf-4030-94be-e3c9eb623428}` (provider and interface GUID are the same). - For each called slot I read the argument shape (registers and stack slots passed) and the number of call sites, and matched them against the calls in libHttpClient's MIT-licensed source: | Slot | Shape | Call sites | Function | |---|---|---|---| | 3 | ptr, bool | 5 | `XAsyncGetStatus` | | 5 | ptr | 2 | `XAsyncCancel` | | 7 | 5 args | 11 | `XAsyncBegin` | | 9 | ptr, u32 | 7 | `XAsyncSchedule` | | 10 | ptr, u32, u64, no result used | 43 | `XAsyncComplete` | | 11 | 5 args | 2 | `XAsyncGetResult` | | 12 | u32, u32, ptr | 2 | `XTaskQueueCreate` | | 13 | ptr, ptr, ptr | 3 | `XTaskQueueCreateComposite` | | 14 | ptr, u32, ptr | 2 | `XTaskQueueGetPort` | | 15 | ptr, ptr | 2 | `XTaskQueueDuplicateHandle` | | 17 | ptr | 12 | `XTaskQueueCloseHandle` | | 19 | ptr, u32, u32, ptr, ptr | 4 | `XTaskQueueSubmitDelayedCallback` | | 22 | ptr, bool, ptr, ptr | 1 | `XTaskQueueTerminate` | | 29 | none, result ignored | 162, at the start of every other thunk | `XThreadAssertNotTimeSensitive` | - Slot 29 is mapped from where it's called, not from the source: every API thunk calls it first. AnyBox's implementation acts only on threads marked time-sensitive, and the table can't mark one (slot 27 is unmapped). - Every other slot (4, 6, 8, 16, 18, 20, 21, 23 to 28, 30) stops and names its slot and interface. That includes slots whose function the order suggests (for example 16 as `XTaskQueueDispatch`), because no call site confirms them. **Code** (`xgameruntime/ApiImpl.cpp`): - A static object per interface, with `QueryInterface` (answers its own GUID and `IUnknown`), `AddRef`/`Release` (a singleton) and the method slots, which forward to the existing `XAsync*`/`XTaskQueue*`/`XThread*` implementations. - `QueryApiImpl` returns it for the matching GUID pair; any other pair still stops with both GUIDs. - `InitializeApiImpl*` now log their values and return `S_OK`, so the module's `XGameRuntimeInitialize` completes. `InitializeApiImplEx2` still stops if its fourth argument isn't null, because that might be an output. The README row and the debt entry describe the table and how it was mapped. ### Tested Windows 10, MinGW (GCC) and MSVC 2022. - New `e2e_api_threading`: the relinked fake title loads the runtime at run time and does the handshake. Through table slots only, it calls slot 29, creates a thread-pool queue (12), runs a delayed callback (19), runs an XAsync operation whose provider schedules (9) and completes (10) while the title waits on it (3), terminates (22) and closes (17) the queue, checks that `QueryInterface` refuses another IID, and releases. - New `e2e_api_unmapped`: calling slot 16 stops as unsupported, naming the slot and the interface. - **With the package's own HTTP client module** (scratch harness, not in the repository), `HCInitialize(nullptr)` now returns `S_OK`: ``` [anybox] loader: LoadLibraryExW(xgameruntime.dll) from libHttpClient.GDK.dll+0x5d8d8 loads ab_xgameruntime.dll [xgameruntime] InitializeApiImplEx2(0x633600002712, 0x65f400001832, flags 0x3) HCInitialize returned 0x00000000 ``` Before slot 29 was mapped, the run stopped there, naming slot 29. - MinGW `ctest`: 77 of 77. With MSVC, the four API and loader e2e tests pass, and every target builds except `ab_gameinput`, which needs `gameinput.lib`, which this machine doesn't have. `python tools/check_conventions.py` and `debt_fold.py --check`: ok. - The harness run with the MSVC-built libraries crashes in the package's `msvcp140.dll`. That's an older, separate bug: the MSVC build links AnyBox's libraries against the dynamic C++ runtime, so they load a title's console copy. A follow-up PR fixes it. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] `python tools/check_conventions.py` passes (no comments in code, one declaration per export, Conventional Commit subjects) - [x] Unimplemented paths stop (`AbxNotImplemented` / `AbxUnsupported`); silent stubs are listed under Silent stubs through a debt fragment - [x] Known gaps added, changed or removed through `docs/dev/debt/changes/<branch>.md` - [x] Generic behaviour, not specific to one title - [x] No game files, keys, notes or logs added to the repository - [x] Depends on: #69, #70 (merged) - [x] Fixes: none - [x] Unblocks: none - [x] Source of behaviour: call sites in a bundled GDK module (argument shapes, call counts, call order) matched against libHttpClient's MIT-licensed source - [x] AI-assisted: yes
QueryApiImpl now returns a COM-style method table for the XAsync and XTaskQueue interface. Its slots are mapped only where a bundled GDK module was measured calling them, matched by argument shape and call count against its open-source caller; other slots and interfaces stop and name themselves. The handshake succeeds and logs its values. A bundled GDK module's initialization now completes on AnyBox's runtime.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 19:17:31 +00:00
github manually merged commit 951af84af3 into gh-pr/71/base 2026-11-26 19:17:32 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.