From 744dfa3c4c7fe5ed85e665259bb7cc4486a476e7 Mon Sep 17 00:00:00 2001 From: Pawel Dziepak Date: Fri, 18 Apr 2014 22:14:50 +0200 Subject: [PATCH] kernel: make sure thread priority is within valid range The scheduler expects that all threads expect the initial idle threads have priority in range [THREAD_MIN_SET_PRIORITY, THREAD_MAX_SET_PRIORITY]. If the requested pririty is out of range the value is clamped. Failing with B_BAD_VALUE is probably an overkill since there isn't any real change in the guarantees provided by the scheduler about the behavior of such thread. Also, BeBook suggests that spawn_thread() can specify priority 0. --- src/system/kernel/thread.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/system/kernel/thread.cpp b/src/system/kernel/thread.cpp index 6f9d4da1c9..de4adb5ac3 100644 --- a/src/system/kernel/thread.cpp +++ b/src/system/kernel/thread.cpp @@ -891,6 +891,10 @@ thread_create_thread(const ThreadCreationAttributes& attributes, bool kernel) // available for deinitialization thread->priority = attributes.priority == -1 ? B_NORMAL_PRIORITY : attributes.priority; + thread->priority = std::max(thread->priority, + (int32)THREAD_MIN_SET_PRIORITY); + thread->priority = std::min(thread->priority, + (int32)THREAD_MAX_SET_PRIORITY); thread->state = B_THREAD_SUSPENDED; thread->sig_block_mask = attributes.signal_mask;