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