xref: /freebsd/lib/libc/gen/setjmp.3 (revision 59c8e88e72633afbc47a4ace0d2170d00d51f7dc)
1.\" Copyright (c) 1990, 1991, 1993
2.\"	The Regents of the University of California.  All rights reserved.
3.\"
4.\" This code is derived from software contributed to Berkeley by
5.\" the American National Standards Committee X3, on Information
6.\" Processing Systems.
7.\"
8.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions
10.\" are met:
11.\" 1. Redistributions of source code must retain the above copyright
12.\"    notice, this list of conditions and the following disclaimer.
13.\" 2. Redistributions in binary form must reproduce the above copyright
14.\"    notice, this list of conditions and the following disclaimer in the
15.\"    documentation and/or other materials provided with the distribution.
16.\" 3. Neither the name of the University nor the names of its contributors
17.\"    may be used to endorse or promote products derived from this software
18.\"    without specific prior written permission.
19.\"
20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30.\" SUCH DAMAGE.
31.\"
32.Dd April 2, 2022
33.Dt SETJMP 3
34.Os
35.Sh NAME
36.Nm sigsetjmp ,
37.Nm siglongjmp ,
38.Nm setjmp ,
39.Nm longjmp ,
40.Nm _setjmp ,
41.Nm _longjmp ,
42.Nm longjmperror
43.Nd non-local jumps
44.Sh LIBRARY
45.Lb libc
46.Sh SYNOPSIS
47.In setjmp.h
48.Ft int
49.Fn sigsetjmp "sigjmp_buf env" "int savemask"
50.Ft void
51.Fn siglongjmp "sigjmp_buf env" "int val"
52.Ft int
53.Fn setjmp "jmp_buf env"
54.Ft void
55.Fn longjmp "jmp_buf env" "int val"
56.Ft int
57.Fn _setjmp "jmp_buf env"
58.Ft void
59.Fn _longjmp "jmp_buf env" "int val"
60.Ft void
61.Fn longjmperror void
62.Sh DESCRIPTION
63The
64.Fn sigsetjmp ,
65.Fn setjmp ,
66and
67.Fn _setjmp
68functions save their calling environment in
69.Fa env .
70Each of these functions returns 0.
71.Pp
72The corresponding
73.Fn longjmp
74functions restore the environment saved by their most recent respective
75invocations
76of the
77.Fn setjmp
78function.
79They then return so that program execution continues as if the corresponding
80invocation of the
81.Fn setjmp
82call had just returned the value specified by
83.Fa val ,
84instead of 0.
85.Pp
86Pairs of calls may be intermixed, i.e., both
87.Fn sigsetjmp
88and
89.Fn siglongjmp
90and
91.Fn setjmp
92and
93.Fn longjmp
94combinations may be used in the same program, however, individual
95calls may not, e.g.\& the
96.Fa env
97argument to
98.Fn setjmp
99may not be passed to
100.Fn siglongjmp .
101.Pp
102The
103.Fn longjmp
104routines may not be called after the routine which called the
105.Fn setjmp
106routines returns.
107.Pp
108All accessible objects have values as of the time
109.Fn longjmp
110routine was called, except that the values of objects of automatic storage
111invocation duration that do not have the
112.Vt volatile
113type and have been changed between the
114.Fn setjmp
115invocation and
116.Fn longjmp
117call are indeterminate.
118.Pp
119The
120.Fn setjmp Ns / Ns Fn longjmp
121pairs save and restore the signal mask while
122.Fn _setjmp Ns / Ns Fn _longjmp
123pairs save and restore only the register set and the stack.
124(See
125.Fn sigprocmask 2 . )
126.Pp
127The
128.Fn sigsetjmp Ns / Ns Fn siglongjmp
129function
130pairs save and restore the signal mask if the argument
131.Fa savemask
132is non-zero, otherwise only the register set and the stack are saved.
133.Sh ERRORS
134If the contents of the
135.Fa env
136are corrupted, or correspond to an environment that has already returned,
137the
138.Fn longjmp
139routine calls the routine
140.Fn longjmperror 3 .
141If
142.Fn longjmperror
143returns the program is aborted (see
144.Xr abort 3 ) .
145The default version of
146.Fn longjmperror
147prints the message
148.Dq Li longjmp botch
149to standard error and returns.
150User programs wishing to exit more gracefully should write their own
151versions of
152.Fn longjmperror .
153.Sh SEE ALSO
154.Xr sigaction 2 ,
155.Xr sigaltstack 2 ,
156.Xr signal 3
157.Sh STANDARDS
158The
159.Fn setjmp
160and
161.Fn longjmp
162functions conform to
163.St -isoC .
164The
165.Fn sigsetjmp
166and
167.Fn siglongjmp
168functions conform to
169.St -p1003.1-88 .
170.Sh HISTORY
171The
172.Fn setjmp
173and
174.Fn longjmp
175functions first appeared in the Programmer's Workbench (PWB/UNIX).
176