1 | // SPDX-License-Identifier: GPL-3.0-or-later |
2 | |
3 | #include <cxxabi.h> |
4 | #include <mos/assert.hpp> |
5 | #include <mos/string.hpp> |
6 | #include <mos_stdlib.hpp> |
7 | |
8 | void *__dso_handle = (void *) 0xcdcdcdcdcdcdcdcd; // this pointer should never get dereferenced |
9 | |
10 | void operator delete(void *) |
11 | { |
12 | mos_panic("unused operator delete called" ); |
13 | } |
14 | |
15 | void operator delete(void *ptr, size_t) noexcept |
16 | { |
17 | do_kfree(ptr); |
18 | } |
19 | |
20 | extern "C" int __cxa_atexit(void (*destructor)(void *), void *arg, void *dso) |
21 | { |
22 | MOS_UNUSED(destructor); |
23 | MOS_UNUSED(arg); |
24 | MOS_UNUSED(dso); |
25 | return 0; |
26 | } |
27 | |
28 | extern "C" void abort() |
29 | { |
30 | mos_panic("Aborted" ); |
31 | } |
32 | |
33 | // static scoped variable constructor support |
34 | |
35 | extern "C" int abi::__cxa_guard_acquire(abi::__guard *g) |
36 | { |
37 | // TODO: stub functions, implement 64-bit mutexes/futex-word |
38 | __atomic_thread_fence(__ATOMIC_ACQUIRE); |
39 | long val; |
40 | __atomic_load(g, &val, __ATOMIC_RELAXED); |
41 | return !val; |
42 | } |
43 | |
44 | // this function is called when a constructor finishes |
45 | extern "C" void abi::__cxa_guard_release(abi::__guard *g) |
46 | { |
47 | long zero = 0; |
48 | __atomic_store(g, &zero, __ATOMIC_RELEASE); |
49 | __atomic_thread_fence(__ATOMIC_RELEASE); |
50 | } |
51 | |
52 | // this function is called when a constructor throws an exception |
53 | extern "C" void abi::__cxa_guard_abort(abi::__guard *) |
54 | { |
55 | } |
56 | |