# cxxabi.h

Go to the documentation of this file.

    00001 // new abi support -*- C++ -*-
    00002
    00003 // Copyright (C) 2000, 2002, 2003, 2004, 2006, 2007 Free Software Foundation, Inc.
    00004 //
    00005 // This file is part of GCC.
    00006 //
    00007 // GCC is free software; you can redistribute it and/or modify
    00008 // it under the terms of the GNU General Public License as published by
    00009 // the Free Software Foundation; either version 2, or (at your option)
    00010 // any later version.
    00011 //
    00012 // GCC is distributed in the hope that it will be useful,
    00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
    00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00015 // GNU General Public License for more details.
    00016 //
    00017 // You should have received a copy of the GNU General Public License
    00018 // along with GCC; see the file COPYING.  If not, write to
    00019 // the Free Software Foundation, 51 Franklin Street, Fifth Floor,
    00020 // Boston, MA 02110-1301, USA.
    00021
    00022 // As a special exception, you may use this file as part of a free software
    00023 // library without restriction.  Specifically, if other files instantiate
    00024 // templates or use macros or inline functions from this file, or you compile
    00025 // this file and link it with other files to produce an executable, this
    00026 // file does not by itself cause the resulting executable to be covered by
    00027 // the GNU General Public License.  This exception does not however
    00028 // invalidate any other reasons why the executable file might be covered by
    00029 // the GNU General Public License.
    00030
    00031 // Written by Nathan Sidwell, Codesourcery LLC, <nathan@codesourcery.com>
    00032
    00033 /* This file declares the new abi entry points into the runtime. It is not
    00034    normally necessary for user programs to include this header, or use the
    00035    entry points directly. However, this header is available should that be
    00036    needed.
    00037
    00038    Some of the entry points are intended for both C and C++, thus this header
    00039    is includable from both C and C++. Though the C++ specific parts are not
    00040    available in C, naturally enough.  */
    00041
    00042 /** @file cxxabi.h
    00043  *  The header provides an interface to the C++ ABI.
    00044  */
    00045
    00046 #ifndef _CXXABI_H
    00047 #define _CXXABI_H 1
    00048
    00049 #pragma GCC visibility push(default)
    00050
    00051 #include <stddef.h>
    00052 #include <bits/cxxabi_tweaks.h>
    00053 #include <cxxabi-forced.h>
    00054
    00055 #ifdef __cplusplus
    00056 #define _GLIBCXX_NOTHROW throw()
    00057 #else
    00058 #define _GLIBCXX_NOTHROW __attribute__((nothrow))
    00059 #endif
    00060
    00061 #ifdef __cplusplus
    00062 namespace __cxxabiv1
    00063 {
    00064   extern "C"
    00065   {
    00066 #endif
    00067
    00068   typedef __cxa_cdtor_return_type (*__cxa_cdtor_type)(void *);
    00069
    00070   // Allocate array.
    00071   void*
    00072   __cxa_vec_new(size_t __element_count, size_t __element_size,
    00073         size_t __padding_size, __cxa_cdtor_type constructor,
    00074         __cxa_cdtor_type destructor);
    00075
    00076   void*
    00077   __cxa_vec_new2(size_t __element_count, size_t __element_size,
    00078          size_t __padding_size, __cxa_cdtor_type constructor,
    00079          __cxa_cdtor_type destructor, void *(*__alloc) (size_t),
    00080          void (*__dealloc) (void*));
    00081
    00082   void*
    00083   __cxa_vec_new3(size_t __element_count, size_t __element_size,
    00084          size_t __padding_size, __cxa_cdtor_type constructor,
    00085          __cxa_cdtor_type destructor, void *(*__alloc) (size_t),
    00086          void (*__dealloc) (void*, size_t));
    00087
    00088   // Construct array.
    00089   __cxa_vec_ctor_return_type
    00090   __cxa_vec_ctor(void* __array_address, size_t __element_count,
    00091          size_t __element_size, __cxa_cdtor_type constructor,
    00092          __cxa_cdtor_type destructor);
    00093
    00094   __cxa_vec_ctor_return_type
    00095   __cxa_vec_cctor(void* dest_array, void* src_array, size_t element_count,
    00096           size_t element_size,
    00097           __cxa_cdtor_return_type (*constructor) (void*, void*),
    00098           __cxa_cdtor_type destructor);
    00099
    00100   // Destruct array.
    00101   void
    00102   __cxa_vec_dtor(void* __array_address, size_t __element_count,
    00103          size_t __element_size, __cxa_cdtor_type destructor);
    00104
    00105   void
    00106   __cxa_vec_cleanup(void* __array_address, size_t __element_count,
    00107             size_t __element_size, __cxa_cdtor_type destructor);
    00108
    00109   // Destruct and release array.
    00110   void
    00111   __cxa_vec_delete(void* __array_address, size_t __element_size,
    00112            size_t __padding_size, __cxa_cdtor_type destructor);
    00113
    00114   void
    00115   __cxa_vec_delete2(void* __array_address, size_t __element_size,
    00116             size_t __padding_size, __cxa_cdtor_type destructor,
    00117             void (*__dealloc) (void*));
    00118
    00119   void
    00120   __cxa_vec_delete3(void* __array_address, size_t __element_size,
    00121             size_t __padding_size, __cxa_cdtor_type destructor,
    00122             void (*__dealloc) (void*, size_t));
    00123
    00124   int
    00125   __cxa_guard_acquire(__guard*);
    00126
    00127   void
    00128   __cxa_guard_release(__guard*);
    00129
    00130   void
    00131   __cxa_guard_abort(__guard*);
    00132
    00133   // Pure virtual functions.
    00134   void
    00135   __cxa_pure_virtual(void);
    00136
    00137   // Exception handling.
    00138   void
    00139   __cxa_bad_cast();
    00140
    00141   void
    00142   __cxa_bad_typeid();
    00143
    00144   // DSO destruction.
    00145   int
    00146   __cxa_atexit(void (*)(void*), void*, void*) _GLIBCXX_NOTHROW;
    00147
    00148   int
    00149   __cxa_finalize(void*);
    00150
    00151   // Demangling routines.
    00152   char*
    00153   __cxa_demangle(const char* __mangled_name, char* __output_buffer,
    00154          size_t* __length, int* __status);
    00155 #ifdef __cplusplus
    00156   }
    00157 } // namespace __cxxabiv1
    00158 #endif
    00159
    00160 #ifdef __cplusplus
    00161
    00162 #include <typeinfo>
    00163
    00164 namespace __cxxabiv1
    00165 {
    00166   // Type information for int, float etc.
    00167   class __fundamental_type_info : public std::type_info
    00168   {
    00169   public:
    00170     explicit
    00171     __fundamental_type_info(const char* __n) : std::type_info(__n) { }
    00172
    00173     virtual
    00174     ~__fundamental_type_info();
    00175   };
    00176
    00177   // Type information for array objects.
    00178   class __array_type_info : public std::type_info
    00179   {
    00180   public:
    00181     explicit
    00182     __array_type_info(const char* __n) : std::type_info(__n) { }
    00183
    00184     virtual
    00185     ~__array_type_info();
    00186   };
    00187
    00188   // Type information for functions (both member and non-member).
    00189   class __function_type_info : public std::type_info
    00190   {
    00191   public:
    00192     explicit
    00193     __function_type_info(const char* __n) : std::type_info(__n) { }
    00194
    00195     virtual
    00196     ~__function_type_info();
    00197
    00198   protected:
    00199     // Implementation defined member function.
    00200     virtual bool
    00201     __is_function_p() const;
    00202   };
    00203
    00204   // Type information for enumerations.
    00205   class __enum_type_info : public std::type_info
    00206   {
    00207   public:
    00208     explicit
    00209     __enum_type_info(const char* __n) : std::type_info(__n) { }
    00210
    00211     virtual
    00212     ~__enum_type_info();
    00213   };
    00214
    00215   // Common type information for simple pointers and pointers to member.
    00216   class __pbase_type_info : public std::type_info
    00217   {
    00218   public:
    00219     unsigned int        __flags; // Qualification of the target object.
    00220     const std::type_info*   __pointee; // Type of pointed to object.
    00221
    00222     explicit
    00223     __pbase_type_info(const char* __n, int __quals,
    00224               const std::type_info* __type)
    00225     : std::type_info(__n), __flags(__quals), __pointee(__type)
    00226     { }
    00227
    00228     virtual
    00229     ~__pbase_type_info();
    00230
    00231     // Implementation defined type.
    00232     enum __masks
    00233       {
    00234     __const_mask = 0x1,
    00235     __volatile_mask = 0x2,
    00236     __restrict_mask = 0x4,
    00237     __incomplete_mask = 0x8,
    00238     __incomplete_class_mask = 0x10
    00239       };
    00240
    00241   protected:
    00242     __pbase_type_info(const __pbase_type_info&);
    00243
    00244     __pbase_type_info&
    00245     operator=(const __pbase_type_info&);
    00246
    00247     // Implementation defined member functions.
    00248     virtual bool
    00249     __do_catch(const std::type_info* __thr_type, void** __thr_obj,
    00250            unsigned int __outer) const;
    00251
    00252     inline virtual bool
    00253     __pointer_catch(const __pbase_type_info* __thr_type, void** __thr_obj,
    00254             unsigned __outer) const;
    00255   };
    00256
    00257   // Type information for simple pointers.
    00258   class __pointer_type_info : public __pbase_type_info
    00259   {
    00260   public:
    00261     explicit
    00262     __pointer_type_info(const char* __n, int __quals,
    00263             const std::type_info* __type)
    00264     : __pbase_type_info (__n, __quals, __type) { }
    00265
    00266
    00267     virtual
    00268     ~__pointer_type_info();
    00269
    00270   protected:
    00271     // Implementation defined member functions.
    00272     virtual bool
    00273     __is_pointer_p() const;
    00274
    00275     virtual bool
    00276     __pointer_catch(const __pbase_type_info* __thr_type, void** __thr_obj,
    00277             unsigned __outer) const;
    00278   };
    00279
    00280   class __class_type_info;
    00281
    00282   // Type information for a pointer to member variable.
    00283   class __pointer_to_member_type_info : public __pbase_type_info
    00284   {
    00285   public:
    00286     __class_type_info* __context;   // Class of the member.
    00287
    00288     explicit
    00289     __pointer_to_member_type_info(const char* __n, int __quals,
    00290                   const std::type_info* __type,
    00291                   __class_type_info* __klass)
    00292     : __pbase_type_info(__n, __quals, __type), __context(__klass) { }
    00293
    00294     virtual
    00295     ~__pointer_to_member_type_info();
    00296
    00297   protected:
    00298     __pointer_to_member_type_info(const __pointer_to_member_type_info&);
    00299
    00300     __pointer_to_member_type_info&
    00301     operator=(const __pointer_to_member_type_info&);
    00302
    00303     // Implementation defined member function.
    00304     virtual bool
    00305     __pointer_catch(const __pbase_type_info* __thr_type, void** __thr_obj,
    00306             unsigned __outer) const;
    00307   };
    00308
    00309   // Helper class for __vmi_class_type.
    00310   class __base_class_type_info
    00311   {
    00312   public:
    00313     const __class_type_info*    __base_type;  // Base class type.
    00314     long            __offset_flags;  // Offset and info.
    00315
    00316     enum __offset_flags_masks
    00317       {
    00318     __virtual_mask = 0x1,
    00319     __public_mask = 0x2,
    00320     __hwm_bit = 2,
    00321     __offset_shift = 8          // Bits to shift offset.
    00322       };
    00323
    00324     // Implementation defined member functions.
    00325     bool
    00326     __is_virtual_p() const
    00327     { return __offset_flags & __virtual_mask; }
    00328
    00329     bool
    00330     __is_public_p() const
    00331     { return __offset_flags & __public_mask; }
    00332
    00333     ptrdiff_t
    00334     __offset() const
    00335     {
    00336       // This shift, being of a signed type, is implementation
    00337       // defined. GCC implements such shifts as arithmetic, which is
    00338       // what we want.
    00339       return static_cast<ptrdiff_t>(__offset_flags) >> __offset_shift;
    00340     }
    00341   };
    00342
    00343   // Type information for a class.
    00344   class __class_type_info : public std::type_info
    00345   {
    00346   public:
    00347     explicit
    00348     __class_type_info (const char *__n) : type_info(__n) { }
    00349
    00350     virtual
    00351     ~__class_type_info ();
    00352
    00353     // Implementation defined types.
    00354     // The type sub_kind tells us about how a base object is contained
    00355     // within a derived object. We often do this lazily, hence the
    00356     // UNKNOWN value. At other times we may use NOT_CONTAINED to mean
    00357     // not publicly contained.
    00358     enum __sub_kind
    00359       {
    00360     // We have no idea.
    00361     __unknown = 0,
    00362
    00363     // Not contained within us (in some circumstances this might
    00364     // mean not contained publicly)
    00365     __not_contained,
    00366
    00367     // Contained ambiguously.
    00368     __contained_ambig,
    00369
    00370     // Via a virtual path.
    00371     __contained_virtual_mask = __base_class_type_info::__virtual_mask,
    00372
    00373     // Via a public path.
    00374     __contained_public_mask = __base_class_type_info::__public_mask,
    00375
    00376     // Contained within us.
    00377     __contained_mask = 1 << __base_class_type_info::__hwm_bit,
    00378
    00379     __contained_private = __contained_mask,
    00380     __contained_public = __contained_mask | __contained_public_mask
    00381       };
    00382
    00383     struct __upcast_result;
    00384     struct __dyncast_result;
    00385
    00386   protected:
    00387     // Implementation defined member functions.
    00388     virtual bool
    00389     __do_upcast(const __class_type_info* __dst_type, void**__obj_ptr) const;
    00390
    00391     virtual bool
    00392     __do_catch(const type_info* __thr_type, void** __thr_obj,
    00393            unsigned __outer) const;
    00394
    00395   public:
    00396     // Helper for upcast. See if DST is us, or one of our bases.
    00397     // Return false if not found, true if found.
    00398     virtual bool
    00399     __do_upcast(const __class_type_info* __dst, const void* __obj,
    00400         __upcast_result& __restrict __result) const;
    00401
    00402     // Indicate whether SRC_PTR of type SRC_TYPE is contained publicly
    00403     // within OBJ_PTR. OBJ_PTR points to a base object of our type,
    00404     // which is the destination type. SRC2DST indicates how SRC
    00405     // objects might be contained within this type.  If SRC_PTR is one
    00406     // of our SRC_TYPE bases, indicate the virtuality. Returns
    00407     // not_contained for non containment or private containment.
    00408     inline __sub_kind
    00409     __find_public_src(ptrdiff_t __src2dst, const void* __obj_ptr,
    00410               const __class_type_info* __src_type,
    00411               const void* __src_ptr) const;
    00412
    00413     // Helper for dynamic cast. ACCESS_PATH gives the access from the
    00414     // most derived object to this base. DST_TYPE indicates the
    00415     // desired type we want. OBJ_PTR points to a base of our type
    00416     // within the complete object. SRC_TYPE indicates the static type
    00417     // started from and SRC_PTR points to that base within the most
    00418     // derived object. Fill in RESULT with what we find. Return true
    00419     // if we have located an ambiguous match.
    00420     virtual bool
    00421     __do_dyncast(ptrdiff_t __src2dst, __sub_kind __access_path,
    00422          const __class_type_info* __dst_type, const void* __obj_ptr,
    00423          const __class_type_info* __src_type, const void* __src_ptr,
    00424          __dyncast_result& __result) const;
    00425
    00426     // Helper for find_public_subobj. SRC2DST indicates how SRC_TYPE
    00427     // bases are inherited by the type started from -- which is not
    00428     // necessarily the current type. The current type will be a base
    00429     // of the destination type.  OBJ_PTR points to the current base.
    00430     virtual __sub_kind
    00431     __do_find_public_src(ptrdiff_t __src2dst, const void* __obj_ptr,
    00432              const __class_type_info* __src_type,
    00433              const void* __src_ptr) const;
    00434   };
    00435
    00436   // Type information for a class with a single non-virtual base.
    00437   class __si_class_type_info : public __class_type_info
    00438   {
    00439   public:
    00440     const __class_type_info* __base_type;
    00441
    00442     explicit
    00443     __si_class_type_info(const char *__n, const __class_type_info *__base)
    00444     : __class_type_info(__n), __base_type(__base) { }
    00445
    00446     virtual
    00447     ~__si_class_type_info();
    00448
    00449   protected:
    00450     __si_class_type_info(const __si_class_type_info&);
    00451
    00452     __si_class_type_info&
    00453     operator=(const __si_class_type_info&);
    00454
    00455     // Implementation defined member functions.
    00456     virtual bool
    00457     __do_dyncast(ptrdiff_t __src2dst, __sub_kind __access_path,
    00458          const __class_type_info* __dst_type, const void* __obj_ptr,
    00459          const __class_type_info* __src_type, const void* __src_ptr,
    00460          __dyncast_result& __result) const;
    00461
    00462     virtual __sub_kind
    00463     __do_find_public_src(ptrdiff_t __src2dst, const void* __obj_ptr,
    00464              const __class_type_info* __src_type,
    00465              const void* __sub_ptr) const;
    00466
    00467     virtual bool
    00468     __do_upcast(const __class_type_info*__dst, const void*__obj,
    00469         __upcast_result& __restrict __result) const;
    00470   };
    00471
    00472   // Type information for a class with multiple and/or virtual bases.
    00473   class __vmi_class_type_info : public __class_type_info
    00474   {
    00475   public:
    00476     unsigned int        __flags;  // Details about the class hierarchy.
    00477     unsigned int        __base_count;  // Number of direct bases.
    00478
    00479     // The array of bases uses the trailing array struct hack so this
    00480     // class is not constructable with a normal constructor. It is
    00481     // internally generated by the compiler.
    00482     __base_class_type_info  __base_info[1];  // Array of bases.
    00483
    00484     explicit
    00485     __vmi_class_type_info(const char* __n, int ___flags)
    00486     : __class_type_info(__n), __flags(___flags), __base_count(0) { }
    00487
    00488     virtual
    00489     ~__vmi_class_type_info();
    00490
    00491     // Implementation defined types.
    00492     enum __flags_masks
    00493       {
    00494     __non_diamond_repeat_mask = 0x1, // Distinct instance of repeated base.
    00495     __diamond_shaped_mask = 0x2, // Diamond shaped multiple inheritance.
    00496     __flags_unknown_mask = 0x10
    00497       };
    00498
    00499   protected:
    00500     // Implementation defined member functions.
    00501     virtual bool
    00502     __do_dyncast(ptrdiff_t __src2dst, __sub_kind __access_path,
    00503          const __class_type_info* __dst_type, const void* __obj_ptr,
    00504          const __class_type_info* __src_type, const void* __src_ptr,
    00505          __dyncast_result& __result) const;
    00506
    00507     virtual __sub_kind
    00508     __do_find_public_src(ptrdiff_t __src2dst, const void* __obj_ptr,
    00509              const __class_type_info* __src_type,
    00510              const void* __src_ptr) const;
    00511
    00512     virtual bool
    00513     __do_upcast(const __class_type_info* __dst, const void* __obj,
    00514         __upcast_result& __restrict __result) const;
    00515   };
    00516
    00517   // Dynamic cast runtime.
    00518   // src2dst has the following possible values
    00519   //  >-1: src_type is a unique public non-virtual base of dst_type
    00520   //       dst_ptr + src2dst == src_ptr
    00521   //   -1: unspecified relationship
    00522   //   -2: src_type is not a public base of dst_type
    00523   //   -3: src_type is a multiple public non-virtual base of dst_type
    00524   extern "C" void*
    00525   __dynamic_cast(const void* __src_ptr, // Starting object.
    00526          const __class_type_info* __src_type, // Static type of object.
    00527          const __class_type_info* __dst_type, // Desired target type.
    00528          ptrdiff_t __src2dst); // How src and dst are related.
    00529
    00530
    00531   // Returns the type_info for the currently handled exception [15.3/8], or
    00532   // null if there is none.
    00533   extern "C" std::type_info*
    00534   __cxa_current_exception_type();
    00535
    00536   // A magic placeholder class that can be caught by reference
    00537   // to recognize foreign exceptions.
    00538   class __foreign_exception
    00539   {
    00540     virtual ~__foreign_exception() throw();
    00541     virtual void __pure_dummy() = 0; // prevent catch by value
    00542   };
    00543
    00544 } // namespace __cxxabiv1
    00545
    00546 // User programs should use the alias `abi'.
    00547 namespace abi = __cxxabiv1;
    00548
    00549 #endif // __cplusplus
    00550
    00551 #pragma GCC visibility pop
    00552
    00553 #endif // __CXXABI_H