setjmp.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /* Copyright (C) 1991-1999,2001,2002,2007,2009 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, see
  13. <http://www.gnu.org/licenses/>. */
  14. /*
  15. * ISO C99 Standard: 7.13 Nonlocal jumps <setjmp.h>
  16. */
  17. #ifndef _SETJMP_H
  18. #define _SETJMP_H 1
  19. #include <features.h>
  20. __BEGIN_DECLS
  21. #include <bits/setjmp.h> /* Get `__jmp_buf'. */
  22. #include <bits/sigset.h> /* Get `__sigset_t'. */
  23. /* Calling environment, plus possibly a saved signal mask. */
  24. struct __jmp_buf_tag
  25. {
  26. /* NOTE: The machine-dependent definitions of `__sigsetjmp'
  27. assume that a `jmp_buf' begins with a `__jmp_buf' and that
  28. `__mask_was_saved' follows it. Do not move these members
  29. or add others before it. */
  30. __jmp_buf __jmpbuf; /* Calling environment. */
  31. int __mask_was_saved; /* Saved the signal mask? */
  32. __sigset_t __saved_mask; /* Saved signal mask. */
  33. };
  34. __BEGIN_NAMESPACE_STD
  35. typedef struct __jmp_buf_tag jmp_buf[1];
  36. /* Store the calling environment in ENV, also saving the signal mask.
  37. Return 0. */
  38. extern int setjmp (jmp_buf __env) __THROW;
  39. __END_NAMESPACE_STD
  40. /* Store the calling environment in ENV, also saving the
  41. signal mask if SAVEMASK is nonzero. Return 0.
  42. This is the internal name for `sigsetjmp'. */
  43. extern int __sigsetjmp (struct __jmp_buf_tag __env[1], int __savemask) __THROW;
  44. #ifndef __FAVOR_BSD
  45. /* Store the calling environment in ENV, not saving the signal mask.
  46. Return 0. */
  47. extern int _setjmp (struct __jmp_buf_tag __env[1]) __THROW;
  48. /* Do not save the signal mask. This is equivalent to the `_setjmp'
  49. BSD function. */
  50. # define setjmp(env) _setjmp (env)
  51. #else
  52. /* We are in 4.3 BSD-compatibility mode in which `setjmp'
  53. saves the signal mask like `sigsetjmp (ENV, 1)'. We have to
  54. define a macro since ISO C says `setjmp' is one. */
  55. # define setjmp(env) setjmp (env)
  56. #endif /* Favor BSD. */
  57. __BEGIN_NAMESPACE_STD
  58. /* Jump to the environment saved in ENV, making the
  59. `setjmp' call there return VAL, or 1 if VAL is 0. */
  60. extern void longjmp (struct __jmp_buf_tag __env[1], int __val)
  61. __THROW __attribute__ ((__noreturn__));
  62. __END_NAMESPACE_STD
  63. #if defined __USE_BSD || defined __USE_XOPEN
  64. /* Same. Usually `_longjmp' is used with `_setjmp', which does not save
  65. the signal mask. But it is how ENV was saved that determines whether
  66. `longjmp' restores the mask; `_longjmp' is just an alias. */
  67. extern void _longjmp (struct __jmp_buf_tag __env[1], int __val)
  68. __THROW __attribute__ ((__noreturn__));
  69. #endif
  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. */
  74. typedef struct __jmp_buf_tag sigjmp_buf[1];
  75. /* Store the calling environment in ENV, also saving the
  76. signal mask if SAVEMASK is nonzero. Return 0. */
  77. # define sigsetjmp(env, savemask) __sigsetjmp (env, savemask)
  78. /* Jump to the environment saved in ENV, making the
  79. sigsetjmp call there return VAL, or 1 if VAL is 0.
  80. Restore the signal mask if that sigsetjmp call saved it.
  81. This is just an alias `longjmp'. */
  82. extern void siglongjmp (sigjmp_buf __env, int __val)
  83. __THROW __attribute__ ((__noreturn__));
  84. #endif /* Use POSIX. */
  85. __END_DECLS
  86. #ifdef _LIBC
  87. extern void __longjmp(__jmp_buf __env, int __val) attribute_noreturn;
  88. libc_hidden_proto(__longjmp)
  89. extern __typeof(longjmp) __libc_longjmp attribute_noreturn;
  90. extern __typeof(siglongjmp) __libc_siglongjmp attribute_noreturn;
  91. extern void _longjmp_unwind(jmp_buf __env, int __val);
  92. libc_hidden_proto(_longjmp_unwind)
  93. extern int __sigjmp_save(sigjmp_buf __env, int __savemask) attribute_hidden;
  94. /* We use the normal longjmp for unwinding */
  95. # define __libc_unwind_longjmp(buf, val) __libc_longjmp(buf, val)
  96. #endif
  97. #endif /* setjmp.h */