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