Cygwin: access: Fix X_OK behaviour for backup operators and admins
[newlib-cygwin.git] / newlib / libc / include / machine / setjmp.h
blob102582c8e2553f6ba4ff216d2ba13ceb7dd24adf
2 _BEGIN_STD_C
4 #if defined(__or1k__) || defined(__or1knd__)
5 /*
6 * r1, r2, r9, r14, r16 .. r30, SR.
7 */
8 #define _JBLEN 13
9 #define _JBTYPE unsigned long
10 #endif
12 #if defined(__arm__) || defined(__thumb__)
14 * All callee preserved registers:
15 * core registers:
16 * r4 - r10, fp, sp, lr
17 * VFP registers (architectural support dependent):
18 * d8 - d15
20 #define _JBLEN 20
21 #define _JBTYPE long long
22 #endif
24 #if defined(__aarch64__)
25 #define _JBLEN 22
26 #define _JBTYPE long long
27 #endif
29 #if defined(__AVR__)
30 #define _JBLEN 24
31 #endif
33 #ifdef __sparc__
35 * onsstack,sigmask,sp,pc,npc,psr,g1,o0,wbcnt (sigcontext).
36 * All else recovered by under/over(flow) handling.
38 #define _JBLEN 13
39 #endif
41 #ifdef __BFIN__
42 #define _JBLEN 40
43 #endif
45 #ifdef __epiphany__
46 /* All callee preserved registers: r4-r10,fp, sp, lr,r15, r32-r39 */
47 #define _JBTYPE long long
48 #define _JBLEN 10
49 #endif
51 /* necv70 was 9 as well. */
53 #if defined(__m68k__) || defined(__mc68000__)
55 * onsstack,sigmask,sp,pc,psl,d2-d7,a2-a6,
56 * fp2-fp7 for 68881.
57 * All else recovered by under/over(flow) handling.
59 #define _JBLEN 34
60 #endif
62 #if defined(__mc68hc11__) || defined(__mc68hc12__) || defined(__mc68hc1x__)
64 * D, X, Y are not saved.
65 * Only take into account the pseudo soft registers (max 32).
67 #define _JBLEN 32
68 #endif
70 #ifdef __nds32__
71 /* 17 words for GPRs,
72 1 word for $fpcfg.freg and 30 words for FPUs
73 Reserved 2 words for aligement-adjustment. When storeing double-precision
74 floating-point register into memory, the address has to be
75 double-word-aligned.
76 Check libc/machine/nds32/setjmp.S for more information. */
77 #if __NDS32_EXT_FPU_SP__ || __NDS32_EXT_FPU_DP__
78 #define _JBLEN 50
79 #else
80 #define _JBLEN 18
81 #endif
82 #endif
84 #if defined(__Z8001__) || defined(__Z8002__)
85 /* 16 regs + pc */
86 #define _JBLEN 20
87 #endif
89 #ifdef _AM29K
91 * onsstack,sigmask,sp,pc,npc,psr,g1,o0,wbcnt (sigcontext).
92 * All else recovered by under/over(flow) handling.
94 #define _JBLEN 9
95 #endif
97 #ifdef __i386__
98 # if defined(__CYGWIN__) && !defined (_JBLEN)
99 # define _JBLEN (13 * 4)
100 # elif defined(__unix__) || defined(__rtems__)
101 # define _JBLEN 9
102 # elif defined(__iamcu__)
103 /* Intel MCU jmp_buf only covers callee-saved registers. */
104 # define _JBLEN 6
105 # else
106 # include "setjmp-dj.h"
107 # endif
108 #endif
110 #ifdef __x86_64__
111 # ifdef __CYGWIN__
112 # define _JBTYPE long
113 # define _JBLEN 32
114 # else
115 # define _JBTYPE long long
116 # define _JBLEN 8
117 # endif
118 #endif
120 #ifdef __i960__
121 #define _JBLEN 35
122 #endif
124 #ifdef __M32R__
125 /* Only 8 words are currently needed. 10 gives us some slop if we need
126 to expand. */
127 #define _JBLEN 10
128 #endif
130 #ifdef __mips__
131 # if defined(__mips64)
132 # define _JBTYPE long long
133 # endif
134 # ifdef __mips_soft_float
135 # define _JBLEN 11
136 # else
137 # define _JBLEN 23
138 # endif
139 #endif
141 #ifdef __m88000__
142 #define _JBLEN 21
143 #endif
145 #ifdef __H8300__
146 #define _JBLEN 5
147 #define _JBTYPE int
148 #endif
150 #ifdef __H8300H__
151 /* same as H8/300 but registers are twice as big */
152 #define _JBLEN 5
153 #define _JBTYPE long
154 #endif
156 #if defined (__H8300S__) || defined (__H8300SX__)
157 /* same as H8/300 but registers are twice as big */
158 #define _JBLEN 5
159 #define _JBTYPE long
160 #endif
162 #ifdef __H8500__
163 #define _JBLEN 4
164 #endif
166 #ifdef __sh__
167 #if __SH5__
168 #define _JBLEN 50
169 #define _JBTYPE long long
170 #else
171 #define _JBLEN 20
172 #endif /* __SH5__ */
173 #endif
175 #ifdef __v800
176 #define _JBLEN 28
177 #endif
179 #ifdef __PPC__
180 #ifdef __powerpc64__
181 #ifdef __ALTIVEC__
182 #define _JBLEN 70
183 #else
184 #define _JBLEN 43
185 #endif
186 #else
187 #ifdef __ALTIVEC__
188 #define _JBLEN 64
189 #else
190 #define _JBLEN 32
191 #endif
192 #endif
193 #define _JBTYPE double
194 #endif
196 #ifdef __MICROBLAZE__
197 #define _JBLEN 20
198 #define _JBTYPE unsigned int
199 #endif
201 #ifdef __hppa__
202 /* %r30, %r2-%r18, %r27, pad, %fr12-%fr15.
203 Note space exists for the FP registers, but they are not
204 saved. */
205 #define _JBLEN 28
206 #endif
208 #if defined(__mn10300__) || defined(__mn10200__)
209 #ifdef __AM33_2__
210 #define _JBLEN 26
211 #else
212 /* A guess */
213 #define _JBLEN 10
214 #endif
215 #endif
217 #ifdef __v850
218 /* I think our setjmp is saving 15 regs at the moment. Gives us one word
219 slop if we need to expand. */
220 #define _JBLEN 16
221 #endif
223 #if defined(_C4x)
224 #define _JBLEN 10
225 #endif
226 #if defined(_C3x)
227 #define _JBLEN 9
228 #endif
230 #ifdef __TMS320C6X__
231 #define _JBLEN 13
232 #endif
234 #ifdef __TIC80__
235 #define _JBLEN 13
236 #endif
238 #ifdef __D10V__
239 #define _JBLEN 8
240 #endif
242 #ifdef __D30V__
243 #define _JBLEN ((64 /* GPR */ + (2*2) /* ACs */ + 18 /* CRs */) / 2)
244 #define _JBTYPE double
245 #endif
247 #ifdef __frv__
248 #define _JBLEN (68/2) /* room for 68 32-bit regs */
249 #define _JBTYPE double
250 #endif
252 #ifdef __moxie__
253 #define _JBLEN 10
254 #endif
256 #ifdef __CRX__
257 #define _JBLEN 9
258 #endif
260 #if (defined(__CR16__) || defined(__CR16C__) ||defined(__CR16CP__))
261 /* r6, r7, r8, r9, r10, r11, r12 (r12L, r12H),
262 * r13 (r13L, r13H), ra(raL, raH), sp(spL, spH) */
263 #define _JBLEN 14
264 #define _JBTYPE unsigned short
265 #endif
267 #ifdef __fr30__
268 #define _JBLEN 10
269 #endif
271 #ifdef __FT32__
272 #define _JBLEN 27
273 #endif
275 #ifdef __iq2000__
276 #define _JBLEN 32
277 #endif
279 #ifdef __mcore__
280 #define _JBLEN 16
281 #endif
283 #ifdef __arc__
284 #define _JBLEN 25 /* r13-r30,blink,lp_count,lp_start,lp_end,status32,r58,r59 */
285 #endif
287 #ifdef __ARC64__
288 /* r14-r27,sp,ilink,r30,blink */
289 #define _JBLEN 18
290 #ifdef __ARC64_ARCH64__
291 #define _JBTYPE long long
292 #else /* __ARC64_ARCH32__ */
293 #define _JBTYPE long
294 #endif
295 #endif /* __ARC64__ */
297 #ifdef __MMIX__
298 /* Using a layout compatible with GCC's built-in. */
299 #define _JBLEN 5
300 #define _JBTYPE unsigned long
301 #endif
303 #ifdef __mt__
304 #define _JBLEN 16
305 #endif
307 #ifdef __SPU__
308 #define _JBLEN 50
309 #define _JBTYPE __vector signed int
310 #endif
312 #ifdef __xstormy16__
313 /* 4 GPRs plus SP plus PC. */
314 #define _JBLEN 8
315 #endif
317 #ifdef __XTENSA__
318 #if __XTENSA_WINDOWED_ABI__
320 /* The jmp_buf structure for Xtensa windowed ABI holds the following
321 (where "proc" is the procedure that calls setjmp): 4-12 registers
322 from the window of proc, the 4 words from the save area at proc's $sp
323 (in case a subsequent alloca in proc moves $sp), and the return
324 address within proc. Everything else is saved on the stack in the
325 normal save areas. The jmp_buf structure is:
327 struct jmp_buf {
328 int regs[12];
329 int save[4];
330 void *return_address;
333 See the setjmp code for details. */
335 /* sizeof(struct jmp_buf) */
336 #define _JBLEN 17
338 #else /* __XTENSA_CALL0_ABI__ */
340 /* a0, a1, a12, a13, a14, a15 */
341 #define _JBLEN 6
343 #endif /* __XTENSA_CALL0_ABI__ */
344 #endif /* __XTENSA__ */
346 #ifdef __mep__
347 /* 16 GPRs, pc, hi, lo */
348 #define _JBLEN 19
349 #endif
351 #ifdef __CRIS__
352 #define _JBLEN 18
353 #endif
355 #ifdef __ia64
356 #define _JBLEN 64
357 #endif
359 #ifdef __lm32__
360 #define _JBLEN 19
361 #endif
363 #ifdef __m32c__
364 #if defined(__r8c_cpu__) || defined(__m16c_cpu__)
365 #define _JBLEN (22/2)
366 #else
367 #define _JBLEN (34/2)
368 #endif
369 #define _JBTYPE unsigned short
370 #endif /* __m32c__ */
372 #ifdef __MSP430__
373 #define _JBLEN 9
375 #ifdef __MSP430X_LARGE__
376 #define _JBTYPE unsigned long
377 #else
378 #define _JBTYPE unsigned short
379 #endif
380 #endif
382 #ifdef __RL78__
383 /* Three banks of registers, SP, CS, ES, PC */
384 #define _JBLEN (8*3+8)
385 #define _JBTYPE unsigned char
386 #endif
389 * There are two versions of setjmp()/longjmp():
390 * 1) Compiler (gcc) built-in versions.
391 * 2) Function-call versions.
393 * The built-in versions are used most of the time. When used, gcc replaces
394 * calls to setjmp()/longjmp() with inline assembly code. The built-in
395 * versions save/restore a variable number of registers.
397 * _JBLEN is set to 40 to be ultra-safe with the built-in versions.
398 * It only needs to be 12 for the function-call versions
399 * but this data structure is used by both versions.
401 #ifdef __NIOS2__
402 #define _JBLEN 40
403 #define _JBTYPE unsigned long
404 #endif
406 #ifdef __PRU__
407 #define _JBLEN 48
408 #define _JBTYPE unsigned int
409 #endif
411 #ifdef __RX__
412 #define _JBLEN 0x44
413 #endif
415 #ifdef __VISIUM__
416 /* All call-saved GP registers: r11-r19,r21,r22,r23. */
417 #define _JBLEN 12
418 #endif
420 #ifdef __riscv
421 /* _JBTYPE using long long to make sure the alignment is align to 8 byte,
422 otherwise in rv32imafd, store/restore FPR may mis-align. */
423 #define _JBTYPE long long
424 #ifdef __riscv_32e
425 #define _JBLEN ((4*sizeof(long))/sizeof(long))
426 #else
427 #define _JBLEN ((14*sizeof(long) + 12*sizeof(double))/sizeof(long))
428 #endif
429 #endif
431 #ifdef __CSKYABIV2__
432 #define _JBTYPE unsigned long
433 #if defined(__CK801__)
434 #define _JBLEN 7
435 #elif defined(__CK802__)
436 #define _JBLEN 10
437 #else
438 #define _JBLEN 18
439 #endif
440 #endif
442 #ifdef _JBLEN
443 #ifdef _JBTYPE
444 typedef _JBTYPE jmp_buf[_JBLEN];
445 #else
446 typedef int jmp_buf[_JBLEN];
447 #endif
448 #endif
450 _END_STD_C
452 #if (defined(__CYGWIN__) || defined(__rtems__)) && __POSIX_VISIBLE
453 #include <signal.h>
455 #ifdef __cplusplus
456 extern "C" {
457 #endif
459 /* POSIX sigsetjmp/siglongjmp macros */
460 #ifdef _JBTYPE
461 typedef _JBTYPE sigjmp_buf[_JBLEN+1+((sizeof (_JBTYPE) + sizeof (sigset_t) - 1)
462 /sizeof (_JBTYPE))];
463 #else
464 typedef int sigjmp_buf[_JBLEN+1+(sizeof (sigset_t)/sizeof (int))];
465 #endif
467 #define _SAVEMASK _JBLEN
468 #define _SIGMASK (_JBLEN+1)
470 #ifdef __CYGWIN__
471 # define _CYGWIN_WORKING_SIGSETJMP
472 #endif
474 #ifdef _POSIX_THREADS
475 #define __SIGMASK_FUNC pthread_sigmask
476 #else
477 #define __SIGMASK_FUNC sigprocmask
478 #endif
480 #ifdef __CYGWIN__
481 /* Per POSIX, siglongjmp has to be implemented as function. Cygwin
482 provides functions for both, siglongjmp and sigsetjmp since 2.2.0. */
483 extern void siglongjmp (sigjmp_buf, int) __attribute__ ((__noreturn__));
484 extern int sigsetjmp (sigjmp_buf, int);
485 #endif
487 #if defined(__GNUC__)
489 #define sigsetjmp(env, savemask) \
490 __extension__ \
491 ({ \
492 sigjmp_buf *_sjbuf = &(env); \
493 ((*_sjbuf)[_SAVEMASK] = savemask,\
494 __SIGMASK_FUNC (SIG_SETMASK, 0, (sigset_t *)((*_sjbuf) + _SIGMASK)),\
495 setjmp (*_sjbuf)); \
498 #define siglongjmp(env, val) \
499 __extension__ \
500 ({ \
501 sigjmp_buf *_sjbuf = &(env); \
502 ((((*_sjbuf)[_SAVEMASK]) ? \
503 __SIGMASK_FUNC (SIG_SETMASK, (sigset_t *)((*_sjbuf) + _SIGMASK), 0)\
504 : 0), \
505 longjmp (*_sjbuf, val)); \
508 #else /* !__GNUC__ */
510 #define sigsetjmp(env, savemask) ((env)[_SAVEMASK] = savemask,\
511 __SIGMASK_FUNC (SIG_SETMASK, 0, (sigset_t *) ((env) + _SIGMASK)),\
512 setjmp (env))
514 #define siglongjmp(env, val) ((((env)[_SAVEMASK])?\
515 __SIGMASK_FUNC (SIG_SETMASK, (sigset_t *) ((env) + _SIGMASK), 0):0),\
516 longjmp (env, val))
518 #endif
520 /* POSIX _setjmp/_longjmp, maintained for XSI compatibility. These
521 are equivalent to sigsetjmp/siglongjmp when not saving the signal mask.
522 New applications should use sigsetjmp/siglongjmp instead. */
523 #ifdef __CYGWIN__
524 extern void _longjmp (jmp_buf, int) __attribute__ ((__noreturn__));
525 extern int _setjmp (jmp_buf);
526 #else
527 #define _setjmp(env) sigsetjmp ((env), 0)
528 #define _longjmp(env, val) siglongjmp ((env), (val))
529 #endif
531 #ifdef __cplusplus
533 #endif
534 #endif /* (__CYGWIN__ or __rtems__) and __POSIX_VISIBLE */