Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:57:06

0001 //===----------------------------------------------------------------------===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //
0008 // C++ ABI Level 1 ABI documented at:
0009 //   https://itanium-cxx-abi.github.io/cxx-abi/abi-eh.html
0010 //
0011 //===----------------------------------------------------------------------===//
0012 
0013 #ifndef __UNWIND_H__
0014 #define __UNWIND_H__
0015 
0016 #include <__libunwind_config.h>
0017 
0018 #include <stdint.h>
0019 #include <stddef.h>
0020 
0021 #if defined(__SEH__) && !defined(__USING_SJLJ_EXCEPTIONS__) && defined(_WIN32)
0022 #include <windows.h>
0023 #include <ntverp.h>
0024 #endif
0025 
0026 #if defined(__APPLE__)
0027 #define LIBUNWIND_UNAVAIL __attribute__ (( unavailable ))
0028 #else
0029 #define LIBUNWIND_UNAVAIL
0030 #endif
0031 
0032 typedef enum {
0033   _URC_NO_REASON = 0,
0034   _URC_OK = 0,
0035   _URC_FOREIGN_EXCEPTION_CAUGHT = 1,
0036   _URC_FATAL_PHASE2_ERROR = 2,
0037   _URC_FATAL_PHASE1_ERROR = 3,
0038   _URC_NORMAL_STOP = 4,
0039   _URC_END_OF_STACK = 5,
0040   _URC_HANDLER_FOUND = 6,
0041   _URC_INSTALL_CONTEXT = 7,
0042   _URC_CONTINUE_UNWIND = 8,
0043 #if defined(_LIBUNWIND_ARM_EHABI)
0044   _URC_FAILURE = 9
0045 #endif
0046 } _Unwind_Reason_Code;
0047 
0048 typedef enum {
0049   _UA_SEARCH_PHASE = 1,
0050   _UA_CLEANUP_PHASE = 2,
0051   _UA_HANDLER_FRAME = 4,
0052   _UA_FORCE_UNWIND = 8,
0053   _UA_END_OF_STACK = 16 // gcc extension to C++ ABI
0054 } _Unwind_Action;
0055 
0056 typedef struct _Unwind_Context _Unwind_Context;   // opaque
0057 
0058 #if defined(_LIBUNWIND_ARM_EHABI)
0059 #include <unwind_arm_ehabi.h>
0060 #else
0061 #include <unwind_itanium.h>
0062 #endif
0063 
0064 typedef _Unwind_Reason_Code (*_Unwind_Stop_Fn)
0065     (int version,
0066      _Unwind_Action actions,
0067      _Unwind_Exception_Class exceptionClass,
0068      _Unwind_Exception* exceptionObject,
0069      struct _Unwind_Context* context,
0070      void* stop_parameter);
0071 
0072 #ifdef __cplusplus
0073 extern "C" {
0074 #endif
0075 
0076 extern uintptr_t _Unwind_GetRegionStart(struct _Unwind_Context *context);
0077 extern uintptr_t
0078     _Unwind_GetLanguageSpecificData(struct _Unwind_Context *context);
0079 #ifdef __USING_SJLJ_EXCEPTIONS__
0080 extern _Unwind_Reason_Code
0081     _Unwind_SjLj_ForcedUnwind(_Unwind_Exception *exception_object,
0082                               _Unwind_Stop_Fn stop, void *stop_parameter);
0083 #else
0084 extern _Unwind_Reason_Code
0085     _Unwind_ForcedUnwind(_Unwind_Exception *exception_object,
0086                          _Unwind_Stop_Fn stop, void *stop_parameter);
0087 #endif
0088 
0089 #ifdef __USING_SJLJ_EXCEPTIONS__
0090 typedef struct _Unwind_FunctionContext *_Unwind_FunctionContext_t;
0091 extern void _Unwind_SjLj_Register(_Unwind_FunctionContext_t fc);
0092 extern void _Unwind_SjLj_Unregister(_Unwind_FunctionContext_t fc);
0093 #endif
0094 
0095 //
0096 // The following are semi-supported extensions to the C++ ABI
0097 //
0098 
0099 //
0100 //  called by __cxa_rethrow().
0101 //
0102 #ifdef __USING_SJLJ_EXCEPTIONS__
0103 extern _Unwind_Reason_Code
0104     _Unwind_SjLj_Resume_or_Rethrow(_Unwind_Exception *exception_object);
0105 #else
0106 extern _Unwind_Reason_Code
0107     _Unwind_Resume_or_Rethrow(_Unwind_Exception *exception_object);
0108 #endif
0109 
0110 // _Unwind_Backtrace() is a gcc extension that walks the stack and calls the
0111 // _Unwind_Trace_Fn once per frame until it reaches the bottom of the stack
0112 // or the _Unwind_Trace_Fn function returns something other than _URC_NO_REASON.
0113 typedef _Unwind_Reason_Code (*_Unwind_Trace_Fn)(struct _Unwind_Context *,
0114                                                 void *);
0115 extern _Unwind_Reason_Code _Unwind_Backtrace(_Unwind_Trace_Fn, void *);
0116 
0117 // _Unwind_GetCFA is a gcc extension that can be called from within a
0118 // personality handler to get the CFA (stack pointer before call) of
0119 // current frame.
0120 extern uintptr_t _Unwind_GetCFA(struct _Unwind_Context *);
0121 
0122 
0123 // _Unwind_GetIPInfo is a gcc extension that can be called from within a
0124 // personality handler.  Similar to _Unwind_GetIP() but also returns in
0125 // *ipBefore a non-zero value if the instruction pointer is at or before the
0126 // instruction causing the unwind. Normally, in a function call, the IP returned
0127 // is the return address which is after the call instruction and may be past the
0128 // end of the function containing the call instruction.
0129 extern uintptr_t _Unwind_GetIPInfo(struct _Unwind_Context *context,
0130                                    int *ipBefore);
0131 
0132 
0133 // __register_frame() is used with dynamically generated code to register the
0134 // FDE for a generated (JIT) code.  The FDE must use pc-rel addressing to point
0135 // to its function and optional LSDA.
0136 // __register_frame() has existed in all versions of Mac OS X, but in 10.4 and
0137 // 10.5 it was buggy and did not actually register the FDE with the unwinder.
0138 // In 10.6 and later it does register properly.
0139 extern void __register_frame(const void *fde);
0140 extern void __deregister_frame(const void *fde);
0141 
0142 // _Unwind_Find_FDE() will locate the FDE if the pc is in some function that has
0143 // an associated FDE. Note, Mac OS X 10.6 and later, introduces "compact unwind
0144 // info" which the runtime uses in preference to DWARF unwind info.  This
0145 // function will only work if the target function has an FDE but no compact
0146 // unwind info.
0147 struct dwarf_eh_bases {
0148   uintptr_t tbase;
0149   uintptr_t dbase;
0150   uintptr_t func;
0151 };
0152 extern const void *_Unwind_Find_FDE(const void *pc, struct dwarf_eh_bases *);
0153 
0154 
0155 // This function attempts to find the start (address of first instruction) of
0156 // a function given an address inside the function.  It only works if the
0157 // function has an FDE (DWARF unwind info).
0158 // This function is unimplemented on Mac OS X 10.6 and later.  Instead, use
0159 // _Unwind_Find_FDE() and look at the dwarf_eh_bases.func result.
0160 extern void *_Unwind_FindEnclosingFunction(void *pc);
0161 
0162 // Mac OS X does not support text-rel and data-rel addressing so these functions
0163 // are unimplemented.
0164 extern uintptr_t _Unwind_GetDataRelBase(struct _Unwind_Context *context)
0165     LIBUNWIND_UNAVAIL;
0166 extern uintptr_t _Unwind_GetTextRelBase(struct _Unwind_Context *context)
0167     LIBUNWIND_UNAVAIL;
0168 
0169 // Mac OS X 10.4 and 10.5 had implementations of these functions in
0170 // libgcc_s.dylib, but they never worked.
0171 /// These functions are no longer available on Mac OS X.
0172 extern void __register_frame_info_bases(const void *fde, void *ob, void *tb,
0173                                         void *db) LIBUNWIND_UNAVAIL;
0174 extern void __register_frame_info(const void *fde, void *ob)
0175     LIBUNWIND_UNAVAIL;
0176 extern void __register_frame_info_table_bases(const void *fde, void *ob,
0177                                               void *tb, void *db)
0178     LIBUNWIND_UNAVAIL;
0179 extern void __register_frame_info_table(const void *fde, void *ob)
0180     LIBUNWIND_UNAVAIL;
0181 extern void __register_frame_table(const void *fde)
0182     LIBUNWIND_UNAVAIL;
0183 extern void *__deregister_frame_info(const void *fde)
0184     LIBUNWIND_UNAVAIL;
0185 extern void *__deregister_frame_info_bases(const void *fde)
0186     LIBUNWIND_UNAVAIL;
0187 
0188 #if defined(__SEH__) && !defined(__USING_SJLJ_EXCEPTIONS__)
0189 #ifndef _WIN32
0190 typedef struct _EXCEPTION_RECORD EXCEPTION_RECORD;
0191 typedef struct _CONTEXT CONTEXT;
0192 typedef struct _DISPATCHER_CONTEXT DISPATCHER_CONTEXT;
0193 #elif !defined(__MINGW32__) && VER_PRODUCTBUILD < 8000
0194 typedef struct _DISPATCHER_CONTEXT DISPATCHER_CONTEXT;
0195 #endif
0196 // This is the common wrapper for GCC-style personality functions with SEH.
0197 extern EXCEPTION_DISPOSITION _GCC_specific_handler(EXCEPTION_RECORD *exc,
0198                                                    void *frame, CONTEXT *ctx,
0199                                                    DISPATCHER_CONTEXT *disp,
0200                                                    _Unwind_Personality_Fn pers);
0201 #endif
0202 
0203 #ifdef __cplusplus
0204 }
0205 #endif
0206 
0207 #endif // __UNWIND_H__