summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/core/hle/kernel/resource_limit.cpp2
-rw-r--r--src/core/hle/kernel/thread.cpp30
-rw-r--r--src/core/hle/service/y2r_u.cpp4
-rw-r--r--src/core/hle/svc.cpp26
4 files changed, 30 insertions, 32 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..3b7555d87 100644
--- a/src/core/hle/kernel/thread.cpp
+++ b/src/core/hle/kernel/thread.cpp
@@ -353,14 +353,8 @@ static void ResetThreadContext(ARM_Interface::ThreadContext& context, u32 stack_
353 353
354ResultVal<SharedPtr<Thread>> Thread::Create(std::string name, VAddr entry_point, s32 priority, 354ResultVal<SharedPtr<Thread>> Thread::Create(std::string name, VAddr entry_point, s32 priority,
355 u32 arg, s32 processor_id, VAddr stack_top) { 355 u32 arg, s32 processor_id, VAddr stack_top) {
356 if (priority < THREADPRIO_HIGHEST || priority > THREADPRIO_LOWEST) { 356 ASSERT_MSG(priority >= THREADPRIO_HIGHEST && priority <= THREADPRIO_LOWEST,
357 s32 new_priority = MathUtil::Clamp<s32>(priority, THREADPRIO_HIGHEST, THREADPRIO_LOWEST); 357 "Invalid thread priority");
358 LOG_WARNING(Kernel_SVC, "(name=%s): invalid priority=%d, clamping to %d", name.c_str(),
359 priority, new_priority);
360 // TODO(bunnei): Clamping to a valid priority is not necessarily correct behavior... Confirm
361 // validity of this
362 priority = new_priority;
363 }
364 358
365 if (!Memory::IsValidVirtualAddress(entry_point)) { 359 if (!Memory::IsValidVirtualAddress(entry_point)) {
366 LOG_ERROR(Kernel_SVC, "(name=%s): invalid entry %08x", name.c_str(), entry_point); 360 LOG_ERROR(Kernel_SVC, "(name=%s): invalid entry %08x", name.c_str(), entry_point);
@@ -444,25 +438,9 @@ ResultVal<SharedPtr<Thread>> Thread::Create(std::string name, VAddr entry_point,
444 return MakeResult<SharedPtr<Thread>>(std::move(thread)); 438 return MakeResult<SharedPtr<Thread>>(std::move(thread));
445} 439}
446 440
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) { 441void Thread::SetPriority(s32 priority) {
464 ClampPriority(this, &priority); 442 ASSERT_MSG(priority <= THREADPRIO_LOWEST && priority >= THREADPRIO_HIGHEST,
465 443 "Invalid priority value.");
466 // If thread was ready, adjust queues 444 // If thread was ready, adjust queues
467 if (status == THREADSTATUS_READY) 445 if (status == THREADSTATUS_READY)
468 ready_queue.move(this, current_priority, priority); 446 ready_queue.move(this, current_priority, priority);
diff --git a/src/core/hle/service/y2r_u.cpp b/src/core/hle/service/y2r_u.cpp
index a20194107..31bb466fc 100644
--- a/src/core/hle/service/y2r_u.cpp
+++ b/src/core/hle/service/y2r_u.cpp
@@ -531,7 +531,9 @@ static void GetStandardCoefficient(Interface* self) {
531 LOG_DEBUG(Service_Y2R, "called standard_coefficient=%u ", index); 531 LOG_DEBUG(Service_Y2R, "called standard_coefficient=%u ", index);
532 } else { 532 } else {
533 cmd_buff[0] = IPC::MakeHeader(0x21, 1, 0); 533 cmd_buff[0] = IPC::MakeHeader(0x21, 1, 0);
534 cmd_buff[1] = -1; // TODO(bunnei): Identify the correct error code for this 534 cmd_buff[1] = ResultCode(ErrorDescription::InvalidEnumValue, ErrorModule::CAM,
535 ErrorSummary::InvalidArgument, ErrorLevel::Usage)
536 .raw;
535 537
536 LOG_ERROR(Service_Y2R, "called standard_coefficient=%u The argument is invalid!", index); 538 LOG_ERROR(Service_Y2R, "called standard_coefficient=%u The argument is invalid!", index);
537 } 539 }
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