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
36 typedef enum _EXCEPTION_DISPOSITION {
37 ExceptionContinueExecution,
38 ExceptionContinueSearch,
39 ExceptionNestedException,
40 ExceptionCollidedUnwind
41 } EXCEPTION_DISPOSITION;
44 * The type of function that is expected as an exception handler to be
45 * installed with __try1.
47 typedef EXCEPTION_DISPOSITION (*PEXCEPTION_HANDLER)
48 (struct _EXCEPTION_RECORD*, void*, struct _CONTEXT*, void*);
51 * This is not entirely necessary, but it is the structure installed by
52 * the __try1 primitive below.
54 typedef struct _EXCEPTION_REGISTRATION
56 struct _EXCEPTION_REGISTRATION* prev;
57 PEXCEPTION_HANDLER handler;
58 } EXCEPTION_REGISTRATION, *PEXCEPTION_REGISTRATION;
60 typedef EXCEPTION_REGISTRATION EXCEPTION_REGISTRATION_RECORD;
61 typedef PEXCEPTION_REGISTRATION PEXCEPTION_REGISTRATION_RECORD;
64 * A macro which installs the supplied exception handler.
65 * Push the pointer to the new handler onto the stack,
66 * then push the pointer to the old registration structure (at fs:0)
67 * onto the stack, then put a pointer to the new registration
68 * structure (i.e. the current stack pointer) at fs:0.
71 # define __try1(pHandler) \
72 __asm__ __volatile__ ("pushq %0;pushq %%gs:0;movq %%rsp,%%gs:0;" : : \
75 # define __try1(pHandler) \
76 __asm__ __volatile__ ("pushl %0;pushl %%fs:0;movl %%esp,%%fs:0;" : : \
81 * A macro which (despite its name) *removes* an installed
82 * exception handler. Should be used only in conjunction with the above
83 * install routine __try1.
84 * Move the pointer to the old reg. struct (at the current stack
85 * position) to fs:0, replacing the pointer we installed above,
86 * then add 8 to the stack pointer to get rid of the space we
87 * used when we pushed on our new reg. struct above. Notice that
88 * the stack must be in the exact state at this point that it was
89 * after we did __try1 or this will smash things.
93 __asm__ __volatile__ ("movq (%%rsp),%%rax;movq %%rax,%%gs:0;addq \
94 $16,%%rsp;" : : : "%rax");
97 __asm__ __volatile__ ("movl (%%esp),%%eax;movl %%eax,%%fs:0;addl \
98 $8,%%esp;" : : : "%eax");
106 #endif /* _EXCPT_H_ not defined */