4047ef2eb346f46ddc6f7724cadfba7f54e060a7
[reactos.git] / reactos / include / excpt.h
1 /*
2 * excpt.h
3 *
4 * Support for operating system level structured exception handling.
5 *
6 * NOTE: This is very preliminary stuff. I am also pretty sure it is
7 * completely Intel specific.
8 *
9 * This file is part of the Mingw32 package.
10 *
11 * Contributors:
12 * Created by Colin Peters <colin@bird.fu.is.saga-u.ac.jp>
13 * Based on code by Mikey <jeffdb@netzone.com>
14 *
15 * THIS SOFTWARE IS NOT COPYRIGHTED
16 *
17 * This source code is offered for use in the public domain. You may
18 * use, modify or distribute it freely.
19 *
20 * This code is distributed in the hope that it will be useful but
21 * WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
22 * DISCLAMED. This includes but is not limited to warranties of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
24 *
25 * $Revision: 1.3 $
26 * $Author: chorns $
27 * $Date: 2002/09/08 10:22:26 $
28 *
29 */
30
31 #ifndef _EXCPT_H_
32 #define _EXCPT_H_
33
34 #ifndef __STRICT_ANSI__
35
36 #include <windows.h>
37
38 /*
39 * NOTE: The constants structs and typedefs below should be defined in the
40 * Win32 API headers.
41 */
42 #define EH_NONCONTINUABLE 0x01
43 #define EH_UNWINDING 0x02
44 #define EH_EXIT_UNWIND 0x04
45 #define EH_STACK_INVALID 0x08
46 #define EH_NESTED_CALL 0x10
47
48 #ifndef RC_INVOKED
49
50 typedef enum {
51 ExceptionContinueExecution,
52 ExceptionContinueSearch,
53 ExceptionNestedException,
54 ExceptionCollidedUnwind
55 } EXCEPTION_DISPOSITION;
56
57
58 /*
59 * End of stuff that should be in the Win32 API files.
60 */
61
62
63 #ifdef __cplusplus
64 extern "C" {
65 #endif
66
67 /*
68 * The type of function that is expected as an exception handler to be
69 * installed with _try1.
70 */
71 typedef EXCEPTION_DISPOSITION (*PEXCEPTION_HANDLER)
72 (struct _EXCEPTION_RECORD*, void*, struct _CONTEXT*, void*);
73
74 /*
75 * This is not entirely necessary, but it is the structure installed by
76 * the _try1 primitive below.
77 */
78 typedef struct _EXCEPTION_REGISTRATION
79 {
80 struct _EXCEPTION_REGISTRATION* prev;
81 PEXCEPTION_HANDLER handler;
82 } EXCEPTION_REGISTRATION, *PEXCEPTION_REGISTRATION;
83
84 typedef EXCEPTION_REGISTRATION EXCEPTION_REGISTRATION_RECORD;
85 typedef PEXCEPTION_REGISTRATION PEXCEPTION_REGISTRATION_RECORD;
86
87 /*
88 * A macro which installs the supplied exception handler.
89 * Push the pointer to the new handler onto the stack,
90 * then push the pointer to the old registration structure (at fs:0)
91 * onto the stack, then put a pointer to the new registration
92 * structure (i.e. the current stack pointer) at fs:0.
93 */
94 #define __try1(pHandler) \
95 __asm__ ("pushl %0;pushl %%fs:0;movl %%esp,%%fs:0;" : : "g" (pHandler));
96
97
98 /*
99 * A macro which (dispite its name) *removes* an installed
100 * exception handler. Should be used only in conjunction with the above
101 * install routine __try1.
102 * Move the pointer to the old reg. struct (at the current stack
103 * position) to fs:0, replacing the pointer we installed above,
104 * then add 8 to the stack pointer to get rid of the space we
105 * used when we pushed on our new reg. struct above. Notice that
106 * the stack must be in the exact state at this point that it was
107 * after we did _try1 or this will smash things.
108 */
109 #define __except1 \
110 __asm__ ("movl (%%esp),%%eax;movl %%eax,%%fs:0;addl $8,%%esp;" \
111 : : : "%eax");
112
113 #ifdef __cplusplus
114 }
115 #endif
116
117 #endif /* Not RC_INVOKED */
118
119 #endif /* Not strict ANSI */
120
121 #endif /* _EXCPT_H_ not defined */