From 4568a628f904cf58f55b17bfefdadaf173a8bef3 Mon Sep 17 00:00:00 2001 From: Itamar Date: Mon, 6 Apr 2020 15:38:33 +0300 Subject: [PATCH] Thread: Set m_blocker to null in Thread::unblock() Before this commit, m_blocker was only set to null in Thread::block, after the thread has been unblocked. Starting with this commit, m_blocker is also set to null in Thread::unblock. This change will allow us to implement a missing feature of the PT_TRACE command of the ptrace syscall - stopping the traced thread when it exits the execve syscall. That feature will be implemented by sending a blocking SIGSTOP to the traced thread after it has executed the execve logic and before it starts executing the new program in userspace. However, since Process::exec arranges the tss to return to userspace (the so-called "yield-teleport"), the code in Thread::block that should be run after the thread unblocks, and sets m_blocker to null, never actually runs. Setting m_blocker to null in Thread::unblock allows us to avoid an incorrect state where the thread is in a Running state but conatins a pointer to a Blocker. --- Kernel/Thread.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Kernel/Thread.cpp b/Kernel/Thread.cpp index 53b6f49b63..d229e46f74 100644 --- a/Kernel/Thread.cpp +++ b/Kernel/Thread.cpp @@ -163,6 +163,7 @@ Thread::~Thread() void Thread::unblock() { + m_blocker = nullptr; if (current == this) { if (m_should_die) set_state(Thread::Dying);