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