OSDN Git Service

* libsupc++/eh_alloc.cc: Ensure that required macros are
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / libsupc++ / unwind-cxx.h
1 // -*- C++ -*- Exception handling and frame unwind runtime interface routines.
2 // Copyright (C) 2001 Free Software Foundation, Inc.
3 //
4 // This file is part of GNU CC.
5 //
6 // GNU CC is free software; you can redistribute it and/or modify
7 // it 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 // GNU CC 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
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with GNU CC; see the file COPYING.  If not, write to
18 // the Free Software Foundation, 59 Temple Place - Suite 330,
19 // Boston, MA 02111-1307, USA.
20
21 // This is derived from the C++ ABI for IA-64.  Where we diverge
22 // for cross-architecture compatibility are noted with "@@@".
23
24 #ifndef __UNWIND_CXX_H
25 #define __UNWIND_CXX_H 1
26
27 // Level 2: C++ ABI
28
29 #include <typeinfo>
30 #include <exception>
31 #include <cstddef>
32 #include "unwind.h"
33
34 namespace __cxxabiv1
35 {
36
37 // A C++ exception object consists of a header, which is a wrapper around
38 // an unwind object header with additional C++ specific information,
39 // followed by the exception object itself.
40
41 struct __cxa_exception
42
43   // Manage the exception object itself.
44   std::type_info *exceptionType;
45   void (*exceptionDestructor)(void *); 
46
47   // The C++ standard has entertaining rules wrt calling set_terminate
48   // and set_unexpected in the middle of the exception cleanup process.
49   std::unexpected_handler unexpectedHandler;
50   std::terminate_handler terminateHandler;
51
52   // The caught exception stack threads through here.
53   __cxa_exception *nextException;
54
55   // How many nested handlers have caught this exception.  A negated
56   // value is a signal that this object has been rethrown.
57   int handlerCount;
58
59   // Cache parsed handler data from the personality routine Phase 1
60   // for Phase 2 and __cxa_call_unexpected.
61   int handlerSwitchValue;
62   const unsigned char *actionRecord;
63   const unsigned char *languageSpecificData;
64   void *catchTemp;
65   void *adjustedPtr;
66
67   // The generic exception header.  Must be last.
68   _Unwind_Exception unwindHeader;
69 };
70
71 // Each thread in a C++ program has access to a __cxa_eh_globals object.
72 struct __cxa_eh_globals
73 {
74   __cxa_exception *caughtExceptions;
75   unsigned int uncaughtExceptions;
76 };
77
78
79 // The __cxa_eh_globals for the current thread can be obtained by using
80 // either of the following functions.  The "fast" version assumes at least
81 // one prior call of __cxa_get_globals has been made from the current
82 // thread, so no initialization is necessary.
83 extern "C" __cxa_eh_globals *__cxa_get_globals () throw();
84 extern "C" __cxa_eh_globals *__cxa_get_globals_fast () throw();
85
86 // Allocate memory for the exception plus the thown object.
87 extern "C" void *__cxa_allocate_exception(std::size_t thrown_size) throw();
88
89 // Free the space allocated for the exception.
90 extern "C" void __cxa_free_exception(void *thrown_exception) throw();
91
92 // Throw the exception.
93 extern "C" void __cxa_throw (void *thrown_exception,
94                              std::type_info *tinfo,
95                              void (*dest) (void *))
96      __attribute__((noreturn));
97
98 // Used to implement exception handlers.
99 extern "C" void *__cxa_begin_catch (_Unwind_Exception *) throw();
100 extern "C" void __cxa_end_catch ();
101 extern "C" void __cxa_rethrow () __attribute__((noreturn));
102
103 // These facilitate code generation for recurring situations.
104 extern "C" void __cxa_bad_cast ();
105 extern "C" void __cxa_bad_typeid ();
106
107 // @@@ These are not directly specified by the IA-64 C++ ABI.
108
109 // Handles re-checking the exception specification if unexpectedHandler
110 // throws, and if bad_exception needs to be thrown.  Called from the
111 // compiler.
112 extern "C" void __cxa_call_unexpected (_Unwind_Exception *)
113      __attribute__((noreturn));
114
115 // Invokes given handler, dying appropriately if the user handler was
116 // so inconsiderate as to return.
117 extern void __terminate(std::terminate_handler) __attribute__((noreturn));
118 extern void __unexpected(std::unexpected_handler) __attribute__((noreturn));
119
120 // The current installed user handlers.
121 extern std::terminate_handler __terminate_handler;
122 extern std::unexpected_handler __unexpected_handler;
123
124 // These are explicitly GNU C++ specific.
125
126 // This is the exception class we report -- "GNUCC++\0".
127 const _Unwind_Exception_Class __gxx_exception_class
128 = ((((((((_Unwind_Exception_Class) 'G' 
129          << 8 | (_Unwind_Exception_Class) 'N')
130         << 8 | (_Unwind_Exception_Class) 'U')
131        << 8 | (_Unwind_Exception_Class) 'C')
132       << 8 | (_Unwind_Exception_Class) 'C')
133      << 8 | (_Unwind_Exception_Class) '+')
134     << 8 | (_Unwind_Exception_Class) '+')
135    << 8 | (_Unwind_Exception_Class) '\0');
136
137 // GNU C++ personality routine, Version 0.
138 extern "C" _Unwind_Reason_Code __gxx_personality_v0
139      (int, _Unwind_Action, _Unwind_Exception_Class,
140       struct _Unwind_Exception *, struct _Unwind_Context *);
141
142 // GNU C++ sjlj personality routine, Version 0.
143 extern "C" _Unwind_Reason_Code __gxx_personality_sj0
144      (int, _Unwind_Action, _Unwind_Exception_Class,
145       struct _Unwind_Exception *, struct _Unwind_Context *);
146
147 // Acquire the C++ exception header from the C++ object.
148 static inline __cxa_exception *
149 __get_exception_header_from_obj (void *ptr)
150 {
151   return reinterpret_cast<__cxa_exception *>(ptr) - 1;
152 }
153
154 // Acquire the C++ exception header from the generic exception header.
155 static inline __cxa_exception *
156 __get_exception_header_from_ue (_Unwind_Exception *exc)
157 {
158   return reinterpret_cast<__cxa_exception *>(exc + 1) - 1;
159 }
160
161 } /* namespace __cxxabiv1 */
162
163 #endif // __UNWIND_CXX_H