Mainly just added some small #ifdef sections for a little portability.
[reactos.git] / reactos / include / ntos / except.h
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * FILE: include/ntos/except.h
5 * PURPOSE: Exception handling structures
6 * PROGRAMMER: Casper S. Hornstrup <chorns@users.sourceforge.net>
7 */
8
9 #ifndef __INCLUDE_EXCEPT_H
10 #define __INCLUDE_EXCEPT_H
11
12 typedef enum {
13 ExceptionContinueExecution = 0,
14 ExceptionContinueSearch,
15 ExceptionNestedException,
16 ExceptionCollidedUnwind,
17 ExceptionDismiss // ???
18 } EXCEPTION_DISPOSITION;
19
20
21 struct _EXCEPTION_RECORD;
22 struct _EXCEPTION_REGISTRATION;
23
24 /*
25 * The type of function that is expected as an exception handler to be
26 * installed with _try1.
27 */
28 #ifdef __GNUC__
29 typedef EXCEPTION_DISPOSITION (CDECL *PEXCEPTION_HANDLER)(
30 struct _EXCEPTION_RECORD* ExceptionRecord,
31 struct _EXCEPTION_REGISTRATION* ExceptionRegistration,
32 PCONTEXT Context,
33 PVOID DispatcherContext);
34 #else
35 typedef EXCEPTION_DISPOSITION (CDECL *PEXCEPTION_HANDLER)(
36 struct _EXCEPTION_RECORD* ExceptionRecord,
37 struct _EXCEPTION_REGISTRATION* ExceptionRegistration,
38 PCONTEXT Context,
39 PVOID DispatcherContext);
40 #endif /*__GNUC__*/
41
42 #ifndef __USE_W32API
43
44 #define EXCEPTION_MAXIMUM_PARAMETERS (15)
45
46 typedef struct _EXCEPTION_RECORD {
47 DWORD ExceptionCode;
48 DWORD ExceptionFlags;
49 struct _EXCEPTION_RECORD *ExceptionRecord;
50 PVOID ExceptionAddress;
51 DWORD NumberParameters;
52 DWORD ExceptionInformation[EXCEPTION_MAXIMUM_PARAMETERS];
53 } EXCEPTION_RECORD, *PEXCEPTION_RECORD, *LPEXCEPTION_RECORD;
54
55 #endif /* !__USE_W32API */
56
57 /* ExceptionFlags */
58 #ifndef _GNU_H_WINDOWS32_DEFINES
59 #ifdef __NTOSKRNL__
60 #define EXCEPTION_NONCONTINUABLE 0x01
61 #endif /* __NTOSKRNL__ */
62 #endif /* _GNU_H_WINDOWS32_DEFINES */
63 #define EXCEPTION_UNWINDING 0x02
64 #define EXCEPTION_EXIT_UNWIND 0x04
65 #define EXCEPTION_STACK_INVALID 0x08
66 #define EXCEPTION_NESTED_CALL 0x10
67
68
69 typedef struct _EXCEPTION_REGISTRATION
70 {
71 struct _EXCEPTION_REGISTRATION* prev;
72 PEXCEPTION_HANDLER handler;
73 } EXCEPTION_REGISTRATION, *PEXCEPTION_REGISTRATION;
74
75 typedef EXCEPTION_REGISTRATION EXCEPTION_REGISTRATION_RECORD;
76 typedef PEXCEPTION_REGISTRATION PEXCEPTION_REGISTRATION_RECORD;
77
78
79 /*
80 * A macro which installs the supplied exception handler.
81 * Push the pointer to the new handler onto the stack,
82 * then push the pointer to the old registration structure (at fs:0)
83 * onto the stack, then put a pointer to the new registration
84 * structure (i.e. the current stack pointer) at fs:0.
85 */
86 #define __try1(pHandler) \
87 __asm__ ("pushl %0;pushl %%fs:0;movl %%esp,%%fs:0;" : : "g" (pHandler));
88
89
90 /*
91 * A macro which (dispite its name) *removes* an installed
92 * exception handler. Should be used only in conjunction with the above
93 * install routine __try1.
94 * Move the pointer to the old reg. struct (at the current stack
95 * position) to fs:0, replacing the pointer we installed above,
96 * then add 8 to the stack pointer to get rid of the space we
97 * used when we pushed on our new reg. struct above. Notice that
98 * the stack must be in the exact state at this point that it was
99 * after we did _try1 or this will smash things.
100 */
101 #define __except1 \
102 __asm__ ("movl (%%esp),%%eax;movl %%eax,%%fs:0;addl $8,%%esp;" \
103 : : : "%eax");
104
105
106 #if 1
107
108 // Runtime DLL structures
109
110 #ifndef _GNU_H_WINDOWS32_DEFINES
111 #ifdef __NTOSKRNL__
112 #define EXCEPTION_EXECUTE_HANDLER 1
113 #define EXCEPTION_CONTINUE_SEARCH 0
114 #define EXCEPTION_CONTINUE_EXECUTION -1
115 #endif /* __NTOSKRNL__ */
116 #endif /* _GNU_H_WINDOWS32_DEFINES */
117
118 // Functions of the following prototype return one of the above constants
119 #ifdef __GNUC__
120 typedef DWORD CDECL (*PSCOPE_EXCEPTION_FILTER)(VOID);
121 typedef VOID CDECL (*PSCOPE_EXCEPTION_HANDLER)(VOID);
122 #else
123 typedef DWORD (CDECL *PSCOPE_EXCEPTION_FILTER)(VOID);
124 typedef VOID (CDECL *PSCOPE_EXCEPTION_HANDLER)(VOID);
125 #endif /*__GNUC__*/
126
127 typedef struct _SCOPETABLE_ENTRY
128 {
129 DWORD PreviousTryLevel;
130 PSCOPE_EXCEPTION_FILTER FilterRoutine;
131 PSCOPE_EXCEPTION_HANDLER HandlerRoutine;
132 } SCOPETABLE_ENTRY, *PSCOPETABLE_ENTRY;
133
134 /*
135 Other structures preceeding this structure:
136 ULONG_PTR StandardESPInFrame;
137 LPEXCEPTION_POINTERS ExceptionPointers;
138 */
139 typedef struct _RTL_EXCEPTION_REGISTRATION_I386
140 {
141 EXCEPTION_REGISTRATION OS;
142 PSCOPETABLE_ENTRY ScopeTable;
143 DWORD TryLevel;
144 /* Value of EBP before the EXCEPTION_REGISTRATION was created */
145 ULONG_PTR Ebp;
146 } RTL_EXCEPTION_REGISTRATION_I386, *PRTL_EXCEPTION_REGISTRATION_I386;
147
148 #define TRYLEVEL_NONE -1
149
150 typedef RTL_EXCEPTION_REGISTRATION_I386 RTL_EXCEPTION_REGISTRATION;
151 typedef PRTL_EXCEPTION_REGISTRATION_I386 PRTL_EXCEPTION_REGISTRATION;
152
153 #endif
154
155 #ifndef __USE_W32API
156
157 #define EXCEPTION_MAXIMUM_PARAMETERS (15)
158
159 typedef struct _EXCEPTION_POINTERS {
160 PEXCEPTION_RECORD ExceptionRecord;
161 PCONTEXT ContextRecord;
162 } EXCEPTION_POINTERS, *PEXCEPTION_POINTERS, *LPEXCEPTION_POINTERS;
163
164 #endif /* !__USE_W32API */
165
166 #endif /* __INCLUDE_EXCEPT_H */