summaryrefslogtreecommitdiff
path: root/Kernel
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-03-11 13:11:59 +0100
committerAndreas Kling <kling@serenityos.org>2021-03-11 14:21:49 +0100
commit4fcc637e29104f543c1bf278cc2481bfeb9ea3fa (patch)
tree773f704e342bb98d926778f1bbd5e874831e0fb8 /Kernel
parent96fb3d4a11ea161af4e56dcf371b3f75626b49ea (diff)
downloadserenity-4fcc637e29104f543c1bf278cc2481bfeb9ea3fa.zip
Kernel: Add MAKE_ALIGNED_ALLOCATED helper macro
This macro inserts operator new/delete into a class, allowing you to very easily specify a specific heap alignment.
Diffstat (limited to 'Kernel')
-rw-r--r--Kernel/Heap/kmalloc.h7
1 files changed, 7 insertions, 0 deletions
diff --git a/Kernel/Heap/kmalloc.h b/Kernel/Heap/kmalloc.h
index 7acc5f018a..5c0101ea32 100644
--- a/Kernel/Heap/kmalloc.h
+++ b/Kernel/Heap/kmalloc.h
@@ -32,6 +32,13 @@
#define KMALLOC_SCRUB_BYTE 0xbb
#define KFREE_SCRUB_BYTE 0xaa
+#define MAKE_ALIGNED_ALLOCATED(type, alignment) \
+public: \
+ void* operator new(size_t) { return kmalloc_aligned<alignment>(sizeof(type)); } \
+ void operator delete(void* ptr) { kfree_aligned(ptr); } \
+ \
+private:
+
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);