Back to index

glibc  2.9
unwind.h
Go to the documentation of this file.
00001 /* Exception handling and frame unwind runtime interface routines.
00002    Copyright (C) 2001, 2003 Free Software Foundation, Inc.
00003 
00004    This file is part of the GNU C Library.
00005 
00006    The GNU C Library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Lesser General Public
00008    License as published by the Free Software Foundation; either
00009    version 2.1 of the License, or (at your option) any later version.
00010 
00011    The GNU C Library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Lesser General Public License for more details.
00015 
00016    You should have received a copy of the GNU Lesser General Public
00017    License along with the GNU C Library; if not, write to the Free
00018    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00019    02111-1307 USA.  */
00020 
00021 /* This is derived from the C++ ABI for IA-64.  Where we diverge
00022    for cross-architecture compatibility are noted with "@@@".  */
00023 
00024 #ifndef _UNWIND_H
00025 #define _UNWIND_H    1
00026 
00027 #ifdef __cplusplus
00028 extern "C" {
00029 #endif
00030 
00031 /* Level 1: Base ABI  */
00032 
00033 /* @@@ The IA-64 ABI uses uint64 throughout.  Most places this is
00034    inefficient for 32-bit and smaller machines.  */
00035 typedef unsigned _Unwind_Word __attribute__((__mode__(__word__)));
00036 typedef signed _Unwind_Sword __attribute__((__mode__(__word__)));
00037 #if defined(__ia64__) && defined(__hpux__)
00038 typedef unsigned _Unwind_Ptr __attribute__((__mode__(__word__)));
00039 #else
00040 typedef unsigned _Unwind_Ptr __attribute__((__mode__(__pointer__)));
00041 #endif
00042 typedef unsigned _Unwind_Internal_Ptr __attribute__((__mode__(__pointer__)));
00043 
00044 /* @@@ The IA-64 ABI uses a 64-bit word to identify the producer and
00045    consumer of an exception.  We'll go along with this for now even on
00046    32-bit machines.  We'll need to provide some other option for
00047    16-bit machines and for machines with > 8 bits per byte.  */
00048 typedef unsigned _Unwind_Exception_Class __attribute__((__mode__(__DI__)));
00049 
00050 /* The unwind interface uses reason codes in several contexts to
00051    identify the reasons for failures or other actions.  */
00052 typedef enum
00053 {
00054   _URC_NO_REASON = 0,
00055   _URC_FOREIGN_EXCEPTION_CAUGHT = 1,
00056   _URC_FATAL_PHASE2_ERROR = 2,
00057   _URC_FATAL_PHASE1_ERROR = 3,
00058   _URC_NORMAL_STOP = 4,
00059   _URC_END_OF_STACK = 5,
00060   _URC_HANDLER_FOUND = 6,
00061   _URC_INSTALL_CONTEXT = 7,
00062   _URC_CONTINUE_UNWIND = 8
00063 } _Unwind_Reason_Code;
00064 
00065 
00066 /* The unwind interface uses a pointer to an exception header object
00067    as its representation of an exception being thrown. In general, the
00068    full representation of an exception object is language- and
00069    implementation-specific, but it will be prefixed by a header
00070    understood by the unwind interface.  */
00071 
00072 struct _Unwind_Exception;
00073 
00074 typedef void (*_Unwind_Exception_Cleanup_Fn) (_Unwind_Reason_Code,
00075                                          struct _Unwind_Exception *);
00076 
00077 struct _Unwind_Exception
00078 {
00079   _Unwind_Exception_Class exception_class;
00080   _Unwind_Exception_Cleanup_Fn exception_cleanup;
00081   _Unwind_Word private_1;
00082   _Unwind_Word private_2;
00083 
00084   /* @@@ The IA-64 ABI says that this structure must be double-word aligned.
00085      Taking that literally does not make much sense generically.  Instead we
00086      provide the maximum alignment required by any type for the machine.  */
00087 } __attribute__((__aligned__));
00088 
00089 
00090 /* The ACTIONS argument to the personality routine is a bitwise OR of one
00091    or more of the following constants.  */
00092 typedef int _Unwind_Action;
00093 
00094 #define _UA_SEARCH_PHASE    1
00095 #define _UA_CLEANUP_PHASE   2
00096 #define _UA_HANDLER_FRAME   4
00097 #define _UA_FORCE_UNWIND    8
00098 #define _UA_END_OF_STACK    16
00099 
00100 /* This is an opaque type used to refer to a system-specific data
00101    structure used by the system unwinder. This context is created and
00102    destroyed by the system, and passed to the personality routine
00103    during unwinding.  */
00104 struct _Unwind_Context;
00105 
00106 /* Raise an exception, passing along the given exception object.  */
00107 extern _Unwind_Reason_Code _Unwind_RaiseException (struct _Unwind_Exception *);
00108 
00109 /* Raise an exception for forced unwinding.  */
00110 
00111 typedef _Unwind_Reason_Code (*_Unwind_Stop_Fn)
00112      (int, _Unwind_Action, _Unwind_Exception_Class,
00113       struct _Unwind_Exception *, struct _Unwind_Context *, void *);
00114 
00115 extern _Unwind_Reason_Code _Unwind_ForcedUnwind (struct _Unwind_Exception *,
00116                                            _Unwind_Stop_Fn,
00117                                            void *);
00118 
00119 /* Helper to invoke the exception_cleanup routine.  */
00120 extern void _Unwind_DeleteException (struct _Unwind_Exception *);
00121 
00122 /* Resume propagation of an existing exception.  This is used after
00123    e.g. executing cleanup code, and not to implement rethrowing.  */
00124 extern void _Unwind_Resume (struct _Unwind_Exception *);
00125 
00126 /* @@@ Use unwind data to perform a stack backtrace.  The trace callback
00127    is called for every stack frame in the call chain, but no cleanup
00128    actions are performed.  */
00129 typedef _Unwind_Reason_Code (*_Unwind_Trace_Fn)
00130      (struct _Unwind_Context *, void *);
00131 
00132 extern _Unwind_Reason_Code _Unwind_Backtrace (_Unwind_Trace_Fn, void *);
00133 
00134 /* These functions are used for communicating information about the unwind
00135    context (i.e. the unwind descriptors and the user register state) between
00136    the unwind library and the personality routine and landing pad.  Only
00137    selected registers maybe manipulated.  */
00138 
00139 extern _Unwind_Word _Unwind_GetGR (struct _Unwind_Context *, int);
00140 extern void _Unwind_SetGR (struct _Unwind_Context *, int, _Unwind_Word);
00141 
00142 extern _Unwind_Ptr _Unwind_GetIP (struct _Unwind_Context *);
00143 extern void _Unwind_SetIP (struct _Unwind_Context *, _Unwind_Ptr);
00144 
00145 /* @@@ Retrieve the CFA of the given context.  */
00146 extern _Unwind_Word _Unwind_GetCFA (struct _Unwind_Context *);
00147 
00148 extern void *_Unwind_GetLanguageSpecificData (struct _Unwind_Context *);
00149 
00150 extern _Unwind_Ptr _Unwind_GetRegionStart (struct _Unwind_Context *);
00151 
00152 
00153 /* The personality routine is the function in the C++ (or other language)
00154    runtime library which serves as an interface between the system unwind
00155    library and language-specific exception handling semantics.  It is
00156    specific to the code fragment described by an unwind info block, and
00157    it is always referenced via the pointer in the unwind info block, and
00158    hence it has no ABI-specified name.
00159 
00160    Note that this implies that two different C++ implementations can
00161    use different names, and have different contents in the language
00162    specific data area.  Moreover, that the language specific data
00163    area contains no version info because name of the function invoked
00164    provides more effective versioning by detecting at link time the
00165    lack of code to handle the different data format.  */
00166 
00167 typedef _Unwind_Reason_Code (*_Unwind_Personality_Fn)
00168      (int, _Unwind_Action, _Unwind_Exception_Class,
00169       struct _Unwind_Exception *, struct _Unwind_Context *);
00170 
00171 /* @@@ The following alternate entry points are for setjmp/longjmp
00172    based unwinding.  */
00173 
00174 struct SjLj_Function_Context;
00175 extern void _Unwind_SjLj_Register (struct SjLj_Function_Context *);
00176 extern void _Unwind_SjLj_Unregister (struct SjLj_Function_Context *);
00177 
00178 extern _Unwind_Reason_Code _Unwind_SjLj_RaiseException
00179      (struct _Unwind_Exception *);
00180 extern _Unwind_Reason_Code _Unwind_SjLj_ForcedUnwind
00181      (struct _Unwind_Exception *, _Unwind_Stop_Fn, void *);
00182 extern void _Unwind_SjLj_Resume (struct _Unwind_Exception *);
00183 
00184 /* @@@ The following provide access to the base addresses for text
00185    and data-relative addressing in the LDSA.  In order to stay link
00186    compatible with the standard ABI for IA-64, we inline these.  */
00187 
00188 #ifdef __ia64__
00189 #include <stdlib.h>
00190 
00191 static inline _Unwind_Ptr
00192 _Unwind_GetDataRelBase (struct _Unwind_Context *_C)
00193 {
00194   /* The GP is stored in R1.  */
00195   return _Unwind_GetGR (_C, 1);
00196 }
00197 
00198 static inline _Unwind_Ptr
00199 _Unwind_GetTextRelBase (struct _Unwind_Context *_C)
00200 {
00201   abort ();
00202   return 0;
00203 }
00204 
00205 /* @@@ Retrieve the Backing Store Pointer of the given context.  */
00206 extern _Unwind_Word _Unwind_GetBSP (struct _Unwind_Context *);
00207 #else
00208 extern _Unwind_Ptr _Unwind_GetDataRelBase (struct _Unwind_Context *);
00209 extern _Unwind_Ptr _Unwind_GetTextRelBase (struct _Unwind_Context *);
00210 #endif
00211 
00212 /* @@@ Given an address, return the entry point of the function that
00213    contains it.  */
00214 extern void * _Unwind_FindEnclosingFunction (void *pc);
00215 
00216 #ifdef __cplusplus
00217 }
00218 #endif
00219 
00220 #endif /* unwind.h */