OSDN Git Service

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