1/* Copyright (C) 1991-2026 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <https://www.gnu.org/licenses/>. */
17
18/*
19 * ISO C99 Standard: 7.13 Nonlocal jumps <setjmp.h>
20 */
21
22#ifndef _SETJMP_H
23#define _SETJMP_H 1
24
25#include <features.h>
26
27__BEGIN_DECLS
28
29#if __GLIBC_USE (ISOC23)
30# define __STDC_VERSION_SETJMP_H__ 202311L
31#endif
32
33#include <bits/setjmp.h> /* Get `__jmp_buf'. */
34#include <bits/types/struct___jmp_buf_tag.h>
35
36typedef struct __jmp_buf_tag jmp_buf[1];
37
38/* Store the calling environment in ENV, also saving the signal mask.
39 Return 0. */
40extern int setjmp (jmp_buf __env) __THROWNL;
41
42/* Store the calling environment in ENV, also saving the
43 signal mask if SAVEMASK is nonzero. Return 0.
44 This is the internal name for `sigsetjmp'. */
45extern int __sigsetjmp (struct __jmp_buf_tag __env[1], int __savemask) __THROWNL;
46
47/* Store the calling environment in ENV, not saving the signal mask.
48 Return 0. */
49extern int _setjmp (struct __jmp_buf_tag __env[1]) __THROWNL;
50
51/* Do not save the signal mask. This is equivalent to the `_setjmp'
52 BSD function. */
53#define setjmp(env) _setjmp (env)
54
55
56/* Jump to the environment saved in ENV, making the
57 `setjmp' call there return VAL, or 1 if VAL is 0. */
58extern void longjmp (struct __jmp_buf_tag __env[1], int __val)
59 __THROWNL __attribute__ ((__noreturn__));
60
61#if defined __USE_MISC || defined __USE_XOPEN
62/* Same. Usually `_longjmp' is used with `_setjmp', which does not save
63 the signal mask. But it is how ENV was saved that determines whether
64 `longjmp' restores the mask; `_longjmp' is just an alias. */
65extern void _longjmp (struct __jmp_buf_tag __env[1], int __val)
66 __THROWNL __attribute__ ((__noreturn__));
67#endif
68
69
70#ifdef __USE_POSIX
71/* Use the same type for `jmp_buf' and `sigjmp_buf'.
72 The `__mask_was_saved' flag determines whether
73 or not `longjmp' will restore the signal mask. */
74typedef struct __jmp_buf_tag sigjmp_buf[1];
75
76/* Store the calling environment in ENV, also saving the
77 signal mask if SAVEMASK is nonzero. Return 0. */
78# define sigsetjmp(env, savemask) __sigsetjmp (env, savemask)
79
80/* Jump to the environment saved in ENV, making the
81 sigsetjmp call there return VAL, or 1 if VAL is 0.
82 Restore the signal mask if that sigsetjmp call saved it.
83 This is just an alias `longjmp'. */
84extern void siglongjmp (sigjmp_buf __env, int __val)
85 __THROWNL __attribute__ ((__noreturn__));
86#endif /* Use POSIX. */
87
88
89/* Define helper functions to catch unsafe code. */
90#if __USE_FORTIFY_LEVEL > 0
91# include <bits/setjmp2.h>
92#endif
93
94__END_DECLS
95
96#endif /* setjmp.h */
97