From 58ed2965d0362707ca043b365ac1f2e89ee8c789 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Tue, 19 Feb 2019 21:35:39 -0500 Subject: [PATCH] kernel: Panic on attempts to block a pinned thread. Preventing "normal" context switches caused by a time interrupt is the primary reason for pinning threads. "thread_block" and friends, however, cause an explicit context switch and will not return until another thread unblocks us. Calling these while a thread is pinned is thus undefined behavior, and so we should just panic in the case anyone attempts to do so. --- src/system/kernel/thread.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/system/kernel/thread.cpp b/src/system/kernel/thread.cpp index 1315338f1c..b92bdec833 100644 --- a/src/system/kernel/thread.cpp +++ b/src/system/kernel/thread.cpp @@ -2847,6 +2847,11 @@ thread_block_timeout(timer* timer) static inline status_t thread_block_locked(Thread* thread) { + if (thread->pinned_to_cpu > 0) { + panic("attempting to block thread %" B_PRId32 ", which is pinned!", + thread->id); + } + if (thread->wait.status == 1) { // check for signals, if interruptible if (thread_is_interrupted(thread, thread->wait.flags)) {