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:
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 b57bbca29..a870cb814 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