瀏覽代碼

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.
Lioncash 7 年之前
父節點
當前提交
77328b0f19
共有 1 個文件被更改,包括 6 次插入5 次删除
  1. 6 5
      src/core/hle/kernel/svc.cpp

+ 6 - 5
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> thread = current_process->GetHandleTable().Get<Thread>(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> thread = current_process->GetHandleTable().Get<Thread>(handle);
+    if (!thread) {
+        return ERR_INVALID_HANDLE;
     }
 
     thread->SetPriority(priority);