xref: /freebsd/contrib/libcxxrt/unwind-itanium.h (revision ae7e8a02e6e93455e026036132c4d053b2c12ad9)
1 /* libunwind - a platform-independent unwind library
2    Copyright (C) 2003 Hewlett-Packard Co
3 	Contributed by David Mosberger-Tang <davidm@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_OK = 0,
44     _URC_FOREIGN_EXCEPTION_CAUGHT = 1,
45     _URC_FATAL_PHASE2_ERROR = 2,
46     _URC_FATAL_PHASE1_ERROR = 3,
47     _URC_NORMAL_STOP = 4,
48     _URC_END_OF_STACK = 5,
49     _URC_HANDLER_FOUND = 6,
50     _URC_INSTALL_CONTEXT = 7,
51     _URC_CONTINUE_UNWIND = 8
52   }
53 _Unwind_Reason_Code;
54 
55 typedef int _Unwind_Action;
56 
57 #define _UA_SEARCH_PHASE	1
58 #define _UA_CLEANUP_PHASE	2
59 #define _UA_HANDLER_FRAME	4
60 #define _UA_FORCE_UNWIND	8
61 
62 struct _Unwind_Context;		/* opaque data-structure */
63 struct _Unwind_Exception;	/* forward-declaration */
64 
65 typedef void (*_Unwind_Exception_Cleanup_Fn) (_Unwind_Reason_Code,
66 					      struct _Unwind_Exception *);
67 
68 typedef _Unwind_Reason_Code (*_Unwind_Stop_Fn) (int, _Unwind_Action,
69 						uint64_t,
70 						struct _Unwind_Exception *,
71 						struct _Unwind_Context *,
72 						void *);
73 
74 /* The C++ ABI requires exception_class, private_1, and private_2 to
75    be of type uint64 and the entire structure to be
76    double-word-aligned. Please note that exception_class stays 64-bit
77    even on 32-bit machines for gcc compatibility.  */
78 struct _Unwind_Exception
79   {
80     uint64_t exception_class;
81     _Unwind_Exception_Cleanup_Fn exception_cleanup;
82     unsigned long private_1;
83     unsigned long private_2;
84   } ;
85 
86 extern _Unwind_Reason_Code _Unwind_RaiseException (struct _Unwind_Exception *);
87 extern _Unwind_Reason_Code _Unwind_ForcedUnwind (struct _Unwind_Exception *,
88 						 _Unwind_Stop_Fn, void *);
89 extern void _Unwind_Resume (struct _Unwind_Exception *);
90 extern void _Unwind_DeleteException (struct _Unwind_Exception *);
91 extern unsigned long _Unwind_GetGR (struct _Unwind_Context *, int);
92 extern void _Unwind_SetGR (struct _Unwind_Context *, int, unsigned long);
93 extern unsigned long _Unwind_GetIP (struct _Unwind_Context *);
94 extern unsigned long _Unwind_GetIPInfo (struct _Unwind_Context *, int *);
95 extern void _Unwind_SetIP (struct _Unwind_Context *, unsigned long);
96 extern unsigned long _Unwind_GetLanguageSpecificData (struct _Unwind_Context*);
97 extern unsigned long _Unwind_GetRegionStart (struct _Unwind_Context *);
98 
99 #ifdef _GNU_SOURCE
100 
101 /* Callback for _Unwind_Backtrace().  The backtrace stops immediately
102    if the callback returns any value other than _URC_NO_REASON. */
103 typedef _Unwind_Reason_Code (*_Unwind_Trace_Fn) (struct _Unwind_Context *,
104 						 void *);
105 
106 /* See http://gcc.gnu.org/ml/gcc-patches/2001-09/msg00082.html for why
107    _UA_END_OF_STACK exists.  */
108 # define _UA_END_OF_STACK	16
109 
110 /* If the unwind was initiated due to a forced unwind, resume that
111    operation, else re-raise the exception.  This is used by
112    __cxa_rethrow().  */
113 extern _Unwind_Reason_Code
114 	  _Unwind_Resume_or_Rethrow (struct _Unwind_Exception *);
115 
116 /* See http://gcc.gnu.org/ml/gcc-patches/2003-09/msg00154.html for why
117    _Unwind_GetBSP() exists.  */
118 extern unsigned long _Unwind_GetBSP (struct _Unwind_Context *);
119 
120 /* Return the "canonical frame address" for the given context.
121    This is used by NPTL... */
122 extern unsigned long _Unwind_GetCFA (struct _Unwind_Context *);
123 
124 /* Return the base-address for data references.  */
125 extern unsigned long _Unwind_GetDataRelBase (struct _Unwind_Context *);
126 
127 /* Return the base-address for text references.  */
128 extern unsigned long _Unwind_GetTextRelBase (struct _Unwind_Context *);
129 
130 /* Call _Unwind_Trace_Fn once for each stack-frame, without doing any
131    cleanup.  The first frame for which the callback is invoked is the
132    one for the caller of _Unwind_Backtrace().  _Unwind_Backtrace()
133    returns _URC_END_OF_STACK when the backtrace stopped due to
134    reaching the end of the call-chain or _URC_FATAL_PHASE1_ERROR if it
135    stops for any other reason.  */
136 extern _Unwind_Reason_Code _Unwind_Backtrace (_Unwind_Trace_Fn, void *);
137 
138 /* Find the start-address of the procedure containing the specified IP
139    or NULL if it cannot be found (e.g., because the function has no
140    unwind info).  Note: there is not necessarily a one-to-one
141    correspondence between source-level functions and procedures: some
142    functions don't have unwind-info and others are split into multiple
143    procedures.  */
144 extern void *_Unwind_FindEnclosingFunction (void *);
145 
146 /* See also Linux Standard Base Spec:
147     http://www.linuxbase.org/spec/refspecs/LSB_1.3.0/gLSB/gLSB/libgcc-s.html */
148 
149 #endif /* _GNU_SOURCE */
150 
151 #define DECLARE_PERSONALITY_FUNCTION(name) \
152 _Unwind_Reason_Code name(int version,\
153                          _Unwind_Action actions,\
154                          uint64_t exceptionClass,\
155                          struct _Unwind_Exception *exceptionObject,\
156                          struct _Unwind_Context *context);
157 #define BEGIN_PERSONALITY_FUNCTION(name) \
158 _Unwind_Reason_Code name(int version,\
159                          _Unwind_Action actions,\
160                          uint64_t exceptionClass,\
161                          struct _Unwind_Exception *exceptionObject,\
162                          struct _Unwind_Context *context)\
163 {
164 
165 #define CALL_PERSONALITY_FUNCTION(name) name(version, actions, exceptionClass, exceptionObject, context)
166 
167 #ifdef __cplusplus
168 }
169 #endif
170 
171 #endif /* _UNWIND_H */
172