1 /*===---- unwind.h - Stack unwinding ----------------------------------------===
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:
10 * The above copyright notice and this permission notice shall be included in
11 * all copies or substantial portions of the Software.
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
21 *===-----------------------------------------------------------------------===
24 /* See "Data Definitions for libgcc_s" in the Linux Standard Base.*/
26 #ifndef __CLANG_UNWIND_H
27 #define __CLANG_UNWIND_H
29 #if defined(__APPLE__) && __has_include_next(<unwind.h>)
30 /* Darwin (from 11.x on) provide an unwind.h. If that's available,
31 * use it. libunwind wraps some of its definitions in #ifdef _GNU_SOURCE,
32 * so define that around the include.*/
34 # define _SHOULD_UNDEFINE_GNU_SOURCE
37 // 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:
44 # include_next <unwind.h>
46 # pragma GCC visibility push(default)
47 # include_next <unwind.h>
48 # pragma GCC visibility pop
50 # ifdef _SHOULD_UNDEFINE_GNU_SOURCE
52 # undef _SHOULD_UNDEFINE_GNU_SOURCE
62 /* 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
66 #pragma GCC visibility push(default)
69 typedef uintptr_t _Unwind_Word
;
70 typedef intptr_t _Unwind_Sword
;
71 typedef uintptr_t _Unwind_Ptr
;
72 typedef uintptr_t _Unwind_Internal_Ptr
;
73 typedef uint64_t _Unwind_Exception_Class
;
75 typedef intptr_t _sleb128_t
;
76 typedef uintptr_t _uleb128_t
;
78 struct _Unwind_Context
;
79 struct _Unwind_Exception
;
82 #if defined(__arm__) && !defined(__USING_SJLJ_EXCEPTIONS__) && \
83 !defined(__ARM_DWARF_EH__)
84 _URC_OK
= 0, /* used by ARM EHABI */
86 _URC_FOREIGN_EXCEPTION_CAUGHT
= 1,
88 _URC_FATAL_PHASE2_ERROR
= 2,
89 _URC_FATAL_PHASE1_ERROR
= 3,
92 _URC_END_OF_STACK
= 5,
93 _URC_HANDLER_FOUND
= 6,
94 _URC_INSTALL_CONTEXT
= 7,
95 _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 */
100 } _Unwind_Reason_Code
;
103 _UA_SEARCH_PHASE
= 1,
104 _UA_CLEANUP_PHASE
= 2,
106 _UA_HANDLER_FRAME
= 4,
107 _UA_FORCE_UNWIND
= 8,
108 _UA_END_OF_STACK
= 16 /* gcc extension to C++ ABI */
111 typedef void (*_Unwind_Exception_Cleanup_Fn
)(_Unwind_Reason_Code
,
112 struct _Unwind_Exception
*);
114 struct _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__
));
124 typedef _Unwind_Reason_Code (*_Unwind_Stop_Fn
)(int, _Unwind_Action
,
125 _Unwind_Exception_Class
,
126 struct _Unwind_Exception
*,
127 struct _Unwind_Context
*,
130 typedef _Unwind_Reason_Code (*_Unwind_Personality_Fn
)(
131 int, _Unwind_Action
, _Unwind_Exception_Class
, struct _Unwind_Exception
*,
132 struct _Unwind_Context
*);
133 typedef _Unwind_Personality_Fn __personality_routine
;
135 typedef _Unwind_Reason_Code (*_Unwind_Trace_Fn
)(struct _Unwind_Context
*,
138 #if defined(__arm__) && !defined(__APPLE__)
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
;
153 } _Unwind_VRS_DataRepresentation
;
157 _UVRSR_NOT_IMPLEMENTED
= 1,
159 } _Unwind_VRS_Result
;
161 #if !defined(__USING_SJLJ_EXCEPTIONS__) && !defined(__ARM_DWARF_EH__)
162 typedef 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)
170 _Unwind_VRS_Result
_Unwind_VRS_Get(struct _Unwind_Context
*__context
,
171 _Unwind_VRS_RegClass __regclass
,
173 _Unwind_VRS_DataRepresentation __representation
,
176 _Unwind_VRS_Result
_Unwind_VRS_Set(struct _Unwind_Context
*__context
,
177 _Unwind_VRS_RegClass __regclass
,
179 _Unwind_VRS_DataRepresentation __representation
,
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
);
190 void _Unwind_SetGR(struct _Unwind_Context
*__context
, int __index
,
191 _Unwind_Word __value
) {
192 _Unwind_VRS_Set(__context
, _UVRSC_CORE
, __index
, _UVRSD_UINT32
, &__value
);
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. */
202 void _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
);
207 _Unwind_Word
_Unwind_GetGR(struct _Unwind_Context
*, int);
208 void _Unwind_SetGR(struct _Unwind_Context
*, int, _Unwind_Word
);
210 _Unwind_Word
_Unwind_GetIP(struct _Unwind_Context
*);
211 void _Unwind_SetIP(struct _Unwind_Context
*, _Unwind_Word
);
215 _Unwind_Word
_Unwind_GetIPInfo(struct _Unwind_Context
*, int *);
217 _Unwind_Word
_Unwind_GetCFA(struct _Unwind_Context
*);
219 _Unwind_Word
_Unwind_GetBSP(struct _Unwind_Context
*);
221 void *_Unwind_GetLanguageSpecificData(struct _Unwind_Context
*);
223 _Unwind_Ptr
_Unwind_GetRegionStart(struct _Unwind_Context
*);
225 /* DWARF EH functions; currently not available on Darwin/ARM */
226 #if !defined(__APPLE__) || !defined(__arm__)
228 _Unwind_Reason_Code
_Unwind_RaiseException(struct _Unwind_Exception
*);
229 _Unwind_Reason_Code
_Unwind_ForcedUnwind(struct _Unwind_Exception
*,
230 _Unwind_Stop_Fn
, void *);
231 void _Unwind_DeleteException(struct _Unwind_Exception
*);
232 void _Unwind_Resume(struct _Unwind_Exception
*);
233 _Unwind_Reason_Code
_Unwind_Resume_or_Rethrow(struct _Unwind_Exception
*);
237 _Unwind_Reason_Code
_Unwind_Backtrace(_Unwind_Trace_Fn
, void *);
239 /* setjmp(3)/longjmp(3) stuff */
240 typedef struct SjLj_Function_Context
*_Unwind_FunctionContext_t
;
242 void _Unwind_SjLj_Register(_Unwind_FunctionContext_t
);
243 void _Unwind_SjLj_Unregister(_Unwind_FunctionContext_t
);
244 _Unwind_Reason_Code
_Unwind_SjLj_RaiseException(struct _Unwind_Exception
*);
245 _Unwind_Reason_Code
_Unwind_SjLj_ForcedUnwind(struct _Unwind_Exception
*,
246 _Unwind_Stop_Fn
, void *);
247 void _Unwind_SjLj_Resume(struct _Unwind_Exception
*);
248 _Unwind_Reason_Code
_Unwind_SjLj_Resume_or_Rethrow(struct _Unwind_Exception
*);
250 void *_Unwind_FindEnclosingFunction(void *);
254 _Unwind_Ptr
_Unwind_GetDataRelBase(struct _Unwind_Context
*)
255 __attribute__((__unavailable__
));
256 _Unwind_Ptr
_Unwind_GetTextRelBase(struct _Unwind_Context
*)
257 __attribute__((__unavailable__
));
259 /* Darwin-specific functions */
260 void __register_frame(const void *);
261 void __deregister_frame(const void *);
263 struct dwarf_eh_bases
{
268 void *_Unwind_Find_FDE(const void *, struct dwarf_eh_bases
*);
270 void __register_frame_info_bases(const void *, void *, void *, void *)
271 __attribute__((__unavailable__
));
272 void __register_frame_info(const void *, void *) __attribute__((__unavailable__
));
273 void __register_frame_info_table_bases(const void *, void*, void *, void *)
274 __attribute__((__unavailable__
));
275 void __register_frame_info_table(const void *, void *)
276 __attribute__((__unavailable__
));
277 void __register_frame_table(const void *) __attribute__((__unavailable__
));
278 void __deregister_frame_info(const void *) __attribute__((__unavailable__
));
279 void __deregister_frame_info_bases(const void *)__attribute__((__unavailable__
));
283 _Unwind_Ptr
_Unwind_GetDataRelBase(struct _Unwind_Context
*);
284 _Unwind_Ptr
_Unwind_GetTextRelBase(struct _Unwind_Context
*);
290 #pragma GCC visibility pop
299 #endif /* __CLANG_UNWIND_H */