setjmp.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. _BEGIN_STD_C
  2. #if defined(__tricore__)
  3. #define _JBTYPE \
  4. struct _jmp_buf { unsigned long return_address; unsigned long upper_ctx[16]; }
  5. #define _JBLEN 1
  6. #endif
  7. #if defined(__arm__) || defined(__thumb__)
  8. /*
  9. * All callee preserved registers:
  10. * v1 - v7, fp, ip, sp, lr, f4, f5, f6, f7
  11. */
  12. #define _JBLEN 23
  13. #endif
  14. #if defined(__AVR__)
  15. #define _JBLEN 24
  16. #endif
  17. #ifdef __sparc__
  18. /*
  19. * onsstack,sigmask,sp,pc,npc,psr,g1,o0,wbcnt (sigcontext).
  20. * All else recovered by under/over(flow) handling.
  21. */
  22. #define _JBLEN 13
  23. #endif
  24. #ifdef __BFIN__
  25. #define _JBLEN 40
  26. #endif
  27. /* necv70 was 9 as well. */
  28. #if defined(__m68k__) || defined(__mc68000__)
  29. /*
  30. * onsstack,sigmask,sp,pc,psl,d2-d7,a2-a6,
  31. * fp2-fp7 for 68881.
  32. * All else recovered by under/over(flow) handling.
  33. */
  34. #define _JBLEN 34
  35. #endif
  36. #if defined(__mc68hc11__) || defined(__mc68hc12__) || defined(__mc68hc1x__)
  37. /*
  38. * D, X, Y are not saved.
  39. * Only take into account the pseudo soft registers (max 32).
  40. */
  41. #define _JBLEN 32
  42. #endif
  43. #if defined(__Z8001__) || defined(__Z8002__)
  44. /* 16 regs + pc */
  45. #define _JBLEN 20
  46. #endif
  47. #ifdef _AM29K
  48. /*
  49. * onsstack,sigmask,sp,pc,npc,psr,g1,o0,wbcnt (sigcontext).
  50. * All else recovered by under/over(flow) handling.
  51. */
  52. #define _JBLEN 9
  53. #endif
  54. #if defined(__CYGWIN__) && !defined (_JBLEN)
  55. #define _JBLEN (13 * 4)
  56. #elif defined (__i386__)
  57. #if defined(__unix__) || defined(__rtems__)
  58. # define _JBLEN 9
  59. #else
  60. #include "setjmp-dj.h"
  61. #endif
  62. #endif
  63. #ifdef __x86_64__
  64. #define _JBTYPE long long
  65. #define _JBLEN 8
  66. #endif
  67. #ifdef __i960__
  68. #define _JBLEN 35
  69. #endif
  70. #ifdef __M32R__
  71. /* Only 8 words are currently needed. 10 gives us some slop if we need
  72. to expand. */
  73. #define _JBLEN 10
  74. #endif
  75. #ifdef __mips__
  76. #ifdef __mips64
  77. #define _JBTYPE long long
  78. #endif
  79. #ifdef __mips_soft_float
  80. #define _JBLEN 11
  81. #else
  82. #define _JBLEN 23
  83. #endif
  84. #endif
  85. #ifdef __m88000__
  86. #define _JBLEN 21
  87. #endif
  88. #ifdef __H8300__
  89. #define _JBLEN 5
  90. #define _JBTYPE int
  91. #endif
  92. #ifdef __H8300H__
  93. /* same as H8/300 but registers are twice as big */
  94. #define _JBLEN 5
  95. #define _JBTYPE long
  96. #endif
  97. #if defined (__H8300S__) || defined (__H8300SX__)
  98. /* same as H8/300 but registers are twice as big */
  99. #define _JBLEN 5
  100. #define _JBTYPE long
  101. #endif
  102. #ifdef __H8500__
  103. #define _JBLEN 4
  104. #endif
  105. #ifdef __sh__
  106. #if __SH5__
  107. #define _JBLEN 50
  108. #define _JBTYPE long long
  109. #else
  110. #define _JBLEN 20
  111. #endif /* __SH5__ */
  112. #endif
  113. #ifdef __v800
  114. #define _JBLEN 28
  115. #endif
  116. #ifdef __PPC__
  117. #ifdef __ALTIVEC__
  118. #define _JBLEN 64
  119. #else
  120. #define _JBLEN 32
  121. #endif
  122. #define _JBTYPE double
  123. #endif
  124. #ifdef __MICROBLAZE__
  125. #define _JBLEN 20
  126. #define _JBTYPE unsigned int
  127. #endif
  128. #ifdef __hppa__
  129. /* %r30, %r2-%r18, %r27, pad, %fr12-%fr15.
  130. Note space exists for the FP registers, but they are not
  131. saved. */
  132. #define _JBLEN 28
  133. #endif
  134. #if defined(__mn10300__) || defined(__mn10200__)
  135. #ifdef __AM33_2__
  136. #define _JBLEN 26
  137. #else
  138. /* A guess */
  139. #define _JBLEN 10
  140. #endif
  141. #endif
  142. #ifdef __v850
  143. /* I think our setjmp is saving 15 regs at the moment. Gives us one word
  144. slop if we need to expand. */
  145. #define _JBLEN 16
  146. #endif
  147. #if defined(_C4x)
  148. #define _JBLEN 10
  149. #endif
  150. #if defined(_C3x)
  151. #define _JBLEN 9
  152. #endif
  153. #ifdef __TIC80__
  154. #define _JBLEN 13
  155. #endif
  156. #ifdef __D10V__
  157. #define _JBLEN 8
  158. #endif
  159. #ifdef __D30V__
  160. #define _JBLEN ((64 /* GPR */ + (2*2) /* ACs */ + 18 /* CRs */) / 2)
  161. #define _JBTYPE double
  162. #endif
  163. #ifdef __frv__
  164. #define _JBLEN (68/2) /* room for 68 32-bit regs */
  165. #define _JBTYPE double
  166. #endif
  167. #ifdef __moxie__
  168. #define _JBLEN 16
  169. #endif
  170. #ifdef __CRX__
  171. #define _JBLEN 9
  172. #endif
  173. #ifdef __fr30__
  174. #define _JBLEN 10
  175. #endif
  176. #ifdef __iq2000__
  177. #define _JBLEN 32
  178. #endif
  179. #ifdef __mcore__
  180. #define _JBLEN 16
  181. #endif
  182. #ifdef __MMIX__
  183. /* Using a layout compatible with GCC's built-in. */
  184. #define _JBLEN 5
  185. #define _JBTYPE unsigned long
  186. #endif
  187. #ifdef __mt__
  188. #define _JBLEN 16
  189. #endif
  190. #ifdef __SPU__
  191. #define _JBLEN 50
  192. #define _JBTYPE __vector signed int
  193. #endif
  194. #ifdef __xstormy16__
  195. /* 4 GPRs plus SP plus PC. */
  196. #define _JBLEN 8
  197. #endif
  198. #ifdef __mep__
  199. /* 16 GPRs, pc, hi, lo */
  200. #define _JBLEN 19
  201. #endif
  202. #ifdef __CRIS__
  203. #define _JBLEN 18
  204. #endif
  205. #ifdef __lm32__
  206. #define _JBLEN 19
  207. #endif
  208. #ifdef __m32c__
  209. #if defined(__r8c_cpu__) || defined(__m16c_cpu__)
  210. #define _JBLEN (22/2)
  211. #else
  212. #define _JBLEN (34/2)
  213. #endif
  214. #define _JBTYPE unsigned short
  215. #endif /* __m32c__ */
  216. #ifdef __RX__
  217. #define _JBLEN 0x44
  218. #endif
  219. #ifdef _JBLEN
  220. #ifdef _JBTYPE
  221. typedef _JBTYPE jmp_buf[_JBLEN];
  222. #else
  223. typedef int jmp_buf[_JBLEN];
  224. #endif
  225. #endif
  226. _END_STD_C
  227. #if defined(__CYGWIN__) || defined(__rtems__)
  228. #include <signal.h>
  229. #ifdef __cplusplus
  230. extern "C" {
  231. #endif
  232. /* POSIX sigsetjmp/siglongjmp macros */
  233. #ifdef _JBTYPE
  234. typedef _JBTYPE sigjmp_buf[_JBLEN+1+(sizeof (sigset_t)/sizeof (_JBTYPE))];
  235. #else
  236. typedef int sigjmp_buf[_JBLEN+1+(sizeof (sigset_t)/sizeof (int))];
  237. #endif
  238. #define _SAVEMASK _JBLEN
  239. #define _SIGMASK (_JBLEN+1)
  240. #ifdef __CYGWIN__
  241. # define _CYGWIN_WORKING_SIGSETJMP
  242. #endif
  243. #ifdef _POSIX_THREADS
  244. #define __SIGMASK_FUNC pthread_sigmask
  245. #else
  246. #define __SIGMASK_FUNC sigprocmask
  247. #endif
  248. #if defined(__GNUC__)
  249. #define sigsetjmp(env, savemask) \
  250. __extension__ \
  251. ({ \
  252. sigjmp_buf *_sjbuf = &(env); \
  253. ((*_sjbuf)[_SAVEMASK] = savemask,\
  254. __SIGMASK_FUNC (SIG_SETMASK, 0, (sigset_t *)((*_sjbuf) + _SIGMASK)),\
  255. setjmp (*_sjbuf)); \
  256. })
  257. #define siglongjmp(env, val) \
  258. __extension__ \
  259. ({ \
  260. sigjmp_buf *_sjbuf = &(env); \
  261. ((((*_sjbuf)[_SAVEMASK]) ? \
  262. __SIGMASK_FUNC (SIG_SETMASK, (sigset_t *)((*_sjbuf) + _SIGMASK), 0)\
  263. : 0), \
  264. longjmp (*_sjbuf, val)); \
  265. })
  266. #else /* !__GNUC__ */
  267. #define sigsetjmp(env, savemask) ((env)[_SAVEMASK] = savemask,\
  268. __SIGMASK_FUNC (SIG_SETMASK, 0, (sigset_t *) ((env) + _SIGMASK)),\
  269. setjmp (env))
  270. #define siglongjmp(env, val) ((((env)[_SAVEMASK])?\
  271. __SIGMASK_FUNC (SIG_SETMASK, (sigset_t *) ((env) + _SIGMASK), 0):0),\
  272. longjmp (env, val))
  273. #endif
  274. /* POSIX _setjmp/_longjmp, maintained for XSI compatibility. These
  275. are equivalent to sigsetjmp/siglongjmp when not saving the signal mask.
  276. New applications should use sigsetjmp/siglongjmp instead. */
  277. #ifdef __CYGWIN__
  278. extern void _longjmp(jmp_buf, int);
  279. extern int _setjmp(jmp_buf);
  280. #else
  281. #define _setjmp(env) sigsetjmp ((env), 0)
  282. #define _longjmp(env, val) siglongjmp ((env), (val))
  283. #endif
  284. #ifdef __cplusplus
  285. }
  286. #endif
  287. #endif /* __CYGWIN__ or __rtems__ */