setjmp.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. /*++
  2. Copyright (c) 2013 Minoca Corp.
  3. This file is licensed under the terms of the GNU General Public License
  4. version 3. Alternative licensing terms are available. Contact
  5. info@minocacorp.com for details. See the LICENSE file at the root of this
  6. project for complete licensing information.
  7. Module Name:
  8. setjmp.h
  9. Abstract:
  10. This header contains definitions for the setjmp and longjmp functions,
  11. which provide non-local goto support.
  12. Author:
  13. Evan Green 22-Jul-2013
  14. --*/
  15. #ifndef _SETJMP_H
  16. #define _SETJMP_H
  17. //
  18. // ------------------------------------------------------------------- Includes
  19. //
  20. #include <libcbase.h>
  21. #include <stddef.h>
  22. //
  23. // ---------------------------------------------------------------- Definitions
  24. //
  25. #ifdef __cplusplus
  26. extern "C" {
  27. #endif
  28. //
  29. // ------------------------------------------------------ Data Type Definitions
  30. //
  31. //
  32. // Define the mystery jump buffer type, which is a platform-depenent structure,
  33. // usually used to hold non-volatile variables.
  34. //
  35. typedef long jmp_buf[16];
  36. typedef long sigjmp_buf[16];
  37. //
  38. // -------------------------------------------------------------------- Globals
  39. //
  40. //
  41. // -------------------------------------------------------- Function Prototypes
  42. //
  43. LIBC_API
  44. int
  45. setjmp (
  46. jmp_buf Environment
  47. );
  48. /*++
  49. Routine Description:
  50. This routine saves the calling environment into the given buffer for
  51. later use by longjmp.
  52. Arguments:
  53. Environment - Supplies the pointer to the environment to save the
  54. application context in.
  55. Return Value:
  56. 0 if this was the direct call to setjmp.
  57. Non-zero if this was a call from longjmp.
  58. --*/
  59. LIBC_API
  60. int
  61. _setjmp (
  62. jmp_buf Environment
  63. );
  64. /*++
  65. Routine Description:
  66. This routine saves the calling environment into the given buffer for
  67. later use by longjmp.
  68. Arguments:
  69. Environment - Supplies the pointer to the environment to save the
  70. application context in.
  71. Return Value:
  72. 0 if this was the direct call to setjmp.
  73. Non-zero if this was a call from longjmp.
  74. --*/
  75. LIBC_API
  76. int
  77. sigsetjmp (
  78. sigjmp_buf Environment,
  79. int SaveMask
  80. );
  81. /*++
  82. Routine Description:
  83. This routine saves the calling environment into the given buffer for
  84. later use by longjmp.
  85. Arguments:
  86. Environment - Supplies the pointer to the environment to save the
  87. application context in.
  88. SaveMask - Supplies a value indicating if the caller would like the
  89. current signal mask to be saved in the environment as well.
  90. Return Value:
  91. 0 if this was the direct call to setjmp.
  92. Non-zero if this was a call from longjmp.
  93. --*/
  94. LIBC_API
  95. void
  96. longjmp (
  97. jmp_buf Environment,
  98. int Value
  99. );
  100. /*++
  101. Routine Description:
  102. This routine restores the environment saved by the most recent invocation
  103. of setjmp with the given environment buffer. If there is no such invocation,
  104. or if the function containing the invocation of setjmp has terminated in
  105. the interim, the behavior is undefined. Most likely, the app will crash
  106. spectacularly.
  107. Arguments:
  108. Environment - Supplies the pointer to the previously saved environment to
  109. restore.
  110. Value - Supplies the value to set as the return value from the setjmp
  111. function. If this value is 0, it will be set to 1.
  112. Return Value:
  113. None, this routine does not return.
  114. --*/
  115. LIBC_API
  116. void
  117. _longjmp (
  118. jmp_buf Environment,
  119. int Value
  120. );
  121. /*++
  122. Routine Description:
  123. This routine restores the environment saved by the most recent invocation
  124. of setjmp with the given environment buffer. If there is no such invocation,
  125. or if the function containing the invocation of setjmp has terminated in
  126. the interim, the behavior is undefined. Most likely, the app will crash
  127. spectacularly.
  128. Arguments:
  129. Environment - Supplies the pointer to the previously saved environment to
  130. restore.
  131. Value - Supplies the value to set as the return value from the setjmp
  132. function. If this value is 0, it will be set to 1.
  133. Return Value:
  134. None, this routine does not return.
  135. --*/
  136. LIBC_API
  137. void
  138. siglongjmp (
  139. sigjmp_buf Environment,
  140. int Value
  141. );
  142. /*++
  143. Routine Description:
  144. This routine restores the environment saved by the most recent invocation
  145. of setjmp with the given environment buffer. It works just like the longjmp
  146. function, except it also restores the signal mask if the given environment
  147. buffer was initialized with sigsetjmp with a non-zero save mask value.
  148. Arguments:
  149. Environment - Supplies the pointer to the previously saved environment to
  150. restore.
  151. Value - Supplies the value to set as the return value from the setjmp
  152. function. If this value is 0, it will be set to 1.
  153. Return Value:
  154. None, this routine does not return.
  155. --*/
  156. #ifdef __cplusplus
  157. }
  158. #endif
  159. #endif