‘struct sigcontext’ On using Linux’s signaling mechanism for debugqing application programs

Download Report

Transcript ‘struct sigcontext’ On using Linux’s signaling mechanism for debugqing application programs

‘struct sigcontext’
On using Linux’s signaling
mechanism for debugqing
application programs
Installing a signal-handler
#include <signal.h>
void handler( int signo, siginfo_t *si, void *sc );
int main( void )
{
struct sigaction oa, sa = {0};
sa.sa_flags = SA_SIGINFO;
sa.sa_sigaction = handler;
sigaction( SIGSEGV, &sa, &oa );
}
Layout of kernel-stack (by cpu)
Upon entry to kernel’s exception-handler:
SS
ESP
saved pointer
to user-stack
EFLAGS
CS
EIP
SS:ESP
saved pointer
to user-opcode
error
code
‘error code’ = segment-selector for the illegal memory-segment access
Layout of kernel-stack (by Linux)
ss
esp
eflags
cs
eip
error
gs
fs
es
ds
SS:ESP
eax
ebp
edi
esi
edx
ecx
ebx
Layout of user-stack
Upon entering ‘main()’
tos
Upon entering ‘handler()’
environment strings
environment strings
command-line arguments
command-line arguments
envp
argv
argc
return-address
envp
argv
argc
return-address
sigstub
sigcontext
siginfo
tos
sc
si
signum
return-address
‘segvtrap.cpp’
• We have constructed this demo-program
to show how you could utilize the context
information that Linux can provide to your
signal-handler (if you use SA_SIGINFO)
• You can use our ‘run.cpp’ tool to examine
an application-program’s exit-status
In-class exercises
• Try commenting out the ‘exit(1)’ statement
• Then add statement: sc ->eip += 1;
• Try replacing ‘asm(“ hlt “)’ statement with
this privileged instruction: inb( 0x1F7 );
• Try replacing ‘asm(“ hlt “)’ statement with
this illegal assignment: *(char*)0 = 0;
• Try replacing ‘asm(“ hlt” )’ statement with
an instruction that reads a kernel-address