|
|
@ -25,9 +25,9 @@ Sys_Crash |
|
|
|
Crash handler, called from system |
|
|
|
Crash handler, called from system |
|
|
|
================ |
|
|
|
================ |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
#if XASH_CRASHHANDLER == CRASHHANDLER_DBGHELP || XASH_CRASHHANDLER == CRASHHANDLER_WIN32 |
|
|
|
#if XASH_WIN32 |
|
|
|
|
|
|
|
|
|
|
|
#if XASH_CRASHHANDLER == CRASHHANDLER_DBGHELP |
|
|
|
#if DBGHELP |
|
|
|
|
|
|
|
|
|
|
|
#pragma comment( lib, "dbghelp" ) |
|
|
|
#pragma comment( lib, "dbghelp" ) |
|
|
|
|
|
|
|
|
|
|
@ -189,7 +189,7 @@ static void Sys_StackTrace( PEXCEPTION_POINTERS pInfo ) |
|
|
|
|
|
|
|
|
|
|
|
SymCleanup( process ); |
|
|
|
SymCleanup( process ); |
|
|
|
} |
|
|
|
} |
|
|
|
#endif /* XASH_CRASHHANDLER == CRASHHANDLER_DBGHELP */ |
|
|
|
#endif /* DBGHELP */ |
|
|
|
|
|
|
|
|
|
|
|
LPTOP_LEVEL_EXCEPTION_FILTER oldFilter; |
|
|
|
LPTOP_LEVEL_EXCEPTION_FILTER oldFilter; |
|
|
|
static long _stdcall Sys_Crash( PEXCEPTION_POINTERS pInfo ) |
|
|
|
static long _stdcall Sys_Crash( PEXCEPTION_POINTERS pInfo ) |
|
|
@ -200,7 +200,7 @@ static long _stdcall Sys_Crash( PEXCEPTION_POINTERS pInfo ) |
|
|
|
// check to avoid recursive call
|
|
|
|
// check to avoid recursive call
|
|
|
|
host.crashed = true; |
|
|
|
host.crashed = true; |
|
|
|
|
|
|
|
|
|
|
|
#if XASH_CRASHHANDLER == CRASHHANDLER_DBGHELP |
|
|
|
#if DBGHELP |
|
|
|
Sys_StackTrace( pInfo ); |
|
|
|
Sys_StackTrace( pInfo ); |
|
|
|
#else |
|
|
|
#else |
|
|
|
Sys_Warn( "Sys_Crash: call %p at address %p", pInfo->ExceptionRecord->ExceptionAddress, pInfo->ExceptionRecord->ExceptionCode ); |
|
|
|
Sys_Warn( "Sys_Crash: call %p at address %p", pInfo->ExceptionRecord->ExceptionAddress, pInfo->ExceptionRecord->ExceptionCode ); |
|
|
@ -239,21 +239,21 @@ void Sys_RestoreCrashHandler( void ) |
|
|
|
if( oldFilter ) SetUnhandledExceptionFilter( oldFilter ); |
|
|
|
if( oldFilter ) SetUnhandledExceptionFilter( oldFilter ); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#elif XASH_CRASHHANDLER == CRASHHANDLER_UCONTEXT |
|
|
|
#elif XASH_FREEBSD || XASH_NETBSD || XASH_OPENBSD || XASH_ANDROID || XASH_LINUX |
|
|
|
// Posix signal handler
|
|
|
|
// Posix signal handler
|
|
|
|
|
|
|
|
#include <ucontext.h> |
|
|
|
|
|
|
|
#include <signal.h> |
|
|
|
|
|
|
|
#include <sys/mman.h> |
|
|
|
#include "library.h" |
|
|
|
#include "library.h" |
|
|
|
|
|
|
|
|
|
|
|
#if XASH_FREEBSD || XASH_NETBSD || XASH_OPENBSD || XASH_ANDROID || XASH_LINUX |
|
|
|
#define STACK_BACKTRACE_STR "Stack backtrace:\n" |
|
|
|
#define HAVE_UCONTEXT_H 1 |
|
|
|
#define STACK_DUMP_STR "Stack dump:\n" |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_UCONTEXT_H |
|
|
|
#define STACK_BACKTRACE_STR_LEN ( sizeof( STACK_BACKTRACE_STR ) - 1 ) |
|
|
|
#include <ucontext.h> |
|
|
|
#define STACK_DUMP_STR_LEN ( sizeof( STACK_DUMP_STR ) - 1 ) |
|
|
|
#endif |
|
|
|
#define ALIGN( x, y ) (((uintptr_t) ( x ) + (( y ) - 1 )) & ~(( y ) - 1 )) |
|
|
|
|
|
|
|
|
|
|
|
#include <signal.h> |
|
|
|
static struct sigaction oldFilter; |
|
|
|
#include <sys/mman.h> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef XASH_DYNAMIC_DLADDR |
|
|
|
#ifdef XASH_DYNAMIC_DLADDR |
|
|
|
static int d_dladdr( void *sym, Dl_info *info ) |
|
|
|
static int d_dladdr( void *sym, Dl_info *info ) |
|
|
@ -284,28 +284,18 @@ static int Sys_PrintFrame( char *buf, int len, int i, void *addr ) |
|
|
|
if( dlinfo.dli_sname ) |
|
|
|
if( dlinfo.dli_sname ) |
|
|
|
return Q_snprintf( buf, len, "%2d: %p <%s+%lu> (%s)\n", i, addr, dlinfo.dli_sname, |
|
|
|
return Q_snprintf( buf, len, "%2d: %p <%s+%lu> (%s)\n", i, addr, dlinfo.dli_sname, |
|
|
|
(unsigned long)addr - (unsigned long)dlinfo.dli_saddr, dlinfo.dli_fname ); // print symbol, module and address
|
|
|
|
(unsigned long)addr - (unsigned long)dlinfo.dli_saddr, dlinfo.dli_fname ); // print symbol, module and address
|
|
|
|
else |
|
|
|
|
|
|
|
return Q_snprintf( buf, len, "%2d: %p (%s)\n", i, addr, dlinfo.dli_fname ); // print module and address
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
return Q_snprintf( buf, len, "%2d: %p\n", i, addr ); // print only address
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct sigaction oldFilter; |
|
|
|
return Q_snprintf( buf, len, "%2d: %p (%s)\n", i, addr, dlinfo.dli_fname ); // print module and address
|
|
|
|
|
|
|
|
} |
|
|
|
#define STACK_BACKTRACE_STR "Stack backtrace:\n" |
|
|
|
|
|
|
|
#define STACK_DUMP_STR "Stack dump:\n" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define STACK_BACKTRACE_STR_LEN (sizeof( STACK_BACKTRACE_STR ) - 1) |
|
|
|
return Q_snprintf( buf, len, "%2d: %p\n", i, addr ); // print only address
|
|
|
|
#define STACK_DUMP_STR_LEN (sizeof( STACK_DUMP_STR ) - 1) |
|
|
|
} |
|
|
|
#define ALIGN( x, y ) (((uintptr_t) (x) + ((y)-1)) & ~((y)-1)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void Sys_Crash( int signal, siginfo_t *si, void *context) |
|
|
|
static void Sys_Crash( int signal, siginfo_t *si, void *context) |
|
|
|
{ |
|
|
|
{ |
|
|
|
void *pc = NULL, **bp = NULL, **sp = NULL; // this must be set for every OS!
|
|
|
|
void *pc = NULL, **bp = NULL, **sp = NULL; // this must be set for every OS!
|
|
|
|
char message[8192]; |
|
|
|
char message[8192]; |
|
|
|
int len, logfd, i = 0; |
|
|
|
int len, logfd, i = 0; |
|
|
|
size_t pagesize; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if XASH_OPENBSD |
|
|
|
#if XASH_OPENBSD |
|
|
|
struct sigcontext *ucontext = (struct sigcontext*)context; |
|
|
|
struct sigcontext *ucontext = (struct sigcontext*)context; |
|
|
@ -382,6 +372,7 @@ static void Sys_Crash( int signal, siginfo_t *si, void *context) |
|
|
|
if( pc && bp && sp ) |
|
|
|
if( pc && bp && sp ) |
|
|
|
{ |
|
|
|
{ |
|
|
|
size_t pagesize = sysconf( _SC_PAGESIZE ); |
|
|
|
size_t pagesize = sysconf( _SC_PAGESIZE ); |
|
|
|
|
|
|
|
|
|
|
|
// try to print backtrace
|
|
|
|
// try to print backtrace
|
|
|
|
write( STDERR_FILENO, STACK_BACKTRACE_STR, STACK_BACKTRACE_STR_LEN ); |
|
|
|
write( STDERR_FILENO, STACK_BACKTRACE_STR, STACK_BACKTRACE_STR_LEN ); |
|
|
|
write( logfd, STACK_BACKTRACE_STR, STACK_BACKTRACE_STR_LEN ); |
|
|
|
write( logfd, STACK_BACKTRACE_STR, STACK_BACKTRACE_STR_LEN ); |
|
|
@ -466,7 +457,7 @@ void Sys_RestoreCrashHandler( void ) |
|
|
|
sigaction( SIGILL, &oldFilter, NULL ); |
|
|
|
sigaction( SIGILL, &oldFilter, NULL ); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#elif XASH_CRASHHANDLER == CRASHHANDLER_NULL |
|
|
|
#else |
|
|
|
|
|
|
|
|
|
|
|
void Sys_SetupCrashHandler( void ) |
|
|
|
void Sys_SetupCrashHandler( void ) |
|
|
|
{ |
|
|
|
{ |
|
|
|