/
klischa
/
AstraScanner2
Обзор
Документация
Войти
/
klischa
/
AstraScanner2
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/crash_handler.h
84 строки
3 KB
k k
fix: purecallHandler uses RaiseException instead of abort()
14 июл 2026, 23:16
14 июл 2026, 23:16
e1a688e
Код
Авторство
О чём код?
#pragma once #ifndef CRASH_HANDLER_H #define CRASH_HANDLER_H #include <windows.h> #include <dbghelp.h> #include <QString> #include <QDateTime> #include <QDir> #include <QDebug> #include <cstdio> #pragma comment(lib, "dbghelp.lib") static char s_crashHandlerStack[64 * 1024]; inline LONG WINAPI crashHandler(PEXCEPTION_POINTERS info) { QDir().mkpath("crash_dumps"); QString filename = QString("crash_dumps/crash_%1_%2.dmp") .arg(QDateTime::currentDateTime().toString("yyyyMMdd_HHmmss")) .arg(GetCurrentProcessId()); HANDLE hFile = CreateFileW( reinterpret_cast<LPCWSTR>(filename.utf16()), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if (hFile != INVALID_HANDLE_VALUE) { MINIDUMP_EXCEPTION_INFORMATION mei = {}; mei.ThreadId = GetCurrentThreadId(); mei.ExceptionPointers = info; mei.ClientPointers = FALSE; MiniDumpWriteDump( GetCurrentProcess(), GetCurrentProcessId(), hFile, MiniDumpWithFullMemory, &mei, NULL, NULL); CloseHandle(hFile); fprintf(stderr, "\n=== CRASH DUMP SAVED: %s ===\n", filename.toLocal8Bit().constData()); fflush(stderr); } if (info && info->ExceptionRecord) { fprintf(stderr, "Exception code: 0x%08X at %p\n", info->ExceptionRecord->ExceptionCode, info->ExceptionRecord->ExceptionAddress); fflush(stderr); } return EXCEPTION_EXECUTE_HANDLER; } inline void __cdecl purecallHandler() { fprintf(stderr, "\n=== PURE VIRTUAL CALL DETECTED ===\n"); fflush(stderr); // Raise SEH exception so crashHandler creates minidump // 0xE0434352 = CLR exception code, non-continuable RaiseException(0xE0434352, EXCEPTION_NONCONTINUABLE, 0, NULL); } inline LONG WINAPI vectoredHandler(EXCEPTION_POINTERS* info) { if (info && info->ExceptionRecord) { DWORD code = info->ExceptionRecord->ExceptionCode; if (code == 0xE06D7363 || code == 0x406D1388 || code == 0x80000003) return EXCEPTION_CONTINUE_SEARCH; fprintf(stderr, "[VECTORED] 0x%08X at %p\n", code, info->ExceptionRecord->ExceptionAddress); fflush(stderr); } return EXCEPTION_CONTINUE_SEARCH; } inline void installCrashHandler() { ULONG stackSize = sizeof(s_crashHandlerStack); SetThreadStackGuarantee(&stackSize); _set_purecall_handler(purecallHandler); AddVectoredExceptionHandler(1, vectoredHandler); SetUnhandledExceptionFilter(crashHandler); } #endif