Download presentation
Presentation is loading. Please wait.
1
‘struct sigcontext’ On using Linux’s signaling mechanism for debugqing application programs
2
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 ); }
3
Layout of kernel-stack (by cpu)
Upon entry to kernel’s exception-handler: SS saved pointer to user-stack ESP EFLAGS CS saved pointer to user-opcode EIP error code SS:ESP ‘error code’ = segment-selector for the illegal memory-segment access
4
Layout of kernel-stack (by Linux)
ss esp eflags cs eip error gs fs es ds eax ebp edi esi edx ecx SS:ESP ebx
5
command-line arguments command-line arguments
Layout of user-stack Upon entering ‘main()’ Upon entering ‘handler()’ environment strings environment strings command-line arguments command-line arguments envp envp argv argv argc argc tos return-address return-address sigstub sigcontext siginfo sc si signum tos return-address
6
‘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
7
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
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.