Create a thread for exception handler for separate stack
This commit is contained in:
@@ -57,11 +57,6 @@ else()
|
||||
"archutils/Win32/WindowsDialogBox.cpp"
|
||||
"archutils/Win32/WindowsResources.rc")
|
||||
|
||||
if(MSVC AND SM_WIN32_ARCH MATCHES "x64")
|
||||
enable_language(ASM_MASM)
|
||||
list(APPEND SMDATA_OS_SRC "archutils/Win32/ExceptionHandler_x64.asm")
|
||||
endif()
|
||||
|
||||
list(APPEND SMDATA_OS_HPP
|
||||
"archutils/Win32/AppInstance.h"
|
||||
"archutils/Win32/arch_setup.h"
|
||||
|
||||
@@ -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
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
extrn ?MainExceptionHandler@@YAJPEAU_EXCEPTION_POINTERS@@@Z : PROC
|
||||
|
||||
.data
|
||||
|
||||
pStack db 8000h dup(?) ; Allocate a new stack
|
||||
|
||||
.code
|
||||
|
||||
; long __stdcall CrashHandler::ExceptionHandler( EXCEPTION_POINTERS *pExc );
|
||||
?ExceptionHandler@CrashHandler@@YAJPEAU_EXCEPTION_POINTERS@@@Z PROC
|
||||
|
||||
push rsp
|
||||
lea rsp, offset pStack + 7FE0h ; Reserve register parameter stack area for RCX, RDX, R8 and R9
|
||||
call ?MainExceptionHandler@@YAJPEAU_EXCEPTION_POINTERS@@@Z
|
||||
pop rsp
|
||||
ret
|
||||
|
||||
?ExceptionHandler@CrashHandler@@YAJPEAU_EXCEPTION_POINTERS@@@Z ENDP
|
||||
|
||||
END
|
||||
Reference in New Issue
Block a user