From 5ff355c0cdf48796bc16335e1af7f34c41dcf576 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 28 Jan 2021 08:41:18 +0100 Subject: [PATCH] Kernel: Generate coredump backtraces from "threads for coredump" list This broke with the change that gave each process a list of its own threads. Since threads are removed slightly earlier from that list during process teardown, we're not able to use it for generating coredump backtraces. Fortunately we have the "threads for coredump" list for just this purpose. :^) --- Kernel/CoreDump.cpp | 6 ++---- Kernel/Process.cpp | 2 +- Kernel/Process.h | 7 ++++++- Kernel/Thread.h | 1 + 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Kernel/CoreDump.cpp b/Kernel/CoreDump.cpp index b03f27da82..2f3007e863 100644 --- a/Kernel/CoreDump.cpp +++ b/Kernel/CoreDump.cpp @@ -240,7 +240,7 @@ ByteBuffer CoreDump::create_notes_threads_data() const { ByteBuffer threads_data; - m_process->for_each_thread([&](Thread& thread) { + for (auto& thread : m_process->threads_for_coredump({})) { ByteBuffer entry_buff; ELF::Core::ThreadInfo info {}; @@ -251,9 +251,7 @@ ByteBuffer CoreDump::create_notes_threads_data() const entry_buff.append((void*)&info, sizeof(info)); threads_data += entry_buff; - - return IterationDecision::Continue; - }); + } return threads_data; } diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index 09c494f25b..8e49cc4187 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -677,7 +677,7 @@ void Process::die() m_tty = nullptr; for_each_thread([&](auto& thread) { - m_threads_for_coredump.append(&thread); + m_threads_for_coredump.append(thread); return IterationDecision::Continue; }); diff --git a/Kernel/Process.h b/Kernel/Process.h index ae43f88aea..612bd6317d 100644 --- a/Kernel/Process.h +++ b/Kernel/Process.h @@ -206,6 +206,9 @@ public: template IterationDecision for_each_thread(Callback) const; + template + IterationDecision for_each_thread_in_coredump(Callback) const; + void die(); void finalize(); @@ -500,6 +503,8 @@ public: HashMap& coredump_metadata() { return m_coredump_metadata; } const HashMap& coredump_metadata() const { return m_coredump_metadata; } + const NonnullRefPtrVector& threads_for_coredump(Badge) const { return m_threads_for_coredump; } + PerformanceEventBuffer* perf_events() { return m_perf_event_buffer; } private: @@ -662,7 +667,7 @@ private: HashMap m_coredump_metadata; - Vector> m_threads_for_coredump; + NonnullRefPtrVector m_threads_for_coredump; }; extern InlineLinkedList* g_processes; diff --git a/Kernel/Thread.h b/Kernel/Thread.h index 1cd6e182ba..f3f1bf9561 100644 --- a/Kernel/Thread.h +++ b/Kernel/Thread.h @@ -785,6 +785,7 @@ public: u32 stack_ptr() const { return m_tss.esp; } RegisterState& get_register_dump_from_stack(); + const RegisterState& get_register_dump_from_stack() const { return const_cast(this)->get_register_dump_from_stack(); } TSS32& tss() { return m_tss; } const TSS32& tss() const { return m_tss; }