From 22ceaca2f415b962416637db9fff9782575746ce Mon Sep 17 00:00:00 2001
From: Fernando Sahmkow <fsahmkow27@gmail.com>
Date: Thu, 18 Jun 2020 18:15:19 -0400
Subject: [PATCH] SVC: Add GetThreadPriority32 & SetThreadPriority32

---
 src/core/hle/kernel/svc.cpp    | 14 ++++++++++++--
 src/core/hle/kernel/svc_wrap.h | 18 ++++++++++++++++++
 2 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp
index 013ae9e34b..5674d95583 100644
--- a/src/core/hle/kernel/svc.cpp
+++ b/src/core/hle/kernel/svc.cpp
@@ -1135,6 +1135,10 @@ static ResultCode SetThreadPriority(Core::System& system, Handle handle, u32 pri
     return RESULT_SUCCESS;
 }
 
+static ResultCode SetThreadPriority32(Core::System& system, Handle handle, u32 priority) {
+  return SetThreadPriority(system, handle, priority);
+}
+
 /// Get which CPU core is executing the current thread
 static u32 GetCurrentProcessorNumber(Core::System& system) {
     LOG_TRACE(Kernel_SVC, "called");
@@ -1933,6 +1937,12 @@ static ResultCode SetThreadCoreMask(Core::System& system, Handle thread_handle,
     return thread->SetCoreAndAffinityMask(core, affinity_mask);
 }
 
+static ResultCode SetThreadCoreMask32(Core::System& system, Handle thread_handle, u32 core,
+                                    u32 affinity_mask_low, u32 affinity_mask_high) {
+    const u64 affinity_mask = static_cast<u64>(affinity_mask_low) | (static_cast<u64>(affinity_mask_high) << 32);
+    return SetThreadCoreMask(system, thread_handle, core, affinity_mask);
+}
+
 static ResultCode CreateEvent(Core::System& system, Handle* write_handle, Handle* read_handle) {
     LOG_DEBUG(Kernel_SVC, "called");
 
@@ -2206,9 +2216,9 @@ static const FunctionDef SVC_Table_32[] = {
     {0x0a, nullptr, "ExitThread32"},
     {0x0b, nullptr, "SleepThread32"},
     {0x0c, SvcWrap32<GetThreadPriority32>, "GetThreadPriority32"},
-    {0x0d, nullptr, "SetThreadPriority32"},
+    {0x0d, SvcWrap32<SetThreadPriority32>, "SetThreadPriority32"},
     {0x0e, nullptr, "GetThreadCoreMask32"},
-    {0x0f, nullptr, "SetThreadCoreMask32"},
+    {0x0f, SvcWrap32<SetThreadCoreMask32>, "SetThreadCoreMask32"},
     {0x10, nullptr, "GetCurrentProcessorNumber32"},
     {0x11, nullptr, "SignalEvent32"},
     {0x12, nullptr, "ClearEvent32"},
diff --git a/src/core/hle/kernel/svc_wrap.h b/src/core/hle/kernel/svc_wrap.h
index 7d735e3fa9..fd4edba2af 100644
--- a/src/core/hle/kernel/svc_wrap.h
+++ b/src/core/hle/kernel/svc_wrap.h
@@ -399,6 +399,24 @@ void SvcWrap32(Core::System& system) {
     func(system, static_cast<u32>(Param(system, 0)), static_cast<s32>(Param(system, 1)));
 }
 
+// Used by SetThreadPriority32
+template <ResultCode func(Core::System&, Handle, u32)>
+void SvcWrap32(Core::System& system) {
+    const u32 retval =
+        func(system, static_cast<Handle>(Param(system, 0)), static_cast<u32>(Param(system, 1))).raw;
+    FuncReturn(system, retval);
+}
+
+// Used by SetThreadCoreMask32
+template <ResultCode func(Core::System&, Handle, u32, u32, u32)>
+void SvcWrap32(Core::System& system) {
+    const u32 retval =
+        func(system, static_cast<Handle>(Param(system, 0)), static_cast<u32>(Param(system, 1)),
+             static_cast<u32>(Param(system, 2)), static_cast<u32>(Param(system, 3)))
+            .raw;
+    FuncReturn(system, retval);
+}
+
 // Used by SendSyncRequest32
 template <ResultCode func(Core::System&, u32)>
 void SvcWrap32(Core::System& system) {