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, write to the Free
16   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17   02111-1307 USA.  */
18
19/*
20 *	ISO C99 Standard: 7.13 Nonlocal jumps	<setjmp.h>
21 */
22
23#ifndef	_SETJMP_H
24#define	_SETJMP_H	1
25
26#include <features.h>
27
28__BEGIN_DECLS
29
30#include <bits/setjmp.h>		/* Get `__jmp_buf'.  */
31#include <bits/sigset.h>		/* Get `__sigset_t'.  */
32
33
34/* Calling environment, plus possibly a saved signal mask.  */
35struct __jmp_buf_tag
36  {
37    /* NOTE: The machine-dependent definitions of `__sigsetjmp'
38       assume that a `jmp_buf' begins with a `__jmp_buf' and that
39       `__mask_was_saved' follows it.  Do not move these members
40       or add others before it.  */
41    __jmp_buf __jmpbuf;		/* Calling environment.  */
42    int __mask_was_saved;	/* Saved the signal mask?  */
43    __sigset_t __saved_mask;	/* Saved signal mask.  */
44  };
45
46
47__BEGIN_NAMESPACE_STD
48
49typedef struct __jmp_buf_tag jmp_buf[1];
50
51/* Store the calling environment in ENV, also saving the signal mask.
52   Return 0.  */
53extern int setjmp (jmp_buf __env) __THROW;
54
55__END_NAMESPACE_STD
56
57/* Store the calling environment in ENV, also saving the
58   signal mask if SAVEMASK is nonzero.  Return 0.
59   This is the internal name for `sigsetjmp'.  */
60extern int __sigsetjmp (struct __jmp_buf_tag __env[1], int __savemask) __THROW;
61
62#ifndef	__FAVOR_BSD
63/* Store the calling environment in ENV, not saving the signal mask.
64   Return 0.  */
65extern int _setjmp (struct __jmp_buf_tag __env[1]) __THROW;
66
67/* Do not save the signal mask.  This is equivalent to the `_setjmp'
68   BSD function.  */
69# define setjmp(env)	_setjmp (env)
70#else
71/* We are in 4.3 BSD-compatibility mode in which `setjmp'
72   saves the signal mask like `sigsetjmp (ENV, 1)'.  We have to
73   define a macro since ISO C says `setjmp' is one.  */
74# define setjmp(env)	setjmp (env)
75#endif /* Favor BSD.  */
76
77
78__BEGIN_NAMESPACE_STD
79
80/* Jump to the environment saved in ENV, making the
81   `setjmp' call there return VAL, or 1 if VAL is 0.  */
82extern void longjmp (struct __jmp_buf_tag __env[1], int __val)
83     __THROW __attribute__ ((__noreturn__));
84
85__END_NAMESPACE_STD
86
87#if defined __USE_BSD || defined __USE_XOPEN
88/* Same.  Usually `_longjmp' is used with `_setjmp', which does not save
89   the signal mask.  But it is how ENV was saved that determines whether
90   `longjmp' restores the mask; `_longjmp' is just an alias.  */
91extern void _longjmp (struct __jmp_buf_tag __env[1], int __val)
92     __THROW __attribute__ ((__noreturn__));
93#endif
94
95
96#ifdef	__USE_POSIX
97/* Use the same type for `jmp_buf' and `sigjmp_buf'.
98   The `__mask_was_saved' flag determines whether
99   or not `longjmp' will restore the signal mask.  */
100typedef struct __jmp_buf_tag sigjmp_buf[1];
101
102/* Store the calling environment in ENV, also saving the
103   signal mask if SAVEMASK is nonzero.  Return 0.  */
104# define sigsetjmp(env, savemask)	__sigsetjmp (env, savemask)
105
106/* Jump to the environment saved in ENV, making the
107   sigsetjmp call there return VAL, or 1 if VAL is 0.
108   Restore the signal mask if that sigsetjmp call saved it.
109   This is just an alias `longjmp'.  */
110extern void siglongjmp (sigjmp_buf __env, int __val)
111     __THROW __attribute__ ((__noreturn__));
112#endif /* Use POSIX.  */
113
114
115/* Define helper functions to catch unsafe code.  */
116#if __USE_FORTIFY_LEVEL > 0
117# include <bits/setjmp2.h>
118#endif
119
120__END_DECLS
121
122#endif /* setjmp.h  */
123