# cxxabi.h

Go to the documentation of this file.

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