2014-07-29 Ed Smith-Rowland <3dw4rd@verizon.net>
[official-gcc.git] / libstdc++-v3 / libsupc++ / cxxabi.h
blob4d9458c2e84b15d38eea559d56ac740483ded232
1 // ABI Support -*- C++ -*-
3 // Copyright (C) 2000-2014 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 3, or (at your option)
10 // any later version.
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.
17 // Under Section 7 of GPL version 3, you are granted additional
18 // permissions described in the GCC Runtime Library Exception, version
19 // 3.1, as published by the Free Software Foundation.
21 // You should have received a copy of the GNU General Public License and
22 // a copy of the GCC Runtime Library Exception along with this program;
23 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 // <http://www.gnu.org/licenses/>.
26 // Written by Nathan Sidwell, Codesourcery LLC, <nathan@codesourcery.com>
28 /* This file declares the new abi entry points into the runtime. It is not
29 normally necessary for user programs to include this header, or use the
30 entry points directly. However, this header is available should that be
31 needed.
33 Some of the entry points are intended for both C and C++, thus this header
34 is includable from both C and C++. Though the C++ specific parts are not
35 available in C, naturally enough. */
37 /** @file cxxabi.h
38 * The header provides an interface to the C++ ABI.
41 #ifndef _CXXABI_H
42 #define _CXXABI_H 1
44 #pragma GCC system_header
46 #pragma GCC visibility push(default)
48 #include <stddef.h>
49 #include <bits/c++config.h>
50 #include <bits/cxxabi_tweaks.h>
51 #include <bits/cxxabi_forced.h>
53 #ifndef _GLIBCXX_CDTOR_CALLABI
54 #define _GLIBCXX_CDTOR_CALLABI
55 #endif
57 #ifdef __cplusplus
58 namespace __cxxabiv1
60 extern "C"
62 #endif
64 typedef __cxa_cdtor_return_type (*__cxa_cdtor_type)(void *);
66 // Allocate array.
67 void*
68 __cxa_vec_new(size_t __element_count, size_t __element_size,
69 size_t __padding_size, __cxa_cdtor_type __constructor,
70 __cxa_cdtor_type __destructor);
72 void*
73 __cxa_vec_new2(size_t __element_count, size_t __element_size,
74 size_t __padding_size, __cxa_cdtor_type __constructor,
75 __cxa_cdtor_type __destructor, void *(*__alloc) (size_t),
76 void (*__dealloc) (void*));
78 void*
79 __cxa_vec_new3(size_t __element_count, size_t __element_size,
80 size_t __padding_size, __cxa_cdtor_type __constructor,
81 __cxa_cdtor_type __destructor, void *(*__alloc) (size_t),
82 void (*__dealloc) (void*, size_t));
84 // Construct array.
85 __cxa_vec_ctor_return_type
86 __cxa_vec_ctor(void* __array_address, size_t __element_count,
87 size_t __element_size, __cxa_cdtor_type __constructor,
88 __cxa_cdtor_type __destructor);
90 __cxa_vec_ctor_return_type
91 __cxa_vec_cctor(void* __dest_array, void* __src_array,
92 size_t __element_count, size_t __element_size,
93 __cxa_cdtor_return_type (*__constructor) (void*, void*),
94 __cxa_cdtor_type __destructor);
96 // Destruct array.
97 void
98 __cxa_vec_dtor(void* __array_address, size_t __element_count,
99 size_t __element_size, __cxa_cdtor_type __destructor);
101 void
102 __cxa_vec_cleanup(void* __array_address, size_t __element_count, size_t __s,
103 __cxa_cdtor_type __destructor) _GLIBCXX_NOTHROW;
105 // Destruct and release array.
106 void
107 __cxa_vec_delete(void* __array_address, size_t __element_size,
108 size_t __padding_size, __cxa_cdtor_type __destructor);
110 void
111 __cxa_vec_delete2(void* __array_address, size_t __element_size,
112 size_t __padding_size, __cxa_cdtor_type __destructor,
113 void (*__dealloc) (void*));
115 void
116 __cxa_vec_delete3(void* __array_address, size_t __element_size,
117 size_t __padding_size, __cxa_cdtor_type __destructor,
118 void (*__dealloc) (void*, size_t));
121 __cxa_guard_acquire(__guard*);
123 void
124 __cxa_guard_release(__guard*) _GLIBCXX_NOTHROW;
126 void
127 __cxa_guard_abort(__guard*) _GLIBCXX_NOTHROW;
129 // DSO destruction.
131 __cxa_atexit(void (*)(void*), void*, void*) _GLIBCXX_NOTHROW;
134 __cxa_finalize(void*);
136 // TLS destruction.
138 __cxa_thread_atexit(void (*)(void*), void*, void *) _GLIBCXX_NOTHROW;
140 // Pure virtual functions.
141 void
142 __cxa_pure_virtual(void) __attribute__ ((__noreturn__));
144 void
145 __cxa_deleted_virtual(void) __attribute__ ((__noreturn__));
147 // Exception handling auxiliary.
148 void
149 __cxa_bad_cast() __attribute__((__noreturn__));
151 void
152 __cxa_bad_typeid() __attribute__((__noreturn__));
154 void
155 __cxa_throw_bad_array_new_length() __attribute__((__noreturn__));
157 void
158 __cxa_throw_bad_array_length() __attribute__((__noreturn__));
161 * @brief Demangling routine.
162 * ABI-mandated entry point in the C++ runtime library for demangling.
164 * @param __mangled_name A NUL-terminated character string
165 * containing the name to be demangled.
167 * @param __output_buffer A region of memory, allocated with
168 * malloc, of @a *__length bytes, into which the demangled name is
169 * stored. If @a __output_buffer is not long enough, it is
170 * expanded using realloc. @a __output_buffer may instead be NULL;
171 * in that case, the demangled name is placed in a region of memory
172 * allocated with malloc.
174 * @param __length If @a __length is non-NULL, the length of the
175 * buffer containing the demangled name is placed in @a *__length.
177 * @param __status @a *__status is set to one of the following values:
178 * 0: The demangling operation succeeded.
179 * -1: A memory allocation failure occurred.
180 * -2: @a mangled_name is not a valid name under the C++ ABI mangling rules.
181 * -3: One of the arguments is invalid.
183 * @return A pointer to the start of the NUL-terminated demangled
184 * name, or NULL if the demangling fails. The caller is
185 * responsible for deallocating this memory using @c free.
187 * The demangling is performed using the C++ ABI mangling rules,
188 * with GNU extensions. For example, this function is used in
189 * __gnu_cxx::__verbose_terminate_handler.
191 * See http://gcc.gnu.org/onlinedocs/libstdc++/manual/bk01pt12ch39.html
192 * for other examples of use.
194 * @note The same demangling functionality is available via
195 * libiberty (@c <libiberty/demangle.h> and @c libiberty.a) in GCC
196 * 3.1 and later, but that requires explicit installation (@c
197 * --enable-install-libiberty) and uses a different API, although
198 * the ABI is unchanged.
200 char*
201 __cxa_demangle(const char* __mangled_name, char* __output_buffer,
202 size_t* __length, int* __status);
204 #ifdef __cplusplus
206 } // namespace __cxxabiv1
207 #endif
209 #ifdef __cplusplus
211 #include <typeinfo>
213 namespace __cxxabiv1
215 // Type information for int, float etc.
216 class __fundamental_type_info : public std::type_info
218 public:
219 explicit
220 __fundamental_type_info(const char* __n) : std::type_info(__n) { }
222 virtual
223 ~__fundamental_type_info();
226 // Type information for array objects.
227 class __array_type_info : public std::type_info
229 public:
230 explicit
231 __array_type_info(const char* __n) : std::type_info(__n) { }
233 virtual
234 ~__array_type_info();
237 // Type information for functions (both member and non-member).
238 class __function_type_info : public std::type_info
240 public:
241 explicit
242 __function_type_info(const char* __n) : std::type_info(__n) { }
244 virtual
245 ~__function_type_info();
247 protected:
248 // Implementation defined member function.
249 virtual bool
250 __is_function_p() const;
253 // Type information for enumerations.
254 class __enum_type_info : public std::type_info
256 public:
257 explicit
258 __enum_type_info(const char* __n) : std::type_info(__n) { }
260 virtual
261 ~__enum_type_info();
264 // Common type information for simple pointers and pointers to member.
265 class __pbase_type_info : public std::type_info
267 public:
268 unsigned int __flags; // Qualification of the target object.
269 const std::type_info* __pointee; // Type of pointed to object.
271 explicit
272 __pbase_type_info(const char* __n, int __quals,
273 const std::type_info* __type)
274 : std::type_info(__n), __flags(__quals), __pointee(__type)
277 virtual
278 ~__pbase_type_info();
280 // Implementation defined type.
281 enum __masks
283 __const_mask = 0x1,
284 __volatile_mask = 0x2,
285 __restrict_mask = 0x4,
286 __incomplete_mask = 0x8,
287 __incomplete_class_mask = 0x10
290 protected:
291 __pbase_type_info(const __pbase_type_info&);
293 __pbase_type_info&
294 operator=(const __pbase_type_info&);
296 // Implementation defined member functions.
297 virtual bool
298 __do_catch(const std::type_info* __thr_type, void** __thr_obj,
299 unsigned int __outer) const;
301 inline virtual bool
302 __pointer_catch(const __pbase_type_info* __thr_type, void** __thr_obj,
303 unsigned __outer) const;
306 inline bool __pbase_type_info::
307 __pointer_catch (const __pbase_type_info *thrown_type,
308 void **thr_obj,
309 unsigned outer) const
311 return __pointee->__do_catch (thrown_type->__pointee, thr_obj, outer + 2);
314 // Type information for simple pointers.
315 class __pointer_type_info : public __pbase_type_info
317 public:
318 explicit
319 __pointer_type_info(const char* __n, int __quals,
320 const std::type_info* __type)
321 : __pbase_type_info (__n, __quals, __type) { }
324 virtual
325 ~__pointer_type_info();
327 protected:
328 // Implementation defined member functions.
329 virtual bool
330 __is_pointer_p() const;
332 virtual bool
333 __pointer_catch(const __pbase_type_info* __thr_type, void** __thr_obj,
334 unsigned __outer) const;
337 class __class_type_info;
339 // Type information for a pointer to member variable.
340 class __pointer_to_member_type_info : public __pbase_type_info
342 public:
343 __class_type_info* __context; // Class of the member.
345 explicit
346 __pointer_to_member_type_info(const char* __n, int __quals,
347 const std::type_info* __type,
348 __class_type_info* __klass)
349 : __pbase_type_info(__n, __quals, __type), __context(__klass) { }
351 virtual
352 ~__pointer_to_member_type_info();
354 protected:
355 __pointer_to_member_type_info(const __pointer_to_member_type_info&);
357 __pointer_to_member_type_info&
358 operator=(const __pointer_to_member_type_info&);
360 // Implementation defined member function.
361 virtual bool
362 __pointer_catch(const __pbase_type_info* __thr_type, void** __thr_obj,
363 unsigned __outer) const;
366 // Helper class for __vmi_class_type.
367 class __base_class_type_info
369 public:
370 const __class_type_info* __base_type; // Base class type.
371 #ifdef _GLIBCXX_LLP64
372 long long __offset_flags; // Offset and info.
373 #else
374 long __offset_flags; // Offset and info.
375 #endif
377 enum __offset_flags_masks
379 __virtual_mask = 0x1,
380 __public_mask = 0x2,
381 __hwm_bit = 2,
382 __offset_shift = 8 // Bits to shift offset.
385 // Implementation defined member functions.
386 bool
387 __is_virtual_p() const
388 { return __offset_flags & __virtual_mask; }
390 bool
391 __is_public_p() const
392 { return __offset_flags & __public_mask; }
394 ptrdiff_t
395 __offset() const
397 // This shift, being of a signed type, is implementation
398 // defined. GCC implements such shifts as arithmetic, which is
399 // what we want.
400 return static_cast<ptrdiff_t>(__offset_flags) >> __offset_shift;
404 // Type information for a class.
405 class __class_type_info : public std::type_info
407 public:
408 explicit
409 __class_type_info (const char *__n) : type_info(__n) { }
411 virtual
412 ~__class_type_info ();
414 // Implementation defined types.
415 // The type sub_kind tells us about how a base object is contained
416 // within a derived object. We often do this lazily, hence the
417 // UNKNOWN value. At other times we may use NOT_CONTAINED to mean
418 // not publicly contained.
419 enum __sub_kind
421 // We have no idea.
422 __unknown = 0,
424 // Not contained within us (in some circumstances this might
425 // mean not contained publicly)
426 __not_contained,
428 // Contained ambiguously.
429 __contained_ambig,
431 // Via a virtual path.
432 __contained_virtual_mask = __base_class_type_info::__virtual_mask,
434 // Via a public path.
435 __contained_public_mask = __base_class_type_info::__public_mask,
437 // Contained within us.
438 __contained_mask = 1 << __base_class_type_info::__hwm_bit,
440 __contained_private = __contained_mask,
441 __contained_public = __contained_mask | __contained_public_mask
444 struct __upcast_result;
445 struct __dyncast_result;
447 protected:
448 // Implementation defined member functions.
449 virtual bool
450 __do_upcast(const __class_type_info* __dst_type, void**__obj_ptr) const;
452 virtual bool
453 __do_catch(const type_info* __thr_type, void** __thr_obj,
454 unsigned __outer) const;
456 public:
457 // Helper for upcast. See if DST is us, or one of our bases.
458 // Return false if not found, true if found.
459 virtual bool
460 __do_upcast(const __class_type_info* __dst, const void* __obj,
461 __upcast_result& __restrict __result) const;
463 // Indicate whether SRC_PTR of type SRC_TYPE is contained publicly
464 // within OBJ_PTR. OBJ_PTR points to a base object of our type,
465 // which is the destination type. SRC2DST indicates how SRC
466 // objects might be contained within this type. If SRC_PTR is one
467 // of our SRC_TYPE bases, indicate the virtuality. Returns
468 // not_contained for non containment or private containment.
469 inline __sub_kind
470 __find_public_src(ptrdiff_t __src2dst, const void* __obj_ptr,
471 const __class_type_info* __src_type,
472 const void* __src_ptr) const;
474 // Helper for dynamic cast. ACCESS_PATH gives the access from the
475 // most derived object to this base. DST_TYPE indicates the
476 // desired type we want. OBJ_PTR points to a base of our type
477 // within the complete object. SRC_TYPE indicates the static type
478 // started from and SRC_PTR points to that base within the most
479 // derived object. Fill in RESULT with what we find. Return true
480 // if we have located an ambiguous match.
481 virtual bool
482 __do_dyncast(ptrdiff_t __src2dst, __sub_kind __access_path,
483 const __class_type_info* __dst_type, const void* __obj_ptr,
484 const __class_type_info* __src_type, const void* __src_ptr,
485 __dyncast_result& __result) const;
487 // Helper for find_public_subobj. SRC2DST indicates how SRC_TYPE
488 // bases are inherited by the type started from -- which is not
489 // necessarily the current type. The current type will be a base
490 // of the destination type. OBJ_PTR points to the current base.
491 virtual __sub_kind
492 __do_find_public_src(ptrdiff_t __src2dst, const void* __obj_ptr,
493 const __class_type_info* __src_type,
494 const void* __src_ptr) const;
497 // Type information for a class with a single non-virtual base.
498 class __si_class_type_info : public __class_type_info
500 public:
501 const __class_type_info* __base_type;
503 explicit
504 __si_class_type_info(const char *__n, const __class_type_info *__base)
505 : __class_type_info(__n), __base_type(__base) { }
507 virtual
508 ~__si_class_type_info();
510 protected:
511 __si_class_type_info(const __si_class_type_info&);
513 __si_class_type_info&
514 operator=(const __si_class_type_info&);
516 // Implementation defined member functions.
517 virtual bool
518 __do_dyncast(ptrdiff_t __src2dst, __sub_kind __access_path,
519 const __class_type_info* __dst_type, const void* __obj_ptr,
520 const __class_type_info* __src_type, const void* __src_ptr,
521 __dyncast_result& __result) const;
523 virtual __sub_kind
524 __do_find_public_src(ptrdiff_t __src2dst, const void* __obj_ptr,
525 const __class_type_info* __src_type,
526 const void* __sub_ptr) const;
528 virtual bool
529 __do_upcast(const __class_type_info*__dst, const void*__obj,
530 __upcast_result& __restrict __result) const;
533 // Type information for a class with multiple and/or virtual bases.
534 class __vmi_class_type_info : public __class_type_info
536 public:
537 unsigned int __flags; // Details about the class hierarchy.
538 unsigned int __base_count; // Number of direct bases.
540 // The array of bases uses the trailing array struct hack so this
541 // class is not constructable with a normal constructor. It is
542 // internally generated by the compiler.
543 __base_class_type_info __base_info[1]; // Array of bases.
545 explicit
546 __vmi_class_type_info(const char* __n, int ___flags)
547 : __class_type_info(__n), __flags(___flags), __base_count(0) { }
549 virtual
550 ~__vmi_class_type_info();
552 // Implementation defined types.
553 enum __flags_masks
555 __non_diamond_repeat_mask = 0x1, // Distinct instance of repeated base.
556 __diamond_shaped_mask = 0x2, // Diamond shaped multiple inheritance.
557 __flags_unknown_mask = 0x10
560 protected:
561 // Implementation defined member functions.
562 virtual bool
563 __do_dyncast(ptrdiff_t __src2dst, __sub_kind __access_path,
564 const __class_type_info* __dst_type, const void* __obj_ptr,
565 const __class_type_info* __src_type, const void* __src_ptr,
566 __dyncast_result& __result) const;
568 virtual __sub_kind
569 __do_find_public_src(ptrdiff_t __src2dst, const void* __obj_ptr,
570 const __class_type_info* __src_type,
571 const void* __src_ptr) const;
573 virtual bool
574 __do_upcast(const __class_type_info* __dst, const void* __obj,
575 __upcast_result& __restrict __result) const;
578 // Exception handling forward declarations.
579 struct __cxa_exception;
580 struct __cxa_refcounted_exception;
581 struct __cxa_dependent_exception;
582 struct __cxa_eh_globals;
584 extern "C"
586 // Dynamic cast runtime.
588 // src2dst has the following possible values
589 // >-1: src_type is a unique public non-virtual base of dst_type
590 // dst_ptr + src2dst == src_ptr
591 // -1: unspecified relationship
592 // -2: src_type is not a public base of dst_type
593 // -3: src_type is a multiple public non-virtual base of dst_type
594 void*
595 __dynamic_cast(const void* __src_ptr, // Starting object.
596 const __class_type_info* __src_type, // Static type of object.
597 const __class_type_info* __dst_type, // Desired target type.
598 ptrdiff_t __src2dst); // How src and dst are related.
601 // Exception handling runtime.
603 // The __cxa_eh_globals for the current thread can be obtained by using
604 // either of the following functions. The "fast" version assumes at least
605 // one prior call of __cxa_get_globals has been made from the current
606 // thread, so no initialization is necessary.
607 __cxa_eh_globals*
608 __cxa_get_globals() _GLIBCXX_NOTHROW __attribute__ ((__const__));
610 __cxa_eh_globals*
611 __cxa_get_globals_fast() _GLIBCXX_NOTHROW __attribute__ ((__const__));
613 // Allocate memory for the primary exception plus the thrown object.
614 void*
615 __cxa_allocate_exception(size_t) _GLIBCXX_NOTHROW;
617 // Free the space allocated for the primary exception.
618 void
619 __cxa_free_exception(void*) _GLIBCXX_NOTHROW;
621 // Throw the exception.
622 void
623 __cxa_throw(void*, std::type_info*, void (_GLIBCXX_CDTOR_CALLABI *) (void *))
624 __attribute__((__noreturn__));
626 // Used to implement exception handlers.
627 void*
628 __cxa_get_exception_ptr(void*) _GLIBCXX_NOTHROW __attribute__ ((__pure__));
630 void*
631 __cxa_begin_catch(void*) _GLIBCXX_NOTHROW;
633 void
634 __cxa_end_catch();
636 void
637 __cxa_rethrow() __attribute__((__noreturn__));
639 // Returns the type_info for the currently handled exception [15.3/8], or
640 // null if there is none.
641 std::type_info*
642 __cxa_current_exception_type() _GLIBCXX_NOTHROW __attribute__ ((__pure__));
644 // GNU Extensions.
646 // Allocate memory for a dependent exception.
647 __cxa_dependent_exception*
648 __cxa_allocate_dependent_exception() _GLIBCXX_NOTHROW;
650 // Free the space allocated for the dependent exception.
651 void
652 __cxa_free_dependent_exception(__cxa_dependent_exception*) _GLIBCXX_NOTHROW;
654 } // extern "C"
656 // A magic placeholder class that can be caught by reference
657 // to recognize foreign exceptions.
658 class __foreign_exception
660 virtual ~__foreign_exception() throw();
661 virtual void __pure_dummy() = 0; // prevent catch by value
664 } // namespace __cxxabiv1
666 /** @namespace abi
667 * @brief The cross-vendor C++ Application Binary Interface. A
668 * namespace alias to __cxxabiv1, but user programs should use the
669 * alias 'abi'.
671 * A brief overview of an ABI is given in the libstdc++ FAQ, question
672 * 5.8 (you may have a copy of the FAQ locally, or you can view the online
673 * version at http://gcc.gnu.org/onlinedocs/libstdc++/faq.html#5_8 ).
675 * GCC subscribes to a cross-vendor ABI for C++, sometimes
676 * called the IA64 ABI because it happens to be the native ABI for that
677 * platform. It is summarized at http://www.codesourcery.com/cxx-abi/
678 * along with the current specification.
680 * For users of GCC greater than or equal to 3.x, entry points are
681 * available in <cxxabi.h>, which notes, <em>'It is not normally
682 * necessary for user programs to include this header, or use the
683 * entry points directly. However, this header is available should
684 * that be needed.'</em>
686 namespace abi = __cxxabiv1;
688 namespace __gnu_cxx
691 * @brief Exception thrown by __cxa_guard_acquire.
692 * @ingroup exceptions
694 * 6.7[stmt.dcl]/4: If control re-enters the declaration (recursively)
695 * while the object is being initialized, the behavior is undefined.
697 * Since we already have a library function to handle locking, we might
698 * as well check for this situation and throw an exception.
699 * We use the second byte of the guard variable to remember that we're
700 * in the middle of an initialization.
702 class recursive_init_error: public std::exception
704 public:
705 recursive_init_error() throw() { }
706 virtual ~recursive_init_error() throw ();
709 #endif // __cplusplus
711 #pragma GCC visibility pop
713 #endif // __CXXABI_H