From 62db9a8ef3cfe94f43a2b8d438d72b1f4bb0e16f Mon Sep 17 00:00:00 2001 From: Bananymous Date: Tue, 30 Jul 2024 12:02:05 +0300 Subject: [PATCH] LibC: Implement C++ static guards --- userspace/libraries/LibC/icxxabi.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/userspace/libraries/LibC/icxxabi.cpp b/userspace/libraries/LibC/icxxabi.cpp index 8a91d1cacc..3d572b2e55 100644 --- a/userspace/libraries/LibC/icxxabi.cpp +++ b/userspace/libraries/LibC/icxxabi.cpp @@ -39,3 +39,26 @@ extern "C" void __cxa_finalize(void* f) } } }; + +namespace __cxxabiv1 +{ + using __guard = uint64_t; + + extern "C" int __cxa_guard_acquire (__guard* g) + { + uint8_t* byte = reinterpret_cast(g); + uint8_t zero = 0; + return __atomic_compare_exchange_n(byte, &zero, 1, false, __ATOMIC_ACQUIRE, __ATOMIC_ACQUIRE); + } + + extern "C" void __cxa_guard_release (__guard* g) + { + uint8_t* byte = reinterpret_cast(g); + __atomic_store_n(byte, 0, __ATOMIC_RELEASE); + } + + extern "C" void __cxa_guard_abort (__guard*) + { + ASSERT_NOT_REACHED(); + } +}