sigfpe(3) (BSD Compatibility Package) sigfpe(3)
NAME
sigfpe - signal handling for specific SIGFPE codes
SYNOPSIS
/usr/ucb/cc [flag ...] file ... -lucb
#include <signal.h>
#include <floatingpoint.h>
sigfpehandlertype sigfpe(code, hdl)
sigfpecodetype code;
sigfpehandlertype hdl;
DESCRIPTION
This function allows signal handling to be specified for particular
SIGFPE codes. A call to sigfpe defines a new handler hdl for a partic-
ular SIGFPE code and returns the old handler as the value of the func-
tion sigfpe. Normally handlers are specified as pointers to functions;
the special cases SIGFPEIGNORE, SIGFPEABORT, and SIGFPEDEFAULT
allow ignoring, specifying core dump using abort, or default handling
respectively.
For these IEEE-related codes:
FPEFLTINEXTRAP fpinexact floating inexact result
FPEFLTDIVTRAP fpdivision floating division by zero
FPEFLTUNDTRAP fpunderflow floating underflow
FPEFLTOVFTRAP fpoverflow floating overflow
FPEFLTBSUNTRAP fpinvalid branch or set on unordered
FPEFLTOPERRTRAP fpinvalid floating operand error
FPEFLTNANTRAP fpinvalid floating Not-A-Number
default handling is defined to be to call the handler specified to
ieeehandler(3M).
For all other SIGFPE codes, default handling is to core dump using
abort(3C).
The compilation option -ffpa causes FPA recomputation to replace the
default abort action for code FPEFPAERROR. Note: SIGFPEDEFAULT will
restore abort rather than FPA recomputation for this code.
Page 1 Reliant UNIX 5.44 Printed 11/98
sigfpe(3) (BSD Compatibility Package) sigfpe(3)
Three steps are required to intercept an IEEE-related SIGFPE code with
sigfpe.
1) Set up a handler with sigfpe.
2) Enable the relevant IEEE trapping capability in the hardware,
perhaps by using assembly-language instructions.
3) Perform a floating-point operation that generates the intended IEEE
exception.
Unlike ieeehandler(3M), sigfpe never changes floating-point hardware
mode bits affecting IEEE trapping. No IEEE-related SIGFPE signals will
be generated unless those hardware mode bits are enabled.
SIGFPE signals can be handled using sigvec(3), signal(3-ucb),
sigfpe(3), or ieeehandler(3M). In a particular program, to avoid con-
fusion, use only one of these interfaces to handle SIGFPE signals.
EXAMPLES
A user-specified signal handler might look like this:
void samplehandler( sig, code, scp, addr )
int sig ; /* sig == SIGFPE always */
int code ;
struct sigcontext *scp ;
char *addr ;
{
/*
Sample user-written sigfpe code handler.
Prints a message and continues.
struct sigcontext is defined in <signal.h>.
*/
printf(" ieee exception code %x occurred at pc %X \n",
code,scp->scpc);
}
Page 2 Reliant UNIX 5.44 Printed 11/98
sigfpe(3) (BSD Compatibility Package) sigfpe(3)
It might be set up like this:
extern void samplehandler;
main
{
sigfpehandlertype hdl, oldhandler1, oldhandler2;
/*
* save current overflow and invalid handlers; set the new
* overflow handler to samplehandler and set the new
* invalid handler to SIGFPEABORT (abort on invalid)
*/
hdl = (sigfpehandlertype) samplehandler;
oldhandler1 = sigfpe(FPEFLTOVFTRAP, hdl);
oldhandler2 = sigfpe(FPEFLTOPERRTRAP, SIGFPEABORT);
...
/*
* restore old overflow and invalid handlers
*/
sigfpe(FPEFLTOVFTRAP, oldhandler1);
sigfpe(FPEFLTOPERRTRAP, oldhandler2);
}
RETURN VALUE
sigfpe returns BADSIG if code is not zero or a defined SIGFPE code.
FILES
/usr/include/floatingpoint.h
/usr/include/signal.h
SEE ALSO
sigvec(3), signal(3-ucb), abort(3C), floatingpoint(3M),
ieeehandler(3M), signal(5).
Page 3 Reliant UNIX 5.44 Printed 11/98