mirror of
https://github.com/Lime3DS/Lime3DS
synced 2024-10-31 20:27:52 +00:00
SVC: QueryMemory merges similar VMA
This commit is contained in:
parent
39cbd4166c
commit
5325388e24
1 changed files with 21 additions and 4 deletions
|
@ -964,10 +964,27 @@ static ResultCode QueryProcessMemory(MemoryInfo* memory_info, PageInfo* page_inf
|
||||||
if (vma == process->vm_manager.vma_map.end())
|
if (vma == process->vm_manager.vma_map.end())
|
||||||
return ERR_INVALID_ADDRESS;
|
return ERR_INVALID_ADDRESS;
|
||||||
|
|
||||||
memory_info->base_address = vma->second.base;
|
auto permissions = vma->second.permissions;
|
||||||
memory_info->permission = static_cast<u32>(vma->second.permissions);
|
auto state = vma->second.meminfo_state;
|
||||||
memory_info->size = vma->second.size;
|
|
||||||
memory_info->state = static_cast<u32>(vma->second.meminfo_state);
|
// Query(Process)Memory merges vma with neighbours when they share the same state and
|
||||||
|
// permissions, regardless of their physical mapping.
|
||||||
|
|
||||||
|
auto mismatch = [permissions, state](const std::pair<VAddr, Kernel::VirtualMemoryArea>& v) {
|
||||||
|
return v.second.permissions != permissions || v.second.meminfo_state != state;
|
||||||
|
};
|
||||||
|
|
||||||
|
std::reverse_iterator rvma(vma);
|
||||||
|
|
||||||
|
auto lower = std::find_if(rvma, process->vm_manager.vma_map.crend(), mismatch);
|
||||||
|
--lower;
|
||||||
|
auto upper = std::find_if(vma, process->vm_manager.vma_map.cend(), mismatch);
|
||||||
|
--upper;
|
||||||
|
|
||||||
|
memory_info->base_address = lower->second.base;
|
||||||
|
memory_info->permission = static_cast<u32>(permissions);
|
||||||
|
memory_info->size = upper->second.base + upper->second.size - lower->second.base;
|
||||||
|
memory_info->state = static_cast<u32>(state);
|
||||||
|
|
||||||
page_info->flags = 0;
|
page_info->flags = 0;
|
||||||
LOG_TRACE(Kernel_SVC, "called process=0x{:08X} addr=0x{:08X}", process_handle, addr);
|
LOG_TRACE(Kernel_SVC, "called process=0x{:08X} addr=0x{:08X}", process_handle, addr);
|
||||||
|
|
Loading…
Reference in a new issue