[CRT]
[reactos.git] / reactos / 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 typedef EXCEPTION_DISPOSITION (*PEXCEPTION_HANDLER)
29 (struct _EXCEPTION_RECORD*, void*, struct _CONTEXT*, void*);
30
31 struct _EXCEPTION_REGISTRATION_RECORD;
32 typedef struct _EXCEPTION_REGISTRATION_RECORD EXCEPTION_REGISTRATION_RECORD, *PEXCEPTION_REGISTRATION_RECORD;
33
34 struct _EXCEPTION_REGISTRATION_RECORD
35 {
36 struct _EXCEPTION_REGISTRATION_RECORD * Prev;
37 PEXCEPTION_HANDLER Handler;
38 };
39 #else
40 typedef struct _WINE_EXCEPTION_REGISTRATION_RECORD
41 {
42 PVOID Prev;
43 PEXCEPTION_ROUTINE Handler;
44 } WINE_EXCEPTION_REGISTRATION_RECORD, *PWINE_EXCEPTION_REGISTRATION_RECORD;
45
46 #define _EXCEPTION_REGISTRATION_RECORD _WINE_EXCEPTION_REGISTRATION_RECORD
47 #define EXCEPTION_REGISTRATION_RECORD WINE_EXCEPTION_REGISTRATION_RECORD
48 #define PEXCEPTION_REGISTRATION_RECORD PWINE_EXCEPTION_REGISTRATION_RECORD
49 #endif
50
51 #define __TRY _SEH2_TRY
52 #define __EXCEPT(func) _SEH2_EXCEPT(func(_SEH2_GetExceptionInformation()))
53 #define __EXCEPT_PAGE_FAULT _SEH2_EXCEPT(_SEH2_GetExceptionCode() == STATUS_ACCESS_VIOLATION)
54 #define __EXCEPT_ALL _SEH2_EXCEPT(_SEH_EXECUTE_HANDLER)
55 #define __ENDTRY _SEH2_END
56 #define __FINALLY(func) _SEH2_FINALLY { func(!_SEH2_AbnormalTermination()); }
57
58 #ifndef GetExceptionCode
59 #define GetExceptionCode() _SEH2_GetExceptionCode()
60 #endif
61
62 #ifndef GetExceptionInformation
63 #define GetExceptionInformation() _SEH2_GetExceptionInformation()
64 #endif
65
66 #ifndef AbnormalTermination
67 #define AbnormalTermination() _SEH2_AbnormalTermination()
68 #endif
69
70
71 #if defined(__MINGW32__) || defined(__CYGWIN__)
72 #define sigjmp_buf jmp_buf
73 #define sigsetjmp(buf,sigs) setjmp(buf)
74 #define siglongjmp(buf,val) longjmp(buf,val)
75 #endif
76
77 static inline EXCEPTION_REGISTRATION_RECORD *__wine_push_frame( EXCEPTION_REGISTRATION_RECORD *frame )
78 {
79 #ifdef __i386__
80 frame->Prev = (struct _EXCEPTION_REGISTRATION_RECORD *)__readfsdword(0);
81 __writefsdword(0, (unsigned long)frame);
82 return frame->Prev;
83 #else
84 NT_TIB *teb = (NT_TIB *)NtCurrentTeb();
85 frame->Prev = teb->ExceptionList;
86 teb->ExceptionList = frame;
87 return frame->Prev;
88 #endif
89 }
90
91 static inline EXCEPTION_REGISTRATION_RECORD *__wine_pop_frame( EXCEPTION_REGISTRATION_RECORD *frame )
92 {
93 #ifdef __i386__
94 __writefsdword(0, (unsigned long)frame->Prev);
95 return frame->Prev;
96 #else
97 NT_TIB *teb = (NT_TIB *)NtCurrentTeb();
98 frame->Prev = teb->ExceptionList;
99 teb->ExceptionList = frame;
100 return frame->Prev;
101 #endif
102 }
103
104 extern void __wine_enter_vm86( CONTEXT *context );
105
106 #ifdef __cplusplus
107 }
108 #endif
109
110 #endif