hle: kernel: Migrate KResourceLimit to KAutoObject.

This commit is contained in:
bunnei 2021-04-20 21:28:11 -07:00
parent 674122038a
commit b57c5a9b54
13 changed files with 198 additions and 123 deletions

View file

@ -138,10 +138,13 @@ ResultCode Process::Initialize(Process* process, Core::System& system, std::stri
kernel.AppendNewProcess(process);
// Open a reference to the resource limit.
process->resource_limit->Open();
return RESULT_SUCCESS;
}
std::shared_ptr<KResourceLimit> Process::GetResourceLimit() const {
KResourceLimit* Process::GetResourceLimit() const {
return resource_limit;
}
@ -166,7 +169,10 @@ u64 Process::GetTotalPhysicalMemoryAvailable() const {
const u64 capacity{resource_limit->GetFreeValue(LimitableResource::PhysicalMemory) +
page_table->GetTotalHeapSize() + GetSystemResourceSize() + image_size +
main_thread_stack_size};
ASSERT(capacity == kernel.MemoryManager().GetSize(KMemoryManager::Pool::Application));
if (const auto pool_size = kernel.MemoryManager().GetSize(KMemoryManager::Pool::Application);
capacity != pool_size) {
LOG_WARNING(Kernel, "capacity {} != application pool size {}", capacity, pool_size);
}
if (capacity < memory_usage_capacity) {
return capacity;
}
@ -371,6 +377,16 @@ void Process::PrepareForTermination() {
ChangeStatus(ProcessStatus::Exited);
}
void Process::Finalize() {
// Release memory to the resource limit.
if (resource_limit != nullptr) {
resource_limit->Close();
}
// Perform inherited finalization.
KAutoObjectWithSlabHeapAndContainer<Process, KSynchronizationObject>::Finalize();
}
/**
* Attempts to find a TLS page that contains a free slot for
* use by a thread.