|
1 | 1 | /* sqSetjmpShim.h |
2 | 2 | * |
3 | | - * Defines to ensure we use the most minimal version of setjmp/longjmp |
| 3 | + * Defines to ensure the VM uses the most minimal version of setjmp/longjmp |
4 | 4 | * available on the platform to avoid issues with stack unwinding. |
5 | 5 | * |
6 | 6 | * Author: Eliot Miranda |
|
27 | 27 | * DEALINGS IN THE SOFTWARE. |
28 | 28 | */ |
29 | 29 |
|
30 | | -/* Use the most minimal setjmp/longjmp pair available; no signal handling |
31 | | - * wanted or necessary. On win64 to avoid crashes when unwinding the stack in |
32 | | - * Kernel32's longjmp we use the pair in platforms/win32/misc/_setjmp-x64.asm. |
| 30 | +#if !defined(__SETJMP_SHIM) |
| 31 | +#define __SETJMP_SHIM |
| 32 | + |
| 33 | +#include <setjmp.h> |
| 34 | + |
| 35 | +/* Use the most minimal setjmp/longjmp pair available; unix signal(3) handling |
| 36 | + * intentionally avoided. On win64 to avoid crashes when unwinding the stack in |
| 37 | + * Kernel32's longjmp use the pairs in platforms/win32/misc/_setjmp-???.asm. |
33 | 38 | */ |
34 | | -#if !defined(_WIN32) |
35 | | -# undef setjmp |
36 | | -# undef longjmp |
37 | | -# define setjmp _setjmp |
38 | | -# define longjmp _longjmp |
39 | | -#endif |
40 | | -/* clang on mingw redeclares _setjmp so we have to provide an alternative */ |
41 | | -#if __MINGW32__ || __MINGW64__ /* clang on cygwin/mingw */ |
42 | | -int __attribute__((__nothrow__,__returns_twice__)) _setjmp0(jmp_buf); |
43 | | -# undef _setjmp |
| 39 | +#undef setjmp |
| 40 | +#undef _setjmp |
| 41 | +#undef longjmp |
| 42 | +#undef _longjmp |
| 43 | +#define setjmp(b) _setjmp(b) |
| 44 | +#define longjmp(b,v) _longjmp(b,v) |
| 45 | + |
| 46 | +#if defined(_WIN32) || defined(_WIN64) |
| 47 | +// Windows clang redeclares _setjmp so provide an alternative |
44 | 48 | # define _setjmp(b) _setjmp0(b) |
45 | | -# undef longjmp |
46 | | -# define longjmp _longjmp |
47 | | -void _longjmp(_JBTYPE *, int); /* setjmp.h only declares __mingw_longjmp via longjmp */ |
48 | | -#endif |
| 49 | +# if defined(__GNUC__) || defined(__clang__) |
| 50 | +int __attribute__((__nothrow__,__returns_twice__)) __cdecl _setjmp0(jmp_buf jb); |
| 51 | +void __attribute__((_Noreturn)) __cdecl _longjmp(jmp_buf jb,int v); |
| 52 | +# else |
| 53 | +int __cdecl _setjmp0(jmp_buf jb); |
| 54 | +void __declspec(noreturn) __cdecl _longjmp(jmp_buf jb,int v); |
| 55 | +# endif |
| 56 | +#endif // _WIN32 || _WIN64 |
| 57 | + |
| 58 | +#endif // __SETJMP_SHIM |
0 commit comments