| 141 | } |
| 142 | |
| 143 | static LONG WINAPI crash_handler_callback(EXCEPTION_POINTERS *ep) { |
| 144 | DWORD code = ep->ExceptionRecord->ExceptionCode; |
| 145 | if (!is_fatal_exception(code)) |
| 146 | return EXCEPTION_CONTINUE_SEARCH; |
| 147 | static volatile long in_handler = 0; |
| 148 | if (InterlockedExchange(&in_handler, 1)) { |
| 149 | _exit(3); |
| 150 | } |
| 151 | if (code == EXCEPTION_STACK_OVERFLOW) { |
| 152 | static const char msg[] = "\nCRASH: EXCEPTION_STACK_OVERFLOW (0xC00000FD)\n" |
| 153 | " (stack overflow - stack trace unavailable)\n"; |
| 154 | WriteFile(GetStdHandle(STD_ERROR_HANDLE), msg, sizeof(msg) - 1, NULL, NULL); |
| 155 | _exit(3); |
| 156 | } |
| 157 | fprintf(stderr, "\nCRASH: %s (0x%08lX) at address 0x%llx\n", |
| 158 | exception_code_to_string(code), (unsigned long)code, |
| 159 | (unsigned long long)ep->ExceptionRecord->ExceptionAddress); |
| 160 | if (code == EXCEPTION_ACCESS_VIOLATION && ep->ExceptionRecord->NumberParameters >= 2) { |
| 161 | fprintf(stderr, " %s address 0x%llx\n", |
| 162 | ep->ExceptionRecord->ExceptionInformation[0] ? "writing" : "reading", |
| 163 | (unsigned long long)ep->ExceptionRecord->ExceptionInformation[1]); |
| 164 | } |
| 165 | print_stack_trace(ep->ContextRecord); |
| 166 | fflush(stderr); |
| 167 | _exit(3); |
| 168 | return EXCEPTION_EXECUTE_HANDLER; |
| 169 | } |
| 170 | |
| 171 | void install_crash_handler() { |
| 172 | SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX); |
nothing calls this directly
no test coverage detected