unwind.h revision 213288
1213288Sdavidxu/* $FreeBSD: head/include/unwind.h 213288 2010-09-30 01:25:54Z davidxu $ */ 2213288Sdavidxu 3213288Sdavidxu/* libunwind - a platform-independent unwind library 4213288Sdavidxu Copyright (C) 2003 Hewlett-Packard Co 5213288Sdavidxu Contributed by David Mosberger-Tang <davidm@hpl.hp.com> 6213288Sdavidxu 7213288SdavidxuThis file is part of libunwind. 8213288Sdavidxu 9213288SdavidxuPermission is hereby granted, free of charge, to any person obtaining 10213288Sdavidxua copy of this software and associated documentation files (the 11213288Sdavidxu"Software"), to deal in the Software without restriction, including 12213288Sdavidxuwithout limitation the rights to use, copy, modify, merge, publish, 13213288Sdavidxudistribute, sublicense, and/or sell copies of the Software, and to 14213288Sdavidxupermit persons to whom the Software is furnished to do so, subject to 15213288Sdavidxuthe following conditions: 16213288Sdavidxu 17213288SdavidxuThe above copyright notice and this permission notice shall be 18213288Sdavidxuincluded in all copies or substantial portions of the Software. 19213288Sdavidxu 20213288SdavidxuTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21213288SdavidxuEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22213288SdavidxuMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23213288SdavidxuNONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24213288SdavidxuLIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25213288SdavidxuOF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26213288SdavidxuWITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 27213288Sdavidxu 28213288Sdavidxu#ifndef _UNWIND_H 29213288Sdavidxu#define _UNWIND_H 30213288Sdavidxu 31213288Sdavidxu#ifdef __cplusplus 32213288Sdavidxuextern "C" { 33213288Sdavidxu#endif 34213288Sdavidxu 35213288Sdavidxu/* Minimal interface as per C++ ABI draft standard: 36213288Sdavidxu 37213288Sdavidxu http://www.codesourcery.com/cxx-abi/abi-eh.html */ 38213288Sdavidxu 39213288Sdavidxutypedef enum 40213288Sdavidxu { 41213288Sdavidxu _URC_NO_REASON = 0, 42213288Sdavidxu _URC_FOREIGN_EXCEPTION_CAUGHT = 1, 43213288Sdavidxu _URC_FATAL_PHASE2_ERROR = 2, 44213288Sdavidxu _URC_FATAL_PHASE1_ERROR = 3, 45213288Sdavidxu _URC_NORMAL_STOP = 4, 46213288Sdavidxu _URC_END_OF_STACK = 5, 47213288Sdavidxu _URC_HANDLER_FOUND = 6, 48213288Sdavidxu _URC_INSTALL_CONTEXT = 7, 49213288Sdavidxu _URC_CONTINUE_UNWIND = 8 50213288Sdavidxu } 51213288Sdavidxu_Unwind_Reason_Code; 52213288Sdavidxu 53213288Sdavidxutypedef int _Unwind_Action; 54213288Sdavidxu 55213288Sdavidxu#define _UA_SEARCH_PHASE 1 56213288Sdavidxu#define _UA_CLEANUP_PHASE 2 57213288Sdavidxu#define _UA_HANDLER_FRAME 4 58213288Sdavidxu#define _UA_FORCE_UNWIND 8 59213288Sdavidxu 60213288Sdavidxustruct _Unwind_Context; /* opaque data-structure */ 61213288Sdavidxustruct _Unwind_Exception; /* forward-declaration */ 62213288Sdavidxu 63213288Sdavidxutypedef void (*_Unwind_Exception_Cleanup_Fn) (_Unwind_Reason_Code, 64213288Sdavidxu struct _Unwind_Exception *); 65213288Sdavidxu 66213288Sdavidxutypedef _Unwind_Reason_Code (*_Unwind_Stop_Fn) (int, _Unwind_Action, 67213288Sdavidxu unsigned long, 68213288Sdavidxu struct _Unwind_Exception *, 69213288Sdavidxu struct _Unwind_Context *, 70213288Sdavidxu void *); 71213288Sdavidxu 72213288Sdavidxu/* The C++ ABI requires exception_class, private_1, and private_2 to 73213288Sdavidxu be of type uint64 and the entire structure to be 74213288Sdavidxu double-word-aligned, but that seems a bit overly IA-64-specific. 75213288Sdavidxu Using "unsigned long" instead should give us the desired effect on 76213288Sdavidxu IA-64, while being more general. */ 77213288Sdavidxustruct _Unwind_Exception 78213288Sdavidxu { 79213288Sdavidxu unsigned long exception_class; 80213288Sdavidxu _Unwind_Exception_Cleanup_Fn exception_cleanup; 81213288Sdavidxu unsigned long private_1; 82213288Sdavidxu unsigned long private_2; 83213288Sdavidxu }; 84213288Sdavidxu 85213288Sdavidxuextern _Unwind_Reason_Code _Unwind_RaiseException (struct _Unwind_Exception *); 86213288Sdavidxuextern _Unwind_Reason_Code _Unwind_ForcedUnwind (struct _Unwind_Exception *, 87213288Sdavidxu _Unwind_Stop_Fn, void *); 88213288Sdavidxuextern void _Unwind_Resume (struct _Unwind_Exception *); 89213288Sdavidxuextern void _Unwind_DeleteException (struct _Unwind_Exception *); 90213288Sdavidxuextern unsigned long _Unwind_GetGR (struct _Unwind_Context *, int); 91213288Sdavidxuextern void _Unwind_SetGR (struct _Unwind_Context *, int, unsigned long); 92213288Sdavidxuextern unsigned long _Unwind_GetIP (struct _Unwind_Context *); 93213288Sdavidxuextern unsigned long _Unwind_GetIPInfo (struct _Unwind_Context *, int *); 94213288Sdavidxuextern void _Unwind_SetIP (struct _Unwind_Context *, unsigned long); 95213288Sdavidxuextern unsigned long _Unwind_GetLanguageSpecificData (struct _Unwind_Context*); 96213288Sdavidxuextern unsigned long _Unwind_GetRegionStart (struct _Unwind_Context *); 97213288Sdavidxu 98213288Sdavidxu#ifdef _GNU_SOURCE 99213288Sdavidxu 100213288Sdavidxu/* Callback for _Unwind_Backtrace(). The backtrace stops immediately 101213288Sdavidxu if the callback returns any value other than _URC_NO_REASON. */ 102213288Sdavidxutypedef _Unwind_Reason_Code (*_Unwind_Trace_Fn) (struct _Unwind_Context *, 103213288Sdavidxu void *); 104213288Sdavidxu 105213288Sdavidxu/* See http://gcc.gnu.org/ml/gcc-patches/2001-09/msg00082.html for why 106213288Sdavidxu _UA_END_OF_STACK exists. */ 107213288Sdavidxu# define _UA_END_OF_STACK 16 108213288Sdavidxu 109213288Sdavidxu/* If the unwind was initiated due to a forced unwind, resume that 110213288Sdavidxu operation, else re-raise the exception. This is used by 111213288Sdavidxu __cxa_rethrow(). */ 112213288Sdavidxuextern _Unwind_Reason_Code 113213288Sdavidxu _Unwind_Resume_or_Rethrow (struct _Unwind_Exception *); 114213288Sdavidxu 115213288Sdavidxu/* See http://gcc.gnu.org/ml/gcc-patches/2003-09/msg00154.html for why 116213288Sdavidxu _Unwind_GetBSP() exists. */ 117213288Sdavidxuextern unsigned long _Unwind_GetBSP (struct _Unwind_Context *); 118213288Sdavidxu 119213288Sdavidxu/* Return the "canonical frame address" for the given context. 120213288Sdavidxu This is used by NPTL... */ 121213288Sdavidxuextern unsigned long _Unwind_GetCFA (struct _Unwind_Context *); 122213288Sdavidxu 123213288Sdavidxu/* Return the base-address for data references. */ 124213288Sdavidxuextern unsigned long _Unwind_GetDataRelBase (struct _Unwind_Context *); 125213288Sdavidxu 126213288Sdavidxu/* Return the base-address for text references. */ 127213288Sdavidxuextern unsigned long _Unwind_GetTextRelBase (struct _Unwind_Context *); 128213288Sdavidxu 129213288Sdavidxu/* Call _Unwind_Trace_Fn once for each stack-frame, without doing any 130213288Sdavidxu cleanup. The first frame for which the callback is invoked is the 131213288Sdavidxu one for the caller of _Unwind_Backtrace(). _Unwind_Backtrace() 132213288Sdavidxu returns _URC_END_OF_STACK when the backtrace stopped due to 133213288Sdavidxu reaching the end of the call-chain or _URC_FATAL_PHASE1_ERROR if it 134213288Sdavidxu stops for any other reason. */ 135213288Sdavidxuextern _Unwind_Reason_Code _Unwind_Backtrace (_Unwind_Trace_Fn, void *); 136213288Sdavidxu 137213288Sdavidxu/* Find the start-address of the procedure containing the specified IP 138213288Sdavidxu or NULL if it cannot be found (e.g., because the function has no 139213288Sdavidxu unwind info). Note: there is not necessarily a one-to-one 140213288Sdavidxu correspondence between source-level functions and procedures: some 141213288Sdavidxu functions don't have unwind-info and others are split into multiple 142213288Sdavidxu procedures. */ 143213288Sdavidxuextern void *_Unwind_FindEnclosingFunction (void *); 144213288Sdavidxu 145213288Sdavidxu/* See also Linux Standard Base Spec: 146213288Sdavidxu http://www.linuxbase.org/spec/refspecs/LSB_1.3.0/gLSB/gLSB/libgcc-s.html */ 147213288Sdavidxu 148213288Sdavidxu#endif /* _GNU_SOURCE */ 149213288Sdavidxu 150213288Sdavidxu#ifdef __cplusplus 151213288Sdavidxu}; 152213288Sdavidxu#endif 153213288Sdavidxu 154213288Sdavidxu#endif /* _UNWIND_H */ 155