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

Generated on Tue Jan 30 17:31:48 2007 for GNU C++ STL by doxygen 1.3.6