crashhandler: remove unknown arch error

This commit is contained in:
Alibek Omarov 2020-08-23 19:01:29 +03:00
parent 90b163dc1d
commit 9ff6d44178

View File

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