]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - include/unwind.h
MFC r368207,368607:
[FreeBSD/stable/10.git] / include / unwind.h
1 /* $FreeBSD$ */
2
3 /* libunwind - a platform-independent unwind library
4    Copyright (C) 2003 Hewlett-Packard Co
5         Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
6
7 This file is part of libunwind.
8
9 Permission is hereby granted, free of charge, to any person obtaining
10 a copy of this software and associated documentation files (the
11 "Software"), to deal in the Software without restriction, including
12 without limitation the rights to use, copy, modify, merge, publish,
13 distribute, sublicense, and/or sell copies of the Software, and to
14 permit persons to whom the Software is furnished to do so, subject to
15 the following conditions:
16
17 The above copyright notice and this permission notice shall be
18 included in all copies or substantial portions of the Software.
19
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.  */
27
28 #ifndef _UNWIND_H
29 #define _UNWIND_H
30
31 #include <sys/_types.h>
32
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36
37 /* Minimal interface as per C++ ABI draft standard:
38
39         http://www.codesourcery.com/cxx-abi/abi-eh.html */
40
41 typedef enum
42   {
43     _URC_NO_REASON = 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
55 typedef 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
62 struct _Unwind_Context;         /* opaque data-structure */
63 struct _Unwind_Exception;       /* forward-declaration */
64
65 typedef void (*_Unwind_Exception_Cleanup_Fn) (_Unwind_Reason_Code,
66                                               struct _Unwind_Exception *);
67
68 typedef _Unwind_Reason_Code (*_Unwind_Stop_Fn) (int, _Unwind_Action,
69                                                 __int64_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, but that seems a bit overly IA-64-specific.
77    Using "unsigned long" instead should give us the desired effect on
78    IA-64, while being more general.  */
79 struct _Unwind_Exception
80   {
81     __int64_t exception_class;
82     _Unwind_Exception_Cleanup_Fn exception_cleanup;
83     unsigned long private_1;
84     unsigned long private_2;
85   };
86
87 extern _Unwind_Reason_Code _Unwind_RaiseException (struct _Unwind_Exception *);
88 extern _Unwind_Reason_Code _Unwind_ForcedUnwind (struct _Unwind_Exception *,
89                                                  _Unwind_Stop_Fn, void *);
90 extern void _Unwind_Resume (struct _Unwind_Exception *);
91 extern void _Unwind_DeleteException (struct _Unwind_Exception *);
92 extern unsigned long _Unwind_GetGR (struct _Unwind_Context *, int);
93 extern void _Unwind_SetGR (struct _Unwind_Context *, int, unsigned long);
94 extern unsigned long _Unwind_GetIP (struct _Unwind_Context *);
95 extern unsigned long _Unwind_GetIPInfo (struct _Unwind_Context *, int *);
96 extern void _Unwind_SetIP (struct _Unwind_Context *, unsigned long);
97 extern unsigned long _Unwind_GetLanguageSpecificData (struct _Unwind_Context*);
98 extern unsigned long _Unwind_GetRegionStart (struct _Unwind_Context *);
99
100 #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
101
102 /* Callback for _Unwind_Backtrace().  The backtrace stops immediately
103    if the callback returns any value other than _URC_NO_REASON. */
104 typedef _Unwind_Reason_Code (*_Unwind_Trace_Fn) (struct _Unwind_Context *,
105                                                  void *);
106
107 /* See http://gcc.gnu.org/ml/gcc-patches/2001-09/msg00082.html for why
108    _UA_END_OF_STACK exists.  */
109 # define _UA_END_OF_STACK       16
110
111 /* If the unwind was initiated due to a forced unwind, resume that
112    operation, else re-raise the exception.  This is used by
113    __cxa_rethrow().  */
114 extern _Unwind_Reason_Code
115           _Unwind_Resume_or_Rethrow (struct _Unwind_Exception *);
116
117 /* See http://gcc.gnu.org/ml/gcc-patches/2003-09/msg00154.html for why
118    _Unwind_GetBSP() exists.  */
119 extern unsigned long _Unwind_GetBSP (struct _Unwind_Context *);
120
121 /* Return the "canonical frame address" for the given context.
122    This is used by NPTL... */
123 extern unsigned long _Unwind_GetCFA (struct _Unwind_Context *);
124
125 /* Return the base-address for data references.  */
126 extern unsigned long _Unwind_GetDataRelBase (struct _Unwind_Context *);
127
128 /* Return the base-address for text references.  */
129 extern unsigned long _Unwind_GetTextRelBase (struct _Unwind_Context *);
130
131 /* Call _Unwind_Trace_Fn once for each stack-frame, without doing any
132    cleanup.  The first frame for which the callback is invoked is the
133    one for the caller of _Unwind_Backtrace().  _Unwind_Backtrace()
134    returns _URC_END_OF_STACK when the backtrace stopped due to
135    reaching the end of the call-chain or _URC_FATAL_PHASE1_ERROR if it
136    stops for any other reason.  */
137 extern _Unwind_Reason_Code _Unwind_Backtrace (_Unwind_Trace_Fn, void *);
138
139 /* Find the start-address of the procedure containing the specified IP
140    or NULL if it cannot be found (e.g., because the function has no
141    unwind info).  Note: there is not necessarily a one-to-one
142    correspondence between source-level functions and procedures: some
143    functions don't have unwind-info and others are split into multiple
144    procedures.  */
145 extern void *_Unwind_FindEnclosingFunction (void *);
146
147 /* See also Linux Standard Base Spec:
148     http://www.linuxbase.org/spec/refspecs/LSB_1.3.0/gLSB/gLSB/libgcc-s.html */
149
150 #endif /* _GNU_SOURCE || _BSD_SOURCE */
151
152 #ifdef __cplusplus
153 };
154 #endif
155
156 #endif /* _UNWIND_H */