summaryrefslogtreecommitdiff
path: root/src/core/hle/svc.cpp
diff options
context:
space:
mode:
authorbunnei <bunneidev@gmail.com>2017-01-12 10:14:30 -0500
committerGitHub <noreply@github.com>2017-01-12 10:14:30 -0500
commit7ddfd3054dc67fa727ec7c7267f27a438ac37dc3 (patch)
tree30bd821242a3f3dad780595673c3d5adf92ebe86 /src/core/hle/svc.cpp
parent597a7c615c9ca3ed8e2fdb49b75111badf537af5 (diff)
parent1ddff1451140ef58058237a3198d363b96dc238e (diff)
Merge pull request #2425 from Subv/cleanup_todos
Implement some TODOs in the code.
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
name = Common::StringFromFormat("unknown-%08x", entry_point);
}
- // TODO(bunnei): Implement resource limits to return an error code instead of the below assert.
- // The error code should be: Description::NotAuthorized, Module::OS, Summary::WrongArgument,
- // Level::Permanent
- ASSERT_MSG(priority >= THREADPRIO_USERLAND_MAX, "Unexpected thread priority!");
-
if (priority > THREADPRIO_LOWEST) {
return ResultCode(ErrorDescription::OutOfRange, ErrorModule::OS,
ErrorSummary::InvalidArgument, ErrorLevel::Usage);
}
+ using Kernel::ResourceLimit;
+ Kernel::SharedPtr<ResourceLimit>& resource_limit = Kernel::g_current_process->resource_limit;
+ if (resource_limit->GetMaxResourceValue(Kernel::ResourceTypes::PRIORITY) > priority) {
+ return ResultCode(ErrorDescription::NotAuthorized, ErrorModule::OS,
+ ErrorSummary::WrongArgument, ErrorLevel::Permanent);
+ }
+
switch (processor_id) {
case THREADPROCESSORID_ALL:
case THREADPROCESSORID_DEFAULT:
@@ -598,10 +600,24 @@ static ResultCode GetThreadPriority(s32* priority, Kernel::Handle handle) {
/// Sets the priority for the specified thread
static ResultCode SetThreadPriority(Kernel::Handle handle, s32 priority) {
+ if (priority > THREADPRIO_LOWEST) {
+ return ResultCode(ErrorDescription::OutOfRange, ErrorModule::OS,
+ ErrorSummary::InvalidArgument, ErrorLevel::Usage);
+ }
+
SharedPtr<Kernel::Thread> thread = Kernel::g_handle_table.Get<Kernel::Thread>(handle);
if (thread == nullptr)
return ERR_INVALID_HANDLE;
+ using Kernel::ResourceLimit;
+ // Note: The kernel uses the current process's resource limit instead of
+ // the one from the thread owner's resource limit.
+ Kernel::SharedPtr<ResourceLimit>& resource_limit = Kernel::g_current_process->resource_limit;
+ if (resource_limit->GetMaxResourceValue(Kernel::ResourceTypes::PRIORITY) > priority) {
+ return ResultCode(ErrorDescription::NotAuthorized, ErrorModule::OS,
+ ErrorSummary::WrongArgument, ErrorLevel::Permanent);
+ }
+
thread->SetPriority(priority);
thread->UpdatePriority();