1 /*===---- unwind.h - Stack unwinding ----------------------------------------===
3 * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 * See https://llvm.org/LICENSE.txt for license information.
5 * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 *===-----------------------------------------------------------------------===
10 /* See "Data Definitions for libgcc_s" in the Linux Standard Base.*/
12 #ifndef __CLANG_UNWIND_H
13 #define __CLANG_UNWIND_H
15 #if defined(__APPLE__) && __has_include_next(<unwind.h>)
16 /* Darwin (from 11.x on) provide an unwind.h. If that's available,
17 * use it. libunwind wraps some of its definitions in #ifdef _GNU_SOURCE,
18 * so define that around the include.*/
20 # define _SHOULD_UNDEFINE_GNU_SOURCE
23 // libunwind's unwind.h reflects the current visibility. However, Mozilla
24 // builds with -fvisibility=hidden and relies on gcc's unwind.h to reset the
25 // visibility to default and export its contents. gcc also allows users to
26 // override its override by #defining HIDE_EXPORTS (but note, this only obeys
27 // the user's -fvisibility setting; it doesn't hide any exports on its own). We
28 // imitate gcc's header here:
30 # include_next <unwind.h>
32 # pragma GCC visibility push(default)
33 # include_next <unwind.h>
34 # pragma GCC visibility pop
36 # ifdef _SHOULD_UNDEFINE_GNU_SOURCE
38 # undef _SHOULD_UNDEFINE_GNU_SOURCE
48 /* It is a bit strange for a header to play with the visibility of the
49 symbols it declares, but this matches gcc's behavior and some programs
52 #pragma GCC visibility push(default)
55 typedef uintptr_t _Unwind_Word __attribute__((__mode__(__unwind_word__)));
56 typedef intptr_t _Unwind_Sword __attribute__((__mode__(__unwind_word__)));
57 typedef uintptr_t _Unwind_Ptr;
58 typedef uintptr_t _Unwind_Internal_Ptr;
59 typedef uint64_t _Unwind_Exception_Class;
61 typedef intptr_t _sleb128_t;
62 typedef uintptr_t _uleb128_t;
64 struct _Unwind_Context;
65 #if defined(__arm__) && !(defined(__USING_SJLJ_EXCEPTIONS__) || defined(__ARM_DWARF_EH__))
66 struct _Unwind_Control_Block;
67 typedef struct _Unwind_Control_Block _Unwind_Exception; /* Alias */
69 struct _Unwind_Exception;
70 typedef struct _Unwind_Exception _Unwind_Exception;
74 #if defined(__arm__) && !defined(__USING_SJLJ_EXCEPTIONS__) && \
75 !defined(__ARM_DWARF_EH__)
76 _URC_OK = 0, /* used by ARM EHABI */
78 _URC_FOREIGN_EXCEPTION_CAUGHT = 1,
80 _URC_FATAL_PHASE2_ERROR = 2,
81 _URC_FATAL_PHASE1_ERROR = 3,
84 _URC_END_OF_STACK = 5,
85 _URC_HANDLER_FOUND = 6,
86 _URC_INSTALL_CONTEXT = 7,
87 _URC_CONTINUE_UNWIND = 8,
88 #if defined(__arm__) && !defined(__USING_SJLJ_EXCEPTIONS__) && \
89 !defined(__ARM_DWARF_EH__)
90 _URC_FAILURE = 9 /* used by ARM EHABI */
92 } _Unwind_Reason_Code;
96 _UA_CLEANUP_PHASE = 2,
98 _UA_HANDLER_FRAME = 4,
100 _UA_END_OF_STACK = 16 /* gcc extension to C++ ABI */
103 typedef void (*_Unwind_Exception_Cleanup_Fn)(_Unwind_Reason_Code,
104 _Unwind_Exception *);
106 #if defined(__arm__) && !(defined(__USING_SJLJ_EXCEPTIONS__) || defined(__ARM_DWARF_EH__))
107 typedef struct _Unwind_Control_Block _Unwind_Control_Block;
108 typedef uint32_t _Unwind_EHT_Header;
110 struct _Unwind_Control_Block {
111 uint64_t exception_class;
112 void (*exception_cleanup)(_Unwind_Reason_Code, _Unwind_Control_Block *);
113 /* unwinder cache (private fields for the unwinder's use) */
115 uint32_t reserved1; /* forced unwind stop function, 0 if not forced */
116 uint32_t reserved2; /* personality routine */
117 uint32_t reserved3; /* callsite */
118 uint32_t reserved4; /* forced unwind stop argument */
121 /* propagation barrier cache (valid after phase 1) */
124 uint32_t bitpattern[5];
126 /* cleanup cache (preserved over cleanup) */
128 uint32_t bitpattern[4];
130 /* personality cache (for personality's benefit) */
132 uint32_t fnstart; /* function start address */
133 _Unwind_EHT_Header *ehtp; /* pointer to EHT entry header word */
134 uint32_t additional; /* additional data */
137 long long int : 0; /* force alignment of next item to 8-byte boundary */
138 } __attribute__((__aligned__(8)));
140 struct _Unwind_Exception {
141 _Unwind_Exception_Class exception_class;
142 _Unwind_Exception_Cleanup_Fn exception_cleanup;
143 #if !defined (__USING_SJLJ_EXCEPTIONS__) && defined (__SEH__)
144 _Unwind_Word private_[6];
146 _Unwind_Word private_1;
147 _Unwind_Word private_2;
149 /* The Itanium ABI requires that _Unwind_Exception objects are "double-word
150 * aligned". GCC has interpreted this to mean "use the maximum useful
151 * alignment for the target"; so do we. */
152 } __attribute__((__aligned__));
155 typedef _Unwind_Reason_Code (*_Unwind_Stop_Fn)(int, _Unwind_Action,
156 _Unwind_Exception_Class,
158 struct _Unwind_Context *,
161 typedef _Unwind_Reason_Code (*_Unwind_Personality_Fn)(int, _Unwind_Action,
162 _Unwind_Exception_Class,
164 struct _Unwind_Context *);
165 typedef _Unwind_Personality_Fn __personality_routine;
167 typedef _Unwind_Reason_Code (*_Unwind_Trace_Fn)(struct _Unwind_Context *,
170 #if defined(__arm__) && !(defined(__USING_SJLJ_EXCEPTIONS__) || defined(__ARM_DWARF_EH__))
172 _UVRSC_CORE = 0, /* integer register */
173 _UVRSC_VFP = 1, /* vfp */
174 _UVRSC_WMMXD = 3, /* Intel WMMX data register */
175 _UVRSC_WMMXC = 4 /* Intel WMMX control register */
176 } _Unwind_VRS_RegClass;
184 } _Unwind_VRS_DataRepresentation;
188 _UVRSR_NOT_IMPLEMENTED = 1,
190 } _Unwind_VRS_Result;
192 typedef uint32_t _Unwind_State;
193 #define _US_VIRTUAL_UNWIND_FRAME ((_Unwind_State)0)
194 #define _US_UNWIND_FRAME_STARTING ((_Unwind_State)1)
195 #define _US_UNWIND_FRAME_RESUME ((_Unwind_State)2)
196 #define _US_ACTION_MASK ((_Unwind_State)3)
197 #define _US_FORCE_UNWIND ((_Unwind_State)8)
199 _Unwind_VRS_Result _Unwind_VRS_Get(struct _Unwind_Context *__context,
200 _Unwind_VRS_RegClass __regclass,
202 _Unwind_VRS_DataRepresentation __representation,
205 _Unwind_VRS_Result _Unwind_VRS_Set(struct _Unwind_Context *__context,
206 _Unwind_VRS_RegClass __regclass,
208 _Unwind_VRS_DataRepresentation __representation,
212 _Unwind_Word _Unwind_GetGR(struct _Unwind_Context *__context, int __index) {
213 _Unwind_Word __value;
214 _Unwind_VRS_Get(__context, _UVRSC_CORE, __index, _UVRSD_UINT32, &__value);
219 void _Unwind_SetGR(struct _Unwind_Context *__context, int __index,
220 _Unwind_Word __value) {
221 _Unwind_VRS_Set(__context, _UVRSC_CORE, __index, _UVRSD_UINT32, &__value);
225 _Unwind_Word _Unwind_GetIP(struct _Unwind_Context *__context) {
226 _Unwind_Word __ip = _Unwind_GetGR(__context, 15);
227 return __ip & ~(_Unwind_Word)(0x1); /* Remove thumb mode bit. */
231 void _Unwind_SetIP(struct _Unwind_Context *__context, _Unwind_Word __value) {
232 _Unwind_Word __thumb_mode_bit = _Unwind_GetGR(__context, 15) & 0x1;
233 _Unwind_SetGR(__context, 15, __value | __thumb_mode_bit);
236 _Unwind_Word _Unwind_GetGR(struct _Unwind_Context *, int);
237 void _Unwind_SetGR(struct _Unwind_Context *, int, _Unwind_Word);
239 _Unwind_Word _Unwind_GetIP(struct _Unwind_Context *);
240 void _Unwind_SetIP(struct _Unwind_Context *, _Unwind_Word);
244 _Unwind_Word _Unwind_GetIPInfo(struct _Unwind_Context *, int *);
246 _Unwind_Word _Unwind_GetCFA(struct _Unwind_Context *);
248 _Unwind_Word _Unwind_GetBSP(struct _Unwind_Context *);
250 void *_Unwind_GetLanguageSpecificData(struct _Unwind_Context *);
252 _Unwind_Ptr _Unwind_GetRegionStart(struct _Unwind_Context *);
254 /* DWARF EH functions; currently not available on Darwin/ARM */
255 #if !defined(__APPLE__) || !defined(__arm__)
256 _Unwind_Reason_Code _Unwind_RaiseException(_Unwind_Exception *);
257 _Unwind_Reason_Code _Unwind_ForcedUnwind(_Unwind_Exception *, _Unwind_Stop_Fn,
259 void _Unwind_DeleteException(_Unwind_Exception *);
260 void _Unwind_Resume(_Unwind_Exception *);
261 _Unwind_Reason_Code _Unwind_Resume_or_Rethrow(_Unwind_Exception *);
265 _Unwind_Reason_Code _Unwind_Backtrace(_Unwind_Trace_Fn, void *);
267 /* setjmp(3)/longjmp(3) stuff */
268 typedef struct SjLj_Function_Context *_Unwind_FunctionContext_t;
270 void _Unwind_SjLj_Register(_Unwind_FunctionContext_t);
271 void _Unwind_SjLj_Unregister(_Unwind_FunctionContext_t);
272 _Unwind_Reason_Code _Unwind_SjLj_RaiseException(_Unwind_Exception *);
273 _Unwind_Reason_Code _Unwind_SjLj_ForcedUnwind(_Unwind_Exception *,
274 _Unwind_Stop_Fn, void *);
275 void _Unwind_SjLj_Resume(_Unwind_Exception *);
276 _Unwind_Reason_Code _Unwind_SjLj_Resume_or_Rethrow(_Unwind_Exception *);
278 void *_Unwind_FindEnclosingFunction(void *);
282 _Unwind_Ptr _Unwind_GetDataRelBase(struct _Unwind_Context *)
283 __attribute__((__unavailable__));
284 _Unwind_Ptr _Unwind_GetTextRelBase(struct _Unwind_Context *)
285 __attribute__((__unavailable__));
287 /* Darwin-specific functions */
288 void __register_frame(const void *);
289 void __deregister_frame(const void *);
291 struct dwarf_eh_bases {
296 void *_Unwind_Find_FDE(const void *, struct dwarf_eh_bases *);
298 void __register_frame_info_bases(const void *, void *, void *, void *)
299 __attribute__((__unavailable__));
300 void __register_frame_info(const void *, void *) __attribute__((__unavailable__));
301 void __register_frame_info_table_bases(const void *, void*, void *, void *)
302 __attribute__((__unavailable__));
303 void __register_frame_info_table(const void *, void *)
304 __attribute__((__unavailable__));
305 void __register_frame_table(const void *) __attribute__((__unavailable__));
306 void __deregister_frame_info(const void *) __attribute__((__unavailable__));
307 void __deregister_frame_info_bases(const void *)__attribute__((__unavailable__));
311 _Unwind_Ptr _Unwind_GetDataRelBase(struct _Unwind_Context *);
312 _Unwind_Ptr _Unwind_GetTextRelBase(struct _Unwind_Context *);
318 #pragma GCC visibility pop
327 #endif /* __CLANG_UNWIND_H */