Start anew
[git/jnareb-git.git] / mingw / lib / gcc / mingw32 / 3.4.2 / include / unwind.h
blob21f3feb86bc9f65110167c7659645e81fd466d15
1 /* Exception handling and frame unwind runtime interface routines.
2 Copyright (C) 2001, 2003, 2004 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GCC is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
14 License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING. If not, write to the Free
18 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
19 02111-1307, USA. */
21 /* As a special exception, if you include this header file into source
22 files compiled by GCC, this header file does not by itself cause
23 the resulting executable to be covered by the GNU General Public
24 License. This exception does not however invalidate any other
25 reasons why the executable file might be covered by the GNU General
26 Public License. */
28 /* This is derived from the C++ ABI for IA-64. Where we diverge
29 for cross-architecture compatibility are noted with "@@@". */
31 #ifndef _UNWIND_H
32 #define _UNWIND_H
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
38 /* Level 1: Base ABI */
40 /* @@@ The IA-64 ABI uses uint64 throughout. Most places this is
41 inefficient for 32-bit and smaller machines. */
42 typedef unsigned _Unwind_Word __attribute__((__mode__(__word__)));
43 typedef signed _Unwind_Sword __attribute__((__mode__(__word__)));
44 #if defined(__ia64__) && defined(__hpux__)
45 typedef unsigned _Unwind_Ptr __attribute__((__mode__(__word__)));
46 #else
47 typedef unsigned _Unwind_Ptr __attribute__((__mode__(__pointer__)));
48 #endif
49 typedef unsigned _Unwind_Internal_Ptr __attribute__((__mode__(__pointer__)));
51 /* @@@ The IA-64 ABI uses a 64-bit word to identify the producer and
52 consumer of an exception. We'll go along with this for now even on
53 32-bit machines. We'll need to provide some other option for
54 16-bit machines and for machines with > 8 bits per byte. */
55 typedef unsigned _Unwind_Exception_Class __attribute__((__mode__(__DI__)));
57 /* The unwind interface uses reason codes in several contexts to
58 identify the reasons for failures or other actions. */
59 typedef enum
61 _URC_NO_REASON = 0,
62 _URC_FOREIGN_EXCEPTION_CAUGHT = 1,
63 _URC_FATAL_PHASE2_ERROR = 2,
64 _URC_FATAL_PHASE1_ERROR = 3,
65 _URC_NORMAL_STOP = 4,
66 _URC_END_OF_STACK = 5,
67 _URC_HANDLER_FOUND = 6,
68 _URC_INSTALL_CONTEXT = 7,
69 _URC_CONTINUE_UNWIND = 8
70 } _Unwind_Reason_Code;
73 /* The unwind interface uses a pointer to an exception header object
74 as its representation of an exception being thrown. In general, the
75 full representation of an exception object is language- and
76 implementation-specific, but it will be prefixed by a header
77 understood by the unwind interface. */
79 struct _Unwind_Exception;
81 typedef void (*_Unwind_Exception_Cleanup_Fn) (_Unwind_Reason_Code,
82 struct _Unwind_Exception *);
84 struct _Unwind_Exception
86 _Unwind_Exception_Class exception_class;
87 _Unwind_Exception_Cleanup_Fn exception_cleanup;
88 _Unwind_Word private_1;
89 _Unwind_Word private_2;
91 /* @@@ The IA-64 ABI says that this structure must be double-word aligned.
92 Taking that literally does not make much sense generically. Instead we
93 provide the maximum alignment required by any type for the machine. */
94 } __attribute__((__aligned__));
97 /* The ACTIONS argument to the personality routine is a bitwise OR of one
98 or more of the following constants. */
99 typedef int _Unwind_Action;
101 #define _UA_SEARCH_PHASE 1
102 #define _UA_CLEANUP_PHASE 2
103 #define _UA_HANDLER_FRAME 4
104 #define _UA_FORCE_UNWIND 8
105 #define _UA_END_OF_STACK 16
107 /* This is an opaque type used to refer to a system-specific data
108 structure used by the system unwinder. This context is created and
109 destroyed by the system, and passed to the personality routine
110 during unwinding. */
111 struct _Unwind_Context;
113 /* Raise an exception, passing along the given exception object. */
114 extern _Unwind_Reason_Code _Unwind_RaiseException (struct _Unwind_Exception *);
116 /* Raise an exception for forced unwinding. */
118 typedef _Unwind_Reason_Code (*_Unwind_Stop_Fn)
119 (int, _Unwind_Action, _Unwind_Exception_Class,
120 struct _Unwind_Exception *, struct _Unwind_Context *, void *);
122 extern _Unwind_Reason_Code _Unwind_ForcedUnwind (struct _Unwind_Exception *,
123 _Unwind_Stop_Fn,
124 void *);
126 /* Helper to invoke the exception_cleanup routine. */
127 extern void _Unwind_DeleteException (struct _Unwind_Exception *);
129 /* Resume propagation of an existing exception. This is used after
130 e.g. executing cleanup code, and not to implement rethrowing. */
131 extern void _Unwind_Resume (struct _Unwind_Exception *);
133 /* @@@ Resume propagation of an FORCE_UNWIND exception, or to rethrow
134 a normal exception that was handled. */
135 extern _Unwind_Reason_Code _Unwind_Resume_or_Rethrow (struct _Unwind_Exception *);
137 /* @@@ Use unwind data to perform a stack backtrace. The trace callback
138 is called for every stack frame in the call chain, but no cleanup
139 actions are performed. */
140 typedef _Unwind_Reason_Code (*_Unwind_Trace_Fn)
141 (struct _Unwind_Context *, void *);
143 extern _Unwind_Reason_Code _Unwind_Backtrace (_Unwind_Trace_Fn, void *);
145 /* These functions are used for communicating information about the unwind
146 context (i.e. the unwind descriptors and the user register state) between
147 the unwind library and the personality routine and landing pad. Only
148 selected registers maybe manipulated. */
150 extern _Unwind_Word _Unwind_GetGR (struct _Unwind_Context *, int);
151 extern void _Unwind_SetGR (struct _Unwind_Context *, int, _Unwind_Word);
153 extern _Unwind_Ptr _Unwind_GetIP (struct _Unwind_Context *);
154 extern void _Unwind_SetIP (struct _Unwind_Context *, _Unwind_Ptr);
156 /* @@@ Retrieve the CFA of the given context. */
157 extern _Unwind_Word _Unwind_GetCFA (struct _Unwind_Context *);
159 extern void *_Unwind_GetLanguageSpecificData (struct _Unwind_Context *);
161 extern _Unwind_Ptr _Unwind_GetRegionStart (struct _Unwind_Context *);
164 /* The personality routine is the function in the C++ (or other language)
165 runtime library which serves as an interface between the system unwind
166 library and language-specific exception handling semantics. It is
167 specific to the code fragment described by an unwind info block, and
168 it is always referenced via the pointer in the unwind info block, and
169 hence it has no ABI-specified name.
171 Note that this implies that two different C++ implementations can
172 use different names, and have different contents in the language
173 specific data area. Moreover, that the language specific data
174 area contains no version info because name of the function invoked
175 provides more effective versioning by detecting at link time the
176 lack of code to handle the different data format. */
178 typedef _Unwind_Reason_Code (*_Unwind_Personality_Fn)
179 (int, _Unwind_Action, _Unwind_Exception_Class,
180 struct _Unwind_Exception *, struct _Unwind_Context *);
182 /* @@@ The following alternate entry points are for setjmp/longjmp
183 based unwinding. */
185 struct SjLj_Function_Context;
186 extern void _Unwind_SjLj_Register (struct SjLj_Function_Context *);
187 extern void _Unwind_SjLj_Unregister (struct SjLj_Function_Context *);
189 extern _Unwind_Reason_Code _Unwind_SjLj_RaiseException
190 (struct _Unwind_Exception *);
191 extern _Unwind_Reason_Code _Unwind_SjLj_ForcedUnwind
192 (struct _Unwind_Exception *, _Unwind_Stop_Fn, void *);
193 extern void _Unwind_SjLj_Resume (struct _Unwind_Exception *);
194 extern _Unwind_Reason_Code _Unwind_SjLj_Resume_or_Rethrow (struct _Unwind_Exception *);
196 /* @@@ The following provide access to the base addresses for text
197 and data-relative addressing in the LDSA. In order to stay link
198 compatible with the standard ABI for IA-64, we inline these. */
200 #ifdef __ia64__
201 #include <stdlib.h>
203 static inline _Unwind_Ptr
204 _Unwind_GetDataRelBase (struct _Unwind_Context *_C)
206 /* The GP is stored in R1. */
207 return _Unwind_GetGR (_C, 1);
210 static inline _Unwind_Ptr
211 _Unwind_GetTextRelBase (struct _Unwind_Context *_C __attribute__ ((__unused__)))
213 abort ();
214 return 0;
217 /* @@@ Retrieve the Backing Store Pointer of the given context. */
218 extern _Unwind_Word _Unwind_GetBSP (struct _Unwind_Context *);
219 #else
220 extern _Unwind_Ptr _Unwind_GetDataRelBase (struct _Unwind_Context *);
221 extern _Unwind_Ptr _Unwind_GetTextRelBase (struct _Unwind_Context *);
222 #endif
224 /* @@@ Given an address, return the entry point of the function that
225 contains it. */
226 extern void * _Unwind_FindEnclosingFunction (void *pc);
228 #ifdef __cplusplus
230 #endif
232 #endif /* unwind.h */