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,54 +366,56 @@ 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 );
// try to print backtrace if( pc && bp && sp )
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 );
do
{ {
int line = printframe( message + len, sizeof( message ) - len, ++i, pc); size_t pagesize = sysconf( _SC_PAGESIZE );
write( 2, message + len, line ); // try to print backtrace
write( logfd, message + len, line ); write( 2, STACK_BACKTRACE_STR, STACK_BACKTRACE_STR_LEN );
len += line; write( logfd, STACK_BACKTRACE_STR, STACK_BACKTRACE_STR_LEN );
//if( !dladdr(bp,0) ) break; // only when bp is in module strncpy( message + len, STACK_BACKTRACE_STR, sizeof( message ) - len );
if( ( mprotect( (char *)ALIGN( bp, pagesize ), pagesize, PROT_READ | PROT_WRITE | PROT_EXEC ) == -1) && len += STACK_BACKTRACE_STR_LEN;
( 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;
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) )
break;
pc = bp[1];
bp = (void**)bp[0];
}
while( bp && i < 128 );
// try to print stack // false on success, true on failure
write( 2, STACK_DUMP_STR, STACK_DUMP_STR_LEN ); #define try_allow_read(pointer, pagesize) \
write( logfd, STACK_DUMP_STR, STACK_DUMP_STR_LEN ); ( mprotect( (char *)ALIGN( (pointer), (pagesize) ), (pagesize), PROT_READ | PROT_WRITE | PROT_EXEC ) == -1 && \
strncpy( message + len, STACK_DUMP_STR, sizeof( message ) - len ); ( mprotect( (char *)ALIGN( (pointer), (pagesize) ), (pagesize), PROT_READ | PROT_EXEC ) == -1) && \
len += STACK_DUMP_STR_LEN; ( mprotect( (char *)ALIGN( (pointer), (pagesize) ), (pagesize), PROT_READ | PROT_WRITE ) == -1) && \
( mprotect( (char *)ALIGN( (pointer), (pagesize) ), (pagesize), PROT_READ ) == -1)
if( ( mprotect((char *)ALIGN( sp, pagesize ), pagesize, PROT_READ | PROT_WRITE | PROT_EXEC ) != -1) || do
( 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++ )
{ {
int line = printframe( message + len, sizeof( message ) - len, i, sp[i] ); int line = printframe( message + len, sizeof( message ) - len, ++i, pc);
write( 2, message + len, line ); write( 2, message + len, line );
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( try_allow_read( bp, pagesize ) )
break;
if( try_allow_read( bp[0], pagesize ) )
break;
pc = bp[1];
bp = (void**)bp[0];
} }
while( bp && i < 128 );
// try to print stack
write( 2, STACK_DUMP_STR, STACK_DUMP_STR_LEN );
write( logfd, STACK_DUMP_STR, STACK_DUMP_STR_LEN );
strncpy( message + len, STACK_DUMP_STR, sizeof( message ) - len );
len += STACK_DUMP_STR_LEN;
if( !try_allow_read( sp, pagesize ) )
{
for( i = 0; i < 32; i++ )
{
int line = printframe( message + len, sizeof( message ) - len, i, sp[i] );
write( 2, message + len, line );
write( logfd, message + len, line );
len += line;
}
}
#undef try_allow_read
} }
// put MessageBox as Sys_Error // put MessageBox as Sys_Error