Guardian Programmer's Guide

Table Of Contents
Debugging, Trap Handling, and Signal Handling
Guardian Programmer’s Guide 421922-014
25 - 31
Examples
--SIGSETJMP_ returns 0 (zero) if called directly and
--returns a nonzero value if returning from a call
--to SIGLONGJMP_.
IF SIGSETJMP_( ENV, 1D ) = 0D THEN
BEGIN
--Code that could generate a signal that is caught by
--MYHANDLER.
i := 3/i; ! SIGFPE generated here is caught by
! MYHANDLER
END
ELSE
BEGIN
--This is the return location for SIGLONGJMP_, which is
--called from MYHANDLER after dealing with the signal.
END;
END;
Using SIGACTION_INIT(): an Example in C
/* You can use this program as a replacement for a trap
handler that calls the ARMTRAP procedure. This program shows
how to do the following:
1. Install a signal handler using the SIGACTION_INIT_()
function.
2. Save the process execution context (including the
process signal mask) and establish the location to return
(jump) to from the handler using the sigsetjmp() function.
3. Restore the process execution context and perform the
nonlocal goto (jump) using the siglongjmp() function. */
#include <tdmsig.h>
#include <setjmp.h>
sigjmp_buf env;
void myHandler (signo, sig_info, sig_contextP)
int signo; /* signal number delivered to this handler*/
siginfo_t *sig_info; /* NULL */
void *sig_contextP;/* pointer to saved process */
/* execution context */
{
printf ("Signal %d occurred\n", signo);
/* Signal-handling code goes here. For example, a
combination of calls to HIST_* functions and the
information provided in sig_contextP can be used to
format and display the execution context of the
process when the signal occurred. */
/* siglongjmp() restores the process execution
context saved by sigsetjmp(), which is called from