Fix crash handling code rarely crashing on 32 bit windows

This commit is contained in:
UnknownShadow200 2021-01-06 11:40:00 +11:00
parent 1585e50b18
commit bc3f27a204

View File

@ -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];