diff --git a/kernel/icxxabi.cpp b/kernel/icxxabi.cpp index 8cdb147e2..f5883a5b5 100644 --- a/kernel/icxxabi.cpp +++ b/kernel/icxxabi.cpp @@ -1,3 +1,7 @@ +#include +#include +#include + #define ATEXIT_MAX_FUNCS 128 #ifdef __cplusplus @@ -109,6 +113,35 @@ void __cxa_finalize(void *f) }; }; + + +namespace __cxxabiv1 +{ + /* guard variables */ + static Kernel::SpinLock s_spin_lock; + + /* The ABI requires a 64-bit type. */ + __extension__ typedef int __guard __attribute__((mode(__DI__))); + + int __cxa_guard_acquire (__guard* g) + { + Kernel::LockGuard lock_guard(s_spin_lock); + return !*(int*)g; + } + + void __cxa_guard_release (__guard* g) + { + Kernel::LockGuard lock_guard(s_spin_lock); + *(int*)g = 1; + } + + void __cxa_guard_abort (__guard*) + { + Kernel::panic("__cxa_guard_abort"); + __builtin_unreachable(); + } +} + #ifdef __cplusplus }; #endif