mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2024-11-30 07:42:13 +00:00
kern: finish SvcGetSystemInfo
This commit is contained in:
parent
43ad4eb794
commit
058f223b97
3 changed files with 58 additions and 0 deletions
|
@ -73,6 +73,8 @@ namespace ams::kern {
|
|||
constexpr size_t GetSize() const { return this->heap.GetSize(); }
|
||||
constexpr KVirtualAddress GetEndAddress() const { return this->heap.GetEndAddress(); }
|
||||
|
||||
size_t GetFreeSize() const { return this->heap.GetFreeSize(); }
|
||||
|
||||
constexpr void SetNext(Impl *n) { this->next = n; }
|
||||
constexpr void SetPrev(Impl *n) { this->prev = n; }
|
||||
constexpr Impl *GetNext() const { return this->next; }
|
||||
|
@ -204,6 +206,23 @@ namespace ams::kern {
|
|||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
size_t GetFreeSize() {
|
||||
size_t total = 0;
|
||||
for (size_t i = 0; i < this->num_managers; i++) {
|
||||
total += this->managers[i].GetFreeSize();
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
size_t GetFreeSize(Pool pool) {
|
||||
constexpr Direction GetSizeDirection = Direction_FromFront;
|
||||
size_t total = 0;
|
||||
for (auto *manager = this->GetFirstManager(pool, GetSizeDirection); manager != nullptr; manager = this->GetNextManager(manager, GetSizeDirection)) {
|
||||
total += manager->GetFreeSize();
|
||||
}
|
||||
return total;
|
||||
}
|
||||
public:
|
||||
static size_t CalculateMetadataOverheadSize(size_t region_size) {
|
||||
return Impl::CalculateMetadataOverheadSize(region_size);
|
||||
|
|
|
@ -145,6 +145,8 @@ namespace ams::kern {
|
|||
return Initialize(heap_address, heap_size, metadata_address, metadata_size, MemoryBlockPageShifts, NumMemoryBlockPageShifts);
|
||||
}
|
||||
|
||||
size_t GetFreeSize() const { return this->GetNumFreePages() * PageSize; }
|
||||
|
||||
void UpdateUsedSize() {
|
||||
this->used_size = this->heap_size - (this->GetNumFreePages() * PageSize);
|
||||
}
|
||||
|
|
|
@ -139,11 +139,48 @@ namespace ams::kern::svc {
|
|||
return ResultSuccess();
|
||||
}
|
||||
|
||||
constexpr bool IsValidMemoryPool(u64 pool) {
|
||||
switch (static_cast<KMemoryManager::Pool>(pool)) {
|
||||
case KMemoryManager::Pool_Application:
|
||||
case KMemoryManager::Pool_Applet:
|
||||
case KMemoryManager::Pool_System:
|
||||
case KMemoryManager::Pool_SystemNonSecure:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Result GetSystemInfo(u64 *out, ams::svc::SystemInfoType info_type, ams::svc::Handle handle, u64 info_subtype) {
|
||||
MESOSPHERE_LOG("GetSystemInfo(%p, %u, %08x, %lu) was called\n", out, static_cast<u32>(info_type), static_cast<u32>(handle), info_subtype);
|
||||
ON_SCOPE_EXIT{ MESOSPHERE_LOG("GetSystemInfo returned %016lx\n", *out); };
|
||||
|
||||
switch (info_type) {
|
||||
case ams::svc::SystemInfoType_TotalPhysicalMemorySize:
|
||||
case ams::svc::SystemInfoType_UsedPhysicalMemorySize:
|
||||
{
|
||||
/* Verify the input handle is invalid. */
|
||||
R_UNLESS(handle == ams::svc::InvalidHandle, svc::ResultInvalidHandle());
|
||||
|
||||
/* Verify the sub-type is valid. */
|
||||
R_UNLESS(IsValidMemoryPool(info_subtype), svc::ResultInvalidCombination());
|
||||
|
||||
/* Convert to pool. */
|
||||
const auto pool = static_cast<KMemoryManager::Pool>(info_subtype);
|
||||
|
||||
/* Get the memory size. */
|
||||
auto &mm = Kernel::GetMemoryManager();
|
||||
switch (info_type) {
|
||||
case ams::svc::SystemInfoType_TotalPhysicalMemorySize:
|
||||
*out = mm.GetSize(pool);
|
||||
break;
|
||||
case ams::svc::SystemInfoType_UsedPhysicalMemorySize:
|
||||
*out = mm.GetSize(pool) - mm.GetFreeSize(pool);
|
||||
break;
|
||||
MESOSPHERE_UNREACHABLE_DEFAULT_CASE();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ams::svc::SystemInfoType_InitialProcessIdRange:
|
||||
{
|
||||
R_UNLESS(handle == ams::svc::InvalidHandle, svc::ResultInvalidHandle());
|
||||
|
|
Loading…
Reference in a new issue