Simplify limitableresource names

This commit is contained in:
Chloe Marcec 2021-02-03 12:55:16 +11:00
parent 64c3582705
commit 2c6e940493
6 changed files with 29 additions and 36 deletions

View File

@ -22,11 +22,11 @@ class System;
namespace Kernel { namespace Kernel {
class KernelCore; class KernelCore;
enum class LimitableResource : u32 { enum class LimitableResource : u32 {
PhysicalMemoryMax = 0, PhysicalMemory = 0,
ThreadCountMax = 1, Threads = 1,
EventCountMax = 2, Events = 2,
TransferMemoryCountMax = 3, TransferMemory = 3,
SessionCountMax = 4, Sessions = 4,
Count, Count,
}; };

View File

@ -247,7 +247,7 @@ void KThread::Finalize() {
// Decrement the parent process's thread count. // Decrement the parent process's thread count.
if (parent != nullptr) { if (parent != nullptr) {
parent->DecrementThreadCount(); parent->DecrementThreadCount();
parent->GetResourceLimit()->Release(LimitableResource::ThreadCountMax, 1); parent->GetResourceLimit()->Release(LimitableResource::Threads, 1);
} }
} }

View File

@ -135,19 +135,15 @@ struct KernelCore::Impl {
system_resource_limit = std::make_shared<KResourceLimit>(kernel, system); system_resource_limit = std::make_shared<KResourceLimit>(kernel, system);
// If setting the default system values fails, then something seriously wrong has occurred. // If setting the default system values fails, then something seriously wrong has occurred.
ASSERT( ASSERT(system_resource_limit->SetLimitValue(LimitableResource::PhysicalMemory, 0x100000000)
system_resource_limit->SetLimitValue(LimitableResource::PhysicalMemoryMax, 0x100000000)
.IsSuccess()); .IsSuccess());
ASSERT(system_resource_limit->SetLimitValue(LimitableResource::ThreadCountMax, 800) ASSERT(system_resource_limit->SetLimitValue(LimitableResource::Threads, 800).IsSuccess());
.IsSuccess()); ASSERT(system_resource_limit->SetLimitValue(LimitableResource::Events, 700).IsSuccess());
ASSERT(system_resource_limit->SetLimitValue(LimitableResource::EventCountMax, 700) ASSERT(system_resource_limit->SetLimitValue(LimitableResource::TransferMemory, 200)
.IsSuccess());
ASSERT(system_resource_limit->SetLimitValue(LimitableResource::TransferMemoryCountMax, 200)
.IsSuccess());
ASSERT(system_resource_limit->SetLimitValue(LimitableResource::SessionCountMax, 900)
.IsSuccess()); .IsSuccess());
ASSERT(system_resource_limit->SetLimitValue(LimitableResource::Sessions, 900).IsSuccess());
if (!system_resource_limit->Reserve(LimitableResource::PhysicalMemoryMax, 0x60000)) { if (!system_resource_limit->Reserve(LimitableResource::PhysicalMemory, 0x60000)) {
UNREACHABLE(); UNREACHABLE();
} }
} }

View File

@ -413,8 +413,8 @@ ResultCode PageTable::MapPhysicalMemory(VAddr addr, std::size_t size) {
const std::size_t remaining_size{size - mapped_size}; const std::size_t remaining_size{size - mapped_size};
const std::size_t remaining_pages{remaining_size / PageSize}; const std::size_t remaining_pages{remaining_size / PageSize};
if (process->GetResourceLimit() && !process->GetResourceLimit()->Reserve( if (process->GetResourceLimit() &&
LimitableResource::PhysicalMemoryMax, remaining_size)) { !process->GetResourceLimit()->Reserve(LimitableResource::PhysicalMemory, remaining_size)) {
return ERR_RESOURCE_LIMIT_EXCEEDED; return ERR_RESOURCE_LIMIT_EXCEEDED;
} }
@ -422,8 +422,7 @@ ResultCode PageTable::MapPhysicalMemory(VAddr addr, std::size_t size) {
{ {
auto block_guard = detail::ScopeExit([&] { auto block_guard = detail::ScopeExit([&] {
system.Kernel().MemoryManager().Free(page_linked_list, remaining_pages, memory_pool); system.Kernel().MemoryManager().Free(page_linked_list, remaining_pages, memory_pool);
process->GetResourceLimit()->Release(LimitableResource::PhysicalMemoryMax, process->GetResourceLimit()->Release(LimitableResource::PhysicalMemory, remaining_size);
remaining_size);
}); });
CASCADE_CODE(system.Kernel().MemoryManager().Allocate(page_linked_list, remaining_pages, CASCADE_CODE(system.Kernel().MemoryManager().Allocate(page_linked_list, remaining_pages,
@ -475,7 +474,7 @@ ResultCode PageTable::UnmapPhysicalMemory(VAddr addr, std::size_t size) {
CASCADE_CODE(UnmapMemory(addr, size)); CASCADE_CODE(UnmapMemory(addr, size));
auto process{system.Kernel().CurrentProcess()}; auto process{system.Kernel().CurrentProcess()};
process->GetResourceLimit()->Release(LimitableResource::PhysicalMemoryMax, mapped_size); process->GetResourceLimit()->Release(LimitableResource::PhysicalMemory, mapped_size);
physical_memory_usage -= mapped_size; physical_memory_usage -= mapped_size;
return RESULT_SUCCESS; return RESULT_SUCCESS;
@ -784,7 +783,7 @@ ResultVal<VAddr> PageTable::SetHeapSize(std::size_t size) {
auto process{system.Kernel().CurrentProcess()}; auto process{system.Kernel().CurrentProcess()};
if (process->GetResourceLimit() && delta != 0 && if (process->GetResourceLimit() && delta != 0 &&
!process->GetResourceLimit()->Reserve(LimitableResource::PhysicalMemoryMax, delta)) { !process->GetResourceLimit()->Reserve(LimitableResource::PhysicalMemory, delta)) {
return ERR_RESOURCE_LIMIT_EXCEEDED; return ERR_RESOURCE_LIMIT_EXCEEDED;
} }

View File

@ -154,7 +154,7 @@ void Process::DecrementThreadCount() {
} }
u64 Process::GetTotalPhysicalMemoryAvailable() const { u64 Process::GetTotalPhysicalMemoryAvailable() const {
const u64 capacity{resource_limit->GetFreeValue(LimitableResource::PhysicalMemoryMax) + const u64 capacity{resource_limit->GetFreeValue(LimitableResource::PhysicalMemory) +
page_table->GetTotalHeapSize() + GetSystemResourceSize() + image_size + page_table->GetTotalHeapSize() + GetSystemResourceSize() + image_size +
main_thread_stack_size}; main_thread_stack_size};
@ -308,13 +308,13 @@ ResultCode Process::LoadFromMetadata(const FileSys::ProgramMetadata& metadata,
// Set initial resource limits // Set initial resource limits
resource_limit->SetLimitValue( resource_limit->SetLimitValue(
LimitableResource::PhysicalMemoryMax, LimitableResource::PhysicalMemory,
kernel.MemoryManager().GetSize(Memory::MemoryManager::Pool::Application)); kernel.MemoryManager().GetSize(Memory::MemoryManager::Pool::Application));
resource_limit->SetLimitValue(LimitableResource::ThreadCountMax, 608); resource_limit->SetLimitValue(LimitableResource::Threads, 608);
resource_limit->SetLimitValue(LimitableResource::EventCountMax, 700); resource_limit->SetLimitValue(LimitableResource::Events, 700);
resource_limit->SetLimitValue(LimitableResource::TransferMemoryCountMax, 128); resource_limit->SetLimitValue(LimitableResource::TransferMemory, 128);
resource_limit->SetLimitValue(LimitableResource::SessionCountMax, 894); resource_limit->SetLimitValue(LimitableResource::Sessions, 894);
ASSERT(resource_limit->Reserve(LimitableResource::PhysicalMemoryMax, code_size)); ASSERT(resource_limit->Reserve(LimitableResource::PhysicalMemory, code_size));
// Create TLS region // Create TLS region
tls_region_address = CreateTLSRegion(); tls_region_address = CreateTLSRegion();
@ -331,8 +331,8 @@ void Process::Run(s32 main_thread_priority, u64 stack_size) {
ChangeStatus(ProcessStatus::Running); ChangeStatus(ProcessStatus::Running);
SetupMainThread(system, *this, main_thread_priority, main_thread_stack_top); SetupMainThread(system, *this, main_thread_priority, main_thread_stack_top);
resource_limit->Reserve(LimitableResource::ThreadCountMax, 1); resource_limit->Reserve(LimitableResource::Threads, 1);
resource_limit->Reserve(LimitableResource::PhysicalMemoryMax, main_thread_stack_size); resource_limit->Reserve(LimitableResource::PhysicalMemory, main_thread_stack_size);
} }
void Process::PrepareForTermination() { void Process::PrepareForTermination() {

View File

@ -312,8 +312,7 @@ static ResultCode ConnectToNamedPort(Core::System& system, Handle* out_handle,
return ERR_NOT_FOUND; return ERR_NOT_FOUND;
} }
ASSERT(kernel.CurrentProcess()->GetResourceLimit()->Reserve(LimitableResource::SessionCountMax, ASSERT(kernel.CurrentProcess()->GetResourceLimit()->Reserve(LimitableResource::Sessions, 1));
1));
auto client_port = it->second; auto client_port = it->second;
@ -1451,9 +1450,8 @@ static ResultCode CreateThread(Core::System& system, Handle* out_handle, VAddr e
Svc::ResultInvalidPriority); Svc::ResultInvalidPriority);
R_UNLESS(process.CheckThreadPriority(priority), Svc::ResultInvalidPriority); R_UNLESS(process.CheckThreadPriority(priority), Svc::ResultInvalidPriority);
ASSERT(process.GetResourceLimit()->Reserve(LimitableResource::ThreadCountMax, 1, ASSERT(process.GetResourceLimit()->Reserve(
system.CoreTiming().GetGlobalTimeNs().count() + LimitableResource::Threads, 1, system.CoreTiming().GetGlobalTimeNs().count() + 100000000));
100000000));
std::shared_ptr<KThread> thread; std::shared_ptr<KThread> thread;
{ {