summaryrefslogtreecommitdiff
path: root/kernel/lib/libcxx/include/new
blob: 3e16108309b12f9dd39c62fcfe706486073a1ce4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// -*- C++ -*-
//===----------------------------------------------------------------------===//
//
// Part of the BastionOS freestanding C++ standard library.
//
// Declares placement new and related facilities.
// The actual operator new/delete are defined in cxxabi.cpp.
//
//===----------------------------------------------------------------------===//

#ifndef _LIBBASTION_NEW
#define _LIBBASTION_NEW

#include <__config>
#include <cstddef>

_LIBBASTION_BEGIN_NAMESPACE_STD

struct nothrow_t { explicit nothrow_t() = default; };
inline constexpr nothrow_t nothrow{};

enum class align_val_t : size_t {};

// launder
template<class _Tp>
_LIBBASTION_NODISCARD inline constexpr _Tp* launder(_Tp* __p) noexcept {
    return __builtin_launder(__p);
}

// hardware_destructive_interference_size / hardware_constructive_interference_size
#ifdef __GCC_DESTRUCTIVE_SIZE
inline constexpr size_t hardware_destructive_interference_size  = __GCC_DESTRUCTIVE_SIZE;
inline constexpr size_t hardware_constructive_interference_size = __GCC_CONSTRUCTIVE_SIZE;
#else
inline constexpr size_t hardware_destructive_interference_size  = 64;
inline constexpr size_t hardware_constructive_interference_size = 64;
#endif

_LIBBASTION_END_NAMESPACE_STD

// Placement new/delete — these must be at global scope.
// Guard against redefinition from cxxabi.cpp or compiler headers.
#ifndef _LIBBASTION_PLACEMENT_NEW_DEFINED
#define _LIBBASTION_PLACEMENT_NEW_DEFINED
_LIBBASTION_NODISCARD inline void* operator new(std::size_t, void* __p) noexcept { return __p; }
_LIBBASTION_NODISCARD inline void* operator new[](std::size_t, void* __p) noexcept { return __p; }
inline void operator delete(void*, void*) noexcept {}
inline void operator delete[](void*, void*) noexcept {}
#endif

#endif // _LIBBASTION_NEW