2015-05-12 15:25:15 -05:00
|
|
|
// Copyright 2015 Citra Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#include <cstring>
|
2019-12-27 18:52:33 +00:00
|
|
|
#include "common/archives.h"
|
2017-05-29 16:45:42 -07:00
|
|
|
#include "common/assert.h"
|
2015-05-12 15:25:15 -05:00
|
|
|
#include "common/logging/log.h"
|
2023-04-04 19:03:08 +02:00
|
|
|
#include "common/settings.h"
|
2016-09-20 23:52:38 -07:00
|
|
|
#include "core/hle/kernel/resource_limit.h"
|
2015-05-12 15:25:15 -05:00
|
|
|
|
2019-12-27 18:52:33 +00:00
|
|
|
SERIALIZE_EXPORT_IMPL(Kernel::ResourceLimit)
|
|
|
|
|
2015-05-12 15:25:15 -05:00
|
|
|
namespace Kernel {
|
|
|
|
|
2019-12-27 18:52:33 +00:00
|
|
|
ResourceLimit::ResourceLimit(KernelSystem& kernel) : Object(kernel) {}
|
|
|
|
ResourceLimit::~ResourceLimit() {}
|
|
|
|
|
2019-03-23 16:04:19 -04:00
|
|
|
std::shared_ptr<ResourceLimit> ResourceLimit::Create(KernelSystem& kernel, std::string name) {
|
2019-12-27 18:52:33 +00:00
|
|
|
auto resource_limit{std::make_shared<ResourceLimit>(kernel)};
|
2015-05-12 15:25:15 -05:00
|
|
|
|
|
|
|
resource_limit->name = std::move(name);
|
|
|
|
return resource_limit;
|
|
|
|
}
|
|
|
|
|
2019-03-23 16:04:19 -04:00
|
|
|
std::shared_ptr<ResourceLimit> ResourceLimitList::GetForCategory(ResourceLimitCategory category) {
|
2016-09-18 09:38:01 +09:00
|
|
|
switch (category) {
|
|
|
|
case ResourceLimitCategory::APPLICATION:
|
|
|
|
case ResourceLimitCategory::SYS_APPLET:
|
|
|
|
case ResourceLimitCategory::LIB_APPLET:
|
|
|
|
case ResourceLimitCategory::OTHER:
|
|
|
|
return resource_limits[static_cast<u8>(category)];
|
|
|
|
default:
|
2018-06-29 14:18:07 +03:00
|
|
|
LOG_CRITICAL(Kernel, "Unknown resource limit category");
|
2016-09-18 09:38:01 +09:00
|
|
|
UNREACHABLE();
|
2015-05-12 15:25:15 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
s32 ResourceLimit::GetCurrentResourceValue(u32 resource) const {
|
|
|
|
switch (resource) {
|
2016-09-18 09:38:01 +09:00
|
|
|
case COMMIT:
|
|
|
|
return current_commit;
|
|
|
|
case THREAD:
|
|
|
|
return current_threads;
|
|
|
|
case EVENT:
|
|
|
|
return current_events;
|
|
|
|
case MUTEX:
|
|
|
|
return current_mutexes;
|
|
|
|
case SEMAPHORE:
|
|
|
|
return current_semaphores;
|
|
|
|
case TIMER:
|
|
|
|
return current_timers;
|
|
|
|
case SHARED_MEMORY:
|
|
|
|
return current_shared_mems;
|
|
|
|
case ADDRESS_ARBITER:
|
|
|
|
return current_address_arbiters;
|
|
|
|
case CPU_TIME:
|
|
|
|
return current_cpu_time;
|
|
|
|
default:
|
2018-06-29 14:18:07 +03:00
|
|
|
LOG_ERROR(Kernel, "Unknown resource type={:08X}", resource);
|
2016-09-18 09:38:01 +09:00
|
|
|
UNIMPLEMENTED();
|
|
|
|
return 0;
|
2015-05-12 15:25:15 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-27 00:26:09 +01:00
|
|
|
u32 ResourceLimit::GetMaxResourceValue(u32 resource) const {
|
2015-05-12 15:25:15 -05:00
|
|
|
switch (resource) {
|
2017-01-11 12:08:10 -05:00
|
|
|
case PRIORITY:
|
|
|
|
return max_priority;
|
2016-09-18 09:38:01 +09:00
|
|
|
case COMMIT:
|
|
|
|
return max_commit;
|
|
|
|
case THREAD:
|
|
|
|
return max_threads;
|
|
|
|
case EVENT:
|
|
|
|
return max_events;
|
|
|
|
case MUTEX:
|
|
|
|
return max_mutexes;
|
|
|
|
case SEMAPHORE:
|
|
|
|
return max_semaphores;
|
|
|
|
case TIMER:
|
|
|
|
return max_timers;
|
|
|
|
case SHARED_MEMORY:
|
|
|
|
return max_shared_mems;
|
|
|
|
case ADDRESS_ARBITER:
|
|
|
|
return max_address_arbiters;
|
|
|
|
case CPU_TIME:
|
|
|
|
return max_cpu_time;
|
|
|
|
default:
|
2018-06-29 14:18:07 +03:00
|
|
|
LOG_ERROR(Kernel, "Unknown resource type={:08X}", resource);
|
2016-09-18 09:38:01 +09:00
|
|
|
UNIMPLEMENTED();
|
|
|
|
return 0;
|
2015-05-12 15:25:15 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-13 16:41:34 -04:00
|
|
|
ResourceLimitList::ResourceLimitList(KernelSystem& kernel) {
|
2015-05-12 15:25:15 -05:00
|
|
|
// Create the four resource limits that the system uses
|
|
|
|
// Create the APPLICATION resource limit
|
2023-04-04 19:03:08 +02:00
|
|
|
const bool is_new_3ds = Settings::values.is_new_3ds.GetValue();
|
|
|
|
|
2019-03-23 16:04:19 -04:00
|
|
|
std::shared_ptr<ResourceLimit> resource_limit = ResourceLimit::Create(kernel, "Applications");
|
2015-05-12 15:25:15 -05:00
|
|
|
resource_limit->max_priority = 0x18;
|
2023-04-04 19:03:08 +02:00
|
|
|
resource_limit->max_commit = is_new_3ds ? 0x7C00000 : 0x4000000;
|
2015-05-12 15:25:15 -05:00
|
|
|
resource_limit->max_threads = 0x20;
|
|
|
|
resource_limit->max_events = 0x20;
|
|
|
|
resource_limit->max_mutexes = 0x20;
|
|
|
|
resource_limit->max_semaphores = 0x8;
|
|
|
|
resource_limit->max_timers = 0x8;
|
|
|
|
resource_limit->max_shared_mems = 0x10;
|
|
|
|
resource_limit->max_address_arbiters = 0x2;
|
2023-04-04 19:03:08 +02:00
|
|
|
resource_limit->max_cpu_time = 0x0;
|
2015-05-12 15:25:15 -05:00
|
|
|
resource_limits[static_cast<u8>(ResourceLimitCategory::APPLICATION)] = resource_limit;
|
|
|
|
|
|
|
|
// Create the SYS_APPLET resource limit
|
2018-10-13 16:41:34 -04:00
|
|
|
resource_limit = ResourceLimit::Create(kernel, "System Applets");
|
2015-05-12 15:25:15 -05:00
|
|
|
resource_limit->max_priority = 0x4;
|
2023-04-04 19:03:08 +02:00
|
|
|
resource_limit->max_commit = is_new_3ds ? 0x5E06000 : 0x2606000;
|
|
|
|
resource_limit->max_threads = is_new_3ds ? 0x1D : 0xE;
|
|
|
|
resource_limit->max_events = is_new_3ds ? 0xB : 0x8;
|
2015-05-12 15:25:15 -05:00
|
|
|
resource_limit->max_mutexes = 0x8;
|
|
|
|
resource_limit->max_semaphores = 0x4;
|
|
|
|
resource_limit->max_timers = 0x4;
|
|
|
|
resource_limit->max_shared_mems = 0x8;
|
|
|
|
resource_limit->max_address_arbiters = 0x3;
|
|
|
|
resource_limit->max_cpu_time = 0x2710;
|
|
|
|
resource_limits[static_cast<u8>(ResourceLimitCategory::SYS_APPLET)] = resource_limit;
|
|
|
|
|
|
|
|
// Create the LIB_APPLET resource limit
|
2018-10-13 16:41:34 -04:00
|
|
|
resource_limit = ResourceLimit::Create(kernel, "Library Applets");
|
2015-05-12 15:25:15 -05:00
|
|
|
resource_limit->max_priority = 0x4;
|
2023-04-04 19:03:08 +02:00
|
|
|
resource_limit->max_commit = 0x602000;
|
2015-05-12 15:25:15 -05:00
|
|
|
resource_limit->max_threads = 0xE;
|
|
|
|
resource_limit->max_events = 0x8;
|
|
|
|
resource_limit->max_mutexes = 0x8;
|
|
|
|
resource_limit->max_semaphores = 0x4;
|
|
|
|
resource_limit->max_timers = 0x4;
|
|
|
|
resource_limit->max_shared_mems = 0x8;
|
|
|
|
resource_limit->max_address_arbiters = 0x1;
|
|
|
|
resource_limit->max_cpu_time = 0x2710;
|
|
|
|
resource_limits[static_cast<u8>(ResourceLimitCategory::LIB_APPLET)] = resource_limit;
|
|
|
|
|
|
|
|
// Create the OTHER resource limit
|
2018-10-13 16:41:34 -04:00
|
|
|
resource_limit = ResourceLimit::Create(kernel, "Others");
|
2015-05-12 15:25:15 -05:00
|
|
|
resource_limit->max_priority = 0x4;
|
2023-04-04 19:03:08 +02:00
|
|
|
resource_limit->max_commit = is_new_3ds ? 0x2182000 : 0x1682000;
|
|
|
|
resource_limit->max_threads = is_new_3ds ? 0xE1 : 0xCA;
|
|
|
|
resource_limit->max_events = is_new_3ds ? 0x108 : 0xF8;
|
|
|
|
resource_limit->max_mutexes = is_new_3ds ? 0x25 : 0x23;
|
|
|
|
resource_limit->max_semaphores = is_new_3ds ? 0x43 : 0x40;
|
|
|
|
resource_limit->max_timers = is_new_3ds ? 0x2C : 0x2B;
|
|
|
|
resource_limit->max_shared_mems = is_new_3ds ? 0x1F : 0x1E;
|
|
|
|
resource_limit->max_address_arbiters = is_new_3ds ? 0x2D : 0x2B;
|
2015-05-12 15:25:15 -05:00
|
|
|
resource_limit->max_cpu_time = 0x3E8;
|
|
|
|
resource_limits[static_cast<u8>(ResourceLimitCategory::OTHER)] = resource_limit;
|
|
|
|
}
|
|
|
|
|
2018-10-13 16:41:34 -04:00
|
|
|
ResourceLimitList::~ResourceLimitList() = default;
|
2015-05-12 15:25:15 -05:00
|
|
|
|
2018-03-09 10:54:43 -07:00
|
|
|
} // namespace Kernel
|