xref: /freebsd/contrib/llvm-project/libunwind/include/unwind.h (revision 5ffd83dbcc34f10e07f6d3e968ae6365869615f4)
10b57cec5SDimitry Andric //===------------------------------- unwind.h -----------------------------===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //
80b57cec5SDimitry Andric // C++ ABI Level 1 ABI documented at:
90b57cec5SDimitry Andric //   https://itanium-cxx-abi.github.io/cxx-abi/abi-eh.html
100b57cec5SDimitry Andric //
110b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
120b57cec5SDimitry Andric 
130b57cec5SDimitry Andric #ifndef __UNWIND_H__
140b57cec5SDimitry Andric #define __UNWIND_H__
150b57cec5SDimitry Andric 
160b57cec5SDimitry Andric #include <__libunwind_config.h>
170b57cec5SDimitry Andric 
180b57cec5SDimitry Andric #include <stdint.h>
190b57cec5SDimitry Andric #include <stddef.h>
200b57cec5SDimitry Andric 
210b57cec5SDimitry Andric #if defined(__SEH__) && !defined(__USING_SJLJ_EXCEPTIONS__) && defined(_WIN32)
220b57cec5SDimitry Andric #include <windows.h>
230b57cec5SDimitry Andric #include <ntverp.h>
240b57cec5SDimitry Andric #endif
250b57cec5SDimitry Andric 
260b57cec5SDimitry Andric #if defined(__APPLE__)
270b57cec5SDimitry Andric #define LIBUNWIND_UNAVAIL __attribute__ (( unavailable ))
280b57cec5SDimitry Andric #else
290b57cec5SDimitry Andric #define LIBUNWIND_UNAVAIL
300b57cec5SDimitry Andric #endif
310b57cec5SDimitry Andric 
320b57cec5SDimitry Andric typedef enum {
330b57cec5SDimitry Andric   _URC_NO_REASON = 0,
340b57cec5SDimitry Andric   _URC_OK = 0,
350b57cec5SDimitry Andric   _URC_FOREIGN_EXCEPTION_CAUGHT = 1,
360b57cec5SDimitry Andric   _URC_FATAL_PHASE2_ERROR = 2,
370b57cec5SDimitry Andric   _URC_FATAL_PHASE1_ERROR = 3,
380b57cec5SDimitry Andric   _URC_NORMAL_STOP = 4,
390b57cec5SDimitry Andric   _URC_END_OF_STACK = 5,
400b57cec5SDimitry Andric   _URC_HANDLER_FOUND = 6,
410b57cec5SDimitry Andric   _URC_INSTALL_CONTEXT = 7,
420b57cec5SDimitry Andric   _URC_CONTINUE_UNWIND = 8,
430b57cec5SDimitry Andric #if defined(_LIBUNWIND_ARM_EHABI)
440b57cec5SDimitry Andric   _URC_FAILURE = 9
450b57cec5SDimitry Andric #endif
460b57cec5SDimitry Andric } _Unwind_Reason_Code;
470b57cec5SDimitry Andric 
480b57cec5SDimitry Andric typedef enum {
490b57cec5SDimitry Andric   _UA_SEARCH_PHASE = 1,
500b57cec5SDimitry Andric   _UA_CLEANUP_PHASE = 2,
510b57cec5SDimitry Andric   _UA_HANDLER_FRAME = 4,
520b57cec5SDimitry Andric   _UA_FORCE_UNWIND = 8,
530b57cec5SDimitry Andric   _UA_END_OF_STACK = 16 // gcc extension to C++ ABI
540b57cec5SDimitry Andric } _Unwind_Action;
550b57cec5SDimitry Andric 
560b57cec5SDimitry Andric typedef struct _Unwind_Context _Unwind_Context;   // opaque
570b57cec5SDimitry Andric 
580b57cec5SDimitry Andric #if defined(_LIBUNWIND_ARM_EHABI)
590b57cec5SDimitry Andric typedef uint32_t _Unwind_State;
600b57cec5SDimitry Andric 
610b57cec5SDimitry Andric static const _Unwind_State _US_VIRTUAL_UNWIND_FRAME   = 0;
620b57cec5SDimitry Andric static const _Unwind_State _US_UNWIND_FRAME_STARTING  = 1;
630b57cec5SDimitry Andric static const _Unwind_State _US_UNWIND_FRAME_RESUME    = 2;
640b57cec5SDimitry Andric static const _Unwind_State _US_ACTION_MASK            = 3;
650b57cec5SDimitry Andric /* Undocumented flag for force unwinding. */
660b57cec5SDimitry Andric static const _Unwind_State _US_FORCE_UNWIND           = 8;
670b57cec5SDimitry Andric 
680b57cec5SDimitry Andric typedef uint32_t _Unwind_EHT_Header;
690b57cec5SDimitry Andric 
70*5ffd83dbSDimitry Andric struct _Unwind_Control_Block;
71*5ffd83dbSDimitry Andric typedef struct _Unwind_Control_Block _Unwind_Control_Block;
72*5ffd83dbSDimitry Andric typedef struct _Unwind_Control_Block _Unwind_Exception; /* Alias */
73*5ffd83dbSDimitry Andric 
74*5ffd83dbSDimitry Andric struct _Unwind_Control_Block {
750b57cec5SDimitry Andric   uint64_t exception_class;
760b57cec5SDimitry Andric   void (*exception_cleanup)(_Unwind_Reason_Code, _Unwind_Control_Block*);
770b57cec5SDimitry Andric 
780b57cec5SDimitry Andric   /* Unwinder cache, private fields for the unwinder's use */
790b57cec5SDimitry Andric   struct {
800b57cec5SDimitry Andric     uint32_t reserved1; /* init reserved1 to 0, then don't touch */
810b57cec5SDimitry Andric     uint32_t reserved2;
820b57cec5SDimitry Andric     uint32_t reserved3;
830b57cec5SDimitry Andric     uint32_t reserved4;
840b57cec5SDimitry Andric     uint32_t reserved5;
850b57cec5SDimitry Andric   } unwinder_cache;
860b57cec5SDimitry Andric 
870b57cec5SDimitry Andric   /* Propagation barrier cache (valid after phase 1): */
880b57cec5SDimitry Andric   struct {
890b57cec5SDimitry Andric     uint32_t sp;
900b57cec5SDimitry Andric     uint32_t bitpattern[5];
910b57cec5SDimitry Andric   } barrier_cache;
920b57cec5SDimitry Andric 
930b57cec5SDimitry Andric   /* Cleanup cache (preserved over cleanup): */
940b57cec5SDimitry Andric   struct {
950b57cec5SDimitry Andric     uint32_t bitpattern[4];
960b57cec5SDimitry Andric   } cleanup_cache;
970b57cec5SDimitry Andric 
980b57cec5SDimitry Andric   /* Pr cache (for pr's benefit): */
990b57cec5SDimitry Andric   struct {
1000b57cec5SDimitry Andric     uint32_t fnstart; /* function start address */
1010b57cec5SDimitry Andric     _Unwind_EHT_Header* ehtp; /* pointer to EHT entry header word */
1020b57cec5SDimitry Andric     uint32_t additional;
1030b57cec5SDimitry Andric     uint32_t reserved1;
1040b57cec5SDimitry Andric   } pr_cache;
1050b57cec5SDimitry Andric 
1060b57cec5SDimitry Andric   long long int :0; /* Enforce the 8-byte alignment */
1070b57cec5SDimitry Andric } __attribute__((__aligned__(8)));
1080b57cec5SDimitry Andric 
1090b57cec5SDimitry Andric typedef _Unwind_Reason_Code (*_Unwind_Stop_Fn)
1100b57cec5SDimitry Andric       (_Unwind_State state,
1110b57cec5SDimitry Andric        _Unwind_Exception* exceptionObject,
1120b57cec5SDimitry Andric        struct _Unwind_Context* context);
1130b57cec5SDimitry Andric 
114*5ffd83dbSDimitry Andric typedef _Unwind_Reason_Code (*_Unwind_Personality_Fn)(
115*5ffd83dbSDimitry Andric     _Unwind_State state, _Unwind_Exception *exceptionObject,
1160b57cec5SDimitry Andric     struct _Unwind_Context *context);
1170b57cec5SDimitry Andric #else
1180b57cec5SDimitry Andric struct _Unwind_Context;   // opaque
1190b57cec5SDimitry Andric struct _Unwind_Exception; // forward declaration
1200b57cec5SDimitry Andric typedef struct _Unwind_Exception _Unwind_Exception;
1210b57cec5SDimitry Andric 
1220b57cec5SDimitry Andric struct _Unwind_Exception {
1230b57cec5SDimitry Andric   uint64_t exception_class;
1240b57cec5SDimitry Andric   void (*exception_cleanup)(_Unwind_Reason_Code reason,
1250b57cec5SDimitry Andric                             _Unwind_Exception *exc);
1260b57cec5SDimitry Andric #if defined(__SEH__) && !defined(__USING_SJLJ_EXCEPTIONS__)
1270b57cec5SDimitry Andric   uintptr_t private_[6];
1280b57cec5SDimitry Andric #else
1290b57cec5SDimitry Andric   uintptr_t private_1; // non-zero means forced unwind
1300b57cec5SDimitry Andric   uintptr_t private_2; // holds sp that phase1 found for phase2 to use
1310b57cec5SDimitry Andric #endif
1320b57cec5SDimitry Andric #if __SIZEOF_POINTER__ == 4
1330b57cec5SDimitry Andric   // The implementation of _Unwind_Exception uses an attribute mode on the
1340b57cec5SDimitry Andric   // above fields which has the side effect of causing this whole struct to
1350b57cec5SDimitry Andric   // round up to 32 bytes in size (48 with SEH). To be more explicit, we add
1360b57cec5SDimitry Andric   // pad fields added for binary compatibility.
1370b57cec5SDimitry Andric   uint32_t reserved[3];
1380b57cec5SDimitry Andric #endif
1390b57cec5SDimitry Andric   // The Itanium ABI requires that _Unwind_Exception objects are "double-word
1400b57cec5SDimitry Andric   // aligned".  GCC has interpreted this to mean "use the maximum useful
1410b57cec5SDimitry Andric   // alignment for the target"; so do we.
1420b57cec5SDimitry Andric } __attribute__((__aligned__));
1430b57cec5SDimitry Andric 
1440b57cec5SDimitry Andric typedef _Unwind_Reason_Code (*_Unwind_Stop_Fn)
1450b57cec5SDimitry Andric     (int version,
1460b57cec5SDimitry Andric      _Unwind_Action actions,
1470b57cec5SDimitry Andric      uint64_t exceptionClass,
1480b57cec5SDimitry Andric      _Unwind_Exception* exceptionObject,
1490b57cec5SDimitry Andric      struct _Unwind_Context* context,
1500b57cec5SDimitry Andric      void* stop_parameter );
1510b57cec5SDimitry Andric 
152*5ffd83dbSDimitry Andric typedef _Unwind_Reason_Code (*_Unwind_Personality_Fn)(
153*5ffd83dbSDimitry Andric     int version, _Unwind_Action actions, uint64_t exceptionClass,
154*5ffd83dbSDimitry Andric     _Unwind_Exception *exceptionObject, struct _Unwind_Context *context);
1550b57cec5SDimitry Andric #endif
1560b57cec5SDimitry Andric 
1570b57cec5SDimitry Andric #ifdef __cplusplus
1580b57cec5SDimitry Andric extern "C" {
1590b57cec5SDimitry Andric #endif
1600b57cec5SDimitry Andric 
1610b57cec5SDimitry Andric //
1620b57cec5SDimitry Andric // The following are the base functions documented by the C++ ABI
1630b57cec5SDimitry Andric //
1640b57cec5SDimitry Andric #ifdef __USING_SJLJ_EXCEPTIONS__
1650b57cec5SDimitry Andric extern _Unwind_Reason_Code
1660b57cec5SDimitry Andric     _Unwind_SjLj_RaiseException(_Unwind_Exception *exception_object);
1670b57cec5SDimitry Andric extern void _Unwind_SjLj_Resume(_Unwind_Exception *exception_object);
1680b57cec5SDimitry Andric #else
1690b57cec5SDimitry Andric extern _Unwind_Reason_Code
1700b57cec5SDimitry Andric     _Unwind_RaiseException(_Unwind_Exception *exception_object);
1710b57cec5SDimitry Andric extern void _Unwind_Resume(_Unwind_Exception *exception_object);
1720b57cec5SDimitry Andric #endif
1730b57cec5SDimitry Andric extern void _Unwind_DeleteException(_Unwind_Exception *exception_object);
1740b57cec5SDimitry Andric 
1750b57cec5SDimitry Andric #if defined(_LIBUNWIND_ARM_EHABI)
1760b57cec5SDimitry Andric typedef enum {
1770b57cec5SDimitry Andric   _UVRSC_CORE = 0, /* integer register */
1780b57cec5SDimitry Andric   _UVRSC_VFP = 1, /* vfp */
1790b57cec5SDimitry Andric   _UVRSC_WMMXD = 3, /* Intel WMMX data register */
1800b57cec5SDimitry Andric   _UVRSC_WMMXC = 4 /* Intel WMMX control register */
1810b57cec5SDimitry Andric } _Unwind_VRS_RegClass;
1820b57cec5SDimitry Andric 
1830b57cec5SDimitry Andric typedef enum {
1840b57cec5SDimitry Andric   _UVRSD_UINT32 = 0,
1850b57cec5SDimitry Andric   _UVRSD_VFPX = 1,
1860b57cec5SDimitry Andric   _UVRSD_UINT64 = 3,
1870b57cec5SDimitry Andric   _UVRSD_FLOAT = 4,
1880b57cec5SDimitry Andric   _UVRSD_DOUBLE = 5
1890b57cec5SDimitry Andric } _Unwind_VRS_DataRepresentation;
1900b57cec5SDimitry Andric 
1910b57cec5SDimitry Andric typedef enum {
1920b57cec5SDimitry Andric   _UVRSR_OK = 0,
1930b57cec5SDimitry Andric   _UVRSR_NOT_IMPLEMENTED = 1,
1940b57cec5SDimitry Andric   _UVRSR_FAILED = 2
1950b57cec5SDimitry Andric } _Unwind_VRS_Result;
1960b57cec5SDimitry Andric 
1970b57cec5SDimitry Andric extern void _Unwind_Complete(_Unwind_Exception* exception_object);
1980b57cec5SDimitry Andric 
1990b57cec5SDimitry Andric extern _Unwind_VRS_Result
2000b57cec5SDimitry Andric _Unwind_VRS_Get(_Unwind_Context *context, _Unwind_VRS_RegClass regclass,
2010b57cec5SDimitry Andric                 uint32_t regno, _Unwind_VRS_DataRepresentation representation,
2020b57cec5SDimitry Andric                 void *valuep);
2030b57cec5SDimitry Andric 
2040b57cec5SDimitry Andric extern _Unwind_VRS_Result
2050b57cec5SDimitry Andric _Unwind_VRS_Set(_Unwind_Context *context, _Unwind_VRS_RegClass regclass,
2060b57cec5SDimitry Andric                 uint32_t regno, _Unwind_VRS_DataRepresentation representation,
2070b57cec5SDimitry Andric                 void *valuep);
2080b57cec5SDimitry Andric 
2090b57cec5SDimitry Andric extern _Unwind_VRS_Result
2100b57cec5SDimitry Andric _Unwind_VRS_Pop(_Unwind_Context *context, _Unwind_VRS_RegClass regclass,
2110b57cec5SDimitry Andric                 uint32_t discriminator,
2120b57cec5SDimitry Andric                 _Unwind_VRS_DataRepresentation representation);
2130b57cec5SDimitry Andric #endif
2140b57cec5SDimitry Andric 
2150b57cec5SDimitry Andric #if !defined(_LIBUNWIND_ARM_EHABI)
2160b57cec5SDimitry Andric 
2170b57cec5SDimitry Andric extern uintptr_t _Unwind_GetGR(struct _Unwind_Context *context, int index);
2180b57cec5SDimitry Andric extern void _Unwind_SetGR(struct _Unwind_Context *context, int index,
2190b57cec5SDimitry Andric                           uintptr_t new_value);
2200b57cec5SDimitry Andric extern uintptr_t _Unwind_GetIP(struct _Unwind_Context *context);
2210b57cec5SDimitry Andric extern void _Unwind_SetIP(struct _Unwind_Context *, uintptr_t new_value);
2220b57cec5SDimitry Andric 
2230b57cec5SDimitry Andric #else  // defined(_LIBUNWIND_ARM_EHABI)
2240b57cec5SDimitry Andric 
2250b57cec5SDimitry Andric #if defined(_LIBUNWIND_UNWIND_LEVEL1_EXTERNAL_LINKAGE)
2260b57cec5SDimitry Andric #define _LIBUNWIND_EXPORT_UNWIND_LEVEL1 extern
2270b57cec5SDimitry Andric #else
2280b57cec5SDimitry Andric #define _LIBUNWIND_EXPORT_UNWIND_LEVEL1 static __inline__
2290b57cec5SDimitry Andric #endif
2300b57cec5SDimitry Andric 
2310b57cec5SDimitry Andric // These are de facto helper functions for ARM, which delegate the function
2320b57cec5SDimitry Andric // calls to _Unwind_VRS_Get/Set().  These are not a part of ARM EHABI
2330b57cec5SDimitry Andric // specification, thus these function MUST be inlined.  Please don't replace
2340b57cec5SDimitry Andric // these with the "extern" function declaration; otherwise, the program
2350b57cec5SDimitry Andric // including this <unwind.h> header won't be ABI compatible and will result in
2360b57cec5SDimitry Andric // link error when we are linking the program with libgcc.
2370b57cec5SDimitry Andric 
2380b57cec5SDimitry Andric _LIBUNWIND_EXPORT_UNWIND_LEVEL1
2390b57cec5SDimitry Andric uintptr_t _Unwind_GetGR(struct _Unwind_Context *context, int index) {
2400b57cec5SDimitry Andric   uintptr_t value = 0;
2410b57cec5SDimitry Andric   _Unwind_VRS_Get(context, _UVRSC_CORE, (uint32_t)index, _UVRSD_UINT32, &value);
2420b57cec5SDimitry Andric   return value;
2430b57cec5SDimitry Andric }
2440b57cec5SDimitry Andric 
2450b57cec5SDimitry Andric _LIBUNWIND_EXPORT_UNWIND_LEVEL1
2460b57cec5SDimitry Andric void _Unwind_SetGR(struct _Unwind_Context *context, int index,
2470b57cec5SDimitry Andric                    uintptr_t value) {
2480b57cec5SDimitry Andric   _Unwind_VRS_Set(context, _UVRSC_CORE, (uint32_t)index, _UVRSD_UINT32, &value);
2490b57cec5SDimitry Andric }
2500b57cec5SDimitry Andric 
2510b57cec5SDimitry Andric _LIBUNWIND_EXPORT_UNWIND_LEVEL1
2520b57cec5SDimitry Andric uintptr_t _Unwind_GetIP(struct _Unwind_Context *context) {
2530b57cec5SDimitry Andric   // remove the thumb-bit before returning
2540b57cec5SDimitry Andric   return _Unwind_GetGR(context, 15) & (~(uintptr_t)0x1);
2550b57cec5SDimitry Andric }
2560b57cec5SDimitry Andric 
2570b57cec5SDimitry Andric _LIBUNWIND_EXPORT_UNWIND_LEVEL1
2580b57cec5SDimitry Andric void _Unwind_SetIP(struct _Unwind_Context *context, uintptr_t value) {
2590b57cec5SDimitry Andric   uintptr_t thumb_bit = _Unwind_GetGR(context, 15) & ((uintptr_t)0x1);
2600b57cec5SDimitry Andric   _Unwind_SetGR(context, 15, value | thumb_bit);
2610b57cec5SDimitry Andric }
2620b57cec5SDimitry Andric #endif  // defined(_LIBUNWIND_ARM_EHABI)
2630b57cec5SDimitry Andric 
2640b57cec5SDimitry Andric extern uintptr_t _Unwind_GetRegionStart(struct _Unwind_Context *context);
2650b57cec5SDimitry Andric extern uintptr_t
2660b57cec5SDimitry Andric     _Unwind_GetLanguageSpecificData(struct _Unwind_Context *context);
2670b57cec5SDimitry Andric #ifdef __USING_SJLJ_EXCEPTIONS__
2680b57cec5SDimitry Andric extern _Unwind_Reason_Code
2690b57cec5SDimitry Andric     _Unwind_SjLj_ForcedUnwind(_Unwind_Exception *exception_object,
2700b57cec5SDimitry Andric                               _Unwind_Stop_Fn stop, void *stop_parameter);
2710b57cec5SDimitry Andric #else
2720b57cec5SDimitry Andric extern _Unwind_Reason_Code
2730b57cec5SDimitry Andric     _Unwind_ForcedUnwind(_Unwind_Exception *exception_object,
2740b57cec5SDimitry Andric                          _Unwind_Stop_Fn stop, void *stop_parameter);
2750b57cec5SDimitry Andric #endif
2760b57cec5SDimitry Andric 
2770b57cec5SDimitry Andric #ifdef __USING_SJLJ_EXCEPTIONS__
2780b57cec5SDimitry Andric typedef struct _Unwind_FunctionContext *_Unwind_FunctionContext_t;
2790b57cec5SDimitry Andric extern void _Unwind_SjLj_Register(_Unwind_FunctionContext_t fc);
2800b57cec5SDimitry Andric extern void _Unwind_SjLj_Unregister(_Unwind_FunctionContext_t fc);
2810b57cec5SDimitry Andric #endif
2820b57cec5SDimitry Andric 
2830b57cec5SDimitry Andric //
2840b57cec5SDimitry Andric // The following are semi-suppoted extensions to the C++ ABI
2850b57cec5SDimitry Andric //
2860b57cec5SDimitry Andric 
2870b57cec5SDimitry Andric //
2880b57cec5SDimitry Andric //  called by __cxa_rethrow().
2890b57cec5SDimitry Andric //
2900b57cec5SDimitry Andric #ifdef __USING_SJLJ_EXCEPTIONS__
2910b57cec5SDimitry Andric extern _Unwind_Reason_Code
2920b57cec5SDimitry Andric     _Unwind_SjLj_Resume_or_Rethrow(_Unwind_Exception *exception_object);
2930b57cec5SDimitry Andric #else
2940b57cec5SDimitry Andric extern _Unwind_Reason_Code
2950b57cec5SDimitry Andric     _Unwind_Resume_or_Rethrow(_Unwind_Exception *exception_object);
2960b57cec5SDimitry Andric #endif
2970b57cec5SDimitry Andric 
2980b57cec5SDimitry Andric // _Unwind_Backtrace() is a gcc extension that walks the stack and calls the
2990b57cec5SDimitry Andric // _Unwind_Trace_Fn once per frame until it reaches the bottom of the stack
3000b57cec5SDimitry Andric // or the _Unwind_Trace_Fn function returns something other than _URC_NO_REASON.
3010b57cec5SDimitry Andric typedef _Unwind_Reason_Code (*_Unwind_Trace_Fn)(struct _Unwind_Context *,
3020b57cec5SDimitry Andric                                                 void *);
3030b57cec5SDimitry Andric extern _Unwind_Reason_Code _Unwind_Backtrace(_Unwind_Trace_Fn, void *);
3040b57cec5SDimitry Andric 
3050b57cec5SDimitry Andric // _Unwind_GetCFA is a gcc extension that can be called from within a
3060b57cec5SDimitry Andric // personality handler to get the CFA (stack pointer before call) of
3070b57cec5SDimitry Andric // current frame.
3080b57cec5SDimitry Andric extern uintptr_t _Unwind_GetCFA(struct _Unwind_Context *);
3090b57cec5SDimitry Andric 
3100b57cec5SDimitry Andric 
3110b57cec5SDimitry Andric // _Unwind_GetIPInfo is a gcc extension that can be called from within a
3120b57cec5SDimitry Andric // personality handler.  Similar to _Unwind_GetIP() but also returns in
3130b57cec5SDimitry Andric // *ipBefore a non-zero value if the instruction pointer is at or before the
3140b57cec5SDimitry Andric // instruction causing the unwind. Normally, in a function call, the IP returned
3150b57cec5SDimitry Andric // is the return address which is after the call instruction and may be past the
3160b57cec5SDimitry Andric // end of the function containing the call instruction.
3170b57cec5SDimitry Andric extern uintptr_t _Unwind_GetIPInfo(struct _Unwind_Context *context,
3180b57cec5SDimitry Andric                                    int *ipBefore);
3190b57cec5SDimitry Andric 
3200b57cec5SDimitry Andric 
3210b57cec5SDimitry Andric // __register_frame() is used with dynamically generated code to register the
3220b57cec5SDimitry Andric // FDE for a generated (JIT) code.  The FDE must use pc-rel addressing to point
3230b57cec5SDimitry Andric // to its function and optional LSDA.
3240b57cec5SDimitry Andric // __register_frame() has existed in all versions of Mac OS X, but in 10.4 and
3250b57cec5SDimitry Andric // 10.5 it was buggy and did not actually register the FDE with the unwinder.
3260b57cec5SDimitry Andric // In 10.6 and later it does register properly.
3270b57cec5SDimitry Andric extern void __register_frame(const void *fde);
3280b57cec5SDimitry Andric extern void __deregister_frame(const void *fde);
3290b57cec5SDimitry Andric 
3300b57cec5SDimitry Andric // _Unwind_Find_FDE() will locate the FDE if the pc is in some function that has
3310b57cec5SDimitry Andric // an associated FDE. Note, Mac OS X 10.6 and later, introduces "compact unwind
3320b57cec5SDimitry Andric // info" which the runtime uses in preference to DWARF unwind info.  This
3330b57cec5SDimitry Andric // function will only work if the target function has an FDE but no compact
3340b57cec5SDimitry Andric // unwind info.
3350b57cec5SDimitry Andric struct dwarf_eh_bases {
3360b57cec5SDimitry Andric   uintptr_t tbase;
3370b57cec5SDimitry Andric   uintptr_t dbase;
3380b57cec5SDimitry Andric   uintptr_t func;
3390b57cec5SDimitry Andric };
3400b57cec5SDimitry Andric extern const void *_Unwind_Find_FDE(const void *pc, struct dwarf_eh_bases *);
3410b57cec5SDimitry Andric 
3420b57cec5SDimitry Andric 
3430b57cec5SDimitry Andric // This function attempts to find the start (address of first instruction) of
3440b57cec5SDimitry Andric // a function given an address inside the function.  It only works if the
3450b57cec5SDimitry Andric // function has an FDE (DWARF unwind info).
3460b57cec5SDimitry Andric // This function is unimplemented on Mac OS X 10.6 and later.  Instead, use
3470b57cec5SDimitry Andric // _Unwind_Find_FDE() and look at the dwarf_eh_bases.func result.
3480b57cec5SDimitry Andric extern void *_Unwind_FindEnclosingFunction(void *pc);
3490b57cec5SDimitry Andric 
3500b57cec5SDimitry Andric // Mac OS X does not support text-rel and data-rel addressing so these functions
3510b57cec5SDimitry Andric // are unimplemented
3520b57cec5SDimitry Andric extern uintptr_t _Unwind_GetDataRelBase(struct _Unwind_Context *context)
3530b57cec5SDimitry Andric     LIBUNWIND_UNAVAIL;
3540b57cec5SDimitry Andric extern uintptr_t _Unwind_GetTextRelBase(struct _Unwind_Context *context)
3550b57cec5SDimitry Andric     LIBUNWIND_UNAVAIL;
3560b57cec5SDimitry Andric 
3570b57cec5SDimitry Andric // Mac OS X 10.4 and 10.5 had implementations of these functions in
3580b57cec5SDimitry Andric // libgcc_s.dylib, but they never worked.
3590b57cec5SDimitry Andric /// These functions are no longer available on Mac OS X.
3600b57cec5SDimitry Andric extern void __register_frame_info_bases(const void *fde, void *ob, void *tb,
3610b57cec5SDimitry Andric                                         void *db) LIBUNWIND_UNAVAIL;
3620b57cec5SDimitry Andric extern void __register_frame_info(const void *fde, void *ob)
3630b57cec5SDimitry Andric     LIBUNWIND_UNAVAIL;
3640b57cec5SDimitry Andric extern void __register_frame_info_table_bases(const void *fde, void *ob,
3650b57cec5SDimitry Andric                                               void *tb, void *db)
3660b57cec5SDimitry Andric     LIBUNWIND_UNAVAIL;
3670b57cec5SDimitry Andric extern void __register_frame_info_table(const void *fde, void *ob)
3680b57cec5SDimitry Andric     LIBUNWIND_UNAVAIL;
3690b57cec5SDimitry Andric extern void __register_frame_table(const void *fde)
3700b57cec5SDimitry Andric     LIBUNWIND_UNAVAIL;
3710b57cec5SDimitry Andric extern void *__deregister_frame_info(const void *fde)
3720b57cec5SDimitry Andric     LIBUNWIND_UNAVAIL;
3730b57cec5SDimitry Andric extern void *__deregister_frame_info_bases(const void *fde)
3740b57cec5SDimitry Andric     LIBUNWIND_UNAVAIL;
3750b57cec5SDimitry Andric 
3760b57cec5SDimitry Andric #if defined(__SEH__) && !defined(__USING_SJLJ_EXCEPTIONS__)
3770b57cec5SDimitry Andric #ifndef _WIN32
3780b57cec5SDimitry Andric typedef struct _EXCEPTION_RECORD EXCEPTION_RECORD;
3790b57cec5SDimitry Andric typedef struct _CONTEXT CONTEXT;
3800b57cec5SDimitry Andric typedef struct _DISPATCHER_CONTEXT DISPATCHER_CONTEXT;
3810b57cec5SDimitry Andric #elif !defined(__MINGW32__) && VER_PRODUCTBUILD < 8000
3820b57cec5SDimitry Andric typedef struct _DISPATCHER_CONTEXT DISPATCHER_CONTEXT;
3830b57cec5SDimitry Andric #endif
3840b57cec5SDimitry Andric // This is the common wrapper for GCC-style personality functions with SEH.
3850b57cec5SDimitry Andric extern EXCEPTION_DISPOSITION _GCC_specific_handler(EXCEPTION_RECORD *exc,
386*5ffd83dbSDimitry Andric                                                    void *frame, CONTEXT *ctx,
3870b57cec5SDimitry Andric                                                    DISPATCHER_CONTEXT *disp,
388*5ffd83dbSDimitry Andric                                                    _Unwind_Personality_Fn pers);
3890b57cec5SDimitry Andric #endif
3900b57cec5SDimitry Andric 
3910b57cec5SDimitry Andric #ifdef __cplusplus
3920b57cec5SDimitry Andric }
3930b57cec5SDimitry Andric #endif
3940b57cec5SDimitry Andric 
3950b57cec5SDimitry Andric #endif // __UNWIND_H__
396