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