Create the AHCI branch for Aman's work
[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
64 #ifndef GetExceptionCode
65 #define GetExceptionCode() _SEH2_GetExceptionCode()
66 #endif
67
68 #ifndef GetExceptionInformation
69 #define GetExceptionInformation() _SEH2_GetExceptionInformation()
70 #endif
71
72 #ifndef AbnormalTermination
73 #define AbnormalTermination() _SEH2_AbnormalTermination()
74 #endif
75
76
77 #if defined(__MINGW32__) || defined(__CYGWIN__)
78 #define sigjmp_buf jmp_buf
79 #define sigsetjmp(buf,sigs) setjmp(buf)
80 #define siglongjmp(buf,val) longjmp(buf,val)
81 #endif
82
83 #ifdef _MSC_VER
84 #pragma warning(push)
85 #pragma warning(disable:4733)
86 #endif
87
88 static inline EXCEPTION_REGISTRATION_RECORD *__wine_push_frame( EXCEPTION_REGISTRATION_RECORD *frame )
89 {
90 #ifdef __i386__
91 frame->Prev = (struct _EXCEPTION_REGISTRATION_RECORD *)__readfsdword(0);
92 __writefsdword(0, (unsigned long)frame);
93 return frame->Prev;
94 #else
95 NT_TIB *teb = (NT_TIB *)NtCurrentTeb();
96 frame->Prev = teb->ExceptionList;
97 teb->ExceptionList = (PVOID)frame;
98 return frame->Prev;
99 #endif
100 }
101
102 static inline EXCEPTION_REGISTRATION_RECORD *__wine_pop_frame( EXCEPTION_REGISTRATION_RECORD *frame )
103 {
104 #ifdef __i386__
105 __writefsdword(0, (unsigned long)frame->Prev);
106 return frame->Prev;
107 #else
108 NT_TIB *teb = (NT_TIB *)NtCurrentTeb();
109 frame->Prev = teb->ExceptionList;
110 teb->ExceptionList = (PVOID)frame;
111 return frame->Prev;
112 #endif
113 }
114
115 #ifdef _MSC_VER
116 #pragma warning(pop)
117 #endif
118
119 extern void __wine_enter_vm86( CONTEXT *context );
120
121 #ifdef __cplusplus
122 }
123 #endif
124
125 #endif