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-25 21:55:15 -0500
committerJan Trencansky <jan.trencansky@protonmail.com>2026-11-25 21:55:15 -0500
commit7b1fe62850f69bc3ad0b3176aea8dda8168867ea (patch)
tree734dfcca22ad613de802c7cdfe78290b243ef409 /runtime/src/main.cpp
parentd09286f62401917641de097ae8d700f13a405cfd (diff)
Keep main's watchdog switch and say where the peek default went
f0611b752 took the executable's addresses out of the code. Two behaviours changed with it; the removal stays, the changes are now explicit: - runtime/src/main.cpp: the watchdog kick runs again only with LEONIDA_TITLE_WATCHDOG=0, as on main; LEONIDA_TITLE_WATCHDOG_KICK only supplies the two RVAs it needs. Either variable alone leaves the watchdog armed and the loader says so once (before this commit the kick ran whenever LEONIDA_TITLE_WATCHDOG_KICK was set). - scripts/windows-boot/boot.ps1 no longer has the game- and session-state RVAs built in, so LEONIDA_PEEK has no default and the RESULT states read "?" unless LEONIDA_GAME_STATE_RVA and LEONIDA_SESSION_STATE_RVA are set. The script now warns when they are not, and runtime/README.md (LEONIDA_PEEK, LEONIDA_TITLE_WATCHDOG and _KICK rows), scripts/windows-boot/README.md and docs/first_run_ui.md say so. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'runtime/src/main.cpp')
-rw-r--r--runtime/src/main.cpp28
1 files changed, 17 insertions, 11 deletions
diff --git a/runtime/src/main.cpp b/runtime/src/main.cpp
index 1550039f4..21551e948 100644
--- a/runtime/src/main.cpp
+++ b/runtime/src/main.cpp
@@ -44,10 +44,11 @@ namespace {
44// one-second ticks, it calls a crash callback and then writes to address 0 (`movl $0, 0`). Under the runtime the 44// one-second ticks, it calls a crash callback and then writes to address 0 (`movl $0, 0`). Under the runtime the
45// game thread can legitimately stall for longer than that, e.g. while the driver compiles pipelines against a cold 45// game thread can legitimately stall for longer than that, e.g. while the driver compiles pipelines against a cold
46// cache (first boot after a driver update), and the title then kills itself. By default the watchdog stays armed, as 46// cache (first boot after a driver update), and the title then kills itself. By default the watchdog stays armed, as
47// on the console. The two places are measured locally and not kept in the repository: 47// on the console. LEONIDA_TITLE_WATCHDOG=0 asks to keep it from firing, as before. The two places that takes are
48// LEONIDA_TITLE_WATCHDOG_KICK="<trap RVA>,<kick RVA>" (hex) names them, and only when that exact trap instruction 48// measured locally and not kept in the repository: LEONIDA_TITLE_WATCHDOG_KICK="<trap RVA>,<kick RVA>" (hex) names
49// sits at the first one does a runtime thread set the byte at the second twice a second, so the title's watchdog 49// them, and only with both variables, and only when that exact trap instruction sits at the first RVA, does a
50// never fires. Unset, or with LEONIDA_TITLE_WATCHDOG=1, the watchdog stays armed. 50// runtime thread set the byte at the second twice a second, so the title's watchdog never fires. Either variable
51// alone leaves the watchdog armed and says so once.
51constexpr 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
52 53
53bool watchdog_rvas(std::uint32_t& trap_rva, std::uint32_t& kick_rva) { 54bool watchdog_rvas(std::uint32_t& trap_rva, std::uint32_t& kick_rva) {
@@ -66,13 +67,18 @@ bool watchdog_rvas(std::uint32_t& trap_rva, std::uint32_t& kick_rva) {
66 67
67void keep_title_watchdog_kicked(std::uint8_t* base) { 68void keep_title_watchdog_kicked(std::uint8_t* base) {
68 char keep[4]{}; 69 char keep[4]{};
69 const DWORD keep_length = GetEnvironmentVariableA("LEONIDA_TITLE_WATCHDOG", keep, sizeof(keep)); 70 const bool disarm = GetEnvironmentVariableA("LEONIDA_TITLE_WATCHDOG", keep, sizeof(keep)) == 1 && keep[0] == '0';
70 if (keep_length == 1 && keep[0] == '1') return;
71 std::uint32_t kWatchdogTrapRva = 0, kWatchdogKickRva = 0; 71 std::uint32_t kWatchdogTrapRva = 0, kWatchdogKickRva = 0;
72 if (!watchdog_rvas(kWatchdogTrapRva, kWatchdogKickRva)) { 72 const bool named = watchdog_rvas(kWatchdogTrapRva, kWatchdogKickRva);
73 if (keep_length == 1 && keep[0] == '0') 73 if (!disarm) {
74 std::fprintf(stderr, "[rt] loader: LEONIDA_TITLE_WATCHDOG=0 needs LEONIDA_TITLE_WATCHDOG_KICK=<trap RVA>," 74 if (named)
75 "<kick RVA> (hex); the title's hang watchdog stays armed\n"); 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");
76 return; 82 return;
77 } 83 }
78 MEMORY_BASIC_INFORMATION trap{}, kick{}; 84 MEMORY_BASIC_INFORMATION trap{}, kick{};
@@ -96,7 +102,7 @@ void keep_title_watchdog_kicked(std::uint8_t* base) {
96 const_cast<std::uint8_t*>(byte), 0, nullptr); 102 const_cast<std::uint8_t*>(byte), 0, nullptr);
97 if (thread) { 103 if (thread) {
98 CloseHandle(thread); 104 CloseHandle(thread);
99 std::fprintf(stderr, "[rt] loader: keeping the title's hang watchdog kicked (LEONIDA_TITLE_WATCHDOG_KICK)\n"); 105 std::fprintf(stderr, "[rt] loader: keeping the title's hang watchdog kicked (LEONIDA_TITLE_WATCHDOG=0; unset or 1 keeps it armed)\n");
100 } 106 }
101} 107}
102 108