Path: blob/main/system/lib/libunwind/include/unwind.h
6178 views
//===----------------------------------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//7// C++ ABI Level 1 ABI documented at:8// https://itanium-cxx-abi.github.io/cxx-abi/abi-eh.html9//10//===----------------------------------------------------------------------===//1112#ifndef __UNWIND_H__13#define __UNWIND_H__1415#include <__libunwind_config.h>1617#include <stdint.h>18#include <stddef.h>1920#if defined(__SEH__) && !defined(__USING_SJLJ_EXCEPTIONS__) && defined(_WIN32)21#include <windows.h>22#include <ntverp.h>23#endif2425#if defined(__APPLE__)26#define LIBUNWIND_UNAVAIL __attribute__ (( unavailable ))27#else28#define LIBUNWIND_UNAVAIL29#endif3031typedef enum {32_URC_NO_REASON = 0,33_URC_OK = 0,34_URC_FOREIGN_EXCEPTION_CAUGHT = 1,35_URC_FATAL_PHASE2_ERROR = 2,36_URC_FATAL_PHASE1_ERROR = 3,37_URC_NORMAL_STOP = 4,38_URC_END_OF_STACK = 5,39_URC_HANDLER_FOUND = 6,40_URC_INSTALL_CONTEXT = 7,41_URC_CONTINUE_UNWIND = 8,42#if defined(_LIBUNWIND_ARM_EHABI)43_URC_FAILURE = 944#endif45} _Unwind_Reason_Code;4647typedef enum {48_UA_SEARCH_PHASE = 1,49_UA_CLEANUP_PHASE = 2,50_UA_HANDLER_FRAME = 4,51_UA_FORCE_UNWIND = 8,52_UA_END_OF_STACK = 16 // gcc extension to C++ ABI53} _Unwind_Action;5455typedef struct _Unwind_Context _Unwind_Context; // opaque5657#if defined(_LIBUNWIND_ARM_EHABI)58#include <unwind_arm_ehabi.h>59#else60#include <unwind_itanium.h>61#endif6263typedef _Unwind_Reason_Code (*_Unwind_Stop_Fn)64(int version,65_Unwind_Action actions,66_Unwind_Exception_Class exceptionClass,67_Unwind_Exception* exceptionObject,68struct _Unwind_Context* context,69void* stop_parameter);7071#ifdef __cplusplus72extern "C" {73#endif7475extern uintptr_t _Unwind_GetRegionStart(struct _Unwind_Context *context);76extern uintptr_t77_Unwind_GetLanguageSpecificData(struct _Unwind_Context *context);78#ifdef __USING_SJLJ_EXCEPTIONS__79extern _Unwind_Reason_Code80_Unwind_SjLj_ForcedUnwind(_Unwind_Exception *exception_object,81_Unwind_Stop_Fn stop, void *stop_parameter);82#else83extern _Unwind_Reason_Code84_Unwind_ForcedUnwind(_Unwind_Exception *exception_object,85_Unwind_Stop_Fn stop, void *stop_parameter);86#endif8788#ifdef __USING_SJLJ_EXCEPTIONS__89typedef struct _Unwind_FunctionContext *_Unwind_FunctionContext_t;90extern void _Unwind_SjLj_Register(_Unwind_FunctionContext_t fc);91extern void _Unwind_SjLj_Unregister(_Unwind_FunctionContext_t fc);92#endif9394//95// The following are semi-supported extensions to the C++ ABI96//9798//99// called by __cxa_rethrow().100//101#ifdef __USING_SJLJ_EXCEPTIONS__102extern _Unwind_Reason_Code103_Unwind_SjLj_Resume_or_Rethrow(_Unwind_Exception *exception_object);104#else105extern _Unwind_Reason_Code106_Unwind_Resume_or_Rethrow(_Unwind_Exception *exception_object);107#endif108109// _Unwind_Backtrace() is a gcc extension that walks the stack and calls the110// _Unwind_Trace_Fn once per frame until it reaches the bottom of the stack111// or the _Unwind_Trace_Fn function returns something other than _URC_NO_REASON.112typedef _Unwind_Reason_Code (*_Unwind_Trace_Fn)(struct _Unwind_Context *,113void *);114extern _Unwind_Reason_Code _Unwind_Backtrace(_Unwind_Trace_Fn, void *);115116// _Unwind_GetCFA is a gcc extension that can be called from within a117// personality handler to get the CFA (stack pointer before call) of118// current frame.119extern uintptr_t _Unwind_GetCFA(struct _Unwind_Context *);120121122// _Unwind_GetIPInfo is a gcc extension that can be called from within a123// personality handler. Similar to _Unwind_GetIP() but also returns in124// *ipBefore a non-zero value if the instruction pointer is at or before the125// instruction causing the unwind. Normally, in a function call, the IP returned126// is the return address which is after the call instruction and may be past the127// end of the function containing the call instruction.128extern uintptr_t _Unwind_GetIPInfo(struct _Unwind_Context *context,129int *ipBefore);130131132// __register_frame() is used with dynamically generated code to register the133// FDE for a generated (JIT) code. The FDE must use pc-rel addressing to point134// to its function and optional LSDA.135// __register_frame() has existed in all versions of Mac OS X, but in 10.4 and136// 10.5 it was buggy and did not actually register the FDE with the unwinder.137// In 10.6 and later it does register properly.138extern void __register_frame(const void *fde);139extern void __deregister_frame(const void *fde);140141// _Unwind_Find_FDE() will locate the FDE if the pc is in some function that has142// an associated FDE. Note, Mac OS X 10.6 and later, introduces "compact unwind143// info" which the runtime uses in preference to DWARF unwind info. This144// function will only work if the target function has an FDE but no compact145// unwind info.146struct dwarf_eh_bases {147uintptr_t tbase;148uintptr_t dbase;149uintptr_t func;150};151extern const void *_Unwind_Find_FDE(const void *pc, struct dwarf_eh_bases *);152153154// This function attempts to find the start (address of first instruction) of155// a function given an address inside the function. It only works if the156// function has an FDE (DWARF unwind info).157// This function is unimplemented on Mac OS X 10.6 and later. Instead, use158// _Unwind_Find_FDE() and look at the dwarf_eh_bases.func result.159extern void *_Unwind_FindEnclosingFunction(void *pc);160161// Mac OS X does not support text-rel and data-rel addressing so these functions162// are unimplemented.163extern uintptr_t _Unwind_GetDataRelBase(struct _Unwind_Context *context)164LIBUNWIND_UNAVAIL;165extern uintptr_t _Unwind_GetTextRelBase(struct _Unwind_Context *context)166LIBUNWIND_UNAVAIL;167168// Mac OS X 10.4 and 10.5 had implementations of these functions in169// libgcc_s.dylib, but they never worked.170/// These functions are no longer available on Mac OS X.171extern void __register_frame_info_bases(const void *fde, void *ob, void *tb,172void *db) LIBUNWIND_UNAVAIL;173extern void __register_frame_info(const void *fde, void *ob)174LIBUNWIND_UNAVAIL;175extern void __register_frame_info_table_bases(const void *fde, void *ob,176void *tb, void *db)177LIBUNWIND_UNAVAIL;178extern void __register_frame_info_table(const void *fde, void *ob)179LIBUNWIND_UNAVAIL;180extern void __register_frame_table(const void *fde)181LIBUNWIND_UNAVAIL;182extern void *__deregister_frame_info(const void *fde)183LIBUNWIND_UNAVAIL;184extern void *__deregister_frame_info_bases(const void *fde)185LIBUNWIND_UNAVAIL;186187#if defined(__SEH__) && !defined(__USING_SJLJ_EXCEPTIONS__)188#ifndef _WIN32189typedef struct _EXCEPTION_RECORD EXCEPTION_RECORD;190typedef struct _CONTEXT CONTEXT;191typedef struct _DISPATCHER_CONTEXT DISPATCHER_CONTEXT;192#elif !defined(__MINGW32__) && VER_PRODUCTBUILD < 8000193typedef struct _DISPATCHER_CONTEXT DISPATCHER_CONTEXT;194#endif195// This is the common wrapper for GCC-style personality functions with SEH.196extern EXCEPTION_DISPOSITION _GCC_specific_handler(EXCEPTION_RECORD *exc,197void *frame, CONTEXT *ctx,198DISPATCHER_CONTEXT *disp,199_Unwind_Personality_Fn pers);200#endif201202#ifdef __cplusplus203}204#endif205206#endif // __UNWIND_H__207208209