kern: add new checks to SetThreadPriority/CoreMask

This commit is contained in:
Michael Scire 2021-04-07 01:11:17 -07:00 committed by SciresM
commit 1b2cf173b3
2 changed files with 20 additions and 12 deletions

View file

@ -132,14 +132,17 @@ namespace ams::kern::svc {
/* Get the current process. */
KProcess &process = GetCurrentProcess();
/* Validate the priority. */
R_UNLESS(ams::svc::HighestThreadPriority <= priority && priority <= ams::svc::LowestThreadPriority, svc::ResultInvalidPriority());
R_UNLESS(process.CheckThreadPriority(priority), svc::ResultInvalidPriority());
/* Get the thread from its handle. */
KScopedAutoObject thread = process.GetHandleTable().GetObject<KThread>(thread_handle);
R_UNLESS(thread.IsNotNull(), svc::ResultInvalidHandle());
/* Validate the thread is owned by the current process. */
R_UNLESS(thread->GetOwnerProcess() == GetCurrentProcessPointer(), svc::ResultInvalidHandle());
/* Validate the priority. */
R_UNLESS(ams::svc::HighestThreadPriority <= priority && priority <= ams::svc::LowestThreadPriority, svc::ResultInvalidPriority());
R_UNLESS(process.CheckThreadPriority(priority), svc::ResultInvalidPriority());
/* Set the thread priority. */
thread->SetBasePriority(priority);
return ResultSuccess();
@ -157,6 +160,13 @@ namespace ams::kern::svc {
}
Result SetThreadCoreMask(ams::svc::Handle thread_handle, int32_t core_id, uint64_t affinity_mask) {
/* Get the thread from its handle. */
KScopedAutoObject thread = GetCurrentProcess().GetHandleTable().GetObject<KThread>(thread_handle);
R_UNLESS(thread.IsNotNull(), svc::ResultInvalidHandle());
/* Validate the thread is owned by the current process. */
R_UNLESS(thread->GetOwnerProcess() == GetCurrentProcessPointer(), svc::ResultInvalidHandle());
/* Determine the core id/affinity mask. */
if (core_id == ams::svc::IdealCoreUseProcessValue) {
core_id = GetCurrentProcess().GetIdealCoreId();
@ -175,10 +185,6 @@ namespace ams::kern::svc {
}
}
/* Get the thread from its handle. */
KScopedAutoObject thread = GetCurrentProcess().GetHandleTable().GetObject<KThread>(thread_handle);
R_UNLESS(thread.IsNotNull(), svc::ResultInvalidHandle());
/* Set the core mask. */
R_TRY(thread->SetCoreMask(core_id, affinity_mask));