blob: 4f74a3478740e9fef0b9432737393c9190ba46a1 [file] [log] [blame]
Rafael Espindola18c79202011-12-08 05:01:39 +00001/*===---- unwind.h - Stack unwinding ----------------------------------------===
2 *
3 * Permission is hereby granted, free of charge, to any person obtaining a copy
4 * of this software and associated documentation files (the "Software"), to deal
5 * in the Software without restriction, including without limitation the rights
6 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 * copies of the Software, and to permit persons to whom the Software is
8 * furnished to do so, subject to the following conditions:
9 *
10 * The above copyright notice and this permission notice shall be included in
11 * all copies or substantial portions of the Software.
12 *
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 * THE SOFTWARE.
20 *
21 *===-----------------------------------------------------------------------===
22 */
23
24/* See "Data Definitions for libgcc_s" in the Linux Standard Base.*/
25
Benjamin Kramer69665142013-01-09 19:54:57 +000026#ifndef __CLANG_UNWIND_H
27#define __CLANG_UNWIND_H
28
Chandler Carruth032d4222014-12-29 13:29:38 +000029#if defined(__APPLE__) && __has_include_next(<unwind.h>)
30/* Darwin (from 11.x on) provide an unwind.h. If that's available,
Peter Collingbourneec1cb852013-08-28 23:16:49 +000031 * use it. libunwind wraps some of its definitions in #ifdef _GNU_SOURCE,
Jeffrey Yasskina09e62a2012-02-21 16:20:12 +000032 * so define that around the include.*/
33# ifndef _GNU_SOURCE
34# define _SHOULD_UNDEFINE_GNU_SOURCE
35# define _GNU_SOURCE
36# endif
Rafael Espindolac31d0042012-03-29 03:37:17 +000037// libunwind's unwind.h reflects the current visibility. However, Mozilla
38// builds with -fvisibility=hidden and relies on gcc's unwind.h to reset the
39// visibility to default and export its contents. gcc also allows users to
40// override its override by #defining HIDE_EXPORTS (but note, this only obeys
41// the user's -fvisibility setting; it doesn't hide any exports on its own). We
42// imitate gcc's header here:
43# ifdef HIDE_EXPORTS
44# include_next <unwind.h>
45# else
46# pragma GCC visibility push(default)
47# include_next <unwind.h>
48# pragma GCC visibility pop
49# endif
Jeffrey Yasskina09e62a2012-02-21 16:20:12 +000050# ifdef _SHOULD_UNDEFINE_GNU_SOURCE
51# undef _GNU_SOURCE
52# undef _SHOULD_UNDEFINE_GNU_SOURCE
53# endif
Rafael Espindola18c79202011-12-08 05:01:39 +000054#else
55
56#include <stdint.h>
57
58#ifdef __cplusplus
59extern "C" {
60#endif
61
Rafael Espindola7a284b22011-12-09 00:08:01 +000062/* It is a bit strange for a header to play with the visibility of the
63 symbols it declares, but this matches gcc's behavior and some programs
64 depend on it */
Benjamin Kramer69665142013-01-09 19:54:57 +000065#ifndef HIDE_EXPORTS
Rafael Espindola7a284b22011-12-09 00:08:01 +000066#pragma GCC visibility push(default)
Benjamin Kramer69665142013-01-09 19:54:57 +000067#endif
Rafael Espindola7a284b22011-12-09 00:08:01 +000068
Peter Collingbourneec1cb852013-08-28 23:16:49 +000069typedef uintptr_t _Unwind_Word;
70typedef intptr_t _Unwind_Sword;
71typedef uintptr_t _Unwind_Ptr;
72typedef uintptr_t _Unwind_Internal_Ptr;
73typedef uint64_t _Unwind_Exception_Class;
74
Peter Collingbourne6c77e722013-08-29 01:56:22 +000075typedef intptr_t _sleb128_t;
76typedef uintptr_t _uleb128_t;
77
Rafael Espindola18c79202011-12-08 05:01:39 +000078struct _Unwind_Context;
Peter Collingbourneec1cb852013-08-28 23:16:49 +000079struct _Unwind_Exception;
Rafael Espindola18c79202011-12-08 05:01:39 +000080typedef enum {
81 _URC_NO_REASON = 0,
Logan Chien3267ca22016-02-28 15:01:42 +000082#if defined(__arm__) && !defined(__USING_SJLJ_EXCEPTIONS__) && \
83 !defined(__ARM_DWARF_EH__)
84 _URC_OK = 0, /* used by ARM EHABI */
85#endif
Rafael Espindola18c79202011-12-08 05:01:39 +000086 _URC_FOREIGN_EXCEPTION_CAUGHT = 1,
87
88 _URC_FATAL_PHASE2_ERROR = 2,
89 _URC_FATAL_PHASE1_ERROR = 3,
90 _URC_NORMAL_STOP = 4,
91
92 _URC_END_OF_STACK = 5,
93 _URC_HANDLER_FOUND = 6,
94 _URC_INSTALL_CONTEXT = 7,
Logan Chien3267ca22016-02-28 15:01:42 +000095 _URC_CONTINUE_UNWIND = 8,
96#if defined(__arm__) && !defined(__USING_SJLJ_EXCEPTIONS__) && \
97 !defined(__ARM_DWARF_EH__)
98 _URC_FAILURE = 9 /* used by ARM EHABI */
99#endif
Rafael Espindola18c79202011-12-08 05:01:39 +0000100} _Unwind_Reason_Code;
101
Peter Collingbourneec1cb852013-08-28 23:16:49 +0000102typedef enum {
103 _UA_SEARCH_PHASE = 1,
104 _UA_CLEANUP_PHASE = 2,
105
106 _UA_HANDLER_FRAME = 4,
107 _UA_FORCE_UNWIND = 8,
108 _UA_END_OF_STACK = 16 /* gcc extension to C++ ABI */
109} _Unwind_Action;
110
111typedef void (*_Unwind_Exception_Cleanup_Fn)(_Unwind_Reason_Code,
112 struct _Unwind_Exception *);
113
114struct _Unwind_Exception {
115 _Unwind_Exception_Class exception_class;
116 _Unwind_Exception_Cleanup_Fn exception_cleanup;
117 _Unwind_Word private_1;
118 _Unwind_Word private_2;
119 /* The Itanium ABI requires that _Unwind_Exception objects are "double-word
120 * aligned". GCC has interpreted this to mean "use the maximum useful
121 * alignment for the target"; so do we. */
122} __attribute__((__aligned__));
123
124typedef _Unwind_Reason_Code (*_Unwind_Stop_Fn)(int, _Unwind_Action,
125 _Unwind_Exception_Class,
126 struct _Unwind_Exception *,
127 struct _Unwind_Context *,
128 void *);
129
Peter Collingbourne7ac84bd2013-08-28 23:32:22 +0000130typedef _Unwind_Reason_Code (*_Unwind_Personality_Fn)(
131 int, _Unwind_Action, _Unwind_Exception_Class, struct _Unwind_Exception *,
132 struct _Unwind_Context *);
Peter Collingbourneec1cb852013-08-28 23:16:49 +0000133typedef _Unwind_Personality_Fn __personality_routine;
134
Peter Collingbourne7ac84bd2013-08-28 23:32:22 +0000135typedef _Unwind_Reason_Code (*_Unwind_Trace_Fn)(struct _Unwind_Context *,
136 void *);
Evgeniy Stepanov5dfe9f22012-01-19 11:39:05 +0000137
Hans Wennborg736a0292013-09-25 22:34:03 +0000138#if defined(__arm__) && !defined(__APPLE__)
Evgeniy Stepanov5dfe9f22012-01-19 11:39:05 +0000139
Logan Chien4d401b42012-11-14 06:33:58 +0000140typedef enum {
141 _UVRSC_CORE = 0, /* integer register */
142 _UVRSC_VFP = 1, /* vfp */
143 _UVRSC_WMMXD = 3, /* Intel WMMX data register */
144 _UVRSC_WMMXC = 4 /* Intel WMMX control register */
145} _Unwind_VRS_RegClass;
Evgeniy Stepanov5dfe9f22012-01-19 11:39:05 +0000146
Logan Chien4d401b42012-11-14 06:33:58 +0000147typedef enum {
148 _UVRSD_UINT32 = 0,
149 _UVRSD_VFPX = 1,
150 _UVRSD_UINT64 = 3,
151 _UVRSD_FLOAT = 4,
152 _UVRSD_DOUBLE = 5
153} _Unwind_VRS_DataRepresentation;
Evgeniy Stepanov5dfe9f22012-01-19 11:39:05 +0000154
Logan Chien4d401b42012-11-14 06:33:58 +0000155typedef enum {
156 _UVRSR_OK = 0,
157 _UVRSR_NOT_IMPLEMENTED = 1,
158 _UVRSR_FAILED = 2
159} _Unwind_VRS_Result;
Evgeniy Stepanov5dfe9f22012-01-19 11:39:05 +0000160
Logan Chien3267ca22016-02-28 15:01:42 +0000161#if !defined(__USING_SJLJ_EXCEPTIONS__) && !defined(__ARM_DWARF_EH__)
162typedef uint32_t _Unwind_State;
163#define _US_VIRTUAL_UNWIND_FRAME ((_Unwind_State)0)
164#define _US_UNWIND_FRAME_STARTING ((_Unwind_State)1)
165#define _US_UNWIND_FRAME_RESUME ((_Unwind_State)2)
166#define _US_ACTION_MASK ((_Unwind_State)3)
167#define _US_FORCE_UNWIND ((_Unwind_State)8)
168#endif
169
David Blaikie3302f2b2013-01-16 23:08:36 +0000170_Unwind_VRS_Result _Unwind_VRS_Get(struct _Unwind_Context *__context,
171 _Unwind_VRS_RegClass __regclass,
172 uint32_t __regno,
173 _Unwind_VRS_DataRepresentation __representation,
174 void *__valuep);
Evgeniy Stepanov5dfe9f22012-01-19 11:39:05 +0000175
Hans Wennborg736a0292013-09-25 22:34:03 +0000176_Unwind_VRS_Result _Unwind_VRS_Set(struct _Unwind_Context *__context,
177 _Unwind_VRS_RegClass __regclass,
178 uint32_t __regno,
179 _Unwind_VRS_DataRepresentation __representation,
180 void *__valuep);
Evgeniy Stepanov5dfe9f22012-01-19 11:39:05 +0000181
Hans Wennborg736a0292013-09-25 22:34:03 +0000182static __inline__
183_Unwind_Word _Unwind_GetGR(struct _Unwind_Context *__context, int __index) {
184 _Unwind_Word __value;
185 _Unwind_VRS_Get(__context, _UVRSC_CORE, __index, _UVRSD_UINT32, &__value);
186 return __value;
187}
188
189static __inline__
190void _Unwind_SetGR(struct _Unwind_Context *__context, int __index,
191 _Unwind_Word __value) {
192 _Unwind_VRS_Set(__context, _UVRSC_CORE, __index, _UVRSD_UINT32, &__value);
193}
194
195static __inline__
196_Unwind_Word _Unwind_GetIP(struct _Unwind_Context *__context) {
197 _Unwind_Word __ip = _Unwind_GetGR(__context, 15);
198 return __ip & ~(_Unwind_Word)(0x1); /* Remove thumb mode bit. */
199}
200
201static __inline__
202void _Unwind_SetIP(struct _Unwind_Context *__context, _Unwind_Word __value) {
203 _Unwind_Word __thumb_mode_bit = _Unwind_GetGR(__context, 15) & 0x1;
204 _Unwind_SetGR(__context, 15, __value | __thumb_mode_bit);
205}
206#else
Peter Collingbourneec1cb852013-08-28 23:16:49 +0000207_Unwind_Word _Unwind_GetGR(struct _Unwind_Context *, int);
208void _Unwind_SetGR(struct _Unwind_Context *, int, _Unwind_Word);
209
210_Unwind_Word _Unwind_GetIP(struct _Unwind_Context *);
Peter Collingbourneec1cb852013-08-28 23:16:49 +0000211void _Unwind_SetIP(struct _Unwind_Context *, _Unwind_Word);
Hans Wennborg736a0292013-09-25 22:34:03 +0000212#endif
213
214
215_Unwind_Word _Unwind_GetIPInfo(struct _Unwind_Context *, int *);
Peter Collingbourneec1cb852013-08-28 23:16:49 +0000216
217_Unwind_Word _Unwind_GetCFA(struct _Unwind_Context *);
218
Chandler Carruthf3cabbd2014-12-29 13:29:36 +0000219_Unwind_Word _Unwind_GetBSP(struct _Unwind_Context *);
220
Peter Collingbourneec1cb852013-08-28 23:16:49 +0000221void *_Unwind_GetLanguageSpecificData(struct _Unwind_Context *);
222
223_Unwind_Ptr _Unwind_GetRegionStart(struct _Unwind_Context *);
224
225/* DWARF EH functions; currently not available on Darwin/ARM */
226#if !defined(__APPLE__) || !defined(__arm__)
227
228_Unwind_Reason_Code _Unwind_RaiseException(struct _Unwind_Exception *);
Peter Collingbourne7ac84bd2013-08-28 23:32:22 +0000229_Unwind_Reason_Code _Unwind_ForcedUnwind(struct _Unwind_Exception *,
230 _Unwind_Stop_Fn, void *);
Peter Collingbourneec1cb852013-08-28 23:16:49 +0000231void _Unwind_DeleteException(struct _Unwind_Exception *);
232void _Unwind_Resume(struct _Unwind_Exception *);
233_Unwind_Reason_Code _Unwind_Resume_or_Rethrow(struct _Unwind_Exception *);
Evgeniy Stepanov5dfe9f22012-01-19 11:39:05 +0000234
235#endif
236
Peter Collingbourneec1cb852013-08-28 23:16:49 +0000237_Unwind_Reason_Code _Unwind_Backtrace(_Unwind_Trace_Fn, void *);
238
239/* setjmp(3)/longjmp(3) stuff */
240typedef struct SjLj_Function_Context *_Unwind_FunctionContext_t;
241
242void _Unwind_SjLj_Register(_Unwind_FunctionContext_t);
243void _Unwind_SjLj_Unregister(_Unwind_FunctionContext_t);
244_Unwind_Reason_Code _Unwind_SjLj_RaiseException(struct _Unwind_Exception *);
Peter Collingbourne7ac84bd2013-08-28 23:32:22 +0000245_Unwind_Reason_Code _Unwind_SjLj_ForcedUnwind(struct _Unwind_Exception *,
246 _Unwind_Stop_Fn, void *);
Peter Collingbourneec1cb852013-08-28 23:16:49 +0000247void _Unwind_SjLj_Resume(struct _Unwind_Exception *);
248_Unwind_Reason_Code _Unwind_SjLj_Resume_or_Rethrow(struct _Unwind_Exception *);
249
250void *_Unwind_FindEnclosingFunction(void *);
251
252#ifdef __APPLE__
253
Peter Collingbourne7ac84bd2013-08-28 23:32:22 +0000254_Unwind_Ptr _Unwind_GetDataRelBase(struct _Unwind_Context *)
David Majnemer1cf22e62015-02-04 00:26:10 +0000255 __attribute__((__unavailable__));
Peter Collingbourne7ac84bd2013-08-28 23:32:22 +0000256_Unwind_Ptr _Unwind_GetTextRelBase(struct _Unwind_Context *)
David Majnemer1cf22e62015-02-04 00:26:10 +0000257 __attribute__((__unavailable__));
Peter Collingbourneec1cb852013-08-28 23:16:49 +0000258
259/* Darwin-specific functions */
260void __register_frame(const void *);
261void __deregister_frame(const void *);
262
263struct dwarf_eh_bases {
264 uintptr_t tbase;
265 uintptr_t dbase;
266 uintptr_t func;
267};
268void *_Unwind_Find_FDE(const void *, struct dwarf_eh_bases *);
269
270void __register_frame_info_bases(const void *, void *, void *, void *)
David Majnemer1cf22e62015-02-04 00:26:10 +0000271 __attribute__((__unavailable__));
272void __register_frame_info(const void *, void *) __attribute__((__unavailable__));
Peter Collingbourneec1cb852013-08-28 23:16:49 +0000273void __register_frame_info_table_bases(const void *, void*, void *, void *)
David Majnemer1cf22e62015-02-04 00:26:10 +0000274 __attribute__((__unavailable__));
Peter Collingbourne7ac84bd2013-08-28 23:32:22 +0000275void __register_frame_info_table(const void *, void *)
David Majnemer1cf22e62015-02-04 00:26:10 +0000276 __attribute__((__unavailable__));
277void __register_frame_table(const void *) __attribute__((__unavailable__));
278void __deregister_frame_info(const void *) __attribute__((__unavailable__));
279void __deregister_frame_info_bases(const void *)__attribute__((__unavailable__));
Peter Collingbourneec1cb852013-08-28 23:16:49 +0000280
281#else
282
283_Unwind_Ptr _Unwind_GetDataRelBase(struct _Unwind_Context *);
284_Unwind_Ptr _Unwind_GetTextRelBase(struct _Unwind_Context *);
285
286#endif
287
Rafael Espindola18c79202011-12-08 05:01:39 +0000288
Benjamin Kramer69665142013-01-09 19:54:57 +0000289#ifndef HIDE_EXPORTS
Rafael Espindola7a284b22011-12-09 00:08:01 +0000290#pragma GCC visibility pop
Benjamin Kramer69665142013-01-09 19:54:57 +0000291#endif
Rafael Espindola7a284b22011-12-09 00:08:01 +0000292
Rafael Espindola18c79202011-12-08 05:01:39 +0000293#ifdef __cplusplus
294}
295#endif
296
297#endif
Benjamin Kramer69665142013-01-09 19:54:57 +0000298
299#endif /* __CLANG_UNWIND_H */