diff options
Diffstat (limited to 'runtime/src/main.cpp')
| -rw-r--r-- | runtime/src/main.cpp | 28 |
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. | ||
| 51 | constexpr unsigned char kWatchdogTrap[] = {0xC7, 0x04, 0x25, 0, 0, 0, 0, 0, 0, 0, 0}; // movl $0, 0x0 | 52 | constexpr unsigned char kWatchdogTrap[] = {0xC7, 0x04, 0x25, 0, 0, 0, 0, 0, 0, 0, 0}; // movl $0, 0x0 |
| 52 | 53 | ||
| 53 | bool watchdog_rvas(std::uint32_t& trap_rva, std::uint32_t& kick_rva) { | 54 | bool 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 | ||
| 67 | void keep_title_watchdog_kicked(std::uint8_t* base) { | 68 | void 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 | ||