1
0
Fork 0
mirror of https://github.com/Atmosphere-NX/Atmosphere.git synced 2024-11-12 15:06:41 +00:00

kern: QueryMemory64From32, QueryProcessMemory64From32

This commit is contained in:
Michael Scire 2020-07-28 18:10:43 -07:00 committed by SciresM
parent 7cf0432569
commit 94a170c437

View file

@ -35,7 +35,39 @@ namespace ams::kern::svc {
return ResultSuccess();
}
Result QueryMemory(ams::svc::MemoryInfo *out_memory_info, ams::svc::PageInfo *out_page_info, uintptr_t address) {
template<typename T>
Result QueryProcessMemory(KUserPointer<T *> out_memory_info, ams::svc::PageInfo *out_page_info, ams::svc::Handle process_handle, uint64_t address) {
/* Get an ams::svc::MemoryInfo for the region. */
ams::svc::MemoryInfo info = {};
R_TRY(QueryProcessMemory(std::addressof(info), out_page_info, process_handle, address));
/* Invoke the implementation. */
if constexpr (std::same_as<T, ams::svc::MemoryInfo>) {
R_TRY(out_memory_info.CopyFrom(std::addressof(info)));
} else {
/* Convert the info. */
T converted_info = {};
static_assert(std::same_as<decltype(T{}.addr), decltype(ams::svc::MemoryInfo{}.addr)>);
static_assert(std::same_as<decltype(T{}.size), decltype(ams::svc::MemoryInfo{}.size)>);
converted_info.addr = info.addr;
converted_info.size = info.size;
converted_info.state = info.state;
converted_info.attr = info.attr;
converted_info.perm = info.perm;
converted_info.ipc_refcount = info.ipc_refcount;
converted_info.device_refcount = info.device_refcount;
/* Invoke. */
R_TRY(out_memory_info.CopyFrom(std::addressof(converted_info)));
}
return ResultSuccess();
}
template<typename T>
Result QueryMemory(KUserPointer<T *> out_memory_info, ams::svc::PageInfo *out_page_info, uintptr_t address) {
/* Query memory is just QueryProcessMemory on the current process. */
return QueryProcessMemory(out_memory_info, out_page_info, ams::svc::PseudoHandle::CurrentProcess, address);
}
@ -45,37 +77,21 @@ namespace ams::kern::svc {
/* ============================= 64 ABI ============================= */
Result QueryMemory64(KUserPointer<ams::svc::lp64::MemoryInfo *> out_memory_info, ams::svc::PageInfo *out_page_info, ams::svc::Address address) {
/* Get an ams::svc::MemoryInfo for the region. */
ams::svc::MemoryInfo info = {};
R_TRY(QueryMemory(std::addressof(info), out_page_info, address));
/* Try to copy to userspace. In the 64-bit case, ams::svc::lp64::MemoryInfo is the same as ams::svc::MemoryInfo. */
static_assert(sizeof(ams::svc::MemoryInfo) == sizeof(ams::svc::lp64::MemoryInfo));
R_TRY(out_memory_info.CopyFrom(std::addressof(info)));
return ResultSuccess();
return QueryMemory(out_memory_info, out_page_info, address);
}
Result QueryProcessMemory64(KUserPointer<ams::svc::lp64::MemoryInfo *> out_memory_info, ams::svc::PageInfo *out_page_info, ams::svc::Handle process_handle, uint64_t address) {
/* Get an ams::svc::MemoryInfo for the region. */
ams::svc::MemoryInfo info = {};
R_TRY(QueryProcessMemory(std::addressof(info), out_page_info, process_handle, address));
/* Try to copy to userspace. In the 64-bit case, ams::svc::lp64::MemoryInfo is the same as ams::svc::MemoryInfo. */
static_assert(sizeof(ams::svc::MemoryInfo) == sizeof(ams::svc::lp64::MemoryInfo));
R_TRY(out_memory_info.CopyFrom(std::addressof(info)));
return ResultSuccess();
return QueryProcessMemory(out_memory_info, out_page_info, process_handle, address);
}
/* ============================= 64From32 ABI ============================= */
Result QueryMemory64From32(KUserPointer<ams::svc::ilp32::MemoryInfo *> out_memory_info, ams::svc::PageInfo *out_page_info, ams::svc::Address address) {
MESOSPHERE_PANIC("Stubbed SvcQueryMemory64From32 was called.");
return QueryMemory(out_memory_info, out_page_info, address);
}
Result QueryProcessMemory64From32(KUserPointer<ams::svc::ilp32::MemoryInfo *> out_memory_info, ams::svc::PageInfo *out_page_info, ams::svc::Handle process_handle, uint64_t address) {
MESOSPHERE_PANIC("Stubbed SvcQueryProcessMemory64From32 was called.");
return QueryProcessMemory(out_memory_info, out_page_info, process_handle, address);
}
}