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