| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| #include "cxa_exception.h" |
|
|
| #include <__thread/support.h> |
|
|
| #if defined(_LIBCXXABI_HAS_NO_THREADS) |
|
|
| namespace __cxxabiv1 { |
| extern "C" { |
| static __cxa_eh_globals eh_globals; |
| __cxa_eh_globals *__cxa_get_globals() { return &eh_globals; } |
| __cxa_eh_globals *__cxa_get_globals_fast() { return &eh_globals; } |
| } |
| } |
|
|
| #elif __has_feature(cxx_thread_local) |
|
|
| namespace __cxxabiv1 { |
| namespace { |
| __cxa_eh_globals *__globals() { |
| static thread_local __cxa_eh_globals eh_globals; |
| return &eh_globals; |
| } |
| } |
|
|
| extern "C" { |
| __cxa_eh_globals *__cxa_get_globals() { return __globals(); } |
| __cxa_eh_globals *__cxa_get_globals_fast() { return __globals(); } |
| } |
| } |
|
|
| #else |
|
|
| #include "abort_message.h" |
| #include "fallback_malloc.h" |
|
|
| #if defined(__ELF__) && defined(_LIBCXXABI_LINK_PTHREAD_LIB) |
| #pragma comment(lib, "pthread") |
| #endif |
|
|
| |
| |
| |
|
|
| namespace __cxxabiv1 { |
| namespace { |
| std::__libcpp_tls_key key_; |
| constinit std::__libcpp_exec_once_flag flag_ = _LIBCPP_EXEC_ONCE_INITIALIZER; |
|
|
| void _LIBCPP_TLS_DESTRUCTOR_CC destruct_(void *p) { |
| __free_with_fallback(p); |
| if (0 != std::__libcpp_tls_set(key_, NULL)) |
| __abort_message("cannot zero out thread value for __cxa_get_globals()"); |
| } |
|
|
| void construct_() { |
| if (0 != std::__libcpp_tls_create(&key_, destruct_)) |
| __abort_message("cannot create thread specific key for __cxa_get_globals()"); |
| } |
| } |
|
|
| extern "C" { |
| __cxa_eh_globals *__cxa_get_globals() { |
| |
| __cxa_eh_globals *retVal = __cxa_get_globals_fast(); |
|
|
| |
| if (NULL == retVal) { |
| retVal = static_cast<__cxa_eh_globals*>( |
| __calloc_with_fallback(1, sizeof(__cxa_eh_globals))); |
| if (NULL == retVal) |
| __abort_message("cannot allocate __cxa_eh_globals"); |
| if (0 != std::__libcpp_tls_set(key_, retVal)) |
| __abort_message("std::__libcpp_tls_set failure in __cxa_get_globals()"); |
| } |
| return retVal; |
| } |
|
|
| |
| |
| |
| |
| __cxa_eh_globals *__cxa_get_globals_fast() { |
| |
| if (0 != std::__libcpp_execute_once(&flag_, construct_)) |
| __abort_message("execute once failure in __cxa_get_globals_fast()"); |
| return static_cast<__cxa_eh_globals*>(std::__libcpp_tls_get(key_)); |
| } |
| } |
| } |
|
|
| #endif |
|
|