blob: 86001bbb5633e625522a51eb4d3ebe8cfdaf89ea [file] [log] [blame]
Nick Kledzikb78da982013-10-07 21:39:41 +00001//===------------------------------- unwind.h -----------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
7//
8//
9// C++ ABI Level 1 ABI documented at:
10// http://mentorembedded.github.io/cxx-abi/abi-eh.html
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef __UNWIND_H__
15#define __UNWIND_H__
16
17#include <stdint.h>
18#include <stddef.h>
19
Saleem Abdulrasool839f7f22013-10-17 03:57:41 +000020#if defined(__APPLE__)
Nick Kledzik29180112013-11-01 00:32:26 +000021#define LIBUNWIND_UNAVAIL __attribute__ (( unavailable ))
Saleem Abdulrasool839f7f22013-10-17 03:57:41 +000022#else
Nick Kledzik29180112013-11-01 00:32:26 +000023#define LIBUNWIND_UNAVAIL
Saleem Abdulrasool839f7f22013-10-17 03:57:41 +000024#endif
25
Dan Albert0a1ce9c2015-03-04 17:08:25 -080026#include <__cxxabi_config.h>
Dan Alberte45805f2014-07-02 16:11:13 -070027
Nick Kledzikb78da982013-10-07 21:39:41 +000028typedef enum {
29 _URC_NO_REASON = 0,
Dan Alberte45805f2014-07-02 16:11:13 -070030 _URC_OK = 0,
Nick Kledzikb78da982013-10-07 21:39:41 +000031 _URC_FOREIGN_EXCEPTION_CAUGHT = 1,
32 _URC_FATAL_PHASE2_ERROR = 2,
33 _URC_FATAL_PHASE1_ERROR = 3,
34 _URC_NORMAL_STOP = 4,
35 _URC_END_OF_STACK = 5,
36 _URC_HANDLER_FOUND = 6,
37 _URC_INSTALL_CONTEXT = 7,
Dan Alberte45805f2014-07-02 16:11:13 -070038 _URC_CONTINUE_UNWIND = 8,
39#if LIBCXXABI_ARM_EHABI
40 _URC_FAILURE = 9
41#endif
Nick Kledzikb78da982013-10-07 21:39:41 +000042} _Unwind_Reason_Code;
43
44typedef enum {
45 _UA_SEARCH_PHASE = 1,
46 _UA_CLEANUP_PHASE = 2,
47 _UA_HANDLER_FRAME = 4,
48 _UA_FORCE_UNWIND = 8,
49 _UA_END_OF_STACK = 16 // gcc extension to C++ ABI
50} _Unwind_Action;
51
Dan Alberte45805f2014-07-02 16:11:13 -070052typedef struct _Unwind_Context _Unwind_Context; // opaque
53
54#if LIBCXXABI_ARM_EHABI
55typedef uint32_t _Unwind_State;
56
57static const _Unwind_State _US_VIRTUAL_UNWIND_FRAME = 0;
58static const _Unwind_State _US_UNWIND_FRAME_STARTING = 1;
59static const _Unwind_State _US_UNWIND_FRAME_RESUME = 2;
Dan Albert0a1ce9c2015-03-04 17:08:25 -080060/* Undocumented flag for force unwinding. */
61static const _Unwind_State _US_FORCE_UNWIND = 8;
Dan Alberte45805f2014-07-02 16:11:13 -070062
63typedef uint32_t _Unwind_EHT_Header;
64
65struct _Unwind_Control_Block;
66typedef struct _Unwind_Control_Block _Unwind_Control_Block;
67typedef struct _Unwind_Control_Block _Unwind_Exception; /* Alias */
68
69struct _Unwind_Control_Block {
70 uint64_t exception_class;
71 void (*exception_cleanup)(_Unwind_Reason_Code, _Unwind_Control_Block*);
72
73 /* Unwinder cache, private fields for the unwinder's use */
74 struct {
75 uint32_t reserved1; /* init reserved1 to 0, then don't touch */
76 uint32_t reserved2;
77 uint32_t reserved3;
78 uint32_t reserved4;
79 uint32_t reserved5;
80 } unwinder_cache;
81
82 /* Propagation barrier cache (valid after phase 1): */
83 struct {
84 uint32_t sp;
85 uint32_t bitpattern[5];
86 } barrier_cache;
87
88 /* Cleanup cache (preserved over cleanup): */
89 struct {
90 uint32_t bitpattern[4];
91 } cleanup_cache;
92
93 /* Pr cache (for pr's benefit): */
94 struct {
95 uint32_t fnstart; /* function start address */
96 _Unwind_EHT_Header* ehtp; /* pointer to EHT entry header word */
97 uint32_t additional;
98 uint32_t reserved1;
99 } pr_cache;
100
101 long long int :0; /* Enforce the 8-byte alignment */
102};
103
104typedef _Unwind_Reason_Code (*_Unwind_Stop_Fn)
105 (_Unwind_State state,
106 _Unwind_Exception* exceptionObject,
107 struct _Unwind_Context* context);
108
109typedef _Unwind_Reason_Code (*__personality_routine)
110 (_Unwind_State state,
111 _Unwind_Exception* exceptionObject,
112 struct _Unwind_Context* context);
113#else
Nick Kledzikb78da982013-10-07 21:39:41 +0000114struct _Unwind_Context; // opaque
115struct _Unwind_Exception; // forward declaration
Dan Alberte45805f2014-07-02 16:11:13 -0700116typedef struct _Unwind_Exception _Unwind_Exception;
Nick Kledzikb78da982013-10-07 21:39:41 +0000117
118struct _Unwind_Exception {
119 uint64_t exception_class;
120 void (*exception_cleanup)(_Unwind_Reason_Code reason,
Dan Alberte45805f2014-07-02 16:11:13 -0700121 _Unwind_Exception *exc);
Nick Kledzikb78da982013-10-07 21:39:41 +0000122 uintptr_t private_1; // non-zero means forced unwind
123 uintptr_t private_2; // holds sp that phase1 found for phase2 to use
Dan Albert0a1ce9c2015-03-04 17:08:25 -0800124#ifndef __LP64__
Nick Kledzikb78da982013-10-07 21:39:41 +0000125 // The gcc implementation of _Unwind_Exception used attribute mode on the
Dan Albert0a1ce9c2015-03-04 17:08:25 -0800126 // above fields which had the side effect of causing this whole struct to
127 // round up to 32 bytes in size. To be more explicit, we add pad fields
Nick Kledzikb78da982013-10-07 21:39:41 +0000128 // added for binary compatibility.
129 uint32_t reserved[3];
130#endif
131};
132
133typedef _Unwind_Reason_Code (*_Unwind_Stop_Fn)
134 (int version,
135 _Unwind_Action actions,
136 uint64_t exceptionClass,
Dan Alberte45805f2014-07-02 16:11:13 -0700137 _Unwind_Exception* exceptionObject,
Nick Kledzikb78da982013-10-07 21:39:41 +0000138 struct _Unwind_Context* context,
139 void* stop_parameter );
140
141typedef _Unwind_Reason_Code (*__personality_routine)
142 (int version,
143 _Unwind_Action actions,
144 uint64_t exceptionClass,
Dan Alberte45805f2014-07-02 16:11:13 -0700145 _Unwind_Exception* exceptionObject,
Nick Kledzikb78da982013-10-07 21:39:41 +0000146 struct _Unwind_Context* context);
Dan Alberte45805f2014-07-02 16:11:13 -0700147#endif
Nick Kledzikb78da982013-10-07 21:39:41 +0000148
149#ifdef __cplusplus
150extern "C" {
151#endif
152
153//
154// The following are the base functions documented by the C++ ABI
155//
Dan Albert0a1ce9c2015-03-04 17:08:25 -0800156#ifdef __USING_SJLJ_EXCEPTIONS__
Nick Kledzikb78da982013-10-07 21:39:41 +0000157extern _Unwind_Reason_Code
Dan Alberte45805f2014-07-02 16:11:13 -0700158 _Unwind_SjLj_RaiseException(_Unwind_Exception *exception_object);
159extern void _Unwind_SjLj_Resume(_Unwind_Exception *exception_object);
Nick Kledzikb78da982013-10-07 21:39:41 +0000160#else
161extern _Unwind_Reason_Code
Dan Alberte45805f2014-07-02 16:11:13 -0700162 _Unwind_RaiseException(_Unwind_Exception *exception_object);
163extern void _Unwind_Resume(_Unwind_Exception *exception_object);
Nick Kledzikb78da982013-10-07 21:39:41 +0000164#endif
Dan Alberte45805f2014-07-02 16:11:13 -0700165extern void _Unwind_DeleteException(_Unwind_Exception *exception_object);
166
167#if LIBCXXABI_ARM_EHABI
168typedef enum {
169 _UVRSC_CORE = 0, /* integer register */
170 _UVRSC_VFP = 1, /* vfp */
171 _UVRSC_WMMXD = 3, /* Intel WMMX data register */
172 _UVRSC_WMMXC = 4 /* Intel WMMX control register */
173} _Unwind_VRS_RegClass;
174
175typedef enum {
176 _UVRSD_UINT32 = 0,
177 _UVRSD_VFPX = 1,
178 _UVRSD_UINT64 = 3,
179 _UVRSD_FLOAT = 4,
180 _UVRSD_DOUBLE = 5
181} _Unwind_VRS_DataRepresentation;
182
183typedef enum {
184 _UVRSR_OK = 0,
185 _UVRSR_NOT_IMPLEMENTED = 1,
186 _UVRSR_FAILED = 2
187} _Unwind_VRS_Result;
188
189extern void _Unwind_Complete(_Unwind_Exception* exception_object);
190
191extern _Unwind_VRS_Result
192_Unwind_VRS_Get(_Unwind_Context *context, _Unwind_VRS_RegClass regclass,
193 uint32_t regno, _Unwind_VRS_DataRepresentation representation,
194 void *valuep);
195
196extern _Unwind_VRS_Result
197_Unwind_VRS_Set(_Unwind_Context *context, _Unwind_VRS_RegClass regclass,
198 uint32_t regno, _Unwind_VRS_DataRepresentation representation,
199 void *valuep);
200
201extern _Unwind_VRS_Result
202_Unwind_VRS_Pop(_Unwind_Context *context, _Unwind_VRS_RegClass regclass,
203 uint32_t discriminator,
204 _Unwind_VRS_DataRepresentation representation);
Dan Alberta146ba02014-10-13 21:01:30 +0000205#endif
Dan Alberte45805f2014-07-02 16:11:13 -0700206
Nick Kledzikb78da982013-10-07 21:39:41 +0000207extern uintptr_t _Unwind_GetGR(struct _Unwind_Context *context, int index);
208extern void _Unwind_SetGR(struct _Unwind_Context *context, int index,
209 uintptr_t new_value);
210extern uintptr_t _Unwind_GetIP(struct _Unwind_Context *context);
211extern void _Unwind_SetIP(struct _Unwind_Context *, uintptr_t new_value);
Dan Alberte45805f2014-07-02 16:11:13 -0700212
Nick Kledzikb78da982013-10-07 21:39:41 +0000213extern uintptr_t _Unwind_GetRegionStart(struct _Unwind_Context *context);
214extern uintptr_t
215 _Unwind_GetLanguageSpecificData(struct _Unwind_Context *context);
Dan Albert0a1ce9c2015-03-04 17:08:25 -0800216#ifdef __USING_SJLJ_EXCEPTIONS__
Nick Kledzikb78da982013-10-07 21:39:41 +0000217extern _Unwind_Reason_Code
Dan Alberte45805f2014-07-02 16:11:13 -0700218 _Unwind_SjLj_ForcedUnwind(_Unwind_Exception *exception_object,
Nick Kledzikb78da982013-10-07 21:39:41 +0000219 _Unwind_Stop_Fn stop, void *stop_parameter);
220#else
221extern _Unwind_Reason_Code
Dan Alberte45805f2014-07-02 16:11:13 -0700222 _Unwind_ForcedUnwind(_Unwind_Exception *exception_object,
Nick Kledzikb78da982013-10-07 21:39:41 +0000223 _Unwind_Stop_Fn stop, void *stop_parameter);
224#endif
225
Dan Albert0a1ce9c2015-03-04 17:08:25 -0800226#ifdef __USING_SJLJ_EXCEPTIONS__
Nick Kledzikb78da982013-10-07 21:39:41 +0000227typedef struct _Unwind_FunctionContext *_Unwind_FunctionContext_t;
228extern void _Unwind_SjLj_Register(_Unwind_FunctionContext_t fc);
229extern void _Unwind_SjLj_Unregister(_Unwind_FunctionContext_t fc);
230#endif
231
232//
233// The following are semi-suppoted extensions to the C++ ABI
234//
235
236//
237// called by __cxa_rethrow().
238//
Dan Albert0a1ce9c2015-03-04 17:08:25 -0800239#ifdef __USING_SJLJ_EXCEPTIONS__
Nick Kledzikb78da982013-10-07 21:39:41 +0000240extern _Unwind_Reason_Code
Dan Alberte45805f2014-07-02 16:11:13 -0700241 _Unwind_SjLj_Resume_or_Rethrow(_Unwind_Exception *exception_object);
Nick Kledzikb78da982013-10-07 21:39:41 +0000242#else
243extern _Unwind_Reason_Code
Dan Alberte45805f2014-07-02 16:11:13 -0700244 _Unwind_Resume_or_Rethrow(_Unwind_Exception *exception_object);
Nick Kledzikb78da982013-10-07 21:39:41 +0000245#endif
246
247// _Unwind_Backtrace() is a gcc extension that walks the stack and calls the
248// _Unwind_Trace_Fn once per frame until it reaches the bottom of the stack
249// or the _Unwind_Trace_Fn function returns something other than _URC_NO_REASON.
250typedef _Unwind_Reason_Code (*_Unwind_Trace_Fn)(struct _Unwind_Context *,
251 void *);
252extern _Unwind_Reason_Code _Unwind_Backtrace(_Unwind_Trace_Fn, void *);
253
254// _Unwind_GetCFA is a gcc extension that can be called from within a
Dan Albert0a1ce9c2015-03-04 17:08:25 -0800255// personality handler to get the CFA (stack pointer before call) of
Nick Kledzikb78da982013-10-07 21:39:41 +0000256// current frame.
257extern uintptr_t _Unwind_GetCFA(struct _Unwind_Context *);
258
259
260// _Unwind_GetIPInfo is a gcc extension that can be called from within a
Dan Alberte45805f2014-07-02 16:11:13 -0700261// personality handler. Similar to _Unwind_GetIP() but also returns in
262// *ipBefore a non-zero value if the instruction pointer is at or before the
263// instruction causing the unwind. Normally, in a function call, the IP returned
Nick Kledzikb78da982013-10-07 21:39:41 +0000264// is the return address which is after the call instruction and may be past the
265// end of the function containing the call instruction.
266extern uintptr_t _Unwind_GetIPInfo(struct _Unwind_Context *context,
267 int *ipBefore);
268
269
270// __register_frame() is used with dynamically generated code to register the
271// FDE for a generated (JIT) code. The FDE must use pc-rel addressing to point
Dan Albert0a1ce9c2015-03-04 17:08:25 -0800272// to its function and optional LSDA.
273// __register_frame() has existed in all versions of Mac OS X, but in 10.4 and
274// 10.5 it was buggy and did not actually register the FDE with the unwinder.
Nick Kledzikb78da982013-10-07 21:39:41 +0000275// In 10.6 and later it does register properly.
276extern void __register_frame(const void *fde);
277extern void __deregister_frame(const void *fde);
278
279// _Unwind_Find_FDE() will locate the FDE if the pc is in some function that has
280// an associated FDE. Note, Mac OS X 10.6 and later, introduces "compact unwind
Dan Albert0a1ce9c2015-03-04 17:08:25 -0800281// info" which the runtime uses in preference to dwarf unwind info. This
282// function will only work if the target function has an FDE but no compact
Nick Kledzikb78da982013-10-07 21:39:41 +0000283// unwind info.
284struct dwarf_eh_bases {
285 uintptr_t tbase;
286 uintptr_t dbase;
287 uintptr_t func;
288};
289extern const void *_Unwind_Find_FDE(const void *pc, struct dwarf_eh_bases *);
290
291
292// This function attempts to find the start (address of first instruction) of
293// a function given an address inside the function. It only works if the
294// function has an FDE (dwarf unwind info).
295// This function is unimplemented on Mac OS X 10.6 and later. Instead, use
296// _Unwind_Find_FDE() and look at the dwarf_eh_bases.func result.
297extern void *_Unwind_FindEnclosingFunction(void *pc);
298
299// Mac OS X does not support text-rel and data-rel addressing so these functions
300// are unimplemented
301extern uintptr_t _Unwind_GetDataRelBase(struct _Unwind_Context *context)
Nick Kledzik29180112013-11-01 00:32:26 +0000302 LIBUNWIND_UNAVAIL;
Nick Kledzikb78da982013-10-07 21:39:41 +0000303extern uintptr_t _Unwind_GetTextRelBase(struct _Unwind_Context *context)
Nick Kledzik29180112013-11-01 00:32:26 +0000304 LIBUNWIND_UNAVAIL;
Nick Kledzikb78da982013-10-07 21:39:41 +0000305
306// Mac OS X 10.4 and 10.5 had implementations of these functions in
Dan Albert0a1ce9c2015-03-04 17:08:25 -0800307// libgcc_s.dylib, but they never worked.
Nick Kledzikb78da982013-10-07 21:39:41 +0000308/// These functions are no longer available on Mac OS X.
309extern void __register_frame_info_bases(const void *fde, void *ob, void *tb,
Nick Kledzik29180112013-11-01 00:32:26 +0000310 void *db) LIBUNWIND_UNAVAIL;
Nick Kledzikb78da982013-10-07 21:39:41 +0000311extern void __register_frame_info(const void *fde, void *ob)
Nick Kledzik29180112013-11-01 00:32:26 +0000312 LIBUNWIND_UNAVAIL;
Nick Kledzikb78da982013-10-07 21:39:41 +0000313extern void __register_frame_info_table_bases(const void *fde, void *ob,
314 void *tb, void *db)
Nick Kledzik29180112013-11-01 00:32:26 +0000315 LIBUNWIND_UNAVAIL;
Nick Kledzikb78da982013-10-07 21:39:41 +0000316extern void __register_frame_info_table(const void *fde, void *ob)
Nick Kledzik29180112013-11-01 00:32:26 +0000317 LIBUNWIND_UNAVAIL;
Nick Kledzikb78da982013-10-07 21:39:41 +0000318extern void __register_frame_table(const void *fde)
Nick Kledzik29180112013-11-01 00:32:26 +0000319 LIBUNWIND_UNAVAIL;
Nick Kledzikb78da982013-10-07 21:39:41 +0000320extern void *__deregister_frame_info(const void *fde)
Nick Kledzik29180112013-11-01 00:32:26 +0000321 LIBUNWIND_UNAVAIL;
Nick Kledzikb78da982013-10-07 21:39:41 +0000322extern void *__deregister_frame_info_bases(const void *fde)
Nick Kledzik29180112013-11-01 00:32:26 +0000323 LIBUNWIND_UNAVAIL;
Nick Kledzikb78da982013-10-07 21:39:41 +0000324
325#ifdef __cplusplus
326}
327#endif
328
329#endif // __UNWIND_H__