cxxabi.h 7.1 KB

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