1 #ifndef __WINE_WINE_EXCEPTION_H 2 #define __WINE_WINE_EXCEPTION_H 3 4 #include <setjmp.h> 5 #include <intrin.h> 6 #include <pseh/pseh2.h> 7 #include <pseh/excpt.h> 8 9 #ifdef __cplusplus 10 extern "C" { 11 #endif 12 13 /* Win32 seems to use the same flags as ExceptionFlags in an EXCEPTION_RECORD */ 14 #define EH_NONCONTINUABLE 0x01 15 #define EH_UNWINDING 0x02 16 #define EH_EXIT_UNWIND 0x04 17 #define EH_STACK_INVALID 0x08 18 #define EH_NESTED_CALL 0x10 19 #define EH_TARGET_UNWIND 0x20 20 #define EH_COLLIDED_UNWIND 0x40 21 22 #define EXCEPTION_WINE_STUB 0x80000100 23 #define EXCEPTION_WINE_ASSERTION 0x80000101 24 25 #define EXCEPTION_VM86_INTx 0x80000110 26 #define EXCEPTION_VM86_STI 0x80000111 27 #define EXCEPTION_VM86_PICRETURN 0x80000112 28 29 #ifndef _RTLTYPES_H 30 struct _EXCEPTION_REGISTRATION_RECORD; 31 32 typedef 33 DWORD 34 (*PEXCEPTION_HANDLER)( 35 struct _EXCEPTION_RECORD*, 36 struct _EXCEPTION_REGISTRATION_RECORD *, 37 struct _CONTEXT*, 38 struct _EXCEPTION_REGISTRATION_RECORD**); 39 40 typedef struct _EXCEPTION_REGISTRATION_RECORD EXCEPTION_REGISTRATION_RECORD, *PEXCEPTION_REGISTRATION_RECORD; 41 42 struct _EXCEPTION_REGISTRATION_RECORD 43 { 44 struct _EXCEPTION_REGISTRATION_RECORD * Prev; 45 PEXCEPTION_HANDLER Handler; 46 }; 47 #else 48 typedef struct _WINE_EXCEPTION_REGISTRATION_RECORD 49 { 50 PVOID Prev; 51 PEXCEPTION_ROUTINE Handler; 52 } WINE_EXCEPTION_REGISTRATION_RECORD, *PWINE_EXCEPTION_REGISTRATION_RECORD; 53 54 #define _EXCEPTION_REGISTRATION_RECORD _WINE_EXCEPTION_REGISTRATION_RECORD 55 #define EXCEPTION_REGISTRATION_RECORD WINE_EXCEPTION_REGISTRATION_RECORD 56 #define PEXCEPTION_REGISTRATION_RECORD PWINE_EXCEPTION_REGISTRATION_RECORD 57 #endif 58 59 #define __TRY _SEH2_TRY 60 #define __EXCEPT(func) _SEH2_EXCEPT(func(_SEH2_GetExceptionInformation())) 61 #define __EXCEPT_CTX(func, ctx) _SEH2_EXCEPT((func)(GetExceptionInformation(), ctx)) 62 #define __EXCEPT_PAGE_FAULT _SEH2_EXCEPT(_SEH2_GetExceptionCode() == STATUS_ACCESS_VIOLATION) 63 #define __EXCEPT_ALL _SEH2_EXCEPT(_SEH_EXECUTE_HANDLER) 64 #define __ENDTRY _SEH2_END 65 #define __FINALLY(func) _SEH2_FINALLY { func(!_SEH2_AbnormalTermination()); } 66 #define __FINALLY_CTX(func, ctx) _SEH2_FINALLY { func(!_SEH2_AbnormalTermination(), ctx); }; _SEH2_END 67 68 #ifndef GetExceptionCode 69 #define GetExceptionCode() _SEH2_GetExceptionCode() 70 #endif 71 72 #ifndef GetExceptionInformation 73 #define GetExceptionInformation() _SEH2_GetExceptionInformation() 74 #endif 75 76 #ifndef AbnormalTermination 77 #define AbnormalTermination() _SEH2_AbnormalTermination() 78 #endif 79 80 81 #if defined(__MINGW32__) || defined(__CYGWIN__) 82 #define sigjmp_buf jmp_buf 83 #define sigsetjmp(buf,sigs) setjmp(buf) 84 #define siglongjmp(buf,val) longjmp(buf,val) 85 #endif 86 87 #ifdef _MSC_VER 88 #pragma warning(push) 89 #pragma warning(disable:4733) 90 #endif 91 92 static inline EXCEPTION_REGISTRATION_RECORD *__wine_push_frame( EXCEPTION_REGISTRATION_RECORD *frame ) 93 { 94 #ifdef __i386__ 95 frame->Prev = (struct _EXCEPTION_REGISTRATION_RECORD *)__readfsdword(0); 96 __writefsdword(0, (unsigned long)frame); 97 return frame->Prev; 98 #else 99 NT_TIB *teb = (NT_TIB *)NtCurrentTeb(); 100 frame->Prev = teb->ExceptionList; 101 teb->ExceptionList = (PVOID)frame; 102 return frame->Prev; 103 #endif 104 } 105 106 static inline EXCEPTION_REGISTRATION_RECORD *__wine_pop_frame( EXCEPTION_REGISTRATION_RECORD *frame ) 107 { 108 #ifdef __i386__ 109 __writefsdword(0, (unsigned long)frame->Prev); 110 return frame->Prev; 111 #else 112 NT_TIB *teb = (NT_TIB *)NtCurrentTeb(); 113 frame->Prev = teb->ExceptionList; 114 teb->ExceptionList = (PVOID)frame; 115 return frame->Prev; 116 #endif 117 } 118 119 #ifdef _MSC_VER 120 #pragma warning(pop) 121 #endif 122 123 extern void __wine_enter_vm86( CONTEXT *context ); 124 125 #ifdef __cplusplus 126 } 127 #endif 128 129 #endif 130