summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Subv2017-01-11 12:08:10 -0500
committerGravatar Subv2017-01-11 16:38:04 -0500
commitf2f2572fed075d2dca5ae7abcea451ac5eb382ec (patch)
tree1a7f133a595f7362a79e3f06d1e0bcb8a4668706
parentY2R: Use the proper error code when GetStandardCoefficient receives an invali... (diff)
downloadyuzu-f2f2572fed075d2dca5ae7abcea451ac5eb382ec.tar.gz
yuzu-f2f2572fed075d2dca5ae7abcea451ac5eb382ec.tar.xz
yuzu-f2f2572fed075d2dca5ae7abcea451ac5eb382ec.zip
Thread: Added priority range checking to svcSetThreadPriority and removed priority clamping code from Thread::SetPriority.
-rw-r--r--src/core/hle/kernel/resource_limit.cpp2
-rw-r--r--src/core/hle/kernel/thread.cpp20
-rw-r--r--src/core/hle/svc.cpp14
3 files changed, 18 insertions, 18 deletions
diff --git a/src/core/hle/kernel/resource_limit.cpp b/src/core/hle/kernel/resource_limit.cpp
index 253ab7045..3f51bc5de 100644
--- a/src/core/hle/kernel/resource_limit.cpp
+++ b/src/core/hle/kernel/resource_limit.cpp
@@ -62,6 +62,8 @@ s32 ResourceLimit::GetCurrentResourceValue(u32 resource) const {
62 62
63s32 ResourceLimit::GetMaxResourceValue(u32 resource) const { 63s32 ResourceLimit::GetMaxResourceValue(u32 resource) const {
64 switch (resource) { 64 switch (resource) {
65 case PRIORITY:
66 return max_priority;
65 case COMMIT: 67 case COMMIT:
66 return max_commit; 68 return max_commit;
67 case THREAD: 69 case THREAD:
diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp
index 8c6fbcd04..5ba9abf29 100644
--- a/src/core/hle/kernel/thread.cpp
+++ b/src/core/hle/kernel/thread.cpp
@@ -444,25 +444,9 @@ ResultVal<SharedPtr<Thread>> Thread::Create(std::string name, VAddr entry_point,
444 return MakeResult<SharedPtr<Thread>>(std::move(thread)); 444 return MakeResult<SharedPtr<Thread>>(std::move(thread));
445} 445}
446 446
447// TODO(peachum): Remove this. Range checking should be done, and an appropriate error should be
448// returned.
449static void ClampPriority(const Thread* thread, s32* priority) {
450 if (*priority < THREADPRIO_HIGHEST || *priority > THREADPRIO_LOWEST) {
451 DEBUG_ASSERT_MSG(
452 false, "Application passed an out of range priority. An error should be returned.");
453
454 s32 new_priority = MathUtil::Clamp<s32>(*priority, THREADPRIO_HIGHEST, THREADPRIO_LOWEST);
455 LOG_WARNING(Kernel_SVC, "(name=%s): invalid priority=%d, clamping to %d",
456 thread->name.c_str(), *priority, new_priority);
457 // TODO(bunnei): Clamping to a valid priority is not necessarily correct behavior... Confirm
458 // validity of this
459 *priority = new_priority;
460 }
461}
462
463void Thread::SetPriority(s32 priority) { 447void Thread::SetPriority(s32 priority) {
464 ClampPriority(this, &priority); 448 ASSERT_MSG(priority <= THREADPRIO_LOWEST && priority >= THREADPRIO_HIGHEST,
465 449 "Invalid priority value.");
466 // If thread was ready, adjust queues 450 // If thread was ready, adjust queues
467 if (status == THREADSTATUS_READY) 451 if (status == THREADSTATUS_READY)
468 ready_queue.move(this, current_priority, priority); 452 ready_queue.move(this, current_priority, priority);
diff --git a/src/core/hle/svc.cpp b/src/core/hle/svc.cpp
index 2b242ff98..8cb6a1c94 100644
--- a/src/core/hle/svc.cpp
+++ b/src/core/hle/svc.cpp
@@ -598,10 +598,24 @@ static ResultCode GetThreadPriority(s32* priority, Kernel::Handle handle) {
598 598
599/// Sets the priority for the specified thread 599/// Sets the priority for the specified thread
600static ResultCode SetThreadPriority(Kernel::Handle handle, s32 priority) { 600static ResultCode SetThreadPriority(Kernel::Handle handle, s32 priority) {
601 if (priority > THREADPRIO_LOWEST) {
602 return ResultCode(ErrorDescription::OutOfRange, ErrorModule::OS,
603 ErrorSummary::InvalidArgument, ErrorLevel::Usage);
604 }
605
601 SharedPtr<Kernel::Thread> thread = Kernel::g_handle_table.Get<Kernel::Thread>(handle); 606 SharedPtr<Kernel::Thread> thread = Kernel::g_handle_table.Get<Kernel::Thread>(handle);
602 if (thread == nullptr) 607 if (thread == nullptr)
603 return ERR_INVALID_HANDLE; 608 return ERR_INVALID_HANDLE;
604 609
610 using Kernel::ResourceLimit;
611 // Note: The kernel uses the current process's resource limit instead of
612 // the one from the thread owner's resource limit.
613 Kernel::SharedPtr<ResourceLimit>& resource_limit = Kernel::g_current_process->resource_limit;
614 if (resource_limit->GetMaxResourceValue(Kernel::ResourceTypes::PRIORITY) > priority) {
615 return ResultCode(ErrorDescription::NotAuthorized, ErrorModule::OS,
616 ErrorSummary::WrongArgument, ErrorLevel::Permanent);
617 }
618
605 thread->SetPriority(priority); 619 thread->SetPriority(priority);
606 thread->UpdatePriority(); 620 thread->UpdatePriority();
607 621