diff --git a/src/Logger.c b/src/Logger.c index 5c0c8378e..b2b4c3e9d 100644 --- a/src/Logger.c +++ b/src/Logger.c @@ -728,50 +728,39 @@ static LONG WINAPI UnhandledFilter(struct _EXCEPTION_POINTERS* info) { } void Logger_Hook(void) { SetUnhandledExceptionFilter(UnhandledFilter); } +#if __GNUC__ /* Don't want compiler doing anything fancy with registers */ -#if _MSC_VER -#pragma optimize ("", off) -#endif +void __attribute__((optimize("O0"))) Logger_Abort2(cc_result result, const char* raw_msg) { +#else void Logger_Abort2(cc_result result, const char* raw_msg) { +#endif CONTEXT ctx; #ifndef _M_IX86 - /* This method is guaranteed to exist on 64 bit windows */ - /* It is missing in 32 bit Windows 2000 however */ + /* This method is guaranteed to exist on 64 bit windows. */ + /* NOTE: This is missing in 32 bit Windows 2000 however, */ + /* so an alternative is provided for MinGW below so that */ + /* the game can cross-compiled for Windows 98 / 2000 */ RtlCaptureContext(&ctx); -#elif _MSC_VER +#elif __GNUC__ /* Stack frame layout on x86: */ - /* [ebp] is previous frame's EBP */ - /* [ebp+4] is previous frame's EIP (return address) */ - /* address of [ebp+8] is previous frame's ESP */ - __asm { - mov eax, [ebp] - mov [ctx.Ebp], eax - mov eax, [ebp+4] - mov [ctx.Eip], eax - lea eax, [ebp+8] - mov [ctx.Esp], eax - mov [ctx.ContextFlags], CONTEXT_CONTROL - } -#else + /* [ebp] is previous frame's EBP */ + /* [ebp+4] is previous frame's EIP (return address) */ + /* address of [ebp+8] is previous frame's ESP */ __asm__( - "mov 0(%%ebp), %%eax \n\t" - "mov %%eax, %0 \n\t" - "mov 4(%%ebp), %%eax \n\t" - "mov %%eax, %1 \n\t" - "lea 8(%%ebp), %%eax \n\t" - "mov %%eax, %2" + "mov 0(%%ebp), %%eax \n\t" /* mov eax, [ebp] */ + "mov %%eax, %0 \n\t" /* mov [ctx.Ebp], eax */ + "mov 4(%%ebp), %%eax \n\t" /* mov eax, [ebp+4] */ + "mov %%eax, %1 \n\t" /* mov [ctx.Eip], eax */ + "lea 8(%%ebp), %%eax \n\t" /* lea eax, [ebp+8] */ + "mov %%eax, %2" /* mov [ctx.Esp], eax */ : "=m" (ctx.Ebp), "=m" (ctx.Eip), "=m" (ctx.Esp) : : "eax", "memory" ); ctx.ContextFlags = CONTEXT_CONTROL; #endif - AbortCommon(result, raw_msg, &ctx); } -#if _MSC_VER -#pragma optimize ("", on) -#endif #elif defined CC_BUILD_POSIX static void SignalHandler(int sig, siginfo_t* info, void* ctx) { cc_string msg; char msgBuffer[128 + 1];