upleb.uk

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

summaryrefslogtreecommitdiff
path: root/runtime/src/main.cpp
diff options
context:
space:
mode:
authorAslan2142 <jan.trencansky@protonmail.com>2026-11-26 04:08:22 +0100
committerGitHub <noreply@github.com>2026-11-26 04:08:22 +0100
commit0b11d86bc07a9be41aa28793eaa651bec768ddf6 (patch)
tree53e0bbdcace9b8f7b83a550c07d402e03942828e /runtime/src/main.cpp
parent7f3d0095a2d51892bc7048f24505c37168f25c34 (diff)
parentb3e541b224e1d0bb691d8b4b5cc719eeea7c7dd7 (diff)
Merge pull request #2138 from ubiquitarianism/integration/boot-combined
[integration] RT-BOOT-COMBINED: translator fixes + null-barrier fix on main; scripted pad past legal terms to the story load
Diffstat (limited to 'runtime/src/main.cpp')
-rw-r--r--runtime/src/main.cpp53
1 files changed, 40 insertions, 13 deletions
diff --git a/runtime/src/main.cpp b/runtime/src/main.cpp
index 4d483ed59..21551e948 100644
--- a/runtime/src/main.cpp
+++ b/runtime/src/main.cpp
@@ -40,24 +40,51 @@
40 40
41namespace { 41namespace {
42 42
43// The retail executable (1.0.2.1) runs a hang watchdog thread (function at RVA 0x2215a60): when the game's main loop 43// The retail title runs a hang watchdog thread: when the game's main loop has not set its "kick" byte for 30
44// has not set its "kick" byte (RVA 0x71b6331) for 30 one-second ticks, it calls a crash callback and then writes to 44// one-second ticks, it calls a crash callback and then writes to address 0 (`movl $0, 0`). Under the runtime the
45// address 0 (`movl $0, 0` at RVA 0x2215c35). Under the runtime the game thread can legitimately stall for longer than 45// game thread can legitimately stall for longer than that, e.g. while the driver compiles pipelines against a cold
46// that, e.g. while the driver compiles pipelines against a cold cache (first boot after a driver update), and the 46// cache (first boot after a driver update), and the title then kills itself. By default the watchdog stays armed, as
47// title then kills itself. By default the watchdog stays armed, as on the console. With LEONIDA_TITLE_WATCHDOG=0, and 47// on the console. LEONIDA_TITLE_WATCHDOG=0 asks to keep it from firing, as before. The two places that takes are
48// only when that exact trap instruction sits where it does in this build, a runtime thread sets the kick byte twice a 48// measured locally and not kept in the repository: LEONIDA_TITLE_WATCHDOG_KICK="<trap RVA>,<kick RVA>" (hex) names
49// second so the title's watchdog never fires. 49// them, and only with both variables, and only when that exact trap instruction sits at the first RVA, does a
50constexpr std::uint32_t kWatchdogTrapRva = 0x2215c35; 50// runtime thread set the byte at the second twice a second, so the title's watchdog never fires. Either variable
51constexpr std::uint32_t kWatchdogKickRva = 0x71b6331; 51// alone leaves the watchdog armed and says so once.
52constexpr unsigned char kWatchdogTrap[] = {0xC7, 0x04, 0x25, 0, 0, 0, 0, 0, 0, 0, 0}; // movl $0, 0x0 52constexpr unsigned char kWatchdogTrap[] = {0xC7, 0x04, 0x25, 0, 0, 0, 0, 0, 0, 0, 0}; // movl $0, 0x0
53 53
54bool watchdog_rvas(std::uint32_t& trap_rva, std::uint32_t& kick_rva) {
55 char value[64]{};
56 const DWORD n = GetEnvironmentVariableA("LEONIDA_TITLE_WATCHDOG_KICK", value, sizeof(value));
57 if (!n || n >= sizeof(value)) return false;
58 char* rest = nullptr;
59 const unsigned long long trap = std::strtoull(value, &rest, 16);
60 if (!rest || *rest != ',') return false;
61 const unsigned long long kick = std::strtoull(rest + 1, &rest, 16);
62 if (!rest || *rest || !trap || !kick || trap > 0xFFFFFFFFull || kick > 0xFFFFFFFFull) return false;
63 trap_rva = static_cast<std::uint32_t>(trap);
64 kick_rva = static_cast<std::uint32_t>(kick);
65 return true;
66}
67
54void keep_title_watchdog_kicked(std::uint8_t* base) { 68void keep_title_watchdog_kicked(std::uint8_t* base) {
55 char value[4]{}; 69 char keep[4]{};
56 if (GetEnvironmentVariableA("LEONIDA_TITLE_WATCHDOG", value, sizeof(value)) != 1 || value[0] != '0') return; 70 const bool disarm = GetEnvironmentVariableA("LEONIDA_TITLE_WATCHDOG", keep, sizeof(keep)) == 1 && keep[0] == '0';
71 std::uint32_t kWatchdogTrapRva = 0, kWatchdogKickRva = 0;
72 const bool named = watchdog_rvas(kWatchdogTrapRva, kWatchdogKickRva);
73 if (!disarm) {
74 if (named)
75 std::fprintf(stderr, "[rt] loader: LEONIDA_TITLE_WATCHDOG_KICK is set but LEONIDA_TITLE_WATCHDOG is not 0;"
76 " the title's hang watchdog stays armed\n");
77 return;
78 }
79 if (!named) {
80 std::fprintf(stderr, "[rt] loader: LEONIDA_TITLE_WATCHDOG=0 needs LEONIDA_TITLE_WATCHDOG_KICK=<trap RVA>,"
81 "<kick RVA> (hex); the title's hang watchdog stays armed\n");
82 return;
83 }
57 MEMORY_BASIC_INFORMATION trap{}, kick{}; 84 MEMORY_BASIC_INFORMATION trap{}, kick{};
58 if (!VirtualQuery(base + kWatchdogTrapRva, &trap, sizeof(trap)) || trap.State != MEM_COMMIT || 85 if (!VirtualQuery(base + kWatchdogTrapRva, &trap, sizeof(trap)) || trap.State != MEM_COMMIT ||
59 std::memcmp(base + kWatchdogTrapRva, kWatchdogTrap, sizeof(kWatchdogTrap)) != 0) 86 std::memcmp(base + kWatchdogTrapRva, kWatchdogTrap, sizeof(kWatchdogTrap)) != 0)
60 return; // not the build this was measured on: leave the title's watchdog alone 87 return; // not the trap the RVAs name: leave the title's watchdog alone
61 const DWORD writable = PAGE_READWRITE | PAGE_WRITECOPY | PAGE_EXECUTE_READWRITE | PAGE_EXECUTE_WRITECOPY; 88 const DWORD writable = PAGE_READWRITE | PAGE_WRITECOPY | PAGE_EXECUTE_READWRITE | PAGE_EXECUTE_WRITECOPY;
62 if (!VirtualQuery(base + kWatchdogKickRva, &kick, sizeof(kick)) || kick.State != MEM_COMMIT || 89 if (!VirtualQuery(base + kWatchdogKickRva, &kick, sizeof(kick)) || kick.State != MEM_COMMIT ||
63 !(kick.Protect & writable)) 90 !(kick.Protect & writable))
@@ -79,7 +106,7 @@ void keep_title_watchdog_kicked(std::uint8_t* base) {
79 } 106 }
80} 107}
81 108
82// LEONIDA_PEEK="0x9e1dac0:3,0x7446510,0x98f828c" (diagnostic): a thread prints the 8-byte values at these RVAs of the 109// LEONIDA_PEEK="<rva>:3,<rva>,<rva>" (diagnostic): a thread prints the 8-byte values at these RVAs of the
83// title's image (":n" = n consecutive values, at most 32; "RVA>OFF" reads through the pointer stored at the RVA, at 110// title's image (":n" = n consecutive values, at most 32; "RVA>OFF" reads through the pointer stored at the RVA, at
84// pointer + OFF, both hex) every LEONIDA_PEEK_SECONDS (default 10). For answering "what does this 111// pointer + OFF, both hex) every LEONIDA_PEEK_SECONDS (default 10). For answering "what does this
85// global hold at run time" without a debugger: the reverse-engineering notes (docs/re/requests.md) ask for exactly 112// global hold at run time" without a debugger: the reverse-engineering notes (docs/re/requests.md) ask for exactly