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:
authorJan Trencansky <jan.trencansky@protonmail.com>2026-11-24 20:32:26 -0500
committerJan Trencansky <jan.trencansky@protonmail.com>2026-11-24 20:32:26 -0500
commit71a783e56fb6eb591849b5c9fb6618ed3af3f595 (patch)
tree5b53f56caeb5d8528938e0a3683a5fc3d4b8658f /runtime/src/main.cpp
parent461efcde4d5d791fe19b6d70c9e26f6ed776b052 (diff)
main: the title's hang watchdog stays armed unless LEONIDA_TITLE_WATCHDOG=0
The retail title runs its own hang watchdog: when the game's main loop has not reported for 30 seconds, it ends itself. #984 kept that watchdog from firing by default, because under the runtime the game thread can wait longer than that, for example while the driver compiles pipelines on the first boot after a driver update. By the maintainer's decision the watchdog now stays armed by default, as on the console, so a real hang still ends the run. LEONIDA_TITLE_WATCHDOG=0 turns on the runtime thread that keeps it from firing; as before, it only acts in the build the watchdog was measured in. The README's environment table and the log line say the same. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'runtime/src/main.cpp')
-rw-r--r--runtime/src/main.cpp11
1 files changed, 6 insertions, 5 deletions
diff --git a/runtime/src/main.cpp b/runtime/src/main.cpp
index b346bc68a..6357dd0b0 100644
--- a/runtime/src/main.cpp
+++ b/runtime/src/main.cpp
@@ -36,15 +36,16 @@ namespace {
36// has not set its "kick" byte (RVA 0x71b6331) for 30 one-second ticks, it calls a crash callback and then writes to 36// has not set its "kick" byte (RVA 0x71b6331) for 30 one-second ticks, it calls a crash callback and then writes to
37// address 0 (`movl $0, 0` at RVA 0x2215c35). Under the runtime the game thread can legitimately stall for longer than 37// address 0 (`movl $0, 0` at RVA 0x2215c35). Under the runtime the game thread can legitimately stall for longer than
38// that, e.g. while the driver compiles pipelines against a cold cache (first boot after a driver update), and the 38// that, e.g. while the driver compiles pipelines against a cold cache (first boot after a driver update), and the
39// title then kills itself. Unless LEONIDA_TITLE_WATCHDOG=1, and only when that exact trap instruction sits where it 39// title then kills itself. By default the watchdog stays armed, as on the console. With LEONIDA_TITLE_WATCHDOG=0, and
40// does in this build, a runtime thread sets the kick byte twice a second so the title's watchdog never fires. 40// only when that exact trap instruction sits where it does in this build, a runtime thread sets the kick byte twice a
41// second so the title's watchdog never fires.
41constexpr std::uint32_t kWatchdogTrapRva = 0x2215c35; 42constexpr std::uint32_t kWatchdogTrapRva = 0x2215c35;
42constexpr std::uint32_t kWatchdogKickRva = 0x71b6331; 43constexpr std::uint32_t kWatchdogKickRva = 0x71b6331;
43constexpr unsigned char kWatchdogTrap[] = {0xC7, 0x04, 0x25, 0, 0, 0, 0, 0, 0, 0, 0}; // movl $0, 0x0 44constexpr unsigned char kWatchdogTrap[] = {0xC7, 0x04, 0x25, 0, 0, 0, 0, 0, 0, 0, 0}; // movl $0, 0x0
44 45
45void keep_title_watchdog_kicked(std::uint8_t* base) { 46void keep_title_watchdog_kicked(std::uint8_t* base) {
46 char keep[4]{}; 47 char value[4]{};
47 if (GetEnvironmentVariableA("LEONIDA_TITLE_WATCHDOG", keep, sizeof(keep)) == 1 && keep[0] == '1') return; 48 if (GetEnvironmentVariableA("LEONIDA_TITLE_WATCHDOG", value, sizeof(value)) != 1 || value[0] != '0') return;
48 MEMORY_BASIC_INFORMATION trap{}, kick{}; 49 MEMORY_BASIC_INFORMATION trap{}, kick{};
49 if (!VirtualQuery(base + kWatchdogTrapRva, &trap, sizeof(trap)) || trap.State != MEM_COMMIT || 50 if (!VirtualQuery(base + kWatchdogTrapRva, &trap, sizeof(trap)) || trap.State != MEM_COMMIT ||
50 std::memcmp(base + kWatchdogTrapRva, kWatchdogTrap, sizeof(kWatchdogTrap)) != 0) 51 std::memcmp(base + kWatchdogTrapRva, kWatchdogTrap, sizeof(kWatchdogTrap)) != 0)
@@ -66,7 +67,7 @@ void keep_title_watchdog_kicked(std::uint8_t* base) {
66 const_cast<std::uint8_t*>(byte), 0, nullptr); 67 const_cast<std::uint8_t*>(byte), 0, nullptr);
67 if (thread) { 68 if (thread) {
68 CloseHandle(thread); 69 CloseHandle(thread);
69 std::fprintf(stderr, "[rt] loader: keeping the title's hang watchdog kicked (LEONIDA_TITLE_WATCHDOG=1 keeps it armed)\n"); 70 std::fprintf(stderr, "[rt] loader: keeping the title's hang watchdog kicked (LEONIDA_TITLE_WATCHDOG=0; unset or 1 keeps it armed)\n");
70 } 71 }
71} 72}
72 73