2 .\" Copyright (c) 1996, Sun Microsystems, Inc.
3 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
4 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
5 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
6 .TH SIGFPE 3C "May 4, 2004"
8 sigfpe \- signal handling for specific SIGFPE codes
12 #include <floatingpoint.h>
15 \fBsigfpe_handler_type\fR \fBsigfpe\fR(\fBsigfpe_code_type\fR \fIcode\fR,
16 \fBsigfpe_handler_type\fR \fIhdl\fR);
22 The \fBsigfpe()\fR function allows signal handling to be specified for
23 particular \fBSIGFPE\fR codes. A call to \fBsigfpe()\fR defines a new handler
24 \fIhdl\fR for a particular \fBSIGFPE\fR \fIcode\fR and returns the old handler
25 as the value of the function \fBsigfpe()\fR. Normally handlers are specified as
26 pointers to functions; the special cases \fBSIGFPE_IGNORE\fR,
27 \fBSIGFPE_ABORT\fR, and \fBSIGFPE_DEFAULT\fR allow ignoring, dumping core using
28 \fBabort\fR(3C), or default handling respectively. Default handling is to dump
29 core using \fBabort\fR(3C).
32 The \fIcode\fR argument is usually one of the five \fBIEEE\|754-related\fR
37 FPE_FLTRES fp_inexact \(mi floating-point inexact result
38 FPE_FLTDIV fp_division \(mi floating-point division by zero
39 FPE_FLTUND fp_underflow \(mi floating-point underflow
40 FPE_FLTOVF fp_overflow \(mi floating-point overflow
41 FPE_FLTINV fp_invalid \(mi floating-point invalid operation
47 Three steps are required to intercept an \fBIEEE\|754-related\fR \fBSIGFPE\fR
48 code with \fBsigfpe()\fR:
52 Set up a handler with \fBsigfpe()\fR.
57 Enable the relevant \fBIEEE\|754\fR trapping capability in the hardware,
58 perhaps by using assembly-language instructions.
63 Perform a floating-point operation that generates the intended
64 \fBIEEE\|754\fR exception.
68 The \fBsigfpe()\fR function never changes floating-point hardware mode bits
69 affecting \fBIEEE\|754\fR trapping. No \fBIEEE\|754-related\fR \fBSIGFPE\fR
70 signals will be generated unless those hardware mode bits are enabled.
73 \fBSIGFPE\fR signals can be handled using \fBsigfpe()\fR, \fBsigaction\fR(2) or
74 \fBsignal\fR(3C). In a particular program, to avoid confusion, use only one of
75 these interfaces to handle \fBSIGFPE\fR signals.
78 \fBExample 1 \fRExample Of A User-Specified Signal Handler
81 A user-specified signal handler might look like this:
86 #include <floatingpoint.h>
90 * The sample_handler prints out a message then commits suicide.
93 sample_handler(int sig, siginfo_t *sip, ucontext_t *uap) {
95 switch (sip\(mi>si_code) {
96 case FPE_FLTINV: label = "invalid operand"; break;
97 case FPE_FLTRES: label = "inexact"; break;
98 case FPE_FLTDIV: label = "division-by-zero"; break;
99 case FPE_FLTUND: label = "underflow"; break;
100 case FPE_FLTOVF: label = "overflow"; break;
101 default: label = "???"; break;
104 "FP exception %s (0x%x) occurred at address %p.\en",
105 label, sip\(mi>si_code, (void *) sip\(mi>si_addr);
113 and it might be set up like this:
118 #include <floatingpoint.h>
120 #include <ucontext.h>
121 extern void sample_handler(int, siginfo_t *, ucontext_t *);
123 sigfpe_handler_type hdl, old_handler1, old_handler2;
125 * save current fp_overflow and fp_invalid handlers; set the new
126 * fp_overflow handler to sample_handler(\|) and set the new
127 * fp_invalid handler to SIGFPE_ABORT (abort on invalid)
129 hdl = (sigfpe_handler_type) sample_handler;
130 old_handler1 = sigfpe(FPE_FLTOVF, hdl);
131 old_handler2 = sigfpe(FPE_FLTINV, SIGFPE_ABORT);
134 * restore old fp_overflow and fp_invalid handlers
136 sigfpe(FPE_FLTOVF, old_handler1);
137 sigfpe(FPE_FLTINV, old_handler2);
146 \fB\fB/usr/include/floatingpoint.h\fR\fR
156 \fB\fB/usr/include/siginfo.h\fR\fR
166 See \fBattributes\fR(5) for descriptions of the following attributes:
174 ATTRIBUTE TYPE ATTRIBUTE VALUE
182 \fBsigaction\fR(2), \fBabort\fR(3C), \fBsignal\fR(3C), \fBattributes\fR(5),
183 \fBfloatingpoint.h\fR(3HEAD)
187 The \fBsigfpe()\fR function returns (void(*)())-1 if \fIcode\fR is not zero or
188 a defined \fBSIGFPE\fR code.