瀏覽代碼

Kernel: Prevent threads from being destructed between die() and finalize()

Killing remaining threads already happens in Process::die(), but
coredumps are only written in Process::finalize(). We need to keep a
reference to each of those threads to prevent them from being destructed
between those two functions, otherwise coredumps will only ever contain
information about the last remaining thread.

Fixes the underlying problem of #4778, though the UI will need
refinements to not show every thread's backtrace mashed together.
Linus Groh 4 年之前
父節點
當前提交
057ae36e32
共有 2 個文件被更改,包括 9 次插入0 次删除
  1. 7 0
      Kernel/Process.cpp
  2. 2 0
      Kernel/Process.h

+ 7 - 0
Kernel/Process.cpp

@@ -631,6 +631,8 @@ void Process::finalize()
             dump_perfcore();
     }
 
+    m_threads_for_coredump.clear();
+
     if (m_alarm_timer)
         TimerQueue::the().cancel_timer(m_alarm_timer.release_nonnull());
     m_fds.clear();
@@ -695,6 +697,11 @@ void Process::die()
     // slave owner, we have to allow the PTY pair to be torn down.
     m_tty = nullptr;
 
+    for_each_thread([&](auto& thread) {
+        m_threads_for_coredump.append(&thread);
+        return IterationDecision::Continue;
+    });
+
     kill_all_threads();
 }
 

+ 2 - 0
Kernel/Process.h

@@ -663,6 +663,8 @@ private:
     Thread::WaitBlockCondition m_wait_block_condition;
 
     HashMap<String, String> m_coredump_metadata;
+
+    Vector<RefPtr<Thread>> m_threads_for_coredump;
 };
 
 extern InlineLinkedList<Process>* g_processes;