[INCLUDE/WINE] Add __FINALLY_CTX in the context of our PSEH library. CORE-16441
[reactos.git] / sdk / include / reactos / wine / exception.h
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
20 #define EXCEPTION_WINE_STUB 0x80000100
21 #define EXCEPTION_WINE_ASSERTION 0x80000101
22
23 #define EXCEPTION_VM86_INTx 0x80000110
24 #define EXCEPTION_VM86_STI 0x80000111
25 #define EXCEPTION_VM86_PICRETURN 0x80000112
26
27 #ifndef _RTLTYPES_H
28 struct _EXCEPTION_REGISTRATION_RECORD;
29
30 typedef
31 DWORD
32 (*PEXCEPTION_HANDLER)(
33 struct _EXCEPTION_RECORD*,
34 struct _EXCEPTION_REGISTRATION_RECORD *,
35 struct _CONTEXT*,
36 struct _EXCEPTION_REGISTRATION_RECORD**);
37
38 typedef struct _EXCEPTION_REGISTRATION_RECORD EXCEPTION_REGISTRATION_RECORD, *PEXCEPTION_REGISTRATION_RECORD;
39
40 struct _EXCEPTION_REGISTRATION_RECORD
41 {
42 struct _EXCEPTION_REGISTRATION_RECORD * Prev;
43 PEXCEPTION_HANDLER Handler;
44 };
45 #else
46 typedef struct _WINE_EXCEPTION_REGISTRATION_RECORD
47 {
48 PVOID Prev;
49 PEXCEPTION_ROUTINE Handler;
50 } WINE_EXCEPTION_REGISTRATION_RECORD, *PWINE_EXCEPTION_REGISTRATION_RECORD;
51
52 #define _EXCEPTION_REGISTRATION_RECORD _WINE_EXCEPTION_REGISTRATION_RECORD
53 #define EXCEPTION_REGISTRATION_RECORD WINE_EXCEPTION_REGISTRATION_RECORD
54 #define PEXCEPTION_REGISTRATION_RECORD PWINE_EXCEPTION_REGISTRATION_RECORD
55 #endif
56
57 #define __TRY _SEH2_TRY
58 #define __EXCEPT(func) _SEH2_EXCEPT(func(_SEH2_GetExceptionInformation()))
59 #define __EXCEPT_PAGE_FAULT _SEH2_EXCEPT(_SEH2_GetExceptionCode() == STATUS_ACCESS_VIOLATION)
60 #define __EXCEPT_ALL _SEH2_EXCEPT(_SEH_EXECUTE_HANDLER)
61 #define __ENDTRY _SEH2_END
62 #define __FINALLY(func) _SEH2_FINALLY { func(!_SEH2_AbnormalTermination()); }
63 #define __FINALLY_CTX(func, ctx) _SEH2_FINALLY { func(!_SEH2_AbnormalTermination(), ctx); }; _SEH2_END
64
65 #ifndef GetExceptionCode
66 #define GetExceptionCode() _SEH2_GetExceptionCode()
67 #endif
68
69 #ifndef GetExceptionInformation
70 #define GetExceptionInformation() _SEH2_GetExceptionInformation()
71 #endif
72
73 #ifndef AbnormalTermination
74 #define AbnormalTermination() _SEH2_AbnormalTermination()
75 #endif
76
77
78 #if defined(__MINGW32__) || defined(__CYGWIN__)
79 #define sigjmp_buf jmp_buf
80 #define sigsetjmp(buf,sigs) setjmp(buf)
81 #define siglongjmp(buf,val) longjmp(buf,val)
82 #endif
83
84 #ifdef _MSC_VER
85 #pragma warning(push)
86 #pragma warning(disable:4733)
87 #endif
88
89 static inline EXCEPTION_REGISTRATION_RECORD *__wine_push_frame( EXCEPTION_REGISTRATION_RECORD *frame )
90 {
91 #ifdef __i386__
92 frame->Prev = (struct _EXCEPTION_REGISTRATION_RECORD *)__readfsdword(0);
93 __writefsdword(0, (unsigned long)frame);
94 return frame->Prev;
95 #else
96 NT_TIB *teb = (NT_TIB *)NtCurrentTeb();
97 frame->Prev = teb->ExceptionList;
98 teb->ExceptionList = (PVOID)frame;
99 return frame->Prev;
100 #endif
101 }
102
103 static inline EXCEPTION_REGISTRATION_RECORD *__wine_pop_frame( EXCEPTION_REGISTRATION_RECORD *frame )
104 {
105 #ifdef __i386__
106 __writefsdword(0, (unsigned long)frame->Prev);
107 return frame->Prev;
108 #else
109 NT_TIB *teb = (NT_TIB *)NtCurrentTeb();
110 frame->Prev = teb->ExceptionList;
111 teb->ExceptionList = (PVOID)frame;
112 return frame->Prev;
113 #endif
114 }
115
116 #ifdef _MSC_VER
117 #pragma warning(pop)
118 #endif
119
120 extern void __wine_enter_vm86( CONTEXT *context );
121
122 #ifdef __cplusplus
123 }
124 #endif
125
126 #endif