From 5163c5cc63c58c6c5244882a2031420d9ba20092 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 27 Jan 2020 20:47:10 +0100 Subject: [PATCH] Kernel: Expose the signal that stopped a thread via sys$waitpid() --- Kernel/Process.cpp | 8 ++++++-- Kernel/Thread.cpp | 2 ++ Kernel/Thread.h | 3 +++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index 47bb4d6a6d..9f62758ff4 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -2318,12 +2318,16 @@ pid_t Process::sys$waitpid(pid_t waitee, int* wstatus, int options) if (!waitee_process) return -ECHILD; + auto* waitee_thread = Thread::from_tid(waitee_pid); + if (!waitee_thread) + return -ECHILD; + ASSERT(waitee_process); if (waitee_process->is_dead()) { exit_status = reap(*waitee_process); } else { - ASSERT(waitee_process->any_thread().state() == Thread::State::Stopped); - exit_status = 0x7f; + ASSERT(waitee_thread->state() == Thread::State::Stopped); + exit_status = (waitee_thread->m_stop_signal << 8) | 0x7f; } if (wstatus) diff --git a/Kernel/Thread.cpp b/Kernel/Thread.cpp index 7bba273378..20bb8878a4 100644 --- a/Kernel/Thread.cpp +++ b/Kernel/Thread.cpp @@ -471,6 +471,7 @@ ShouldUnblockThread Thread::dispatch_signal(u8 signal) m_pending_signals &= ~(1 << (signal - 1)); if (signal == SIGSTOP) { + m_stop_signal = SIGSTOP; set_state(Stopped); return ShouldUnblockThread::No; } @@ -482,6 +483,7 @@ ShouldUnblockThread Thread::dispatch_signal(u8 signal) if (handler_vaddr.is_null()) { switch (default_signal_action(signal)) { case DefaultSignalAction::Stop: + m_stop_signal = signal; set_state(Stopped); return ShouldUnblockThread::No; case DefaultSignalAction::DumpCore: diff --git a/Kernel/Thread.h b/Kernel/Thread.h index 76c6f994bd..1082a8606a 100644 --- a/Kernel/Thread.h +++ b/Kernel/Thread.h @@ -485,6 +485,9 @@ private: u32 m_priority { THREAD_PRIORITY_NORMAL }; u32 m_extra_priority { 0 }; u32 m_priority_boost { 0 }; + + u8 m_stop_signal { 0 }; + bool m_dump_backtrace_on_finalization { false }; bool m_should_die { false };