| 154 | const int desired_signals[3] = {SIGSEGV,SIGILL,SIGABRT}; |
| 155 | namespace DFHack { |
| 156 | void dfhack_crashlog_init() { |
| 157 | // Initialize eventfd flag |
| 158 | crashlog_complete = eventfd(0, EFD_CLOEXEC); |
| 159 | |
| 160 | crashlog_thread = std::thread(dfhack_crashlog_thread); |
| 161 | |
| 162 | for (int signal : desired_signals) { |
| 163 | std::signal(signal, dfhack_crashlog_handle_signal); |
| 164 | } |
| 165 | term_handler = std::set_terminate(dfhack_crashlog_handle_terminate); |
| 166 | |
| 167 | // https://sourceware.org/glibc/manual/latest/html_mono/libc.html#index-backtrace-1 |
| 168 | // backtrace is AsyncSignal-Unsafe due to dynamic loading of libgcc_s |
| 169 | // Using it here ensures it is loaded before use in the signal handler. |
| 170 | [[maybe_unused]] int _ = backtrace(crash_info.backtrace, 1); |
| 171 | } |
| 172 | |
| 173 | void dfhack_crashlog_shutdown() { |
| 174 | shutdown.exchange(true); |