1
0
Fork 0
mirror of https://github.com/Atmosphere-NX/Atmosphere.git synced 2024-11-18 01:46:47 +00:00

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
parent 2fb258ca7e
commit 1b2cf173b3
2 changed files with 20 additions and 12 deletions

View file

@ -599,14 +599,16 @@ namespace ams::kern {
KScopedSchedulerLock sl; KScopedSchedulerLock sl;
MESOSPHERE_ASSERT(m_num_core_migration_disables >= 0); MESOSPHERE_ASSERT(m_num_core_migration_disables >= 0);
/* If the core id is no-update magic, preserve the ideal core id. */ /* If we're updating, set our ideal virtual core. */
if (core_id == ams::svc::IdealCoreNoUpdate) { if (core_id != ams::svc::IdealCoreNoUpdate) {
m_virtual_ideal_core_id = core_id;
} else {
/* Preserve our ideal core id. */
core_id = m_virtual_ideal_core_id; core_id = m_virtual_ideal_core_id;
R_UNLESS(((1ul << core_id) & v_affinity_mask) != 0, svc::ResultInvalidCombination()); R_UNLESS(((1ul << core_id) & v_affinity_mask) != 0, svc::ResultInvalidCombination());
} }
/* Set the virtual core/affinity mask. */ /* Set our affinity mask. */
m_virtual_ideal_core_id = core_id;
m_virtual_affinity_mask = v_affinity_mask; m_virtual_affinity_mask = v_affinity_mask;
/* Translate the virtual core to a physical core. */ /* Translate the virtual core to a physical core. */

View file

@ -132,14 +132,17 @@ namespace ams::kern::svc {
/* Get the current process. */ /* Get the current process. */
KProcess &process = GetCurrentProcess(); 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. */ /* Get the thread from its handle. */
KScopedAutoObject thread = process.GetHandleTable().GetObject<KThread>(thread_handle); KScopedAutoObject thread = process.GetHandleTable().GetObject<KThread>(thread_handle);
R_UNLESS(thread.IsNotNull(), svc::ResultInvalidHandle()); 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. */ /* Set the thread priority. */
thread->SetBasePriority(priority); thread->SetBasePriority(priority);
return ResultSuccess(); 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) { 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. */ /* Determine the core id/affinity mask. */
if (core_id == ams::svc::IdealCoreUseProcessValue) { if (core_id == ams::svc::IdealCoreUseProcessValue) {
core_id = GetCurrentProcess().GetIdealCoreId(); 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. */ /* Set the core mask. */
R_TRY(thread->SetCoreMask(core_id, affinity_mask)); R_TRY(thread->SetCoreMask(core_id, affinity_mask));