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