From 3cc0e86cd826766123d0f67d0991c4928c5df3e9 Mon Sep 17 00:00:00 2001 From: Tom Date: Thu, 2 Jul 2020 08:34:11 -0600 Subject: [PATCH] Kernel: Change kmalloc lock to be recursive If the heap code dumps a stack trace (e.g. out of memory) then it may recursively call into it. Rather than deadlocking, allow recursion. --- Kernel/Heap/kmalloc.cpp | 2 +- Kernel/SpinLock.h | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Kernel/Heap/kmalloc.cpp b/Kernel/Heap/kmalloc.cpp index 083d5313a8..c47b671ac2 100644 --- a/Kernel/Heap/kmalloc.cpp +++ b/Kernel/Heap/kmalloc.cpp @@ -67,7 +67,7 @@ bool g_dump_kmalloc_stacks; static u8* s_next_eternal_ptr; static u8* s_end_of_eternal_range; -static SpinLock s_lock; +static RecursiveSpinLock s_lock; // needs to be recursive because of dump_backtrace() void kmalloc_init() { diff --git a/Kernel/SpinLock.h b/Kernel/SpinLock.h index 538895e658..e0855a0790 100644 --- a/Kernel/SpinLock.h +++ b/Kernel/SpinLock.h @@ -103,6 +103,11 @@ public: { return m_lock.load(AK::memory_order_consume) != 0; } + + ALWAYS_INLINE void initialize() + { + m_lock.store(0, AK::memory_order_release); + } }; template >