2626extern "C" {
2727#endif
2828
29- #if ( defined(_X86_ ) && !defined( __x86_64 ) )
29+ #if defined(__i386__ )
3030
3131#define _JBLEN 16
3232#define _JBTYPE int
@@ -40,6 +40,7 @@ extern "C" {
4040 unsigned long Eip ;
4141 unsigned long Registration ;
4242 unsigned long TryLevel ;
43+ /* Following fields are only for new _setjmp3(), the are not for old _setjmp(). */
4344 unsigned long Cookie ;
4445 unsigned long UnwindFunc ;
4546 unsigned long UnwindData [6 ];
@@ -107,7 +108,7 @@ extern "C" {
107108
108109 } _JUMP_BUFFER ;
109110
110- #elif defined(__x86_64 )
111+ #elif defined(__x86_64__ )
111112
112113 typedef _CRT_ALIGN (16 ) struct _SETJMP_FLOAT128 {
113114 __MINGW_EXTENSION unsigned __int64 Part [2 ];
@@ -202,68 +203,83 @@ extern "C" {
202203#define _JMP_BUF_DEFINED
203204#endif
204205
205- _CRTIMP __MINGW_ATTRIB_NORETURN __attribute__ ((__nothrow__ )) void __cdecl longjmp (jmp_buf _Buf ,int _Value );
206+ _CRTIMP __MINGW_ATTRIB_NORETURN __attribute__ ((__nothrow__ )) void __cdecl longjmp (jmp_buf _Buf , int _Value ); /* for setjmp.h and non-i386 setjmpex.h */
207+ #ifdef __i386__
208+ _CRTIMP __MINGW_ATTRIB_NORETURN __attribute__ ((__nothrow__ )) void __cdecl _longjmpex (jmp_buf _Buf , int _Value ); /* for i386 setjmpex.h */
209+ #endif
210+
211+ #ifdef __i386__
212+ _CRTIMP int __cdecl __attribute__ ((__nothrow__ ,__returns_twice__ )) _setjmp (jmp_buf _Buf ); /* old i386 crtdll setjmp.h */
213+ _CRTIMP int __cdecl __attribute__ ((__nothrow__ ,__returns_twice__ )) _setjmp3 (jmp_buf _Buf , int _Count , ...); /* new i386 msvcrt20+ setjmp.h and setjmpex.h */
214+ #else
215+ #ifndef __aarch64__
216+ _CRTIMP int __cdecl __attribute__ ((__nothrow__ ,__returns_twice__ )) _setjmp (jmp_buf _Buf , void * _Frame ); /* for non-i386 and non-aarch64 setjmp.h */
217+ #endif
218+ _CRTIMP int __cdecl __attribute__ ((__nothrow__ ,__returns_twice__ )) _setjmpex (jmp_buf _Buf , void * _Frame ); /* for non-i386 setjmpex.h and aarch64 setjmp.h */
219+ #endif
220+
221+ #if defined(__arm__ ) || defined(__aarch64__ )
222+ int __cdecl __attribute__ ( (__nothrow__ ,__returns_twice__ )) __mingw_setjmp (jmp_buf _Buf );
223+ __MINGW_ATTRIB_NORETURN __attribute__ ((__nothrow__ )) void __mingw_longjmp (jmp_buf _Buf , int _Value );
224+ #endif
206225
207226void * __cdecl __attribute__ ((__nothrow__ )) mingw_getsp (void );
208227
228+ #ifdef __cplusplus
229+ }
230+ #endif
231+
232+ #pragma pack(pop)
233+ #endif /* _INC_SETJMP */
234+
235+ /*
236+ * Now outside of the _INC_SETJMP block, defines setjmp() and longjmp().
237+ * It allows '#include <setjmpex.h>' to override the existing setjmp() and longjmp() definitions.
238+ */
239+
209240#pragma push_macro("__has_builtin")
210241#ifndef __has_builtin
211242 #define __has_builtin (x ) 0
212243#endif
213244
214- #ifdef _UCRT
215- # ifdef _WIN64
216- # define _setjmp __intrinsic_setjmpex
245+ #ifdef setjmp
246+ # undef setjmp
247+ #endif
248+ #if defined(__i386__ )
249+ # define setjmp (BUF ) _setjmp3((BUF), 0)
250+ #elif !defined(_INC_SETJMPEX ) && (!defined(__SEH__ ) || defined(__USE_MINGW_SETJMP_NON_SEH ))
251+ # if defined(__arm__ ) || defined(__aarch64__ )
252+ # define setjmp (BUF ) __mingw_setjmp((BUF))
217253# else
218- # define _setjmp __intrinsic_setjmp
254+ # define setjmp ( BUF ) _setjmp((BUF), NULL)
219255# endif
220- #elif defined(__aarch64__ )
221- /* ARM64 msvcrt.dll lacks _setjmp, only has _setjmpex. */
222- # define _setjmp _setjmpex
223- #endif
224- #ifndef _INC_SETJMPEX
225- # if defined(_X86_ ) || defined(__i386__ )
226- # define setjmp (BUF ) _setjmp3((BUF), NULL)
227- # elif !defined(__SEH__ ) || defined(__USE_MINGW_SETJMP_NON_SEH )
228- # if defined(__arm__ ) || defined(__aarch64__ )
229- # define setjmp (BUF ) __mingw_setjmp((BUF))
230- # define longjmp __mingw_longjmp
231- int __cdecl __attribute__ ( (__nothrow__ ,__returns_twice__ )) __mingw_setjmp (jmp_buf _Buf );
232- __MINGW_ATTRIB_NORETURN __attribute__ ((__nothrow__ )) void __mingw_longjmp (jmp_buf _Buf ,int _Value );
233- # else
234- # define setjmp (BUF ) _setjmp((BUF), NULL)
235- # endif
236- # elif __has_builtin (__builtin_sponentry )
256+ #elif !defined(_INC_SETJMPEX ) && !defined(__aarch64__ )
257+ # if __has_builtin (__builtin_sponentry )
237258# define setjmp (BUF ) _setjmp((BUF), __builtin_sponentry())
238259# elif (__MINGW_GCC_VERSION < 40702 ) && !defined(__clang__ )
239260# define setjmp (BUF ) _setjmp((BUF), mingw_getsp())
240261# else
241- # define setjmp (BUF ) _setjmp((BUF), __builtin_frame_address (0))
262+ # define setjmp (BUF ) _setjmp((BUF), __builtin_frame_address(0))
242263# endif
243- int __cdecl __attribute__ ( (__nothrow__ ,__returns_twice__ )) _setjmp (jmp_buf _Buf , void * _Ctx );
244- int __cdecl __attribute__ ( (__nothrow__ ,__returns_twice__ )) _setjmp3 (jmp_buf _Buf , void * _Ctx );
245264#else
246- # undef setjmp
247- # ifdef __SEH__
248- # if (__MINGW_GCC_VERSION < 40702 ) && !defined(__clang__ )
249- # define setjmp (BUF ) _setjmpex((BUF), mingw_getsp())
250- # define setjmpex (BUF ) _setjmpex((BUF), mingw_getsp())
251- # else
252- # define setjmp (BUF ) _setjmpex((BUF), __builtin_frame_address (0))
253- # define setjmpex (BUF ) _setjmpex((BUF), __builtin_frame_address (0))
254- # endif
265+ # if __has_builtin (__builtin_sponentry )
266+ # define setjmp (BUF ) _setjmpex((BUF), __builtin_sponentry())
267+ # elif (__MINGW_GCC_VERSION < 40702 ) && !defined(__clang__ )
268+ # define setjmp (BUF ) _setjmpex((BUF), mingw_getsp())
255269# else
256- # define setjmp (BUF ) _setjmpex((BUF), NULL)
257- # define setjmpex (BUF ) _setjmpex((BUF), NULL)
270+ # define setjmp (BUF ) _setjmpex((BUF), __builtin_frame_address(0))
258271# endif
259- int __cdecl __attribute__ ( (__nothrow__ ,__returns_twice__ )) _setjmpex (jmp_buf _Buf ,void * _Ctx );
260272#endif
261273
262- #pragma pop_macro("__has_builtin")
263-
264- #ifdef __cplusplus
265- }
274+ #ifdef longjmp
275+ # undef longjmp
266276#endif
267-
268- #pragma pack(pop)
277+ #if defined(_INC_SETJMPEX ) && defined(__i386__ )
278+ # define longjmp _longjmpex
279+ #elif !defined(_INC_SETJMPEX ) && (!defined(__SEH__ ) || defined(__USE_MINGW_SETJMP_NON_SEH )) && (defined(__arm__ ) || defined(__aarch64__ ))
280+ # define longjmp __mingw_longjmp
281+ #else
282+ # define longjmp longjmp
269283#endif
284+
285+ #pragma pop_macro("__has_builtin")
0 commit comments