diff options
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/README.md | 1 | ||||
| -rw-r--r-- | docs/import_routing.md | 77 |
2 files changed, 78 insertions, 0 deletions
diff --git a/docs/README.md b/docs/README.md index 2998f8191..545f3ba37 100644 --- a/docs/README.md +++ b/docs/README.md | |||
| @@ -66,6 +66,7 @@ method, scope and caveats. No game data is included. | |||
| 66 | | [d3d12_command_objects.md](d3d12_command_objects.md) | Measured command queue/list/fence/`PresentX` surface; verified vs prior art vs open. | | 66 | | [d3d12_command_objects.md](d3d12_command_objects.md) | Measured command queue/list/fence/`PresentX` surface; verified vs prior art vs open. | |
| 67 | | [runtime_imports.md](runtime_imports.md) | The 16 shipped modules' measured imports and shim/host/unimplemented split. | | 67 | | [runtime_imports.md](runtime_imports.md) | The 16 shipped modules' measured imports and shim/host/unimplemented split. | |
| 68 | | [console_libraries.md](console_libraries.md) | The console-DLL surface a title can import (`d3d12_xs`, `xgameruntime`, `xmem`, `gameinput`, `xaudio2_9`, `dstorage_xs`, `xg_xs`, `AcpHal`, `chad`/`xapu`/`xcrdapi`): which are shimmed, classified or unbound. | | 68 | | [console_libraries.md](console_libraries.md) | The console-DLL surface a title can import (`d3d12_xs`, `xgameruntime`, `xmem`, `gameinput`, `xaudio2_9`, `dstorage_xs`, `xg_xs`, `AcpHal`, `chad`/`xapu`/`xcrdapi`): which are shimmed, classified or unbound. | |
| 69 | | [import_routing.md](import_routing.md) | The bind order (shim → bundled → host → unimplemented), `owns_dll` and the pseudo-handle path, per-DLL outcome. | | ||
| 69 | | [gameinput.md](gameinput.md) | The GameInput shim on SDL3: `GameInputCreate` and the v0 `IGameInput`/`IGameInputDevice`/`IGameInputReading`/`IGameInputDispatcher` surface on any SDL gamepad, DualSense adaptive-trigger approximation and lightbar, force-feedback motors and trigger haptics through SDL's haptic API; 261 checks on virtual joysticks and a fake haptic backend, not yet tried on a real pad. | | 70 | | [gameinput.md](gameinput.md) | The GameInput shim on SDL3: `GameInputCreate` and the v0 `IGameInput`/`IGameInputDevice`/`IGameInputReading`/`IGameInputDispatcher` surface on any SDL gamepad, DualSense adaptive-trigger approximation and lightbar, force-feedback motors and trigger haptics through SDL's haptic API; 261 checks on virtual joysticks and a fake haptic backend, not yet tried on a real pad. | |
| 70 | | [saves.md](saves.md) | Save containers: `JSAV` (index + JSON story save, byte-exact rebuild), `ASAV` header, `SLAYER1` packed copy (not decoded); `tools/saves.py` and import into the offline `XGameSave` folder; key hashes are case-sensitive joaat (`tools/save_keys.py`). | | 71 | | [saves.md](saves.md) | Save containers: `JSAV` (index + JSON story save, byte-exact rebuild), `ASAV` header, `SLAYER1` packed copy (not decoded); `tools/saves.py` and import into the offline `XGameSave` folder; key hashes are case-sensitive joaat (`tools/save_keys.py`). | |
| 71 | | [pipeline_check.md](pipeline_check.md) | Driver-level corpus check: 10/12 shards, 22,092 modules, 2,217 compute pipelines, 0 failures. | | 72 | | [pipeline_check.md](pipeline_check.md) | Driver-level corpus check: 10/12 shards, 22,092 modules, 2,217 compute pipelines, 0 failures. | |
diff --git a/docs/import_routing.md b/docs/import_routing.md new file mode 100644 index 000000000..b4aa5c560 --- /dev/null +++ b/docs/import_routing.md | |||
| @@ -0,0 +1,77 @@ | |||
| 1 | # Import routing: shim, bundled, host or unimplemented | ||
| 2 | |||
| 3 | How `gta6rt` binds an import, per DLL. The code paths are `Loader::resolve` for the import table | ||
| 4 | (`runtime/src/pe_loader.cpp`), `Loader::resolve_forwarder` for a forwarded export, and the `LoadLibrary*` / | ||
| 5 | `GetProcAddress` shims for run-time loads (`runtime/shims/library_loader.cpp`). Measured against the 16 shipped | ||
| 6 | modules in [runtime_imports.md](runtime_imports.md): every import binds, 0 unimplemented. | ||
| 7 | |||
| 8 | ## The bind order | ||
| 9 | |||
| 10 | `resolve(dll, name)` tries, in order: | ||
| 11 | |||
| 12 | 1. **Shim** — `rt::shims::find("dll!name")`, the clean-room tables registered by `SHIM_TABLE` in | ||
| 13 | `runtime/shims/*.cpp`. The registry is searched first even for host DLLs, which is how `kernel32!CreateFileW` | ||
| 14 | or `ExitProcess` get redirected without losing the rest of `kernel32`. | ||
| 15 | 2. **Bundled** — `<game-dir>/<dll>` mapped by the same loader, unless the name is in `prefer_host_copy` | ||
| 16 | (the `vcruntime140`/`msvcp140`/`concrt140`/`vccorlib140`/`vcomp140` family: the host CRT is always used, so a | ||
| 17 | mapped image's `RtlPcToFileHeader` can be redirected, `pe_loader.cpp`). A bundled export that is itself a | ||
| 18 | forwarder string is followed by `resolve_forwarder` (8 deep, then a loop is declared). | ||
| 19 | 3. **Host** — `LoadLibraryExA(dll, LOAD_LIBRARY_SEARCH_SYSTEM32)` + `GetProcAddress`. System32 only, so the game | ||
| 20 | folder is never in the search. API-set names (`api-ms-*`, `ext-ms-*`) resolve here through the host's API-set | ||
| 21 | schema; the measured run binds every api-ms import the package asks for. | ||
| 22 | 4. **Unimplemented** — `shims::make_unimplemented_thunk`: a 32-byte stub per import that calls `rt_unimplemented` | ||
| 23 | with `"dll!name"` and the argument registers; `LEONIDA_UNIMPLEMENTED` = log (default) / fail / stop picks the | ||
| 24 | answer (`runtime/shims/registry.cpp`, policy documented in `runtime/README.md` and | ||
| 25 | [runtime_imports.md](runtime_imports.md#when-an-unimplemented-import-is-called)). | ||
| 26 | |||
| 27 | Step 3 is skipped when `shims::owns_dll(dll)` is true. `xgameruntime.dll` and `gameinput.dll` are real PC names | ||
| 28 | (Gaming Services installs `xgameruntime.dll` in System32); without the skip, an import the registry doesn't serve | ||
| 29 | would bind to the live service runtime while a run-time `GetProcAddress` for the same name returns NULL, and the | ||
| 30 | process would be online-capable. `resolve_forwarder` applies the same order, so a forwarder string naming a | ||
| 31 | shimmed module resolves to the shim. | ||
| 32 | |||
| 33 | ## `owns_dll`: whole-module shims | ||
| 34 | |||
| 35 | `owns_dll` (registry.cpp) is false for `api-ms-*`/`ext-ms-*` prefixes and for the eight host DLLs that the tables | ||
| 36 | partially override — `kernel32`, `kernelbase`, `msvcrt`, `ucrtbase`, `ucrtbased`, `vulkan-1`, `ntdll`, `user32` — | ||
| 37 | and otherwise true exactly when the registry holds at least one `dll!` entry. Owned today: `d3d12_xs.dll`, | ||
| 38 | `xgameruntime.dll`, `gameinput.dll`, `xmem.dll`. | ||
| 39 | |||
| 40 | A title's `LoadLibrary*`/`GetModuleHandle*` for an owned module returns a pseudo-handle | ||
| 41 | (`library_loader.cpp`); `GetProcAddress` on it resolves through the registry only — an unserved name is NULL with | ||
| 42 | `ERROR_PROC_NOT_FOUND`, never the host. `FreeLibrary` on a pseudo-handle is a no-op. Every other module goes to | ||
| 43 | the real `LoadLibrary*`/`GetProcAddress`. | ||
| 44 | |||
| 45 | ## Per-DLL outcome | ||
| 46 | |||
| 47 | | DLL | Registry entries | Static import | Run-time load | | ||
| 48 | |---|---|---|---| | ||
| 49 | | `d3d12_xs.dll` | 4: `D3D12XboxCreateDevice`, `D3D12Serialize{,Versioned}RootSignature`, `D3D12CreateRootSignatureDeserializer` | those → shim; any other → unimplemented (no host namesake) | owned → pseudo-handle | | ||
| 50 | | `xgameruntime.dll` | ~40: `*ApiImpl*` entry points, `XGameRuntime*`, `XSystem*`, `XPackage*`, `XTaskQueue*`, `XAsync*`, `GameInputCreate` | registered → shim; unregistered → unimplemented | owned → pseudo-handle (the path `xgameruntime.lib` thunks use) | | ||
| 51 | | `gameinput.dll` | `GameInputCreate` | registered → shim; unregistered → unimplemented | owned → pseudo-handle | | ||
| 52 | | `xmem.dll` | `XMemAlloc`, `XMemFree`, `XMemVirtualQuery`, `XMemGetWorkingSetStatistics` | registered → shim; unregistered → unimplemented | owned → pseudo-handle | | ||
| 53 | | `d3d12.dll`, `dxgi.dll` | none | host (the real PC DLLs; the console surface rides on them through the `d3d12_xs` device proxy and the DXGI COM wrappers) | real host DLL | | ||
| 54 | | `xaudio2_9.dll`, `xaudio2_9redist.dll` | none | host if installed, else unimplemented | real host DLL | | ||
| 55 | | `dstorage.dll`, `dstorage_xs.dll` | none | `dstorage.dll` host if the DirectStorage redist is installed, else unimplemented; `dstorage_xs.dll` unimplemented | real host DLL / fails | | ||
| 56 | | `xg_xs.dll`, `acphal.dll`, `chad*`/`xapu*`/`xcrdapi*` (legacy Xbox names) | none | unimplemented | fails (host can't load them) | | ||
| 57 | | `kernel32`, `kernelbase` | file (`CreateFile*`, `FindFirstFile*`, `GetFileAttributes*`, `DeleteFile*`), loader (`LoadLibrary*`, `GetModuleHandle*`, `GetProcAddress`, `FreeLibrary`), process (`ExitProcess`, `GetCommandLine*`) | registered → shim; everything else → host | real host DLL (not owned) | | ||
| 58 | | `msvcrt`, `ucrtbase`, `ucrtbased` | exit/`abort`/argv/command-line overrides | registered → shim; everything else → host | real host DLL | | ||
| 59 | | `ntdll`, `user32`, `vulkan-1` | none | host | real host DLL | | ||
| 60 | | `api-ms-*`, `ext-ms-*` | only the sets a GDK title links: `core-file-l1-1-0/l1-2-0/l2-1-0`, `core-libraryloader-l1-1-0/l1-1-1/l1-2-0/l1-2-1/l1-2-2`, `core-processthreads-l1-1-0`, `core-processenvironment-l1-1-0`, `crt-runtime-l1-1-0` | registered names → shim; all other names and sets → host API-set schema (this is what covers every UCRT `api-ms-win-crt-*` variant without a table entry) | real host resolution | | ||
| 61 | | `vcruntime140*`, `msvcp140*`, `concrt140`, `vccorlib140`, `vcomp140` | none | host, even when a bundled copy exists (`prefer_host_copy`) | real host DLL | | ||
| 62 | | the package's own DLLs (`Bink2Scarlett.dll`, `XCurl.dll`, …) | none | bundled module, mapped by the loader | host `LoadLibrary` — see the caveat in [runtime_imports.md](runtime_imports.md#run-time-loaded-modules) | | ||
| 63 | | anything else | none | unimplemented | host or failure | | ||
| 64 | |||
| 65 | ## Edge cases | ||
| 66 | |||
| 67 | - **`d3d12.dll`/`dxgi.dll` can never hit the unimplemented thunk** for a name the PC DLL exports: no registry | ||
| 68 | entries exist for them, and they are real System32 DLLs. A name they don't export ends unimplemented, which is | ||
| 69 | the wanted answer. | ||
| 70 | - **Ordinals**: registry keys are `dll!#N` in `Entry.name`, but no shipped table registers an ordinal; an | ||
| 71 | ordinal-only import from a shimmed or console-only DLL lands unimplemented. Host DLLs bind ordinals through | ||
| 72 | `GetProcAddress` normally. | ||
| 73 | - **No console DLL matches the host list.** The `owns_dll` host list holds only names that also exist on the PC | ||
| 74 | and have partial table overrides. A console-only name (`d3d12_xs`, `xmem`, `xg_xs`, …) can't be owned by | ||
| 75 | accident and can't be excluded from the tables by accident. | ||
| 76 | - **Owned ≠ bundled-blocked.** A bundled copy of an owned name would still map through the bundled step before | ||
| 77 | the unimplemented fallback; nothing in the package ships one. | ||