stdlib: fix potential UB and integer overflow with huge allocations using malloc...
[uclibc-ng.git] / include / setjmp.h
blob27cac9500a1551ca1d0b5396f6f9e960e563e5da
1 /* Copyright (C) 1991-1999,2001,2002,2007,2009 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
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.
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.
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 <http://www.gnu.org/licenses/>. */
19 * ISO C99 Standard: 7.13 Nonlocal jumps <setjmp.h>
22 #ifndef _SETJMP_H
23 #define _SETJMP_H 1
25 #include <features.h>
27 __BEGIN_DECLS
29 #include <bits/setjmp.h> /* Get `__jmp_buf'. */
30 #include <bits/sigset.h> /* Get `__sigset_t'. */
33 /* Calling environment, plus possibly a saved signal mask. */
34 struct __jmp_buf_tag
36 /* NOTE: The machine-dependent definitions of `__sigsetjmp'
37 assume that a `jmp_buf' begins with a `__jmp_buf' and that
38 `__mask_was_saved' follows it. Do not move these members
39 or add others before it. */
40 __jmp_buf __jmpbuf; /* Calling environment. */
41 int __mask_was_saved; /* Saved the signal mask? */
42 __sigset_t __saved_mask; /* Saved signal mask. */
46 __BEGIN_NAMESPACE_STD
48 typedef struct __jmp_buf_tag jmp_buf[1];
50 /* Store the calling environment in ENV, also saving the signal mask.
51 Return 0. */
52 extern int setjmp (jmp_buf __env) __THROWNL;
54 __END_NAMESPACE_STD
56 /* Store the calling environment in ENV, also saving the
57 signal mask if SAVEMASK is nonzero. Return 0.
58 This is the internal name for `sigsetjmp'. */
59 extern int __sigsetjmp (struct __jmp_buf_tag __env[1], int __savemask)
60 __THROWNL;
62 /* Store the calling environment in ENV, not saving the signal mask.
63 Return 0. */
64 extern int _setjmp (struct __jmp_buf_tag __env[1]) __THROWNL;
66 /* Do not save the signal mask. This is equivalent to the `_setjmp'
67 BSD function. */
68 #define setjmp(env) _setjmp (env)
70 __BEGIN_NAMESPACE_STD
72 /* Jump to the environment saved in ENV, making the
73 `setjmp' call there return VAL, or 1 if VAL is 0. */
74 extern void longjmp (struct __jmp_buf_tag __env[1], int __val)
75 __THROWNL __attribute__ ((__noreturn__));
77 __END_NAMESPACE_STD
79 #if defined __USE_BSD || defined __USE_XOPEN
80 /* Same. Usually `_longjmp' is used with `_setjmp', which does not save
81 the signal mask. But it is how ENV was saved that determines whether
82 `longjmp' restores the mask; `_longjmp' is just an alias. */
83 extern void _longjmp (struct __jmp_buf_tag __env[1], int __val)
84 __THROWNL __attribute__ ((__noreturn__));
85 #endif
88 #ifdef __USE_POSIX
89 /* Use the same type for `jmp_buf' and `sigjmp_buf'.
90 The `__mask_was_saved' flag determines whether
91 or not `longjmp' will restore the signal mask. */
92 typedef struct __jmp_buf_tag sigjmp_buf[1];
94 /* Store the calling environment in ENV, also saving the
95 signal mask if SAVEMASK is nonzero. Return 0. */
96 # define sigsetjmp(env, savemask) __sigsetjmp (env, savemask)
98 /* Jump to the environment saved in ENV, making the
99 sigsetjmp call there return VAL, or 1 if VAL is 0.
100 Restore the signal mask if that sigsetjmp call saved it.
101 This is just an alias `longjmp'. */
102 extern void siglongjmp (sigjmp_buf __env, int __val)
103 __THROWNL __attribute__ ((__noreturn__));
104 #endif /* Use POSIX. */
106 __END_DECLS
108 #ifdef _LIBC
109 extern void __longjmp(__jmp_buf __env, int __val) __THROWNL attribute_noreturn;
110 libc_hidden_proto(__longjmp)
111 extern __typeof(longjmp) __libc_longjmp __THROWNL attribute_noreturn;
112 extern __typeof(siglongjmp) __libc_siglongjmp __THROWNL attribute_noreturn;
113 extern void _longjmp_unwind(jmp_buf __env, int __val);
114 libc_hidden_proto(_longjmp_unwind)
115 extern int __sigjmp_save(sigjmp_buf __env, int __savemask) attribute_hidden;
116 /* We use the normal longjmp for unwinding */
117 # define __libc_unwind_longjmp(buf, val) __libc_longjmp(buf, val)
118 #endif
120 #endif /* setjmp.h */