From 9decdbabab9998a557541b18d3af6f819f5570b7 Mon Sep 17 00:00:00 2001
From: comex <comexk@gmail.com>
Date: Mon, 20 Jun 2022 17:39:10 -0700
Subject: [PATCH 1/3] Support InfoType_MesosphereCurrentProcess

---
 src/core/hle/kernel/svc.cpp | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp
index 2ff6d5fa6d..0aa068f1d4 100644
--- a/src/core/hle/kernel/svc.cpp
+++ b/src/core/hle/kernel/svc.cpp
@@ -692,6 +692,9 @@ static ResultCode GetInfo(Core::System& system, u64* result, u64 info_id, Handle
         // 6.0.0+
         TotalPhysicalMemoryAvailableWithoutSystemResource = 21,
         TotalPhysicalMemoryUsedWithoutSystemResource = 22,
+
+        // Homebrew only
+        MesosphereCurrentProcess = 65001,
     };
 
     const auto info_id_type = static_cast<GetInfoType>(info_id);
@@ -914,6 +917,17 @@ static ResultCode GetInfo(Core::System& system, u64* result, u64 info_id, Handle
         *result = system.Kernel().CurrentScheduler()->GetIdleThread()->GetCpuTime();
         return ResultSuccess;
     }
+    case GetInfoType::MesosphereCurrentProcess: {
+        R_UNLESS(handle == InvalidHandle, ResultInvalidHandle);
+        R_UNLESS(info_sub_id == 0, ResultInvalidCombination);
+
+        KProcess* const current_process = system.Kernel().CurrentProcess();
+        Handle process_handle{};
+        R_TRY(current_process->GetHandleTable().Add(&process_handle, current_process));
+
+        *result = process_handle;
+        return ResultSuccess;
+    }
     default:
         LOG_ERROR(Kernel_SVC, "Unimplemented svcGetInfo id=0x{:016X}", info_id);
         return ResultInvalidEnumValue;

From 593f978ad22d7e2a618d5966299446af5390ace0 Mon Sep 17 00:00:00 2001
From: comex <comexk@gmail.com>
Date: Sat, 25 Jun 2022 18:00:29 -0700
Subject: [PATCH 2/3] Update src/core/hle/kernel/svc.cpp

Co-authored-by: liamwhite <liamwhite@users.noreply.github.com>
---
 src/core/hle/kernel/svc.cpp | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp
index 0aa068f1d4..fdfd69ebdc 100644
--- a/src/core/hle/kernel/svc.cpp
+++ b/src/core/hle/kernel/svc.cpp
@@ -917,17 +917,25 @@ static ResultCode GetInfo(Core::System& system, u64* result, u64 info_id, Handle
         *result = system.Kernel().CurrentScheduler()->GetIdleThread()->GetCpuTime();
         return ResultSuccess;
     }
-    case GetInfoType::MesosphereCurrentProcess: {
+        // Verify the input handle is invalid.
         R_UNLESS(handle == InvalidHandle, ResultInvalidHandle);
+
+        // Verify the sub-type is valid.
         R_UNLESS(info_sub_id == 0, ResultInvalidCombination);
 
-        KProcess* const current_process = system.Kernel().CurrentProcess();
-        Handle process_handle{};
-        R_TRY(current_process->GetHandleTable().Add(&process_handle, current_process));
+        // Get the handle table.
+        KProcess* current_process = system.Kernel().CurrentProcess();
+        KHandleTable& handle_table = current_process->GetHandleTable();
 
-        *result = process_handle;
+        // Get a new handle for the current process.
+        Handle tmp;
+        R_TRY(handle_table.Add(&tmp, current_process));
+
+        // Set the output.
+        *result = tmp;
+        
+        // We succeeded.
         return ResultSuccess;
-    }
     default:
         LOG_ERROR(Kernel_SVC, "Unimplemented svcGetInfo id=0x{:016X}", info_id);
         return ResultInvalidEnumValue;

From 0c3a934b6e6e8d6d0874dff5c92423b81fce9e3e Mon Sep 17 00:00:00 2001
From: comex <comexk@gmail.com>
Date: Sat, 25 Jun 2022 18:01:56 -0700
Subject: [PATCH 3/3] Re-add missing `case` and braces, and trim whitespace

---
 src/core/hle/kernel/svc.cpp | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp
index fdfd69ebdc..72272a34e8 100644
--- a/src/core/hle/kernel/svc.cpp
+++ b/src/core/hle/kernel/svc.cpp
@@ -917,6 +917,7 @@ static ResultCode GetInfo(Core::System& system, u64* result, u64 info_id, Handle
         *result = system.Kernel().CurrentScheduler()->GetIdleThread()->GetCpuTime();
         return ResultSuccess;
     }
+    case GetInfoType::MesosphereCurrentProcess: {
         // Verify the input handle is invalid.
         R_UNLESS(handle == InvalidHandle, ResultInvalidHandle);
 
@@ -933,9 +934,10 @@ static ResultCode GetInfo(Core::System& system, u64* result, u64 info_id, Handle
 
         // Set the output.
         *result = tmp;
-        
+
         // We succeeded.
         return ResultSuccess;
+    }
     default:
         LOG_ERROR(Kernel_SVC, "Unimplemented svcGetInfo id=0x{:016X}", info_id);
         return ResultInvalidEnumValue;