mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-15 02:25:32 -04:00
Fix crash handling code rarely crashing on 32 bit windows
This commit is contained in:
parent
1585e50b18
commit
bc3f27a204
41
src/Logger.c
41
src/Logger.c
@ -728,50 +728,39 @@ static LONG WINAPI UnhandledFilter(struct _EXCEPTION_POINTERS* info) {
|
|||||||
}
|
}
|
||||||
void Logger_Hook(void) { SetUnhandledExceptionFilter(UnhandledFilter); }
|
void Logger_Hook(void) { SetUnhandledExceptionFilter(UnhandledFilter); }
|
||||||
|
|
||||||
|
#if __GNUC__
|
||||||
/* Don't want compiler doing anything fancy with registers */
|
/* Don't want compiler doing anything fancy with registers */
|
||||||
#if _MSC_VER
|
void __attribute__((optimize("O0"))) Logger_Abort2(cc_result result, const char* raw_msg) {
|
||||||
#pragma optimize ("", off)
|
#else
|
||||||
#endif
|
|
||||||
void Logger_Abort2(cc_result result, const char* raw_msg) {
|
void Logger_Abort2(cc_result result, const char* raw_msg) {
|
||||||
|
#endif
|
||||||
CONTEXT ctx;
|
CONTEXT ctx;
|
||||||
#ifndef _M_IX86
|
#ifndef _M_IX86
|
||||||
/* This method is guaranteed to exist on 64 bit windows */
|
/* This method is guaranteed to exist on 64 bit windows. */
|
||||||
/* It is missing in 32 bit Windows 2000 however */
|
/* 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);
|
RtlCaptureContext(&ctx);
|
||||||
#elif _MSC_VER
|
#elif __GNUC__
|
||||||
/* Stack frame layout on x86: */
|
/* Stack frame layout on x86: */
|
||||||
/* [ebp] is previous frame's EBP */
|
/* [ebp] is previous frame's EBP */
|
||||||
/* [ebp+4] is previous frame's EIP (return address) */
|
/* [ebp+4] is previous frame's EIP (return address) */
|
||||||
/* address of [ebp+8] is previous frame's ESP */
|
/* 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
|
|
||||||
__asm__(
|
__asm__(
|
||||||
"mov 0(%%ebp), %%eax \n\t"
|
"mov 0(%%ebp), %%eax \n\t" /* mov eax, [ebp] */
|
||||||
"mov %%eax, %0 \n\t"
|
"mov %%eax, %0 \n\t" /* mov [ctx.Ebp], eax */
|
||||||
"mov 4(%%ebp), %%eax \n\t"
|
"mov 4(%%ebp), %%eax \n\t" /* mov eax, [ebp+4] */
|
||||||
"mov %%eax, %1 \n\t"
|
"mov %%eax, %1 \n\t" /* mov [ctx.Eip], eax */
|
||||||
"lea 8(%%ebp), %%eax \n\t"
|
"lea 8(%%ebp), %%eax \n\t" /* lea eax, [ebp+8] */
|
||||||
"mov %%eax, %2"
|
"mov %%eax, %2" /* mov [ctx.Esp], eax */
|
||||||
: "=m" (ctx.Ebp), "=m" (ctx.Eip), "=m" (ctx.Esp)
|
: "=m" (ctx.Ebp), "=m" (ctx.Eip), "=m" (ctx.Esp)
|
||||||
:
|
:
|
||||||
: "eax", "memory"
|
: "eax", "memory"
|
||||||
);
|
);
|
||||||
ctx.ContextFlags = CONTEXT_CONTROL;
|
ctx.ContextFlags = CONTEXT_CONTROL;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
AbortCommon(result, raw_msg, &ctx);
|
AbortCommon(result, raw_msg, &ctx);
|
||||||
}
|
}
|
||||||
#if _MSC_VER
|
|
||||||
#pragma optimize ("", on)
|
|
||||||
#endif
|
|
||||||
#elif defined CC_BUILD_POSIX
|
#elif defined CC_BUILD_POSIX
|
||||||
static void SignalHandler(int sig, siginfo_t* info, void* ctx) {
|
static void SignalHandler(int sig, siginfo_t* info, void* ctx) {
|
||||||
cc_string msg; char msgBuffer[128 + 1];
|
cc_string msg; char msgBuffer[128 + 1];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user