clang  15.0.0git
unwind.h
Go to the documentation of this file.
1 /*===---- unwind.h - Stack unwinding ----------------------------------------===
2  *
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
6  *
7  *===-----------------------------------------------------------------------===
8  */
9 
10 /* See "Data Definitions for libgcc_s" in the Linux Standard Base.*/
11 
12 #ifndef __CLANG_UNWIND_H
13 #define __CLANG_UNWIND_H
14 
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.*/
19 # ifndef _GNU_SOURCE
20 # define _SHOULD_UNDEFINE_GNU_SOURCE
21 # define _GNU_SOURCE
22 # endif
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:
29 # ifdef HIDE_EXPORTS
30 # include_next <unwind.h>
31 # else
32 # pragma GCC visibility push(default)
33 # include_next <unwind.h>
34 # pragma GCC visibility pop
35 # endif
36 # ifdef _SHOULD_UNDEFINE_GNU_SOURCE
37 # undef _GNU_SOURCE
38 # undef _SHOULD_UNDEFINE_GNU_SOURCE
39 # endif
40 #else
41 
42 #include <stdint.h>
43 
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47 
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
50  depend on it */
51 #ifndef HIDE_EXPORTS
52 #pragma GCC visibility push(default)
53 #endif
54 
55 typedef uintptr_t _Unwind_Word __attribute__((__mode__(__unwind_word__)));
56 typedef intptr_t _Unwind_Sword __attribute__((__mode__(__unwind_word__)));
60 
63 
64 struct _Unwind_Context;
65 #if defined(__arm__) && !(defined(__USING_SJLJ_EXCEPTIONS__) || \
66  defined(__ARM_DWARF_EH__) || defined(__SEH__))
67 struct _Unwind_Control_Block;
68 typedef struct _Unwind_Control_Block _Unwind_Exception; /* Alias */
69 #else
70 struct _Unwind_Exception;
72 #endif
73 typedef enum {
75 #if defined(__arm__) && !defined(__USING_SJLJ_EXCEPTIONS__) && \
76  !defined(__ARM_DWARF_EH__) && !defined(__SEH__)
77  _URC_OK = 0, /* used by ARM EHABI */
78 #endif
80 
84 
89 #if defined(__arm__) && !defined(__USING_SJLJ_EXCEPTIONS__) && \
90  !defined(__ARM_DWARF_EH__) && !defined(__SEH__)
91  _URC_FAILURE = 9 /* used by ARM EHABI */
92 #endif
94 
95 typedef enum {
98 
101  _UA_END_OF_STACK = 16 /* gcc extension to C++ ABI */
103 
106 
107 #if defined(__arm__) && !(defined(__USING_SJLJ_EXCEPTIONS__) || \
108  defined(__ARM_DWARF_EH__) || defined(__SEH__))
109 typedef struct _Unwind_Control_Block _Unwind_Control_Block;
110 typedef uint32_t _Unwind_EHT_Header;
111 
112 struct _Unwind_Control_Block {
114  void (*exception_cleanup)(_Unwind_Reason_Code, _Unwind_Control_Block *);
115  /* unwinder cache (private fields for the unwinder's use) */
116  struct {
117  uint32_t reserved1; /* forced unwind stop function, 0 if not forced */
118  uint32_t reserved2; /* personality routine */
119  uint32_t reserved3; /* callsite */
120  uint32_t reserved4; /* forced unwind stop argument */
121  uint32_t reserved5;
122  } unwinder_cache;
123  /* propagation barrier cache (valid after phase 1) */
124  struct {
125  uint32_t sp;
126  uint32_t bitpattern[5];
127  } barrier_cache;
128  /* cleanup cache (preserved over cleanup) */
129  struct {
130  uint32_t bitpattern[4];
131  } cleanup_cache;
132  /* personality cache (for personality's benefit) */
133  struct {
134  uint32_t fnstart; /* function start address */
135  _Unwind_EHT_Header *ehtp; /* pointer to EHT entry header word */
136  uint32_t additional; /* additional data */
137  uint32_t reserved1;
138  } pr_cache;
139  long long int : 0; /* force alignment of next item to 8-byte boundary */
140 } __attribute__((__aligned__(8)));
141 #else
145 #if !defined (__USING_SJLJ_EXCEPTIONS__) && defined (__SEH__)
146  _Unwind_Word private_[6];
147 #else
148  _Unwind_Word private_1;
149  _Unwind_Word private_2;
150 #endif
151  /* The Itanium ABI requires that _Unwind_Exception objects are "double-word
152  * aligned". GCC has interpreted this to mean "use the maximum useful
153  * alignment for the target"; so do we. */
154 } __attribute__((__aligned__));
155 #endif
156 
160  struct _Unwind_Context *,
161  void *);
162 
166  struct _Unwind_Context *);
168 
169 typedef _Unwind_Reason_Code (*_Unwind_Trace_Fn)(struct _Unwind_Context *,
170  void *);
171 
172 #if defined(__arm__) && !(defined(__USING_SJLJ_EXCEPTIONS__) || \
173  defined(__ARM_DWARF_EH__) || defined(__SEH__))
174 typedef enum {
175  _UVRSC_CORE = 0, /* integer register */
176  _UVRSC_VFP = 1, /* vfp */
177  _UVRSC_WMMXD = 3, /* Intel WMMX data register */
178  _UVRSC_WMMXC = 4, /* Intel WMMX control register */
179  _UVRSC_PSEUDO = 5 /* Special purpose pseudo register */
180 } _Unwind_VRS_RegClass;
181 
182 typedef enum {
183  _UVRSD_UINT32 = 0,
184  _UVRSD_VFPX = 1,
185  _UVRSD_UINT64 = 3,
186  _UVRSD_FLOAT = 4,
187  _UVRSD_DOUBLE = 5
188 } _Unwind_VRS_DataRepresentation;
189 
190 typedef enum {
191  _UVRSR_OK = 0,
192  _UVRSR_NOT_IMPLEMENTED = 1,
193  _UVRSR_FAILED = 2
194 } _Unwind_VRS_Result;
195 
196 typedef uint32_t _Unwind_State;
197 #define _US_VIRTUAL_UNWIND_FRAME ((_Unwind_State)0)
198 #define _US_UNWIND_FRAME_STARTING ((_Unwind_State)1)
199 #define _US_UNWIND_FRAME_RESUME ((_Unwind_State)2)
200 #define _US_ACTION_MASK ((_Unwind_State)3)
201 #define _US_FORCE_UNWIND ((_Unwind_State)8)
202 
203 _Unwind_VRS_Result _Unwind_VRS_Get(struct _Unwind_Context *__context,
204  _Unwind_VRS_RegClass __regclass,
205  uint32_t __regno,
206  _Unwind_VRS_DataRepresentation __representation,
207  void *__valuep);
208 
209 _Unwind_VRS_Result _Unwind_VRS_Set(struct _Unwind_Context *__context,
210  _Unwind_VRS_RegClass __regclass,
211  uint32_t __regno,
212  _Unwind_VRS_DataRepresentation __representation,
213  void *__valuep);
214 
215 static __inline__
216 _Unwind_Word _Unwind_GetGR(struct _Unwind_Context *__context, int __index) {
217  _Unwind_Word __value;
218  _Unwind_VRS_Get(__context, _UVRSC_CORE, __index, _UVRSD_UINT32, &__value);
219  return __value;
220 }
221 
222 static __inline__
223 void _Unwind_SetGR(struct _Unwind_Context *__context, int __index,
224  _Unwind_Word __value) {
225  _Unwind_VRS_Set(__context, _UVRSC_CORE, __index, _UVRSD_UINT32, &__value);
226 }
227 
228 static __inline__
229 _Unwind_Word _Unwind_GetIP(struct _Unwind_Context *__context) {
230  _Unwind_Word __ip = _Unwind_GetGR(__context, 15);
231  return __ip & ~(_Unwind_Word)(0x1); /* Remove thumb mode bit. */
232 }
233 
234 static __inline__
235 void _Unwind_SetIP(struct _Unwind_Context *__context, _Unwind_Word __value) {
236  _Unwind_Word __thumb_mode_bit = _Unwind_GetGR(__context, 15) & 0x1;
237  _Unwind_SetGR(__context, 15, __value | __thumb_mode_bit);
238 }
239 #else
240 _Unwind_Word _Unwind_GetGR(struct _Unwind_Context *, int);
241 void _Unwind_SetGR(struct _Unwind_Context *, int, _Unwind_Word);
242 
243 _Unwind_Word _Unwind_GetIP(struct _Unwind_Context *);
244 void _Unwind_SetIP(struct _Unwind_Context *, _Unwind_Word);
245 #endif
246 
247 
248 _Unwind_Word _Unwind_GetIPInfo(struct _Unwind_Context *, int *);
249 
250 _Unwind_Word _Unwind_GetCFA(struct _Unwind_Context *);
251 
252 _Unwind_Word _Unwind_GetBSP(struct _Unwind_Context *);
253 
254 void *_Unwind_GetLanguageSpecificData(struct _Unwind_Context *);
255 
256 _Unwind_Ptr _Unwind_GetRegionStart(struct _Unwind_Context *);
257 
258 /* DWARF EH functions; currently not available on Darwin/ARM */
259 #if !defined(__APPLE__) || !defined(__arm__)
262  void *);
266 
267 #endif
268 
270 
271 /* setjmp(3)/longjmp(3) stuff */
272 typedef struct SjLj_Function_Context *_Unwind_FunctionContext_t;
273 
278  _Unwind_Stop_Fn, void *);
281 
282 void *_Unwind_FindEnclosingFunction(void *);
283 
284 #ifdef __APPLE__
285 
286 _Unwind_Ptr _Unwind_GetDataRelBase(struct _Unwind_Context *)
287  __attribute__((__unavailable__));
288 _Unwind_Ptr _Unwind_GetTextRelBase(struct _Unwind_Context *)
289  __attribute__((__unavailable__));
290 
291 /* Darwin-specific functions */
292 void __register_frame(const void *);
293 void __deregister_frame(const void *);
294 
295 struct dwarf_eh_bases {
296  uintptr_t tbase;
297  uintptr_t dbase;
298  uintptr_t func;
299 };
300 void *_Unwind_Find_FDE(const void *, struct dwarf_eh_bases *);
301 
302 void __register_frame_info_bases(const void *, void *, void *, void *)
303  __attribute__((__unavailable__));
304 void __register_frame_info(const void *, void *) __attribute__((__unavailable__));
305 void __register_frame_info_table_bases(const void *, void*, void *, void *)
306  __attribute__((__unavailable__));
307 void __register_frame_info_table(const void *, void *)
308  __attribute__((__unavailable__));
309 void __register_frame_table(const void *) __attribute__((__unavailable__));
310 void __deregister_frame_info(const void *) __attribute__((__unavailable__));
311 void __deregister_frame_info_bases(const void *)__attribute__((__unavailable__));
312 
313 #else
314 
315 _Unwind_Ptr _Unwind_GetDataRelBase(struct _Unwind_Context *);
316 _Unwind_Ptr _Unwind_GetTextRelBase(struct _Unwind_Context *);
317 
318 #endif
319 
320 
321 #ifndef HIDE_EXPORTS
322 #pragma GCC visibility pop
323 #endif
324 
325 #ifdef __cplusplus
326 }
327 #endif
328 
329 #endif
330 
331 #endif /* __CLANG_UNWIND_H */
_Unwind_RaiseException
_Unwind_Reason_Code _Unwind_RaiseException(_Unwind_Exception *)
_Unwind_Exception_Cleanup_Fn
void(* _Unwind_Exception_Cleanup_Fn)(_Unwind_Reason_Code, _Unwind_Exception *)
Definition: unwind.h:104
__attribute__
uintptr_t _Unwind_Word __attribute__((__mode__(__unwind_word__)))
Definition: unwind.h:55
_UA_HANDLER_FRAME
@ _UA_HANDLER_FRAME
Definition: unwind.h:99
_URC_INSTALL_CONTEXT
@ _URC_INSTALL_CONTEXT
Definition: unwind.h:87
_UA_FORCE_UNWIND
@ _UA_FORCE_UNWIND
Definition: unwind.h:100
_uleb128_t
uintptr_t _uleb128_t
Definition: unwind.h:62
_UA_END_OF_STACK
@ _UA_END_OF_STACK
Definition: unwind.h:101
_Unwind_SetIP
void _Unwind_SetIP(struct _Unwind_Context *, _Unwind_Word)
int
__device__ int
Definition: __clang_hip_libdevice_declares.h:63
_Unwind_GetRegionStart
_Unwind_Ptr _Unwind_GetRegionStart(struct _Unwind_Context *)
_Unwind_FindEnclosingFunction
void * _Unwind_FindEnclosingFunction(void *)
_Unwind_Backtrace
_Unwind_Reason_Code _Unwind_Backtrace(_Unwind_Trace_Fn, void *)
_Unwind_Stop_Fn
_Unwind_Reason_Code(* _Unwind_Stop_Fn)(int, _Unwind_Action, _Unwind_Exception_Class, _Unwind_Exception *, struct _Unwind_Context *, void *)
Definition: unwind.h:157
_Unwind_Internal_Ptr
uintptr_t _Unwind_Internal_Ptr
Definition: unwind.h:58
exception_cleanup
_Unwind_Exception_Cleanup_Fn exception_cleanup
Definition: unwind.h:106
_Unwind_GetCFA
_Unwind_Word _Unwind_GetCFA(struct _Unwind_Context *)
uint64_t
unsigned long uint64_t
Definition: hlsl_basic_types.h:24
_sleb128_t
intptr_t _sleb128_t
Definition: unwind.h:61
_Unwind_GetTextRelBase
_Unwind_Ptr _Unwind_GetTextRelBase(struct _Unwind_Context *)
_Unwind_Trace_Fn
_Unwind_Reason_Code(* _Unwind_Trace_Fn)(struct _Unwind_Context *, void *)
Definition: unwind.h:169
_URC_NO_REASON
@ _URC_NO_REASON
Definition: unwind.h:74
_URC_FATAL_PHASE2_ERROR
@ _URC_FATAL_PHASE2_ERROR
Definition: unwind.h:81
_URC_END_OF_STACK
@ _URC_END_OF_STACK
Definition: unwind.h:85
intptr_t
__INTPTR_TYPE__ intptr_t
A signed integer type with the property that any valid pointer to void can be converted to this type,...
Definition: opencl-c-base.h:133
_UA_SEARCH_PHASE
@ _UA_SEARCH_PHASE
Definition: unwind.h:96
_URC_FOREIGN_EXCEPTION_CAUGHT
@ _URC_FOREIGN_EXCEPTION_CAUGHT
Definition: unwind.h:79
exception_class
_Unwind_Exception_Class exception_class
Definition: unwind.h:105
_Unwind_Exception::exception_cleanup
_Unwind_Exception_Cleanup_Fn exception_cleanup
Definition: unwind.h:144
_Unwind_GetGR
_Unwind_Word _Unwind_GetGR(struct _Unwind_Context *, int)
_Unwind_Resume_or_Rethrow
_Unwind_Reason_Code _Unwind_Resume_or_Rethrow(_Unwind_Exception *)
uintptr_t
__UINTPTR_TYPE__ uintptr_t
An unsigned integer type with the property that any valid pointer to void can be converted to this ty...
Definition: opencl-c-base.h:140
_Unwind_SetGR
void _Unwind_SetGR(struct _Unwind_Context *, int, _Unwind_Word)
_Unwind_Action
_Unwind_Action
Definition: unwind.h:95
_UA_CLEANUP_PHASE
@ _UA_CLEANUP_PHASE
Definition: unwind.h:97
_Unwind_GetIP
_Unwind_Word _Unwind_GetIP(struct _Unwind_Context *)
_URC_HANDLER_FOUND
@ _URC_HANDLER_FOUND
Definition: unwind.h:86
_Unwind_Exception_Class
uint64_t _Unwind_Exception_Class
Definition: unwind.h:59
_Unwind_Exception::private_2
_Unwind_Word private_2
Definition: unwind.h:149
_URC_NORMAL_STOP
@ _URC_NORMAL_STOP
Definition: unwind.h:83
_URC_FATAL_PHASE1_ERROR
@ _URC_FATAL_PHASE1_ERROR
Definition: unwind.h:82
_Unwind_SjLj_ForcedUnwind
_Unwind_Reason_Code _Unwind_SjLj_ForcedUnwind(_Unwind_Exception *, _Unwind_Stop_Fn, void *)
stdint.h
_Unwind_GetBSP
_Unwind_Word _Unwind_GetBSP(struct _Unwind_Context *)
_Unwind_DeleteException
void _Unwind_DeleteException(_Unwind_Exception *)
_Unwind_FunctionContext_t
struct SjLj_Function_Context * _Unwind_FunctionContext_t
Definition: unwind.h:272
_Unwind_Exception::private_1
_Unwind_Word private_1
Definition: unwind.h:148
_Unwind_SjLj_Register
void _Unwind_SjLj_Register(_Unwind_FunctionContext_t)
_Unwind_GetDataRelBase
_Unwind_Ptr _Unwind_GetDataRelBase(struct _Unwind_Context *)
_Unwind_SjLj_Resume_or_Rethrow
_Unwind_Reason_Code _Unwind_SjLj_Resume_or_Rethrow(_Unwind_Exception *)
_Unwind_ForcedUnwind
_Unwind_Reason_Code _Unwind_ForcedUnwind(_Unwind_Exception *, _Unwind_Stop_Fn, void *)
__value
static __inline__ void unsigned int __value
Definition: movdirintrin.h:20
_Unwind_GetIPInfo
_Unwind_Word _Unwind_GetIPInfo(struct _Unwind_Context *, int *)
_Unwind_Reason_Code
_Unwind_Reason_Code
Definition: unwind.h:73
_Unwind_SjLj_Unregister
void _Unwind_SjLj_Unregister(_Unwind_FunctionContext_t)
_URC_CONTINUE_UNWIND
@ _URC_CONTINUE_UNWIND
Definition: unwind.h:88
_Unwind_Ptr
uintptr_t _Unwind_Ptr
Definition: unwind.h:57
_Unwind_GetLanguageSpecificData
void * _Unwind_GetLanguageSpecificData(struct _Unwind_Context *)
_Unwind_Exception
Definition: unwind.h:142
_Unwind_Exception::exception_class
_Unwind_Exception_Class exception_class
Definition: unwind.h:143
_Unwind_Resume
void _Unwind_Resume(_Unwind_Exception *)
_Unwind_SjLj_RaiseException
_Unwind_Reason_Code _Unwind_SjLj_RaiseException(_Unwind_Exception *)
_Unwind_Personality_Fn
_Unwind_Reason_Code(* _Unwind_Personality_Fn)(int, _Unwind_Action, _Unwind_Exception_Class, _Unwind_Exception *, struct _Unwind_Context *)
Definition: unwind.h:163
__personality_routine
_Unwind_Personality_Fn __personality_routine
Definition: unwind.h:167
_Unwind_SjLj_Resume
void _Unwind_SjLj_Resume(_Unwind_Exception *)