2022-10-05 02:15:40 +02:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
|
|
|
#include "core/core.h"
|
|
|
|
#include "core/hle/kernel/k_process.h"
|
|
|
|
#include "core/hle/kernel/svc.h"
|
|
|
|
|
|
|
|
namespace Kernel::Svc {
|
|
|
|
|
2023-02-05 20:22:02 +01:00
|
|
|
Result QueryMemory(Core::System& system, uint64_t out_memory_info, PageInfo* out_page_info,
|
2022-10-05 02:15:40 +02:00
|
|
|
VAddr query_address) {
|
|
|
|
LOG_TRACE(Kernel_SVC,
|
2023-02-05 20:22:02 +01:00
|
|
|
"called, out_memory_info=0x{:016X}, "
|
2022-10-05 02:15:40 +02:00
|
|
|
"query_address=0x{:016X}",
|
2023-02-05 20:22:02 +01:00
|
|
|
out_memory_info, query_address);
|
2022-10-05 02:15:40 +02:00
|
|
|
|
2023-02-05 20:22:02 +01:00
|
|
|
// Query memory is just QueryProcessMemory on the current process.
|
|
|
|
return QueryProcessMemory(system, out_memory_info, out_page_info, CurrentProcess,
|
2022-10-05 02:15:40 +02:00
|
|
|
query_address);
|
|
|
|
}
|
|
|
|
|
2023-02-05 20:22:02 +01:00
|
|
|
Result QueryProcessMemory(Core::System& system, uint64_t out_memory_info, PageInfo* out_page_info,
|
|
|
|
Handle process_handle, uint64_t address) {
|
2022-10-05 02:15:40 +02:00
|
|
|
LOG_TRACE(Kernel_SVC, "called process=0x{:08X} address={:X}", process_handle, address);
|
|
|
|
const auto& handle_table = system.Kernel().CurrentProcess()->GetHandleTable();
|
|
|
|
KScopedAutoObject process = handle_table.GetObject<KProcess>(process_handle);
|
|
|
|
if (process.IsNull()) {
|
|
|
|
LOG_ERROR(Kernel_SVC, "Process handle does not exist, process_handle=0x{:08X}",
|
|
|
|
process_handle);
|
|
|
|
return ResultInvalidHandle;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto& memory{system.Memory()};
|
|
|
|
const auto memory_info{process->PageTable().QueryInfo(address).GetSvcMemoryInfo()};
|
|
|
|
|
2023-02-05 20:22:02 +01:00
|
|
|
memory.WriteBlock(out_memory_info, &memory_info, sizeof(memory_info));
|
|
|
|
|
|
|
|
//! This is supposed to be part of the QueryInfo call.
|
|
|
|
*out_page_info = {};
|
|
|
|
|
|
|
|
R_SUCCEED();
|
|
|
|
}
|
|
|
|
|
|
|
|
Result QueryMemory64(Core::System& system, uint64_t out_memory_info, PageInfo* out_page_info,
|
|
|
|
uint64_t address) {
|
|
|
|
R_RETURN(QueryMemory(system, out_memory_info, out_page_info, address));
|
|
|
|
}
|
2022-10-05 02:15:40 +02:00
|
|
|
|
2023-02-05 20:22:02 +01:00
|
|
|
Result QueryProcessMemory64(Core::System& system, uint64_t out_memory_info, PageInfo* out_page_info,
|
|
|
|
Handle process_handle, uint64_t address) {
|
|
|
|
R_RETURN(QueryProcessMemory(system, out_memory_info, out_page_info, process_handle, address));
|
|
|
|
}
|
|
|
|
|
|
|
|
Result QueryMemory64From32(Core::System& system, uint32_t out_memory_info, PageInfo* out_page_info,
|
|
|
|
uint32_t address) {
|
|
|
|
R_RETURN(QueryMemory(system, out_memory_info, out_page_info, address));
|
|
|
|
}
|
2022-10-05 02:15:40 +02:00
|
|
|
|
2023-02-05 20:22:02 +01:00
|
|
|
Result QueryProcessMemory64From32(Core::System& system, uint32_t out_memory_info,
|
|
|
|
PageInfo* out_page_info, Handle process_handle,
|
|
|
|
uint64_t address) {
|
|
|
|
R_RETURN(QueryProcessMemory(system, out_memory_info, out_page_info, process_handle, address));
|
2022-10-05 02:15:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Kernel::Svc
|