Browse Source

crashhandler: remove unknown arch error

pull/2/head
Alibek Omarov 4 years ago
parent
commit
9ff6d44178
  1. 32
      engine/common/crashhandler.c

32
engine/common/crashhandler.c

@ -289,7 +289,7 @@ struct sigaction oldFilter; @@ -289,7 +289,7 @@ struct sigaction oldFilter;
static void Sys_Crash( int signal, siginfo_t *si, void *context)
{
void *pc, **bp, **sp; // this must be set for every OS!
void *pc = NULL, **bp = NULL, **sp = NULL; // this must be set for every OS!
char message[8192];
int len, logfd, i = 0;
size_t pagesize;
@ -344,8 +344,6 @@ static void Sys_Crash( int signal, siginfo_t *si, void *context) @@ -344,8 +344,6 @@ static void Sys_Crash( int signal, siginfo_t *si, void *context)
pc = (void*)ucontext->uc_mcontext.arm_pc;
bp = (void*)ucontext->uc_mcontext.arm_fp;
sp = (void*)ucontext->uc_mcontext.arm_sp;
#else
#error "Unknown arch!!!"
#endif
// safe actions first, stack and memory may be corrupted
@ -368,13 +366,21 @@ static void Sys_Crash( int signal, siginfo_t *si, void *context) @@ -368,13 +366,21 @@ static void Sys_Crash( int signal, siginfo_t *si, void *context)
logfd = Sys_LogFileNo();
write( logfd, message, len );
if( pc && bp && sp )
{
size_t pagesize = sysconf( _SC_PAGESIZE );
// try to print backtrace
write( 2, STACK_BACKTRACE_STR, STACK_BACKTRACE_STR_LEN );
write( logfd, STACK_BACKTRACE_STR, STACK_BACKTRACE_STR_LEN );
strncpy( message + len, STACK_BACKTRACE_STR, sizeof( message ) - len );
len += STACK_BACKTRACE_STR_LEN;
pagesize = sysconf( _SC_PAGESIZE );
// false on success, true on failure
#define try_allow_read(pointer, pagesize) \
( mprotect( (char *)ALIGN( (pointer), (pagesize) ), (pagesize), PROT_READ | PROT_WRITE | PROT_EXEC ) == -1 && \
( mprotect( (char *)ALIGN( (pointer), (pagesize) ), (pagesize), PROT_READ | PROT_EXEC ) == -1) && \
( mprotect( (char *)ALIGN( (pointer), (pagesize) ), (pagesize), PROT_READ | PROT_WRITE ) == -1) && \
( mprotect( (char *)ALIGN( (pointer), (pagesize) ), (pagesize), PROT_READ ) == -1)
do
{
@ -383,15 +389,9 @@ static void Sys_Crash( int signal, siginfo_t *si, void *context) @@ -383,15 +389,9 @@ static void Sys_Crash( int signal, siginfo_t *si, void *context)
write( logfd, message + len, line );
len += line;
//if( !dladdr(bp,0) ) break; // only when bp is in module
if( ( mprotect( (char *)ALIGN( bp, pagesize ), pagesize, PROT_READ | PROT_WRITE | PROT_EXEC ) == -1) &&
( mprotect( (char *)ALIGN( bp, pagesize ), pagesize, PROT_READ | PROT_EXEC ) == -1) &&
( mprotect( (char *)ALIGN( bp, pagesize ), pagesize, PROT_READ | PROT_WRITE ) == -1) &&
( mprotect( (char *)ALIGN( bp, pagesize ), pagesize, PROT_READ ) == -1) )
if( try_allow_read( bp, pagesize ) )
break;
if( ( mprotect( (char *)ALIGN( bp[0], pagesize ), pagesize, PROT_READ | PROT_WRITE | PROT_EXEC ) == -1) &&
( mprotect( (char *)ALIGN( bp[0], pagesize ), pagesize, PROT_READ | PROT_EXEC ) == -1) &&
( mprotect( (char *)ALIGN( bp[0], pagesize ), pagesize, PROT_READ | PROT_WRITE ) == -1) &&
( mprotect( (char *)ALIGN( bp[0], pagesize ), pagesize, PROT_READ ) == -1) )
if( try_allow_read( bp[0], pagesize ) )
break;
pc = bp[1];
bp = (void**)bp[0];
@ -404,10 +404,7 @@ static void Sys_Crash( int signal, siginfo_t *si, void *context) @@ -404,10 +404,7 @@ static void Sys_Crash( int signal, siginfo_t *si, void *context)
strncpy( message + len, STACK_DUMP_STR, sizeof( message ) - len );
len += STACK_DUMP_STR_LEN;
if( ( mprotect((char *)ALIGN( sp, pagesize ), pagesize, PROT_READ | PROT_WRITE | PROT_EXEC ) != -1) ||
( mprotect((char *)ALIGN( sp, pagesize ), pagesize, PROT_READ | PROT_EXEC ) != -1) ||
( mprotect((char *)ALIGN( sp, pagesize ), pagesize, PROT_READ | PROT_WRITE ) != -1) ||
( mprotect((char *)ALIGN( sp, pagesize ), pagesize, PROT_READ ) != -1) )
if( !try_allow_read( sp, pagesize ) )
{
for( i = 0; i < 32; i++ )
{
@ -418,6 +415,9 @@ static void Sys_Crash( int signal, siginfo_t *si, void *context) @@ -418,6 +415,9 @@ static void Sys_Crash( int signal, siginfo_t *si, void *context)
}
}
#undef try_allow_read
}
// put MessageBox as Sys_Error
Msg( "%s\n", message );
#ifdef XASH_SDL

Loading…
Cancel
Save