1 / 7

‘struct sigcontext’

‘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;

lavada
Download Presentation

‘struct sigcontext’

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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. 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

More Related