1 .\" $NetBSD: setjmp.3,v 1.17 2008/05/31 16:15:07 enami Exp $
3 .\" Copyright (c) 1990, 1991, 1993
4 .\" The Regents of the University of California. All rights reserved.
6 .\" This code is derived from software contributed to Berkeley by
7 .\" the American National Standards Committee X3, on Information
8 .\" Processing Systems.
10 .\" Redistribution and use in source and binary forms, with or without
11 .\" modification, are permitted provided that the following conditions
13 .\" 1. Redistributions of source code must retain the above copyright
14 .\" notice, this list of conditions and the following disclaimer.
15 .\" 2. Redistributions in binary form must reproduce the above copyright
16 .\" notice, this list of conditions and the following disclaimer in the
17 .\" documentation and/or other materials provided with the distribution.
18 .\" 3. Neither the name of the University nor the names of its contributors
19 .\" may be used to endorse or promote products derived from this software
20 .\" without specific prior written permission.
22 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 .\" @(#)setjmp.3 8.1 (Berkeley) 6/4/93
53 .Fn sigsetjmp "sigjmp_buf env" "int savemask"
55 .Fn siglongjmp "sigjmp_buf env" "int val"
57 .Fn setjmp "jmp_buf env"
59 .Fn longjmp "jmp_buf env" "int val"
61 .Fn _setjmp "jmp_buf env"
63 .Fn _longjmp "jmp_buf env" "int val"
72 functions save their calling environment in
74 Each of these functions returns 0.
78 functions restore the environment saved by the most recent
79 invocation of the respective
82 They then return so that program execution continues as if the corresponding
85 call had just returned the value specified by
89 Pairs of calls may be intermixed, i.e., both
97 combinations may be used in the same program.
98 However, individual calls may not, e.g., the
107 routines may not be called after the routine which called the
111 All accessible objects have values as of the time
113 routine was called, except that the values of objects of automatic storage
114 invocation duration that do not have the
116 type and have been changed between the
120 call are indeterminate.
123 .Fn setjmp Ns / Ns Fn longjmp
124 function pairs save and restore the signal mask while
125 .Fn _setjmp Ns / Ns Fn _longjmp
126 function pairs save and restore only the register set and the stack.
128 .Fn sigprocmask 2 . )
131 .Fn sigsetjmp Ns / Ns Fn siglongjmp
132 function pairs save and restore the signal mask if the argument
135 Otherwise, only the register set and the stack are saved.
138 .Fn setjmp Ns / Ns Fn longjmp
139 are functionally equivalent to
140 .Fn sigsetjmp Ns / Ns Fn siglongjmp
143 is called with a non-zero
147 .Fn _setjmp Ns / Ns Fn _longjmp
148 are functionally equivalent to
149 .Fn sigsetjmp Ns / Ns Fn siglongjmp
152 is called with a zero-value
156 .Fn sigsetjmp Ns / Ns Fn siglongjmp
157 interfaces are preferred for maximum portability.
159 If the contents of the
161 are corrupted or correspond to an environment that has already returned,
164 routine calls the routine
168 returns, the program is aborted (see
170 The default version of
174 to standard error and returns.
175 User programs wishing to exit more gracefully should write their own
182 .Xr pthread_sigmask 3 ,
201 .Fn setjmp Ns / Ns Fn longjmp
202 functions have been equivalent to the
204 .Fn _setjmp Ns / Ns Fn _longjmp
205 functions and do not restore the signal mask.
206 Because of this discrepancy, the
207 .Fn sigsetjmp Ns / Ns Fn siglongjmp
208 interfaces should be used if portability is desired.
214 from inside a signal handler is not as easy as it might seem.
215 Generally speaking, all possible code paths between the
219 must be signal race safe.
220 Furthermore, the code paths must not do resource management
225 without blocking the signal in question, or resources might
229 much less useful than previously thought.