|
@@ -13,13 +13,29 @@
|
|
|
#define KMALLOC_SCRUB_BYTE 0xbb
|
|
|
#define KFREE_SCRUB_BYTE 0xaa
|
|
|
|
|
|
-#define MAKE_ALIGNED_ALLOCATED(type, alignment) \
|
|
|
-public: \
|
|
|
- [[nodiscard]] void* operator new(size_t) noexcept { return kmalloc_aligned<alignment>(sizeof(type)); } \
|
|
|
- void operator delete(void* ptr) noexcept { kfree_aligned(ptr); } \
|
|
|
- \
|
|
|
+#define MAKE_ALIGNED_ALLOCATED(type, alignment) \
|
|
|
+public: \
|
|
|
+ [[nodiscard]] void* operator new(size_t) \
|
|
|
+ { \
|
|
|
+ void* ptr = kmalloc_aligned<alignment>(sizeof(type)); \
|
|
|
+ VERIFY(ptr); \
|
|
|
+ return ptr; \
|
|
|
+ } \
|
|
|
+ [[nodiscard]] void* operator new(size_t, const std::nothrow_t&) noexcept { return kmalloc_aligned<alignment>(sizeof(type)); } \
|
|
|
+ void operator delete(void* ptr) noexcept { kfree_aligned(ptr); } \
|
|
|
+ \
|
|
|
private:
|
|
|
|
|
|
+// The C++ standard specifies that the nothrow allocation tag should live in the std namespace.
|
|
|
+// Otherwise, `new (std::nothrow)` calls wouldn't get resolved.
|
|
|
+namespace std {
|
|
|
+struct nothrow_t {
|
|
|
+ explicit nothrow_t() = default;
|
|
|
+};
|
|
|
+
|
|
|
+extern const nothrow_t nothrow;
|
|
|
+};
|
|
|
+
|
|
|
void kmalloc_init();
|
|
|
[[gnu::malloc, gnu::returns_nonnull, gnu::alloc_size(1)]] void* kmalloc_impl(size_t);
|
|
|
[[gnu::malloc, gnu::returns_nonnull, gnu::alloc_size(1)]] void* kmalloc_eternal(size_t);
|
|
@@ -41,10 +57,12 @@ extern bool g_dump_kmalloc_stacks;
|
|
|
inline void* operator new(size_t, void* p) { return p; }
|
|
|
inline void* operator new[](size_t, void* p) { return p; }
|
|
|
|
|
|
-[[nodiscard]] void* operator new(size_t size) noexcept;
|
|
|
+[[nodiscard]] void* operator new(size_t size);
|
|
|
+[[nodiscard]] void* operator new(size_t size, const std::nothrow_t&) noexcept;
|
|
|
void operator delete(void* ptr) noexcept;
|
|
|
void operator delete(void* ptr, size_t) noexcept;
|
|
|
-[[nodiscard]] void* operator new[](size_t size) noexcept;
|
|
|
+[[nodiscard]] void* operator new[](size_t size);
|
|
|
+[[nodiscard]] void* operator new[](size_t size, const std::nothrow_t&) noexcept;
|
|
|
void operator delete[](void* ptrs) noexcept;
|
|
|
void operator delete[](void* ptr, size_t) noexcept;
|
|
|
|