[BZ #2172]
[glibc.git] / sysdeps / generic / unwind.h
blob81fc4db55903a52d2a35a76fb707b2fc0056317e
1 /* Exception handling and frame unwind runtime interface routines.
2 Copyright (C) 2001, 2003 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, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA. */
21 /* This is derived from the C++ ABI for IA-64. Where we diverge
22 for cross-architecture compatibility are noted with "@@@". */
24 #ifndef _UNWIND_H
25 #define _UNWIND_H 1
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
31 /* Level 1: Base ABI */
33 /* @@@ The IA-64 ABI uses uint64 throughout. Most places this is
34 inefficient for 32-bit and smaller machines. */
35 typedef unsigned _Unwind_Word __attribute__((__mode__(__word__)));
36 typedef signed _Unwind_Sword __attribute__((__mode__(__word__)));
37 #if defined(__ia64__) && defined(__hpux__)
38 typedef unsigned _Unwind_Ptr __attribute__((__mode__(__word__)));
39 #else
40 typedef unsigned _Unwind_Ptr __attribute__((__mode__(__pointer__)));
41 #endif
42 typedef unsigned _Unwind_Internal_Ptr __attribute__((__mode__(__pointer__)));
44 /* @@@ The IA-64 ABI uses a 64-bit word to identify the producer and
45 consumer of an exception. We'll go along with this for now even on
46 32-bit machines. We'll need to provide some other option for
47 16-bit machines and for machines with > 8 bits per byte. */
48 typedef unsigned _Unwind_Exception_Class __attribute__((__mode__(__DI__)));
50 /* The unwind interface uses reason codes in several contexts to
51 identify the reasons for failures or other actions. */
52 typedef enum
54 _URC_NO_REASON = 0,
55 _URC_FOREIGN_EXCEPTION_CAUGHT = 1,
56 _URC_FATAL_PHASE2_ERROR = 2,
57 _URC_FATAL_PHASE1_ERROR = 3,
58 _URC_NORMAL_STOP = 4,
59 _URC_END_OF_STACK = 5,
60 _URC_HANDLER_FOUND = 6,
61 _URC_INSTALL_CONTEXT = 7,
62 _URC_CONTINUE_UNWIND = 8
63 } _Unwind_Reason_Code;
66 /* The unwind interface uses a pointer to an exception header object
67 as its representation of an exception being thrown. In general, the
68 full representation of an exception object is language- and
69 implementation-specific, but it will be prefixed by a header
70 understood by the unwind interface. */
72 struct _Unwind_Exception;
74 typedef void (*_Unwind_Exception_Cleanup_Fn) (_Unwind_Reason_Code,
75 struct _Unwind_Exception *);
77 struct _Unwind_Exception
79 _Unwind_Exception_Class exception_class;
80 _Unwind_Exception_Cleanup_Fn exception_cleanup;
81 _Unwind_Word private_1;
82 _Unwind_Word private_2;
84 /* @@@ The IA-64 ABI says that this structure must be double-word aligned.
85 Taking that literally does not make much sense generically. Instead we
86 provide the maximum alignment required by any type for the machine. */
87 } __attribute__((__aligned__));
90 /* The ACTIONS argument to the personality routine is a bitwise OR of one
91 or more of the following constants. */
92 typedef int _Unwind_Action;
94 #define _UA_SEARCH_PHASE 1
95 #define _UA_CLEANUP_PHASE 2
96 #define _UA_HANDLER_FRAME 4
97 #define _UA_FORCE_UNWIND 8
98 #define _UA_END_OF_STACK 16
100 /* This is an opaque type used to refer to a system-specific data
101 structure used by the system unwinder. This context is created and
102 destroyed by the system, and passed to the personality routine
103 during unwinding. */
104 struct _Unwind_Context;
106 /* Raise an exception, passing along the given exception object. */
107 extern _Unwind_Reason_Code _Unwind_RaiseException (struct _Unwind_Exception *);
109 /* Raise an exception for forced unwinding. */
111 typedef _Unwind_Reason_Code (*_Unwind_Stop_Fn)
112 (int, _Unwind_Action, _Unwind_Exception_Class,
113 struct _Unwind_Exception *, struct _Unwind_Context *, void *);
115 extern _Unwind_Reason_Code _Unwind_ForcedUnwind (struct _Unwind_Exception *,
116 _Unwind_Stop_Fn,
117 void *);
119 /* Helper to invoke the exception_cleanup routine. */
120 extern void _Unwind_DeleteException (struct _Unwind_Exception *);
122 /* Resume propagation of an existing exception. This is used after
123 e.g. executing cleanup code, and not to implement rethrowing. */
124 extern void _Unwind_Resume (struct _Unwind_Exception *);
126 /* @@@ Use unwind data to perform a stack backtrace. The trace callback
127 is called for every stack frame in the call chain, but no cleanup
128 actions are performed. */
129 typedef _Unwind_Reason_Code (*_Unwind_Trace_Fn)
130 (struct _Unwind_Context *, void *);
132 extern _Unwind_Reason_Code _Unwind_Backtrace (_Unwind_Trace_Fn, void *);
134 /* These functions are used for communicating information about the unwind
135 context (i.e. the unwind descriptors and the user register state) between
136 the unwind library and the personality routine and landing pad. Only
137 selected registers maybe manipulated. */
139 extern _Unwind_Word _Unwind_GetGR (struct _Unwind_Context *, int);
140 extern void _Unwind_SetGR (struct _Unwind_Context *, int, _Unwind_Word);
142 extern _Unwind_Ptr _Unwind_GetIP (struct _Unwind_Context *);
143 extern void _Unwind_SetIP (struct _Unwind_Context *, _Unwind_Ptr);
145 /* @@@ Retrieve the CFA of the given context. */
146 extern _Unwind_Word _Unwind_GetCFA (struct _Unwind_Context *);
148 extern void *_Unwind_GetLanguageSpecificData (struct _Unwind_Context *);
150 extern _Unwind_Ptr _Unwind_GetRegionStart (struct _Unwind_Context *);
153 /* The personality routine is the function in the C++ (or other language)
154 runtime library which serves as an interface between the system unwind
155 library and language-specific exception handling semantics. It is
156 specific to the code fragment described by an unwind info block, and
157 it is always referenced via the pointer in the unwind info block, and
158 hence it has no ABI-specified name.
160 Note that this implies that two different C++ implementations can
161 use different names, and have different contents in the language
162 specific data area. Moreover, that the language specific data
163 area contains no version info because name of the function invoked
164 provides more effective versioning by detecting at link time the
165 lack of code to handle the different data format. */
167 typedef _Unwind_Reason_Code (*_Unwind_Personality_Fn)
168 (int, _Unwind_Action, _Unwind_Exception_Class,
169 struct _Unwind_Exception *, struct _Unwind_Context *);
171 /* @@@ The following alternate entry points are for setjmp/longjmp
172 based unwinding. */
174 struct SjLj_Function_Context;
175 extern void _Unwind_SjLj_Register (struct SjLj_Function_Context *);
176 extern void _Unwind_SjLj_Unregister (struct SjLj_Function_Context *);
178 extern _Unwind_Reason_Code _Unwind_SjLj_RaiseException
179 (struct _Unwind_Exception *);
180 extern _Unwind_Reason_Code _Unwind_SjLj_ForcedUnwind
181 (struct _Unwind_Exception *, _Unwind_Stop_Fn, void *);
182 extern void _Unwind_SjLj_Resume (struct _Unwind_Exception *);
184 /* @@@ The following provide access to the base addresses for text
185 and data-relative addressing in the LDSA. In order to stay link
186 compatible with the standard ABI for IA-64, we inline these. */
188 #ifdef __ia64__
189 #include <stdlib.h>
191 static inline _Unwind_Ptr
192 _Unwind_GetDataRelBase (struct _Unwind_Context *_C)
194 /* The GP is stored in R1. */
195 return _Unwind_GetGR (_C, 1);
198 static inline _Unwind_Ptr
199 _Unwind_GetTextRelBase (struct _Unwind_Context *_C)
201 abort ();
202 return 0;
205 /* @@@ Retrieve the Backing Store Pointer of the given context. */
206 extern _Unwind_Word _Unwind_GetBSP (struct _Unwind_Context *);
207 #else
208 extern _Unwind_Ptr _Unwind_GetDataRelBase (struct _Unwind_Context *);
209 extern _Unwind_Ptr _Unwind_GetTextRelBase (struct _Unwind_Context *);
210 #endif
212 /* @@@ Given an address, return the entry point of the function that
213 contains it. */
214 extern void * _Unwind_FindEnclosingFunction (void *pc);
216 #ifdef __cplusplus
218 #endif
220 #endif /* unwind.h */