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