1213288Sdavidxu/* $FreeBSD$ */
2213288Sdavidxu
3213288Sdavidxu/* libunwind - a platform-independent unwind library
4213288Sdavidxu   Copyright (C) 2003 Hewlett-Packard Co
5213288Sdavidxu	Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
6213288Sdavidxu
7213288SdavidxuThis file is part of libunwind.
8213288Sdavidxu
9213288SdavidxuPermission is hereby granted, free of charge, to any person obtaining
10213288Sdavidxua copy of this software and associated documentation files (the
11213288Sdavidxu"Software"), to deal in the Software without restriction, including
12213288Sdavidxuwithout limitation the rights to use, copy, modify, merge, publish,
13213288Sdavidxudistribute, sublicense, and/or sell copies of the Software, and to
14213288Sdavidxupermit persons to whom the Software is furnished to do so, subject to
15213288Sdavidxuthe following conditions:
16213288Sdavidxu
17213288SdavidxuThe above copyright notice and this permission notice shall be
18213288Sdavidxuincluded in all copies or substantial portions of the Software.
19213288Sdavidxu
20213288SdavidxuTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21213288SdavidxuEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22213288SdavidxuMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23213288SdavidxuNONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24213288SdavidxuLIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25213288SdavidxuOF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26213288SdavidxuWITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.  */
27213288Sdavidxu
28213288Sdavidxu#ifndef _UNWIND_H
29213288Sdavidxu#define _UNWIND_H
30213288Sdavidxu
31213289Sdavidxu#include <sys/_types.h>
32213289Sdavidxu
33213288Sdavidxu#ifdef __cplusplus
34213288Sdavidxuextern "C" {
35213288Sdavidxu#endif
36213288Sdavidxu
37213288Sdavidxu/* Minimal interface as per C++ ABI draft standard:
38213288Sdavidxu
39213288Sdavidxu	http://www.codesourcery.com/cxx-abi/abi-eh.html */
40213288Sdavidxu
41213288Sdavidxutypedef enum
42213288Sdavidxu  {
43213288Sdavidxu    _URC_NO_REASON = 0,
44213288Sdavidxu    _URC_FOREIGN_EXCEPTION_CAUGHT = 1,
45213288Sdavidxu    _URC_FATAL_PHASE2_ERROR = 2,
46213288Sdavidxu    _URC_FATAL_PHASE1_ERROR = 3,
47213288Sdavidxu    _URC_NORMAL_STOP = 4,
48213288Sdavidxu    _URC_END_OF_STACK = 5,
49213288Sdavidxu    _URC_HANDLER_FOUND = 6,
50213288Sdavidxu    _URC_INSTALL_CONTEXT = 7,
51213288Sdavidxu    _URC_CONTINUE_UNWIND = 8
52213288Sdavidxu  }
53213288Sdavidxu_Unwind_Reason_Code;
54213288Sdavidxu
55213288Sdavidxutypedef int _Unwind_Action;
56213288Sdavidxu
57213288Sdavidxu#define _UA_SEARCH_PHASE	1
58213288Sdavidxu#define _UA_CLEANUP_PHASE	2
59213288Sdavidxu#define _UA_HANDLER_FRAME	4
60213288Sdavidxu#define _UA_FORCE_UNWIND	8
61213288Sdavidxu
62213288Sdavidxustruct _Unwind_Context;		/* opaque data-structure */
63213288Sdavidxustruct _Unwind_Exception;	/* forward-declaration */
64213288Sdavidxu
65213288Sdavidxutypedef void (*_Unwind_Exception_Cleanup_Fn) (_Unwind_Reason_Code,
66213288Sdavidxu					      struct _Unwind_Exception *);
67213288Sdavidxu
68213288Sdavidxutypedef _Unwind_Reason_Code (*_Unwind_Stop_Fn) (int, _Unwind_Action,
69213290Sdavidxu						__int64_t,
70213288Sdavidxu						struct _Unwind_Exception *,
71213288Sdavidxu						struct _Unwind_Context *,
72213288Sdavidxu						void *);
73213288Sdavidxu
74213288Sdavidxu/* The C++ ABI requires exception_class, private_1, and private_2 to
75213288Sdavidxu   be of type uint64 and the entire structure to be
76213288Sdavidxu   double-word-aligned, but that seems a bit overly IA-64-specific.
77213288Sdavidxu   Using "unsigned long" instead should give us the desired effect on
78213288Sdavidxu   IA-64, while being more general.  */
79213288Sdavidxustruct _Unwind_Exception
80213288Sdavidxu  {
81213289Sdavidxu    __int64_t exception_class;
82213288Sdavidxu    _Unwind_Exception_Cleanup_Fn exception_cleanup;
83213288Sdavidxu    unsigned long private_1;
84213288Sdavidxu    unsigned long private_2;
85213288Sdavidxu  };
86213288Sdavidxu
87213288Sdavidxuextern _Unwind_Reason_Code _Unwind_RaiseException (struct _Unwind_Exception *);
88213288Sdavidxuextern _Unwind_Reason_Code _Unwind_ForcedUnwind (struct _Unwind_Exception *,
89213288Sdavidxu						 _Unwind_Stop_Fn, void *);
90213288Sdavidxuextern void _Unwind_Resume (struct _Unwind_Exception *);
91213288Sdavidxuextern void _Unwind_DeleteException (struct _Unwind_Exception *);
92213288Sdavidxuextern unsigned long _Unwind_GetGR (struct _Unwind_Context *, int);
93213288Sdavidxuextern void _Unwind_SetGR (struct _Unwind_Context *, int, unsigned long);
94213288Sdavidxuextern unsigned long _Unwind_GetIP (struct _Unwind_Context *);
95213288Sdavidxuextern unsigned long _Unwind_GetIPInfo (struct _Unwind_Context *, int *);
96213288Sdavidxuextern void _Unwind_SetIP (struct _Unwind_Context *, unsigned long);
97213288Sdavidxuextern unsigned long _Unwind_GetLanguageSpecificData (struct _Unwind_Context*);
98213288Sdavidxuextern unsigned long _Unwind_GetRegionStart (struct _Unwind_Context *);
99213288Sdavidxu
100213289Sdavidxu#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
101213288Sdavidxu
102213288Sdavidxu/* Callback for _Unwind_Backtrace().  The backtrace stops immediately
103213288Sdavidxu   if the callback returns any value other than _URC_NO_REASON. */
104213288Sdavidxutypedef _Unwind_Reason_Code (*_Unwind_Trace_Fn) (struct _Unwind_Context *,
105213288Sdavidxu						 void *);
106213288Sdavidxu
107213288Sdavidxu/* See http://gcc.gnu.org/ml/gcc-patches/2001-09/msg00082.html for why
108213288Sdavidxu   _UA_END_OF_STACK exists.  */
109213288Sdavidxu# define _UA_END_OF_STACK	16
110213288Sdavidxu
111213288Sdavidxu/* If the unwind was initiated due to a forced unwind, resume that
112213288Sdavidxu   operation, else re-raise the exception.  This is used by
113213288Sdavidxu   __cxa_rethrow().  */
114213288Sdavidxuextern _Unwind_Reason_Code
115213288Sdavidxu	  _Unwind_Resume_or_Rethrow (struct _Unwind_Exception *);
116213288Sdavidxu
117213288Sdavidxu/* See http://gcc.gnu.org/ml/gcc-patches/2003-09/msg00154.html for why
118213288Sdavidxu   _Unwind_GetBSP() exists.  */
119213288Sdavidxuextern unsigned long _Unwind_GetBSP (struct _Unwind_Context *);
120213288Sdavidxu
121213288Sdavidxu/* Return the "canonical frame address" for the given context.
122213288Sdavidxu   This is used by NPTL... */
123213288Sdavidxuextern unsigned long _Unwind_GetCFA (struct _Unwind_Context *);
124213288Sdavidxu
125213288Sdavidxu/* Return the base-address for data references.  */
126213288Sdavidxuextern unsigned long _Unwind_GetDataRelBase (struct _Unwind_Context *);
127213288Sdavidxu
128213288Sdavidxu/* Return the base-address for text references.  */
129213288Sdavidxuextern unsigned long _Unwind_GetTextRelBase (struct _Unwind_Context *);
130213288Sdavidxu
131213288Sdavidxu/* Call _Unwind_Trace_Fn once for each stack-frame, without doing any
132213288Sdavidxu   cleanup.  The first frame for which the callback is invoked is the
133213288Sdavidxu   one for the caller of _Unwind_Backtrace().  _Unwind_Backtrace()
134213288Sdavidxu   returns _URC_END_OF_STACK when the backtrace stopped due to
135213288Sdavidxu   reaching the end of the call-chain or _URC_FATAL_PHASE1_ERROR if it
136213288Sdavidxu   stops for any other reason.  */
137213288Sdavidxuextern _Unwind_Reason_Code _Unwind_Backtrace (_Unwind_Trace_Fn, void *);
138213288Sdavidxu
139213288Sdavidxu/* Find the start-address of the procedure containing the specified IP
140213288Sdavidxu   or NULL if it cannot be found (e.g., because the function has no
141213288Sdavidxu   unwind info).  Note: there is not necessarily a one-to-one
142213288Sdavidxu   correspondence between source-level functions and procedures: some
143213288Sdavidxu   functions don't have unwind-info and others are split into multiple
144213288Sdavidxu   procedures.  */
145213288Sdavidxuextern void *_Unwind_FindEnclosingFunction (void *);
146213288Sdavidxu
147213288Sdavidxu/* See also Linux Standard Base Spec:
148213288Sdavidxu    http://www.linuxbase.org/spec/refspecs/LSB_1.3.0/gLSB/gLSB/libgcc-s.html */
149213288Sdavidxu
150213289Sdavidxu#endif /* _GNU_SOURCE || _BSD_SOURCE */
151213288Sdavidxu
152213288Sdavidxu#ifdef __cplusplus
153213288Sdavidxu};
154213288Sdavidxu#endif
155213288Sdavidxu
156213288Sdavidxu#endif /* _UNWIND_H */
157