unwind.h revision 7dc8e8175a3a1d4e40819932165e26b01091541e
1f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson/*===---- unwind.h - Stack unwinding ----------------------------------------===
2f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson *
3f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson * Permission is hereby granted, free of charge, to any person obtaining a copy
4f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson * of this software and associated documentation files (the "Software"), to deal
5f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson * in the Software without restriction, including without limitation the rights
6f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson * copies of the Software, and to permit persons to whom the Software is
8f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson * furnished to do so, subject to the following conditions:
9f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson *
10f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson * The above copyright notice and this permission notice shall be included in
11f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson * all copies or substantial portions of the Software.
12f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson *
13f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson * THE SOFTWARE.
20f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson *
21f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson *===-----------------------------------------------------------------------===
22f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson */
23f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson
243da1eb108d36da35333b2d655202791af854996bPrzemyslaw Szczepaniak/* See "Data Definitions for libgcc_s" in the Linux Standard Base.*/
25f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson
26f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson#ifndef __CLANG_UNWIND_H
27f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson#define __CLANG_UNWIND_H
28f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson
29f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson#if __has_include_next(<unwind.h>)
30f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson/* Darwin (from 11.x on) and libunwind provide an unwind.h. If that's available,
31f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson * use it. libunwind wraps some of its definitions in #ifdef _GNU_SOURCE,
32f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson * so define that around the include.*/
33f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson# ifndef _GNU_SOURCE
34f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson#  define _SHOULD_UNDEFINE_GNU_SOURCE
35f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson#  define _GNU_SOURCE
36f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson# endif
37f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// libunwind's unwind.h reflects the current visibility.  However, Mozilla
38f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// builds with -fvisibility=hidden and relies on gcc's unwind.h to reset the
39f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// visibility to default and export its contents.  gcc also allows users to
40f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// override its override by #defining HIDE_EXPORTS (but note, this only obeys
41f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// the user's -fvisibility setting; it doesn't hide any exports on its own).  We
42f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// imitate gcc's header here:
43f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson# ifdef HIDE_EXPORTS
44f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson#  include_next <unwind.h>
45f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson# else
46f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson#  pragma GCC visibility push(default)
47f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson#  include_next <unwind.h>
48f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson#  pragma GCC visibility pop
49f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson# endif
50f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson# ifdef _SHOULD_UNDEFINE_GNU_SOURCE
51f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson#  undef _GNU_SOURCE
52f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson#  undef _SHOULD_UNDEFINE_GNU_SOURCE
53f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson# endif
54f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson#else
55f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson
56f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson#include <stdint.h>
57f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson
58f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson#ifdef __cplusplus
59f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodsonextern "C" {
60f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson#endif
61f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson
62f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson/* It is a bit strange for a header to play with the visibility of the
63f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson   symbols it declares, but this matches gcc's behavior and some programs
64f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson   depend on it */
65f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson#ifndef HIDE_EXPORTS
66f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson#pragma GCC visibility push(default)
67f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson#endif
68f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson
69f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodsontypedef uintptr_t _Unwind_Word;
70f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodsontypedef intptr_t _Unwind_Sword;
71f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodsontypedef uintptr_t _Unwind_Ptr;
72f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodsontypedef uintptr_t _Unwind_Internal_Ptr;
73f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodsontypedef uint64_t _Unwind_Exception_Class;
74
75struct _Unwind_Context;
76struct _Unwind_Exception;
77typedef enum {
78  _URC_NO_REASON = 0,
79  _URC_FOREIGN_EXCEPTION_CAUGHT = 1,
80
81  _URC_FATAL_PHASE2_ERROR = 2,
82  _URC_FATAL_PHASE1_ERROR = 3,
83  _URC_NORMAL_STOP = 4,
84
85  _URC_END_OF_STACK = 5,
86  _URC_HANDLER_FOUND = 6,
87  _URC_INSTALL_CONTEXT = 7,
88  _URC_CONTINUE_UNWIND = 8
89} _Unwind_Reason_Code;
90
91typedef enum {
92  _UA_SEARCH_PHASE = 1,
93  _UA_CLEANUP_PHASE = 2,
94
95  _UA_HANDLER_FRAME = 4,
96  _UA_FORCE_UNWIND = 8,
97  _UA_END_OF_STACK = 16 /* gcc extension to C++ ABI */
98} _Unwind_Action;
99
100typedef void (*_Unwind_Exception_Cleanup_Fn)(_Unwind_Reason_Code,
101                                             struct _Unwind_Exception *);
102
103struct _Unwind_Exception {
104  _Unwind_Exception_Class exception_class;
105  _Unwind_Exception_Cleanup_Fn exception_cleanup;
106  _Unwind_Word private_1;
107  _Unwind_Word private_2;
108  /* The Itanium ABI requires that _Unwind_Exception objects are "double-word
109   * aligned".  GCC has interpreted this to mean "use the maximum useful
110   * alignment for the target"; so do we. */
111} __attribute__((__aligned__));
112
113typedef _Unwind_Reason_Code (*_Unwind_Stop_Fn)(int, _Unwind_Action,
114                                               _Unwind_Exception_Class,
115                                               struct _Unwind_Exception *,
116                                               struct _Unwind_Context *,
117                                               void *);
118
119typedef _Unwind_Reason_Code (*_Unwind_Personality_Fn)(int, _Unwind_Action,
120                                                      _Unwind_Exception_Class,
121                                                      struct _Unwind_Exception *,
122                                                      struct _Unwind_Context *);
123typedef _Unwind_Personality_Fn __personality_routine;
124
125typedef _Unwind_Reason_Code (*_Unwind_Trace_Fn)(struct _Unwind_Context *, void *);
126
127#ifdef __arm__
128
129typedef enum {
130  _UVRSC_CORE = 0,        /* integer register */
131  _UVRSC_VFP = 1,         /* vfp */
132  _UVRSC_WMMXD = 3,       /* Intel WMMX data register */
133  _UVRSC_WMMXC = 4        /* Intel WMMX control register */
134} _Unwind_VRS_RegClass;
135
136typedef enum {
137  _UVRSD_UINT32 = 0,
138  _UVRSD_VFPX = 1,
139  _UVRSD_UINT64 = 3,
140  _UVRSD_FLOAT = 4,
141  _UVRSD_DOUBLE = 5
142} _Unwind_VRS_DataRepresentation;
143
144typedef enum {
145  _UVRSR_OK = 0,
146  _UVRSR_NOT_IMPLEMENTED = 1,
147  _UVRSR_FAILED = 2
148} _Unwind_VRS_Result;
149
150_Unwind_VRS_Result _Unwind_VRS_Get(struct _Unwind_Context *__context,
151  _Unwind_VRS_RegClass __regclass,
152  uint32_t __regno,
153  _Unwind_VRS_DataRepresentation __representation,
154  void *__valuep);
155
156#endif
157
158_Unwind_Word _Unwind_GetGR(struct _Unwind_Context *, int);
159void _Unwind_SetGR(struct _Unwind_Context *, int, _Unwind_Word);
160
161_Unwind_Word _Unwind_GetIP(struct _Unwind_Context *);
162_Unwind_Word _Unwind_GetIPInfo(struct _Unwind_Context *, int *);
163void _Unwind_SetIP(struct _Unwind_Context *, _Unwind_Word);
164
165_Unwind_Word _Unwind_GetCFA(struct _Unwind_Context *);
166
167void *_Unwind_GetLanguageSpecificData(struct _Unwind_Context *);
168
169_Unwind_Ptr _Unwind_GetRegionStart(struct _Unwind_Context *);
170
171/* DWARF EH functions; currently not available on Darwin/ARM */
172#if !defined(__APPLE__) || !defined(__arm__)
173
174_Unwind_Reason_Code _Unwind_RaiseException(struct _Unwind_Exception *);
175_Unwind_Reason_Code _Unwind_ForcedUnwind(struct _Unwind_Exception *, _Unwind_Stop_Fn,
176                                         void *);
177void _Unwind_DeleteException(struct _Unwind_Exception *);
178void _Unwind_Resume(struct _Unwind_Exception *);
179_Unwind_Reason_Code _Unwind_Resume_or_Rethrow(struct _Unwind_Exception *);
180
181#endif
182
183_Unwind_Reason_Code _Unwind_Backtrace(_Unwind_Trace_Fn, void *);
184
185/* setjmp(3)/longjmp(3) stuff */
186typedef struct SjLj_Function_Context *_Unwind_FunctionContext_t;
187
188void _Unwind_SjLj_Register(_Unwind_FunctionContext_t);
189void _Unwind_SjLj_Unregister(_Unwind_FunctionContext_t);
190_Unwind_Reason_Code _Unwind_SjLj_RaiseException(struct _Unwind_Exception *);
191_Unwind_Reason_Code _Unwind_SjLj_ForcedUnwind(struct _Unwind_Exception *, _Unwind_Stop_Fn,
192                                         void *);
193void _Unwind_SjLj_Resume(struct _Unwind_Exception *);
194_Unwind_Reason_Code _Unwind_SjLj_Resume_or_Rethrow(struct _Unwind_Exception *);
195
196void *_Unwind_FindEnclosingFunction(void *);
197
198#ifdef __APPLE__
199
200_Unwind_Ptr _Unwind_GetDataRelBase(struct _Unwind_Context *) __attribute__((unavailable));
201_Unwind_Ptr _Unwind_GetTextRelBase(struct _Unwind_Context *) __attribute__((unavailable));
202
203/* Darwin-specific functions */
204void __register_frame(const void *);
205void __deregister_frame(const void *);
206
207struct dwarf_eh_bases {
208  uintptr_t tbase;
209  uintptr_t dbase;
210  uintptr_t func;
211};
212void *_Unwind_Find_FDE(const void *, struct dwarf_eh_bases *);
213
214void __register_frame_info_bases(const void *, void *, void *, void *)
215  __attribute__((unavailable));
216void __register_frame_info(const void *, void *) __attribute__((unavailable));
217void __register_frame_info_table_bases(const void *, void*, void *, void *)
218  __attribute__((unavailable));
219void __register_frame_info_table(const void *, void *) __attribute__((unavailable));
220void __register_frame_table(const void *) __attribute__((unavailable));
221void __deregister_frame_info(const void *) __attribute__((unavailable));
222void __deregister_frame_info_bases(const void *)__attribute__((unavailable));
223
224#else
225
226_Unwind_Ptr _Unwind_GetDataRelBase(struct _Unwind_Context *);
227_Unwind_Ptr _Unwind_GetTextRelBase(struct _Unwind_Context *);
228
229#endif
230
231
232#ifndef HIDE_EXPORTS
233#pragma GCC visibility pop
234#endif
235
236#ifdef __cplusplus
237}
238#endif
239
240#endif
241
242#endif /* __CLANG_UNWIND_H */
243