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