1227972Stheraven/* libunwind - a platform-independent unwind library
2227972Stheraven   Copyright (C) 2003 Hewlett-Packard Co
3227972Stheraven	Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
4227972Stheraven
5227972StheravenThis file is part of libunwind.
6227972Stheraven
7227972StheravenPermission is hereby granted, free of charge, to any person obtaining
8227972Stheravena copy of this software and associated documentation files (the
9227972Stheraven"Software"), to deal in the Software without restriction, including
10227972Stheravenwithout limitation the rights to use, copy, modify, merge, publish,
11227972Stheravendistribute, sublicense, and/or sell copies of the Software, and to
12227972Stheravenpermit persons to whom the Software is furnished to do so, subject to
13227972Stheraventhe following conditions:
14227972Stheraven
15227972StheravenThe above copyright notice and this permission notice shall be
16227972Stheravenincluded in all copies or substantial portions of the Software.
17227972Stheraven
18227972StheravenTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19227972StheravenEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20227972StheravenMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21227972StheravenNONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22227972StheravenLIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23227972StheravenOF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24227972StheravenWITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.  */
25227972Stheraven
26227972Stheraven#ifndef _UNWIND_H
27227972Stheraven#define _UNWIND_H
28227972Stheraven
29227972Stheraven/* For uint64_t */
30227972Stheraven#include <stdint.h>
31227972Stheraven
32227972Stheraven#ifdef __cplusplus
33227972Stheravenextern "C" {
34227972Stheraven#endif
35227972Stheraven
36227972Stheraven/* Minimal interface as per C++ ABI draft standard:
37227972Stheraven
38227972Stheraven	http://www.codesourcery.com/cxx-abi/abi-eh.html */
39227972Stheraven
40227972Stheraventypedef enum
41227972Stheraven  {
42227972Stheraven    _URC_NO_REASON = 0,
43227972Stheraven    _URC_FOREIGN_EXCEPTION_CAUGHT = 1,
44227972Stheraven    _URC_FATAL_PHASE2_ERROR = 2,
45227972Stheraven    _URC_FATAL_PHASE1_ERROR = 3,
46227972Stheraven    _URC_NORMAL_STOP = 4,
47227972Stheraven    _URC_END_OF_STACK = 5,
48227972Stheraven    _URC_HANDLER_FOUND = 6,
49227972Stheraven    _URC_INSTALL_CONTEXT = 7,
50227972Stheraven    _URC_CONTINUE_UNWIND = 8
51227972Stheraven  }
52227972Stheraven_Unwind_Reason_Code;
53227972Stheraven
54227972Stheraventypedef int _Unwind_Action;
55227972Stheraven
56227972Stheraven#define _UA_SEARCH_PHASE	1
57227972Stheraven#define _UA_CLEANUP_PHASE	2
58227972Stheraven#define _UA_HANDLER_FRAME	4
59227972Stheraven#define _UA_FORCE_UNWIND	8
60227972Stheraven
61227972Stheravenstruct _Unwind_Context;		/* opaque data-structure */
62227972Stheravenstruct _Unwind_Exception;	/* forward-declaration */
63227972Stheraven
64227972Stheraventypedef void (*_Unwind_Exception_Cleanup_Fn) (_Unwind_Reason_Code,
65227972Stheraven					      struct _Unwind_Exception *);
66227972Stheraven
67227972Stheraventypedef _Unwind_Reason_Code (*_Unwind_Stop_Fn) (int, _Unwind_Action,
68227972Stheraven						uint64_t,
69227972Stheraven						struct _Unwind_Exception *,
70227972Stheraven						struct _Unwind_Context *,
71227972Stheraven						void *);
72227972Stheraven
73227972Stheraven/* The C++ ABI requires exception_class, private_1, and private_2 to
74227972Stheraven   be of type uint64 and the entire structure to be
75227972Stheraven   double-word-aligned. Please note that exception_class stays 64-bit
76227972Stheraven   even on 32-bit machines for gcc compatibility.  */
77227972Stheravenstruct _Unwind_Exception
78227972Stheraven  {
79227972Stheraven    uint64_t exception_class;
80227972Stheraven    _Unwind_Exception_Cleanup_Fn exception_cleanup;
81227972Stheraven    unsigned long private_1;
82227972Stheraven    unsigned long private_2;
83261645Sdim  } ;
84227972Stheraven
85227972Stheravenextern _Unwind_Reason_Code _Unwind_RaiseException (struct _Unwind_Exception *);
86227972Stheravenextern _Unwind_Reason_Code _Unwind_ForcedUnwind (struct _Unwind_Exception *,
87227972Stheraven						 _Unwind_Stop_Fn, void *);
88227972Stheravenextern void _Unwind_Resume (struct _Unwind_Exception *);
89227972Stheravenextern void _Unwind_DeleteException (struct _Unwind_Exception *);
90227972Stheravenextern unsigned long _Unwind_GetGR (struct _Unwind_Context *, int);
91227972Stheravenextern void _Unwind_SetGR (struct _Unwind_Context *, int, unsigned long);
92227972Stheravenextern unsigned long _Unwind_GetIP (struct _Unwind_Context *);
93227972Stheravenextern unsigned long _Unwind_GetIPInfo (struct _Unwind_Context *, int *);
94227972Stheravenextern void _Unwind_SetIP (struct _Unwind_Context *, unsigned long);
95227972Stheravenextern unsigned long _Unwind_GetLanguageSpecificData (struct _Unwind_Context*);
96227972Stheravenextern unsigned long _Unwind_GetRegionStart (struct _Unwind_Context *);
97227972Stheraven
98227972Stheraven#ifdef _GNU_SOURCE
99227972Stheraven
100227972Stheraven/* Callback for _Unwind_Backtrace().  The backtrace stops immediately
101227972Stheraven   if the callback returns any value other than _URC_NO_REASON. */
102227972Stheraventypedef _Unwind_Reason_Code (*_Unwind_Trace_Fn) (struct _Unwind_Context *,
103227972Stheraven						 void *);
104227972Stheraven
105227972Stheraven/* See http://gcc.gnu.org/ml/gcc-patches/2001-09/msg00082.html for why
106227972Stheraven   _UA_END_OF_STACK exists.  */
107227972Stheraven# define _UA_END_OF_STACK	16
108227972Stheraven
109227972Stheraven/* If the unwind was initiated due to a forced unwind, resume that
110227972Stheraven   operation, else re-raise the exception.  This is used by
111227972Stheraven   __cxa_rethrow().  */
112227972Stheravenextern _Unwind_Reason_Code
113227972Stheraven	  _Unwind_Resume_or_Rethrow (struct _Unwind_Exception *);
114227972Stheraven
115227972Stheraven/* See http://gcc.gnu.org/ml/gcc-patches/2003-09/msg00154.html for why
116227972Stheraven   _Unwind_GetBSP() exists.  */
117227972Stheravenextern unsigned long _Unwind_GetBSP (struct _Unwind_Context *);
118227972Stheraven
119227972Stheraven/* Return the "canonical frame address" for the given context.
120227972Stheraven   This is used by NPTL... */
121227972Stheravenextern unsigned long _Unwind_GetCFA (struct _Unwind_Context *);
122227972Stheraven
123227972Stheraven/* Return the base-address for data references.  */
124227972Stheravenextern unsigned long _Unwind_GetDataRelBase (struct _Unwind_Context *);
125227972Stheraven
126227972Stheraven/* Return the base-address for text references.  */
127227972Stheravenextern unsigned long _Unwind_GetTextRelBase (struct _Unwind_Context *);
128227972Stheraven
129227972Stheraven/* Call _Unwind_Trace_Fn once for each stack-frame, without doing any
130227972Stheraven   cleanup.  The first frame for which the callback is invoked is the
131227972Stheraven   one for the caller of _Unwind_Backtrace().  _Unwind_Backtrace()
132227972Stheraven   returns _URC_END_OF_STACK when the backtrace stopped due to
133227972Stheraven   reaching the end of the call-chain or _URC_FATAL_PHASE1_ERROR if it
134227972Stheraven   stops for any other reason.  */
135227972Stheravenextern _Unwind_Reason_Code _Unwind_Backtrace (_Unwind_Trace_Fn, void *);
136227972Stheraven
137227972Stheraven/* Find the start-address of the procedure containing the specified IP
138227972Stheraven   or NULL if it cannot be found (e.g., because the function has no
139227972Stheraven   unwind info).  Note: there is not necessarily a one-to-one
140227972Stheraven   correspondence between source-level functions and procedures: some
141227972Stheraven   functions don't have unwind-info and others are split into multiple
142227972Stheraven   procedures.  */
143227972Stheravenextern void *_Unwind_FindEnclosingFunction (void *);
144227972Stheraven
145227972Stheraven/* See also Linux Standard Base Spec:
146227972Stheraven    http://www.linuxbase.org/spec/refspecs/LSB_1.3.0/gLSB/gLSB/libgcc-s.html */
147227972Stheraven
148227972Stheraven#endif /* _GNU_SOURCE */
149227972Stheraven
150227972Stheraven#define DECLARE_PERSONALITY_FUNCTION(name) \
151227972Stheraven_Unwind_Reason_Code name(int version,\
152227972Stheraven                         _Unwind_Action actions,\
153227972Stheraven                         uint64_t exceptionClass,\
154227972Stheraven                         struct _Unwind_Exception *exceptionObject,\
155227972Stheraven                         struct _Unwind_Context *context);
156227972Stheraven#define BEGIN_PERSONALITY_FUNCTION(name) \
157227972Stheraven_Unwind_Reason_Code name(int version,\
158227972Stheraven                         _Unwind_Action actions,\
159227972Stheraven                         uint64_t exceptionClass,\
160227972Stheraven                         struct _Unwind_Exception *exceptionObject,\
161227972Stheraven                         struct _Unwind_Context *context)\
162227972Stheraven{
163227972Stheraven
164227972Stheraven#define CALL_PERSONALITY_FUNCTION(name) name(version, actions, exceptionClass, exceptionObject, context)
165227972Stheraven
166227972Stheraven#ifdef __cplusplus
167227972Stheraven}
168227972Stheraven#endif
169227972Stheraven
170227972Stheraven#endif /* _UNWIND_H */
171