From 057ae36e32da6d0d6b4ba5afdf90a31dd6e950fc Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Fri, 15 Jan 2021 20:29:13 +0100 Subject: 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. --- Kernel/Process.cpp | 7 +++++++ Kernel/Process.h | 2 ++ 2 files changed, 9 insertions(+) (limited to 'Kernel') diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index 3f93912f1a..edc448fb02 100644 --- a/Kernel/Process.cpp +++ b/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(); } diff --git a/Kernel/Process.h b/Kernel/Process.h index d504224ddd..fbc669bd2d 100644 --- a/Kernel/Process.h +++ b/Kernel/Process.h @@ -663,6 +663,8 @@ private: Thread::WaitBlockCondition m_wait_block_condition; HashMap m_coredump_metadata; + + Vector> m_threads_for_coredump; }; extern InlineLinkedList* g_processes; -- cgit v1.2.3