diff options
| author | ubiquitarianism <283527159+ubiquitarianism@users.noreply.github.com> | 2026-11-25 01:00:37 -0500 |
|---|---|---|
| committer | ubiquitarianism <283527159+ubiquitarianism@users.noreply.github.com> | 2026-11-25 01:00:37 -0500 |
| commit | f0611b752fd2c7b52f25688be7d6c17909ee3533 (patch) | |
| tree | b33bba16c7c872448d9ed0224402b075fb770a4d /runtime/src/main.cpp | |
| parent | 3f220075079a3d21d91bd21bf19e1d3122697eff (diff) | |
Remove the title's executable addresses #984 brought in; read them from the environment
#984 (273b3bdf9) put RVAs and file offsets of the retail executable into code, docs and scripts.
The code paths that need one now read it from an environment variable and are off when it is
unset; the docs and examples say the location is measured locally.
- runtime/src/main.cpp: the hang-watchdog kick takes its trap and kick RVAs from
LEONIDA_TITLE_WATCHDOG_KICK="<trap RVA>,<kick RVA>" (hex), still only when the trap
instruction is at the first one. Unset, the watchdog stays armed, as before by default;
LEONIDA_TITLE_WATCHDOG=1 keeps it armed, and LEONIDA_TITLE_WATCHDOG=0 without the RVAs says
once that it needs them. The LEONIDA_PEEK example uses placeholders.
- runtime/shims/startup_trace.h: the transient-pool dump fires at the int3 that
LEONIDA_POOL_DIAG_AT names (`<module>+0x<offset>`, as the trace prints it), off when unset.
- scripts/windows-boot/boot.ps1: LEONIDA_PEEK's default comes from LEONIDA_GAME_STATE_RVA and
LEONIDA_SESSION_STATE_RVA (no peek when unset), and the RESULT digest matches those values;
the examples and README use placeholders.
- runtime/README.md documents LEONIDA_TITLE_WATCHDOG_KICK and LEONIDA_POOL_DIAG_AT.
- docs/fspx.md, docs/d3d12_vulkan.md, docs/movies.md, docs/embedded_shaders.md and a comment in
runtime/shims/d3d12_xs_alloc_size.h drop the addresses and offsets.
This follows the same change on the earlier integration branch (#1495).
Diffstat (limited to 'runtime/src/main.cpp')
| -rw-r--r-- | runtime/src/main.cpp | 49 |
1 files changed, 35 insertions, 14 deletions
diff --git a/runtime/src/main.cpp b/runtime/src/main.cpp index 8e3767740..83f5bd70d 100644 --- a/runtime/src/main.cpp +++ b/runtime/src/main.cpp | |||
| @@ -32,24 +32,45 @@ | |||
| 32 | 32 | ||
| 33 | namespace { | 33 | namespace { |
| 34 | 34 | ||
| 35 | // The retail executable (1.0.2.1) runs a hang watchdog thread (function at RVA 0x2215a60): when the game's main loop | 35 | // The retail title runs a hang watchdog thread: when the game's main loop has not set its "kick" byte for 30 |
| 36 | // has not set its "kick" byte (RVA 0x71b6331) for 30 one-second ticks, it calls a crash callback and then writes to | 36 | // one-second ticks, it calls a crash callback and then writes to address 0 (`movl $0, 0`). Under the runtime the |
| 37 | // address 0 (`movl $0, 0` at RVA 0x2215c35). Under the runtime the game thread can legitimately stall for longer than | 37 | // game thread can legitimately stall for longer than that, e.g. while the driver compiles pipelines against a cold |
| 38 | // that, e.g. while the driver compiles pipelines against a cold cache (first boot after a driver update), and the | 38 | // cache (first boot after a driver update), and the title then kills itself. By default the watchdog stays armed, as |
| 39 | // title then kills itself. By default the watchdog stays armed, as on the console. With LEONIDA_TITLE_WATCHDOG=0, and | 39 | // on the console. The two places are measured locally and not kept in the repository: |
| 40 | // only when that exact trap instruction sits where it does in this build, a runtime thread sets the kick byte twice a | 40 | // LEONIDA_TITLE_WATCHDOG_KICK="<trap RVA>,<kick RVA>" (hex) names them, and only when that exact trap instruction |
| 41 | // second so the title's watchdog never fires. | 41 | // sits at the first one does a runtime thread set the byte at the second twice a second, so the title's watchdog |
| 42 | constexpr std::uint32_t kWatchdogTrapRva = 0x2215c35; | 42 | // never fires. Unset, or with LEONIDA_TITLE_WATCHDOG=1, the watchdog stays armed. |
| 43 | constexpr std::uint32_t kWatchdogKickRva = 0x71b6331; | ||
| 44 | constexpr unsigned char kWatchdogTrap[] = {0xC7, 0x04, 0x25, 0, 0, 0, 0, 0, 0, 0, 0}; // movl $0, 0x0 | 43 | constexpr unsigned char kWatchdogTrap[] = {0xC7, 0x04, 0x25, 0, 0, 0, 0, 0, 0, 0, 0}; // movl $0, 0x0 |
| 45 | 44 | ||
| 45 | bool watchdog_rvas(std::uint32_t& trap_rva, std::uint32_t& kick_rva) { | ||
| 46 | char value[64]{}; | ||
| 47 | const DWORD n = GetEnvironmentVariableA("LEONIDA_TITLE_WATCHDOG_KICK", value, sizeof(value)); | ||
| 48 | if (!n || n >= sizeof(value)) return false; | ||
| 49 | char* rest = nullptr; | ||
| 50 | const unsigned long long trap = std::strtoull(value, &rest, 16); | ||
| 51 | if (!rest || *rest != ',') return false; | ||
| 52 | const unsigned long long kick = std::strtoull(rest + 1, &rest, 16); | ||
| 53 | if (!rest || *rest || !trap || !kick || trap > 0xFFFFFFFFull || kick > 0xFFFFFFFFull) return false; | ||
| 54 | trap_rva = static_cast<std::uint32_t>(trap); | ||
| 55 | kick_rva = static_cast<std::uint32_t>(kick); | ||
| 56 | return true; | ||
| 57 | } | ||
| 58 | |||
| 46 | void keep_title_watchdog_kicked(std::uint8_t* base) { | 59 | void keep_title_watchdog_kicked(std::uint8_t* base) { |
| 47 | char value[4]{}; | 60 | char keep[4]{}; |
| 48 | if (GetEnvironmentVariableA("LEONIDA_TITLE_WATCHDOG", value, sizeof(value)) != 1 || value[0] != '0') return; | 61 | const DWORD keep_length = GetEnvironmentVariableA("LEONIDA_TITLE_WATCHDOG", keep, sizeof(keep)); |
| 62 | if (keep_length == 1 && keep[0] == '1') return; | ||
| 63 | std::uint32_t kWatchdogTrapRva = 0, kWatchdogKickRva = 0; | ||
| 64 | if (!watchdog_rvas(kWatchdogTrapRva, kWatchdogKickRva)) { | ||
| 65 | if (keep_length == 1 && keep[0] == '0') | ||
| 66 | std::fprintf(stderr, "[rt] loader: LEONIDA_TITLE_WATCHDOG=0 needs LEONIDA_TITLE_WATCHDOG_KICK=<trap RVA>," | ||
| 67 | "<kick RVA> (hex); the title's hang watchdog stays armed\n"); | ||
| 68 | return; | ||
| 69 | } | ||
| 49 | MEMORY_BASIC_INFORMATION trap{}, kick{}; | 70 | MEMORY_BASIC_INFORMATION trap{}, kick{}; |
| 50 | if (!VirtualQuery(base + kWatchdogTrapRva, &trap, sizeof(trap)) || trap.State != MEM_COMMIT || | 71 | if (!VirtualQuery(base + kWatchdogTrapRva, &trap, sizeof(trap)) || trap.State != MEM_COMMIT || |
| 51 | std::memcmp(base + kWatchdogTrapRva, kWatchdogTrap, sizeof(kWatchdogTrap)) != 0) | 72 | std::memcmp(base + kWatchdogTrapRva, kWatchdogTrap, sizeof(kWatchdogTrap)) != 0) |
| 52 | return; // not the build this was measured on: leave the title's watchdog alone | 73 | return; // not the trap the RVAs name: leave the title's watchdog alone |
| 53 | const DWORD writable = PAGE_READWRITE | PAGE_WRITECOPY | PAGE_EXECUTE_READWRITE | PAGE_EXECUTE_WRITECOPY; | 74 | const DWORD writable = PAGE_READWRITE | PAGE_WRITECOPY | PAGE_EXECUTE_READWRITE | PAGE_EXECUTE_WRITECOPY; |
| 54 | if (!VirtualQuery(base + kWatchdogKickRva, &kick, sizeof(kick)) || kick.State != MEM_COMMIT || | 75 | if (!VirtualQuery(base + kWatchdogKickRva, &kick, sizeof(kick)) || kick.State != MEM_COMMIT || |
| 55 | !(kick.Protect & writable)) | 76 | !(kick.Protect & writable)) |
| @@ -67,11 +88,11 @@ void keep_title_watchdog_kicked(std::uint8_t* base) { | |||
| 67 | const_cast<std::uint8_t*>(byte), 0, nullptr); | 88 | const_cast<std::uint8_t*>(byte), 0, nullptr); |
| 68 | if (thread) { | 89 | if (thread) { |
| 69 | CloseHandle(thread); | 90 | CloseHandle(thread); |
| 70 | std::fprintf(stderr, "[rt] loader: keeping the title's hang watchdog kicked (LEONIDA_TITLE_WATCHDOG=0; unset or 1 keeps it armed)\n"); | 91 | std::fprintf(stderr, "[rt] loader: keeping the title's hang watchdog kicked (LEONIDA_TITLE_WATCHDOG_KICK)\n"); |
| 71 | } | 92 | } |
| 72 | } | 93 | } |
| 73 | 94 | ||
| 74 | // LEONIDA_PEEK="0x9e1dac0:3,0x7446510,0x98f828c" (diagnostic): a thread prints the 8-byte values at these RVAs of the | 95 | // LEONIDA_PEEK="<rva>:3,<rva>,<rva>" (diagnostic): a thread prints the 8-byte values at these RVAs of the |
| 75 | // title's image (":n" = n consecutive values) every LEONIDA_PEEK_SECONDS (default 10). For answering "what does this | 96 | // title's image (":n" = n consecutive values) every LEONIDA_PEEK_SECONDS (default 10). For answering "what does this |
| 76 | // global hold at run time" without a debugger: the reverse-engineering notes (docs/re/requests.md) ask for exactly | 97 | // global hold at run time" without a debugger: the reverse-engineering notes (docs/re/requests.md) ask for exactly |
| 77 | // that. Reads are checked; nothing is written. | 98 | // that. Reads are checked; nothing is written. |