AK+Kernel: Don't allow allocations in AK::Function in kernel mode
Refs #6369. Fixes #15053. Co-authored-by: Brian Gianforcaro <bgianf@serenityos.org>
This commit is contained in:
parent
2a840a538c
commit
e44ccddba3
Notes:
sideshowbarker
2024-07-18 04:46:35 +09:00
Author: https://github.com/gunnarbeutner Commit: https://github.com/SerenityOS/serenity/commit/e44ccddba3 Pull-request: https://github.com/SerenityOS/serenity/pull/15869 Reviewed-by: https://github.com/linusg
1 changed files with 10 additions and 0 deletions
|
@ -213,13 +213,18 @@ private:
|
|||
{
|
||||
VERIFY(m_call_nesting_level == 0);
|
||||
using WrapperType = CallableWrapper<Callable>;
|
||||
#ifndef KERNEL
|
||||
if constexpr (sizeof(WrapperType) > inline_capacity) {
|
||||
*bit_cast<CallableWrapperBase**>(&m_storage) = new WrapperType(forward<Callable>(callable));
|
||||
m_kind = FunctionKind::Outline;
|
||||
} else {
|
||||
#endif
|
||||
static_assert(sizeof(WrapperType) <= inline_capacity);
|
||||
new (m_storage) WrapperType(forward<Callable>(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<u16> 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];
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue