753d50a453842dbc100118d5c7ae50c19b47f06c
[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 #ifndef EXCEPTION_NONCONTINUABLE
61 #define EXCEPTION_NONCONTINUABLE 0x01
62 #endif
63 #endif /* __NTOSKRNL__ */
64 #endif /* _GNU_H_WINDOWS32_DEFINES */
65 #define EXCEPTION_UNWINDING 0x02
66 #define EXCEPTION_EXIT_UNWIND 0x04
67 #define EXCEPTION_STACK_INVALID 0x08
68 #define EXCEPTION_NESTED_CALL 0x10
69
70
71 typedef struct _EXCEPTION_REGISTRATION
72 {
73 struct _EXCEPTION_REGISTRATION* prev;
74 PEXCEPTION_HANDLER handler;
75 } EXCEPTION_REGISTRATION, *PEXCEPTION_REGISTRATION;
76
77 typedef EXCEPTION_REGISTRATION EXCEPTION_REGISTRATION_RECORD;
78 typedef PEXCEPTION_REGISTRATION PEXCEPTION_REGISTRATION_RECORD;
79
80
81 /*
82 * A macro which installs the supplied exception handler.
83 * Push the pointer to the new handler onto the stack,
84 * then push the pointer to the old registration structure (at fs:0)
85 * onto the stack, then put a pointer to the new registration
86 * structure (i.e. the current stack pointer) at fs:0.
87 */
88 #define __try1(pHandler) \
89 __asm__ ("pushl %0;pushl %%fs:0;movl %%esp,%%fs:0;" : : "g" (pHandler));
90
91
92 /*
93 * A macro which (dispite its name) *removes* an installed
94 * exception handler. Should be used only in conjunction with the above
95 * install routine __try1.
96 * Move the pointer to the old reg. struct (at the current stack
97 * position) to fs:0, replacing the pointer we installed above,
98 * then add 8 to the stack pointer to get rid of the space we
99 * used when we pushed on our new reg. struct above. Notice that
100 * the stack must be in the exact state at this point that it was
101 * after we did _try1 or this will smash things.
102 */
103 #define __except1 \
104 __asm__ ("movl (%%esp),%%eax;movl %%eax,%%fs:0;addl $8,%%esp;" \
105 : : : "%eax");
106
107
108 #if 1
109
110 /* Runtime DLL structures */
111
112 #ifndef _GNU_H_WINDOWS32_DEFINES
113 #ifdef __NTOSKRNL__
114 #define EXCEPTION_EXECUTE_HANDLER 1
115 #define EXCEPTION_CONTINUE_SEARCH 0
116 /* #define EXCEPTION_CONTINUE_EXECUTION -1 */
117 #endif /* __NTOSKRNL__ */
118 #endif /* _GNU_H_WINDOWS32_DEFINES */
119
120 /* Functions of the following prototype return one of the above constants */
121 #ifdef __GNUC__
122 typedef DWORD CDECL (*PSCOPE_EXCEPTION_FILTER)(VOID);
123 typedef VOID CDECL (*PSCOPE_EXCEPTION_HANDLER)(VOID);
124 #else
125 typedef DWORD (CDECL *PSCOPE_EXCEPTION_FILTER)(VOID);
126 typedef VOID (CDECL *PSCOPE_EXCEPTION_HANDLER)(VOID);
127 #endif /*__GNUC__*/
128
129 typedef struct _SCOPETABLE_ENTRY
130 {
131 DWORD PreviousTryLevel;
132 PSCOPE_EXCEPTION_FILTER FilterRoutine;
133 PSCOPE_EXCEPTION_HANDLER HandlerRoutine;
134 } SCOPETABLE_ENTRY, *PSCOPETABLE_ENTRY;
135
136 /*
137 Other structures preceeding this structure:
138 ULONG_PTR StandardESPInFrame;
139 LPEXCEPTION_POINTERS ExceptionPointers;
140 */
141 typedef struct _RTL_EXCEPTION_REGISTRATION_I386
142 {
143 EXCEPTION_REGISTRATION OS;
144 PSCOPETABLE_ENTRY ScopeTable;
145 DWORD TryLevel;
146 /* Value of EBP before the EXCEPTION_REGISTRATION was created */
147 ULONG_PTR Ebp;
148 } RTL_EXCEPTION_REGISTRATION_I386, *PRTL_EXCEPTION_REGISTRATION_I386;
149
150 #define TRYLEVEL_NONE -1
151
152 typedef RTL_EXCEPTION_REGISTRATION_I386 RTL_EXCEPTION_REGISTRATION;
153 typedef PRTL_EXCEPTION_REGISTRATION_I386 PRTL_EXCEPTION_REGISTRATION;
154
155 #endif
156
157 #ifndef __USE_W32API
158
159 #define EXCEPTION_MAXIMUM_PARAMETERS (15)
160
161 typedef struct _EXCEPTION_POINTERS {
162 PEXCEPTION_RECORD ExceptionRecord;
163 PCONTEXT ContextRecord;
164 } EXCEPTION_POINTERS, *PEXCEPTION_POINTERS, *LPEXCEPTION_POINTERS;
165
166 #endif /* !__USE_W32API */
167
168 #endif /* __INCLUDE_EXCEPT_H */