2003-02-28 Aldy Hernandez <aldyh@redhat.com>
[official-gcc.git] / gcc / unwind.h
blobe4b1e10865d45f18e15bc51156f0116c4d118c4b
1 /* Exception handling and frame unwind runtime interface routines.
2 Copyright (C) 2001, 2003 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GCC is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
14 License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING. If not, write to the Free
18 Software Foundation, 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 #ifdef __cplusplus
25 extern "C" {
26 #endif
28 /* Level 1: Base ABI */
30 /* @@@ The IA-64 ABI uses uint64 throughout. Most places this is
31 inefficient for 32-bit and smaller machines. */
32 typedef unsigned _Unwind_Word __attribute__((__mode__(__word__)));
33 typedef signed _Unwind_Sword __attribute__((__mode__(__word__)));
34 #if defined(__ia64__) && defined(__hpux__)
35 typedef unsigned _Unwind_Ptr __attribute__((__mode__(__word__)));
36 #else
37 typedef unsigned _Unwind_Ptr __attribute__((__mode__(__pointer__)));
38 #endif
39 typedef unsigned _Unwind_Internal_Ptr __attribute__((__mode__(__pointer__)));
41 /* @@@ The IA-64 ABI uses a 64-bit word to identify the producer and
42 consumer of an exception. We'll go along with this for now even on
43 32-bit machines. We'll need to provide some other option for
44 16-bit machines and for machines with > 8 bits per byte. */
45 typedef unsigned _Unwind_Exception_Class __attribute__((__mode__(__DI__)));
47 /* The unwind interface uses reason codes in several contexts to
48 identify the reasons for failures or other actions. */
49 typedef enum
51 _URC_NO_REASON = 0,
52 _URC_FOREIGN_EXCEPTION_CAUGHT = 1,
53 _URC_FATAL_PHASE2_ERROR = 2,
54 _URC_FATAL_PHASE1_ERROR = 3,
55 _URC_NORMAL_STOP = 4,
56 _URC_END_OF_STACK = 5,
57 _URC_HANDLER_FOUND = 6,
58 _URC_INSTALL_CONTEXT = 7,
59 _URC_CONTINUE_UNWIND = 8
60 } _Unwind_Reason_Code;
63 /* The unwind interface uses a pointer to an exception header object
64 as its representation of an exception being thrown. In general, the
65 full representation of an exception object is language- and
66 implementation-specific, but it will be prefixed by a header
67 understood by the unwind interface. */
69 struct _Unwind_Exception;
71 typedef void (*_Unwind_Exception_Cleanup_Fn) (_Unwind_Reason_Code,
72 struct _Unwind_Exception *);
74 struct _Unwind_Exception
76 _Unwind_Exception_Class exception_class;
77 _Unwind_Exception_Cleanup_Fn exception_cleanup;
78 _Unwind_Word private_1;
79 _Unwind_Word private_2;
81 /* @@@ The IA-64 ABI says that this structure must be double-word aligned.
82 Taking that literally does not make much sense generically. Instead we
83 provide the maximum alignment required by any type for the machine. */
84 } __attribute__((__aligned__));
87 /* The ACTIONS argument to the personality routine is a bitwise OR of one
88 or more of the following constants. */
89 typedef int _Unwind_Action;
91 #define _UA_SEARCH_PHASE 1
92 #define _UA_CLEANUP_PHASE 2
93 #define _UA_HANDLER_FRAME 4
94 #define _UA_FORCE_UNWIND 8
95 #define _UA_END_OF_STACK 16
97 /* This is an opaque type used to refer to a system-specific data
98 structure used by the system unwinder. This context is created and
99 destroyed by the system, and passed to the personality routine
100 during unwinding. */
101 struct _Unwind_Context;
103 /* Raise an exception, passing along the given exception object. */
104 extern _Unwind_Reason_Code _Unwind_RaiseException (struct _Unwind_Exception *);
106 /* Raise an exception for forced unwinding. */
108 typedef _Unwind_Reason_Code (*_Unwind_Stop_Fn)
109 (int, _Unwind_Action, _Unwind_Exception_Class,
110 struct _Unwind_Exception *, struct _Unwind_Context *, void *);
112 extern _Unwind_Reason_Code _Unwind_ForcedUnwind (struct _Unwind_Exception *,
113 _Unwind_Stop_Fn,
114 void *);
116 /* Helper to invoke the exception_cleanup routine. */
117 extern void _Unwind_DeleteException (struct _Unwind_Exception *);
119 /* Resume propagation of an existing exception. This is used after
120 e.g. executing cleanup code, and not to implement rethrowing. */
121 extern void _Unwind_Resume (struct _Unwind_Exception *);
123 /* These functions are used for communicating information about the unwind
124 context (i.e. the unwind descriptors and the user register state) between
125 the unwind library and the personality routine and landing pad. Only
126 selected registers maybe manipulated. */
128 extern _Unwind_Word _Unwind_GetGR (struct _Unwind_Context *, int);
129 extern void _Unwind_SetGR (struct _Unwind_Context *, int, _Unwind_Word);
131 extern _Unwind_Ptr _Unwind_GetIP (struct _Unwind_Context *);
132 extern void _Unwind_SetIP (struct _Unwind_Context *, _Unwind_Ptr);
134 extern void *_Unwind_GetLanguageSpecificData (struct _Unwind_Context *);
136 extern _Unwind_Ptr _Unwind_GetRegionStart (struct _Unwind_Context *);
139 /* The personality routine is the function in the C++ (or other language)
140 runtime library which serves as an interface between the system unwind
141 library and language-specific exception handling semantics. It is
142 specific to the code fragment described by an unwind info block, and
143 it is always referenced via the pointer in the unwind info block, and
144 hence it has no ABI-specified name.
146 Note that this implies that two different C++ implementations can
147 use different names, and have different contents in the language
148 specific data area. Moreover, that the language specific data
149 area contains no version info because name of the function invoked
150 provides more effective versioning by detecting at link time the
151 lack of code to handle the different data format. */
153 typedef _Unwind_Reason_Code (*_Unwind_Personality_Fn)
154 (int, _Unwind_Action, _Unwind_Exception_Class,
155 struct _Unwind_Exception *, struct _Unwind_Context *);
157 /* @@@ The following alternate entry points are for setjmp/longjmp
158 based unwinding. */
160 struct SjLj_Function_Context;
161 extern void _Unwind_SjLj_Register (struct SjLj_Function_Context *);
162 extern void _Unwind_SjLj_Unregister (struct SjLj_Function_Context *);
164 extern _Unwind_Reason_Code _Unwind_SjLj_RaiseException
165 (struct _Unwind_Exception *);
166 extern _Unwind_Reason_Code _Unwind_SjLj_ForcedUnwind
167 (struct _Unwind_Exception *, _Unwind_Stop_Fn, void *);
168 extern void _Unwind_SjLj_Resume (struct _Unwind_Exception *);
170 /* @@@ The following provide access to the base addresses for text
171 and data-relative addressing in the LDSA. In order to stay link
172 compatible with the standard ABI for IA-64, we inline these. */
174 #ifdef __ia64__
175 #include <stdlib.h>
177 static inline _Unwind_Ptr
178 _Unwind_GetDataRelBase (struct _Unwind_Context *_C)
180 /* The GP is stored in R1. */
181 return _Unwind_GetGR (_C, 1);
184 static inline _Unwind_Ptr
185 _Unwind_GetTextRelBase (struct _Unwind_Context *_C __attribute__ ((__unused__)))
187 abort ();
188 return 0;
190 #else
191 extern _Unwind_Ptr _Unwind_GetDataRelBase (struct _Unwind_Context *);
192 extern _Unwind_Ptr _Unwind_GetTextRelBase (struct _Unwind_Context *);
193 #endif
195 /* @@@ Given an address, return the entry point of the function that
196 contains it. */
197 extern void * _Unwind_FindEnclosingFunction (void *pc);
199 #ifdef __cplusplus
201 #endif