unwind.h revision 752076789fdeec16827ddd846485182d4c3cd11f
1e853bb34ec1f86e12dcdaa9b5e782fac2117b08fFariborz Jahanian/* libunwind - a platform-independent unwind library
2e853bb34ec1f86e12dcdaa9b5e782fac2117b08fFariborz Jahanian   Copyright (C) 2003 Hewlett-Packard Co
3e853bb34ec1f86e12dcdaa9b5e782fac2117b08fFariborz Jahanian	Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
4e853bb34ec1f86e12dcdaa9b5e782fac2117b08fFariborz Jahanian
5e853bb34ec1f86e12dcdaa9b5e782fac2117b08fFariborz JahanianThis file is part of libunwind.
6e853bb34ec1f86e12dcdaa9b5e782fac2117b08fFariborz Jahanian
7e853bb34ec1f86e12dcdaa9b5e782fac2117b08fFariborz JahanianPermission is hereby granted, free of charge, to any person obtaining
8e853bb34ec1f86e12dcdaa9b5e782fac2117b08fFariborz Jahaniana copy of this software and associated documentation files (the
9e853bb34ec1f86e12dcdaa9b5e782fac2117b08fFariborz Jahanian"Software"), to deal in the Software without restriction, including
10e853bb34ec1f86e12dcdaa9b5e782fac2117b08fFariborz Jahanianwithout limitation the rights to use, copy, modify, merge, publish,
11a0e005b06b271f6dd1fdbbeed03d9e14f7f3e6a3Fariborz Jahaniandistribute, sublicense, and/or sell copies of the Software, and to
12a0e005b06b271f6dd1fdbbeed03d9e14f7f3e6a3Fariborz Jahanianpermit persons to whom the Software is furnished to do so, subject to
13e853bb34ec1f86e12dcdaa9b5e782fac2117b08fFariborz Jahanianthe 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_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
54typedef 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
61struct _Unwind_Context;		/* opaque data-structure */
62struct _Unwind_Exception;	/* forward-declaration */
63
64typedef void (*_Unwind_Exception_Cleanup_Fn) (_Unwind_Reason_Code,
65					      struct _Unwind_Exception *);
66
67typedef _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.  */
77struct _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
85extern _Unwind_Reason_Code _Unwind_RaiseException (struct _Unwind_Exception *);
86extern _Unwind_Reason_Code _Unwind_ForcedUnwind (struct _Unwind_Exception *,
87						 _Unwind_Stop_Fn, void *);
88extern void _Unwind_Resume (struct _Unwind_Exception *);
89extern void _Unwind_DeleteException (struct _Unwind_Exception *);
90extern unsigned long _Unwind_GetGR (struct _Unwind_Context *, int);
91extern void _Unwind_SetGR (struct _Unwind_Context *, int, unsigned long);
92extern unsigned long _Unwind_GetIP (struct _Unwind_Context *);
93extern unsigned long _Unwind_GetIPInfo (struct _Unwind_Context *, int *);
94extern void _Unwind_SetIP (struct _Unwind_Context *, unsigned long);
95extern unsigned long _Unwind_GetLanguageSpecificData (struct _Unwind_Context*);
96extern 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. */
102typedef _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().  */
112extern _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.  */
117extern unsigned long _Unwind_GetBSP (struct _Unwind_Context *);
118
119/* Return the "canonical frame address" for the given context.
120   This is used by NPTL... */
121extern unsigned long _Unwind_GetCFA (struct _Unwind_Context *);
122
123/* Return the base-address for data references.  */
124extern unsigned long _Unwind_GetDataRelBase (struct _Unwind_Context *);
125
126/* Return the base-address for text references.  */
127extern 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.  */
135extern _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.  */
143extern 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