]> git.ipfire.org Git - thirdparty/gcc.git/blame - libgcc/unwind-generic.h
[Ada] Bump copyright year
[thirdparty/gcc.git] / libgcc / unwind-generic.h
CommitLineData
52a11cbf 1/* Exception handling and frame unwind runtime interface routines.
8d9254fc 2 Copyright (C) 2001-2020 Free Software Foundation, Inc.
52a11cbf 3
1322177d 4 This file is part of GCC.
52a11cbf 5
1322177d
LB
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
748086b7 8 the Free Software Foundation; either version 3, or (at your option)
52a11cbf
RH
9 any later version.
10
1322177d
LB
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.
52a11cbf 15
748086b7
JJ
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/>. */
336d0d96 24
52a11cbf
RH
25/* This is derived from the C++ ABI for IA-64. Where we diverge
26 for cross-architecture compatibility are noted with "@@@". */
27
7ce27103
ZW
28#ifndef _UNWIND_H
29#define _UNWIND_H
30
e5a81c8e 31#if defined (__SEH__) && !defined (__USING_SJLJ_EXCEPTIONS__)
bf1431e3
TG
32/* Only for _GCC_specific_handler. */
33#include <windows.h>
34#endif
35
7370bebd 36#ifndef HIDE_EXPORTS
3fc1f660 37#pragma GCC visibility push(default)
7370bebd 38#endif
3fc1f660 39
52a11cbf
RH
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. */
7b0518e3
UW
48typedef unsigned _Unwind_Word __attribute__((__mode__(__unwind_word__)));
49typedef signed _Unwind_Sword __attribute__((__mode__(__unwind_word__)));
9ef30f83
SE
50#if defined(__ia64__) && defined(__hpux__)
51typedef unsigned _Unwind_Ptr __attribute__((__mode__(__word__)));
52#else
52a11cbf 53typedef unsigned _Unwind_Ptr __attribute__((__mode__(__pointer__)));
9ef30f83
SE
54#endif
55typedef unsigned _Unwind_Internal_Ptr __attribute__((__mode__(__pointer__)));
52a11cbf
RH
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;
bf1431e3
TG
94
95#if !defined (__USING_SJLJ_EXCEPTIONS__) && defined (__SEH__)
96 _Unwind_Word private_[6];
97#else
52a11cbf
RH
98 _Unwind_Word private_1;
99 _Unwind_Word private_2;
bf1431e3 100#endif
52a11cbf
RH
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
4c21ef03 116#define _UA_END_OF_STACK 16
52a11cbf 117
56e449d3
SL
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
52a11cbf
RH
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. */
56e449d3
SL
131extern _Unwind_Reason_Code LIBGCC2_UNWIND_ATTRIBUTE
132_Unwind_RaiseException (struct _Unwind_Exception *);
52a11cbf
RH
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
56e449d3
SL
140extern _Unwind_Reason_Code LIBGCC2_UNWIND_ATTRIBUTE
141_Unwind_ForcedUnwind (struct _Unwind_Exception *, _Unwind_Stop_Fn, void *);
52a11cbf
RH
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. */
56e449d3
SL
148extern void LIBGCC2_UNWIND_ATTRIBUTE
149_Unwind_Resume (struct _Unwind_Exception *);
52a11cbf 150
573b3837 151/* @@@ Resume propagation of a FORCE_UNWIND exception, or to rethrow
a944ceb9 152 a normal exception that was handled. */
56e449d3
SL
153extern _Unwind_Reason_Code LIBGCC2_UNWIND_ATTRIBUTE
154_Unwind_Resume_or_Rethrow (struct _Unwind_Exception *);
a944ceb9 155
7344f3d7
UW
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
56e449d3
SL
162extern _Unwind_Reason_Code LIBGCC2_UNWIND_ATTRIBUTE
163_Unwind_Backtrace (_Unwind_Trace_Fn, void *);
7344f3d7 164
52a11cbf
RH
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
573b3837 168 selected registers may be manipulated. */
52a11cbf
RH
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 *);
754e45a8 174extern _Unwind_Ptr _Unwind_GetIPInfo (struct _Unwind_Context *, int *);
52a11cbf
RH
175extern void _Unwind_SetIP (struct _Unwind_Context *, _Unwind_Ptr);
176
378683cf
RH
177/* @@@ Retrieve the CFA of the given context. */
178extern _Unwind_Word _Unwind_GetCFA (struct _Unwind_Context *);
179
52a11cbf
RH
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
41077ce4 190 hence it has no ABI-specified name.
52a11cbf
RH
191
192 Note that this implies that two different C++ implementations can
193 use different names, and have different contents in the language
41077ce4 194 specific data area. Moreover, that the language specific data
52a11cbf
RH
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. */
41077ce4 198
52a11cbf
RH
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
56e449d3
SL
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 *);
52a11cbf 218
2a1ee410
RH
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__
2a1ee410
RH
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
9a600d0c 232_Unwind_GetTextRelBase (struct _Unwind_Context *_C __attribute__ ((__unused__)))
2a1ee410 233{
077067a5 234 __builtin_abort ();
e4d0c41c 235 return 0;
2a1ee410 236}
bc93e287
JJ
237
238/* @@@ Retrieve the Backing Store Pointer of the given context. */
239extern _Unwind_Word _Unwind_GetBSP (struct _Unwind_Context *);
2a1ee410
RH
240#else
241extern _Unwind_Ptr _Unwind_GetDataRelBase (struct _Unwind_Context *);
242extern _Unwind_Ptr _Unwind_GetTextRelBase (struct _Unwind_Context *);
243#endif
244
5154b05d
AH
245/* @@@ Given an address, return the entry point of the function that
246 contains it. */
247extern void * _Unwind_FindEnclosingFunction (void *pc);
248
f767122b
AK
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
58c11467
RH
266#if __SIZEOF_LONG__ >= __SIZEOF_POINTER__
267 typedef long _sleb128_t;
268 typedef unsigned long _uleb128_t;
269#elif __SIZEOF_LONG_LONG__ >= __SIZEOF_POINTER__
f767122b
AK
270 typedef long long _sleb128_t;
271 typedef unsigned long long _uleb128_t;
272#else
58c11467 273# error "What type shall we use for _sleb128_t?"
f767122b
AK
274#endif
275
e5a81c8e 276#if defined (__SEH__) && !defined (__USING_SJLJ_EXCEPTIONS__)
bf1431e3
TG
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
52a11cbf
RH
283#ifdef __cplusplus
284}
285#endif
7ce27103 286
7370bebd 287#ifndef HIDE_EXPORTS
3fc1f660 288#pragma GCC visibility pop
7370bebd 289#endif
3fc1f660 290
6a10fff4
IT
291/* Additional actions to unwind number of stack frames. */
292#define _Unwind_Frames_Extra(frames)
293
5707be3c
L
294/* Increment frame count. */
295#define _Unwind_Frames_Increment(context, frames) frames++
296
7ce27103 297#endif /* unwind.h */