From a7564cf303d1e97d801f8f3f4efc0f1bea493ad7 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Wed, 17 Mar 2021 17:48:30 -0700 Subject: [PATCH] kern: add extension InfoType for retrieving current process handle. --- .../source/svc/kern_svc_info.cpp | 19 +++++++++++++++++++ .../include/vapours/svc/svc_types_common.hpp | 1 + 2 files changed, 20 insertions(+) diff --git a/libraries/libmesosphere/source/svc/kern_svc_info.cpp b/libraries/libmesosphere/source/svc/kern_svc_info.cpp index 60a72fbc0..308871fa0 100644 --- a/libraries/libmesosphere/source/svc/kern_svc_info.cpp +++ b/libraries/libmesosphere/source/svc/kern_svc_info.cpp @@ -276,6 +276,25 @@ namespace ams::kern::svc { } } break; + case ams::svc::InfoType_MesosphereCurrentProcess: + { + /* Verify the input handle is invalid. */ + R_UNLESS(handle == ams::svc::InvalidHandle, svc::ResultInvalidHandle()); + + /* Verify the sub-type is valid. */ + R_UNLESS(info_subtype == 0, svc::ResultInvalidCombination()); + + /* Get the handle table. */ + KHandleTable &handle_table = GetCurrentProcess().GetHandleTable(); + + /* Get a new handle for the current process. */ + ams::svc::Handle tmp; + R_TRY(handle_table.Add(std::addressof(tmp), GetCurrentProcessPointer())); + + /* Set the output. */ + *out = tmp; + } + break; default: { /* For debug, log the invalid info call. */ diff --git a/libraries/libvapours/include/vapours/svc/svc_types_common.hpp b/libraries/libvapours/include/vapours/svc/svc_types_common.hpp index b533d4e03..069518989 100644 --- a/libraries/libvapours/include/vapours/svc/svc_types_common.hpp +++ b/libraries/libvapours/include/vapours/svc/svc_types_common.hpp @@ -159,6 +159,7 @@ namespace ams::svc { InfoType_FreeThreadCount = 24, InfoType_MesosphereMeta = 65000, + InfoType_MesosphereCurrentProcess = 65001, InfoType_ThreadTickCount = 0xF0000002, };