diff options
| author | Amlal El Mahrouss <amlal@nekernel.org> | 2026-03-06 05:54:15 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal@nekernel.org> | 2026-03-06 05:54:15 +0100 |
| commit | e9eb93ced36628f2c111b96c4916bb649636e71c (patch) | |
| tree | 8337972610acc6de512e5e6203eab9f44428f49b /src/neboot-cxx-abi.cpp | |
| parent | 484ce476198a7b2fa2753f78a30e683c467817c0 (diff) | |
[CHORE] Source code level refactors and improvements.
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
Diffstat (limited to 'src/neboot-cxx-abi.cpp')
| -rw-r--r-- | src/neboot-cxx-abi.cpp | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/src/neboot-cxx-abi.cpp b/src/neboot-cxx-abi.cpp new file mode 100644 index 0000000..a630f3e --- /dev/null +++ b/src/neboot-cxx-abi.cpp @@ -0,0 +1,76 @@ +// Copyright 2024-2026, Amlal El Mahrouss (amlal@nekernel.org) +// Distributed under the Apache Software License, Version 2.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.apache.org/licenses/LICENSE-2.0) +// Official repository: https://github.com/ne-foss-org/neboot + +#include <include/cxx-abi.hpp> + +/// BUGS: 0 + +extern "C" __SIZE_TYPE__ nb_put_string(const char* text); +extern "C" void nb_panic(const char* reason); + +extern "C" void __stack_chk_fail() { + nb_put_string("[stack-canary] Buffer overflow detected, halting...\n"); + nb_panic("stack_canary_fail"); +} + +void* __dso_handle; + +extern "C" __SIZE_TYPE__ nb_put_string(const char* text); +extern "C" void nb_panic(const char* reason); + +atexit_func_entry_t __atexit_funcs[DSO_MAX_OBJECTS]; +uarch_t __atexit_func_count; + +extern "C" void __cxa_pure_virtual() { + nb_put_string("[__cxa_pure_virtual] Placeholder\n"); +} + +extern "C" int __cxa_atexit(void (*f)(void*), void* arg, void* dso) { + if (__atexit_func_count >= DSO_MAX_OBJECTS) return -1; + + __atexit_funcs[__atexit_func_count].destructor_func = f; + __atexit_funcs[__atexit_func_count].obj_ptr = arg; + __atexit_funcs[__atexit_func_count].dso_handle = dso; + + __atexit_func_count++; + + return 0; +} + +extern "C" void __cxa_finalize(void* f) { + uarch_t i = __atexit_func_count; + if (!f) { + while (i--) { + if (__atexit_funcs[i].destructor_func) { + (*__atexit_funcs[i].destructor_func)(__atexit_funcs[i].obj_ptr); + }; + } + + return; + } + + while (i--) { + if (__atexit_funcs[i].destructor_func) { + (*__atexit_funcs[i].destructor_func)(__atexit_funcs[i].obj_ptr); + __atexit_funcs[i].destructor_func = 0; + }; + } +} + +namespace cxxabiv1 { +extern "C" int __cxa_guard_acquire(__guard* g) { + (void) g; + return 0; +} + +extern "C" int __cxa_guard_release(__guard* g) { + *(char*) g = 1; + return 0; +} + +extern "C" void __cxa_guard_abort(__guard* g) { + (void) g; +} +} // namespace cxxabiv1 |
