diff options
author | jackpoz <giacomopoz@gmail.com> | 2015-06-01 21:43:57 +0200 |
---|---|---|
committer | DDuarte <dnpd.dd@gmail.com> | 2015-06-26 02:59:27 +0100 |
commit | edc2476e84fba6e2696c93001e19a5eae7714a3c (patch) | |
tree | f108cfdcf54cfd91fdd486b334d6736b41009915 | |
parent | 985e417f47dd744367d2a8eeaa316f2b01652816 (diff) |
Core/CrashHandler: Make crashhandler tread-safe
Handle only 1 exception in the whole process lifetime and create only 1 crash report.
(cherry picked from commit 1a5051a9c3b8246e92543962c04c3883c4d03f5f)
-rw-r--r-- | src/server/shared/Debugging/WheatyExceptionReport.cpp | 10 | ||||
-rw-r--r-- | src/server/shared/Debugging/WheatyExceptionReport.h | 2 |
2 files changed, 12 insertions, 0 deletions
diff --git a/src/server/shared/Debugging/WheatyExceptionReport.cpp b/src/server/shared/Debugging/WheatyExceptionReport.cpp index e50cf42e439..e9f888f280d 100644 --- a/src/server/shared/Debugging/WheatyExceptionReport.cpp +++ b/src/server/shared/Debugging/WheatyExceptionReport.cpp @@ -62,6 +62,8 @@ HANDLE WheatyExceptionReport::m_hProcess; SymbolPairs WheatyExceptionReport::symbols; std::stack<SymbolDetail> WheatyExceptionReport::symbolDetails; bool WheatyExceptionReport::stackOverflowException; +bool WheatyExceptionReport::alreadyCrashed; +std::mutex WheatyExceptionReport::alreadyCrashedLock; // Declare global instance of class WheatyExceptionReport g_WheatyExceptionReport; @@ -74,6 +76,7 @@ WheatyExceptionReport::WheatyExceptionReport() // Constructor m_previousFilter = SetUnhandledExceptionFilter(WheatyUnhandledExceptionFilter); m_hProcess = GetCurrentProcess(); stackOverflowException = false; + alreadyCrashed = false; if (!IsDebuggerPresent()) { _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE); @@ -99,6 +102,13 @@ WheatyExceptionReport::~WheatyExceptionReport() LONG WINAPI WheatyExceptionReport::WheatyUnhandledExceptionFilter( PEXCEPTION_POINTERS pExceptionInfo) { + std::unique_lock<std::mutex> guard(alreadyCrashedLock); + // Handle only 1 exception in the whole process lifetime + if (alreadyCrashed) + return EXCEPTION_EXECUTE_HANDLER; + + alreadyCrashed = true; + if (pExceptionInfo->ExceptionRecord->ExceptionCode == STATUS_STACK_OVERFLOW) stackOverflowException = true; diff --git a/src/server/shared/Debugging/WheatyExceptionReport.h b/src/server/shared/Debugging/WheatyExceptionReport.h index 101b6187f2b..ef6334add16 100644 --- a/src/server/shared/Debugging/WheatyExceptionReport.h +++ b/src/server/shared/Debugging/WheatyExceptionReport.h @@ -194,6 +194,8 @@ class WheatyExceptionReport static SymbolPairs symbols; static std::stack<SymbolDetail> symbolDetails; static bool stackOverflowException; + static bool alreadyCrashed; + static std::mutex alreadyCrashedLock; static char* PushSymbolDetail(char* pszCurrBuffer); static char* PopSymbolDetail(char* pszCurrBuffer); |