unwind-itanium.h revision 369332
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
5This file is part of libunwind.
6
7Permission is hereby granted, free of charge, to any person obtaining
8a copy of this software and associated documentation files (the
9"Software"), to deal in the Software without restriction, including
10without limitation the rights to use, copy, modify, merge, publish,
11distribute, sublicense, and/or sell copies of the Software, and to
12permit persons to whom the Software is furnished to do so, subject to
13the following conditions:
14
15The above copyright notice and this permission notice shall be
16included in all copies or substantial portions of the Software.
17
18THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24WITH 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
33extern "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
40typedef 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
55typedef 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
62struct _Unwind_Context;		/* opaque data-structure */
63struct _Unwind_Exception;	/* forward-declaration */
64
65typedef void (*_Unwind_Exception_Cleanup_Fn) (_Unwind_Reason_Code,
66					      struct _Unwind_Exception *);
67
68typedef _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.  */
78struct _Unwind_Exception
79  {
80    uint64_t exception_class;
81    _Unwind_Exception_Cleanup_Fn exception_cleanup;
82    uintptr_t private_1;
83    uintptr_t private_2;
84#if __SIZEOF_POINTER__ == 4
85    uint32_t reserved[3];
86#endif
87  } __attribute__((__aligned__));
88
89extern _Unwind_Reason_Code _Unwind_RaiseException (struct _Unwind_Exception *);
90extern _Unwind_Reason_Code _Unwind_ForcedUnwind (struct _Unwind_Exception *,
91						 _Unwind_Stop_Fn, void *);
92extern void _Unwind_Resume (struct _Unwind_Exception *);
93extern void _Unwind_DeleteException (struct _Unwind_Exception *);
94extern unsigned long _Unwind_GetGR (struct _Unwind_Context *, int);
95extern void _Unwind_SetGR (struct _Unwind_Context *, int, unsigned long);
96extern unsigned long _Unwind_GetIP (struct _Unwind_Context *);
97extern unsigned long _Unwind_GetIPInfo (struct _Unwind_Context *, int *);
98extern void _Unwind_SetIP (struct _Unwind_Context *, unsigned long);
99extern unsigned long _Unwind_GetLanguageSpecificData (struct _Unwind_Context*);
100extern unsigned long _Unwind_GetRegionStart (struct _Unwind_Context *);
101
102#ifdef _GNU_SOURCE
103
104/* Callback for _Unwind_Backtrace().  The backtrace stops immediately
105   if the callback returns any value other than _URC_NO_REASON. */
106typedef _Unwind_Reason_Code (*_Unwind_Trace_Fn) (struct _Unwind_Context *,
107						 void *);
108
109/* See http://gcc.gnu.org/ml/gcc-patches/2001-09/msg00082.html for why
110   _UA_END_OF_STACK exists.  */
111# define _UA_END_OF_STACK	16
112
113/* If the unwind was initiated due to a forced unwind, resume that
114   operation, else re-raise the exception.  This is used by
115   __cxa_rethrow().  */
116extern _Unwind_Reason_Code
117	  _Unwind_Resume_or_Rethrow (struct _Unwind_Exception *);
118
119/* See http://gcc.gnu.org/ml/gcc-patches/2003-09/msg00154.html for why
120   _Unwind_GetBSP() exists.  */
121extern unsigned long _Unwind_GetBSP (struct _Unwind_Context *);
122
123/* Return the "canonical frame address" for the given context.
124   This is used by NPTL... */
125extern unsigned long _Unwind_GetCFA (struct _Unwind_Context *);
126
127/* Return the base-address for data references.  */
128extern unsigned long _Unwind_GetDataRelBase (struct _Unwind_Context *);
129
130/* Return the base-address for text references.  */
131extern unsigned long _Unwind_GetTextRelBase (struct _Unwind_Context *);
132
133/* Call _Unwind_Trace_Fn once for each stack-frame, without doing any
134   cleanup.  The first frame for which the callback is invoked is the
135   one for the caller of _Unwind_Backtrace().  _Unwind_Backtrace()
136   returns _URC_END_OF_STACK when the backtrace stopped due to
137   reaching the end of the call-chain or _URC_FATAL_PHASE1_ERROR if it
138   stops for any other reason.  */
139extern _Unwind_Reason_Code _Unwind_Backtrace (_Unwind_Trace_Fn, void *);
140
141/* Find the start-address of the procedure containing the specified IP
142   or NULL if it cannot be found (e.g., because the function has no
143   unwind info).  Note: there is not necessarily a one-to-one
144   correspondence between source-level functions and procedures: some
145   functions don't have unwind-info and others are split into multiple
146   procedures.  */
147extern void *_Unwind_FindEnclosingFunction (void *);
148
149/* See also Linux Standard Base Spec:
150    http://www.linuxbase.org/spec/refspecs/LSB_1.3.0/gLSB/gLSB/libgcc-s.html */
151
152#endif /* _GNU_SOURCE */
153
154#define DECLARE_PERSONALITY_FUNCTION(name) \
155_Unwind_Reason_Code name(int version,\
156                         _Unwind_Action actions,\
157                         uint64_t exceptionClass,\
158                         struct _Unwind_Exception *exceptionObject,\
159                         struct _Unwind_Context *context);
160#define BEGIN_PERSONALITY_FUNCTION(name) \
161_Unwind_Reason_Code name(int version,\
162                         _Unwind_Action actions,\
163                         uint64_t exceptionClass,\
164                         struct _Unwind_Exception *exceptionObject,\
165                         struct _Unwind_Context *context)\
166{
167
168#define CALL_PERSONALITY_FUNCTION(name) name(version, actions, exceptionClass, exceptionObject, context)
169
170#ifdef __cplusplus
171}
172#endif
173
174#endif /* _UNWIND_H */
175