From 75e6999668b6aaf20e971c26cd07e4213240eb27 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Fri, 17 Jul 2020 22:25:01 -0700 Subject: [PATCH] kern: implement SvcSetThreadPriority --- .../source/svc/kern_svc_thread.cpp | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/libraries/libmesosphere/source/svc/kern_svc_thread.cpp b/libraries/libmesosphere/source/svc/kern_svc_thread.cpp index b74200471..81fdc89fd 100644 --- a/libraries/libmesosphere/source/svc/kern_svc_thread.cpp +++ b/libraries/libmesosphere/source/svc/kern_svc_thread.cpp @@ -127,6 +127,23 @@ namespace ams::kern::svc { return ResultSuccess(); } + Result SetThreadPriority(ams::svc::Handle thread_handle, int32_t priority) { + /* Get the current process. */ + KProcess &process = GetCurrentProcess(); + + /* Validate the priority. */ + R_UNLESS(ams::svc::HighestThreadPriority <= priority && priority <= ams::svc::LowestThreadPriority, svc::ResultInvalidPriority()); + R_UNLESS(process.CheckThreadPriority(priority), svc::ResultInvalidPriority()); + + /* Get the thread from its handle. */ + KScopedAutoObject thread = process.GetHandleTable().GetObject(thread_handle); + R_UNLESS(thread.IsNotNull(), svc::ResultInvalidHandle()); + + /* Set the thread priority. */ + thread->SetPriority(priority); + return ResultSuccess(); + } + Result GetThreadId(uint64_t *out_thread_id, ams::svc::Handle thread_handle) { /* Get the thread from its handle. */ KScopedAutoObject thread = GetCurrentProcess().GetHandleTable().GetObject(thread_handle); @@ -162,7 +179,7 @@ namespace ams::kern::svc { } Result SetThreadPriority64(ams::svc::Handle thread_handle, int32_t priority) { - MESOSPHERE_PANIC("Stubbed SvcSetThreadPriority64 was called."); + return SetThreadPriority(thread_handle, priority); } Result GetThreadCoreMask64(int32_t *out_core_id, uint64_t *out_affinity_mask, ams::svc::Handle thread_handle) { @@ -216,7 +233,7 @@ namespace ams::kern::svc { } Result SetThreadPriority64From32(ams::svc::Handle thread_handle, int32_t priority) { - MESOSPHERE_PANIC("Stubbed SvcSetThreadPriority64From32 was called."); + return SetThreadPriority(thread_handle, priority); } Result GetThreadCoreMask64From32(int32_t *out_core_id, uint64_t *out_affinity_mask, ams::svc::Handle thread_handle) {