1 | /* Exception handling and frame unwind runtime interface routines. |
2 | Copyright (C) 2001-2024 Free Software Foundation, Inc. |
3 | |
4 | This file is part of the GNU C Library. |
5 | |
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. |
10 | |
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. |
15 | |
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/>. */ |
19 | |
20 | /* This is derived from the C++ ABI for IA-64. Where we diverge |
21 | for cross-architecture compatibility are noted with "@@@". */ |
22 | |
23 | #ifndef _UNWIND_H |
24 | #define _UNWIND_H 1 |
25 | |
26 | #ifdef __cplusplus |
27 | extern "C" { |
28 | #endif |
29 | |
30 | /* Level 1: Base ABI */ |
31 | |
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 | typedef unsigned _Unwind_Ptr __attribute__((__mode__(__pointer__))); |
37 | typedef unsigned _Unwind_Internal_Ptr __attribute__((__mode__(__pointer__))); |
38 | |
39 | /* @@@ The IA-64 ABI uses a 64-bit word to identify the producer and |
40 | consumer of an exception. We'll go along with this for now even on |
41 | 32-bit machines. We'll need to provide some other option for |
42 | 16-bit machines and for machines with > 8 bits per byte. */ |
43 | typedef unsigned _Unwind_Exception_Class __attribute__((__mode__(__DI__))); |
44 | |
45 | /* The unwind interface uses reason codes in several contexts to |
46 | identify the reasons for failures or other actions. */ |
47 | typedef enum |
48 | { |
49 | _URC_NO_REASON = 0, |
50 | _URC_FOREIGN_EXCEPTION_CAUGHT = 1, |
51 | _URC_FATAL_PHASE2_ERROR = 2, |
52 | _URC_FATAL_PHASE1_ERROR = 3, |
53 | _URC_NORMAL_STOP = 4, |
54 | _URC_END_OF_STACK = 5, |
55 | _URC_HANDLER_FOUND = 6, |
56 | _URC_INSTALL_CONTEXT = 7, |
57 | _URC_CONTINUE_UNWIND = 8 |
58 | } _Unwind_Reason_Code; |
59 | |
60 | |
61 | /* The unwind interface uses a pointer to an exception header object |
62 | as its representation of an exception being thrown. In general, the |
63 | full representation of an exception object is language- and |
64 | implementation-specific, but it will be prefixed by a header |
65 | understood by the unwind interface. */ |
66 | |
67 | struct _Unwind_Exception; |
68 | |
69 | typedef void (*_Unwind_Exception_Cleanup_Fn) (_Unwind_Reason_Code, |
70 | struct _Unwind_Exception *); |
71 | |
72 | struct _Unwind_Exception |
73 | { |
74 | union |
75 | { |
76 | struct |
77 | { |
78 | _Unwind_Exception_Class exception_class; |
79 | _Unwind_Exception_Cleanup_Fn exception_cleanup; |
80 | _Unwind_Word private_1; |
81 | _Unwind_Word private_2; |
82 | }; |
83 | |
84 | /* The IA-64 ABI says that this structure must be double-word aligned. */ |
85 | _Unwind_Word unwind_exception_align[2] |
86 | __attribute__ ((__aligned__ (2 * sizeof (_Unwind_Word)))); |
87 | }; |
88 | }; |
89 | |
90 | |
91 | /* The ACTIONS argument to the personality routine is a bitwise OR of one |
92 | or more of the following constants. */ |
93 | typedef int _Unwind_Action; |
94 | |
95 | #define _UA_SEARCH_PHASE 1 |
96 | #define _UA_CLEANUP_PHASE 2 |
97 | #define _UA_HANDLER_FRAME 4 |
98 | #define _UA_FORCE_UNWIND 8 |
99 | #define _UA_END_OF_STACK 16 |
100 | |
101 | /* This is an opaque type used to refer to a system-specific data |
102 | structure used by the system unwinder. This context is created and |
103 | destroyed by the system, and passed to the personality routine |
104 | during unwinding. */ |
105 | struct _Unwind_Context; |
106 | |
107 | /* Raise an exception, passing along the given exception object. */ |
108 | extern _Unwind_Reason_Code _Unwind_RaiseException (struct _Unwind_Exception *); |
109 | |
110 | /* Raise an exception for forced unwinding. */ |
111 | |
112 | typedef _Unwind_Reason_Code (*_Unwind_Stop_Fn) |
113 | (int, _Unwind_Action, _Unwind_Exception_Class, |
114 | struct _Unwind_Exception *, struct _Unwind_Context *, void *); |
115 | |
116 | extern _Unwind_Reason_Code _Unwind_ForcedUnwind (struct _Unwind_Exception *, |
117 | _Unwind_Stop_Fn, |
118 | void *); |
119 | |
120 | /* Helper to invoke the exception_cleanup routine. */ |
121 | extern void _Unwind_DeleteException (struct _Unwind_Exception *); |
122 | |
123 | /* Resume propagation of an existing exception. This is used after |
124 | e.g. executing cleanup code, and not to implement rethrowing. */ |
125 | extern void _Unwind_Resume (struct _Unwind_Exception *); |
126 | |
127 | /* @@@ Use unwind data to perform a stack backtrace. The trace callback |
128 | is called for every stack frame in the call chain, but no cleanup |
129 | actions are performed. */ |
130 | typedef _Unwind_Reason_Code (*_Unwind_Trace_Fn) |
131 | (struct _Unwind_Context *, void *); |
132 | |
133 | extern _Unwind_Reason_Code _Unwind_Backtrace (_Unwind_Trace_Fn, void *); |
134 | |
135 | /* These functions are used for communicating information about the unwind |
136 | context (i.e. the unwind descriptors and the user register state) between |
137 | the unwind library and the personality routine and landing pad. Only |
138 | selected registers maybe manipulated. */ |
139 | |
140 | extern _Unwind_Word _Unwind_GetGR (struct _Unwind_Context *, int); |
141 | extern void _Unwind_SetGR (struct _Unwind_Context *, int, _Unwind_Word); |
142 | |
143 | extern _Unwind_Ptr _Unwind_GetIP (struct _Unwind_Context *); |
144 | extern void _Unwind_SetIP (struct _Unwind_Context *, _Unwind_Ptr); |
145 | |
146 | /* @@@ Retrieve the CFA of the given context. */ |
147 | extern _Unwind_Word _Unwind_GetCFA (struct _Unwind_Context *); |
148 | |
149 | extern void *_Unwind_GetLanguageSpecificData (struct _Unwind_Context *); |
150 | |
151 | extern _Unwind_Ptr _Unwind_GetRegionStart (struct _Unwind_Context *); |
152 | |
153 | |
154 | /* The personality routine is the function in the C++ (or other language) |
155 | runtime library which serves as an interface between the system unwind |
156 | library and language-specific exception handling semantics. It is |
157 | specific to the code fragment described by an unwind info block, and |
158 | it is always referenced via the pointer in the unwind info block, and |
159 | hence it has no ABI-specified name. |
160 | |
161 | Note that this implies that two different C++ implementations can |
162 | use different names, and have different contents in the language |
163 | specific data area. Moreover, that the language specific data |
164 | area contains no version info because name of the function invoked |
165 | provides more effective versioning by detecting at link time the |
166 | lack of code to handle the different data format. */ |
167 | |
168 | typedef _Unwind_Reason_Code (*_Unwind_Personality_Fn) |
169 | (int, _Unwind_Action, _Unwind_Exception_Class, |
170 | struct _Unwind_Exception *, struct _Unwind_Context *); |
171 | |
172 | /* @@@ The following alternate entry points are for setjmp/longjmp |
173 | based unwinding. */ |
174 | |
175 | struct SjLj_Function_Context; |
176 | extern void _Unwind_SjLj_Register (struct SjLj_Function_Context *); |
177 | extern void _Unwind_SjLj_Unregister (struct SjLj_Function_Context *); |
178 | |
179 | extern _Unwind_Reason_Code _Unwind_SjLj_RaiseException |
180 | (struct _Unwind_Exception *); |
181 | extern _Unwind_Reason_Code _Unwind_SjLj_ForcedUnwind |
182 | (struct _Unwind_Exception *, _Unwind_Stop_Fn, void *); |
183 | extern void _Unwind_SjLj_Resume (struct _Unwind_Exception *); |
184 | |
185 | /* @@@ The following provide access to the base addresses for text |
186 | and data-relative addressing in the LDSA. In order to stay link |
187 | compatible with the standard ABI for IA-64, we inline these. */ |
188 | |
189 | extern _Unwind_Ptr _Unwind_GetDataRelBase (struct _Unwind_Context *); |
190 | extern _Unwind_Ptr _Unwind_GetTextRelBase (struct _Unwind_Context *); |
191 | |
192 | /* @@@ Given an address, return the entry point of the function that |
193 | contains it. */ |
194 | extern void * _Unwind_FindEnclosingFunction (void *pc); |
195 | |
196 | #ifdef __cplusplus |
197 | } |
198 | #endif |
199 | |
200 | #endif /* unwind.h */ |
201 | |