From 6cbad718fbe207c92aef3400690bca35891d38b3 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Thu, 2 Feb 2023 15:50:26 +0200 Subject: [PATCH] Kernel: Add some more cxxabi functionality We can now declate static variables in functions --- kernel/icxxabi.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) 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