mirror of
https://github.com/Atmosphere-NX/Atmosphere
synced 2024-12-22 20:31:14 +00:00
kern: fix/add InfoType_(Total/Used)(NonSystem/)MemorySize
This commit is contained in:
parent
35c1959131
commit
57867d6ced
5 changed files with 38 additions and 3 deletions
|
@ -328,7 +328,7 @@ namespace ams::kern {
|
|||
/* Lock the table. */
|
||||
KScopedLightLock lk(this->general_lock);
|
||||
|
||||
return this->GetHeapRegionSize() + this->mapped_physical_memory_size;
|
||||
return (this->current_heap_end - this->heap_region_start) + this->mapped_physical_memory_size;
|
||||
}
|
||||
public:
|
||||
static ALWAYS_INLINE KVirtualAddress GetLinearMappedVirtualAddress(KPhysicalAddress addr) {
|
||||
|
|
|
@ -176,6 +176,8 @@ namespace ams::kern {
|
|||
constexpr KHandleTable &GetHandleTable() { return this->handle_table; }
|
||||
constexpr const KHandleTable &GetHandleTable() const { return this->handle_table; }
|
||||
|
||||
size_t GetUsedUserPhysicalMemorySize() const;
|
||||
size_t GetTotalUserPhysicalMemorySize() const;
|
||||
size_t GetUsedNonSystemUserPhysicalMemorySize() const;
|
||||
size_t GetTotalNonSystemUserPhysicalMemorySize() const;
|
||||
|
||||
|
|
|
@ -303,7 +303,7 @@ namespace ams::kern {
|
|||
this->thread_list.erase(this->thread_list.iterator_to(*thread));
|
||||
}
|
||||
|
||||
size_t KProcess::GetUsedNonSystemUserPhysicalMemorySize() const {
|
||||
size_t KProcess::GetUsedUserPhysicalMemorySize() 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);
|
||||
|
@ -311,10 +311,30 @@ namespace ams::kern {
|
|||
return norm_size + other_size + sec_size;
|
||||
}
|
||||
|
||||
size_t KProcess::GetTotalNonSystemUserPhysicalMemorySize() const {
|
||||
size_t KProcess::GetTotalUserPhysicalMemorySize() 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 max_size = this->max_process_memory;
|
||||
|
||||
if (used_size + free_size > max_size) {
|
||||
return max_size;
|
||||
} else {
|
||||
return free_size + used_size;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
return norm_size + other_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->GetUsedUserPhysicalMemorySize();
|
||||
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;
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@ namespace ams::kern::svc {
|
|||
/* ============================= 64 ABI ============================= */
|
||||
|
||||
void Break64(ams::svc::BreakReason break_reason, ams::svc::Address arg, ams::svc::Size size) {
|
||||
MESOSPHERE_LOG("%s: Break\n", GetCurrentProcess().GetName());
|
||||
MESOSPHERE_PANIC("Stubbed SvcBreak64 was called.");
|
||||
}
|
||||
|
||||
|
|
|
@ -32,6 +32,8 @@ namespace ams::kern::svc {
|
|||
case ams::svc::InfoType_AliasRegionSize:
|
||||
case ams::svc::InfoType_HeapRegionAddress:
|
||||
case ams::svc::InfoType_HeapRegionSize:
|
||||
case ams::svc::InfoType_TotalMemorySize:
|
||||
case ams::svc::InfoType_UsedMemorySize:
|
||||
case ams::svc::InfoType_AslrRegionAddress:
|
||||
case ams::svc::InfoType_AslrRegionSize:
|
||||
case ams::svc::InfoType_StackRegionAddress:
|
||||
|
@ -40,6 +42,7 @@ namespace ams::kern::svc {
|
|||
case ams::svc::InfoType_InitialProcessIdRange:
|
||||
case ams::svc::InfoType_UserExceptionContextAddress:
|
||||
case ams::svc::InfoType_TotalNonSystemMemorySize:
|
||||
case ams::svc::InfoType_UsedNonSystemMemorySize:
|
||||
{
|
||||
/* These info types don't support non-zero subtypes. */
|
||||
R_UNLESS(info_subtype == 0, svc::ResultInvalidCombination());
|
||||
|
@ -67,6 +70,12 @@ namespace ams::kern::svc {
|
|||
case ams::svc::InfoType_HeapRegionSize:
|
||||
*out = process->GetPageTable().GetHeapRegionSize();
|
||||
break;
|
||||
case ams::svc::InfoType_TotalMemorySize:
|
||||
*out = process->GetTotalUserPhysicalMemorySize();
|
||||
break;
|
||||
case ams::svc::InfoType_UsedMemorySize:
|
||||
*out = process->GetUsedUserPhysicalMemorySize();
|
||||
break;
|
||||
case ams::svc::InfoType_AslrRegionAddress:
|
||||
*out = GetInteger(process->GetPageTable().GetAliasCodeRegionStart());
|
||||
break;
|
||||
|
@ -91,6 +100,9 @@ namespace ams::kern::svc {
|
|||
case ams::svc::InfoType_TotalNonSystemMemorySize:
|
||||
*out = process->GetTotalNonSystemUserPhysicalMemorySize();
|
||||
break;
|
||||
case ams::svc::InfoType_UsedNonSystemMemorySize:
|
||||
*out = process->GetUsedNonSystemUserPhysicalMemorySize();
|
||||
break;
|
||||
MESOSPHERE_UNREACHABLE_DEFAULT_CASE();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue