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