19452ca15e8793445ee6b3644abedf195af1a5b7
[reactos.git] / reactos / w32api / 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 #include <windef.h>
23
24 /*
25 * NOTE: The constants structs and typedefs below should be defined in the
26 * Win32 API headers.
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 typedef EXCEPTION_DISPOSITION (*PEXCEPTION_HANDLER)
58 (struct _EXCEPTION_RECORD*, void*, struct _CONTEXT*, void*);
59
60
61 /*
62 * A macro which installs the supplied exception handler.
63 * Push the pointer to the new handler onto the stack,
64 * then push the pointer to the old registration structure (at fs:0)
65 * onto the stack, then put a pointer to the new registration
66 * structure (i.e. the current stack pointer) at fs:0.
67 */
68 #define __try1(pHandler) \
69 __asm__ ("pushl %0;pushl %%fs:0;movl %%esp,%%fs:0;" : : "g" (pHandler));
70
71 /*
72 * A macro which (despite its name) *removes* an installed
73 * exception handler. Should be used only in conjunction with the above
74 * install routine __try1.
75 * Move the pointer to the old reg. struct (at the current stack
76 * position) to fs:0, replacing the pointer we installed above,
77 * then add 8 to the stack pointer to get rid of the space we
78 * used when we pushed on our new reg. struct above. Notice that
79 * the stack must be in the exact state at this point that it was
80 * after we did _try1 or this will smash things.
81 */
82 #define __except1 \
83 __asm__ ("movl (%%esp),%%eax;movl %%eax,%%fs:0;addl $8,%%esp;" \
84 : : : "%eax");
85
86 #ifdef __cplusplus
87 }
88 #endif
89
90 #endif /* Not RC_INVOKED */
91
92 #endif /* _EXCPT_H_ not defined */