From 266c1c802039548b5dc242c8c2312289918b323f Mon Sep 17 00:00:00 2001 From: bunnei Date: Mon, 23 Oct 2017 00:15:45 -0400 Subject: svc: Implement GetThreadId and GetProcessId. --- src/core/hle/function_wrappers.h | 8 ++++++++ src/core/hle/svc.cpp | 31 +++++++++++++++++++++++++++++-- 2 files changed, 37 insertions(+), 2 deletions(-) (limited to 'src/core/hle') diff --git a/src/core/hle/function_wrappers.h b/src/core/hle/function_wrappers.h index 3e886fdba..abc2b96a8 100644 --- a/src/core/hle/function_wrappers.h +++ b/src/core/hle/function_wrappers.h @@ -161,6 +161,14 @@ void Wrap() { FuncReturn(retval); } +template +void Wrap() { + u32 param_1 = 0; + u32 retval = func(¶m_1, PARAM(1)).raw; + Core::CPU().SetReg(1, param_1); + FuncReturn(retval); +} + template void Wrap() { FuncReturn(func(PARAM(0)).raw); diff --git a/src/core/hle/svc.cpp b/src/core/hle/svc.cpp index 0401f763b..4b5c1dff3 100644 --- a/src/core/hle/svc.cpp +++ b/src/core/hle/svc.cpp @@ -71,6 +71,33 @@ static ResultCode SendSyncRequest(Kernel::Handle handle) { return session->SendSyncRequest(Kernel::GetCurrentThread()); } +/// Get the ID for the specified thread. +static ResultCode GetThreadId(u32* thread_id, Kernel::Handle handle) { + LOG_TRACE(Kernel_SVC, "called thread=0x%08X", handle); + + const SharedPtr thread = Kernel::g_handle_table.Get(handle); + if (thread == nullptr) { + return ERR_INVALID_HANDLE; + } + + *thread_id = thread->GetThreadId(); + return RESULT_SUCCESS; +} + +/// Get the ID of the specified process +static ResultCode GetProcessId(u32* process_id, Kernel::Handle process_handle) { + LOG_TRACE(Kernel_SVC, "called process=0x%08X", process_handle); + + const SharedPtr process = + Kernel::g_handle_table.Get(process_handle); + if (process == nullptr) { + return ERR_INVALID_HANDLE; + } + + *process_id = process->process_id; + return RESULT_SUCCESS; +} + /// Break program execution static void Break(u64 unk_0, u64 unk_1, u64 unk_2) { LOG_CRITICAL(Debug_Emulated, "Emulated program broke execution!"); @@ -213,8 +240,8 @@ static const FunctionDef SVC_Table[] = { {0x21, HLE::Wrap, "svcSendSyncRequest"}, {0x22, nullptr, "svcSendSyncRequestWithUserBuffer"}, {0x23, nullptr, "svcSendAsyncRequestWithUserBuffer"}, - {0x24, nullptr, "svcGetProcessId"}, - {0x25, nullptr, "svcGetThreadId"}, + {0x24, HLE::Wrap, "svcGetProcessId"}, + {0x25, HLE::Wrap, "svcGetThreadId"}, {0x26, HLE::Wrap, "svcBreak"}, {0x27, HLE::Wrap, "svcOutputDebugString"}, {0x28, nullptr, "svcReturnFromException"}, -- cgit v1.2.3