OSDN Git Service

Redo the filters based on assumptions discussed in mingw-dvlpr list.
[mingw/mingw-org-wsl.git] / include / excpt.h
1 /**
2  * @file excpt.h
3  * @copy 2012 MinGW.org project
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  * 
12  * The above copyright notice and this permission notice (including the next
13  * paragraph) shall be included in all copies or substantial portions of the
14  * Software.
15  * 
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  * DEALINGS IN THE SOFTWARE.
23  */
24 #ifndef _EXCPT_H_
25 #define _EXCPT_H_
26 #pragma GCC system_header
27
28 /*
29  * Support for operating system level structured exception handling.
30  *
31  * NOTE: This is very preliminary stuff. I am also pretty sure it is
32  *       completely Intel specific.
33  */
34
35 /* All the headers include this file. */
36 #include <_mingw.h>
37
38 #include <windef.h>
39
40 /*
41  * NOTE: The constants structs and typedefs below should be defined in the
42  *       Win32 API headers.
43  */
44 #define EH_NONCONTINUABLE       0x01
45 #define EH_UNWINDING            0x02
46 #define EH_EXIT_UNWIND          0x04
47 #define EH_STACK_INVALID        0x08
48 #define EH_NESTED_CALL          0x10
49
50 #ifndef RC_INVOKED
51
52 typedef enum {
53         ExceptionContinueExecution,
54         ExceptionContinueSearch,
55         ExceptionNestedException,
56         ExceptionCollidedUnwind
57 } EXCEPTION_DISPOSITION;
58
59
60 /*
61  * End of stuff that should be in the Win32 API files.
62  */
63
64
65 #ifdef  __cplusplus
66 extern "C" {
67 #endif
68
69 /*
70  * The type of function that is expected as an exception handler to be
71  * installed with __try1.
72  */
73 typedef EXCEPTION_DISPOSITION (*PEXCEPTION_HANDLER)
74                 (struct _EXCEPTION_RECORD*, void*, struct _CONTEXT*, void*);
75
76 /*
77  * This is not entirely necessary, but it is the structure installed by
78  * the __try1 primitive below.
79  */
80 typedef struct _EXCEPTION_REGISTRATION
81 {
82         struct _EXCEPTION_REGISTRATION* prev;
83         PEXCEPTION_HANDLER              handler;
84 } EXCEPTION_REGISTRATION, *PEXCEPTION_REGISTRATION;
85
86 typedef EXCEPTION_REGISTRATION EXCEPTION_REGISTRATION_RECORD;
87 typedef PEXCEPTION_REGISTRATION PEXCEPTION_REGISTRATION_RECORD;
88
89 /*
90  * A macro which installs the supplied exception handler.
91  * Push the pointer to the new handler onto the stack,
92  * then push the pointer to the old registration structure (at fs:0)
93  * onto the stack, then put a pointer to the new registration
94  * structure (i.e. the current stack pointer) at fs:0.
95  */
96 #ifdef _WIN64
97 # define __try1(pHandler) \
98         __asm__ __volatile__ ("pushq %0;pushq %%gs:0;movq %%rsp,%%gs:0;" : : \
99         "g" (pHandler));
100 #else
101 # define __try1(pHandler) \
102         __asm__ __volatile__ ("pushl %0;pushl %%fs:0;movl %%esp,%%fs:0;" : : \
103         "g" (pHandler));
104 #endif
105
106 /*
107  * A macro which (despite its name) *removes* an installed
108  * exception handler. Should be used only in conjunction with the above
109  * install routine __try1.
110  * Move the pointer to the old reg. struct (at the current stack
111  * position) to fs:0, replacing the pointer we installed above,
112  * then add 8 to the stack pointer to get rid of the space we
113  * used when we pushed on our new reg. struct above. Notice that
114  * the stack must be in the exact state at this point that it was
115  * after we did __try1 or this will smash things.
116  */
117 #ifdef _WIN64
118 # define        __except1       \
119         __asm__ __volatile__ ("movq (%%rsp),%%rax;movq %%rax,%%gs:0;addq \
120         $16,%%rsp;" : : : "%rax");
121 #else
122 # define __except1      \
123         __asm__ __volatile__ ("movl (%%esp),%%eax;movl %%eax,%%fs:0;addl \
124         $8,%%esp;" : : : "%eax");
125 #endif
126
127 #ifdef  __cplusplus
128 }
129 #endif
130
131 #endif  /* Not RC_INVOKED */
132
133 #endif  /* _EXCPT_H_ not defined */