Fixed rare threading problem
[official-gcc.git] / libstdc++-v3 / libsupc++ / cxxabi.h
blob1cad20580591967a7ee1f7197a03ff02ea63be73
1 // new abi support -*- C++ -*-
3 // Copyright (C) 2000, 2002, 2003 Free Software Foundation, Inc.
4 //
5 // This file is part of GCC.
6 //
7 // GCC is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation; either version 2, or (at your option)
10 // any later version.
11 //
12 // GCC is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with GCC; see the file COPYING. If not, write to
19 // the Free Software Foundation, 59 Temple Place - Suite 330,
20 // Boston, MA 02111-1307, USA.
22 // As a special exception, you may use this file as part of a free software
23 // library without restriction. Specifically, if other files instantiate
24 // templates or use macros or inline functions from this file, or you compile
25 // this file and link it with other files to produce an executable, this
26 // file does not by itself cause the resulting executable to be covered by
27 // the GNU General Public License. This exception does not however
28 // invalidate any other reasons why the executable file might be covered by
29 // the GNU General Public License.
31 // Written by Nathan Sidwell, Codesourcery LLC, <nathan@codesourcery.com>
33 /* This file declares the new abi entry points into the runtime. It is not
34 normally necessary for user programs to include this header, or use the
35 entry points directly. However, this header is available should that be
36 needed.
38 Some of the entry points are intended for both C and C++, thus this header
39 is includable from both C and C++. Though the C++ specific parts are not
40 available in C, naturally enough. */
42 #ifndef _CXXABI_H
43 #define _CXXABI_H 1
45 #ifdef __cplusplus
47 // We use the compiler builtins __SIZE_TYPE__ and __PTRDIFF_TYPE__ instead of
48 // std::size_t and std::ptrdiff_t respectively. This makes us independent of
49 // the conformance level of <cstddef> and whether -fhonor-std was supplied.
50 // <cstddef> is not currently available during compiler building anyway.
51 // Including <stddef.h> would be wrong, as that would rudely place size_t in
52 // the global namespace.
54 #include <typeinfo>
56 namespace __cxxabiv1
59 /* type information for int, float etc */
60 class __fundamental_type_info
61 : public std::type_info
63 public:
64 virtual ~__fundamental_type_info ();
65 public:
66 explicit __fundamental_type_info (const char *__n)
67 : std::type_info (__n)
68 { }
71 /* type information for array objects */
72 class __array_type_info
73 : public std::type_info
75 /* abi defined member functions */
76 protected:
77 virtual ~__array_type_info ();
78 public:
79 explicit __array_type_info (const char *__n)
80 : std::type_info (__n)
81 { }
84 /* type information for functions (both member and non-member) */
85 class __function_type_info
86 : public std::type_info
88 /* abi defined member functions */
89 public:
90 virtual ~__function_type_info ();
91 public:
92 explicit __function_type_info (const char *__n)
93 : std::type_info (__n)
94 { }
96 /* implementation defined member functions */
97 protected:
98 virtual bool __is_function_p () const;
101 /* type information for enumerations */
102 class __enum_type_info
103 : public std::type_info
105 /* abi defined member functions */
106 public:
107 virtual ~__enum_type_info ();
108 public:
109 explicit __enum_type_info (const char *__n)
110 : std::type_info (__n)
114 /* common type information for simple pointers and pointers to member */
115 class __pbase_type_info
116 : public std::type_info
118 /* abi defined member variables */
119 public:
120 unsigned int __flags; /* qualification of the target object */
121 const std::type_info *__pointee; /* type of pointed to object */
123 /* abi defined member functions */
124 public:
125 virtual ~__pbase_type_info ();
126 public:
127 explicit __pbase_type_info (const char *__n,
128 int __quals,
129 const std::type_info *__type)
130 : std::type_info (__n), __flags (__quals), __pointee (__type)
133 /* implementation defined types */
134 public:
135 enum __masks {
136 __const_mask = 0x1,
137 __volatile_mask = 0x2,
138 __restrict_mask = 0x4,
139 __incomplete_mask = 0x8,
140 __incomplete_class_mask = 0x10
143 /* implementation defined member functions */
144 protected:
145 virtual bool __do_catch (const std::type_info *__thr_type,
146 void **__thr_obj,
147 unsigned __outer) const;
148 protected:
149 inline virtual bool __pointer_catch (const __pbase_type_info *__thr_type,
150 void **__thr_obj,
151 unsigned __outer) const;
154 /* type information for simple pointers */
155 class __pointer_type_info
156 : public __pbase_type_info
158 /* abi defined member functions */
159 public:
160 virtual ~__pointer_type_info ();
161 public:
162 explicit __pointer_type_info (const char *__n,
163 int __quals,
164 const std::type_info *__type)
165 : __pbase_type_info (__n, __quals, __type)
168 /* implementation defined member functions */
169 protected:
170 virtual bool __is_pointer_p () const;
172 protected:
173 virtual bool __pointer_catch (const __pbase_type_info *__thr_type,
174 void **__thr_obj,
175 unsigned __outer) const;
178 /* type information for a pointer to member variable */
179 class __pointer_to_member_type_info
180 : public __pbase_type_info
182 /* abi defined member variables */
183 public:
184 __class_type_info *__context; /* class of the member */
186 /* abi defined member functions */
187 public:
188 virtual ~__pointer_to_member_type_info ();
189 public:
190 explicit __pointer_to_member_type_info (const char *__n,
191 int __quals,
192 const std::type_info *__type,
193 __class_type_info *__klass)
194 : __pbase_type_info (__n, __quals, __type), __context (__klass)
197 /* implementation defined member functions */
198 protected:
199 virtual bool __pointer_catch (const __pbase_type_info *__thr_type,
200 void **__thr_obj,
201 unsigned __outer) const;
204 class __class_type_info;
206 /* helper class for __vmi_class_type */
207 class __base_class_type_info
209 /* abi defined member variables */
210 public:
211 const __class_type_info* __base_type; /* base class type */
212 long __offset_flags; /* offset and info */
214 /* implementation defined types */
215 public:
216 enum __offset_flags_masks {
217 __virtual_mask = 0x1,
218 __public_mask = 0x2,
219 __hwm_bit = 2,
220 __offset_shift = 8 /* bits to shift offset by */
223 /* implementation defined member functions */
224 public:
225 bool __is_virtual_p () const
226 { return __offset_flags & __virtual_mask; }
227 bool __is_public_p () const
228 { return __offset_flags & __public_mask; }
229 __PTRDIFF_TYPE__ __offset () const
231 // This shift, being of a signed type, is implementation defined. GCC
232 // implements such shifts as arithmetic, which is what we want.
233 return static_cast<__PTRDIFF_TYPE__> (__offset_flags) >> __offset_shift;
237 /* type information for a class */
238 class __class_type_info
239 : public std::type_info
241 /* abi defined member functions */
242 public:
243 virtual ~__class_type_info ();
244 public:
245 explicit __class_type_info (const char *__n)
246 : type_info (__n)
249 /* implementation defined types */
250 public:
251 /* sub_kind tells us about how a base object is contained within a derived
252 object. We often do this lazily, hence the UNKNOWN value. At other times
253 we may use NOT_CONTAINED to mean not publicly contained. */
254 enum __sub_kind
256 __unknown = 0, /* we have no idea */
257 __not_contained, /* not contained within us (in some */
258 /* circumstances this might mean not contained */
259 /* publicly) */
260 __contained_ambig, /* contained ambiguously */
262 __contained_virtual_mask = __base_class_type_info::__virtual_mask, /* via a virtual path */
263 __contained_public_mask = __base_class_type_info::__public_mask, /* via a public path */
264 __contained_mask = 1 << __base_class_type_info::__hwm_bit, /* contained within us */
266 __contained_private = __contained_mask,
267 __contained_public = __contained_mask | __contained_public_mask
270 public:
271 struct __upcast_result;
272 struct __dyncast_result;
274 /* implementation defined member functions */
275 protected:
276 virtual bool __do_upcast (const __class_type_info *__dst_type, void **__obj_ptr) const;
278 protected:
279 virtual bool __do_catch (const type_info *__thr_type, void **__thr_obj,
280 unsigned __outer) const;
283 public:
284 /* Helper for upcast. See if DST is us, or one of our bases. */
285 /* Return false if not found, true if found. */
286 virtual bool __do_upcast (const __class_type_info *__dst,
287 const void *__obj,
288 __upcast_result &__restrict __result) const;
290 public:
291 /* Indicate whether SRC_PTR of type SRC_TYPE is contained publicly within
292 OBJ_PTR. OBJ_PTR points to a base object of our type, which is the
293 destination type. SRC2DST indicates how SRC objects might be contained
294 within this type. If SRC_PTR is one of our SRC_TYPE bases, indicate the
295 virtuality. Returns not_contained for non containment or private
296 containment. */
297 inline __sub_kind __find_public_src (__PTRDIFF_TYPE__ __src2dst,
298 const void *__obj_ptr,
299 const __class_type_info *__src_type,
300 const void *__src_ptr) const;
302 public:
303 /* dynamic cast helper. ACCESS_PATH gives the access from the most derived
304 object to this base. DST_TYPE indicates the desired type we want. OBJ_PTR
305 points to a base of our type within the complete object. SRC_TYPE
306 indicates the static type started from and SRC_PTR points to that base
307 within the most derived object. Fill in RESULT with what we find. Return
308 true if we have located an ambiguous match. */
309 virtual bool __do_dyncast (__PTRDIFF_TYPE__ __src2dst,
310 __sub_kind __access_path,
311 const __class_type_info *__dst_type,
312 const void *__obj_ptr,
313 const __class_type_info *__src_type,
314 const void *__src_ptr,
315 __dyncast_result &__result) const;
316 public:
317 /* Helper for find_public_subobj. SRC2DST indicates how SRC_TYPE bases are
318 inherited by the type started from -- which is not necessarily the
319 current type. The current type will be a base of the destination type.
320 OBJ_PTR points to the current base. */
321 virtual __sub_kind __do_find_public_src (__PTRDIFF_TYPE__ __src2dst,
322 const void *__obj_ptr,
323 const __class_type_info *__src_type,
324 const void *__src_ptr) const;
327 /* type information for a class with a single non-virtual base */
328 class __si_class_type_info
329 : public __class_type_info
331 /* abi defined member variables */
332 public:
333 const __class_type_info *__base_type;
335 /* abi defined member functions */
336 public:
337 virtual ~__si_class_type_info ();
338 public:
339 explicit __si_class_type_info (const char *__n,
340 const __class_type_info *__base)
341 : __class_type_info (__n), __base_type (__base)
344 /* implementation defined member functions */
345 protected:
346 virtual bool __do_dyncast (__PTRDIFF_TYPE__ __src2dst,
347 __sub_kind __access_path,
348 const __class_type_info *__dst_type,
349 const void *__obj_ptr,
350 const __class_type_info *__src_type,
351 const void *__src_ptr,
352 __dyncast_result &__result) const;
353 virtual __sub_kind __do_find_public_src (__PTRDIFF_TYPE__ __src2dst,
354 const void *__obj_ptr,
355 const __class_type_info *__src_type,
356 const void *__sub_ptr) const;
357 virtual bool __do_upcast (const __class_type_info *__dst,
358 const void *__obj,
359 __upcast_result &__restrict __result) const;
362 /* type information for a class with multiple and/or virtual bases */
363 class __vmi_class_type_info : public __class_type_info {
364 /* abi defined member variables */
365 public:
366 unsigned int __flags; /* details about the class hierarchy */
367 unsigned int __base_count; /* number of direct bases */
368 __base_class_type_info __base_info[1]; /* array of bases */
369 /* The array of bases uses the trailing array struct hack
370 so this class is not constructable with a normal constructor. It is
371 internally generated by the compiler. */
373 /* abi defined member functions */
374 public:
375 virtual ~__vmi_class_type_info ();
376 public:
377 explicit __vmi_class_type_info (const char *__n,
378 int ___flags)
379 : __class_type_info (__n), __flags (___flags), __base_count (0)
382 /* implementation defined types */
383 public:
384 enum __flags_masks {
385 __non_diamond_repeat_mask = 0x1, /* distinct instance of repeated base */
386 __diamond_shaped_mask = 0x2, /* diamond shaped multiple inheritance */
387 __flags_unknown_mask = 0x10
390 /* implementation defined member functions */
391 protected:
392 virtual bool __do_dyncast (__PTRDIFF_TYPE__ __src2dst,
393 __sub_kind __access_path,
394 const __class_type_info *__dst_type,
395 const void *__obj_ptr,
396 const __class_type_info *__src_type,
397 const void *__src_ptr,
398 __dyncast_result &__result) const;
399 virtual __sub_kind __do_find_public_src (__PTRDIFF_TYPE__ __src2dst,
400 const void *__obj_ptr,
401 const __class_type_info *__src_type,
402 const void *__src_ptr) const;
403 virtual bool __do_upcast (const __class_type_info *__dst,
404 const void *__obj,
405 __upcast_result &__restrict __result) const;
408 /* dynamic cast runtime */
409 extern "C"
410 void *__dynamic_cast (const void *__src_ptr, /* object started from */
411 const __class_type_info *__src_type, /* static type of object */
412 const __class_type_info *__dst_type, /* desired target type */
413 __PTRDIFF_TYPE__ __src2dst); /* how src and dst are related */
415 /* src2dst has the following possible values
416 >= 0: src_type is a unique public non-virtual base of dst_type
417 dst_ptr + src2dst == src_ptr
418 -1: unspecified relationship
419 -2: src_type is not a public base of dst_type
420 -3: src_type is a multiple public non-virtual base of dst_type */
422 /* array ctor/dtor routines */
424 /* allocate and construct array */
425 extern "C"
426 void *__cxa_vec_new (__SIZE_TYPE__ __element_count,
427 __SIZE_TYPE__ __element_size,
428 __SIZE_TYPE__ __padding_size,
429 void (*__constructor) (void *),
430 void (*__destructor) (void *));
432 extern "C"
433 void *__cxa_vec_new2 (__SIZE_TYPE__ __element_count,
434 __SIZE_TYPE__ __element_size,
435 __SIZE_TYPE__ __padding_size,
436 void (*__constructor) (void *),
437 void (*__destructor) (void *),
438 void *(*__alloc) (__SIZE_TYPE__),
439 void (*__dealloc) (void *));
441 extern "C"
442 void *__cxa_vec_new3 (__SIZE_TYPE__ __element_count,
443 __SIZE_TYPE__ __element_size,
444 __SIZE_TYPE__ __padding_size,
445 void (*__constructor) (void *),
446 void (*__destructor) (void *),
447 void *(*__alloc) (__SIZE_TYPE__),
448 void (*__dealloc) (void *, __SIZE_TYPE__));
450 /* construct array */
451 extern "C"
452 void __cxa_vec_ctor (void *__array_address,
453 __SIZE_TYPE__ __element_count,
454 __SIZE_TYPE__ __element_size,
455 void (*__constructor) (void *),
456 void (*__destructor) (void *));
458 extern "C"
459 void __cxa_vec_cctor (void *dest_array,
460 void *src_array,
461 __SIZE_TYPE__ element_count,
462 __SIZE_TYPE__ element_size,
463 void (*constructor) (void *, void *),
464 void (*destructor) (void *));
466 /* destruct array */
467 extern "C"
468 void __cxa_vec_dtor (void *__array_address,
469 __SIZE_TYPE__ __element_count,
470 __SIZE_TYPE__ __element_size,
471 void (*__destructor) (void *));
473 /* destruct array */
474 extern "C"
475 void __cxa_vec_cleanup (void *__array_address,
476 __SIZE_TYPE__ __element_count,
477 __SIZE_TYPE__ __element_size,
478 void (*__destructor) (void *));
480 /* destruct and release array */
481 extern "C"
482 void __cxa_vec_delete (void *__array_address,
483 __SIZE_TYPE__ __element_size,
484 __SIZE_TYPE__ __padding_size,
485 void (*__destructor) (void *));
487 extern "C"
488 void __cxa_vec_delete2 (void *__array_address,
489 __SIZE_TYPE__ __element_size,
490 __SIZE_TYPE__ __padding_size,
491 void (*__destructor) (void *),
492 void (*__dealloc) (void *));
494 extern "C"
495 void __cxa_vec_delete3 (void *__array_address,
496 __SIZE_TYPE__ __element_size,
497 __SIZE_TYPE__ __padding_size,
498 void (*__destructor) (void *),
499 void (*__dealloc) (void *, __SIZE_TYPE__));
501 /* guard variables */
503 /* The ABI requires a 64-bit type. */
504 __extension__ typedef int __guard __attribute__((mode (__DI__)));
506 extern "C"
507 int __cxa_guard_acquire (__guard *);
509 extern "C"
510 void __cxa_guard_release (__guard *);
512 extern "C"
513 void __cxa_guard_abort (__guard *);
515 /* pure virtual functions */
517 extern "C" void
518 __cxa_pure_virtual (void);
520 /* exception handling */
522 extern "C" void
523 __cxa_bad_cast ();
525 extern "C" void
526 __cxa_bad_typeid ();
528 /* DSO destruction */
530 extern "C" int
531 __cxa_atexit (void (*)(void *), void *, void *);
533 extern "C" int
534 __cxa_finalize (void *);
536 /* demangling routines */
538 extern "C"
539 char *__cxa_demangle (const char *__mangled_name,
540 char *__output_buffer,
541 __SIZE_TYPE__ *__length,
542 int *__status);
544 // Returns the type_info for the currently handled exception [15.3/8], or
545 // null if there is none.
546 extern "C"
547 std::type_info *__cxa_current_exception_type ();
549 } /* namespace __cxxabiv1 */
551 /* User programs should use the alias `abi'. */
552 namespace abi = __cxxabiv1;
554 #else
555 #endif /* __cplusplus */
558 #endif /* __CXXABI_H */