summaryrefslogtreecommitdiff
path: root/src/core/hle/svc.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/hle/svc.cpp')
-rw-r--r--src/core/hle/svc.cpp26
1 files changed, 21 insertions, 5 deletions
diff --git a/src/core/hle/svc.cpp b/src/core/hle/svc.cpp
index 2b242ff98..96db39ad9 100644
--- a/src/core/hle/svc.cpp
+++ b/src/core/hle/svc.cpp
@@ -532,16 +532,18 @@ static ResultCode CreateThread(Kernel::Handle* out_handle, s32 priority, u32 ent
532 name = Common::StringFromFormat("unknown-%08x", entry_point); 532 name = Common::StringFromFormat("unknown-%08x", entry_point);
533 } 533 }
534 534
535 // TODO(bunnei): Implement resource limits to return an error code instead of the below assert.
536 // The error code should be: Description::NotAuthorized, Module::OS, Summary::WrongArgument,
537 // Level::Permanent
538 ASSERT_MSG(priority >= THREADPRIO_USERLAND_MAX, "Unexpected thread priority!");
539
540 if (priority > THREADPRIO_LOWEST) { 535 if (priority > THREADPRIO_LOWEST) {
541 return ResultCode(ErrorDescription::OutOfRange, ErrorModule::OS, 536 return ResultCode(ErrorDescription::OutOfRange, ErrorModule::OS,
542 ErrorSummary::InvalidArgument, ErrorLevel::Usage); 537 ErrorSummary::InvalidArgument, ErrorLevel::Usage);
543 } 538 }
544 539
540 using Kernel::ResourceLimit;
541 Kernel::SharedPtr<ResourceLimit>& resource_limit = Kernel::g_current_process->resource_limit;
542 if (resource_limit->GetMaxResourceValue(Kernel::ResourceTypes::PRIORITY) > priority) {
543 return ResultCode(ErrorDescription::NotAuthorized, ErrorModule::OS,
544 ErrorSummary::WrongArgument, ErrorLevel::Permanent);
545 }
546
545 switch (processor_id) { 547 switch (processor_id) {
546 case THREADPROCESSORID_ALL: 548 case THREADPROCESSORID_ALL:
547 case THREADPROCESSORID_DEFAULT: 549 case THREADPROCESSORID_DEFAULT:
@@ -598,10 +600,24 @@ static ResultCode GetThreadPriority(s32* priority, Kernel::Handle handle) {
598 600
599/// Sets the priority for the specified thread 601/// Sets the priority for the specified thread
600static ResultCode SetThreadPriority(Kernel::Handle handle, s32 priority) { 602static ResultCode SetThreadPriority(Kernel::Handle handle, s32 priority) {
603 if (priority > THREADPRIO_LOWEST) {
604 return ResultCode(ErrorDescription::OutOfRange, ErrorModule::OS,
605 ErrorSummary::InvalidArgument, ErrorLevel::Usage);
606 }
607
601 SharedPtr<Kernel::Thread> thread = Kernel::g_handle_table.Get<Kernel::Thread>(handle); 608 SharedPtr<Kernel::Thread> thread = Kernel::g_handle_table.Get<Kernel::Thread>(handle);
602 if (thread == nullptr) 609 if (thread == nullptr)
603 return ERR_INVALID_HANDLE; 610 return ERR_INVALID_HANDLE;
604 611
612 using Kernel::ResourceLimit;
613 // Note: The kernel uses the current process's resource limit instead of
614 // the one from the thread owner's resource limit.
615 Kernel::SharedPtr<ResourceLimit>& resource_limit = Kernel::g_current_process->resource_limit;
616 if (resource_limit->GetMaxResourceValue(Kernel::ResourceTypes::PRIORITY) > priority) {
617 return ResultCode(ErrorDescription::NotAuthorized, ErrorModule::OS,
618 ErrorSummary::WrongArgument, ErrorLevel::Permanent);
619 }
620
605 thread->SetPriority(priority); 621 thread->SetPriority(priority);
606 thread->UpdatePriority(); 622 thread->UpdatePriority();
607 623