xref: /freebsd/lib/libc/gen/setjmp.3 (revision 05248206f720394d95c2a7475429311df670a2e9)
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.\"     @(#)setjmp.3	8.1 (Berkeley) 6/4/93
33.\"
34.Dd April 2, 2022
35.Dt SETJMP 3
36.Os
37.Sh NAME
38.Nm sigsetjmp ,
39.Nm siglongjmp ,
40.Nm setjmp ,
41.Nm longjmp ,
42.Nm _setjmp ,
43.Nm _longjmp ,
44.Nm longjmperror
45.Nd non-local jumps
46.Sh LIBRARY
47.Lb libc
48.Sh SYNOPSIS
49.In setjmp.h
50.Ft int
51.Fn sigsetjmp "sigjmp_buf env" "int savemask"
52.Ft void
53.Fn siglongjmp "sigjmp_buf env" "int val"
54.Ft int
55.Fn setjmp "jmp_buf env"
56.Ft void
57.Fn longjmp "jmp_buf env" "int val"
58.Ft int
59.Fn _setjmp "jmp_buf env"
60.Ft void
61.Fn _longjmp "jmp_buf env" "int val"
62.Ft void
63.Fn longjmperror void
64.Sh DESCRIPTION
65The
66.Fn sigsetjmp ,
67.Fn setjmp ,
68and
69.Fn _setjmp
70functions save their calling environment in
71.Fa env .
72Each of these functions returns 0.
73.Pp
74The corresponding
75.Fn longjmp
76functions restore the environment saved by their most recent respective
77invocations
78of the
79.Fn setjmp
80function.
81They then return so that program execution continues as if the corresponding
82invocation of the
83.Fn setjmp
84call had just returned the value specified by
85.Fa val ,
86instead of 0.
87.Pp
88Pairs of calls may be intermixed, i.e., both
89.Fn sigsetjmp
90and
91.Fn siglongjmp
92and
93.Fn setjmp
94and
95.Fn longjmp
96combinations may be used in the same program, however, individual
97calls may not, e.g.\& the
98.Fa env
99argument to
100.Fn setjmp
101may not be passed to
102.Fn siglongjmp .
103.Pp
104The
105.Fn longjmp
106routines may not be called after the routine which called the
107.Fn setjmp
108routines returns.
109.Pp
110All accessible objects have values as of the time
111.Fn longjmp
112routine was called, except that the values of objects of automatic storage
113invocation duration that do not have the
114.Vt volatile
115type and have been changed between the
116.Fn setjmp
117invocation and
118.Fn longjmp
119call are indeterminate.
120.Pp
121The
122.Fn setjmp Ns / Ns Fn longjmp
123pairs save and restore the signal mask while
124.Fn _setjmp Ns / Ns Fn _longjmp
125pairs save and restore only the register set and the stack.
126(See
127.Fn sigprocmask 2 . )
128.Pp
129The
130.Fn sigsetjmp Ns / Ns Fn siglongjmp
131function
132pairs save and restore the signal mask if the argument
133.Fa savemask
134is non-zero, otherwise only the register set and the stack are saved.
135.Sh ERRORS
136If the contents of the
137.Fa env
138are corrupted, or correspond to an environment that has already returned,
139the
140.Fn longjmp
141routine calls the routine
142.Fn longjmperror 3 .
143If
144.Fn longjmperror
145returns the program is aborted (see
146.Xr abort 3 ) .
147The default version of
148.Fn longjmperror
149prints the message
150.Dq Li longjmp botch
151to standard error and returns.
152User programs wishing to exit more gracefully should write their own
153versions of
154.Fn longjmperror .
155.Sh SEE ALSO
156.Xr sigaction 2 ,
157.Xr sigaltstack 2 ,
158.Xr signal 3
159.Sh STANDARDS
160The
161.Fn setjmp
162and
163.Fn longjmp
164functions conform to
165.St -isoC .
166The
167.Fn sigsetjmp
168and
169.Fn siglongjmp
170functions conform to
171.St -p1003.1-88 .
172.Sh HISTORY
173The
174.Fn setjmp
175and
176.Fn longjmp
177functions first appeared in the Programmer's Workbench (PWB/UNIX).
178