From e44ccddba34e32be20794edec4699ba89731f8e0 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Tue, 1 Nov 2022 09:28:44 +0100 Subject: [PATCH] AK+Kernel: Don't allow allocations in AK::Function in kernel mode Refs #6369. Fixes #15053. Co-authored-by: Brian Gianforcaro --- AK/Function.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/AK/Function.h b/AK/Function.h index 315743ee1a..4753c25e35 100644 --- a/AK/Function.h +++ b/AK/Function.h @@ -213,13 +213,18 @@ private: { VERIFY(m_call_nesting_level == 0); using WrapperType = CallableWrapper; +#ifndef KERNEL if constexpr (sizeof(WrapperType) > inline_capacity) { *bit_cast(&m_storage) = new WrapperType(forward(callable)); m_kind = FunctionKind::Outline; } else { +#endif + static_assert(sizeof(WrapperType) <= inline_capacity); new (m_storage) WrapperType(forward(callable)); m_kind = FunctionKind::Inline; +#ifndef KERNEL } +#endif } void move_from(Function&& other) @@ -246,8 +251,13 @@ private: FunctionKind m_kind { FunctionKind::NullPointer }; bool m_deferred_clear { false }; mutable Atomic m_call_nesting_level { 0 }; +#ifndef KERNEL // Empirically determined to fit most lambdas and functions. static constexpr size_t inline_capacity = 4 * sizeof(void*); +#else + // FIXME: Try to decrease this. + static constexpr size_t inline_capacity = 6 * sizeof(void*); +#endif alignas(max(alignof(CallableWrapperBase), alignof(CallableWrapperBase*))) u8 m_storage[inline_capacity]; };