upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/docs/console_libraries.md
diff options
context:
space:
mode:
authorNolan Cotter <186326284+NolanCotter@users.noreply.github.com>2026-11-22 09:16:54 -0700
committerNolan Cotter <186326284+NolanCotter@users.noreply.github.com>2026-11-22 16:40:46 -0700
commit75b2ea486c876b44b8ad7e9cacd9af95e045e989 (patch)
tree61123ba729fb8f9456fb994a1057284979e6ce78 /docs/console_libraries.md
parent2c6424bbc38adb892d8f752e500bf55717ccbfbb (diff)
docs: catalogue the console library surface and shim coverage
Diffstat (limited to 'docs/console_libraries.md')
-rw-r--r--docs/console_libraries.md222
1 files changed, 222 insertions, 0 deletions
diff --git a/docs/console_libraries.md b/docs/console_libraries.md
new file mode 100644
index 000000000..b7d1ca2d9
--- /dev/null
+++ b/docs/console_libraries.md
@@ -0,0 +1,222 @@
1# Console libraries: what the console build can import, and how the loader answers
2
3Status: catalogue, sourced. This page lists the console-only or console-flavoured DLLs an Xbox
4Series title's imports can name, what is measured about each one's export surface, and what
5`gta6rt` does with each today. It is the module-level counterpart to
6[runtime_imports.md](runtime_imports.md) (what the 16 shipped DLLs import) and to
7[d3d12_vulkan.md §7](d3d12_vulkan.md#7-prior-art-and-measured-xbox-abi) (the measured ABI inside
8the main one, `d3d12_xs.dll`).
9
10Basis tags:
11
12- **This repo** — verifiable in this tree: a `SHIM_TABLE` in `runtime/shims/*.cpp`, the
13 `classify()` list in `runtime/shims/registry.cpp`, the binding order in
14 `runtime/src/pe_loader.cpp`, or a measurement recorded in another page here.
15- **Sibling-layer measurement** — a fact folded in from `d3d12_vulkan.md` §7, measured elsewhere
16 by running the console DLLs or a retail title behind a compatibility layer. Paraphrased, not
17 re-measured here; no external repository is named on this page.
18
19Scope limit: the game executable is not in the package, so its own import table is unmeasured.
20The list below is the surface a console title *can* name — from sibling-layer inventories of the
21console DLLs and from one retail title's run — not a claim about what this title does.
22
23## 1. How an import binds today
24
25`Loader::resolve` in `runtime/src/pe_loader.cpp` binds each import in a fixed order (**this
26repo**):
27
281. **Shim registry** — `rt::shims::find(dll, name)`. Ordinal imports look up `"#N"`, so a shim
29 serves an ordinal import only if its table carries the `"#N"` spelling.
302. **Bundled module** — a DLL of the same name in `--game-dir`, mapped by the same loader (the
31 `module` count of the dry run; the CRT families are deliberately excluded and always take the
32 host copy).
333. **Host** — `LoadLibraryEx` on `System32` plus `GetProcAddress`, by name or ordinal.
344. **Unimplemented thunk** — a generated stub whose behaviour `LEONIDA_UNIMPLEMENTED` sets
35 (`log`/`fail`/`stop`; see
36 [runtime_imports.md](runtime_imports.md#when-an-unimplemented-import-is-called)). Under `fail`,
37 `classify()` in `runtime/shims/registry.cpp` decides by DLL and name which imports return
38 `E_NOTIMPL`.
39
40A module the registry serves at all and that is not a host DLL is **owned** (`owns_dll`): a
41title's `LoadLibrary`/`GetModuleHandle` on it gets a pseudo-handle and its `GetProcAddress`
42resolves through the registry by name or `"#N"`, with unknown names returning
43`ERROR_PROC_NOT_FOUND`
44([runtime_imports.md](runtime_imports.md#run-time-loaded-modules)). Owned today:
45`d3d12_xs.dll`, `xgameruntime.dll`, `xmem.dll` and `gameinput.dll` — the modules with a
46`SHIM_TABLE` entry.
47
48The registry also holds tables under `kernel32.dll`, `kernelbase.dll`, the `api-ms-*` sets,
49`msvcrt.dll` and `ucrtbase*.dll` (file system, library loader, process entry/exit). Those are
50host DLLs a few functions are replaced on, not owned console modules, so they are not in the
51list below.
52
53## 2. The modules
54
55| Module | What it is | Leonida today | Status |
56|---|---|---|---|
57| `d3d12_xs.dll` | Console D3D12 runtime front end | 4 names registered | partial shim |
58| `xgameruntime.dll` | GDK runtime (task queues, users, store, packaging) | 39 names registered; 2 impl classes | partial shim |
59| `xmem.dll` | Console tracked allocator / virtual-memory API | all 4 measured imports implemented | shimmed |
60| `gameinput.dll` | GameInput v0, controller input | `GameInputCreate` registered (SDL3 build) | shimmed |
61| `xaudio2_9.dll` | Console XAudio2 2.9 | no table; host binds it by ordinal | classified only |
62| `dstorage_xs.dll` | Console DirectStorage | no table; `DStorageGetFactory` classified | classified only |
63| `xg_xs.dll` | Texture layout helpers | nothing | unhandled |
64| `AcpHal.dll` | Audio co-processor HAL | nothing | unhandled |
65| `chad`, `xapu`, `xcrdapi`, `*legacy` | DSP, APU and card-API modules; names only | nothing | unhandled |
66
67### `d3d12_xs.dll`
68
69The console D3D12 runtime's front end: a thin DLL that loads the user-mode driver, which owns the
70device and command objects (**sibling-layer measurement**;
71[d3d12_xs_surface.md](d3d12_xs_surface.md) records the reported 116-export surface — 23 functions
72plus 93 GUID data exports — and which of the 83 standard GUIDs match the PC SDK). Beyond the
73standard `D3D12*` names its exports include `D3D12XboxCreateDevice` — the device entry point, call
74shape `(adapter, params, riid, out)` with a 24-word params block that is only logged —
75`D3D12XboxCreateSyntheticDevice` and `D3D12XboxSetProcessDebugFlags` (**sibling-layer
76measurement**).
77
78Leonida registers four names (**this repo**, `runtime/shims/d3d12_xs.cpp`):
79`D3D12SerializeVersionedRootSignature`, `D3D12SerializeRootSignature` and
80`D3D12CreateRootSignatureDeserializer`, each forwarded to the host `d3d12.dll` after the Xbox
81high flag byte is cleared on a copy; and `D3D12XboxCreateDevice`, which returns an Xbox-ABI proxy
82over the PC `ID3D12Device` — or over the Vulkan-backed device with `LEONIDA_D3D12=vulkan` — with
83the measured slot overrides (device slot 62 as compute-PSO creation, slot 76 as texture creation,
84descriptor-heap start handles returned in RAX). The other 19 function exports, including
85`D3D12XboxCreateSyntheticDevice` and `D3D12XboxSetProcessDebugFlags`, are not registered.
86`classify()` marks the `D3D12Create*`/`D3D12Serialize*` families, the two debug entries and both
87`D3D12XboxCreate*Device` names as HRESULT; `D3D12XboxSetProcessDebugFlags` is deliberately left
88out because its return was not measured (**this repo**, `registry.cpp`).
89
90The COM surface behind the device — queue, command list, fence, `PresentX` — is vtable work, not
91an import problem; it is tracked in [d3d12_vulkan.md](d3d12_vulkan.md) and
92[d3d12_command_objects.md](d3d12_command_objects.md). The presentation core
93(`runtime/shims/xbox_present.h`) waits on the unmeasured Xbox device/queue slots.
94
95### `xgameruntime.dll`
96
97The GDK runtime. Not in the package; GDK titles reach it either by import or by `LoadLibraryW` +
98`GetProcAddress` of `InitializeApiImpl`, `InitializeApiImplEx`, `InitializeApiImplEx2`,
99`QueryApiImpl` and `UninitializeApiImpl`, which is how the package's `libHttpClient.GDK.dll` and
100`XCurl.dll` do it (**this repo**,
101[runtime_imports.md](runtime_imports.md#run-time-loaded-modules)).
102
103Leonida registers 38 names plus `GameInputCreate` (**this repo**,
104`runtime/shims/xgameruntime.cpp`): the five loader entry points,
105`XGameRuntimeInitialize`/`Uninitialize`, five `XSystem*` queries, three `XPackage*` queries, the
10615-function `XTaskQueue*` set and the 8-function `XAsync*` set, both on the vendored
107`third_party/xtaskqueue`. `QueryApiImpl` serves `XThreadingImpl` and `XErrorImpl` and answers
108every other class with the documented "not provided" error so the first boot lists what is
109missing. `classify()` marks the `XAsync*`/`XTaskQueue*`/`XUser*`/`XStore*`/`XGameSave*`/
110`XPackage*`/`XGameUi*` families as HRESULT except the members the public pages document as
111`void`/`bool`/`int` (**this repo**, `registry.cpp`).
112
113### `xmem.dll`
114
115The console's tracked allocator. The only console module whose whole measured import surface is
116implemented (**this repo**, `runtime/shims/xmem.cpp`): `XMemAlloc`/`XMemFree` on the 64-byte
117aligned CRT heap, `XMemVirtualQuery(process, address, out64)` filling the
118`MEMORY_BASIC_INFORMATION` prefix and zeroing the rest of the measured 64-byte output, and
119`XMemGetWorkingSetStatistics(kind, out)` writing the process working set at +8 of the measured
120output. All four names are exactly the set the package's DLLs import
121([runtime_imports.md](runtime_imports.md)).
122
123A sibling layer additionally measured a title's physical-page calls on this module: 64 KiB pages,
124with runs of consecutive pages mapping contiguously inside one unified region and scattered or
125explicitly addressed mappings refused (**sibling-layer measurement**). Nothing in the package
126imports them and no such names are registered; see section 3.
127
128### `gameinput.dll`
129
130GameInput v0. The console build's ordinal 1 is `GameInputCreate` (**sibling-layer
131measurement**).
132
133Leonida registers `GameInputCreate` by name under both `gameinput.dll` and `xgameruntime.dll`:
134the PC API lives in the former, the GDK links it through the latter, and which the executable
135imports is unknown until it exists (**this repo**, `runtime/shims/gameinput.cpp`; the shim's API
136surface is [gameinput.md](gameinput.md)). The registration is a name only — no `"#1"` entry — so
137an ordinal-1 import would not hit the table (section 3). The shim is optional and built only with
138SDL3; without it the import falls through to the host DLL or the unimplemented thunk as before.
139
140### `xaudio2_9.dll`
141
142Console XAudio2 2.9. Ordinal 1 is `XAudio2Create` (**sibling-layer measurement**). Voices accept
143the console formats — XMA/XMA2 and an Opus format tag `0x704F` — and a `CO_E_NOTINITIALIZED`
144from the system XAudio2 is retried after `CoInitializeEx` on the calling thread; forwarding to
145the system XAudio2 2.9 works with those two quirks (**sibling-layer measurement**).
146
147Leonida has no table for it (**this repo**). The package's `Bink2Scarlett.dll` imports
148`XAudio2_9.dll` ordinal 1 and the dry run binds it to the host copy by ordinal — 57 host, 0
149unimplemented ([movies.md](movies.md), [runtime_imports.md](runtime_imports.md)) — so creation by
150ordinal resolves today, but the console voice formats and the retry quirk are not reproduced: a
151voice created with XMA/XMA2 or `0x704F` would reach the host unremapped. `classify()` marks
152`xaudio2_9.dll`/`xaudio2_9redist.dll` `XAudio2Create` as HRESULT — by name; the ordinal lookup
153classifies as Other (**this repo**, `registry.cpp`).
154
155### `dstorage_xs.dll`
156
157Console DirectStorage; named in the sibling export inventory with no export list measured
158(**sibling-layer measurement**). Leonida has no table; `DStorageGetFactory` is classified HRESULT
159under both `dstorage.dll` and `dstorage_xs.dll` (**this repo**, `registry.cpp`).
160
161### `xg_xs.dll`
162
163Texture layout helpers. The sibling export inventory names `XGCreateTexture2DComputer` and
164`XGComputeOptimalSwizzleMode` (**sibling-layer measurement**); prior-art text folded into
165[d3d12_vulkan.md](d3d12_vulkan.md#35-root-signature-to-user-sgprs) also names
166`XGComputeTexture2DLayout` as the module's untiling reference. Leonida has no table and no
167classification (`xg_xs.dll!XGCreateTexture2DComputer` is pinned as Other in
168`unimplemented_policy_test`; **this repo**). Nothing in the package imports it.
169
170### `AcpHal.dll`
171
172The audio co-processor HAL. The sibling export inventory names `ApuAlloc`, `ApuFree`,
173`ApuMapVirtualAddress`, `ApuIsVirtualAddressValid`, `AcpHalCreate`,
174`AcpHalAllocateShapeContexts` and `AcpHalReleaseShapeContexts` (**sibling-layer measurement**).
175Leonida has nothing for it (`acphal.dll!AcpHalCreate` is pinned as Other in
176`unimplemented_policy_test`; **this repo**).
177
178### `chad`, `xapu`, `xcrdapi`, `*legacy` variants
179
180A retail title booted to its menu and lobby through console-library stand-ins, and its
181console-only library set added `chad` (`XDsp*` exports), `xapu` (`XApu*` exports), `xcrdapi` and
182`*legacy` DLL variants to the modules above (**sibling-layer measurement**). These are names
183only: no export list, call shape or argument is measured, and Leonida has nothing for them.
184
185### Not console modules
186
187`d3d12.dll`, `dxgi.dll` and the `api-ms-*` sets are ordinary host bindings, not console modules.
188The package's own middleware (`Bink2Scarlett.dll`, `XboxBvhBuilder.dll`, the FidelityFX pair,
189`libHttpClient.GDK.dll`, `XCurl.dll`, the CRT set) binds as `module`, with the CRT families
190deliberately host-bound; their imports are catalogued in
191[runtime_imports.md](runtime_imports.md), not here. `xgs12_10.dll`, the user-mode driver a real
192`d3d12_xs.dll` loads (recorded in [d3d12_vulkan.md](d3d12_vulkan.md) from prior-art text), is not
193an import target a title names; Leonida replaces the whole stack rather than providing it.
194
195## 3. Gaps
196
197What a real title is known to call that Leonida does not yet cover (**sibling-layer
198measurement** unless noted):
199
200- **The whole `xg_xs`, `AcpHal`, `dstorage_xs`, `chad`, `xapu`, `xcrdapi` and `*legacy`
201 surface.** No table, no classification. A retail run reached its menu and lobby with stand-ins
202 for them; for this title, whether any is imported at all is unknown until the executable exists.
203- **The `xaudio2_9` quirks.** Creation by ordinal already binds to the host (**this repo**), but
204 the XMA/XMA2 and Opus `0x704F` voice formats and the `CoInitializeEx` retry would need a shim
205 that wraps or remaps — the host sees console format tags it does not know.
206- **The unregistered `d3d12_xs` functions.** 4 of the 23 function exports are registered; the
207 rest — `D3D12XboxCreateSyntheticDevice`, `D3D12XboxSetProcessDebugFlags`, the `DXGIX*`
208 present/frame-notification functions, `D3D12UploadCustomMicrocodeX`-type console entries —
209 would hit the unimplemented thunk. Two are at least classified (`D3D12XboxCreate*Device` →
210 HRESULT under `fail`).
211- **`xmem` physical-page calls.** A title's physical-page API uses 64 KiB pages and contiguous
212 mappings inside one unified region; the shim covers only the four allocator/query names the
213 package measured.
214- **Ordinal-only registrations.** The shim tables serve names; an ordinal import is looked up as
215 `"#N"`. `gameinput.dll` and `xaudio2_9.dll` ordinal 1 are the measured console entry points,
216 and neither has a `"#1"` entry — a static ordinal import therefore skips the shim and binds to
217 the host DLL where one exists (as `xaudio2_9.dll!#1` does today; **this repo**), and a
218 `GetProcAddress` for ordinal 1 on an owned module returns `ERROR_PROC_NOT_FOUND`.
219- **Run-time loading of bundled middleware.** A title that `LoadLibrary`s a package DLL such as
220 `Bink2Scarlett.dll` gets the host loader, which maps the Xbox build without the registry's
221 bindings for its own console imports — recorded as an open item in
222 [runtime_imports.md](runtime_imports.md#run-time-loaded-modules) (**this repo**).