6be9b852edc0c152653c71d2390a6515f3c0a39a
[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 #if defined(__MINGW32__)
19 #include <_mingw.h>
20 #endif
21
22 /*
23 * NOTE: The constants structs and typedefs below should be defined in the
24 * Win32 API headers.
25 */
26 #define EXCEPTION_EXECUTE_HANDLER 1
27 #define EXCEPTION_CONTINUE_SEARCH 0
28 #define EXCEPTION_CONTINUE_EXECUTION -1
29
30 #define EH_NONCONTINUABLE 0x01
31 #define EH_UNWINDING 0x02
32 #define EH_EXIT_UNWIND 0x04
33 #define EH_STACK_INVALID 0x08
34 #define EH_NESTED_CALL 0x10
35
36 #ifndef RC_INVOKED
37
38 typedef enum {
39 ExceptionContinueExecution,
40 ExceptionContinueSearch,
41 ExceptionNestedException,
42 ExceptionCollidedUnwind
43 } EXCEPTION_DISPOSITION;
44
45
46 /*
47 * End of stuff that should be in the Win32 API files.
48 */
49
50
51 #ifdef __cplusplus
52 extern "C" {
53 #endif
54
55 /*
56 * The type of function that is expected as an exception handler to be
57 * installed with __try1.
58 */
59 struct _CONTEXT;
60 struct _EXCEPTION_RECORD;
61 typedef EXCEPTION_DISPOSITION (*PEXCEPTION_HANDLER)
62 (struct _EXCEPTION_RECORD*, void*, struct _CONTEXT*, void*);
63
64 /*
65 * This is not entirely necessary, but it is the structure installed by
66 * the __try1 primitive below.
67 */
68 typedef struct _EXCEPTION_REGISTRATION
69 {
70 struct _EXCEPTION_REGISTRATION* prev;
71 PEXCEPTION_HANDLER handler;
72 } EXCEPTION_REGISTRATION, *PEXCEPTION_REGISTRATION;
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 * A macro which (despite its name) *removes* an installed
86 * exception handler. Should be used only in conjunction with the above
87 * install routine __try1.
88 * Move the pointer to the old reg. struct (at the current stack
89 * position) to fs:0, replacing the pointer we installed above,
90 * then add 8 to the stack pointer to get rid of the space we
91 * used when we pushed on our new reg. struct above. Notice that
92 * the stack must be in the exact state at this point that it was
93 * after we did __try1 or this will smash things.
94 */
95 #define __except1 \
96 __asm__ ("movl (%%esp),%%eax;movl %%eax,%%fs:0;addl $8,%%esp;" \
97 : : : "%eax");
98
99 #ifdef __cplusplus
100 }
101 #endif
102
103 #endif /* Not RC_INVOKED */
104
105 #endif /* _EXCPT_H_ not defined */