]> git.ipfire.org Git - thirdparty/gcc.git/blame - libgcc/unwind-generic.h
Update copyright years.
[thirdparty/gcc.git] / libgcc / unwind-generic.h
CommitLineData
df4b504c 1/* Exception handling and frame unwind runtime interface routines.
f1717362 2 Copyright (C) 2001-2016 Free Software Foundation, Inc.
df4b504c 3
f12b58b3 4 This file is part of GCC.
df4b504c 5
f12b58b3 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
6bc9506f 8 the Free Software Foundation; either version 3, or (at your option)
df4b504c 9 any later version.
10
f12b58b3 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.
df4b504c 15
6bc9506f 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.
19
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/>. */
aec3ae55 24
df4b504c 25/* This is derived from the C++ ABI for IA-64. Where we diverge
26 for cross-architecture compatibility are noted with "@@@". */
27
817adc77 28#ifndef _UNWIND_H
29#define _UNWIND_H
30
a92cf445 31#if defined (__SEH__) && !defined (__USING_SJLJ_EXCEPTIONS__)
8ad0b530 32/* Only for _GCC_specific_handler. */
33#include <windows.h>
34#endif
35
cca0d0c6 36#ifndef HIDE_EXPORTS
bc9fbf5d 37#pragma GCC visibility push(default)
cca0d0c6 38#endif
bc9fbf5d 39
df4b504c 40#ifdef __cplusplus
41extern "C" {
42#endif
43
44/* Level 1: Base ABI */
45
46/* @@@ The IA-64 ABI uses uint64 throughout. Most places this is
47 inefficient for 32-bit and smaller machines. */
1bd43494 48typedef unsigned _Unwind_Word __attribute__((__mode__(__unwind_word__)));
49typedef signed _Unwind_Sword __attribute__((__mode__(__unwind_word__)));
d786f066 50#if defined(__ia64__) && defined(__hpux__)
51typedef unsigned _Unwind_Ptr __attribute__((__mode__(__word__)));
52#else
df4b504c 53typedef unsigned _Unwind_Ptr __attribute__((__mode__(__pointer__)));
d786f066 54#endif
55typedef unsigned _Unwind_Internal_Ptr __attribute__((__mode__(__pointer__)));
df4b504c 56
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. */
61typedef unsigned _Unwind_Exception_Class __attribute__((__mode__(__DI__)));
62
63/* The unwind interface uses reason codes in several contexts to
64 identify the reasons for failures or other actions. */
65typedef enum
66{
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;
77
78
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. */
84
85struct _Unwind_Exception;
86
87typedef void (*_Unwind_Exception_Cleanup_Fn) (_Unwind_Reason_Code,
88 struct _Unwind_Exception *);
89
90struct _Unwind_Exception
91{
92 _Unwind_Exception_Class exception_class;
93 _Unwind_Exception_Cleanup_Fn exception_cleanup;
8ad0b530 94
95#if !defined (__USING_SJLJ_EXCEPTIONS__) && defined (__SEH__)
96 _Unwind_Word private_[6];
97#else
df4b504c 98 _Unwind_Word private_1;
99 _Unwind_Word private_2;
8ad0b530 100#endif
df4b504c 101
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__));
106
107
108/* The ACTIONS argument to the personality routine is a bitwise OR of one
109 or more of the following constants. */
110typedef int _Unwind_Action;
111
112#define _UA_SEARCH_PHASE 1
113#define _UA_CLEANUP_PHASE 2
114#define _UA_HANDLER_FRAME 4
115#define _UA_FORCE_UNWIND 8
8c584592 116#define _UA_END_OF_STACK 16
df4b504c 117
07e0e650 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
123
df4b504c 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. */
128struct _Unwind_Context;
129
130/* Raise an exception, passing along the given exception object. */
07e0e650 131extern _Unwind_Reason_Code LIBGCC2_UNWIND_ATTRIBUTE
132_Unwind_RaiseException (struct _Unwind_Exception *);
df4b504c 133
134/* Raise an exception for forced unwinding. */
135
136typedef _Unwind_Reason_Code (*_Unwind_Stop_Fn)
137 (int, _Unwind_Action, _Unwind_Exception_Class,
138 struct _Unwind_Exception *, struct _Unwind_Context *, void *);
139
07e0e650 140extern _Unwind_Reason_Code LIBGCC2_UNWIND_ATTRIBUTE
141_Unwind_ForcedUnwind (struct _Unwind_Exception *, _Unwind_Stop_Fn, void *);
df4b504c 142
143/* Helper to invoke the exception_cleanup routine. */
144extern void _Unwind_DeleteException (struct _Unwind_Exception *);
145
146/* Resume propagation of an existing exception. This is used after
147 e.g. executing cleanup code, and not to implement rethrowing. */
07e0e650 148extern void LIBGCC2_UNWIND_ATTRIBUTE
149_Unwind_Resume (struct _Unwind_Exception *);
df4b504c 150
e0f40ead 151/* @@@ Resume propagation of a FORCE_UNWIND exception, or to rethrow
ce9beb5c 152 a normal exception that was handled. */
07e0e650 153extern _Unwind_Reason_Code LIBGCC2_UNWIND_ATTRIBUTE
154_Unwind_Resume_or_Rethrow (struct _Unwind_Exception *);
ce9beb5c 155
4f0ee686 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. */
159typedef _Unwind_Reason_Code (*_Unwind_Trace_Fn)
160 (struct _Unwind_Context *, void *);
161
07e0e650 162extern _Unwind_Reason_Code LIBGCC2_UNWIND_ATTRIBUTE
163_Unwind_Backtrace (_Unwind_Trace_Fn, void *);
4f0ee686 164
df4b504c 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
e0f40ead 168 selected registers may be manipulated. */
df4b504c 169
170extern _Unwind_Word _Unwind_GetGR (struct _Unwind_Context *, int);
171extern void _Unwind_SetGR (struct _Unwind_Context *, int, _Unwind_Word);
172
173extern _Unwind_Ptr _Unwind_GetIP (struct _Unwind_Context *);
15c73eb7 174extern _Unwind_Ptr _Unwind_GetIPInfo (struct _Unwind_Context *, int *);
df4b504c 175extern void _Unwind_SetIP (struct _Unwind_Context *, _Unwind_Ptr);
176
c7beb4b3 177/* @@@ Retrieve the CFA of the given context. */
178extern _Unwind_Word _Unwind_GetCFA (struct _Unwind_Context *);
179
df4b504c 180extern void *_Unwind_GetLanguageSpecificData (struct _Unwind_Context *);
181
182extern _Unwind_Ptr _Unwind_GetRegionStart (struct _Unwind_Context *);
183
184
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
6c34d0c2 190 hence it has no ABI-specified name.
df4b504c 191
192 Note that this implies that two different C++ implementations can
193 use different names, and have different contents in the language
6c34d0c2 194 specific data area. Moreover, that the language specific data
df4b504c 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. */
6c34d0c2 198
df4b504c 199typedef _Unwind_Reason_Code (*_Unwind_Personality_Fn)
200 (int, _Unwind_Action, _Unwind_Exception_Class,
201 struct _Unwind_Exception *, struct _Unwind_Context *);
202
203/* @@@ The following alternate entry points are for setjmp/longjmp
204 based unwinding. */
205
206struct SjLj_Function_Context;
207extern void _Unwind_SjLj_Register (struct SjLj_Function_Context *);
208extern void _Unwind_SjLj_Unregister (struct SjLj_Function_Context *);
209
07e0e650 210extern _Unwind_Reason_Code LIBGCC2_UNWIND_ATTRIBUTE
211_Unwind_SjLj_RaiseException (struct _Unwind_Exception *);
212extern _Unwind_Reason_Code LIBGCC2_UNWIND_ATTRIBUTE
213_Unwind_SjLj_ForcedUnwind (struct _Unwind_Exception *, _Unwind_Stop_Fn, void *);
214extern void LIBGCC2_UNWIND_ATTRIBUTE
215_Unwind_SjLj_Resume (struct _Unwind_Exception *);
216extern _Unwind_Reason_Code LIBGCC2_UNWIND_ATTRIBUTE
217_Unwind_SjLj_Resume_or_Rethrow (struct _Unwind_Exception *);
df4b504c 218
ad5818ae 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. */
222
223#ifdef __ia64__
ad5818ae 224static inline _Unwind_Ptr
225_Unwind_GetDataRelBase (struct _Unwind_Context *_C)
226{
227 /* The GP is stored in R1. */
228 return _Unwind_GetGR (_C, 1);
229}
230
231static inline _Unwind_Ptr
5a1a138d 232_Unwind_GetTextRelBase (struct _Unwind_Context *_C __attribute__ ((__unused__)))
ad5818ae 233{
9ff93578 234 __builtin_abort ();
9fedfdae 235 return 0;
ad5818ae 236}
f8ecef74 237
238/* @@@ Retrieve the Backing Store Pointer of the given context. */
239extern _Unwind_Word _Unwind_GetBSP (struct _Unwind_Context *);
ad5818ae 240#else
241extern _Unwind_Ptr _Unwind_GetDataRelBase (struct _Unwind_Context *);
242extern _Unwind_Ptr _Unwind_GetTextRelBase (struct _Unwind_Context *);
243#endif
244
41acc81b 245/* @@@ Given an address, return the entry point of the function that
246 contains it. */
247extern void * _Unwind_FindEnclosingFunction (void *pc);
248
c68b099b 249#ifndef __SIZEOF_LONG__
250 #error "__SIZEOF_LONG__ macro not defined"
251#endif
252
253#ifndef __SIZEOF_POINTER__
254 #error "__SIZEOF_POINTER__ macro not defined"
255#endif
256
257
258/* leb128 type numbers have a potentially unlimited size.
259 The target of the following definitions of _sleb128_t and _uleb128_t
260 is to have efficient data types large enough to hold the leb128 type
261 numbers used in the unwind code.
262 Mostly these types will simply be defined to long and unsigned long
263 except when a unsigned long data type on the target machine is not
264 capable of storing a pointer. */
265
9c0794a1 266#if __SIZEOF_LONG__ >= __SIZEOF_POINTER__
267 typedef long _sleb128_t;
268 typedef unsigned long _uleb128_t;
269#elif __SIZEOF_LONG_LONG__ >= __SIZEOF_POINTER__
c68b099b 270 typedef long long _sleb128_t;
271 typedef unsigned long long _uleb128_t;
272#else
9c0794a1 273# error "What type shall we use for _sleb128_t?"
c68b099b 274#endif
275
a92cf445 276#if defined (__SEH__) && !defined (__USING_SJLJ_EXCEPTIONS__)
8ad0b530 277/* Handles the mapping from SEH to GCC interfaces. */
278EXCEPTION_DISPOSITION _GCC_specific_handler (PEXCEPTION_RECORD, void *,
279 PCONTEXT, PDISPATCHER_CONTEXT,
280 _Unwind_Personality_Fn);
281#endif
282
df4b504c 283#ifdef __cplusplus
284}
285#endif
817adc77 286
cca0d0c6 287#ifndef HIDE_EXPORTS
bc9fbf5d 288#pragma GCC visibility pop
cca0d0c6 289#endif
bc9fbf5d 290
817adc77 291#endif /* unwind.h */