Home | History | Annotate | Download | only in include
      1 /* libunwind - a platform-independent unwind library
      2    Copyright (C) 2003 Hewlett-Packard Co
      3 	Contributed by David Mosberger-Tang <davidm (at) hpl.hp.com>
      4 
      5 This file is part of libunwind.
      6 
      7 Permission is hereby granted, free of charge, to any person obtaining
      8 a copy of this software and associated documentation files (the
      9 "Software"), to deal in the Software without restriction, including
     10 without limitation the rights to use, copy, modify, merge, publish,
     11 distribute, sublicense, and/or sell copies of the Software, and to
     12 permit persons to whom the Software is furnished to do so, subject to
     13 the following conditions:
     14 
     15 The above copyright notice and this permission notice shall be
     16 included in all copies or substantial portions of the Software.
     17 
     18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
     19 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
     20 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
     21 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
     22 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
     23 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
     24 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.  */
     25 
     26 #ifndef _UNWIND_H
     27 #define _UNWIND_H
     28 
     29 /* For uint64_t */
     30 #include <stdint.h>
     31 
     32 #ifdef __cplusplus
     33 extern "C" {
     34 #endif
     35 
     36 /* Minimal interface as per C++ ABI draft standard:
     37 
     38 	http://www.codesourcery.com/cxx-abi/abi-eh.html */
     39 
     40 typedef enum
     41   {
     42     _URC_NO_REASON = 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 = 8
     51   }
     52 _Unwind_Reason_Code;
     53 
     54 typedef int _Unwind_Action;
     55 
     56 #define _UA_SEARCH_PHASE	1
     57 #define _UA_CLEANUP_PHASE	2
     58 #define _UA_HANDLER_FRAME	4
     59 #define _UA_FORCE_UNWIND	8
     60 
     61 struct _Unwind_Context;		/* opaque data-structure */
     62 struct _Unwind_Exception;	/* forward-declaration */
     63 
     64 typedef void (*_Unwind_Exception_Cleanup_Fn) (_Unwind_Reason_Code,
     65 					      struct _Unwind_Exception *);
     66 
     67 typedef _Unwind_Reason_Code (*_Unwind_Stop_Fn) (int, _Unwind_Action,
     68 						uint64_t,
     69 						struct _Unwind_Exception *,
     70 						struct _Unwind_Context *,
     71 						void *);
     72 
     73 /* The C++ ABI requires exception_class, private_1, and private_2 to
     74    be of type uint64 and the entire structure to be
     75    double-word-aligned. Please note that exception_class stays 64-bit
     76    even on 32-bit machines for gcc compatibility.  */
     77 struct _Unwind_Exception
     78   {
     79     uint64_t exception_class;
     80     _Unwind_Exception_Cleanup_Fn exception_cleanup;
     81     unsigned long private_1;
     82     unsigned long private_2;
     83   } __attribute__((__aligned__));
     84 
     85 extern _Unwind_Reason_Code _Unwind_RaiseException (struct _Unwind_Exception *);
     86 extern _Unwind_Reason_Code _Unwind_ForcedUnwind (struct _Unwind_Exception *,
     87 						 _Unwind_Stop_Fn, void *);
     88 extern void _Unwind_Resume (struct _Unwind_Exception *);
     89 extern void _Unwind_DeleteException (struct _Unwind_Exception *);
     90 extern unsigned long _Unwind_GetGR (struct _Unwind_Context *, int);
     91 extern void _Unwind_SetGR (struct _Unwind_Context *, int, unsigned long);
     92 extern unsigned long _Unwind_GetIP (struct _Unwind_Context *);
     93 extern unsigned long _Unwind_GetIPInfo (struct _Unwind_Context *, int *);
     94 extern void _Unwind_SetIP (struct _Unwind_Context *, unsigned long);
     95 extern unsigned long _Unwind_GetLanguageSpecificData (struct _Unwind_Context*);
     96 extern 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. */
    102 typedef _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().  */
    112 extern _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.  */
    117 extern unsigned long _Unwind_GetBSP (struct _Unwind_Context *);
    118 
    119 /* Return the "canonical frame address" for the given context.
    120    This is used by NPTL... */
    121 extern unsigned long _Unwind_GetCFA (struct _Unwind_Context *);
    122 
    123 /* Return the base-address for data references.  */
    124 extern unsigned long _Unwind_GetDataRelBase (struct _Unwind_Context *);
    125 
    126 /* Return the base-address for text references.  */
    127 extern 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.  */
    135 extern _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.  */
    143 extern 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