3 * @copy 2012 MinGW.org project
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:
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
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.
26 #pragma GCC system_header
29 * Support for operating system level structured exception handling.
31 * NOTE: This is very preliminary stuff. I am also pretty sure it is
32 * completely Intel specific.
35 /* All the headers include this file. */
41 * NOTE: The constants structs and typedefs below should be defined in the
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
53 ExceptionContinueExecution,
54 ExceptionContinueSearch,
55 ExceptionNestedException,
56 ExceptionCollidedUnwind
57 } EXCEPTION_DISPOSITION;
61 * End of stuff that should be in the Win32 API files.
70 * The type of function that is expected as an exception handler to be
71 * installed with __try1.
73 typedef EXCEPTION_DISPOSITION (*PEXCEPTION_HANDLER)
74 (struct _EXCEPTION_RECORD*, void*, struct _CONTEXT*, void*);
77 * This is not entirely necessary, but it is the structure installed by
78 * the __try1 primitive below.
80 typedef struct _EXCEPTION_REGISTRATION
82 struct _EXCEPTION_REGISTRATION* prev;
83 PEXCEPTION_HANDLER handler;
84 } EXCEPTION_REGISTRATION, *PEXCEPTION_REGISTRATION;
86 typedef EXCEPTION_REGISTRATION EXCEPTION_REGISTRATION_RECORD;
87 typedef PEXCEPTION_REGISTRATION PEXCEPTION_REGISTRATION_RECORD;
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.
97 # define __try1(pHandler) \
98 __asm__ __volatile__ ("pushq %0;pushq %%gs:0;movq %%rsp,%%gs:0;" : : \
101 # define __try1(pHandler) \
102 __asm__ __volatile__ ("pushl %0;pushl %%fs:0;movl %%esp,%%fs:0;" : : \
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.
119 __asm__ __volatile__ ("movq (%%rsp),%%rax;movq %%rax,%%gs:0;addq \
120 $16,%%rsp;" : : : "%rax");
123 __asm__ __volatile__ ("movl (%%esp),%%eax;movl %%eax,%%fs:0;addl \
124 $8,%%esp;" : : : "%eax");
131 #endif /* Not RC_INVOKED */
133 #endif /* _EXCPT_H_ not defined */