13 #include "pol_global_config.h" 15 #if defined( WINDOWS ) 35 void se_trans_func(
unsigned int n, EXCEPTION_POINTERS* ex )
38 tmp <<
"Structured Exception Detected: 0x" << fmt::hex( n ) <<
"\n" 39 <<
"ExceptionRecord:\n" 40 <<
" Exception Code: 0x" << fmt::hex( ex->ExceptionRecord->ExceptionCode ) <<
"\n" 41 <<
" Exception Flags: 0x" << fmt::hex( ex->ExceptionRecord->ExceptionFlags ) <<
"\n" 42 <<
" Exception Record: 0x" 44 (
long long)( reinterpret_cast<const void*>( ex->ExceptionRecord->ExceptionRecord ) ) )
46 <<
" Exception Address: 0x" 48 (
long long)( reinterpret_cast<const void*>( ex->ExceptionRecord->ExceptionAddress ) ) )
50 <<
" NumberParameters: 0x" << fmt::hex( ex->ExceptionRecord->NumberParameters ) <<
"\n";
52 if ( ex->ExceptionRecord->NumberParameters )
54 tmp <<
" Exception Information:";
55 for (
DWORD i = 0; i < ex->ExceptionRecord->NumberParameters; i++ )
58 _tmp.Format(
"{}{:#X}" ) << ( ( ( i & 7 ) == 0 ) ?
"\n " 60 << ex->ExceptionRecord->ExceptionInformation[i];
69 <<
" ContextFlags: 0x" << fmt::hex( ex->ContextRecord->ContextFlags ) <<
"\n";
70 if ( ex->ContextRecord->ContextFlags & CONTEXT_DEBUG_REGISTERS )
73 <<
" Dr0: 0x" << fmt::hex( ex->ContextRecord->Dr0 ) <<
"\n" 74 <<
" Dr1: 0x" << fmt::hex( ex->ContextRecord->Dr1 ) <<
"\n" 75 <<
" Dr2: 0x" << fmt::hex( ex->ContextRecord->Dr2 ) <<
"\n" 76 <<
" Dr3: 0x" << fmt::hex( ex->ContextRecord->Dr3 ) <<
"\n" 77 <<
" Dr6: 0x" << fmt::hex( ex->ContextRecord->Dr6 ) <<
"\n" 78 <<
" Dr7: 0x" << fmt::hex( ex->ContextRecord->Dr7 ) <<
"\n";
80 if ( ex->ContextRecord->ContextFlags & CONTEXT_SEGMENTS )
83 <<
" SegGs: 0x" << fmt::hex( ex->ContextRecord->SegGs ) <<
"\n" 84 <<
" SegFs: 0x" << fmt::hex( ex->ContextRecord->SegFs ) <<
"\n" 85 <<
" SegEs: 0x" << fmt::hex( ex->ContextRecord->SegEs ) <<
"\n" 86 <<
" SegDs: 0x" << fmt::hex( ex->ContextRecord->SegDs ) <<
"\n";
88 if ( ex->ContextRecord->ContextFlags & CONTEXT_INTEGER )
91 <<
" Edi: 0x" << fmt::hex( ex->ContextRecord->Edi ) <<
"\n" 92 <<
" Esi: 0x" << fmt::hex( ex->ContextRecord->Esi ) <<
"\n" 93 <<
" Ebx: 0x" << fmt::hex( ex->ContextRecord->Ebx ) <<
"\n" 94 <<
" Edx: 0x" << fmt::hex( ex->ContextRecord->Edx ) <<
"\n" 95 <<
" Ecx: 0x" << fmt::hex( ex->ContextRecord->Ecx ) <<
"\n" 96 <<
" Eax: 0x" << fmt::hex( ex->ContextRecord->Eax ) <<
"\n";
98 if ( ex->ContextRecord->ContextFlags & CONTEXT_CONTROL )
101 <<
" Ebp: 0x" << fmt::hex( ex->ContextRecord->Ebp ) <<
"\n" 102 <<
" Eip: 0x" << fmt::hex( ex->ContextRecord->Eip ) <<
"\n" 103 <<
" SegCs: 0x" << fmt::hex( ex->ContextRecord->SegCs ) <<
"\n" 104 <<
" EFlags: 0x" << fmt::hex( ex->ContextRecord->EFlags ) <<
"\n" 105 <<
" Esp: 0x" << fmt::hex( ex->ContextRecord->Esp ) <<
"\n" 106 <<
" SegSs: 0x" << fmt::hex( ex->ContextRecord->SegSs ) <<
"\n";
111 DWORD eip = ex->ContextRecord->Eip;
117 tmp <<
" EIP RETADDR\n";
118 int levelsleft = 100;
119 while ( ebp && levelsleft-- )
121 tmp <<
" 0x" << fmt::hex( eip );
123 if ( !IsBadReadPtr( ebp,
sizeof *ebp ) )
125 new_ebp = (
DWORD*)*ebp;
129 tmp <<
"[Can't read stack!]\n";
132 if ( !IsBadReadPtr( ebp + 1,
sizeof *ebp ) )
134 tmp <<
" 0x" << fmt::hex( *( ebp + 1 ) );
135 new_eip = *( ebp + 1 );
139 tmp <<
"[Can't read stack!]\n";
150 if ( n == EXCEPTION_ACCESS_VIOLATION )
152 throw access_violation();
156 throw structured_exception( n );
161 static bool in_ex_handler =
false;
162 void alt_se_trans_func(
unsigned int u, _EXCEPTION_POINTERS* pExp )
171 in_ex_handler =
true;
172 POLLOG_INFO.Format(
"Structured exception in {} compiled on {} at {}\n" )
176 in_ex_handler =
false;
178 throw structured_exception( u );
183 if ( !IsDebuggerPresent() )
185 _set_se_translator( alt_se_trans_func );
static LONG WINAPI MSJUnhandledExceptionFilter(PEXCEPTION_POINTERS pExceptionInfo)
typedef DWORD(WINAPI *__SymGetOptions)(VOID)
void InstallOldStructuredExceptionHandler(void)
static std::string build_datetime()