1*06c3fb27SDimitry Andric //===----------------------------------------------------------------------===// 2*06c3fb27SDimitry Andric // 3*06c3fb27SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*06c3fb27SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 5*06c3fb27SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6*06c3fb27SDimitry Andric // 7*06c3fb27SDimitry Andric //===----------------------------------------------------------------------===// 8*06c3fb27SDimitry Andric 9*06c3fb27SDimitry Andric #include <new> 10*06c3fb27SDimitry Andric 11*06c3fb27SDimitry Andric #include "include/atomic_support.h" 12*06c3fb27SDimitry Andric 13*06c3fb27SDimitry Andric #if defined(_LIBCPP_ABI_MICROSOFT) 14*06c3fb27SDimitry Andric # if !defined(_LIBCPP_ABI_VCRUNTIME) 15*06c3fb27SDimitry Andric # define _LIBPCPP_DEFINE_NEW_HANDLER 16*06c3fb27SDimitry Andric # endif 17*06c3fb27SDimitry Andric #elif defined(LIBCXX_BUILDING_LIBCXXABI) 18*06c3fb27SDimitry Andric // nothing to do, we use the one from libc++abi 19*06c3fb27SDimitry Andric #elif defined(LIBCXXRT) 20*06c3fb27SDimitry Andric # define _LIBPCPP_DEFINE_NEW_HANDLER 21*06c3fb27SDimitry Andric #elif defined(__GLIBCXX__) 22*06c3fb27SDimitry Andric // nothing to do, we use the one from libstdc++/libsupc++ 23*06c3fb27SDimitry Andric #else 24*06c3fb27SDimitry Andric # define _LIBPCPP_DEFINE_NEW_HANDLER 25*06c3fb27SDimitry Andric #endif 26*06c3fb27SDimitry Andric 27*06c3fb27SDimitry Andric #if defined(_LIBPCPP_DEFINE_NEW_HANDLER) 28*06c3fb27SDimitry Andric 29*06c3fb27SDimitry Andric namespace std { // purposefully not versioned 30*06c3fb27SDimitry Andric 31*06c3fb27SDimitry Andric static constinit std::new_handler __new_handler = nullptr; 32*06c3fb27SDimitry Andric set_new_handler(new_handler handler)33*06c3fb27SDimitry Andricnew_handler set_new_handler(new_handler handler) noexcept { return __libcpp_atomic_exchange(&__new_handler, handler); } 34*06c3fb27SDimitry Andric get_new_handler()35*06c3fb27SDimitry Andricnew_handler get_new_handler() noexcept { return __libcpp_atomic_load(&__new_handler); } 36*06c3fb27SDimitry Andric 37*06c3fb27SDimitry Andric } // namespace std 38*06c3fb27SDimitry Andric 39*06c3fb27SDimitry Andric #endif // _LIBPCPP_DEFINE_NEW_HANDLER 40