stdlib: Fix stdbit.h with -Wconversion for clang
[glibc.git] / sysdeps / generic / unwind.h
blob3013c18d15bada47762f48b653905cc3ff5613e9
1 /* Exception handling and frame unwind runtime interface routines.
2 Copyright (C) 2001-2024 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <https://www.gnu.org/licenses/>. */
20 /* This is derived from the C++ ABI for IA-64. Where we diverge
21 for cross-architecture compatibility are noted with "@@@". */
23 #ifndef _UNWIND_H
24 #define _UNWIND_H 1
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
30 /* Level 1: Base ABI */
32 /* @@@ The IA-64 ABI uses uint64 throughout. Most places this is
33 inefficient for 32-bit and smaller machines. */
34 typedef unsigned _Unwind_Word __attribute__((__mode__(__unwind_word__)));
35 typedef signed _Unwind_Sword __attribute__((__mode__(__unwind_word__)));
36 #if defined(__ia64__) && defined(__hpux__)
37 typedef unsigned _Unwind_Ptr __attribute__((__mode__(__word__)));
38 #else
39 typedef unsigned _Unwind_Ptr __attribute__((__mode__(__pointer__)));
40 #endif
41 typedef unsigned _Unwind_Internal_Ptr __attribute__((__mode__(__pointer__)));
43 /* @@@ The IA-64 ABI uses a 64-bit word to identify the producer and
44 consumer of an exception. We'll go along with this for now even on
45 32-bit machines. We'll need to provide some other option for
46 16-bit machines and for machines with > 8 bits per byte. */
47 typedef unsigned _Unwind_Exception_Class __attribute__((__mode__(__DI__)));
49 /* The unwind interface uses reason codes in several contexts to
50 identify the reasons for failures or other actions. */
51 typedef enum
53 _URC_NO_REASON = 0,
54 _URC_FOREIGN_EXCEPTION_CAUGHT = 1,
55 _URC_FATAL_PHASE2_ERROR = 2,
56 _URC_FATAL_PHASE1_ERROR = 3,
57 _URC_NORMAL_STOP = 4,
58 _URC_END_OF_STACK = 5,
59 _URC_HANDLER_FOUND = 6,
60 _URC_INSTALL_CONTEXT = 7,
61 _URC_CONTINUE_UNWIND = 8
62 } _Unwind_Reason_Code;
65 /* The unwind interface uses a pointer to an exception header object
66 as its representation of an exception being thrown. In general, the
67 full representation of an exception object is language- and
68 implementation-specific, but it will be prefixed by a header
69 understood by the unwind interface. */
71 struct _Unwind_Exception;
73 typedef void (*_Unwind_Exception_Cleanup_Fn) (_Unwind_Reason_Code,
74 struct _Unwind_Exception *);
76 struct _Unwind_Exception
78 union
80 struct
82 _Unwind_Exception_Class exception_class;
83 _Unwind_Exception_Cleanup_Fn exception_cleanup;
84 _Unwind_Word private_1;
85 _Unwind_Word private_2;
88 /* The IA-64 ABI says that this structure must be double-word aligned. */
89 _Unwind_Word unwind_exception_align[2]
90 __attribute__ ((__aligned__ (2 * sizeof (_Unwind_Word))));
95 /* The ACTIONS argument to the personality routine is a bitwise OR of one
96 or more of the following constants. */
97 typedef int _Unwind_Action;
99 #define _UA_SEARCH_PHASE 1
100 #define _UA_CLEANUP_PHASE 2
101 #define _UA_HANDLER_FRAME 4
102 #define _UA_FORCE_UNWIND 8
103 #define _UA_END_OF_STACK 16
105 /* This is an opaque type used to refer to a system-specific data
106 structure used by the system unwinder. This context is created and
107 destroyed by the system, and passed to the personality routine
108 during unwinding. */
109 struct _Unwind_Context;
111 /* Raise an exception, passing along the given exception object. */
112 extern _Unwind_Reason_Code _Unwind_RaiseException (struct _Unwind_Exception *);
114 /* Raise an exception for forced unwinding. */
116 typedef _Unwind_Reason_Code (*_Unwind_Stop_Fn)
117 (int, _Unwind_Action, _Unwind_Exception_Class,
118 struct _Unwind_Exception *, struct _Unwind_Context *, void *);
120 extern _Unwind_Reason_Code _Unwind_ForcedUnwind (struct _Unwind_Exception *,
121 _Unwind_Stop_Fn,
122 void *);
124 /* Helper to invoke the exception_cleanup routine. */
125 extern void _Unwind_DeleteException (struct _Unwind_Exception *);
127 /* Resume propagation of an existing exception. This is used after
128 e.g. executing cleanup code, and not to implement rethrowing. */
129 extern void _Unwind_Resume (struct _Unwind_Exception *);
131 /* @@@ Use unwind data to perform a stack backtrace. The trace callback
132 is called for every stack frame in the call chain, but no cleanup
133 actions are performed. */
134 typedef _Unwind_Reason_Code (*_Unwind_Trace_Fn)
135 (struct _Unwind_Context *, void *);
137 extern _Unwind_Reason_Code _Unwind_Backtrace (_Unwind_Trace_Fn, void *);
139 /* These functions are used for communicating information about the unwind
140 context (i.e. the unwind descriptors and the user register state) between
141 the unwind library and the personality routine and landing pad. Only
142 selected registers maybe manipulated. */
144 extern _Unwind_Word _Unwind_GetGR (struct _Unwind_Context *, int);
145 extern void _Unwind_SetGR (struct _Unwind_Context *, int, _Unwind_Word);
147 extern _Unwind_Ptr _Unwind_GetIP (struct _Unwind_Context *);
148 extern void _Unwind_SetIP (struct _Unwind_Context *, _Unwind_Ptr);
150 /* @@@ Retrieve the CFA of the given context. */
151 extern _Unwind_Word _Unwind_GetCFA (struct _Unwind_Context *);
153 extern void *_Unwind_GetLanguageSpecificData (struct _Unwind_Context *);
155 extern _Unwind_Ptr _Unwind_GetRegionStart (struct _Unwind_Context *);
158 /* The personality routine is the function in the C++ (or other language)
159 runtime library which serves as an interface between the system unwind
160 library and language-specific exception handling semantics. It is
161 specific to the code fragment described by an unwind info block, and
162 it is always referenced via the pointer in the unwind info block, and
163 hence it has no ABI-specified name.
165 Note that this implies that two different C++ implementations can
166 use different names, and have different contents in the language
167 specific data area. Moreover, that the language specific data
168 area contains no version info because name of the function invoked
169 provides more effective versioning by detecting at link time the
170 lack of code to handle the different data format. */
172 typedef _Unwind_Reason_Code (*_Unwind_Personality_Fn)
173 (int, _Unwind_Action, _Unwind_Exception_Class,
174 struct _Unwind_Exception *, struct _Unwind_Context *);
176 /* @@@ The following alternate entry points are for setjmp/longjmp
177 based unwinding. */
179 struct SjLj_Function_Context;
180 extern void _Unwind_SjLj_Register (struct SjLj_Function_Context *);
181 extern void _Unwind_SjLj_Unregister (struct SjLj_Function_Context *);
183 extern _Unwind_Reason_Code _Unwind_SjLj_RaiseException
184 (struct _Unwind_Exception *);
185 extern _Unwind_Reason_Code _Unwind_SjLj_ForcedUnwind
186 (struct _Unwind_Exception *, _Unwind_Stop_Fn, void *);
187 extern void _Unwind_SjLj_Resume (struct _Unwind_Exception *);
189 /* @@@ The following provide access to the base addresses for text
190 and data-relative addressing in the LDSA. In order to stay link
191 compatible with the standard ABI for IA-64, we inline these. */
193 #ifdef __ia64__
194 #include <stdlib.h>
196 static inline _Unwind_Ptr
197 _Unwind_GetDataRelBase (struct _Unwind_Context *_C)
199 /* The GP is stored in R1. */
200 return _Unwind_GetGR (_C, 1);
203 static inline _Unwind_Ptr
204 _Unwind_GetTextRelBase (struct _Unwind_Context *_C)
206 abort ();
207 return 0;
210 /* @@@ Retrieve the Backing Store Pointer of the given context. */
211 extern _Unwind_Word _Unwind_GetBSP (struct _Unwind_Context *);
212 #else
213 extern _Unwind_Ptr _Unwind_GetDataRelBase (struct _Unwind_Context *);
214 extern _Unwind_Ptr _Unwind_GetTextRelBase (struct _Unwind_Context *);
215 #endif
217 /* @@@ Given an address, return the entry point of the function that
218 contains it. */
219 extern void * _Unwind_FindEnclosingFunction (void *pc);
221 #ifdef __cplusplus
223 #endif
225 #endif /* unwind.h */