annotate libgcc/unwind-generic.h @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* Exception handling and frame unwind runtime interface routines.
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2 Copyright (C) 2001-2018 Free Software Foundation, Inc.
111
kono
parents:
diff changeset
3
kono
parents:
diff changeset
4 This file is part of GCC.
kono
parents:
diff changeset
5
kono
parents:
diff changeset
6 GCC is free software; you can redistribute it and/or modify it
kono
parents:
diff changeset
7 under the terms of the GNU General Public License as published by
kono
parents:
diff changeset
8 the Free Software Foundation; either version 3, or (at your option)
kono
parents:
diff changeset
9 any later version.
kono
parents:
diff changeset
10
kono
parents:
diff changeset
11 GCC is distributed in the hope that it will be useful, but WITHOUT
kono
parents:
diff changeset
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
kono
parents:
diff changeset
13 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
kono
parents:
diff changeset
14 License for more details.
kono
parents:
diff changeset
15
kono
parents:
diff changeset
16 Under Section 7 of GPL version 3, you are granted additional
kono
parents:
diff changeset
17 permissions described in the GCC Runtime Library Exception, version
kono
parents:
diff changeset
18 3.1, as published by the Free Software Foundation.
kono
parents:
diff changeset
19
kono
parents:
diff changeset
20 You should have received a copy of the GNU General Public License and
kono
parents:
diff changeset
21 a copy of the GCC Runtime Library Exception along with this program;
kono
parents:
diff changeset
22 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
kono
parents:
diff changeset
23 <http://www.gnu.org/licenses/>. */
kono
parents:
diff changeset
24
kono
parents:
diff changeset
25 /* This is derived from the C++ ABI for IA-64. Where we diverge
kono
parents:
diff changeset
26 for cross-architecture compatibility are noted with "@@@". */
kono
parents:
diff changeset
27
kono
parents:
diff changeset
28 #ifndef _UNWIND_H
kono
parents:
diff changeset
29 #define _UNWIND_H
kono
parents:
diff changeset
30
kono
parents:
diff changeset
31 #if defined (__SEH__) && !defined (__USING_SJLJ_EXCEPTIONS__)
kono
parents:
diff changeset
32 /* Only for _GCC_specific_handler. */
kono
parents:
diff changeset
33 #include <windows.h>
kono
parents:
diff changeset
34 #endif
kono
parents:
diff changeset
35
kono
parents:
diff changeset
36 #ifndef HIDE_EXPORTS
kono
parents:
diff changeset
37 #pragma GCC visibility push(default)
kono
parents:
diff changeset
38 #endif
kono
parents:
diff changeset
39
kono
parents:
diff changeset
40 #ifdef __cplusplus
kono
parents:
diff changeset
41 extern "C" {
kono
parents:
diff changeset
42 #endif
kono
parents:
diff changeset
43
kono
parents:
diff changeset
44 /* Level 1: Base ABI */
kono
parents:
diff changeset
45
kono
parents:
diff changeset
46 /* @@@ The IA-64 ABI uses uint64 throughout. Most places this is
kono
parents:
diff changeset
47 inefficient for 32-bit and smaller machines. */
kono
parents:
diff changeset
48 typedef unsigned _Unwind_Word __attribute__((__mode__(__unwind_word__)));
kono
parents:
diff changeset
49 typedef signed _Unwind_Sword __attribute__((__mode__(__unwind_word__)));
kono
parents:
diff changeset
50 #if defined(__ia64__) && defined(__hpux__)
kono
parents:
diff changeset
51 typedef unsigned _Unwind_Ptr __attribute__((__mode__(__word__)));
kono
parents:
diff changeset
52 #else
kono
parents:
diff changeset
53 typedef unsigned _Unwind_Ptr __attribute__((__mode__(__pointer__)));
kono
parents:
diff changeset
54 #endif
kono
parents:
diff changeset
55 typedef unsigned _Unwind_Internal_Ptr __attribute__((__mode__(__pointer__)));
kono
parents:
diff changeset
56
kono
parents:
diff changeset
57 /* @@@ The IA-64 ABI uses a 64-bit word to identify the producer and
kono
parents:
diff changeset
58 consumer of an exception. We'll go along with this for now even on
kono
parents:
diff changeset
59 32-bit machines. We'll need to provide some other option for
kono
parents:
diff changeset
60 16-bit machines and for machines with > 8 bits per byte. */
kono
parents:
diff changeset
61 typedef unsigned _Unwind_Exception_Class __attribute__((__mode__(__DI__)));
kono
parents:
diff changeset
62
kono
parents:
diff changeset
63 /* The unwind interface uses reason codes in several contexts to
kono
parents:
diff changeset
64 identify the reasons for failures or other actions. */
kono
parents:
diff changeset
65 typedef enum
kono
parents:
diff changeset
66 {
kono
parents:
diff changeset
67 _URC_NO_REASON = 0,
kono
parents:
diff changeset
68 _URC_FOREIGN_EXCEPTION_CAUGHT = 1,
kono
parents:
diff changeset
69 _URC_FATAL_PHASE2_ERROR = 2,
kono
parents:
diff changeset
70 _URC_FATAL_PHASE1_ERROR = 3,
kono
parents:
diff changeset
71 _URC_NORMAL_STOP = 4,
kono
parents:
diff changeset
72 _URC_END_OF_STACK = 5,
kono
parents:
diff changeset
73 _URC_HANDLER_FOUND = 6,
kono
parents:
diff changeset
74 _URC_INSTALL_CONTEXT = 7,
kono
parents:
diff changeset
75 _URC_CONTINUE_UNWIND = 8
kono
parents:
diff changeset
76 } _Unwind_Reason_Code;
kono
parents:
diff changeset
77
kono
parents:
diff changeset
78
kono
parents:
diff changeset
79 /* The unwind interface uses a pointer to an exception header object
kono
parents:
diff changeset
80 as its representation of an exception being thrown. In general, the
kono
parents:
diff changeset
81 full representation of an exception object is language- and
kono
parents:
diff changeset
82 implementation-specific, but it will be prefixed by a header
kono
parents:
diff changeset
83 understood by the unwind interface. */
kono
parents:
diff changeset
84
kono
parents:
diff changeset
85 struct _Unwind_Exception;
kono
parents:
diff changeset
86
kono
parents:
diff changeset
87 typedef void (*_Unwind_Exception_Cleanup_Fn) (_Unwind_Reason_Code,
kono
parents:
diff changeset
88 struct _Unwind_Exception *);
kono
parents:
diff changeset
89
kono
parents:
diff changeset
90 struct _Unwind_Exception
kono
parents:
diff changeset
91 {
kono
parents:
diff changeset
92 _Unwind_Exception_Class exception_class;
kono
parents:
diff changeset
93 _Unwind_Exception_Cleanup_Fn exception_cleanup;
kono
parents:
diff changeset
94
kono
parents:
diff changeset
95 #if !defined (__USING_SJLJ_EXCEPTIONS__) && defined (__SEH__)
kono
parents:
diff changeset
96 _Unwind_Word private_[6];
kono
parents:
diff changeset
97 #else
kono
parents:
diff changeset
98 _Unwind_Word private_1;
kono
parents:
diff changeset
99 _Unwind_Word private_2;
kono
parents:
diff changeset
100 #endif
kono
parents:
diff changeset
101
kono
parents:
diff changeset
102 /* @@@ The IA-64 ABI says that this structure must be double-word aligned.
kono
parents:
diff changeset
103 Taking that literally does not make much sense generically. Instead we
kono
parents:
diff changeset
104 provide the maximum alignment required by any type for the machine. */
kono
parents:
diff changeset
105 } __attribute__((__aligned__));
kono
parents:
diff changeset
106
kono
parents:
diff changeset
107
kono
parents:
diff changeset
108 /* The ACTIONS argument to the personality routine is a bitwise OR of one
kono
parents:
diff changeset
109 or more of the following constants. */
kono
parents:
diff changeset
110 typedef int _Unwind_Action;
kono
parents:
diff changeset
111
kono
parents:
diff changeset
112 #define _UA_SEARCH_PHASE 1
kono
parents:
diff changeset
113 #define _UA_CLEANUP_PHASE 2
kono
parents:
diff changeset
114 #define _UA_HANDLER_FRAME 4
kono
parents:
diff changeset
115 #define _UA_FORCE_UNWIND 8
kono
parents:
diff changeset
116 #define _UA_END_OF_STACK 16
kono
parents:
diff changeset
117
kono
parents:
diff changeset
118 /* The target can override this macro to define any back-end-specific
kono
parents:
diff changeset
119 attributes required for the lowest-level stack frame. */
kono
parents:
diff changeset
120 #ifndef LIBGCC2_UNWIND_ATTRIBUTE
kono
parents:
diff changeset
121 #define LIBGCC2_UNWIND_ATTRIBUTE
kono
parents:
diff changeset
122 #endif
kono
parents:
diff changeset
123
kono
parents:
diff changeset
124 /* This is an opaque type used to refer to a system-specific data
kono
parents:
diff changeset
125 structure used by the system unwinder. This context is created and
kono
parents:
diff changeset
126 destroyed by the system, and passed to the personality routine
kono
parents:
diff changeset
127 during unwinding. */
kono
parents:
diff changeset
128 struct _Unwind_Context;
kono
parents:
diff changeset
129
kono
parents:
diff changeset
130 /* Raise an exception, passing along the given exception object. */
kono
parents:
diff changeset
131 extern _Unwind_Reason_Code LIBGCC2_UNWIND_ATTRIBUTE
kono
parents:
diff changeset
132 _Unwind_RaiseException (struct _Unwind_Exception *);
kono
parents:
diff changeset
133
kono
parents:
diff changeset
134 /* Raise an exception for forced unwinding. */
kono
parents:
diff changeset
135
kono
parents:
diff changeset
136 typedef _Unwind_Reason_Code (*_Unwind_Stop_Fn)
kono
parents:
diff changeset
137 (int, _Unwind_Action, _Unwind_Exception_Class,
kono
parents:
diff changeset
138 struct _Unwind_Exception *, struct _Unwind_Context *, void *);
kono
parents:
diff changeset
139
kono
parents:
diff changeset
140 extern _Unwind_Reason_Code LIBGCC2_UNWIND_ATTRIBUTE
kono
parents:
diff changeset
141 _Unwind_ForcedUnwind (struct _Unwind_Exception *, _Unwind_Stop_Fn, void *);
kono
parents:
diff changeset
142
kono
parents:
diff changeset
143 /* Helper to invoke the exception_cleanup routine. */
kono
parents:
diff changeset
144 extern void _Unwind_DeleteException (struct _Unwind_Exception *);
kono
parents:
diff changeset
145
kono
parents:
diff changeset
146 /* Resume propagation of an existing exception. This is used after
kono
parents:
diff changeset
147 e.g. executing cleanup code, and not to implement rethrowing. */
kono
parents:
diff changeset
148 extern void LIBGCC2_UNWIND_ATTRIBUTE
kono
parents:
diff changeset
149 _Unwind_Resume (struct _Unwind_Exception *);
kono
parents:
diff changeset
150
kono
parents:
diff changeset
151 /* @@@ Resume propagation of a FORCE_UNWIND exception, or to rethrow
kono
parents:
diff changeset
152 a normal exception that was handled. */
kono
parents:
diff changeset
153 extern _Unwind_Reason_Code LIBGCC2_UNWIND_ATTRIBUTE
kono
parents:
diff changeset
154 _Unwind_Resume_or_Rethrow (struct _Unwind_Exception *);
kono
parents:
diff changeset
155
kono
parents:
diff changeset
156 /* @@@ Use unwind data to perform a stack backtrace. The trace callback
kono
parents:
diff changeset
157 is called for every stack frame in the call chain, but no cleanup
kono
parents:
diff changeset
158 actions are performed. */
kono
parents:
diff changeset
159 typedef _Unwind_Reason_Code (*_Unwind_Trace_Fn)
kono
parents:
diff changeset
160 (struct _Unwind_Context *, void *);
kono
parents:
diff changeset
161
kono
parents:
diff changeset
162 extern _Unwind_Reason_Code LIBGCC2_UNWIND_ATTRIBUTE
kono
parents:
diff changeset
163 _Unwind_Backtrace (_Unwind_Trace_Fn, void *);
kono
parents:
diff changeset
164
kono
parents:
diff changeset
165 /* These functions are used for communicating information about the unwind
kono
parents:
diff changeset
166 context (i.e. the unwind descriptors and the user register state) between
kono
parents:
diff changeset
167 the unwind library and the personality routine and landing pad. Only
kono
parents:
diff changeset
168 selected registers may be manipulated. */
kono
parents:
diff changeset
169
kono
parents:
diff changeset
170 extern _Unwind_Word _Unwind_GetGR (struct _Unwind_Context *, int);
kono
parents:
diff changeset
171 extern void _Unwind_SetGR (struct _Unwind_Context *, int, _Unwind_Word);
kono
parents:
diff changeset
172
kono
parents:
diff changeset
173 extern _Unwind_Ptr _Unwind_GetIP (struct _Unwind_Context *);
kono
parents:
diff changeset
174 extern _Unwind_Ptr _Unwind_GetIPInfo (struct _Unwind_Context *, int *);
kono
parents:
diff changeset
175 extern void _Unwind_SetIP (struct _Unwind_Context *, _Unwind_Ptr);
kono
parents:
diff changeset
176
kono
parents:
diff changeset
177 /* @@@ Retrieve the CFA of the given context. */
kono
parents:
diff changeset
178 extern _Unwind_Word _Unwind_GetCFA (struct _Unwind_Context *);
kono
parents:
diff changeset
179
kono
parents:
diff changeset
180 extern void *_Unwind_GetLanguageSpecificData (struct _Unwind_Context *);
kono
parents:
diff changeset
181
kono
parents:
diff changeset
182 extern _Unwind_Ptr _Unwind_GetRegionStart (struct _Unwind_Context *);
kono
parents:
diff changeset
183
kono
parents:
diff changeset
184
kono
parents:
diff changeset
185 /* The personality routine is the function in the C++ (or other language)
kono
parents:
diff changeset
186 runtime library which serves as an interface between the system unwind
kono
parents:
diff changeset
187 library and language-specific exception handling semantics. It is
kono
parents:
diff changeset
188 specific to the code fragment described by an unwind info block, and
kono
parents:
diff changeset
189 it is always referenced via the pointer in the unwind info block, and
kono
parents:
diff changeset
190 hence it has no ABI-specified name.
kono
parents:
diff changeset
191
kono
parents:
diff changeset
192 Note that this implies that two different C++ implementations can
kono
parents:
diff changeset
193 use different names, and have different contents in the language
kono
parents:
diff changeset
194 specific data area. Moreover, that the language specific data
kono
parents:
diff changeset
195 area contains no version info because name of the function invoked
kono
parents:
diff changeset
196 provides more effective versioning by detecting at link time the
kono
parents:
diff changeset
197 lack of code to handle the different data format. */
kono
parents:
diff changeset
198
kono
parents:
diff changeset
199 typedef _Unwind_Reason_Code (*_Unwind_Personality_Fn)
kono
parents:
diff changeset
200 (int, _Unwind_Action, _Unwind_Exception_Class,
kono
parents:
diff changeset
201 struct _Unwind_Exception *, struct _Unwind_Context *);
kono
parents:
diff changeset
202
kono
parents:
diff changeset
203 /* @@@ The following alternate entry points are for setjmp/longjmp
kono
parents:
diff changeset
204 based unwinding. */
kono
parents:
diff changeset
205
kono
parents:
diff changeset
206 struct SjLj_Function_Context;
kono
parents:
diff changeset
207 extern void _Unwind_SjLj_Register (struct SjLj_Function_Context *);
kono
parents:
diff changeset
208 extern void _Unwind_SjLj_Unregister (struct SjLj_Function_Context *);
kono
parents:
diff changeset
209
kono
parents:
diff changeset
210 extern _Unwind_Reason_Code LIBGCC2_UNWIND_ATTRIBUTE
kono
parents:
diff changeset
211 _Unwind_SjLj_RaiseException (struct _Unwind_Exception *);
kono
parents:
diff changeset
212 extern _Unwind_Reason_Code LIBGCC2_UNWIND_ATTRIBUTE
kono
parents:
diff changeset
213 _Unwind_SjLj_ForcedUnwind (struct _Unwind_Exception *, _Unwind_Stop_Fn, void *);
kono
parents:
diff changeset
214 extern void LIBGCC2_UNWIND_ATTRIBUTE
kono
parents:
diff changeset
215 _Unwind_SjLj_Resume (struct _Unwind_Exception *);
kono
parents:
diff changeset
216 extern _Unwind_Reason_Code LIBGCC2_UNWIND_ATTRIBUTE
kono
parents:
diff changeset
217 _Unwind_SjLj_Resume_or_Rethrow (struct _Unwind_Exception *);
kono
parents:
diff changeset
218
kono
parents:
diff changeset
219 /* @@@ The following provide access to the base addresses for text
kono
parents:
diff changeset
220 and data-relative addressing in the LDSA. In order to stay link
kono
parents:
diff changeset
221 compatible with the standard ABI for IA-64, we inline these. */
kono
parents:
diff changeset
222
kono
parents:
diff changeset
223 #ifdef __ia64__
kono
parents:
diff changeset
224 static inline _Unwind_Ptr
kono
parents:
diff changeset
225 _Unwind_GetDataRelBase (struct _Unwind_Context *_C)
kono
parents:
diff changeset
226 {
kono
parents:
diff changeset
227 /* The GP is stored in R1. */
kono
parents:
diff changeset
228 return _Unwind_GetGR (_C, 1);
kono
parents:
diff changeset
229 }
kono
parents:
diff changeset
230
kono
parents:
diff changeset
231 static inline _Unwind_Ptr
kono
parents:
diff changeset
232 _Unwind_GetTextRelBase (struct _Unwind_Context *_C __attribute__ ((__unused__)))
kono
parents:
diff changeset
233 {
kono
parents:
diff changeset
234 __builtin_abort ();
kono
parents:
diff changeset
235 return 0;
kono
parents:
diff changeset
236 }
kono
parents:
diff changeset
237
kono
parents:
diff changeset
238 /* @@@ Retrieve the Backing Store Pointer of the given context. */
kono
parents:
diff changeset
239 extern _Unwind_Word _Unwind_GetBSP (struct _Unwind_Context *);
kono
parents:
diff changeset
240 #else
kono
parents:
diff changeset
241 extern _Unwind_Ptr _Unwind_GetDataRelBase (struct _Unwind_Context *);
kono
parents:
diff changeset
242 extern _Unwind_Ptr _Unwind_GetTextRelBase (struct _Unwind_Context *);
kono
parents:
diff changeset
243 #endif
kono
parents:
diff changeset
244
kono
parents:
diff changeset
245 /* @@@ Given an address, return the entry point of the function that
kono
parents:
diff changeset
246 contains it. */
kono
parents:
diff changeset
247 extern void * _Unwind_FindEnclosingFunction (void *pc);
kono
parents:
diff changeset
248
kono
parents:
diff changeset
249 #ifndef __SIZEOF_LONG__
kono
parents:
diff changeset
250 #error "__SIZEOF_LONG__ macro not defined"
kono
parents:
diff changeset
251 #endif
kono
parents:
diff changeset
252
kono
parents:
diff changeset
253 #ifndef __SIZEOF_POINTER__
kono
parents:
diff changeset
254 #error "__SIZEOF_POINTER__ macro not defined"
kono
parents:
diff changeset
255 #endif
kono
parents:
diff changeset
256
kono
parents:
diff changeset
257
kono
parents:
diff changeset
258 /* leb128 type numbers have a potentially unlimited size.
kono
parents:
diff changeset
259 The target of the following definitions of _sleb128_t and _uleb128_t
kono
parents:
diff changeset
260 is to have efficient data types large enough to hold the leb128 type
kono
parents:
diff changeset
261 numbers used in the unwind code.
kono
parents:
diff changeset
262 Mostly these types will simply be defined to long and unsigned long
kono
parents:
diff changeset
263 except when a unsigned long data type on the target machine is not
kono
parents:
diff changeset
264 capable of storing a pointer. */
kono
parents:
diff changeset
265
kono
parents:
diff changeset
266 #if __SIZEOF_LONG__ >= __SIZEOF_POINTER__
kono
parents:
diff changeset
267 typedef long _sleb128_t;
kono
parents:
diff changeset
268 typedef unsigned long _uleb128_t;
kono
parents:
diff changeset
269 #elif __SIZEOF_LONG_LONG__ >= __SIZEOF_POINTER__
kono
parents:
diff changeset
270 typedef long long _sleb128_t;
kono
parents:
diff changeset
271 typedef unsigned long long _uleb128_t;
kono
parents:
diff changeset
272 #else
kono
parents:
diff changeset
273 # error "What type shall we use for _sleb128_t?"
kono
parents:
diff changeset
274 #endif
kono
parents:
diff changeset
275
kono
parents:
diff changeset
276 #if defined (__SEH__) && !defined (__USING_SJLJ_EXCEPTIONS__)
kono
parents:
diff changeset
277 /* Handles the mapping from SEH to GCC interfaces. */
kono
parents:
diff changeset
278 EXCEPTION_DISPOSITION _GCC_specific_handler (PEXCEPTION_RECORD, void *,
kono
parents:
diff changeset
279 PCONTEXT, PDISPATCHER_CONTEXT,
kono
parents:
diff changeset
280 _Unwind_Personality_Fn);
kono
parents:
diff changeset
281 #endif
kono
parents:
diff changeset
282
kono
parents:
diff changeset
283 #ifdef __cplusplus
kono
parents:
diff changeset
284 }
kono
parents:
diff changeset
285 #endif
kono
parents:
diff changeset
286
kono
parents:
diff changeset
287 #ifndef HIDE_EXPORTS
kono
parents:
diff changeset
288 #pragma GCC visibility pop
kono
parents:
diff changeset
289 #endif
kono
parents:
diff changeset
290
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
291 /* Additional actions to unwind number of stack frames. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
292 #define _Unwind_Frames_Extra(frames)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
293
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
294 /* Increment frame count. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
295 #define _Unwind_Frames_Increment(context, frames) frames++
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
296
111
kono
parents:
diff changeset
297 #endif /* unwind.h */