diff options
| author | TreXito <81475944+TreXito@users.noreply.github.com> | 2026-11-23 21:45:35 +0000 |
|---|---|---|
| committer | TreXito <81475944+TreXito@users.noreply.github.com> | 2026-11-23 21:45:35 +0000 |
| commit | f09afa4dee4bcd2a69920a1507581aab3d1c79d0 (patch) | |
| tree | bf036898f306f4125571ded6a93ef76db9051cdb /docs | |
| parent | 239002fb0a0bf509a09d124a2d55b7ef081e7b7a (diff) | |
| parent | 07e818b40638f52daa590b1e00b581599df2b7b9 (diff) | |
Merge #7010 (exe/import-fail-fast)
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/README.md | 1 | ||||
| -rw-r--r-- | docs/exe_fail_fast.md | 81 |
2 files changed, 82 insertions, 0 deletions
diff --git a/docs/README.md b/docs/README.md index 93f28da46..d367687a6 100644 --- a/docs/README.md +++ b/docs/README.md | |||
| @@ -77,6 +77,7 @@ method, scope and caveats. No game data is included. | |||
| 77 | | [xbox_d3d12_xs.md](xbox_d3d12_xs.md) | The `d3d12_xs` graphics ABI quoted from Microsoft's public GDK reference: root signatures, state objects, DXIL libraries, hit groups, shader cache sessions; which pages are missing or NDA-gated. | | 77 | | [xbox_d3d12_xs.md](xbox_d3d12_xs.md) | The `d3d12_xs` graphics ABI quoted from Microsoft's public GDK reference: root signatures, state objects, DXIL libraries, hit groups, shader cache sessions; which pages are missing or NDA-gated. | |
| 78 | | [runtime_imports.md](runtime_imports.md) | The 16 shipped modules' measured imports and shim/host/unimplemented split. | | 78 | | [runtime_imports.md](runtime_imports.md) | The 16 shipped modules' measured imports and shim/host/unimplemented split. | |
| 79 | | [xmem_exe_calls.md](xmem_exe_calls.md) | How the retail executable calls `xmem.dll`: call sites and constant arguments per import (`tools/import_call_sites.py`), the 23 `XMemVirtualAlloc` calls that all pass an attribute word, and the inferred shape of the physical-page family. | | 79 | | [xmem_exe_calls.md](xmem_exe_calls.md) | How the retail executable calls `xmem.dll`: call sites and constant arguments per import (`tools/import_call_sites.py`), the 23 `XMemVirtualAlloc` calls that all pass an attribute word, and the inferred shape of the physical-page family. | |
| 80 | | [exe_fail_fast.md](exe_fail_fast.md) | Where the retail executable stops itself (`int3`) on an import's result: 78 sites over 27 imports (`tools/import_fail_fast.py`), grouped by how `main` binds each import, and the 8 sites a return of 0 from an unbound xmem import stops. | | ||
| 80 | | [audio_hal_exe_calls.md](audio_hal_exe_calls.md) | How the retail executable calls the 22 audio coprocessor, texture layout and DirectStorage imports that have no shim: call sites, constant arguments, and the four calls with a negative-result branch. | | 81 | | [audio_hal_exe_calls.md](audio_hal_exe_calls.md) | How the retail executable calls the 22 audio coprocessor, texture layout and DirectStorage imports that have no shim: call sites, constant arguments, and the four calls with a negative-result branch. | |
| 81 | | [cpu_features.md](cpu_features.md) | CPU instructions in the executable a desktop CPU may lack (`tools/cpu_feature_scan.py`): 19 SSE4a, 10 CLZERO and 4 MONITORX/MWAITX sites (AMD only) and 8 CLWB sites (Intel since Ice Lake), all real code; `#UD` on hosts without them. | | 82 | | [cpu_features.md](cpu_features.md) | CPU instructions in the executable a desktop CPU may lack (`tools/cpu_feature_scan.py`): 19 SSE4a, 10 CLZERO and 4 MONITORX/MWAITX sites (AMD only) and 8 CLWB sites (Intel since Ice Lake), all real code; `#UD` on hosts without them. | |
| 82 | | [xcl_compare.md](xcl_compare.md) | XCL's synthetic test title under `gta6rt --run` and under XCL (`tools/xcl_compare.py`): 5 of 50 checks pass here, both hangs are the documented manual-queue terminate deadlock, and each other difference mapped to an open item or a lead. | | 83 | | [xcl_compare.md](xcl_compare.md) | XCL's synthetic test title under `gta6rt --run` and under XCL (`tools/xcl_compare.py`): 5 of 50 checks pass here, both hangs are the documented manual-queue terminate deadlock, and each other difference mapped to an open item or a lead. | |
diff --git a/docs/exe_fail_fast.md b/docs/exe_fail_fast.md new file mode 100644 index 000000000..9686e478d --- /dev/null +++ b/docs/exe_fail_fast.md | |||
| @@ -0,0 +1,81 @@ | |||
| 1 | # Where the retail executable stops itself on an import's result (RT-5) | ||
| 2 | |||
| 3 | A title treats some results as impossible. It tests the value an import returned and, when it is the failing one, | ||
| 4 | branches to `int3`: MSVC's `__debugbreak`, and the marker it places after a call that does not return. A shim that | ||
| 5 | returns that value at such a site ends the boot there, with no message. This page lists those sites for | ||
| 6 | `game_scarlett_master.exe`, per import: how many there are and which value takes them. It shows which results each shim | ||
| 7 | must get right before a run reaches them. | ||
| 8 | |||
| 9 | Nothing was run. `tools/import_fail_fast.py` reads the file: it finds each import's call sites (through its thunk with | ||
| 10 | `tools/import_call_sites.py`, and as `call [rip+slot]` for the `api-ms-win-*` imports). It then decodes the instructions | ||
| 11 | after each call up to the test of the result and follows both sides of the branch for a few instructions. The method | ||
| 12 | and its limits are in the tool's docstring. No code or data of the executable is quoted here, only names, counts and | ||
| 13 | conditions. Measured on SHA-256 `e95020b2fa4a721db3df59fdecf75621730ac559d8835252f6c3b658d5a08993`. The bindings below | ||
| 14 | are those of `main` `829e5ede`. | ||
| 15 | |||
| 16 | ```powershell | ||
| 17 | python -I tools/import_fail_fast.py game_scarlett_master.exe | ||
| 18 | python -I tools/import_fail_fast.py game_scarlett_master.exe --dll xmem.dll --all --json | ||
| 19 | ``` | ||
| 20 | |||
| 21 | Result: 515 of 587 imports called directly, 27 with a fatal result check, 78 fatal sites. An independent pass with Capstone found the | ||
| 22 | same sites, apart from two `XMemVirtualAlloc` sites that the tool finds and that pass missed. At one, the result is copied | ||
| 23 | to another register before the test. At the other, the failing side reaches `int3` through a `jmp`. | ||
| 24 | |||
| 25 | ## The sites, by how `main` binds the import | ||
| 26 | |||
| 27 | "Stops when" is the result that takes the fatal side. It is written with the register at the width the test reads: | ||
| 28 | `eax < 0` is a failed `HRESULT`, `rax == -1` is `INVALID_HANDLE_VALUE`. | ||
| 29 | |||
| 30 | ### Shims: results to keep | ||
| 31 | |||
| 32 | | Import | Calls | Fatal | Stops when | Note | | ||
| 33 | |---|---:|---:|---|---| | ||
| 34 | | `xmem.dll!XMemVirtualAlloc` | 23 | 14 | `rax == 0` | Since #6908 the shim takes the attribute word and drops the `PAGE_GRAPHICS_*` bits. Since #6919 it takes the 2 MiB page mode (`allocation_type` `0x20003000`), which 4 of these 14 sites pass, reserving it 2 MiB-aligned through `VirtualAlloc2`; the other 10 reach `VirtualAlloc`. A host without the placeholder API (`VirtualAlloc2`, `MapViewOfFile3`) still gets `ERROR_NOT_SUPPORTED` for those 4. The 6 calls with `0x4000` (`MEM_REPLACE_PLACEHOLDER`) or `0x40000` (`MEM_RESERVE_PLACEHOLDER`) that `docs/xmem_exe_calls.md` lists as refused are placeholder windows the shim now makes too; they are not among the 14 | | ||
| 35 | | `XMemGetWorkingSetStatistics` | 3 | 2 | `eax == 0` | The shim returns `FALSE` only for a null output or a failed `GetProcessMemoryInfo`; both sites pass a stack buffer | | ||
| 36 | | `XMemTransferMemory` | 1 | 1 | `eax == 0` | The shim returns `TRUE` | | ||
| 37 | | `CreateFileW` | 13 | 1 | `rax == -1` | One open that has no failure path: the file must exist where `runtime/shims/file_system.cpp` maps it | | ||
| 38 | | `GetModuleHandleW` | 3 | 1 | `rax == 0` | Two calls in a row, for `api-ms-win-core-synch-l1-2-0.dll` and then `kernel32.dll`; the title stops when both give `NULL` | | ||
| 39 | | `_configure_narrow_argv` | 1 | 1 | `eax != 0` | The CRT's start-up; the shim returns 0 | | ||
| 40 | | `d3d12_xs.dll!D3D12ConfigureVirtualMemoryX` | 1 | 1 | `eax < 0` | The shim (#6792) returns `S_OK` | | ||
| 41 | |||
| 42 | ### No binding at `main`: what the default return does | ||
| 43 | |||
| 44 | An import with no shim, host function or bundled module returns 0 under `LEONIDA_UNIMPLEMENTED=log` (the default), and | ||
| 45 | under `fail` too unless `runtime/shims/registry.cpp` lists it as returning an `HRESULT`, which none of these is. | ||
| 46 | |||
| 47 | | Import | Calls | Fatal | Stops when | 0 stops it? | | ||
| 48 | |---|---:|---:|---|---| | ||
| 49 | | `xmem.dll!XMemMapPhysicalPages` | 12 | 3 | `rax == 0` | yes | | ||
| 50 | | `XMemAllocatePhysicalPages` | 4 | 2 | `eax != 1` (1), `eax == 0` (1) | yes, both | | ||
| 51 | | `XMemMapPhysicalPagesScatter` | 2 | 2 | `eax == 0` | yes | | ||
| 52 | | `XMemIsToolsMemAvailable` | 1 | 1 | `eax == 0` | yes, where reached: the function holding the site has 6 callers, and each calls it only after one helper returns true (the first after an allocation failed) | | ||
| 53 | | `AcpHal.dll!ApuCreateHeap` | 1 | 1 | `eax < 0` | no: 0 is `S_OK`, with the output unset | | ||
| 54 | | `GameInput.dll!#1` | 1 | 1 | `eax < 0` | no. The executable imports `GameInput.dll` by ordinal 1 only, and the shim table names `GameInputCreate`. The site zeroes an out pointer before the call and calls the object's `AddRef` after it, so ordinal 1 is `GameInputCreate(IGameInput**)`, which #3410 binds | | ||
| 55 | |||
| 56 | The four xmem rows are the ones a return of 0 stops: 8 sites. | ||
| 57 | |||
| 58 | ### Host and CRT: not failures a shim causes | ||
| 59 | |||
| 60 | | Import | Calls | Fatal | Stops when | What it is | | ||
| 61 | |---|---:|---:|---|---| | ||
| 62 | | `MSVCP140.dll!_Mtx_lock` | 21 | 19 | `eax != 0` | `std::mutex::lock`'s error path | | ||
| 63 | | `VirtualFree` | 23 | 12 | `eax == 0` | Whatever `XMemVirtualAlloc` returns must be memory the host `VirtualFree` releases, or `VirtualFree` needs a shim | | ||
| 64 | | `IsProcessorFeaturePresent` | 3 | 3 | `eax != 0` | `PF_FASTFAIL_AVAILABLE` (`0x17`) before `int 29h`: the CRT's abort path, after the decision to stop | | ||
| 65 | | `GetLogicalProcessorInformation` | 2 | 2 | `eax != 0` (1), `eax == 0` (1) | The size query must fail, then the real call must succeed | | ||
| 66 | | `GetLastError` | 36 | 1 | `eax != 0x7a` | Between those two: the size query's error must be `ERROR_INSUFFICIENT_BUFFER` | | ||
| 67 | | `strcmp` | 464 | 2 | `eax == 0` | The title's own string checks | | ||
| 68 | | `_stricmp` | 160 | 1 | `eax != 0` | as above | | ||
| 69 | | `strrchr` | 32 | 1 | `rax == 0` | as above | | ||
| 70 | | `MSVCP140.dll!_Getcat` (`codecvt<char>`, `ctype<wchar_t>`) | 2 | 2 | `rax == -1` | Locale facets; `msvcp140.dll` binds to the host copy | | ||
| 71 | | `ReadFile` | 2 | 1 | `eax == 0` | Host | | ||
| 72 | | `CreateEventW` | 1 | 1 | `rax == 0` | Host | | ||
| 73 | | `CreateSemaphoreExW` | 2 | 1 | `rax == 0` | Host | | ||
| 74 | | `WS2_32.dll!#115` (`WSAStartup`) | 1 | 1 | `eax != 0` | Host; #6943's offline Winsock shim serves ordinal 115 and must return 0 here | | ||
| 75 | |||
| 76 | ## What this does not show | ||
| 77 | |||
| 78 | A site found here is code that can stop the title, not proof that the boot reaches it: nothing ran. Only | ||
| 79 | straight-line code after each call is read. A result stored and tested later, or a failure path that logs before it | ||
| 80 | stops, is not seen, and a stray call byte pair inside another instruction could add a false site (rare). Each count | ||
| 81 | is a heuristic count that can miss sites or include false matches. #6915 records the stops one run reached, in order. | ||