|
2 | 2 | #include "loader/component_loader.hpp" |
3 | 3 | #include "game/game.hpp" |
4 | 4 |
|
5 | | -#include "component/utils/scheduler.hpp" |
| 5 | +#include "scheduler.hpp" |
6 | 6 |
|
7 | 7 | #include <utils/hook.hpp> |
8 | 8 | #include <utils/io.hpp> |
9 | 9 | #include <utils/string.hpp> |
10 | 10 | #include <utils/thread.hpp> |
11 | | -#include <atomic> |
12 | | -#include <thread> |
13 | 11 |
|
14 | 12 | #include <exception/minidump.hpp> |
15 | 13 |
|
16 | 14 | namespace exception |
17 | 15 | { |
18 | 16 | namespace |
19 | 17 | { |
20 | | - using namespace std::chrono_literals; |
21 | | - |
22 | | - std::atomic<unsigned long long> last_heartbeat_ms{0}; |
23 | | - std::atomic<bool> watchdog_running{false}; |
24 | | - |
25 | 18 | thread_local struct |
26 | 19 | { |
27 | 20 | DWORD code = 0; |
@@ -94,21 +87,12 @@ namespace exception |
94 | 87 |
|
95 | 88 | void write_minidump(const LPEXCEPTION_POINTERS exceptioninfo) |
96 | 89 | { |
97 | | - utils::io::create_directory("minidumps"); |
98 | 90 | const std::string crash_name = utils::string::va("minidumps/consolation-crash-%s.dmp", |
99 | 91 | utils::string::get_timestamp().data()); |
100 | 92 | create_minidump(exceptioninfo); |
101 | 93 | utils::io::write_file(crash_name, create_minidump(exceptioninfo), false); |
102 | 94 | } |
103 | 95 |
|
104 | | - void write_hang_dump() |
105 | | - { |
106 | | - utils::io::create_directory("minidumps"); |
107 | | - const std::string crash_name = utils::string::va("minidumps/consolation-hang-%s.dmp", |
108 | | - utils::string::get_timestamp().data()); |
109 | | - utils::io::write_file(crash_name, create_minidump(), false); |
110 | | - } |
111 | | - |
112 | 96 | bool is_harmless_error(const LPEXCEPTION_POINTERS exceptioninfo) |
113 | 97 | { |
114 | 98 | const auto code = exceptioninfo->ExceptionRecord->ExceptionCode; |
@@ -136,77 +120,17 @@ namespace exception |
136 | 120 | // Don't register anything here... |
137 | 121 | return &exception_filter; |
138 | 122 | } |
139 | | - |
140 | | - bool command_line_has(const char* token) |
141 | | - { |
142 | | - const auto* const cmd = GetCommandLineA(); |
143 | | - return cmd && token && std::strstr(cmd, token) != nullptr; |
144 | | - } |
145 | | - |
146 | | - void start_watchdog() |
147 | | - { |
148 | | - if (watchdog_running.exchange(true)) |
149 | | - { |
150 | | - return; |
151 | | - } |
152 | | - |
153 | | - last_heartbeat_ms = GetTickCount64(); |
154 | | - |
155 | | - std::thread([]() |
156 | | - { |
157 | | - constexpr auto timeout_ms = 10000ULL; |
158 | | - |
159 | | - while (true) |
160 | | - { |
161 | | - std::this_thread::sleep_for(1s); |
162 | | - const auto now = GetTickCount64(); |
163 | | - const auto last = last_heartbeat_ms.load(); |
164 | | - if (now - last >= timeout_ms) |
165 | | - { |
166 | | - write_hang_dump(); |
167 | | - TerminateProcess(GetCurrentProcess(), 0xDEAD); |
168 | | - } |
169 | | - } |
170 | | - }).detach(); |
171 | | - |
172 | | - scheduler::loop([]() |
173 | | - { |
174 | | - last_heartbeat_ms = GetTickCount64(); |
175 | | - }, scheduler::main, 250ms); |
176 | | - } |
177 | 123 | } |
178 | 124 |
|
179 | 125 | class component final : public component_interface |
180 | 126 | { |
181 | 127 | public: |
182 | 128 | void post_load() override |
183 | 129 | { |
184 | | - if (command_line_has("-no_crashdump")) |
185 | | - { |
186 | | - return; |
187 | | - } |
188 | | - |
189 | | - if (!command_line_has("-no_watchdog")) |
190 | | - { |
191 | | - start_watchdog(); |
192 | | - } |
193 | | - |
194 | | - const auto enable_handler = []() |
195 | | - { |
196 | | - SetUnhandledExceptionFilter(exception_filter); |
197 | | - utils::hook::jump(reinterpret_cast<uintptr_t>(&SetUnhandledExceptionFilter), set_unhandled_exception_filter_stub); |
198 | | - }; |
199 | | - |
200 | | - if (command_line_has("-crashdump")) |
201 | | - { |
202 | | - enable_handler(); |
203 | | - return; |
204 | | - } |
205 | | - |
206 | | - // Delay hook to avoid interfering with early boot while still capturing later crashes. |
207 | | - scheduler::once(enable_handler, scheduler::main, 15s); |
| 130 | + SetUnhandledExceptionFilter(exception_filter); |
| 131 | + utils::hook::jump(reinterpret_cast<uintptr_t>(&SetUnhandledExceptionFilter), set_unhandled_exception_filter_stub); |
208 | 132 | } |
209 | 133 | }; |
210 | 134 | } |
211 | 135 |
|
212 | | -REGISTER_COMPONENT(exception::component) |
| 136 | +//REGISTER_COMPONENT(exception::component) |
0 commit comments