cxxabi.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #ifndef __CXXABI_H
  9. #define __CXXABI_H
  10. /*
  11. * This header provides the interface to the C++ ABI as defined at:
  12. * https://itanium-cxx-abi.github.io/cxx-abi/
  13. */
  14. #include <stddef.h>
  15. #include <stdint.h>
  16. #include <__cxxabi_config.h>
  17. #define _LIBCPPABI_VERSION 15000
  18. #define _LIBCXXABI_NORETURN __attribute__((noreturn))
  19. #define _LIBCXXABI_ALWAYS_COLD __attribute__((cold))
  20. #ifdef __cplusplus
  21. namespace std {
  22. #if defined(_WIN32)
  23. class _LIBCXXABI_TYPE_VIS type_info; // forward declaration
  24. #else
  25. class type_info; // forward declaration
  26. #endif
  27. }
  28. // runtime routines use C calling conventions, but are in __cxxabiv1 namespace
  29. namespace __cxxabiv1 {
  30. struct __cxa_exception;
  31. extern "C" {
  32. // 2.4.2 Allocating the Exception Object
  33. extern _LIBCXXABI_FUNC_VIS void *
  34. __cxa_allocate_exception(size_t thrown_size) throw();
  35. extern _LIBCXXABI_FUNC_VIS void
  36. __cxa_free_exception(void *thrown_exception) throw();
  37. // This function is an LLVM extension, which mirrors the same extension in libsupc++ and libcxxrt
  38. extern _LIBCXXABI_FUNC_VIS __cxa_exception*
  39. #ifdef __wasm__
  40. // In Wasm, a destructor returns its argument
  41. __cxa_init_primary_exception(void* object, std::type_info* tinfo, void*(_LIBCXXABI_DTOR_FUNC* dest)(void*)) throw();
  42. #else
  43. __cxa_init_primary_exception(void* object, std::type_info* tinfo, void(_LIBCXXABI_DTOR_FUNC* dest)(void*)) throw();
  44. #endif
  45. // 2.4.3 Throwing the Exception Object
  46. extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_NORETURN void
  47. __cxa_throw(void *thrown_exception, std::type_info *tinfo,
  48. #ifdef __wasm__
  49. void *(_LIBCXXABI_DTOR_FUNC *dest)(void *));
  50. #else
  51. void (_LIBCXXABI_DTOR_FUNC *dest)(void *));
  52. #endif
  53. // 2.5.3 Exception Handlers
  54. extern _LIBCXXABI_FUNC_VIS void *
  55. __cxa_get_exception_ptr(void *exceptionObject) throw();
  56. extern _LIBCXXABI_FUNC_VIS void *
  57. __cxa_begin_catch(void *exceptionObject) throw();
  58. extern _LIBCXXABI_FUNC_VIS void __cxa_end_catch();
  59. #if defined(_LIBCXXABI_ARM_EHABI)
  60. extern _LIBCXXABI_FUNC_VIS bool
  61. __cxa_begin_cleanup(void *exceptionObject) throw();
  62. extern _LIBCXXABI_FUNC_VIS void __cxa_end_cleanup();
  63. #endif
  64. extern _LIBCXXABI_FUNC_VIS std::type_info *__cxa_current_exception_type();
  65. // GNU extension
  66. // Calls `terminate` with the current exception being caught. This function is used by GCC when a `noexcept` function
  67. // throws an exception inside a try/catch block and doesn't catch it.
  68. extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_NORETURN void __cxa_call_terminate(void*) throw();
  69. // 2.5.4 Rethrowing Exceptions
  70. extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_NORETURN void __cxa_rethrow();
  71. // 2.6 Auxiliary Runtime APIs
  72. extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_NORETURN void __cxa_bad_cast(void);
  73. extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_NORETURN void __cxa_bad_typeid(void);
  74. extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_NORETURN void
  75. __cxa_throw_bad_array_new_length(void);
  76. // 3.2.6 Pure Virtual Function API
  77. extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_NORETURN void __cxa_pure_virtual(void);
  78. // 3.2.7 Deleted Virtual Function API
  79. extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_NORETURN void __cxa_deleted_virtual(void);
  80. // 3.3.2 One-time Construction API
  81. #if defined(_LIBCXXABI_GUARD_ABI_ARM)
  82. extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_ALWAYS_COLD int __cxa_guard_acquire(uint32_t *);
  83. extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_ALWAYS_COLD void __cxa_guard_release(uint32_t *);
  84. extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_ALWAYS_COLD void __cxa_guard_abort(uint32_t *);
  85. #else
  86. extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_ALWAYS_COLD int __cxa_guard_acquire(uint64_t *);
  87. extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_ALWAYS_COLD void __cxa_guard_release(uint64_t *);
  88. extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_ALWAYS_COLD void __cxa_guard_abort(uint64_t *);
  89. #endif
  90. // 3.3.3 Array Construction and Destruction API
  91. extern _LIBCXXABI_FUNC_VIS void *
  92. __cxa_vec_new(size_t element_count, size_t element_size, size_t padding_size,
  93. void (*constructor)(void *), void (*destructor)(void *));
  94. extern _LIBCXXABI_FUNC_VIS void *
  95. __cxa_vec_new2(size_t element_count, size_t element_size, size_t padding_size,
  96. void (*constructor)(void *), void (*destructor)(void *),
  97. void *(*alloc)(size_t), void (*dealloc)(void *));
  98. extern _LIBCXXABI_FUNC_VIS void *
  99. __cxa_vec_new3(size_t element_count, size_t element_size, size_t padding_size,
  100. void (*constructor)(void *), void (*destructor)(void *),
  101. void *(*alloc)(size_t), void (*dealloc)(void *, size_t));
  102. extern _LIBCXXABI_FUNC_VIS void
  103. __cxa_vec_ctor(void *array_address, size_t element_count, size_t element_size,
  104. void (*constructor)(void *), void (*destructor)(void *));
  105. extern _LIBCXXABI_FUNC_VIS void __cxa_vec_dtor(void *array_address,
  106. size_t element_count,
  107. size_t element_size,
  108. void (*destructor)(void *));
  109. extern _LIBCXXABI_FUNC_VIS void __cxa_vec_cleanup(void *array_address,
  110. size_t element_count,
  111. size_t element_size,
  112. void (*destructor)(void *));
  113. extern _LIBCXXABI_FUNC_VIS void __cxa_vec_delete(void *array_address,
  114. size_t element_size,
  115. size_t padding_size,
  116. void (*destructor)(void *));
  117. extern _LIBCXXABI_FUNC_VIS void
  118. __cxa_vec_delete2(void *array_address, size_t element_size, size_t padding_size,
  119. void (*destructor)(void *), void (*dealloc)(void *));
  120. extern _LIBCXXABI_FUNC_VIS void
  121. __cxa_vec_delete3(void *__array_address, size_t element_size,
  122. size_t padding_size, void (*destructor)(void *),
  123. void (*dealloc)(void *, size_t));
  124. extern _LIBCXXABI_FUNC_VIS void
  125. __cxa_vec_cctor(void *dest_array, void *src_array, size_t element_count,
  126. size_t element_size, void (*constructor)(void *, void *),
  127. void (*destructor)(void *));
  128. // 3.3.5.3 Runtime API
  129. // These functions are part of the C++ ABI, but they are not defined in libc++abi:
  130. // int __cxa_atexit(void (*)(void *), void *, void *);
  131. // void __cxa_finalize(void *);
  132. // 3.4 Demangler API
  133. extern _LIBCXXABI_FUNC_VIS char *__cxa_demangle(const char *mangled_name,
  134. char *output_buffer,
  135. size_t *length, int *status);
  136. // Apple additions to support C++ 0x exception_ptr class
  137. // These are primitives to wrap a smart pointer around an exception object
  138. extern _LIBCXXABI_FUNC_VIS void *__cxa_current_primary_exception() throw();
  139. extern _LIBCXXABI_FUNC_VIS void
  140. __cxa_rethrow_primary_exception(void *primary_exception);
  141. extern _LIBCXXABI_FUNC_VIS void
  142. __cxa_increment_exception_refcount(void *primary_exception) throw();
  143. extern _LIBCXXABI_FUNC_VIS void
  144. __cxa_decrement_exception_refcount(void *primary_exception) throw();
  145. // Apple extension to support std::uncaught_exception()
  146. extern _LIBCXXABI_FUNC_VIS bool __cxa_uncaught_exception() throw();
  147. extern _LIBCXXABI_FUNC_VIS unsigned int __cxa_uncaught_exceptions() throw();
  148. #if defined(__linux__) || defined(__Fuchsia__)
  149. // Linux and Fuchsia TLS support. Not yet an official part of the Itanium ABI.
  150. // https://sourceware.org/glibc/wiki/Destructor%20support%20for%20thread_local%20variables
  151. extern _LIBCXXABI_FUNC_VIS int __cxa_thread_atexit(void (*)(void *), void *,
  152. void *) throw();
  153. #endif
  154. } // extern "C"
  155. } // namespace __cxxabiv1
  156. namespace abi = __cxxabiv1;
  157. #endif // __cplusplus
  158. #endif // __CXXABI_H