/* libunwind - a platform-independent unwind library1Copyright (C) 2003 Hewlett-Packard Co2Contributed by David Mosberger-Tang <[email protected]>34This file is part of libunwind.56Permission is hereby granted, free of charge, to any person obtaining7a copy of this software and associated documentation files (the8"Software"), to deal in the Software without restriction, including9without limitation the rights to use, copy, modify, merge, publish,10distribute, sublicense, and/or sell copies of the Software, and to11permit persons to whom the Software is furnished to do so, subject to12the following conditions:1314The above copyright notice and this permission notice shall be15included in all copies or substantial portions of the Software.1617THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,18EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF19MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND20NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE21LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION22OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION23WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */2425#ifndef _UNWIND_H26#define _UNWIND_H2728/* For uint64_t */29#include <stdint.h>3031#ifdef __cplusplus32extern "C" {33#endif3435/* Minimal interface as per C++ ABI draft standard:3637http://www.codesourcery.com/cxx-abi/abi-eh.html */3839typedef enum40{41_URC_NO_REASON = 0,42_URC_OK = 0,43_URC_FOREIGN_EXCEPTION_CAUGHT = 1,44_URC_FATAL_PHASE2_ERROR = 2,45_URC_FATAL_PHASE1_ERROR = 3,46_URC_NORMAL_STOP = 4,47_URC_END_OF_STACK = 5,48_URC_HANDLER_FOUND = 6,49_URC_INSTALL_CONTEXT = 7,50_URC_CONTINUE_UNWIND = 851}52_Unwind_Reason_Code;5354typedef int _Unwind_Action;5556#define _UA_SEARCH_PHASE 157#define _UA_CLEANUP_PHASE 258#define _UA_HANDLER_FRAME 459#define _UA_FORCE_UNWIND 86061struct _Unwind_Context; /* opaque data-structure */62struct _Unwind_Exception; /* forward-declaration */6364typedef void (*_Unwind_Exception_Cleanup_Fn) (_Unwind_Reason_Code,65struct _Unwind_Exception *);6667typedef _Unwind_Reason_Code (*_Unwind_Stop_Fn) (int, _Unwind_Action,68uint64_t,69struct _Unwind_Exception *,70struct _Unwind_Context *,71void *);7273/* The C++ ABI requires exception_class, private_1, and private_2 to74be of type uint64 and the entire structure to be75double-word-aligned. Please note that exception_class stays 64-bit76even on 32-bit machines for gcc compatibility. */77struct _Unwind_Exception78{79uint64_t exception_class;80_Unwind_Exception_Cleanup_Fn exception_cleanup;81uintptr_t private_1;82uintptr_t private_2;83#if __SIZEOF_POINTER__ == 484uint32_t reserved[3];85#endif86} __attribute__((__aligned__));8788extern _Unwind_Reason_Code _Unwind_RaiseException (struct _Unwind_Exception *);89extern _Unwind_Reason_Code _Unwind_ForcedUnwind (struct _Unwind_Exception *,90_Unwind_Stop_Fn, void *);91extern void _Unwind_Resume (struct _Unwind_Exception *);92extern void _Unwind_DeleteException (struct _Unwind_Exception *);93extern unsigned long _Unwind_GetGR (struct _Unwind_Context *, int);94extern void _Unwind_SetGR (struct _Unwind_Context *, int, unsigned long);95extern unsigned long _Unwind_GetIP (struct _Unwind_Context *);96extern unsigned long _Unwind_GetIPInfo (struct _Unwind_Context *, int *);97extern void _Unwind_SetIP (struct _Unwind_Context *, unsigned long);98extern unsigned long _Unwind_GetLanguageSpecificData (struct _Unwind_Context*);99extern unsigned long _Unwind_GetRegionStart (struct _Unwind_Context *);100101#ifdef _GNU_SOURCE102103/* Callback for _Unwind_Backtrace(). The backtrace stops immediately104if the callback returns any value other than _URC_NO_REASON. */105typedef _Unwind_Reason_Code (*_Unwind_Trace_Fn) (struct _Unwind_Context *,106void *);107108/* See http://gcc.gnu.org/ml/gcc-patches/2001-09/msg00082.html for why109_UA_END_OF_STACK exists. */110# define _UA_END_OF_STACK 16111112/* If the unwind was initiated due to a forced unwind, resume that113operation, else re-raise the exception. This is used by114__cxa_rethrow(). */115extern _Unwind_Reason_Code116_Unwind_Resume_or_Rethrow (struct _Unwind_Exception *);117118/* See http://gcc.gnu.org/ml/gcc-patches/2003-09/msg00154.html for why119_Unwind_GetBSP() exists. */120extern unsigned long _Unwind_GetBSP (struct _Unwind_Context *);121122/* Return the "canonical frame address" for the given context.123This is used by NPTL... */124extern unsigned long _Unwind_GetCFA (struct _Unwind_Context *);125126/* Return the base-address for data references. */127extern unsigned long _Unwind_GetDataRelBase (struct _Unwind_Context *);128129/* Return the base-address for text references. */130extern unsigned long _Unwind_GetTextRelBase (struct _Unwind_Context *);131132/* Call _Unwind_Trace_Fn once for each stack-frame, without doing any133cleanup. The first frame for which the callback is invoked is the134one for the caller of _Unwind_Backtrace(). _Unwind_Backtrace()135returns _URC_END_OF_STACK when the backtrace stopped due to136reaching the end of the call-chain or _URC_FATAL_PHASE1_ERROR if it137stops for any other reason. */138extern _Unwind_Reason_Code _Unwind_Backtrace (_Unwind_Trace_Fn, void *);139140/* Find the start-address of the procedure containing the specified IP141or NULL if it cannot be found (e.g., because the function has no142unwind info). Note: there is not necessarily a one-to-one143correspondence between source-level functions and procedures: some144functions don't have unwind-info and others are split into multiple145procedures. */146extern void *_Unwind_FindEnclosingFunction (void *);147148/* See also Linux Standard Base Spec:149http://www.linuxbase.org/spec/refspecs/LSB_1.3.0/gLSB/gLSB/libgcc-s.html */150151#endif /* _GNU_SOURCE */152153#define DECLARE_PERSONALITY_FUNCTION(name) \154_Unwind_Reason_Code name(int version,\155_Unwind_Action actions,\156uint64_t exceptionClass,\157struct _Unwind_Exception *exceptionObject,\158struct _Unwind_Context *context);159#define BEGIN_PERSONALITY_FUNCTION(name) \160_Unwind_Reason_Code name(int version,\161_Unwind_Action actions,\162uint64_t exceptionClass,\163struct _Unwind_Exception *exceptionObject,\164struct _Unwind_Context *context)\165{166167#define CALL_PERSONALITY_FUNCTION(name) name(version, actions, exceptionClass, exceptionObject, context)168169#ifdef __cplusplus170}171#endif172173#endif /* _UNWIND_H */174175176