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