:pserver:cvsanon@mok.lvcm.com:/CVS/ReactOS reactos
[reactos.git] / 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 typedef EXCEPTION_DISPOSITION CDECL (*PEXCEPTION_HANDLER)(
29   struct _EXCEPTION_RECORD* ExceptionRecord,
30   struct _EXCEPTION_REGISTRATION* ExceptionRegistration,
31   PCONTEXT Context,
32   PVOID DispatcherContext);
33
34
35 #define EXCEPTION_MAXIMUM_PARAMETERS    (15)
36
37 typedef struct _EXCEPTION_RECORD {
38   DWORD ExceptionCode;
39   DWORD ExceptionFlags;
40   struct _EXCEPTION_RECORD *ExceptionRecord;
41   PVOID ExceptionAddress;
42   DWORD NumberParameters;
43   DWORD ExceptionInformation[EXCEPTION_MAXIMUM_PARAMETERS];
44 } EXCEPTION_RECORD, *PEXCEPTION_RECORD, *LPEXCEPTION_RECORD;
45
46 /* ExceptionFlags */
47 #ifndef _GNU_H_WINDOWS32_DEFINES
48 #ifdef __NTOSKRNL__
49 #define EXCEPTION_NONCONTINUABLE        0x01
50 #endif /* __NTOSKRNL__ */
51 #endif /* _GNU_H_WINDOWS32_DEFINES */
52 #define EXCEPTION_UNWINDING       0x02
53 #define EXCEPTION_EXIT_UNWIND             0x04
54 #define EXCEPTION_STACK_INVALID   0x08
55 #define EXCEPTION_NESTED_CALL             0x10
56
57
58 typedef struct _EXCEPTION_POINTERS { 
59   PEXCEPTION_RECORD ExceptionRecord; 
60   PCONTEXT ContextRecord; 
61 } EXCEPTION_POINTERS, *PEXCEPTION_POINTERS, *LPEXCEPTION_POINTERS; 
62
63
64 typedef struct _EXCEPTION_REGISTRATION
65 {
66         struct _EXCEPTION_REGISTRATION* prev;
67         PEXCEPTION_HANDLER              handler;
68 } EXCEPTION_REGISTRATION, *PEXCEPTION_REGISTRATION;
69
70 typedef EXCEPTION_REGISTRATION EXCEPTION_REGISTRATION_RECORD;
71 typedef PEXCEPTION_REGISTRATION PEXCEPTION_REGISTRATION_RECORD;
72
73
74 /*
75  * A macro which installs the supplied exception handler.
76  * Push the pointer to the new handler onto the stack,
77  * then push the pointer to the old registration structure (at fs:0)
78  * onto the stack, then put a pointer to the new registration
79  * structure (i.e. the current stack pointer) at fs:0.
80  */
81 #define __try1(pHandler) \
82         __asm__ ("pushl %0;pushl %%fs:0;movl %%esp,%%fs:0;" : : "g" (pHandler));
83
84
85 /*
86  * A macro which (dispite its name) *removes* an installed
87  * exception handler. Should be used only in conjunction with the above
88  * install routine __try1.
89  * Move the pointer to the old reg. struct (at the current stack
90  * position) to fs:0, replacing the pointer we installed above,
91  * then add 8 to the stack pointer to get rid of the space we
92  * used when we pushed on our new reg. struct above. Notice that
93  * the stack must be in the exact state at this point that it was
94  * after we did _try1 or this will smash things.
95  */
96 #define __except1       \
97         __asm__ ("movl (%%esp),%%eax;movl %%eax,%%fs:0;addl $8,%%esp;" \
98          : : : "%eax");
99
100
101 #if 1
102
103 // Runtime DLL structures
104
105 #ifndef _GNU_H_WINDOWS32_DEFINES
106 #ifdef __NTOSKRNL__
107 #define EXCEPTION_EXECUTE_HANDLER     1
108 #define EXCEPTION_CONTINUE_SEARCH     0
109 #define EXCEPTION_CONTINUE_EXECUTION -1
110 #endif /* __NTOSKRNL__ */
111 #endif /* _GNU_H_WINDOWS32_DEFINES */
112
113 // Functions of the following prototype return one of the above constants
114 typedef DWORD CDECL (*PSCOPE_EXCEPTION_FILTER)(VOID);
115 typedef VOID CDECL (*PSCOPE_EXCEPTION_HANDLER)(VOID);
116
117 typedef struct _SCOPETABLE_ENTRY
118 {
119   DWORD                    PreviousTryLevel;
120   PSCOPE_EXCEPTION_FILTER  FilterRoutine;
121   PSCOPE_EXCEPTION_HANDLER HandlerRoutine;
122 } SCOPETABLE_ENTRY, *PSCOPETABLE_ENTRY;
123
124 /*
125    Other structures preceeding this structure:
126      ULONG_PTR              StandardESPInFrame;
127      LPEXCEPTION_POINTERS   ExceptionPointers;
128  */
129 typedef struct _RTL_EXCEPTION_REGISTRATION_I386
130 {
131   EXCEPTION_REGISTRATION OS;
132   PSCOPETABLE_ENTRY ScopeTable;
133   DWORD             TryLevel;
134   /* Value of EBP before the EXCEPTION_REGISTRATION was created */
135   ULONG_PTR         Ebp;
136 } RTL_EXCEPTION_REGISTRATION_I386, *PRTL_EXCEPTION_REGISTRATION_I386;
137
138 #define TRYLEVEL_NONE -1
139
140 typedef RTL_EXCEPTION_REGISTRATION_I386 RTL_EXCEPTION_REGISTRATION;
141 typedef PRTL_EXCEPTION_REGISTRATION_I386 PRTL_EXCEPTION_REGISTRATION;
142
143 #endif
144
145 #endif /* __INCLUDE_EXCEPT_H */