OSDN Git Service

PR target/34091
[pf3gnuchains/gcc-fork.git] / gcc / unwind-generic.h
1 /* Exception handling and frame unwind runtime interface routines.
2    Copyright (C) 2001, 2003, 2004, 2006 Free Software Foundation, Inc.
3
4    This file is part of GCC.
5
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.
10
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.
15
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, 51 Franklin Street, Fifth Floor, Boston, MA
19    02110-1301, USA.  */
20
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.  */
27
28 /* This is derived from the C++ ABI for IA-64.  Where we diverge
29    for cross-architecture compatibility are noted with "@@@".  */
30
31 #ifndef _UNWIND_H
32 #define _UNWIND_H
33
34 #ifndef HIDE_EXPORTS
35 #pragma GCC visibility push(default)
36 #endif
37
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41
42 /* Level 1: Base ABI  */
43
44 /* @@@ The IA-64 ABI uses uint64 throughout.  Most places this is
45    inefficient for 32-bit and smaller machines.  */
46 typedef unsigned _Unwind_Word __attribute__((__mode__(__word__)));
47 typedef signed _Unwind_Sword __attribute__((__mode__(__word__)));
48 #if defined(__ia64__) && defined(__hpux__)
49 typedef unsigned _Unwind_Ptr __attribute__((__mode__(__word__)));
50 #else
51 typedef unsigned _Unwind_Ptr __attribute__((__mode__(__pointer__)));
52 #endif
53 typedef unsigned _Unwind_Internal_Ptr __attribute__((__mode__(__pointer__)));
54
55 /* @@@ The IA-64 ABI uses a 64-bit word to identify the producer and
56    consumer of an exception.  We'll go along with this for now even on
57    32-bit machines.  We'll need to provide some other option for
58    16-bit machines and for machines with > 8 bits per byte.  */
59 typedef unsigned _Unwind_Exception_Class __attribute__((__mode__(__DI__)));
60
61 /* The unwind interface uses reason codes in several contexts to
62    identify the reasons for failures or other actions.  */
63 typedef enum
64 {
65   _URC_NO_REASON = 0,
66   _URC_FOREIGN_EXCEPTION_CAUGHT = 1,
67   _URC_FATAL_PHASE2_ERROR = 2,
68   _URC_FATAL_PHASE1_ERROR = 3,
69   _URC_NORMAL_STOP = 4,
70   _URC_END_OF_STACK = 5,
71   _URC_HANDLER_FOUND = 6,
72   _URC_INSTALL_CONTEXT = 7,
73   _URC_CONTINUE_UNWIND = 8
74 } _Unwind_Reason_Code;
75
76
77 /* The unwind interface uses a pointer to an exception header object
78    as its representation of an exception being thrown. In general, the
79    full representation of an exception object is language- and
80    implementation-specific, but it will be prefixed by a header
81    understood by the unwind interface.  */
82
83 struct _Unwind_Exception;
84
85 typedef void (*_Unwind_Exception_Cleanup_Fn) (_Unwind_Reason_Code,
86                                               struct _Unwind_Exception *);
87
88 struct _Unwind_Exception
89 {
90   _Unwind_Exception_Class exception_class;
91   _Unwind_Exception_Cleanup_Fn exception_cleanup;
92   _Unwind_Word private_1;
93   _Unwind_Word private_2;
94
95   /* @@@ The IA-64 ABI says that this structure must be double-word aligned.
96      Taking that literally does not make much sense generically.  Instead we
97      provide the maximum alignment required by any type for the machine.  */
98 } __attribute__((__aligned__));
99
100
101 /* The ACTIONS argument to the personality routine is a bitwise OR of one
102    or more of the following constants.  */
103 typedef int _Unwind_Action;
104
105 #define _UA_SEARCH_PHASE        1
106 #define _UA_CLEANUP_PHASE       2
107 #define _UA_HANDLER_FRAME       4
108 #define _UA_FORCE_UNWIND        8
109 #define _UA_END_OF_STACK        16
110
111 /* The target can override this macro to define any back-end-specific
112    attributes required for the lowest-level stack frame.  */
113 #ifndef LIBGCC2_UNWIND_ATTRIBUTE
114 #define LIBGCC2_UNWIND_ATTRIBUTE
115 #endif
116
117 /* This is an opaque type used to refer to a system-specific data
118    structure used by the system unwinder. This context is created and
119    destroyed by the system, and passed to the personality routine
120    during unwinding.  */
121 struct _Unwind_Context;
122
123 /* Raise an exception, passing along the given exception object.  */
124 extern _Unwind_Reason_Code LIBGCC2_UNWIND_ATTRIBUTE
125 _Unwind_RaiseException (struct _Unwind_Exception *);
126
127 /* Raise an exception for forced unwinding.  */
128
129 typedef _Unwind_Reason_Code (*_Unwind_Stop_Fn)
130      (int, _Unwind_Action, _Unwind_Exception_Class,
131       struct _Unwind_Exception *, struct _Unwind_Context *, void *);
132
133 extern _Unwind_Reason_Code LIBGCC2_UNWIND_ATTRIBUTE
134 _Unwind_ForcedUnwind (struct _Unwind_Exception *, _Unwind_Stop_Fn, void *);
135
136 /* Helper to invoke the exception_cleanup routine.  */
137 extern void _Unwind_DeleteException (struct _Unwind_Exception *);
138
139 /* Resume propagation of an existing exception.  This is used after
140    e.g. executing cleanup code, and not to implement rethrowing.  */
141 extern void LIBGCC2_UNWIND_ATTRIBUTE
142 _Unwind_Resume (struct _Unwind_Exception *);
143
144 /* @@@ Resume propagation of a FORCE_UNWIND exception, or to rethrow
145    a normal exception that was handled.  */
146 extern _Unwind_Reason_Code LIBGCC2_UNWIND_ATTRIBUTE
147 _Unwind_Resume_or_Rethrow (struct _Unwind_Exception *);
148
149 /* @@@ Use unwind data to perform a stack backtrace.  The trace callback
150    is called for every stack frame in the call chain, but no cleanup
151    actions are performed.  */
152 typedef _Unwind_Reason_Code (*_Unwind_Trace_Fn)
153      (struct _Unwind_Context *, void *);
154
155 extern _Unwind_Reason_Code LIBGCC2_UNWIND_ATTRIBUTE
156 _Unwind_Backtrace (_Unwind_Trace_Fn, void *);
157
158 /* These functions are used for communicating information about the unwind
159    context (i.e. the unwind descriptors and the user register state) between
160    the unwind library and the personality routine and landing pad.  Only
161    selected registers may be manipulated.  */
162
163 extern _Unwind_Word _Unwind_GetGR (struct _Unwind_Context *, int);
164 extern void _Unwind_SetGR (struct _Unwind_Context *, int, _Unwind_Word);
165
166 extern _Unwind_Ptr _Unwind_GetIP (struct _Unwind_Context *);
167 extern _Unwind_Ptr _Unwind_GetIPInfo (struct _Unwind_Context *, int *);
168 extern void _Unwind_SetIP (struct _Unwind_Context *, _Unwind_Ptr);
169
170 /* @@@ Retrieve the CFA of the given context.  */
171 extern _Unwind_Word _Unwind_GetCFA (struct _Unwind_Context *);
172
173 extern void *_Unwind_GetLanguageSpecificData (struct _Unwind_Context *);
174
175 extern _Unwind_Ptr _Unwind_GetRegionStart (struct _Unwind_Context *);
176
177
178 /* The personality routine is the function in the C++ (or other language)
179    runtime library which serves as an interface between the system unwind
180    library and language-specific exception handling semantics.  It is
181    specific to the code fragment described by an unwind info block, and
182    it is always referenced via the pointer in the unwind info block, and
183    hence it has no ABI-specified name.
184
185    Note that this implies that two different C++ implementations can
186    use different names, and have different contents in the language
187    specific data area.  Moreover, that the language specific data
188    area contains no version info because name of the function invoked
189    provides more effective versioning by detecting at link time the
190    lack of code to handle the different data format.  */
191
192 typedef _Unwind_Reason_Code (*_Unwind_Personality_Fn)
193      (int, _Unwind_Action, _Unwind_Exception_Class,
194       struct _Unwind_Exception *, struct _Unwind_Context *);
195
196 /* @@@ The following alternate entry points are for setjmp/longjmp
197    based unwinding.  */
198
199 struct SjLj_Function_Context;
200 extern void _Unwind_SjLj_Register (struct SjLj_Function_Context *);
201 extern void _Unwind_SjLj_Unregister (struct SjLj_Function_Context *);
202
203 extern _Unwind_Reason_Code LIBGCC2_UNWIND_ATTRIBUTE
204 _Unwind_SjLj_RaiseException (struct _Unwind_Exception *);
205 extern _Unwind_Reason_Code LIBGCC2_UNWIND_ATTRIBUTE
206 _Unwind_SjLj_ForcedUnwind (struct _Unwind_Exception *, _Unwind_Stop_Fn, void *);
207 extern void LIBGCC2_UNWIND_ATTRIBUTE
208 _Unwind_SjLj_Resume (struct _Unwind_Exception *);
209 extern _Unwind_Reason_Code LIBGCC2_UNWIND_ATTRIBUTE
210 _Unwind_SjLj_Resume_or_Rethrow (struct _Unwind_Exception *);
211
212 /* @@@ The following provide access to the base addresses for text
213    and data-relative addressing in the LDSA.  In order to stay link
214    compatible with the standard ABI for IA-64, we inline these.  */
215
216 #ifdef __ia64__
217 #include <stdlib.h>
218
219 static inline _Unwind_Ptr
220 _Unwind_GetDataRelBase (struct _Unwind_Context *_C)
221 {
222   /* The GP is stored in R1.  */
223   return _Unwind_GetGR (_C, 1);
224 }
225
226 static inline _Unwind_Ptr
227 _Unwind_GetTextRelBase (struct _Unwind_Context *_C __attribute__ ((__unused__)))
228 {
229   abort ();
230   return 0;
231 }
232
233 /* @@@ Retrieve the Backing Store Pointer of the given context.  */
234 extern _Unwind_Word _Unwind_GetBSP (struct _Unwind_Context *);
235 #else
236 extern _Unwind_Ptr _Unwind_GetDataRelBase (struct _Unwind_Context *);
237 extern _Unwind_Ptr _Unwind_GetTextRelBase (struct _Unwind_Context *);
238 #endif
239
240 /* @@@ Given an address, return the entry point of the function that
241    contains it.  */
242 extern void * _Unwind_FindEnclosingFunction (void *pc);
243
244 #ifndef __SIZEOF_LONG__
245   #error "__SIZEOF_LONG__ macro not defined"
246 #endif
247
248 #ifndef __SIZEOF_POINTER__
249   #error "__SIZEOF_POINTER__ macro not defined"
250 #endif
251
252
253 /* leb128 type numbers have a potentially unlimited size.
254    The target of the following definitions of _sleb128_t and _uleb128_t
255    is to have efficient data types large enough to hold the leb128 type
256    numbers used in the unwind code.
257    Mostly these types will simply be defined to long and unsigned long
258    except when a unsigned long data type on the target machine is not
259    capable of storing a pointer.  */
260
261 #if __SIZEOF_LONG__ >= __SIZEOF_POINTER__
262   typedef long _sleb128_t;
263   typedef unsigned long _uleb128_t;
264 #elif __SIZEOF_LONG_LONG__ >= __SIZEOF_POINTER__
265   typedef long long _sleb128_t;
266   typedef unsigned long long _uleb128_t;
267 #else
268 # error "What type shall we use for _sleb128_t?"
269 #endif
270
271 #ifdef __cplusplus
272 }
273 #endif
274
275 #ifndef HIDE_EXPORTS
276 #pragma GCC visibility pop
277 #endif
278
279 #endif /* unwind.h */