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:38:14 -0500
committerJan Trencansky <jan.trencansky@protonmail.com>2026-11-24 20:38:14 -0500
commitc5510733e9696cac6f3839b472e517725607c1d5 (patch)
tree110af0af7587dd3f58954594684e198ad56c4b4b /runtime/src/main.cpp
parent7fcbf1fde67dffb641e0fa018aca80c15558561c (diff)
parent18a22c1aefa227fd2eda047bab3385147d569f9d (diff)
Merge main (with #984) into RT-QUEUE31 (#968)
main now contains the #984 merge this branch was built on, plus its last commits (the five tests of #984 settled under Wine, and the title's hang watchdog staying armed by default). No conflicts: runtime/test/xmem_test.cpp and docs/d3d12_vulkan.md merged cleanly, with test_copy_page_mappings and test_copy_page_mappings_cpu_view each defined and called once. 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