Create a thread for exception handler for separate stack
This commit is contained in:
@@ -266,7 +266,7 @@ void RunChild()
|
||||
}
|
||||
}
|
||||
|
||||
/* static */ long MainExceptionHandler( EXCEPTION_POINTERS *pExc )
|
||||
static DWORD WINAPI MainExceptionHandler( LPVOID lpParameter )
|
||||
{
|
||||
// Flush the log so it isn't cut off at the end.
|
||||
/* 1. We can't do regular file access in the crash handler.
|
||||
@@ -283,6 +283,7 @@ void RunChild()
|
||||
* does this exception occur, and we never unmask it.
|
||||
* However, once in a while some driver or library turns evil and unmasks an
|
||||
* exception flag on us. If this happens, re-mask it and continue execution. */
|
||||
PEXCEPTION_POINTERS pExc = reinterpret_cast<PEXCEPTION_POINTERS>(lpParameter);
|
||||
switch( pExc->ExceptionRecord->ExceptionCode )
|
||||
{
|
||||
case EXCEPTION_FLT_INVALID_OPERATION:
|
||||
@@ -360,26 +361,25 @@ void RunChild()
|
||||
return EXCEPTION_EXECUTE_HANDLER;
|
||||
}
|
||||
|
||||
#if !_WIN64
|
||||
long __stdcall CrashHandler::ExceptionHandler( EXCEPTION_POINTERS *pExc )
|
||||
{
|
||||
/* If the stack overflowed, we have a very limited amount of stack space.
|
||||
* Allocate a new stack, and run the exception handler in it, to increase
|
||||
* the chances of success. */
|
||||
static BYTE new_stack[0x8000];
|
||||
LPBYTE pStack = new_stack + 0x8000;
|
||||
#if defined(_MSC_VER)
|
||||
_asm mov esp, pStack;
|
||||
#elif defined(__GNUC__)
|
||||
asm volatile ("movl %%esp, %0\n\t"
|
||||
:
|
||||
: "r" (pStack)
|
||||
);
|
||||
#endif
|
||||
HANDLE hExceptionHandler = CreateThread(nullptr, 1024 * 32, MainExceptionHandler, reinterpret_cast<LPVOID>(pExc), 0, nullptr);
|
||||
if (hExceptionHandler == NULL)
|
||||
{
|
||||
TerminateProcess(GetCurrentProcess(), 0);
|
||||
return EXCEPTION_EXECUTE_HANDLER;
|
||||
}
|
||||
WaitForSingleObject(hExceptionHandler, INFINITE);
|
||||
|
||||
return MainExceptionHandler( pExc );
|
||||
DWORD ret;
|
||||
GetExitCodeThread(hExceptionHandler, &ret);
|
||||
CloseHandle(hExceptionHandler);
|
||||
|
||||
return static_cast<long>(ret);
|
||||
}
|
||||
#endif
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
Reference in New Issue
Block a user