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