mirror of
https://git.suyu.dev/suyu/suyu.git
synced 2024-11-22 23:02:47 +01:00
vm_manager: Migrate memory querying to the VMManager interface
Gets rid of the need to directly access the managed VMAs outside of the memory manager itself just for querying memory.
This commit is contained in:
parent
c02b8c895b
commit
a8cc03502b
4 changed files with 33 additions and 18 deletions
|
@ -1068,8 +1068,8 @@ static ResultCode UnmapSharedMemory(Handle shared_memory_handle, VAddr addr, u64
|
||||||
|
|
||||||
/// Query process memory
|
/// Query process memory
|
||||||
static ResultCode QueryProcessMemory(MemoryInfo* memory_info, PageInfo* /*page_info*/,
|
static ResultCode QueryProcessMemory(MemoryInfo* memory_info, PageInfo* /*page_info*/,
|
||||||
Handle process_handle, u64 addr) {
|
Handle process_handle, u64 address) {
|
||||||
LOG_TRACE(Kernel_SVC, "called process=0x{:08X} addr={:X}", process_handle, addr);
|
LOG_TRACE(Kernel_SVC, "called process=0x{:08X} address={:X}", process_handle, address);
|
||||||
const auto& handle_table = Core::CurrentProcess()->GetHandleTable();
|
const auto& handle_table = Core::CurrentProcess()->GetHandleTable();
|
||||||
SharedPtr<Process> process = handle_table.Get<Process>(process_handle);
|
SharedPtr<Process> process = handle_table.Get<Process>(process_handle);
|
||||||
if (!process) {
|
if (!process) {
|
||||||
|
@ -1079,21 +1079,9 @@ static ResultCode QueryProcessMemory(MemoryInfo* memory_info, PageInfo* /*page_i
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto& vm_manager = process->VMManager();
|
const auto& vm_manager = process->VMManager();
|
||||||
const auto vma = vm_manager.FindVMA(addr);
|
const auto result = vm_manager.QueryMemory(address);
|
||||||
|
|
||||||
memory_info->attributes = 0;
|
|
||||||
if (vm_manager.IsValidHandle(vma)) {
|
|
||||||
memory_info->base_address = vma->second.base;
|
|
||||||
memory_info->permission = static_cast<u32>(vma->second.permissions);
|
|
||||||
memory_info->size = vma->second.size;
|
|
||||||
memory_info->type = ToSvcMemoryState(vma->second.meminfo_state);
|
|
||||||
} else {
|
|
||||||
memory_info->base_address = 0;
|
|
||||||
memory_info->permission = static_cast<u32>(VMAPermission::None);
|
|
||||||
memory_info->size = 0;
|
|
||||||
memory_info->type = static_cast<u32>(MemoryState::Unmapped);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
*memory_info = result;
|
||||||
return RESULT_SUCCESS;
|
return RESULT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -199,7 +199,7 @@ void SvcWrap() {
|
||||||
|
|
||||||
Memory::Write64(Param(0), memory_info.base_address);
|
Memory::Write64(Param(0), memory_info.base_address);
|
||||||
Memory::Write64(Param(0) + 8, memory_info.size);
|
Memory::Write64(Param(0) + 8, memory_info.size);
|
||||||
Memory::Write32(Param(0) + 16, memory_info.type);
|
Memory::Write32(Param(0) + 16, memory_info.state);
|
||||||
Memory::Write32(Param(0) + 20, memory_info.attributes);
|
Memory::Write32(Param(0) + 20, memory_info.attributes);
|
||||||
Memory::Write32(Param(0) + 24, memory_info.permission);
|
Memory::Write32(Param(0) + 24, memory_info.permission);
|
||||||
|
|
||||||
|
|
|
@ -302,6 +302,25 @@ ResultCode VMManager::HeapFree(VAddr target, u64 size) {
|
||||||
return RESULT_SUCCESS;
|
return RESULT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MemoryInfo VMManager::QueryMemory(VAddr address) const {
|
||||||
|
const auto vma = FindVMA(address);
|
||||||
|
MemoryInfo memory_info{};
|
||||||
|
|
||||||
|
if (IsValidHandle(vma)) {
|
||||||
|
memory_info.base_address = vma->second.base;
|
||||||
|
memory_info.permission = static_cast<u32>(vma->second.permissions);
|
||||||
|
memory_info.size = vma->second.size;
|
||||||
|
memory_info.state = ToSvcMemoryState(vma->second.meminfo_state);
|
||||||
|
} else {
|
||||||
|
memory_info.base_address = 0;
|
||||||
|
memory_info.permission = static_cast<u32>(VMAPermission::None);
|
||||||
|
memory_info.size = 0;
|
||||||
|
memory_info.state = static_cast<u32>(MemoryState::Unmapped);
|
||||||
|
}
|
||||||
|
|
||||||
|
return memory_info;
|
||||||
|
}
|
||||||
|
|
||||||
ResultCode VMManager::MirrorMemory(VAddr dst_addr, VAddr src_addr, u64 size, MemoryState state) {
|
ResultCode VMManager::MirrorMemory(VAddr dst_addr, VAddr src_addr, u64 size, MemoryState state) {
|
||||||
const auto vma = FindVMA(src_addr);
|
const auto vma = FindVMA(src_addr);
|
||||||
|
|
||||||
|
|
|
@ -153,7 +153,7 @@ constexpr u32 ToSvcMemoryState(MemoryState state) {
|
||||||
struct MemoryInfo {
|
struct MemoryInfo {
|
||||||
u64 base_address;
|
u64 base_address;
|
||||||
u64 size;
|
u64 size;
|
||||||
u32 type;
|
u32 state;
|
||||||
u32 attributes;
|
u32 attributes;
|
||||||
u32 permission;
|
u32 permission;
|
||||||
u32 device_refcount;
|
u32 device_refcount;
|
||||||
|
@ -288,6 +288,14 @@ public:
|
||||||
|
|
||||||
ResultCode MirrorMemory(VAddr dst_addr, VAddr src_addr, u64 size, MemoryState state);
|
ResultCode MirrorMemory(VAddr dst_addr, VAddr src_addr, u64 size, MemoryState state);
|
||||||
|
|
||||||
|
/// Queries the memory manager for information about the given address.
|
||||||
|
///
|
||||||
|
/// @param address The address to query the memory manager about for information.
|
||||||
|
///
|
||||||
|
/// @return A MemoryInfo instance containing information about the given address.
|
||||||
|
///
|
||||||
|
MemoryInfo QueryMemory(VAddr address) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Scans all VMAs and updates the page table range of any that use the given vector as backing
|
* Scans all VMAs and updates the page table range of any that use the given vector as backing
|
||||||
* memory. This should be called after any operation that causes reallocation of the vector.
|
* memory. This should be called after any operation that causes reallocation of the vector.
|
||||||
|
|
Loading…
Reference in a new issue