summaryrefslogtreecommitdiffstats
path: root/man-pages-posix-2017/man3p/longjmp.3p
blob: 816d9b8eb53c5d251d8ad47a656a44c1ec90ab8d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
'\" et
.TH LONGJMP "3P" 2017 "IEEE/The Open Group" "POSIX Programmer's Manual"
.\"
.SH PROLOG
This manual page is part of the POSIX Programmer's Manual.
The Linux implementation of this interface may differ (consult
the corresponding Linux manual page for details of Linux behavior),
or the interface may not be implemented on Linux.
.\"
.SH NAME
longjmp
\(em non-local goto
.SH SYNOPSIS
.LP
.nf
#include <setjmp.h>
.P
void longjmp(jmp_buf \fIenv\fP, int \fIval\fP);
.fi
.SH DESCRIPTION
The functionality described on this reference page is aligned with the
ISO\ C standard. Any conflict between the requirements described here and the
ISO\ C standard is unintentional. This volume of POSIX.1\(hy2017 defers to the ISO\ C standard.
.P
The
\fIlongjmp\fR()
function shall restore the environment saved by the most recent
invocation of
\fIsetjmp\fR()
in the same process, with the corresponding
.BR jmp_buf
argument. If the most recent invocation of
\fIsetjmp\fR()
with the corresponding
.BR jmp_buf
occurred in another thread, or if there is no such invocation, or if
the function containing the invocation of
\fIsetjmp\fR()
has terminated execution in the interim, or if the invocation of
\fIsetjmp\fR()
was within the scope of an identifier with variably modified type and
execution has left that scope in the interim, the behavior is undefined.
It is unspecified whether
\fIlongjmp\fR()
restores the signal mask, leaves the signal mask unchanged, or restores
it to its value at the time
\fIsetjmp\fR()
was called.
.P
All accessible objects have values, and all other components of the
abstract machine have state (for example, floating-point status flags
and open files), as of the time
\fIlongjmp\fR()
was called, except that the values of objects of automatic storage
duration are unspecified if they meet all the following conditions:
.IP " *" 4
They are local to the function containing the corresponding
\fIsetjmp\fR()
invocation.
.IP " *" 4
They do not have volatile-qualified type.
.IP " *" 4
They are changed between the
\fIsetjmp\fR()
invocation and
\fIlongjmp\fR()
call.
.P
Although
\fIlongjmp\fR()
is an async-signal-safe function, if it is invoked from a signal
handler which interrupted a non-async-signal-safe function or
equivalent (such as the processing equivalent to
\fIexit\fR()
performed after a return from the initial call to
\fImain\fR()),
the behavior of any subsequent call to a non-async-signal-safe
function or equivalent is undefined.
.P
The effect of a call to
\fIlongjmp\fR()
where initialization of the
.BR jmp_buf
structure was not performed in the calling thread is undefined.
.SH "RETURN VALUE"
After
\fIlongjmp\fR()
is completed, program execution continues as if the corresponding
invocation of
\fIsetjmp\fR()
had just returned the value specified by
.IR val .
The
\fIlongjmp\fR()
function shall not cause
\fIsetjmp\fR()
to return 0; if
.IR val
is 0,
\fIsetjmp\fR()
shall return 1.
.SH ERRORS
No errors are defined.
.LP
.IR "The following sections are informative."
.SH EXAMPLES
None.
.SH "APPLICATION USAGE"
Applications whose behavior depends on the value of the signal mask
should not use
\fIlongjmp\fR()
and
\fIsetjmp\fR(),
since their effect on the signal mask is unspecified, but should
instead use the
\fIsiglongjmp\fR()
and
\fIsigsetjmp\fR()
functions (which can save and restore the signal mask under application
control).
.P
It is recommended that applications do not call
\fIlongjmp\fR()
or
\fIsiglongjmp\fR()
from signal handlers. To avoid undefined behavior when calling these
functions from a signal handler, the application needs to ensure one
of the following two things:
.IP " 1." 4
After the call to
\fIlongjmp\fR()
or
\fIsiglongjmp\fR()
the process only calls async-signal-safe functions and does not return
from the initial call to
\fImain\fR().
.IP " 2." 4
Any signal whose handler calls
\fIlongjmp\fR()
or
\fIsiglongjmp\fR()
is blocked during
.IR every
call to a non-async-signal-safe function, and no such calls are made
after returning from the initial call to
\fImain\fR().
.SH RATIONALE
None.
.SH "FUTURE DIRECTIONS"
None.
.SH "SEE ALSO"
.IR "\fIsetjmp\fR\^(\|)",
.IR "\fIsigaction\fR\^(\|)",
.IR "\fIsiglongjmp\fR\^(\|)",
.IR "\fIsigsetjmp\fR\^(\|)"
.P
The Base Definitions volume of POSIX.1\(hy2017,
.IR "\fB<setjmp.h>\fP"
.\"
.SH COPYRIGHT
Portions of this text are reprinted and reproduced in electronic form
from IEEE Std 1003.1-2017, Standard for Information Technology
-- Portable Operating System Interface (POSIX), The Open Group Base
Specifications Issue 7, 2018 Edition,
Copyright (C) 2018 by the Institute of
Electrical and Electronics Engineers, Inc and The Open Group.
In the event of any discrepancy between this version and the original IEEE and
The Open Group Standard, the original IEEE and The Open Group Standard
is the referee document. The original Standard can be obtained online at
http://www.opengroup.org/unix/online.html .
.PP
Any typographical or formatting errors that appear
in this page are most likely
to have been introduced during the conversion of the source files to
man page format. To report such errors, see
https://www.kernel.org/doc/man-pages/reporting_bugs.html .