//---------------------------------------------------------------- // sigdemo1.s // // This is an assembly language version of our 'sigdemo.cpp' // application, independent of the standard runtime library. // It directly calls the kernel's 'sys_sigaction' service to // install its signal-handling function. // // assemble using: $ as sigdemo1.s -o sigdemo1.o // then link with: $ ld sigdemo1.o -o sigdemo1 // // programmer: ALLAN CRUSE // written on: 03 MAY 2005 //---------------------------------------------------------------- .equ SIGSEGV, 11 # ID-number of the signal .equ sys_exit, 1 # system-call's ID-number .equ sys_sigaction, 67 # system-call's ID-number .equ SA_SIGINFO, 0x00000004 # bitmask for flag value .section .data sa: # this labels the beginning of our 'struct sigaction' object sa_handler: .long action # __sighandler_t sa_handler sa_mask: .long 0 # sigset_t sa_mask sa_flags: .long SA_SIGINFO # unsigned long sa_flags sa_restorer: .long 0 # __sig_restore_t sa_restorer .section .text action: # this is the entry-point to our signal-handling function # exit( 1 ) movl $sys_exit, %eax # system-call ID-number movl $1, %ebx # value for exit-status int $0x80 # enter the Linux kernel subrtn: # try writing 0 to the supplied memory-address movl 4(%esp), %edi # get function-argument movb $0, (%edi) # store 0 into address ret # return to the caller _start: # sigaction( SIGSEGV, &mysa, NULL ); movl $sys_sigaction, %eax # system-call ID-number movl $SIGSEGV, %ebx # ID-number for signal movl $sa, %ecx # address of sa struct movl $0, %edx # null-pointer int $0x80 # enter the Linux kernel # subrtn( NULL ); pushl $0 # push function argument call subrtn # call the function addl $4, %esp # discard the argument # exit( 0 ); movl $sys_exit, %eax # system-call ID-number movl $0, %ebx # value for exit-status int $0x80 # enter the Linux kernel .global _start # program-entry is public .end # no instructions follow