cxxabi.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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 1002
  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. extern "C" {
  31. // 2.4.2 Allocating the Exception Object
  32. #ifndef __EMSCRIPTEN__
  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. #else
  38. extern _LIBCXXABI_FUNC_VIS void *
  39. __cxa_allocate_exception(size_t thrown_size) _NOEXCEPT;
  40. extern _LIBCXXABI_FUNC_VIS void
  41. __cxa_free_exception(void *thrown_exception) _NOEXCEPT;
  42. #endif
  43. // 2.4.3 Throwing the Exception Object
  44. #ifdef __USING_WASM_EXCEPTIONS__
  45. extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_NORETURN void
  46. __cxa_throw(void *thrown_exception, std::type_info *tinfo,
  47. void *(*dest)(void *));
  48. #else
  49. extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_NORETURN void
  50. __cxa_throw(void *thrown_exception, std::type_info *tinfo,
  51. void (*dest)(void *));
  52. #endif
  53. // 2.5.3 Exception Handlers
  54. #ifndef __EMSCRIPTEN__
  55. extern _LIBCXXABI_FUNC_VIS void *
  56. __cxa_get_exception_ptr(void *exceptionObject) throw();
  57. #else
  58. extern _LIBCXXABI_FUNC_VIS void *
  59. __cxa_get_exception_ptr(void *exceptionObject) _NOEXCEPT;
  60. #endif
  61. #ifndef __EMSCRIPTEN__
  62. extern _LIBCXXABI_FUNC_VIS void *
  63. __cxa_begin_catch(void *exceptionObject) throw();
  64. #else
  65. extern _LIBCXXABI_FUNC_VIS void *
  66. __cxa_begin_catch(void *exceptionObject) _NOEXCEPT;
  67. #endif
  68. extern _LIBCXXABI_FUNC_VIS void __cxa_end_catch();
  69. #if defined(_LIBCXXABI_ARM_EHABI)
  70. extern _LIBCXXABI_FUNC_VIS bool
  71. __cxa_begin_cleanup(void *exceptionObject) throw();
  72. extern _LIBCXXABI_FUNC_VIS void __cxa_end_cleanup();
  73. #endif
  74. extern _LIBCXXABI_FUNC_VIS std::type_info *__cxa_current_exception_type();
  75. // 2.5.4 Rethrowing Exceptions
  76. extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_NORETURN void __cxa_rethrow();
  77. // 2.6 Auxiliary Runtime APIs
  78. extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_NORETURN void __cxa_bad_cast(void);
  79. extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_NORETURN void __cxa_bad_typeid(void);
  80. extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_NORETURN void
  81. __cxa_throw_bad_array_new_length(void);
  82. // 3.2.6 Pure Virtual Function API
  83. extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_NORETURN void __cxa_pure_virtual(void);
  84. // 3.2.7 Deleted Virtual Function API
  85. extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_NORETURN void __cxa_deleted_virtual(void);
  86. // 3.3.2 One-time Construction API
  87. #if defined(_LIBCXXABI_GUARD_ABI_ARM)
  88. extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_ALWAYS_COLD int __cxa_guard_acquire(uint32_t *);
  89. extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_ALWAYS_COLD void __cxa_guard_release(uint32_t *);
  90. extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_ALWAYS_COLD void __cxa_guard_abort(uint32_t *);
  91. #else
  92. extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_ALWAYS_COLD int __cxa_guard_acquire(uint64_t *);
  93. extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_ALWAYS_COLD void __cxa_guard_release(uint64_t *);
  94. extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_ALWAYS_COLD void __cxa_guard_abort(uint64_t *);
  95. #endif
  96. // 3.3.3 Array Construction and Destruction API
  97. extern _LIBCXXABI_FUNC_VIS void *
  98. __cxa_vec_new(size_t element_count, size_t element_size, size_t padding_size,
  99. void (*constructor)(void *), void (*destructor)(void *));
  100. extern _LIBCXXABI_FUNC_VIS void *
  101. __cxa_vec_new2(size_t element_count, size_t element_size, size_t padding_size,
  102. void (*constructor)(void *), void (*destructor)(void *),
  103. void *(*alloc)(size_t), void (*dealloc)(void *));
  104. extern _LIBCXXABI_FUNC_VIS void *
  105. __cxa_vec_new3(size_t element_count, size_t element_size, size_t padding_size,
  106. void (*constructor)(void *), void (*destructor)(void *),
  107. void *(*alloc)(size_t), void (*dealloc)(void *, size_t));
  108. extern _LIBCXXABI_FUNC_VIS void
  109. __cxa_vec_ctor(void *array_address, size_t element_count, size_t element_size,
  110. void (*constructor)(void *), void (*destructor)(void *));
  111. extern _LIBCXXABI_FUNC_VIS void __cxa_vec_dtor(void *array_address,
  112. size_t element_count,
  113. size_t element_size,
  114. void (*destructor)(void *));
  115. extern _LIBCXXABI_FUNC_VIS void __cxa_vec_cleanup(void *array_address,
  116. size_t element_count,
  117. size_t element_size,
  118. void (*destructor)(void *));
  119. extern _LIBCXXABI_FUNC_VIS void __cxa_vec_delete(void *array_address,
  120. size_t element_size,
  121. size_t padding_size,
  122. void (*destructor)(void *));
  123. extern _LIBCXXABI_FUNC_VIS void
  124. __cxa_vec_delete2(void *array_address, size_t element_size, size_t padding_size,
  125. void (*destructor)(void *), void (*dealloc)(void *));
  126. extern _LIBCXXABI_FUNC_VIS void
  127. __cxa_vec_delete3(void *__array_address, size_t element_size,
  128. size_t padding_size, void (*destructor)(void *),
  129. void (*dealloc)(void *, size_t));
  130. extern _LIBCXXABI_FUNC_VIS void
  131. __cxa_vec_cctor(void *dest_array, void *src_array, size_t element_count,
  132. size_t element_size, void (*constructor)(void *, void *),
  133. void (*destructor)(void *));
  134. // 3.3.5.3 Runtime API
  135. // These functions are part of the C++ ABI, but they are not defined in libc++abi:
  136. // int __cxa_atexit(void (*)(void *), void *, void *);
  137. // void __cxa_finalize(void *);
  138. // 3.4 Demangler API
  139. extern _LIBCXXABI_FUNC_VIS char *__cxa_demangle(const char *mangled_name,
  140. char *output_buffer,
  141. size_t *length, int *status);
  142. // Apple additions to support C++ 0x exception_ptr class
  143. // These are primitives to wrap a smart pointer around an exception object
  144. #ifndef __EMSCRIPTEN__
  145. extern _LIBCXXABI_FUNC_VIS void *__cxa_current_primary_exception() throw();
  146. #else
  147. extern _LIBCXXABI_FUNC_VIS void *__cxa_current_primary_exception() _NOEXCEPT;
  148. #endif
  149. extern _LIBCXXABI_FUNC_VIS void
  150. __cxa_rethrow_primary_exception(void *primary_exception);
  151. #ifndef __EMSCRIPTEN__
  152. extern _LIBCXXABI_FUNC_VIS void
  153. __cxa_increment_exception_refcount(void *primary_exception) throw();
  154. #else
  155. extern _LIBCXXABI_FUNC_VIS void
  156. __cxa_increment_exception_refcount(void *primary_exception) _NOEXCEPT;
  157. #endif
  158. #ifndef __EMSCRIPTEN__
  159. extern _LIBCXXABI_FUNC_VIS void
  160. __cxa_decrement_exception_refcount(void *primary_exception) throw();
  161. #else
  162. extern _LIBCXXABI_FUNC_VIS void
  163. __cxa_decrement_exception_refcount(void *primary_exception) _NOEXCEPT;
  164. #endif
  165. // Apple extension to support std::uncaught_exception()
  166. #ifndef __EMSCRIPTEN__
  167. extern _LIBCXXABI_FUNC_VIS bool __cxa_uncaught_exception() throw();
  168. extern _LIBCXXABI_FUNC_VIS unsigned int __cxa_uncaught_exceptions() throw();
  169. #else
  170. extern _LIBCXXABI_FUNC_VIS bool __cxa_uncaught_exception() _NOEXCEPT;
  171. extern _LIBCXXABI_FUNC_VIS unsigned int __cxa_uncaught_exceptions() _NOEXCEPT;
  172. #endif
  173. #if defined(__linux__) || defined(__Fuchsia__)
  174. // Linux and Fuchsia TLS support. Not yet an official part of the Itanium ABI.
  175. // https://sourceware.org/glibc/wiki/Destructor%20support%20for%20thread_local%20variables
  176. extern _LIBCXXABI_FUNC_VIS int __cxa_thread_atexit(void (*)(void *), void *,
  177. void *) throw();
  178. #endif
  179. } // extern "C"
  180. } // namespace __cxxabiv1
  181. namespace abi = __cxxabiv1;
  182. #endif // __cplusplus
  183. #endif // __CXXABI_H