1218887Sdim/* libunwind - a platform-independent unwind library 2218887Sdim Copyright (C) 2003 Hewlett-Packard Co 3218887Sdim Contributed by David Mosberger-Tang <davidm@hpl.hp.com> 4218887Sdim 5218887SdimThis file is part of libunwind. 6218887Sdim 7218887SdimPermission is hereby granted, free of charge, to any person obtaining 8218887Sdima copy of this software and associated documentation files (the 9218887Sdim"Software"), to deal in the Software without restriction, including 10218887Sdimwithout limitation the rights to use, copy, modify, merge, publish, 11218887Sdimdistribute, sublicense, and/or sell copies of the Software, and to 12218887Sdimpermit persons to whom the Software is furnished to do so, subject to 13218887Sdimthe following conditions: 14249423Sdim 15243830SdimThe above copyright notice and this permission notice shall be 16276479Sdimincluded in all copies or substantial portions of the Software. 17218887Sdim 18243830SdimTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 19218887SdimEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20249423SdimMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 21249423SdimNONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 22218887SdimLIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 23218887SdimOF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 24249423SdimWITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 25218887Sdim 26218887Sdim#ifndef _UNWIND_H 27276479Sdim#define _UNWIND_H 28218887Sdim 29218887Sdim/* For uint64_t */ 30226633Sdim#include <stdint.h> 31218887Sdim 32218887Sdim#ifdef __cplusplus 33234353Sdimextern "C" { 34218887Sdim#endif 35249423Sdim 36249423Sdim/* Minimal interface as per C++ ABI draft standard: 37249423Sdim 38239462Sdim http://www.codesourcery.com/cxx-abi/abi-eh.html */ 39218887Sdim 40288943Sdimtypedef enum 41218887Sdim { 42234353Sdim _URC_NO_REASON = 0, 43276479Sdim _URC_FOREIGN_EXCEPTION_CAUGHT = 1, 44276479Sdim _URC_FATAL_PHASE2_ERROR = 2, 45280031Sdim _URC_FATAL_PHASE1_ERROR = 3, 46218887Sdim _URC_NORMAL_STOP = 4, 47218887Sdim _URC_END_OF_STACK = 5, 48218887Sdim _URC_HANDLER_FOUND = 6, 49276479Sdim _URC_INSTALL_CONTEXT = 7, 50276479Sdim _URC_CONTINUE_UNWIND = 8 51276479Sdim } 52276479Sdim_Unwind_Reason_Code; 53276479Sdim 54234353Sdimtypedef int _Unwind_Action; 55234353Sdim 56218887Sdim#define _UA_SEARCH_PHASE 1 57218887Sdim#define _UA_CLEANUP_PHASE 2 58218887Sdim#define _UA_HANDLER_FRAME 4 59249423Sdim#define _UA_FORCE_UNWIND 8 60249423Sdim 61218887Sdimstruct _Unwind_Context; /* opaque data-structure */ 62239462Sdimstruct _Unwind_Exception; /* forward-declaration */ 63249423Sdim 64249423Sdimtypedef void (*_Unwind_Exception_Cleanup_Fn) (_Unwind_Reason_Code, 65234353Sdim struct _Unwind_Exception *); 66218887Sdim 67249423Sdimtypedef _Unwind_Reason_Code (*_Unwind_Stop_Fn) (int, _Unwind_Action, 68249423Sdim uint64_t, 69239462Sdim struct _Unwind_Exception *, 70239462Sdim struct _Unwind_Context *, 71249423Sdim void *); 72249423Sdim 73218887Sdim/* The C++ ABI requires exception_class, private_1, and private_2 to 74218887Sdim be of type uint64 and the entire structure to be 75249423Sdim double-word-aligned. Please note that exception_class stays 64-bit 76249423Sdim even on 32-bit machines for gcc compatibility. */ 77239462Sdimstruct _Unwind_Exception 78239462Sdim { 79249423Sdim uint64_t exception_class; 80249423Sdim _Unwind_Exception_Cleanup_Fn exception_cleanup; 81234353Sdim unsigned long private_1; 82234353Sdim unsigned long private_2; 83226633Sdim } ; 84218887Sdim 85218887Sdimextern _Unwind_Reason_Code _Unwind_RaiseException (struct _Unwind_Exception *); 86218887Sdimextern _Unwind_Reason_Code _Unwind_ForcedUnwind (struct _Unwind_Exception *, 87218887Sdim _Unwind_Stop_Fn, void *); 88218887Sdimextern void _Unwind_Resume (struct _Unwind_Exception *); 89218887Sdimextern void _Unwind_DeleteException (struct _Unwind_Exception *); 90218887Sdimextern unsigned long _Unwind_GetGR (struct _Unwind_Context *, int); 91218887Sdimextern void _Unwind_SetGR (struct _Unwind_Context *, int, unsigned long); 92218887Sdimextern unsigned long _Unwind_GetIP (struct _Unwind_Context *); 93218887Sdimextern unsigned long _Unwind_GetIPInfo (struct _Unwind_Context *, int *); 94218887Sdimextern void _Unwind_SetIP (struct _Unwind_Context *, unsigned long); 95218887Sdimextern unsigned long _Unwind_GetLanguageSpecificData (struct _Unwind_Context*); 96218887Sdimextern unsigned long _Unwind_GetRegionStart (struct _Unwind_Context *); 97218887Sdim 98218887Sdim#ifdef _GNU_SOURCE 99218887Sdim 100218887Sdim/* Callback for _Unwind_Backtrace(). The backtrace stops immediately 101218887Sdim if the callback returns any value other than _URC_NO_REASON. */ 102218887Sdimtypedef _Unwind_Reason_Code (*_Unwind_Trace_Fn) (struct _Unwind_Context *, 103218887Sdim void *); 104239462Sdim 105239462Sdim/* See http://gcc.gnu.org/ml/gcc-patches/2001-09/msg00082.html for why 106239462Sdim _UA_END_OF_STACK exists. */ 107239462Sdim# define _UA_END_OF_STACK 16 108218887Sdim 109288943Sdim/* If the unwind was initiated due to a forced unwind, resume that 110288943Sdim operation, else re-raise the exception. This is used by 111288943Sdim __cxa_rethrow(). */ 112276479Sdimextern _Unwind_Reason_Code 113239462Sdim _Unwind_Resume_or_Rethrow (struct _Unwind_Exception *); 114218887Sdim 115288943Sdim/* See http://gcc.gnu.org/ml/gcc-patches/2003-09/msg00154.html for why 116288943Sdim _Unwind_GetBSP() exists. */ 117276479Sdimextern unsigned long _Unwind_GetBSP (struct _Unwind_Context *); 118239462Sdim 119218887Sdim/* Return the "canonical frame address" for the given context. 120218887Sdim This is used by NPTL... */ 121218887Sdimextern unsigned long _Unwind_GetCFA (struct _Unwind_Context *); 122218887Sdim 123218887Sdim/* Return the base-address for data references. */ 124218887Sdimextern unsigned long _Unwind_GetDataRelBase (struct _Unwind_Context *); 125218887Sdim 126218887Sdim/* Return the base-address for text references. */ 127218887Sdimextern unsigned long _Unwind_GetTextRelBase (struct _Unwind_Context *); 128218887Sdim 129218887Sdim/* Call _Unwind_Trace_Fn once for each stack-frame, without doing any 130218887Sdim cleanup. The first frame for which the callback is invoked is the 131218887Sdim one for the caller of _Unwind_Backtrace(). _Unwind_Backtrace() 132218887Sdim returns _URC_END_OF_STACK when the backtrace stopped due to 133218887Sdim reaching the end of the call-chain or _URC_FATAL_PHASE1_ERROR if it 134218887Sdim stops for any other reason. */ 135218887Sdimextern _Unwind_Reason_Code _Unwind_Backtrace (_Unwind_Trace_Fn, void *); 136218887Sdim 137226633Sdim/* Find the start-address of the procedure containing the specified IP 138218887Sdim or NULL if it cannot be found (e.g., because the function has no 139218887Sdim unwind info). Note: there is not necessarily a one-to-one 140218887Sdim correspondence between source-level functions and procedures: some 141234353Sdim functions don't have unwind-info and others are split into multiple 142261991Sdim procedures. */ 143261991Sdimextern void *_Unwind_FindEnclosingFunction (void *); 144218887Sdim 145218887Sdim/* See also Linux Standard Base Spec: 146218887Sdim http://www.linuxbase.org/spec/refspecs/LSB_1.3.0/gLSB/gLSB/libgcc-s.html */ 147218887Sdim 148218887Sdim#endif /* _GNU_SOURCE */ 149218887Sdim 150261991Sdim#define DECLARE_PERSONALITY_FUNCTION(name) \ 151261991Sdim_Unwind_Reason_Code name(int version,\ 152261991Sdim _Unwind_Action actions,\ 153261991Sdim uint64_t exceptionClass,\ 154218887Sdim struct _Unwind_Exception *exceptionObject,\ 155218887Sdim struct _Unwind_Context *context); 156218887Sdim#define BEGIN_PERSONALITY_FUNCTION(name) \ 157218887Sdim_Unwind_Reason_Code name(int version,\ 158288943Sdim _Unwind_Action actions,\ 159218887Sdim uint64_t exceptionClass,\ 160218887Sdim struct _Unwind_Exception *exceptionObject,\ 161239462Sdim struct _Unwind_Context *context)\ 162218887Sdim{ 163239462Sdim 164218887Sdim#define CALL_PERSONALITY_FUNCTION(name) name(version, actions, exceptionClass, exceptionObject, context) 165218887Sdim 166218887Sdim#ifdef __cplusplus 167288943Sdim} 168288943Sdim#endif 169288943Sdim 170288943Sdim#endif /* _UNWIND_H */ 171218887Sdim