1// SPDX-License-Identifier: GPL-3.0-or-later
2
3#include <cxxabi.h>
4#include <mos/assert.hpp>
5#include <mos/cpp_support.hpp>
6#include <mos/string.hpp>
7#include <mos_stdlib.hpp>
8
9void *__dso_handle = (void *) 0xcdcdcdcdcdcdcdcd; // this pointer should never get dereferenced
10
11void operator delete(void *)
12{
13 mos_panic("unused operator delete called");
14}
15
16void operator delete(void *ptr, size_t) noexcept
17{
18 do_kfree(ptr);
19}
20
21extern "C" int __cxa_atexit(void (*destructor)(void *), void *arg, void *dso)
22{
23 MOS_UNUSED(destructor);
24 MOS_UNUSED(arg);
25 MOS_UNUSED(dso);
26 return 0;
27}
28
29extern "C" void abort()
30{
31 mos_panic("Aborted");
32}
33
34void std::__glibcxx_assert_fail(const char *__file, int __line, const char *__function, const char *__condition) noexcept
35{
36 mos_panic_inline("assertion failed: %s:%u: %s: %s", __file, __line, __function, __condition);
37}
38
39void mos::__raise_bad_ptrresult_value(int errorCode)
40{
41 mos_panic_inline("PtrResultBase: bad value accessed: %d", errorCode);
42}
43
44void mos::__raise_null_pointer_exception()
45{
46 mos_panic_inline("mos::string: null pointer exception");
47}
48
49// static scoped variable constructor support
50
51extern "C" int abi::__cxa_guard_acquire(abi::__guard *g)
52{
53 // TODO: stub functions, implement 64-bit mutexes/futex-word
54 __atomic_thread_fence(__ATOMIC_ACQUIRE);
55 long val;
56 __atomic_load(g, &val, __ATOMIC_RELAXED);
57 return !val;
58}
59
60// this function is called when a constructor finishes
61extern "C" void abi::__cxa_guard_release(abi::__guard *g)
62{
63 long zero = 0;
64 __atomic_store(g, &zero, __ATOMIC_RELEASE);
65 __atomic_thread_fence(__ATOMIC_RELEASE);
66}
67
68// this function is called when a constructor throws an exception
69extern "C" void abi::__cxa_guard_abort(abi::__guard *)
70{
71}
72