(BSD System Compatibility)

sigfpe(3bsd)


sigfpe -- (BSD) signal handling for specific SIGFPE codes

Synopsis

   /usr/ucb/cc [flag . . . ] file . . .
   

#include <signal.h>

#include <fp.h>

sigfpe_handler_type sigfpe(sigfpe_code_type code, sigfpe_handler_type 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 particular SIGFPE code and returns the old handler as the value of the function sigfpe. Normally handlers are specified as pointers to functions; the special cases SIGFPE_IGNORE, SIGFPE_ABORT, and SIGFPE_DEFAULT allow ignoring, specifying core dump using abort(3C), or default handling respectively.

Default handling is defined to call the handler specified to ieee_handler(3bsd) for these IEEE-related codes:

FPE_FLTINEX_TRAP fp_inexact floating inexact result
FPE_FLTDIV_TRAP fp_division floating division by zero
FPE_FLTUND_TRAP fp_underflow floating underflow
FPE_FLTOVF_TRAP fp_overflow floating overflow
FPE_FLTBSUN_TRAP fp_invalid branch or set on unordered
FPE_FLTOPERR_TRAP fp_invalid floating operand error
FPE_FLTNAN_TRAP fp_invalid floating Not-A-Number

 FPE_FLTINEX_TRAP    fp_inexact     floating inexact result
 FPE_FLTDIV_TRAP     fp_division    floating division by zero
 FPE_FLTUND_TRAP     fp_underflow   floating underflow
 FPE_FLTOVF_TRAP     fp_overflow    floating overflow
 FPE_FLTBSUN_TRAP    fp_invalid     branch or set on unordered
 FPE_FLTOPERR_TRAP   fp_invalid     floating operand error
 FPE_FLTNAN_TRAP     fp_invalid     floating Not-A-Number

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


NOTE: SIGFPE_DEFAULT will restore abort rather than FPA recomputation for this code.

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 ieee_handler(3bsd), 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(3bsd), signal(3bsd), sigfpe(3bsd), or ieee_handler(3bsd). In a particular program, to avoid confusion, use only one of these interfaces to handle SIGFPE signals.

Files


/usr/ucbinclude/fp.h

/usr/ucbinclude/signal.h

Return values

sigfpe returns BADSIG if code is not 0 or a defined SIGFPE code.

References

abort(3C), floatingpoint(3bsd), ieee_handler(3bsd), signal(3bsd), sigvec(3bsd)

Examples

A user-specified signal handler might look like this:
   void sample_handler( 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->sc_pc);
   	}

and it might be set up like this:

   	extern void sample_handler;
    	main
   	{
   		sigfpe_handler_type hdl, old_handler1, old_handler2;
   	/*
   	 * save current overflow and invalid handlers; set the new
   	 * overflow handler to sample_handler and set the new
   	 * invalid handler to SIGFPE_ABORT (abort on invalid)
   	 */
   		hdl = (sigfpe_handler_type) sample_handler;
   		old_handler1 = sigfpe(FPE_FLTOVF_TRAP, hdl);
   		old_handler2 = sigfpe(FPE_FLTOPERR_TRAP, SIGFPE_ABORT);
   		...
   	/*
   	 * restore old overflow and invalid handlers
   	 */
   		sigfpe(FPE_FLTOVF_TRAP,   old_handler1);
   		sigfpe(FPE_FLTOPERR_TRAP, old_handler2);
   	}

© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 25 April 2004