1 //===----------------------------------------------------------------------===//
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
8 // C++ ABI Level 1 ABI documented at:
9 // https://itanium-cxx-abi.github.io/cxx-abi/abi-eh.html
11 //===----------------------------------------------------------------------===//
16 #include <__libunwind_config.h>
21 #if defined(__SEH__) && !defined(__USING_SJLJ_EXCEPTIONS__) && defined(_WIN32)
26 #if defined(__APPLE__)
27 #define LIBUNWIND_UNAVAIL __attribute__ (( unavailable ))
29 #define LIBUNWIND_UNAVAIL
35 _URC_FOREIGN_EXCEPTION_CAUGHT
= 1,
36 _URC_FATAL_PHASE2_ERROR
= 2,
37 _URC_FATAL_PHASE1_ERROR
= 3,
39 _URC_END_OF_STACK
= 5,
40 _URC_HANDLER_FOUND
= 6,
41 _URC_INSTALL_CONTEXT
= 7,
42 _URC_CONTINUE_UNWIND
= 8,
43 #if defined(_LIBUNWIND_ARM_EHABI)
46 } _Unwind_Reason_Code
;
50 _UA_CLEANUP_PHASE
= 2,
51 _UA_HANDLER_FRAME
= 4,
53 _UA_END_OF_STACK
= 16 // gcc extension to C++ ABI
56 typedef struct _Unwind_Context _Unwind_Context
; // opaque
58 #if defined(_LIBUNWIND_ARM_EHABI)
59 #include <unwind_arm_ehabi.h>
61 #include <unwind_itanium.h>
64 typedef _Unwind_Reason_Code (*_Unwind_Stop_Fn
)
66 _Unwind_Action actions
,
67 _Unwind_Exception_Class exceptionClass
,
68 _Unwind_Exception
* exceptionObject
,
69 struct _Unwind_Context
* context
,
70 void* stop_parameter
);
76 extern uintptr_t _Unwind_GetRegionStart(struct _Unwind_Context
*context
);
78 _Unwind_GetLanguageSpecificData(struct _Unwind_Context
*context
);
79 #ifdef __USING_SJLJ_EXCEPTIONS__
80 extern _Unwind_Reason_Code
81 _Unwind_SjLj_ForcedUnwind(_Unwind_Exception
*exception_object
,
82 _Unwind_Stop_Fn stop
, void *stop_parameter
);
84 extern _Unwind_Reason_Code
85 _Unwind_ForcedUnwind(_Unwind_Exception
*exception_object
,
86 _Unwind_Stop_Fn stop
, void *stop_parameter
);
89 #ifdef __USING_SJLJ_EXCEPTIONS__
90 typedef struct _Unwind_FunctionContext
*_Unwind_FunctionContext_t
;
91 extern void _Unwind_SjLj_Register(_Unwind_FunctionContext_t fc
);
92 extern void _Unwind_SjLj_Unregister(_Unwind_FunctionContext_t fc
);
96 // The following are semi-supported extensions to the C++ ABI
100 // called by __cxa_rethrow().
102 #ifdef __USING_SJLJ_EXCEPTIONS__
103 extern _Unwind_Reason_Code
104 _Unwind_SjLj_Resume_or_Rethrow(_Unwind_Exception
*exception_object
);
106 extern _Unwind_Reason_Code
107 _Unwind_Resume_or_Rethrow(_Unwind_Exception
*exception_object
);
110 // _Unwind_Backtrace() is a gcc extension that walks the stack and calls the
111 // _Unwind_Trace_Fn once per frame until it reaches the bottom of the stack
112 // or the _Unwind_Trace_Fn function returns something other than _URC_NO_REASON.
113 typedef _Unwind_Reason_Code (*_Unwind_Trace_Fn
)(struct _Unwind_Context
*,
115 extern _Unwind_Reason_Code
_Unwind_Backtrace(_Unwind_Trace_Fn
, void *);
117 // _Unwind_GetCFA is a gcc extension that can be called from within a
118 // personality handler to get the CFA (stack pointer before call) of
120 extern uintptr_t _Unwind_GetCFA(struct _Unwind_Context
*);
123 // _Unwind_GetIPInfo is a gcc extension that can be called from within a
124 // personality handler. Similar to _Unwind_GetIP() but also returns in
125 // *ipBefore a non-zero value if the instruction pointer is at or before the
126 // instruction causing the unwind. Normally, in a function call, the IP returned
127 // is the return address which is after the call instruction and may be past the
128 // end of the function containing the call instruction.
129 extern uintptr_t _Unwind_GetIPInfo(struct _Unwind_Context
*context
,
133 // __register_frame() is used with dynamically generated code to register the
134 // FDE for a generated (JIT) code. The FDE must use pc-rel addressing to point
135 // to its function and optional LSDA.
136 // __register_frame() has existed in all versions of Mac OS X, but in 10.4 and
137 // 10.5 it was buggy and did not actually register the FDE with the unwinder.
138 // In 10.6 and later it does register properly.
139 extern void __register_frame(const void *fde
);
140 extern void __deregister_frame(const void *fde
);
142 // _Unwind_Find_FDE() will locate the FDE if the pc is in some function that has
143 // an associated FDE. Note, Mac OS X 10.6 and later, introduces "compact unwind
144 // info" which the runtime uses in preference to DWARF unwind info. This
145 // function will only work if the target function has an FDE but no compact
147 struct dwarf_eh_bases
{
152 extern const void *_Unwind_Find_FDE(const void *pc
, struct dwarf_eh_bases
*);
155 // This function attempts to find the start (address of first instruction) of
156 // a function given an address inside the function. It only works if the
157 // function has an FDE (DWARF unwind info).
158 // This function is unimplemented on Mac OS X 10.6 and later. Instead, use
159 // _Unwind_Find_FDE() and look at the dwarf_eh_bases.func result.
160 extern void *_Unwind_FindEnclosingFunction(void *pc
);
162 // Mac OS X does not support text-rel and data-rel addressing so these functions
163 // are unimplemented.
164 extern uintptr_t _Unwind_GetDataRelBase(struct _Unwind_Context
*context
)
166 extern uintptr_t _Unwind_GetTextRelBase(struct _Unwind_Context
*context
)
169 // Mac OS X 10.4 and 10.5 had implementations of these functions in
170 // libgcc_s.dylib, but they never worked.
171 /// These functions are no longer available on Mac OS X.
172 extern void __register_frame_info_bases(const void *fde
, void *ob
, void *tb
,
173 void *db
) LIBUNWIND_UNAVAIL
;
174 extern void __register_frame_info(const void *fde
, void *ob
)
176 extern void __register_frame_info_table_bases(const void *fde
, void *ob
,
179 extern void __register_frame_info_table(const void *fde
, void *ob
)
181 extern void __register_frame_table(const void *fde
)
183 extern void *__deregister_frame_info(const void *fde
)
185 extern void *__deregister_frame_info_bases(const void *fde
)
188 #if defined(__SEH__) && !defined(__USING_SJLJ_EXCEPTIONS__)
190 typedef struct _EXCEPTION_RECORD EXCEPTION_RECORD
;
191 typedef struct _CONTEXT CONTEXT
;
192 typedef struct _DISPATCHER_CONTEXT DISPATCHER_CONTEXT
;
193 #elif !defined(__MINGW32__) && VER_PRODUCTBUILD < 8000
194 typedef struct _DISPATCHER_CONTEXT DISPATCHER_CONTEXT
;
196 // This is the common wrapper for GCC-style personality functions with SEH.
197 extern EXCEPTION_DISPOSITION
_GCC_specific_handler(EXCEPTION_RECORD
*exc
,
198 void *frame
, CONTEXT
*ctx
,
199 DISPATCHER_CONTEXT
*disp
,
200 _Unwind_Personality_Fn pers
);
207 #endif // __UNWIND_H__