1 // new abi support -*- C++ -*- 2 3 // Copyright (C) 2000, 2002, 2003, 2004 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. 21 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. 30 31 // Written by Nathan Sidwell, Codesourcery LLC, <nathan@codesourcery.com> 32 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. 37 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. */ 41 42 #ifndef _CXXABI_H 43 #define _CXXABI_H 1 44 45 #include <stddef.h> 46 47 #ifdef __cplusplus 48 namespace __cxxabiv1 49 { 50 extern "C" 51 { 52 #endif 53 54 // Allocate array. 55 void* 56 __cxa_vec_new(size_t __element_count, size_t __element_size, 57 size_t __padding_size, void (*__constructor) (void*), 58 void (*__destructor) (void*)); 59 60 void* 61 __cxa_vec_new2(size_t __element_count, size_t __element_size, 62 size_t __padding_size, void (*__constructor) (void*), 63 void (*__destructor) (void*), void *(*__alloc) (size_t), 64 void (*__dealloc) (void*)); 65 66 void* 67 __cxa_vec_new3(size_t __element_count, size_t __element_size, 68 size_t __padding_size, void (*__constructor) (void*), 69 void (*__destructor) (void*), void *(*__alloc) (size_t), 70 void (*__dealloc) (void*, size_t)); 71 72 // Construct array. 73 void 74 __cxa_vec_ctor(void* __array_address, size_t __element_count, 75 size_t __element_size, void (*__constructor) (void*), 76 void (*__destructor) (void*)); 77 78 void 79 __cxa_vec_cctor(void* dest_array, void* src_array, size_t element_count, 80 size_t element_size, void (*constructor) (void*, void*), 81 void (*destructor) (void*)); 82 83 // Destruct array. 84 void 85 __cxa_vec_dtor(void* __array_address, size_t __element_count, 86 size_t __element_size, void (*__destructor) (void*)); 87 88 void 89 __cxa_vec_cleanup(void* __array_address, size_t __element_count, 90 size_t __element_size, void (*__destructor) (void*)); 91 92 // Destruct and release array. 93 void 94 __cxa_vec_delete(void* __array_address, size_t __element_size, 95 size_t __padding_size, void (*__destructor) (void*)); 96 97 void 98 __cxa_vec_delete2(void* __array_address, size_t __element_size, 99 size_t __padding_size, void (*__destructor) (void*), 100 void (*__dealloc) (void*)); 101 102 void 103 __cxa_vec_delete3(void* __array_address, size_t __element_size, 104 size_t __padding_size, void (*__destructor) (void*), 105 void (*__dealloc) (void*, size_t)); 106 107 // The ABI requires a 64-bit type. 108 __extension__ typedef int __guard __attribute__((mode (__DI__))); 109 110 int 111 __cxa_guard_acquire(__guard*); 112 113 void 114 __cxa_guard_release(__guard*); 115 116 void 117 __cxa_guard_abort(__guard*); 118 119 // Pure virtual functions. 120 void 121 __cxa_pure_virtual(void); 122 123 // Exception handling. 124 void 125 __cxa_bad_cast(); 126 127 void 128 __cxa_bad_typeid(); 129 130 // DSO destruction. 131 int 132 __cxa_atexit(void (*)(void*), void*, void*); 133 134 int 135 __cxa_finalize(void*); 136 137 // Demangling routines. 138 char* 139 __cxa_demangle(const char* __mangled_name, char* __output_buffer, 140 size_t* __length, int* __status); 141 #ifdef __cplusplus 142 } 143 } // namespace __cxxabiv1 144 #endif 145 146 #ifdef __cplusplus 147 148 #include <typeinfo> 149 150 namespace __cxxabiv1 151 { 152 // Type information for int, float etc. 153 class __fundamental_type_info : public std::type_info 154 { 155 public: 156 explicit __fundamental_type_info(const char * __n)157 __fundamental_type_info(const char* __n) : std::type_info(__n) { } 158 159 virtual 160 ~__fundamental_type_info(); 161 }; 162 163 // Type information for array objects. 164 class __array_type_info : public std::type_info 165 { 166 public: 167 explicit __array_type_info(const char * __n)168 __array_type_info(const char* __n) : std::type_info(__n) { } 169 170 virtual 171 ~__array_type_info(); 172 }; 173 174 // Type information for functions (both member and non-member). 175 class __function_type_info : public std::type_info 176 { 177 public: 178 explicit __function_type_info(const char * __n)179 __function_type_info(const char* __n) : std::type_info(__n) { } 180 181 virtual 182 ~__function_type_info(); 183 184 protected: 185 // Implementation defined member function. 186 virtual bool 187 __is_function_p() const; 188 }; 189 190 // Type information for enumerations. 191 class __enum_type_info : public std::type_info 192 { 193 public: 194 explicit __enum_type_info(const char * __n)195 __enum_type_info(const char* __n) : std::type_info(__n) { } 196 197 virtual 198 ~__enum_type_info(); 199 }; 200 201 // Common type information for simple pointers and pointers to member. 202 class __pbase_type_info : public std::type_info 203 { 204 public: 205 unsigned int __flags; // Qualification of the target object. 206 const std::type_info* __pointee; // Type of pointed to object. 207 208 explicit __pbase_type_info(const char * __n,int __quals,const std::type_info * __type)209 __pbase_type_info(const char* __n, int __quals, 210 const std::type_info* __type) 211 : std::type_info(__n), __flags(__quals), __pointee(__type) 212 { } 213 214 virtual 215 ~__pbase_type_info(); 216 217 // Implementation defined type. 218 enum __masks 219 { 220 __const_mask = 0x1, 221 __volatile_mask = 0x2, 222 __restrict_mask = 0x4, 223 __incomplete_mask = 0x8, 224 __incomplete_class_mask = 0x10 225 }; 226 227 protected: 228 __pbase_type_info(const __pbase_type_info&); 229 230 __pbase_type_info& 231 operator=(const __pbase_type_info&); 232 233 // Implementation defined member functions. 234 virtual bool 235 __do_catch(const std::type_info* __thr_type, void** __thr_obj, 236 unsigned int __outer) const; 237 238 inline virtual bool 239 __pointer_catch(const __pbase_type_info* __thr_type, void** __thr_obj, 240 unsigned __outer) const; 241 }; 242 243 // Type information for simple pointers. 244 class __pointer_type_info : public __pbase_type_info 245 { 246 public: 247 explicit __pointer_type_info(const char * __n,int __quals,const std::type_info * __type)248 __pointer_type_info(const char* __n, int __quals, 249 const std::type_info* __type) 250 : __pbase_type_info (__n, __quals, __type) { } 251 252 253 virtual 254 ~__pointer_type_info(); 255 256 protected: 257 // Implementation defined member functions. 258 virtual bool 259 __is_pointer_p() const; 260 261 virtual bool 262 __pointer_catch(const __pbase_type_info* __thr_type, void** __thr_obj, 263 unsigned __outer) const; 264 }; 265 266 class __class_type_info; 267 268 // Type information for a pointer to member variable. 269 class __pointer_to_member_type_info : public __pbase_type_info 270 { 271 public: 272 __class_type_info* __context; // Class of the member. 273 274 explicit __pointer_to_member_type_info(const char * __n,int __quals,const std::type_info * __type,__class_type_info * __klass)275 __pointer_to_member_type_info(const char* __n, int __quals, 276 const std::type_info* __type, 277 __class_type_info* __klass) 278 : __pbase_type_info(__n, __quals, __type), __context(__klass) { } 279 280 virtual 281 ~__pointer_to_member_type_info(); 282 283 protected: 284 __pointer_to_member_type_info(const __pointer_to_member_type_info&); 285 286 __pointer_to_member_type_info& 287 operator=(const __pointer_to_member_type_info&); 288 289 // Implementation defined member function. 290 virtual bool 291 __pointer_catch(const __pbase_type_info* __thr_type, void** __thr_obj, 292 unsigned __outer) const; 293 }; 294 295 // Helper class for __vmi_class_type. 296 class __base_class_type_info 297 { 298 public: 299 const __class_type_info* __base_type; // Base class type. 300 long __offset_flags; // Offset and info. 301 302 enum __offset_flags_masks 303 { 304 __virtual_mask = 0x1, 305 __public_mask = 0x2, 306 __hwm_bit = 2, 307 __offset_shift = 8 // Bits to shift offset. 308 }; 309 310 // Implementation defined member functions. 311 bool __is_virtual_p()312 __is_virtual_p() const 313 { return __offset_flags & __virtual_mask; } 314 315 bool __is_public_p()316 __is_public_p() const 317 { return __offset_flags & __public_mask; } 318 319 ptrdiff_t __offset()320 __offset() const 321 { 322 // This shift, being of a signed type, is implementation 323 // defined. GCC implements such shifts as arithmetic, which is 324 // what we want. 325 return static_cast<ptrdiff_t>(__offset_flags) >> __offset_shift; 326 } 327 }; 328 329 // Type information for a class. 330 class __class_type_info : public std::type_info 331 { 332 public: 333 explicit __class_type_info(const char * __n)334 __class_type_info (const char *__n) : type_info(__n) { } 335 336 virtual 337 ~__class_type_info (); 338 339 // Implementation defined types. 340 // The type sub_kind tells us about how a base object is contained 341 // within a derived object. We often do this lazily, hence the 342 // UNKNOWN value. At other times we may use NOT_CONTAINED to mean 343 // not publicly contained. 344 enum __sub_kind 345 { 346 // We have no idea. 347 __unknown = 0, 348 349 // Not contained within us (in some circumstances this might 350 // mean not contained publicly) 351 __not_contained, 352 353 // Contained ambiguously. 354 __contained_ambig, 355 356 // Via a virtual path. 357 __contained_virtual_mask = __base_class_type_info::__virtual_mask, 358 359 // Via a public path. 360 __contained_public_mask = __base_class_type_info::__public_mask, 361 362 // Contained within us. 363 __contained_mask = 1 << __base_class_type_info::__hwm_bit, 364 365 __contained_private = __contained_mask, 366 __contained_public = __contained_mask | __contained_public_mask 367 }; 368 369 struct __upcast_result; 370 struct __dyncast_result; 371 372 protected: 373 // Implementation defined member functions. 374 virtual bool 375 __do_upcast(const __class_type_info* __dst_type, void**__obj_ptr) const; 376 377 virtual bool 378 __do_catch(const type_info* __thr_type, void** __thr_obj, 379 unsigned __outer) const; 380 381 public: 382 // Helper for upcast. See if DST is us, or one of our bases. 383 // Return false if not found, true if found. 384 virtual bool 385 __do_upcast(const __class_type_info* __dst, const void* __obj, 386 __upcast_result& __restrict __result) const; 387 388 // Indicate whether SRC_PTR of type SRC_TYPE is contained publicly 389 // within OBJ_PTR. OBJ_PTR points to a base object of our type, 390 // which is the destination type. SRC2DST indicates how SRC 391 // objects might be contained within this type. If SRC_PTR is one 392 // of our SRC_TYPE bases, indicate the virtuality. Returns 393 // not_contained for non containment or private containment. 394 inline __sub_kind 395 __find_public_src(ptrdiff_t __src2dst, const void* __obj_ptr, 396 const __class_type_info* __src_type, 397 const void* __src_ptr) const; 398 399 // Helper for dynamic cast. ACCESS_PATH gives the access from the 400 // most derived object to this base. DST_TYPE indicates the 401 // desired type we want. OBJ_PTR points to a base of our type 402 // within the complete object. SRC_TYPE indicates the static type 403 // started from and SRC_PTR points to that base within the most 404 // derived object. Fill in RESULT with what we find. Return true 405 // if we have located an ambiguous match. 406 virtual bool 407 __do_dyncast(ptrdiff_t __src2dst, __sub_kind __access_path, 408 const __class_type_info* __dst_type, const void* __obj_ptr, 409 const __class_type_info* __src_type, const void* __src_ptr, 410 __dyncast_result& __result) const; 411 412 // Helper for find_public_subobj. SRC2DST indicates how SRC_TYPE 413 // bases are inherited by the type started from -- which is not 414 // necessarily the current type. The current type will be a base 415 // of the destination type. OBJ_PTR points to the current base. 416 virtual __sub_kind 417 __do_find_public_src(ptrdiff_t __src2dst, const void* __obj_ptr, 418 const __class_type_info* __src_type, 419 const void* __src_ptr) const; 420 }; 421 422 // Type information for a class with a single non-virtual base. 423 class __si_class_type_info : public __class_type_info 424 { 425 public: 426 const __class_type_info* __base_type; 427 428 explicit __si_class_type_info(const char * __n,const __class_type_info * __base)429 __si_class_type_info(const char *__n, const __class_type_info *__base) 430 : __class_type_info(__n), __base_type(__base) { } 431 432 virtual 433 ~__si_class_type_info(); 434 435 protected: 436 __si_class_type_info(const __si_class_type_info&); 437 438 __si_class_type_info& 439 operator=(const __si_class_type_info&); 440 441 // Implementation defined member functions. 442 virtual bool 443 __do_dyncast(ptrdiff_t __src2dst, __sub_kind __access_path, 444 const __class_type_info* __dst_type, const void* __obj_ptr, 445 const __class_type_info* __src_type, const void* __src_ptr, 446 __dyncast_result& __result) const; 447 448 virtual __sub_kind 449 __do_find_public_src(ptrdiff_t __src2dst, const void* __obj_ptr, 450 const __class_type_info* __src_type, 451 const void* __sub_ptr) const; 452 453 virtual bool 454 __do_upcast(const __class_type_info*__dst, const void*__obj, 455 __upcast_result& __restrict __result) const; 456 }; 457 458 // Type information for a class with multiple and/or virtual bases. 459 class __vmi_class_type_info : public __class_type_info 460 { 461 public: 462 unsigned int __flags; // Details about the class hierarchy. 463 unsigned int __base_count; // Dumber of direct bases. 464 465 // The array of bases uses the trailing array struct hack so this 466 // class is not constructable with a normal constructor. It is 467 // internally generated by the compiler. 468 __base_class_type_info __base_info[1]; // Array of bases. 469 470 explicit __vmi_class_type_info(const char * __n,int ___flags)471 __vmi_class_type_info(const char* __n, int ___flags) 472 : __class_type_info(__n), __flags(___flags), __base_count(0) { } 473 474 virtual 475 ~__vmi_class_type_info(); 476 477 // Implementation defined types. 478 enum __flags_masks 479 { 480 __non_diamond_repeat_mask = 0x1, // Distinct instance of repeated base. 481 __diamond_shaped_mask = 0x2, // Diamond shaped multiple inheritance. 482 __flags_unknown_mask = 0x10 483 }; 484 485 protected: 486 // Implementation defined member functions. 487 virtual bool 488 __do_dyncast(ptrdiff_t __src2dst, __sub_kind __access_path, 489 const __class_type_info* __dst_type, const void* __obj_ptr, 490 const __class_type_info* __src_type, const void* __src_ptr, 491 __dyncast_result& __result) const; 492 493 virtual __sub_kind 494 __do_find_public_src(ptrdiff_t __src2dst, const void* __obj_ptr, 495 const __class_type_info* __src_type, 496 const void* __src_ptr) const; 497 498 virtual bool 499 __do_upcast(const __class_type_info* __dst, const void* __obj, 500 __upcast_result& __restrict __result) const; 501 }; 502 503 // Dynamic cast runtime. 504 // src2dst has the following possible values 505 // >-1: src_type is a unique public non-virtual base of dst_type 506 // dst_ptr + src2dst == src_ptr 507 // -1: unspecified relationship 508 // -2: src_type is not a public base of dst_type 509 // -3: src_type is a multiple public non-virtual base of dst_type 510 extern "C" void* 511 __dynamic_cast(const void* __src_ptr, // Starting object. 512 const __class_type_info* __src_type, // Static type of object. 513 const __class_type_info* __dst_type, // Desired target type. 514 ptrdiff_t __src2dst); // How src and dst are related. 515 516 517 // Returns the type_info for the currently handled exception [15.3/8], or 518 // null if there is none. 519 extern "C" std::type_info* 520 __cxa_current_exception_type(); 521 } // namespace __cxxabiv1 522 523 // User programs should use the alias `abi'. 524 namespace abi = __cxxabiv1; 525 526 #endif // __cplusplus 527 528 #endif // __CXXABI_H 529