1*4684ddb6SLionel Sambuc /* libunwind - a platform-independent unwind library 2*4684ddb6SLionel Sambuc Copyright (C) 2003 Hewlett-Packard Co 3*4684ddb6SLionel Sambuc Contributed by David Mosberger-Tang <davidm@hpl.hp.com> 4*4684ddb6SLionel Sambuc 5*4684ddb6SLionel Sambuc This file is part of libunwind. 6*4684ddb6SLionel Sambuc 7*4684ddb6SLionel Sambuc Permission is hereby granted, free of charge, to any person obtaining 8*4684ddb6SLionel Sambuc a copy of this software and associated documentation files (the 9*4684ddb6SLionel Sambuc "Software"), to deal in the Software without restriction, including 10*4684ddb6SLionel Sambuc without limitation the rights to use, copy, modify, merge, publish, 11*4684ddb6SLionel Sambuc distribute, sublicense, and/or sell copies of the Software, and to 12*4684ddb6SLionel Sambuc permit persons to whom the Software is furnished to do so, subject to 13*4684ddb6SLionel Sambuc the following conditions: 14*4684ddb6SLionel Sambuc 15*4684ddb6SLionel Sambuc The above copyright notice and this permission notice shall be 16*4684ddb6SLionel Sambuc included in all copies or substantial portions of the Software. 17*4684ddb6SLionel Sambuc 18*4684ddb6SLionel Sambuc THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 19*4684ddb6SLionel Sambuc EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20*4684ddb6SLionel Sambuc MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 21*4684ddb6SLionel Sambuc NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 22*4684ddb6SLionel Sambuc LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 23*4684ddb6SLionel Sambuc OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 24*4684ddb6SLionel Sambuc WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 25*4684ddb6SLionel Sambuc 26*4684ddb6SLionel Sambuc #ifndef _UNWIND_H 27*4684ddb6SLionel Sambuc #define _UNWIND_H 28*4684ddb6SLionel Sambuc 29*4684ddb6SLionel Sambuc /* For uint64_t */ 30*4684ddb6SLionel Sambuc #include <stdint.h> 31*4684ddb6SLionel Sambuc 32*4684ddb6SLionel Sambuc #ifdef __cplusplus 33*4684ddb6SLionel Sambuc extern "C" { 34*4684ddb6SLionel Sambuc #endif 35*4684ddb6SLionel Sambuc 36*4684ddb6SLionel Sambuc /* Minimal interface as per C++ ABI draft standard: 37*4684ddb6SLionel Sambuc 38*4684ddb6SLionel Sambuc http://www.codesourcery.com/cxx-abi/abi-eh.html */ 39*4684ddb6SLionel Sambuc 40*4684ddb6SLionel Sambuc typedef enum 41*4684ddb6SLionel Sambuc { 42*4684ddb6SLionel Sambuc _URC_NO_REASON = 0, 43*4684ddb6SLionel Sambuc _URC_FOREIGN_EXCEPTION_CAUGHT = 1, 44*4684ddb6SLionel Sambuc _URC_FATAL_PHASE2_ERROR = 2, 45*4684ddb6SLionel Sambuc _URC_FATAL_PHASE1_ERROR = 3, 46*4684ddb6SLionel Sambuc _URC_NORMAL_STOP = 4, 47*4684ddb6SLionel Sambuc _URC_END_OF_STACK = 5, 48*4684ddb6SLionel Sambuc _URC_HANDLER_FOUND = 6, 49*4684ddb6SLionel Sambuc _URC_INSTALL_CONTEXT = 7, 50*4684ddb6SLionel Sambuc _URC_CONTINUE_UNWIND = 8 51*4684ddb6SLionel Sambuc } 52*4684ddb6SLionel Sambuc _Unwind_Reason_Code; 53*4684ddb6SLionel Sambuc 54*4684ddb6SLionel Sambuc typedef int _Unwind_Action; 55*4684ddb6SLionel Sambuc 56*4684ddb6SLionel Sambuc #define _UA_SEARCH_PHASE 1 57*4684ddb6SLionel Sambuc #define _UA_CLEANUP_PHASE 2 58*4684ddb6SLionel Sambuc #define _UA_HANDLER_FRAME 4 59*4684ddb6SLionel Sambuc #define _UA_FORCE_UNWIND 8 60*4684ddb6SLionel Sambuc 61*4684ddb6SLionel Sambuc struct _Unwind_Context; /* opaque data-structure */ 62*4684ddb6SLionel Sambuc struct _Unwind_Exception; /* forward-declaration */ 63*4684ddb6SLionel Sambuc 64*4684ddb6SLionel Sambuc typedef void (*_Unwind_Exception_Cleanup_Fn) (_Unwind_Reason_Code, 65*4684ddb6SLionel Sambuc struct _Unwind_Exception *); 66*4684ddb6SLionel Sambuc 67*4684ddb6SLionel Sambuc typedef _Unwind_Reason_Code (*_Unwind_Stop_Fn) (int, _Unwind_Action, 68*4684ddb6SLionel Sambuc uint64_t, 69*4684ddb6SLionel Sambuc struct _Unwind_Exception *, 70*4684ddb6SLionel Sambuc struct _Unwind_Context *, 71*4684ddb6SLionel Sambuc void *); 72*4684ddb6SLionel Sambuc 73*4684ddb6SLionel Sambuc /* The C++ ABI requires exception_class, private_1, and private_2 to 74*4684ddb6SLionel Sambuc be of type uint64 and the entire structure to be 75*4684ddb6SLionel Sambuc double-word-aligned. Please note that exception_class stays 64-bit 76*4684ddb6SLionel Sambuc even on 32-bit machines for gcc compatibility. */ 77*4684ddb6SLionel Sambuc struct _Unwind_Exception 78*4684ddb6SLionel Sambuc { 79*4684ddb6SLionel Sambuc uint64_t exception_class; 80*4684ddb6SLionel Sambuc _Unwind_Exception_Cleanup_Fn exception_cleanup; 81*4684ddb6SLionel Sambuc unsigned long private_1; 82*4684ddb6SLionel Sambuc unsigned long private_2; 83*4684ddb6SLionel Sambuc } __attribute__((__aligned__)); 84*4684ddb6SLionel Sambuc 85*4684ddb6SLionel Sambuc extern _Unwind_Reason_Code _Unwind_RaiseException (struct _Unwind_Exception *); 86*4684ddb6SLionel Sambuc extern _Unwind_Reason_Code _Unwind_ForcedUnwind (struct _Unwind_Exception *, 87*4684ddb6SLionel Sambuc _Unwind_Stop_Fn, void *); 88*4684ddb6SLionel Sambuc extern void _Unwind_Resume (struct _Unwind_Exception *); 89*4684ddb6SLionel Sambuc extern void _Unwind_DeleteException (struct _Unwind_Exception *); 90*4684ddb6SLionel Sambuc extern unsigned long _Unwind_GetGR (struct _Unwind_Context *, int); 91*4684ddb6SLionel Sambuc extern void _Unwind_SetGR (struct _Unwind_Context *, int, unsigned long); 92*4684ddb6SLionel Sambuc extern unsigned long _Unwind_GetIP (struct _Unwind_Context *); 93*4684ddb6SLionel Sambuc extern unsigned long _Unwind_GetIPInfo (struct _Unwind_Context *, int *); 94*4684ddb6SLionel Sambuc extern void _Unwind_SetIP (struct _Unwind_Context *, unsigned long); 95*4684ddb6SLionel Sambuc extern unsigned long _Unwind_GetLanguageSpecificData (struct _Unwind_Context*); 96*4684ddb6SLionel Sambuc extern unsigned long _Unwind_GetRegionStart (struct _Unwind_Context *); 97*4684ddb6SLionel Sambuc 98*4684ddb6SLionel Sambuc #ifdef _GNU_SOURCE 99*4684ddb6SLionel Sambuc 100*4684ddb6SLionel Sambuc /* Callback for _Unwind_Backtrace(). The backtrace stops immediately 101*4684ddb6SLionel Sambuc if the callback returns any value other than _URC_NO_REASON. */ 102*4684ddb6SLionel Sambuc typedef _Unwind_Reason_Code (*_Unwind_Trace_Fn) (struct _Unwind_Context *, 103*4684ddb6SLionel Sambuc void *); 104*4684ddb6SLionel Sambuc 105*4684ddb6SLionel Sambuc /* See http://gcc.gnu.org/ml/gcc-patches/2001-09/msg00082.html for why 106*4684ddb6SLionel Sambuc _UA_END_OF_STACK exists. */ 107*4684ddb6SLionel Sambuc # define _UA_END_OF_STACK 16 108*4684ddb6SLionel Sambuc 109*4684ddb6SLionel Sambuc /* If the unwind was initiated due to a forced unwind, resume that 110*4684ddb6SLionel Sambuc operation, else re-raise the exception. This is used by 111*4684ddb6SLionel Sambuc __cxa_rethrow(). */ 112*4684ddb6SLionel Sambuc extern _Unwind_Reason_Code 113*4684ddb6SLionel Sambuc _Unwind_Resume_or_Rethrow (struct _Unwind_Exception *); 114*4684ddb6SLionel Sambuc 115*4684ddb6SLionel Sambuc /* See http://gcc.gnu.org/ml/gcc-patches/2003-09/msg00154.html for why 116*4684ddb6SLionel Sambuc _Unwind_GetBSP() exists. */ 117*4684ddb6SLionel Sambuc extern unsigned long _Unwind_GetBSP (struct _Unwind_Context *); 118*4684ddb6SLionel Sambuc 119*4684ddb6SLionel Sambuc /* Return the "canonical frame address" for the given context. 120*4684ddb6SLionel Sambuc This is used by NPTL... */ 121*4684ddb6SLionel Sambuc extern unsigned long _Unwind_GetCFA (struct _Unwind_Context *); 122*4684ddb6SLionel Sambuc 123*4684ddb6SLionel Sambuc /* Return the base-address for data references. */ 124*4684ddb6SLionel Sambuc extern unsigned long _Unwind_GetDataRelBase (struct _Unwind_Context *); 125*4684ddb6SLionel Sambuc 126*4684ddb6SLionel Sambuc /* Return the base-address for text references. */ 127*4684ddb6SLionel Sambuc extern unsigned long _Unwind_GetTextRelBase (struct _Unwind_Context *); 128*4684ddb6SLionel Sambuc 129*4684ddb6SLionel Sambuc /* Call _Unwind_Trace_Fn once for each stack-frame, without doing any 130*4684ddb6SLionel Sambuc cleanup. The first frame for which the callback is invoked is the 131*4684ddb6SLionel Sambuc one for the caller of _Unwind_Backtrace(). _Unwind_Backtrace() 132*4684ddb6SLionel Sambuc returns _URC_END_OF_STACK when the backtrace stopped due to 133*4684ddb6SLionel Sambuc reaching the end of the call-chain or _URC_FATAL_PHASE1_ERROR if it 134*4684ddb6SLionel Sambuc stops for any other reason. */ 135*4684ddb6SLionel Sambuc extern _Unwind_Reason_Code _Unwind_Backtrace (_Unwind_Trace_Fn, void *); 136*4684ddb6SLionel Sambuc 137*4684ddb6SLionel Sambuc /* Find the start-address of the procedure containing the specified IP 138*4684ddb6SLionel Sambuc or NULL if it cannot be found (e.g., because the function has no 139*4684ddb6SLionel Sambuc unwind info). Note: there is not necessarily a one-to-one 140*4684ddb6SLionel Sambuc correspondence between source-level functions and procedures: some 141*4684ddb6SLionel Sambuc functions don't have unwind-info and others are split into multiple 142*4684ddb6SLionel Sambuc procedures. */ 143*4684ddb6SLionel Sambuc extern void *_Unwind_FindEnclosingFunction (void *); 144*4684ddb6SLionel Sambuc 145*4684ddb6SLionel Sambuc /* See also Linux Standard Base Spec: 146*4684ddb6SLionel Sambuc http://www.linuxbase.org/spec/refspecs/LSB_1.3.0/gLSB/gLSB/libgcc-s.html */ 147*4684ddb6SLionel Sambuc 148*4684ddb6SLionel Sambuc #endif /* _GNU_SOURCE */ 149*4684ddb6SLionel Sambuc 150*4684ddb6SLionel Sambuc #define DECLARE_PERSONALITY_FUNCTION(name) \ 151*4684ddb6SLionel Sambuc _Unwind_Reason_Code name(int version,\ 152*4684ddb6SLionel Sambuc _Unwind_Action actions,\ 153*4684ddb6SLionel Sambuc uint64_t exceptionClass,\ 154*4684ddb6SLionel Sambuc struct _Unwind_Exception *exceptionObject,\ 155*4684ddb6SLionel Sambuc struct _Unwind_Context *context); 156*4684ddb6SLionel Sambuc #define BEGIN_PERSONALITY_FUNCTION(name) \ 157*4684ddb6SLionel Sambuc _Unwind_Reason_Code name(int version,\ 158*4684ddb6SLionel Sambuc _Unwind_Action actions,\ 159*4684ddb6SLionel Sambuc uint64_t exceptionClass,\ 160*4684ddb6SLionel Sambuc struct _Unwind_Exception *exceptionObject,\ 161*4684ddb6SLionel Sambuc struct _Unwind_Context *context)\ 162*4684ddb6SLionel Sambuc { 163*4684ddb6SLionel Sambuc 164*4684ddb6SLionel Sambuc #define CALL_PERSONALITY_FUNCTION(name) name(version, actions, exceptionClass, exceptionObject, context) 165*4684ddb6SLionel Sambuc 166*4684ddb6SLionel Sambuc #ifdef __cplusplus 167*4684ddb6SLionel Sambuc } 168*4684ddb6SLionel Sambuc #endif 169*4684ddb6SLionel Sambuc 170*4684ddb6SLionel Sambuc #endif /* _UNWIND_H */ 171