address review commentary
This commit is contained in:
parent
13a8fde3ad
commit
1689784c19
5 changed files with 42 additions and 36 deletions
|
@ -129,20 +129,16 @@ u64 Process::GetTotalPhysicalMemoryAvailable() const {
|
||||||
return vm_manager.GetTotalPhysicalMemoryAvailable();
|
return vm_manager.GetTotalPhysicalMemoryAvailable();
|
||||||
}
|
}
|
||||||
|
|
||||||
u64 Process::GetTotalPhysicalMemoryAvailableWithoutMmHeap() const {
|
u64 Process::GetTotalPhysicalMemoryAvailableWithoutSystemResource() const {
|
||||||
// TODO: Subtract the personal heap size from this when the
|
return GetTotalPhysicalMemoryAvailable() - GetSystemResourceSize();
|
||||||
// personal heap is implemented.
|
|
||||||
return GetTotalPhysicalMemoryAvailable();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
u64 Process::GetTotalPhysicalMemoryUsed() const {
|
u64 Process::GetTotalPhysicalMemoryUsed() const {
|
||||||
return vm_manager.GetCurrentHeapSize() + main_thread_stack_size + code_memory_size;
|
return vm_manager.GetCurrentHeapSize() + main_thread_stack_size + code_memory_size + GetSystemResourceUsage();
|
||||||
}
|
}
|
||||||
|
|
||||||
u64 Process::GetTotalPhysicalMemoryUsedWithoutMmHeap() const {
|
u64 Process::GetTotalPhysicalMemoryUsedWithoutSystemResource() const {
|
||||||
// TODO: Subtract the personal heap size from this when the
|
return GetTotalPhysicalMemoryUsed() - GetSystemResourceUsage();
|
||||||
// personal heap is implemented.
|
|
||||||
return GetTotalPhysicalMemoryUsed();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Process::RegisterThread(const Thread* thread) {
|
void Process::RegisterThread(const Thread* thread) {
|
||||||
|
|
|
@ -173,6 +173,21 @@ public:
|
||||||
return system_resource_size;
|
return system_resource_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Gets the amount of secure memory currently in use for memory management.
|
||||||
|
u32 GetSystemResourceUsage() const {
|
||||||
|
// On hardware, this returns the amount of system resource memory that has
|
||||||
|
// been used by the kernel. This is problematic for Yuzu to emulate, because
|
||||||
|
// system resource memory is used for page tables -- and yuzu doesn't really
|
||||||
|
// have a way to calculate how much memory is required for page tables for
|
||||||
|
// the current process at any given time.
|
||||||
|
// TODO: Is this even worth implementing? Games may retrieve this value via
|
||||||
|
// an SDK function that gets used + available system resource size for debug
|
||||||
|
// or diagnostic purposes. However, it seems unlikely that a game would make
|
||||||
|
// decisions based on how much system memory is dedicated to its page tables.
|
||||||
|
// Is returning a value other than zero wise?
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/// Whether this process is an AArch64 or AArch32 process.
|
/// Whether this process is an AArch64 or AArch32 process.
|
||||||
bool Is64BitProcess() const {
|
bool Is64BitProcess() const {
|
||||||
return is_64bit_process;
|
return is_64bit_process;
|
||||||
|
@ -197,15 +212,15 @@ public:
|
||||||
u64 GetTotalPhysicalMemoryAvailable() const;
|
u64 GetTotalPhysicalMemoryAvailable() const;
|
||||||
|
|
||||||
/// Retrieves the total physical memory available to this process in bytes,
|
/// Retrieves the total physical memory available to this process in bytes,
|
||||||
/// without the size of the personal heap added to it.
|
/// without the size of the personal system resource heap added to it.
|
||||||
u64 GetTotalPhysicalMemoryAvailableWithoutMmHeap() const;
|
u64 GetTotalPhysicalMemoryAvailableWithoutSystemResource() const;
|
||||||
|
|
||||||
/// Retrieves the total physical memory used by this process in bytes.
|
/// Retrieves the total physical memory used by this process in bytes.
|
||||||
u64 GetTotalPhysicalMemoryUsed() const;
|
u64 GetTotalPhysicalMemoryUsed() const;
|
||||||
|
|
||||||
/// Retrieves the total physical memory used by this process in bytes,
|
/// Retrieves the total physical memory used by this process in bytes,
|
||||||
/// without the size of the personal heap added to it.
|
/// without the size of the personal system resource heap added to it.
|
||||||
u64 GetTotalPhysicalMemoryUsedWithoutMmHeap() const;
|
u64 GetTotalPhysicalMemoryUsedWithoutSystemResource() const;
|
||||||
|
|
||||||
/// Gets the list of all threads created with this process as their owner.
|
/// Gets the list of all threads created with this process as their owner.
|
||||||
const std::list<const Thread*>& GetThreadList() const {
|
const std::list<const Thread*>& GetThreadList() const {
|
||||||
|
|
|
@ -737,8 +737,8 @@ static ResultCode GetInfo(Core::System& system, u64* result, u64 info_id, u64 ha
|
||||||
// 5.0.0+
|
// 5.0.0+
|
||||||
UserExceptionContextAddr = 20,
|
UserExceptionContextAddr = 20,
|
||||||
// 6.0.0+
|
// 6.0.0+
|
||||||
TotalPhysicalMemoryAvailableWithoutMmHeap = 21,
|
TotalPhysicalMemoryAvailableWithoutSystemResource = 21,
|
||||||
TotalPhysicalMemoryUsedWithoutMmHeap = 22,
|
TotalPhysicalMemoryUsedWithoutSystemResource = 22,
|
||||||
};
|
};
|
||||||
|
|
||||||
const auto info_id_type = static_cast<GetInfoType>(info_id);
|
const auto info_id_type = static_cast<GetInfoType>(info_id);
|
||||||
|
@ -760,8 +760,8 @@ static ResultCode GetInfo(Core::System& system, u64* result, u64 info_id, u64 ha
|
||||||
case GetInfoType::SystemResourceUsage:
|
case GetInfoType::SystemResourceUsage:
|
||||||
case GetInfoType::TitleId:
|
case GetInfoType::TitleId:
|
||||||
case GetInfoType::UserExceptionContextAddr:
|
case GetInfoType::UserExceptionContextAddr:
|
||||||
case GetInfoType::TotalPhysicalMemoryAvailableWithoutMmHeap:
|
case GetInfoType::TotalPhysicalMemoryAvailableWithoutSystemResource:
|
||||||
case GetInfoType::TotalPhysicalMemoryUsedWithoutMmHeap: {
|
case GetInfoType::TotalPhysicalMemoryUsedWithoutSystemResource: {
|
||||||
if (info_sub_id != 0) {
|
if (info_sub_id != 0) {
|
||||||
return ERR_INVALID_ENUM_VALUE;
|
return ERR_INVALID_ENUM_VALUE;
|
||||||
}
|
}
|
||||||
|
@ -827,17 +827,9 @@ static ResultCode GetInfo(Core::System& system, u64* result, u64 info_id, u64 ha
|
||||||
return RESULT_SUCCESS;
|
return RESULT_SUCCESS;
|
||||||
|
|
||||||
case GetInfoType::SystemResourceUsage:
|
case GetInfoType::SystemResourceUsage:
|
||||||
// On hardware, this returns the amount of system resource memory that has
|
|
||||||
// been used by the kernel. This is problematic for Yuzu to emulate, because
|
|
||||||
// system resource memory is used for page tables -- and yuzu doesn't really
|
|
||||||
// have a way to calculate how much memory is required for page tables for
|
|
||||||
// the current process at any given time.
|
|
||||||
// TODO: Is this even worth implementing? No game should ever use it, since
|
|
||||||
// the amount of remaining page table space should never be relevant except
|
|
||||||
// for diagnostics. Is returning a value other than zero wise?
|
|
||||||
LOG_WARNING(Kernel_SVC,
|
LOG_WARNING(Kernel_SVC,
|
||||||
"(STUBBED) Attempted to query system resource usage, returned 0");
|
"(STUBBED) Attempted to query system resource usage");
|
||||||
*result = 0;
|
*result = process->GetSystemResourceUsage();
|
||||||
return RESULT_SUCCESS;
|
return RESULT_SUCCESS;
|
||||||
|
|
||||||
case GetInfoType::TitleId:
|
case GetInfoType::TitleId:
|
||||||
|
@ -850,12 +842,12 @@ static ResultCode GetInfo(Core::System& system, u64* result, u64 info_id, u64 ha
|
||||||
*result = 0;
|
*result = 0;
|
||||||
return RESULT_SUCCESS;
|
return RESULT_SUCCESS;
|
||||||
|
|
||||||
case GetInfoType::TotalPhysicalMemoryAvailableWithoutMmHeap:
|
case GetInfoType::TotalPhysicalMemoryAvailableWithoutSystemResource:
|
||||||
*result = process->GetTotalPhysicalMemoryAvailable();
|
*result = process->GetTotalPhysicalMemoryAvailableWithoutSystemResource();
|
||||||
return RESULT_SUCCESS;
|
return RESULT_SUCCESS;
|
||||||
|
|
||||||
case GetInfoType::TotalPhysicalMemoryUsedWithoutMmHeap:
|
case GetInfoType::TotalPhysicalMemoryUsedWithoutSystemResource:
|
||||||
*result = process->GetTotalPhysicalMemoryUsedWithoutMmHeap();
|
*result = process->GetTotalPhysicalMemoryUsedWithoutSystemResource();
|
||||||
return RESULT_SUCCESS;
|
return RESULT_SUCCESS;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -984,7 +976,7 @@ static ResultCode MapPhysicalMemory(Core::System& system, VAddr addr, u64 size)
|
||||||
return ERR_INVALID_MEMORY_RANGE;
|
return ERR_INVALID_MEMORY_RANGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto* const current_process = Core::CurrentProcess();
|
Process* const current_process = system.Kernel().CurrentProcess();
|
||||||
auto& vm_manager = current_process->VMManager();
|
auto& vm_manager = current_process->VMManager();
|
||||||
|
|
||||||
if (current_process->GetSystemResourceSize() == 0) {
|
if (current_process->GetSystemResourceSize() == 0) {
|
||||||
|
@ -1024,7 +1016,7 @@ static ResultCode UnmapPhysicalMemory(Core::System& system, VAddr addr, u64 size
|
||||||
return ERR_INVALID_MEMORY_RANGE;
|
return ERR_INVALID_MEMORY_RANGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto* const current_process = Core::CurrentProcess();
|
Process* const current_process = system.Kernel().CurrentProcess();
|
||||||
auto& vm_manager = current_process->VMManager();
|
auto& vm_manager = current_process->VMManager();
|
||||||
|
|
||||||
if (current_process->GetSystemResourceSize() == 0) {
|
if (current_process->GetSystemResourceSize() == 0) {
|
||||||
|
|
|
@ -349,7 +349,7 @@ ResultCode VMManager::MapPhysicalMemory(VAddr target, u64 size) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check that we can map the memory we want.
|
// Check that we can map the memory we want.
|
||||||
const auto res_limit = Core::CurrentProcess()->GetResourceLimit();
|
const auto res_limit = system.CurrentProcess()->GetResourceLimit();
|
||||||
const u64 physmem_remaining = res_limit->GetMaxResourceValue(ResourceType::PhysicalMemory) -
|
const u64 physmem_remaining = res_limit->GetMaxResourceValue(ResourceType::PhysicalMemory) -
|
||||||
res_limit->GetCurrentResourceValue(ResourceType::PhysicalMemory);
|
res_limit->GetCurrentResourceValue(ResourceType::PhysicalMemory);
|
||||||
if (physmem_remaining < (size - mapped_size)) {
|
if (physmem_remaining < (size - mapped_size)) {
|
||||||
|
@ -558,6 +558,9 @@ ResultCode VMManager::UnmapPhysicalMemory(VAddr target, u64 size) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update mapped amount
|
||||||
|
physical_memory_mapped -= mapped_size;
|
||||||
|
|
||||||
return RESULT_SUCCESS;
|
return RESULT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -458,7 +458,7 @@ public:
|
||||||
///
|
///
|
||||||
/// @note The destination address must lie within the Map region.
|
/// @note The destination address must lie within the Map region.
|
||||||
///
|
///
|
||||||
/// @note This function requires SystemResourceSize is non-zero,
|
/// @note This function requires that SystemResourceSize be non-zero,
|
||||||
/// however, this is just because if it were not then the
|
/// however, this is just because if it were not then the
|
||||||
/// resulting page tables could be exploited on hardware by
|
/// resulting page tables could be exploited on hardware by
|
||||||
/// a malicious program. SystemResource usage does not need
|
/// a malicious program. SystemResource usage does not need
|
||||||
|
@ -472,7 +472,7 @@ public:
|
||||||
///
|
///
|
||||||
/// @note The destination address must lie within the Map region.
|
/// @note The destination address must lie within the Map region.
|
||||||
///
|
///
|
||||||
/// @note This function requires SystemResourceSize is non-zero,
|
/// @note This function requires that SystemResourceSize be non-zero,
|
||||||
/// however, this is just because if it were not then the
|
/// however, this is just because if it were not then the
|
||||||
/// resulting page tables could be exploited on hardware by
|
/// resulting page tables could be exploited on hardware by
|
||||||
/// a malicious program. SystemResource usage does not need
|
/// a malicious program. SystemResource usage does not need
|
||||||
|
|
Loading…
Reference in a new issue