From daf107d606429c89d6f58f5f851ef0fc686ffd0e Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Mon, 12 Feb 2007 08:03:24 +0000 Subject: [PATCH] fix crash handler for stack overflwos --- stepmania/src/archutils/Win32/Crash.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/stepmania/src/archutils/Win32/Crash.cpp b/stepmania/src/archutils/Win32/Crash.cpp index adb3b6f6a4..8c78176ec5 100644 --- a/stepmania/src/archutils/Win32/Crash.cpp +++ b/stepmania/src/archutils/Win32/Crash.cpp @@ -264,7 +264,7 @@ void RunChild() } } -long __stdcall CrashHandler::ExceptionHandler( EXCEPTION_POINTERS *pExc ) +static long MainExceptionHandler( EXCEPTION_POINTERS *pExc ) { /* Flush the log it isn't cut off at the end. */ /* 1. We can't do regular file access in the crash handler. @@ -321,7 +321,7 @@ long __stdcall CrashHandler::ExceptionHandler( EXCEPTION_POINTERS *pExc ) if( !g_CrashInfo.m_CrashReason[0] ) GetReason( pExc->ExceptionRecord, &g_CrashInfo ); - do_backtrace( g_CrashInfo.m_BacktracePointers, BACKTRACE_MAX_SIZE, GetCurrentProcess(), GetCurrentThread(), pExc->ContextRecord ); + CrashHandler::do_backtrace( g_CrashInfo.m_BacktracePointers, BACKTRACE_MAX_SIZE, GetCurrentProcess(), GetCurrentThread(), pExc->ContextRecord ); RunChild(); @@ -356,6 +356,18 @@ long __stdcall CrashHandler::ExceptionHandler( EXCEPTION_POINTERS *pExc ) return EXCEPTION_EXECUTE_HANDLER; } +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. */ + int iSize = 1024*32; + char *pStack = (char *) VirtualAlloc( NULL, iSize, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE ); + pStack += iSize; + _asm mov esp, pStack; + + return MainExceptionHandler( pExc ); +} + ////////////////////////////////////////////////////////////////////////////// static bool IsValidCall(char *buf, int len)