Use SetUnhandledExceptionFilter instead of vectored exceptions

This commit is contained in:
Joshua Kriegshauser 2024-09-24 09:20:04 -07:00
parent 9378718231
commit 5213c53bb0
2 changed files with 15 additions and 9 deletions

View File

@ -1501,14 +1501,17 @@ void Profiler::InstallCrashHandler()
sigaction( SIGPIPE, &crashHandler, &m_prevSignal.pipe ); sigaction( SIGPIPE, &crashHandler, &m_prevSignal.pipe );
sigaction( SIGBUS, &crashHandler, &m_prevSignal.bus ); sigaction( SIGBUS, &crashHandler, &m_prevSignal.bus );
sigaction( SIGABRT, &crashHandler, &m_prevSignal.abrt ); sigaction( SIGABRT, &crashHandler, &m_prevSignal.abrt );
m_crashHandlerInstalled = true;
#endif #endif
#if defined _WIN32 && !defined TRACY_UWP && !defined TRACY_NO_CRASH_HANDLER #if defined _WIN32 && !defined TRACY_UWP && !defined TRACY_NO_CRASH_HANDLER
m_exceptionHandler = AddVectoredExceptionHandler( 0, CrashFilter ); // We cannot use Vectored Exception handling because it catches application-wide frame-based SEH blocks. We only
#endif // want to catch unhandled exceptions in the event that there is not already an unhandled exception filter.
if( auto prev = SetUnhandledExceptionFilter( CrashFilter ) )
#ifndef TRACY_NO_CRASH_HANDLER SetUnhandledExceptionFilter( prev ); // Already had a handler => put it back
m_crashHandlerInstalled = true; else
m_crashHandlerInstalled = true;
#endif #endif
} }
@ -1516,7 +1519,12 @@ void Profiler::InstallCrashHandler()
void Profiler::RemoveCrashHandler() void Profiler::RemoveCrashHandler()
{ {
#if defined _WIN32 && !defined TRACY_UWP #if defined _WIN32 && !defined TRACY_UWP
if( m_crashHandlerInstalled ) RemoveVectoredExceptionHandler( m_exceptionHandler ); if( m_crashHandlerInstalled )
{
auto prev = SetUnhandledExceptionFilter( NULL );
if( prev != CrashFilter )
SetUnhandledExceptionFilter( prev ); // A different exception filter was installed over ours => put it back
}
#endif #endif
#if defined __linux__ && !defined TRACY_NO_CRASH_HANDLER #if defined __linux__ && !defined TRACY_NO_CRASH_HANDLER

View File

@ -1063,9 +1063,7 @@ private:
char* m_safeSendBuffer; char* m_safeSendBuffer;
size_t m_safeSendBufferSize; size_t m_safeSendBufferSize;
#if defined _WIN32 #ifndef _WIN32
void* m_exceptionHandler;
#else
int m_pipe[2]; int m_pipe[2];
int m_pipeBufSize; int m_pipeBufSize;
#endif #endif