2019-06-29 10:20:36 +01:00
|
|
|
/*
|
2020-01-24 10:10:40 +00:00
|
|
|
* Copyright (c) 2018-2020 Atmosphère-NX
|
2019-06-29 10:20:36 +01:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms and conditions of the GNU General Public License,
|
|
|
|
* version 2, as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
* more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
#include "pm_resource_manager.hpp"
|
|
|
|
|
2019-10-24 10:30:10 +01:00
|
|
|
namespace ams::pm::resource {
|
2019-06-29 10:20:36 +01:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
constexpr LimitableResource LimitableResources[] = {
|
|
|
|
LimitableResource_Memory,
|
|
|
|
LimitableResource_Threads,
|
|
|
|
LimitableResource_Events,
|
|
|
|
LimitableResource_TransferMemories,
|
|
|
|
LimitableResource_Sessions,
|
|
|
|
};
|
2019-07-02 22:36:57 +01:00
|
|
|
constexpr size_t LimitableResource_Count = util::size(LimitableResources);
|
2019-06-29 10:20:36 +01:00
|
|
|
|
|
|
|
/* Definitions for limit differences over time. */
|
|
|
|
constexpr size_t ExtraSystemThreadCount400 = 100;
|
2020-01-03 01:43:17 +00:00
|
|
|
constexpr size_t ExtraSystemMemorySize400 = 10_MB;
|
|
|
|
constexpr size_t ExtraSystemMemorySize500 = 12_MB;
|
2019-06-29 10:20:36 +01:00
|
|
|
constexpr size_t ExtraSystemEventCount600 = 100;
|
|
|
|
constexpr size_t ExtraSystemSessionCount600 = 100;
|
2020-01-03 01:43:17 +00:00
|
|
|
constexpr size_t ReservedMemorySize600 = 5_MB;
|
2019-06-29 10:20:36 +01:00
|
|
|
|
2019-12-10 01:56:38 +00:00
|
|
|
/* Atmosphere always allocates extra memory for system usage. */
|
2020-01-03 01:43:17 +00:00
|
|
|
constexpr size_t ExtraSystemMemorySizeAtmosphere = 24_MB;
|
|
|
|
constexpr size_t ExtraSystemMemorySizeAtmosphere500 = 33_MB; /* Applet pool is 0x20100000 */
|
2019-06-29 10:20:36 +01:00
|
|
|
|
|
|
|
/* Globals. */
|
2019-09-24 11:15:36 +01:00
|
|
|
os::Mutex g_resource_limit_lock;
|
2019-06-29 10:20:36 +01:00
|
|
|
Handle g_resource_limit_handles[ResourceLimitGroup_Count];
|
|
|
|
spl::MemoryArrangement g_memory_arrangement = spl::MemoryArrangement_Standard;
|
|
|
|
u64 g_system_memory_boost_size = 0;
|
2019-07-03 05:27:53 +01:00
|
|
|
u64 g_extra_application_threads_available = 0;
|
2019-06-29 10:20:36 +01:00
|
|
|
|
|
|
|
u64 g_resource_limits[ResourceLimitGroup_Count][LimitableResource_Count] = {
|
|
|
|
[ResourceLimitGroup_System] = {
|
|
|
|
[LimitableResource_Memory] = 0, /* Initialized by more complicated logic later. */
|
|
|
|
[LimitableResource_Threads] = 508,
|
|
|
|
[LimitableResource_Events] = 600,
|
|
|
|
[LimitableResource_TransferMemories] = 128,
|
|
|
|
[LimitableResource_Sessions] = 794,
|
|
|
|
},
|
|
|
|
[ResourceLimitGroup_Application] = {
|
|
|
|
[LimitableResource_Memory] = 0, /* Initialized by more complicated logic later. */
|
|
|
|
[LimitableResource_Threads] = 96,
|
|
|
|
[LimitableResource_Events] = 0,
|
|
|
|
[LimitableResource_TransferMemories] = 32,
|
|
|
|
[LimitableResource_Sessions] = 1,
|
|
|
|
},
|
|
|
|
[ResourceLimitGroup_Applet] = {
|
|
|
|
[LimitableResource_Memory] = 0, /* Initialized by more complicated logic later. */
|
|
|
|
[LimitableResource_Threads] = 96,
|
|
|
|
[LimitableResource_Events] = 0,
|
|
|
|
[LimitableResource_TransferMemories] = 32,
|
|
|
|
[LimitableResource_Sessions] = 5,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
u64 g_memory_resource_limits[spl::MemoryArrangement_Count][ResourceLimitGroup_Count] = {
|
|
|
|
[spl::MemoryArrangement_Standard] = {
|
2020-01-03 01:43:17 +00:00
|
|
|
[ResourceLimitGroup_System] = 269_MB,
|
|
|
|
[ResourceLimitGroup_Application] = 3285_MB,
|
|
|
|
[ResourceLimitGroup_Applet] = 535_MB,
|
2019-06-29 10:20:36 +01:00
|
|
|
},
|
|
|
|
[spl::MemoryArrangement_StandardForAppletDev] = {
|
2020-01-03 01:43:17 +00:00
|
|
|
[ResourceLimitGroup_System] = 481_MB,
|
|
|
|
[ResourceLimitGroup_Application] = 2048_MB,
|
|
|
|
[ResourceLimitGroup_Applet] = 1560_MB,
|
2019-06-29 10:20:36 +01:00
|
|
|
},
|
|
|
|
[spl::MemoryArrangement_StandardForSystemDev] = {
|
2020-01-03 01:43:17 +00:00
|
|
|
[ResourceLimitGroup_System] = 328_MB,
|
|
|
|
[ResourceLimitGroup_Application] = 3285_MB,
|
|
|
|
[ResourceLimitGroup_Applet] = 476_MB,
|
2019-06-29 10:20:36 +01:00
|
|
|
},
|
|
|
|
[spl::MemoryArrangement_Expanded] = {
|
2020-01-03 01:43:17 +00:00
|
|
|
[ResourceLimitGroup_System] = 653_MB,
|
|
|
|
[ResourceLimitGroup_Application] = 4916_MB,
|
|
|
|
[ResourceLimitGroup_Applet] = 568_MB,
|
2019-06-29 10:20:36 +01:00
|
|
|
},
|
|
|
|
[spl::MemoryArrangement_ExpandedForAppletDev] = {
|
2020-01-03 01:43:17 +00:00
|
|
|
[ResourceLimitGroup_System] = 653_MB,
|
|
|
|
[ResourceLimitGroup_Application] = 3285_MB,
|
|
|
|
[ResourceLimitGroup_Applet] = 2199_MB,
|
2019-06-29 10:20:36 +01:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Helpers. */
|
|
|
|
Result SetMemoryResourceLimitLimitValue(ResourceLimitGroup group, u64 new_memory_limit) {
|
|
|
|
const u64 old_memory_limit = g_resource_limits[group][LimitableResource_Memory];
|
|
|
|
g_resource_limits[group][LimitableResource_Memory] = new_memory_limit;
|
2019-10-24 09:40:44 +01:00
|
|
|
|
|
|
|
{
|
2019-06-29 10:20:36 +01:00
|
|
|
/* If we fail, restore the old memory limit. */
|
2019-10-24 09:40:44 +01:00
|
|
|
auto limit_guard = SCOPE_GUARD { g_resource_limits[group][LimitableResource_Memory] = old_memory_limit; };
|
|
|
|
R_TRY(svcSetResourceLimitLimitValue(GetResourceLimitHandle(group), LimitableResource_Memory, g_resource_limits[group][LimitableResource_Memory]));
|
|
|
|
limit_guard.Cancel();
|
|
|
|
}
|
|
|
|
|
|
|
|
return ResultSuccess();
|
2019-06-29 10:20:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Result SetResourceLimitLimitValues(ResourceLimitGroup group, u64 new_memory_limit) {
|
|
|
|
/* First, set memory limit. */
|
|
|
|
R_TRY(SetMemoryResourceLimitLimitValue(group, new_memory_limit));
|
|
|
|
|
|
|
|
/* Set other limit values. */
|
|
|
|
for (size_t i = 0; i < LimitableResource_Count; i++) {
|
|
|
|
const auto resource = LimitableResources[i];
|
|
|
|
if (resource == LimitableResource_Memory) {
|
|
|
|
continue;
|
|
|
|
}
|
2019-07-03 09:19:48 +01:00
|
|
|
R_TRY(svcSetResourceLimitLimitValue(GetResourceLimitHandle(group), resource, g_resource_limits[group][resource]));
|
2019-06-29 10:20:36 +01:00
|
|
|
}
|
2019-10-24 09:40:44 +01:00
|
|
|
return ResultSuccess();
|
2019-06-29 10:20:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
inline ResourceLimitGroup GetResourceLimitGroup(const ldr::ProgramInfo *info) {
|
|
|
|
switch (info->flags & ldr::ProgramInfoFlag_ApplicationTypeMask) {
|
|
|
|
case ldr::ProgramInfoFlag_Application:
|
|
|
|
return ResourceLimitGroup_Application;
|
|
|
|
case ldr::ProgramInfoFlag_Applet:
|
|
|
|
return ResourceLimitGroup_Applet;
|
|
|
|
default:
|
|
|
|
return ResourceLimitGroup_System;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void WaitResourceAvailable(ResourceLimitGroup group) {
|
|
|
|
const Handle reslimit_hnd = GetResourceLimitHandle(group);
|
|
|
|
for (size_t i = 0; i < LimitableResource_Count; i++) {
|
|
|
|
const auto resource = LimitableResources[i];
|
|
|
|
|
|
|
|
u64 value = 0;
|
|
|
|
while (true) {
|
|
|
|
R_ASSERT(svcGetResourceLimitCurrentValue(&value, reslimit_hnd, resource));
|
|
|
|
if (value == 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
svcSleepThread(1'000'000ul);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void WaitApplicationMemoryAvailable() {
|
|
|
|
u64 value = 0;
|
|
|
|
while (true) {
|
|
|
|
R_ASSERT(svcGetSystemInfo(&value, SystemInfoType_UsedPhysicalMemorySize, INVALID_HANDLE, PhysicalMemoryInfo_Application));
|
|
|
|
if (value == 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
svcSleepThread(1'000'000ul);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Resource API. */
|
|
|
|
Result InitializeResourceManager() {
|
|
|
|
/* Create resource limit handles. */
|
|
|
|
for (size_t i = 0; i < ResourceLimitGroup_Count; i++) {
|
|
|
|
if (i == ResourceLimitGroup_System) {
|
|
|
|
u64 value = 0;
|
|
|
|
R_ASSERT(svcGetInfo(&value, InfoType_ResourceLimit, INVALID_HANDLE, 0));
|
|
|
|
g_resource_limit_handles[i] = static_cast<Handle>(value);
|
|
|
|
} else {
|
|
|
|
R_ASSERT(svcCreateResourceLimit(&g_resource_limit_handles[i]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-15 06:49:06 +01:00
|
|
|
/* Adjust resource limits based on hos firmware version. */
|
|
|
|
const auto hos_version = hos::GetVersion();
|
|
|
|
if (hos_version >= hos::Version_400) {
|
2019-06-29 10:20:36 +01:00
|
|
|
/* 4.0.0 increased the system thread limit. */
|
|
|
|
g_resource_limits[ResourceLimitGroup_System][LimitableResource_Threads] += ExtraSystemThreadCount400;
|
|
|
|
/* 4.0.0 also took memory away from applet and gave it to system, for the Standard and StandardForSystemDev profiles. */
|
|
|
|
g_memory_resource_limits[spl::MemoryArrangement_Standard][ResourceLimitGroup_System] += ExtraSystemMemorySize400;
|
|
|
|
g_memory_resource_limits[spl::MemoryArrangement_Standard][ResourceLimitGroup_Applet] -= ExtraSystemMemorySize400;
|
|
|
|
g_memory_resource_limits[spl::MemoryArrangement_StandardForSystemDev][ResourceLimitGroup_System] += ExtraSystemMemorySize400;
|
|
|
|
g_memory_resource_limits[spl::MemoryArrangement_StandardForSystemDev][ResourceLimitGroup_Applet] -= ExtraSystemMemorySize400;
|
|
|
|
}
|
2019-10-15 06:49:06 +01:00
|
|
|
if (hos_version >= hos::Version_500) {
|
2019-06-29 10:20:36 +01:00
|
|
|
/* 5.0.0 took more memory away from applet and gave it to system, for the Standard and StandardForSystemDev profiles. */
|
|
|
|
g_memory_resource_limits[spl::MemoryArrangement_Standard][ResourceLimitGroup_System] += ExtraSystemMemorySize500;
|
|
|
|
g_memory_resource_limits[spl::MemoryArrangement_Standard][ResourceLimitGroup_Applet] -= ExtraSystemMemorySize500;
|
|
|
|
g_memory_resource_limits[spl::MemoryArrangement_StandardForSystemDev][ResourceLimitGroup_System] += ExtraSystemMemorySize500;
|
|
|
|
g_memory_resource_limits[spl::MemoryArrangement_StandardForSystemDev][ResourceLimitGroup_Applet] -= ExtraSystemMemorySize500;
|
|
|
|
}
|
2019-10-15 06:49:06 +01:00
|
|
|
if (hos_version >= hos::Version_600) {
|
2019-06-29 10:20:36 +01:00
|
|
|
/* 6.0.0 increased the system event and session limits. */
|
|
|
|
g_resource_limits[ResourceLimitGroup_System][LimitableResource_Events] += ExtraSystemEventCount600;
|
|
|
|
g_resource_limits[ResourceLimitGroup_System][LimitableResource_Sessions] += ExtraSystemSessionCount600;
|
|
|
|
}
|
|
|
|
|
2019-07-03 05:27:53 +01:00
|
|
|
/* 7.0.0+: Calculate the number of extra application threads available. */
|
2019-10-15 06:49:06 +01:00
|
|
|
if (hos::GetVersion() >= hos::Version_700) {
|
2019-07-03 05:27:53 +01:00
|
|
|
/* See how many threads we have available. */
|
|
|
|
u64 total_threads_available = 0;
|
|
|
|
R_ASSERT(svcGetResourceLimitLimitValue(&total_threads_available, GetResourceLimitHandle(ResourceLimitGroup_System), LimitableResource_Threads));
|
|
|
|
|
|
|
|
/* See how many threads we're expecting. */
|
|
|
|
const size_t total_threads_allocated = g_resource_limits[ResourceLimitGroup_System][LimitableResource_Threads] -
|
|
|
|
g_resource_limits[ResourceLimitGroup_Application][LimitableResource_Threads] -
|
|
|
|
g_resource_limits[ResourceLimitGroup_Applet][LimitableResource_Threads];
|
|
|
|
|
|
|
|
/* Ensure we don't over-commit threads. */
|
2019-10-24 10:30:10 +01:00
|
|
|
AMS_ASSERT(total_threads_allocated <= total_threads_available);
|
2019-07-03 05:27:53 +01:00
|
|
|
|
|
|
|
/* Set number of extra threads. */
|
2019-07-03 09:19:48 +01:00
|
|
|
g_extra_application_threads_available = total_threads_available - total_threads_allocated;
|
2019-07-03 05:27:53 +01:00
|
|
|
}
|
2019-06-29 10:20:36 +01:00
|
|
|
|
|
|
|
/* Choose and initialize memory arrangement. */
|
2019-10-15 06:49:06 +01:00
|
|
|
if (hos_version >= hos::Version_600) {
|
2019-06-29 10:20:36 +01:00
|
|
|
/* 6.0.0 retrieves memory limit information from the kernel, rather than using a hardcoded profile. */
|
|
|
|
g_memory_arrangement = spl::MemoryArrangement_Dynamic;
|
|
|
|
|
|
|
|
/* Get total memory available. */
|
|
|
|
u64 total_memory = 0;
|
|
|
|
R_ASSERT(svcGetResourceLimitLimitValue(&total_memory, GetResourceLimitHandle(ResourceLimitGroup_System), LimitableResource_Memory));
|
|
|
|
|
|
|
|
/* Get and save application + applet memory. */
|
|
|
|
R_ASSERT(svcGetSystemInfo(&g_memory_resource_limits[spl::MemoryArrangement_Dynamic][ResourceLimitGroup_Application], SystemInfoType_TotalPhysicalMemorySize, INVALID_HANDLE, PhysicalMemoryInfo_Application));
|
|
|
|
R_ASSERT(svcGetSystemInfo(&g_memory_resource_limits[spl::MemoryArrangement_Dynamic][ResourceLimitGroup_Applet], SystemInfoType_TotalPhysicalMemorySize, INVALID_HANDLE, PhysicalMemoryInfo_Applet));
|
|
|
|
|
|
|
|
const u64 application_size = g_memory_resource_limits[spl::MemoryArrangement_Dynamic][ResourceLimitGroup_Application];
|
|
|
|
const u64 applet_size = g_memory_resource_limits[spl::MemoryArrangement_Dynamic][ResourceLimitGroup_Applet];
|
|
|
|
const u64 reserved_non_system_size = (application_size + applet_size + ReservedMemorySize600);
|
|
|
|
|
|
|
|
/* Ensure there's enough memory for the system region. */
|
2019-10-24 10:30:10 +01:00
|
|
|
AMS_ASSERT(reserved_non_system_size < total_memory);
|
2019-06-29 10:20:36 +01:00
|
|
|
|
|
|
|
g_memory_resource_limits[spl::MemoryArrangement_Dynamic][ResourceLimitGroup_System] = total_memory - reserved_non_system_size;
|
|
|
|
} else {
|
|
|
|
g_memory_arrangement = spl::GetMemoryArrangement();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Adjust memory limits for atmosphere. */
|
|
|
|
/* We take memory away from applet normally, but away from application on < 3.0.0 to avoid a rare hang on boot. */
|
2019-12-10 01:56:38 +00:00
|
|
|
/* NOTE: On Version 5.0.0+, we cannot set the pools so simply. We must instead modify the kernel, which we do */
|
|
|
|
/* via patches in fusee-secondary. */
|
|
|
|
if (hos_version < hos::Version_600) {
|
|
|
|
const size_t extra_memory_size = hos_version == hos::Version_500 ? ExtraSystemMemorySizeAtmosphere500 : ExtraSystemMemorySizeAtmosphere;
|
|
|
|
const auto src_group = hos_version >= hos::Version_300 ? ResourceLimitGroup_Applet : ResourceLimitGroup_Application;
|
|
|
|
for (size_t i = 0; i < spl::MemoryArrangement_Count; i++) {
|
|
|
|
g_memory_resource_limits[i][ResourceLimitGroup_System] += extra_memory_size;
|
|
|
|
g_memory_resource_limits[i][src_group] -= extra_memory_size;
|
2019-06-29 10:20:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Actually set resource limits. */
|
|
|
|
{
|
2019-07-03 05:27:53 +01:00
|
|
|
std::scoped_lock lk(g_resource_limit_lock);
|
2019-06-29 10:20:36 +01:00
|
|
|
|
|
|
|
for (size_t group = 0; group < ResourceLimitGroup_Count; group++) {
|
|
|
|
R_ASSERT(SetResourceLimitLimitValues(static_cast<ResourceLimitGroup>(group), g_memory_resource_limits[g_memory_arrangement][group]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-24 09:40:44 +01:00
|
|
|
return ResultSuccess();
|
2019-06-29 10:20:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Result BoostSystemMemoryResourceLimit(u64 boost_size) {
|
|
|
|
/* Don't allow all application memory to be taken away. */
|
2019-10-24 09:40:44 +01:00
|
|
|
R_UNLESS(boost_size <= g_memory_resource_limits[g_memory_arrangement][ResourceLimitGroup_Application], pm::ResultInvalidSize());
|
2019-06-29 10:20:36 +01:00
|
|
|
|
|
|
|
const u64 new_app_size = g_memory_resource_limits[g_memory_arrangement][ResourceLimitGroup_Application] - boost_size;
|
|
|
|
{
|
2019-07-03 05:27:53 +01:00
|
|
|
std::scoped_lock lk(g_resource_limit_lock);
|
2019-06-29 10:20:36 +01:00
|
|
|
|
2019-10-15 06:49:06 +01:00
|
|
|
if (hos::GetVersion() >= hos::Version_500) {
|
2019-06-29 10:20:36 +01:00
|
|
|
/* Starting in 5.0.0, PM does not allow for only one of the sets to fail. */
|
|
|
|
if (boost_size < g_system_memory_boost_size) {
|
|
|
|
R_TRY(svcSetUnsafeLimit(boost_size));
|
|
|
|
R_ASSERT(SetMemoryResourceLimitLimitValue(ResourceLimitGroup_Application, new_app_size));
|
|
|
|
} else {
|
|
|
|
R_TRY(SetMemoryResourceLimitLimitValue(ResourceLimitGroup_Application, new_app_size));
|
|
|
|
R_ASSERT(svcSetUnsafeLimit(boost_size));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
const u64 new_sys_size = g_memory_resource_limits[g_memory_arrangement][ResourceLimitGroup_System] + boost_size;
|
|
|
|
if (boost_size < g_system_memory_boost_size) {
|
|
|
|
R_TRY(SetMemoryResourceLimitLimitValue(ResourceLimitGroup_System, new_sys_size));
|
|
|
|
R_TRY(SetMemoryResourceLimitLimitValue(ResourceLimitGroup_Application, new_app_size));
|
|
|
|
} else {
|
|
|
|
R_TRY(SetMemoryResourceLimitLimitValue(ResourceLimitGroup_Application, new_app_size));
|
|
|
|
R_TRY(SetMemoryResourceLimitLimitValue(ResourceLimitGroup_System, new_sys_size));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_system_memory_boost_size = boost_size;
|
|
|
|
}
|
|
|
|
|
2019-10-24 09:40:44 +01:00
|
|
|
return ResultSuccess();
|
2019-06-29 10:20:36 +01:00
|
|
|
}
|
|
|
|
|
2019-07-03 05:27:53 +01:00
|
|
|
Result BoostApplicationThreadResourceLimit() {
|
|
|
|
std::scoped_lock lk(g_resource_limit_lock);
|
|
|
|
/* Set new limit. */
|
|
|
|
const u64 new_thread_count = g_resource_limits[ResourceLimitGroup_Application][LimitableResource_Threads] + g_extra_application_threads_available;
|
|
|
|
R_TRY(svcSetResourceLimitLimitValue(GetResourceLimitHandle(ResourceLimitGroup_Application), LimitableResource_Threads, new_thread_count));
|
|
|
|
|
|
|
|
/* Record that we did so. */
|
|
|
|
g_resource_limits[ResourceLimitGroup_Application][LimitableResource_Threads] = new_thread_count;
|
|
|
|
g_extra_application_threads_available = 0;
|
|
|
|
|
2019-10-24 09:40:44 +01:00
|
|
|
return ResultSuccess();
|
2019-06-29 10:20:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Handle GetResourceLimitHandle(ResourceLimitGroup group) {
|
|
|
|
return g_resource_limit_handles[group];
|
|
|
|
}
|
|
|
|
|
|
|
|
Handle GetResourceLimitHandle(const ldr::ProgramInfo *info) {
|
|
|
|
return GetResourceLimitHandle(GetResourceLimitGroup(info));
|
|
|
|
}
|
|
|
|
|
|
|
|
void WaitResourceAvailable(const ldr::ProgramInfo *info) {
|
|
|
|
if (GetResourceLimitGroup(info) == ResourceLimitGroup_Application) {
|
|
|
|
WaitResourceAvailable(ResourceLimitGroup_Application);
|
2019-10-15 06:49:06 +01:00
|
|
|
if (hos::GetVersion() >= hos::Version_500) {
|
2019-06-29 10:20:36 +01:00
|
|
|
WaitApplicationMemoryAvailable();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Result GetResourceLimitValues(u64 *out_cur, u64 *out_lim, ResourceLimitGroup group, LimitableResource resource) {
|
|
|
|
/* Do not allow out of bounds access. */
|
2019-10-24 10:30:10 +01:00
|
|
|
AMS_ASSERT(group < ResourceLimitGroup_Count);
|
|
|
|
AMS_ASSERT(resource < LimitableResource_Count);
|
2019-06-29 10:20:36 +01:00
|
|
|
|
|
|
|
const Handle reslimit_hnd = GetResourceLimitHandle(group);
|
|
|
|
R_TRY(svcGetResourceLimitCurrentValue(out_cur, reslimit_hnd, resource));
|
|
|
|
R_TRY(svcGetResourceLimitLimitValue(out_lim, reslimit_hnd, resource));
|
|
|
|
|
2019-10-24 09:40:44 +01:00
|
|
|
return ResultSuccess();
|
2019-06-29 10:20:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|