1 /* Copyright (C) 1991-1999,2001,2002,2007,2009 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 <http://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 #pragma GCC system_header 26 27 #include <features.h> 28 29 __BEGIN_DECLS 30 31 #include <bits/setjmp.h> /* Get `__jmp_buf'. */ 32 #include <bits/sigset.h> /* Get `__sigset_t'. */ 33 34 35 /* Calling environment, plus possibly a saved signal mask. */ 36 struct __jmp_buf_tag 37 { 38 /* NOTE: The machine-dependent definitions of `__sigsetjmp' 39 assume that a `jmp_buf' begins with a `__jmp_buf' and that 40 `__mask_was_saved' follows it. Do not move these members 41 or add others before it. */ 42 __jmp_buf __jmpbuf; /* Calling environment. */ 43 int __mask_was_saved; /* Saved the signal mask? */ 44 __sigset_t __saved_mask; /* Saved signal mask. */ 45 }; 46 47 48 __BEGIN_NAMESPACE_STD 49 50 typedef struct __jmp_buf_tag jmp_buf[1]; 51 52 /* Store the calling environment in ENV, also saving the signal mask. 53 Return 0. */ 54 extern int setjmp (jmp_buf __env) __THROW; 55 56 __END_NAMESPACE_STD 57 58 /* Store the calling environment in ENV, also saving the 59 signal mask if SAVEMASK is nonzero. Return 0. 60 This is the internal name for `sigsetjmp'. */ 61 extern int __sigsetjmp (struct __jmp_buf_tag __env[1], int __savemask) __THROW; 62 63 #ifndef __FAVOR_BSD 64 /* Store the calling environment in ENV, not saving the signal mask. 65 Return 0. */ 66 extern int _setjmp (struct __jmp_buf_tag __env[1]) __THROW; 67 68 /* Do not save the signal mask. This is equivalent to the `_setjmp' 69 BSD function. */ 70 # define setjmp(env) _setjmp (env) 71 #else 72 /* We are in 4.3 BSD-compatibility mode in which `setjmp' 73 saves the signal mask like `sigsetjmp (ENV, 1)'. We have to 74 define a macro since ISO C says `setjmp' is one. */ 75 # define setjmp(env) setjmp (env) 76 #endif /* Favor BSD. */ 77 78 79 __BEGIN_NAMESPACE_STD 80 81 /* Jump to the environment saved in ENV, making the 82 `setjmp' call there return VAL, or 1 if VAL is 0. */ 83 extern void longjmp (struct __jmp_buf_tag __env[1], int __val) 84 __THROW __attribute__ ((__noreturn__)); 85 86 __END_NAMESPACE_STD 87 88 #if defined __USE_BSD || defined __USE_XOPEN 89 /* Same. Usually `_longjmp' is used with `_setjmp', which does not save 90 the signal mask. But it is how ENV was saved that determines whether 91 `longjmp' restores the mask; `_longjmp' is just an alias. */ 92 extern void _longjmp (struct __jmp_buf_tag __env[1], int __val) 93 __THROW __attribute__ ((__noreturn__)); 94 #endif 95 96 97 #ifdef __USE_POSIX 98 /* Use the same type for `jmp_buf' and `sigjmp_buf'. 99 The `__mask_was_saved' flag determines whether 100 or not `longjmp' will restore the signal mask. */ 101 typedef struct __jmp_buf_tag sigjmp_buf[1]; 102 103 /* Store the calling environment in ENV, also saving the 104 signal mask if SAVEMASK is nonzero. Return 0. */ 105 # define sigsetjmp(env, savemask) __sigsetjmp (env, savemask) 106 107 /* Jump to the environment saved in ENV, making the 108 sigsetjmp call there return VAL, or 1 if VAL is 0. 109 Restore the signal mask if that sigsetjmp call saved it. 110 This is just an alias `longjmp'. */ 111 extern void siglongjmp (sigjmp_buf __env, int __val) 112 __THROW __attribute__ ((__noreturn__)); 113 #endif /* Use POSIX. */ 114 115 __END_DECLS 116 117 #ifdef _LIBC 118 extern void __longjmp(__jmp_buf __env, int __val) attribute_noreturn; 119 libc_hidden_proto(__longjmp) 120 extern __typeof(longjmp) __libc_longjmp attribute_noreturn; 121 extern __typeof(siglongjmp) __libc_siglongjmp attribute_noreturn; 122 extern void _longjmp_unwind(jmp_buf __env, int __val); 123 libc_hidden_proto(_longjmp_unwind) 124 extern int __sigjmp_save(sigjmp_buf __env, int __savemask) attribute_hidden; 125 /* We use the normal longjmp for unwinding */ 126 # define __libc_unwind_longjmp(buf, val) __libc_longjmp(buf, val) 127 #endif 128 129 #endif /* setjmp.h */ 130