From 5b8a20dbf7aa043088c2302e38f149e7d07fa8ed Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Mon, 20 Jul 2020 02:11:49 -0700 Subject: [PATCH] kern: fix bug in SvcSetThreadPriority --- .../include/mesosphere/kern_k_thread.hpp | 3 +++ libraries/libmesosphere/source/kern_k_thread.cpp | 13 +++++++++++++ .../libmesosphere/source/svc/kern_svc_thread.cpp | 2 +- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/libraries/libmesosphere/include/mesosphere/kern_k_thread.hpp b/libraries/libmesosphere/include/mesosphere/kern_k_thread.hpp index 90bbacb09..7db14b565 100644 --- a/libraries/libmesosphere/include/mesosphere/kern_k_thread.hpp +++ b/libraries/libmesosphere/include/mesosphere/kern_k_thread.hpp @@ -347,8 +347,10 @@ namespace ams::kern { constexpr s32 GetIdealCore() const { return this->ideal_core_id; } constexpr s32 GetActiveCore() const { return this->core_id; } constexpr void SetActiveCore(s32 core) { this->core_id = core; } + constexpr s32 GetPriority() const { return this->priority; } constexpr void SetPriority(s32 prio) { this->priority = prio; } + constexpr s32 GetBasePriority() const { return this->base_priority; } constexpr QueueEntry &GetPriorityQueueEntry(s32 core) { return this->per_core_priority_queue_entry[core]; } @@ -438,6 +440,7 @@ namespace ams::kern { void Wakeup(); + void SetBasePriority(s32 priority); Result SetPriorityToIdle(); Result Run(); diff --git a/libraries/libmesosphere/source/kern_k_thread.cpp b/libraries/libmesosphere/source/kern_k_thread.cpp index 3c0681683..16e52b95b 100644 --- a/libraries/libmesosphere/source/kern_k_thread.cpp +++ b/libraries/libmesosphere/source/kern_k_thread.cpp @@ -384,6 +384,19 @@ namespace ams::kern { } } + void KThread::SetBasePriority(s32 priority) { + MESOSPHERE_ASSERT_THIS(); + MESOSPHERE_ASSERT(ams::svc::HighestThreadPriority <= priority && priority <= ams::svc::LowestThreadPriority); + + KScopedSchedulerLock sl; + + /* Change our base priority. */ + this->base_priority = priority; + + /* Perform a priority restoration. */ + RestorePriority(this); + } + Result KThread::SetPriorityToIdle() { MESOSPHERE_ASSERT_THIS(); diff --git a/libraries/libmesosphere/source/svc/kern_svc_thread.cpp b/libraries/libmesosphere/source/svc/kern_svc_thread.cpp index d1314b6a6..4cf9b3305 100644 --- a/libraries/libmesosphere/source/svc/kern_svc_thread.cpp +++ b/libraries/libmesosphere/source/svc/kern_svc_thread.cpp @@ -141,7 +141,7 @@ namespace ams::kern::svc { R_UNLESS(thread.IsNotNull(), svc::ResultInvalidHandle()); /* Set the thread priority. */ - thread->SetPriority(priority); + thread->SetBasePriority(priority); return ResultSuccess(); }