From 77328b0f1978f044f05a60cd864a4dff0c4b7493 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 24 Oct 2018 14:07:53 -0400 Subject: kernel/svc: Move and correct returned error code for invalid thread priorities in SetThreadPriority() All priority checks are supposed to occur before checking the validity of the thread handle, we're also not supposed to return ERR_NOT_AUTHORIZED here. --- src/core/hle/kernel/svc.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src/core/hle/kernel/svc.cpp') diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp index 9a783d524..e7e4c59b6 100644 --- a/src/core/hle/kernel/svc.cpp +++ b/src/core/hle/kernel/svc.cpp @@ -594,16 +594,17 @@ static ResultCode SetThreadPriority(Handle handle, u32 priority) { } const auto* const current_process = Core::CurrentProcess(); - SharedPtr thread = current_process->GetHandleTable().Get(handle); - if (!thread) { - return ERR_INVALID_HANDLE; - } // Note: The kernel uses the current process's resource limit instead of // the one from the thread owner's resource limit. const ResourceLimit& resource_limit = current_process->GetResourceLimit(); if (resource_limit.GetMaxResourceValue(ResourceType::Priority) > priority) { - return ERR_NOT_AUTHORIZED; + return ERR_INVALID_THREAD_PRIORITY; + } + + SharedPtr thread = current_process->GetHandleTable().Get(handle); + if (!thread) { + return ERR_INVALID_HANDLE; } thread->SetPriority(priority); -- cgit v1.2.3 From fcf8f53a631fe5f15f2b456bc34331de8e67a64b Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 24 Oct 2018 14:10:30 -0400 Subject: kernel/svc: Amend returned error code for invalid priorities in CreateThread Like with the previous change, the kernel doesn't return NOT_AUTHORIZED here. It returns INVALID_THREAD_PRIORITY. --- src/core/hle/kernel/svc.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/core/hle/kernel/svc.cpp') diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp index e7e4c59b6..a5302d924 100644 --- a/src/core/hle/kernel/svc.cpp +++ b/src/core/hle/kernel/svc.cpp @@ -746,7 +746,7 @@ static ResultCode CreateThread(Handle* out_handle, VAddr entry_point, u64 arg, V auto* const current_process = Core::CurrentProcess(); const ResourceLimit& resource_limit = current_process->GetResourceLimit(); if (resource_limit.GetMaxResourceValue(ResourceType::Priority) > priority) { - return ERR_NOT_AUTHORIZED; + return ERR_INVALID_THREAD_PRIORITY; } if (processor_id == THREADPROCESSORID_DEFAULT) { -- cgit v1.2.3