소스 검색

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.
Tom 5 년 전
부모
커밋
3cc0e86cd8
2개의 변경된 파일6개의 추가작업 그리고 1개의 파일을 삭제
  1. 1 1
      Kernel/Heap/kmalloc.cpp
  2. 5 0
      Kernel/SpinLock.h

+ 1 - 1
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()
 {

+ 5 - 0
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 <typename BaseType = u32, typename LockType = SpinLock<BaseType>>