Merge to trunk HEAD(r36856)
[reactos.git] / reactos / include / crt / excpt.h
1 /*
2 * excpt.h
3 * This file has no copyright assigned and is placed in the Public Domain.
4 * This file is a part of the mingw-runtime package.
5 * No warranty is given; refer to the file DISCLAIMER within the package.
6 *
7 * Support for operating system level structured exception handling.
8 *
9 * NOTE: This is very preliminary stuff. I am also pretty sure it is
10 * completely Intel specific.
11 *
12 */
13
14 #ifndef _EXCPT_H_
15 #define _EXCPT_H_
16
17 /* All the headers include this file. */
18 #include <_mingw.h>
19
20 /*
21 * NOTE: The constants structs and typedefs below should be defined in the
22 * Win32 API headers.
23 */
24 #define EXCEPTION_EXECUTE_HANDLER 1
25 #define EXCEPTION_CONTINUE_SEARCH 0
26 #define EXCEPTION_CONTINUE_EXECUTION -1
27
28 #define EH_NONCONTINUABLE 0x01
29 #define EH_UNWINDING 0x02
30 #define EH_EXIT_UNWIND 0x04
31 #define EH_STACK_INVALID 0x08
32 #define EH_NESTED_CALL 0x10
33
34 #ifndef RC_INVOKED
35
36 typedef enum {
37 ExceptionContinueExecution,
38 ExceptionContinueSearch,
39 ExceptionNestedException,
40 ExceptionCollidedUnwind
41 } EXCEPTION_DISPOSITION;
42
43
44 /*
45 * End of stuff that should be in the Win32 API files.
46 */
47
48
49 #ifdef __cplusplus
50 extern "C" {
51 #endif
52
53 /*
54 * The type of function that is expected as an exception handler to be
55 * installed with __try1.
56 */
57 struct _CONTEXT;
58 struct _EXCEPTION_RECORD;
59 typedef EXCEPTION_DISPOSITION (*PEXCEPTION_HANDLER)
60 (struct _EXCEPTION_RECORD*, void*, struct _CONTEXT*, void*);
61
62 /*
63 * This is not entirely necessary, but it is the structure installed by
64 * the __try1 primitive below.
65 */
66 typedef struct _EXCEPTION_REGISTRATION
67 {
68 struct _EXCEPTION_REGISTRATION* prev;
69 PEXCEPTION_HANDLER handler;
70 } EXCEPTION_REGISTRATION, *PEXCEPTION_REGISTRATION;
71
72 /*
73 * A macro which installs the supplied exception handler.
74 * Push the pointer to the new handler onto the stack,
75 * then push the pointer to the old registration structure (at fs:0)
76 * onto the stack, then put a pointer to the new registration
77 * structure (i.e. the current stack pointer) at fs:0.
78 */
79 #define __try1(pHandler) \
80 __asm__ ("pushl %0;pushl %%fs:0;movl %%esp,%%fs:0;" : : "g" (pHandler));
81
82 /*
83 * A macro which (despite its name) *removes* an installed
84 * exception handler. Should be used only in conjunction with the above
85 * install routine __try1.
86 * Move the pointer to the old reg. struct (at the current stack
87 * position) to fs:0, replacing the pointer we installed above,
88 * then add 8 to the stack pointer to get rid of the space we
89 * used when we pushed on our new reg. struct above. Notice that
90 * the stack must be in the exact state at this point that it was
91 * after we did __try1 or this will smash things.
92 */
93 #define __except1 \
94 __asm__ ("movl (%%esp),%%eax;movl %%eax,%%fs:0;addl $8,%%esp;" \
95 : : : "%eax");
96
97 #ifdef __cplusplus
98 }
99 #endif
100
101 #endif /* Not RC_INVOKED */
102
103 #endif /* _EXCPT_H_ not defined */