Skip to content

Commit

Permalink
Kernel: Change kmalloc lock to be recursive
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tomuta authored and awesomekling committed Jul 3, 2020
1 parent 038dd9f commit 3cc0e86
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Kernel/Heap/kmalloc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
5 changes: 5 additions & 0 deletions Kernel/SpinLock.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ class RecursiveSpinLock
{
return m_lock.load(AK::memory_order_consume) != 0;
}

ALWAYS_INLINE void initialize()
{
m_lock.store(0, AK::memory_order_release);
}
};

template <typename BaseType = u32, typename LockType = SpinLock<BaseType>>
Expand Down

0 comments on commit 3cc0e86

Please sign in to comment.