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