kern: implement SvcUnmapMemory, more of SvcGetInfo

This commit is contained in:
Michael Scire 2020-05-29 00:57:25 -07:00
commit 1a0696f8a3
14 changed files with 231 additions and 37 deletions

View file

@ -280,6 +280,28 @@ namespace ams::kern {
this->thread_list.erase(this->thread_list.iterator_to(*thread));
}
size_t KProcess::GetUsedNonSystemUserPhysicalMemorySize() const {
const size_t norm_size = this->page_table.GetNormalMemorySize();
const size_t other_size = this->code_size + this->main_thread_stack_size;
const size_t sec_size = KSystemControl::CalculateRequiredSecureMemorySize(this->system_resource_num_pages * PageSize, this->memory_pool);
return norm_size + other_size + sec_size;
}
size_t KProcess::GetTotalNonSystemUserPhysicalMemorySize() const {
/* Get the amount of free and used size. */
const size_t free_size = this->resource_limit->GetFreeValue(ams::svc::LimitableResource_PhysicalMemoryMax);
const size_t used_size = this->GetUsedNonSystemUserPhysicalMemorySize();
const size_t sec_size = KSystemControl::CalculateRequiredSecureMemorySize(this->system_resource_num_pages * PageSize, this->memory_pool);
const size_t max_size = this->max_process_memory;
if (used_size + free_size > max_size) {
return max_size - sec_size;
} else {
return free_size + used_size - sec_size;
}
}
Result KProcess::Run(s32 priority, size_t stack_size) {
MESOSPHERE_ASSERT_THIS();