From cbecda2a27ee084edd44bc340b43cdbf130f7ea6 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Fri, 24 Jul 2020 08:50:31 -0700 Subject: [PATCH] kern: SvcQueryProcessMemory64, notification SvcBreaks --- .../source/svc/kern_svc_exception.cpp | 21 ++++++++++++++++--- .../source/svc/kern_svc_query_memory.cpp | 10 ++++++++- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/libraries/libmesosphere/source/svc/kern_svc_exception.cpp b/libraries/libmesosphere/source/svc/kern_svc_exception.cpp index d6a3222f9..77f24df2d 100644 --- a/libraries/libmesosphere/source/svc/kern_svc_exception.cpp +++ b/libraries/libmesosphere/source/svc/kern_svc_exception.cpp @@ -21,15 +21,30 @@ namespace ams::kern::svc { namespace { + void Break(ams::svc::BreakReason break_reason, uintptr_t address, size_t size) { + /* Log for debug that Break was called. */ + MESOSPHERE_LOG("%s: Break(%08x)\n", GetCurrentProcess().GetName(), static_cast(break_reason)); + /* If the current process is attached to debugger, notify it. */ + if (GetCurrentProcess().IsAttachedToDebugger()) { + MESOSPHERE_UNIMPLEMENTED(); + } + + /* If the break is only a notification, we're done. */ + if ((break_reason & ams::svc::BreakReason_NotificationOnlyFlag) != 0) { + return; + } + + /* TODO */ + MESOSPHERE_UNIMPLEMENTED(); + } } /* ============================= 64 ABI ============================= */ void Break64(ams::svc::BreakReason break_reason, ams::svc::Address arg, ams::svc::Size size) { - MESOSPHERE_LOG("%s: Break\n", GetCurrentProcess().GetName()); - MESOSPHERE_PANIC("Stubbed SvcBreak64 was called."); + return Break(break_reason, arg, size); } void ReturnFromException64(ams::Result result) { @@ -39,7 +54,7 @@ namespace ams::kern::svc { /* ============================= 64From32 ABI ============================= */ void Break64From32(ams::svc::BreakReason break_reason, ams::svc::Address arg, ams::svc::Size size) { - MESOSPHERE_PANIC("Stubbed SvcBreak64From32 was called."); + return Break(break_reason, arg, size); } void ReturnFromException64From32(ams::Result result) { diff --git a/libraries/libmesosphere/source/svc/kern_svc_query_memory.cpp b/libraries/libmesosphere/source/svc/kern_svc_query_memory.cpp index 93ecaae1b..f893322fe 100644 --- a/libraries/libmesosphere/source/svc/kern_svc_query_memory.cpp +++ b/libraries/libmesosphere/source/svc/kern_svc_query_memory.cpp @@ -57,7 +57,15 @@ namespace ams::kern::svc { } Result QueryProcessMemory64(KUserPointer out_memory_info, ams::svc::PageInfo *out_page_info, ams::svc::Handle process_handle, uint64_t address) { - MESOSPHERE_PANIC("Stubbed SvcQueryProcessMemory64 was called."); + /* 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(); } /* ============================= 64From32 ABI ============================= */