From 1e0010e8aa7c923bc751e1cfb77a37ce339b2657 Mon Sep 17 00:00:00 2001 From: FearlessTobi Date: Tue, 27 Feb 2024 19:42:47 +0100 Subject: [PATCH] pm: Migrate to cmif serialization --- src/core/hle/service/pm/boot_mode_service.cpp | 18 ++--- src/core/hle/service/pm/boot_mode_service.h | 6 +- .../hle/service/pm/debug_monitor_service.cpp | 67 ++++++------------- .../hle/service/pm/debug_monitor_service.h | 11 +-- .../hle/service/pm/information_service.cpp | 39 ++++------- src/core/hle/service/pm/information_service.h | 6 +- src/core/hle/service/pm/pm_types.h | 24 +++++-- src/core/hle/service/pm/shell_service.cpp | 9 ++- src/core/hle/service/pm/shell_service.h | 3 +- 9 files changed, 84 insertions(+), 99 deletions(-) diff --git a/src/core/hle/service/pm/boot_mode_service.cpp b/src/core/hle/service/pm/boot_mode_service.cpp index ab22f20411..d9b8b4d9a6 100644 --- a/src/core/hle/service/pm/boot_mode_service.cpp +++ b/src/core/hle/service/pm/boot_mode_service.cpp @@ -1,33 +1,33 @@ // SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later +#include "core/hle/service/cmif_serialization.h" #include "core/hle/service/pm/boot_mode_service.h" namespace Service::PM { BootModeService::BootModeService(Core::System& system_) : ServiceFramework{system_, "pm:bm"} { static const FunctionInfo functions[] = { - {0, &BootModeService::GetBootMode, "GetBootMode"}, - {1, &BootModeService::SetMaintenanceBoot, "SetMaintenanceBoot"}, + {0, C<&BootModeService::GetBootMode>, "GetBootMode"}, + {1, C<&BootModeService::SetMaintenanceBoot>, "SetMaintenanceBoot"}, }; RegisterHandlers(functions); } -void BootModeService::GetBootMode(HLERequestContext& ctx) { +Result BootModeService::GetBootMode(Out out_boot_mode) { LOG_DEBUG(Service_PM, "called"); - IPC::ResponseBuilder rb{ctx, 3}; - rb.Push(ResultSuccess); - rb.PushEnum(boot_mode); + *out_boot_mode = static_cast(boot_mode); + + R_SUCCEED(); } -void BootModeService::SetMaintenanceBoot(HLERequestContext& ctx) { +Result BootModeService::SetMaintenanceBoot() { LOG_DEBUG(Service_PM, "called"); boot_mode = BootMode::Maintenance; - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); + R_SUCCEED(); } } // namespace Service::PM diff --git a/src/core/hle/service/pm/boot_mode_service.h b/src/core/hle/service/pm/boot_mode_service.h index 81d27baba3..bac57fea72 100644 --- a/src/core/hle/service/pm/boot_mode_service.h +++ b/src/core/hle/service/pm/boot_mode_service.h @@ -3,7 +3,7 @@ #pragma once -#include "core/hle/service/ipc_helpers.h" +#include "core/hle/service/cmif_types.h" #include "core/hle/service/pm/pm_types.h" #include "core/hle/service/service.h" @@ -14,8 +14,8 @@ public: explicit BootModeService(Core::System& system_); private: - void GetBootMode(HLERequestContext& ctx); - void SetMaintenanceBoot(HLERequestContext& ctx); + Result GetBootMode(Out out_boot_mode); + Result SetMaintenanceBoot(); BootMode boot_mode = BootMode::Normal; }; diff --git a/src/core/hle/service/pm/debug_monitor_service.cpp b/src/core/hle/service/pm/debug_monitor_service.cpp index 9fec74d39e..bdaf2a4de7 100644 --- a/src/core/hle/service/pm/debug_monitor_service.cpp +++ b/src/core/hle/service/pm/debug_monitor_service.cpp @@ -1,8 +1,8 @@ // SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later +#include "core/hle/service/cmif_serialization.h" #include "core/hle/service/pm/debug_monitor_service.h" -#include "core/hle/service/pm/pm_types.h" namespace Service::PM { @@ -10,14 +10,14 @@ DebugMonitorService::DebugMonitorService(Core::System& system_) : ServiceFramework{system_, "pm:dmnt"} { // clang-format off static const FunctionInfo functions[] = { - {0, nullptr, "GetJitDebugProcessIdList"}, + {0, nullptr, "GetExceptionProcessIdList"}, {1, nullptr, "StartProcess"}, - {2, &DebugMonitorService::GetProcessId, "GetProcessId"}, + {2, C<&DebugMonitorService::GetProcessId>, "GetProcessId"}, {3, nullptr, "HookToCreateProcess"}, - {4, &DebugMonitorService::GetApplicationProcessId, "GetApplicationProcessId"}, + {4, C<&DebugMonitorService::GetApplicationProcessId>, "GetApplicationProcessId"}, {5, nullptr, "HookToCreateApplicationProgress"}, {6, nullptr, "ClearHook"}, - {65000, &DebugMonitorService::AtmosphereGetProcessInfo, "AtmosphereGetProcessInfo"}, + {65000, C<&DebugMonitorService::AtmosphereGetProcessInfo>, "AtmosphereGetProcessInfo"}, {65001, nullptr, "AtmosphereGetCurrentLimitInfo"}, }; // clang-format on @@ -25,61 +25,38 @@ DebugMonitorService::DebugMonitorService(Core::System& system_) RegisterHandlers(functions); } -void DebugMonitorService::GetProcessId(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto program_id = rp.PopRaw(); - +Result DebugMonitorService::GetProcessId(Out out_process_id, u64 program_id) { LOG_DEBUG(Service_PM, "called, program_id={:016X}", program_id); auto list = kernel.GetProcessList(); auto process = SearchProcessList(list, [program_id](auto& p) { return p->GetProgramId() == program_id; }); - if (process.IsNull()) { - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultProcessNotFound); - return; - } + R_UNLESS(!process.IsNull(), ResultProcessNotFound); - IPC::ResponseBuilder rb{ctx, 4}; - rb.Push(ResultSuccess); - rb.Push(process->GetProcessId()); + *out_process_id = ProcessId(process->GetProcessId()); + + R_SUCCEED(); } -void DebugMonitorService::GetApplicationProcessId(HLERequestContext& ctx) { +Result DebugMonitorService::GetApplicationProcessId(Out out_process_id) { LOG_DEBUG(Service_PM, "called"); auto list = kernel.GetProcessList(); - GetApplicationPidGeneric(ctx, list); + R_RETURN(GetApplicationPidGeneric(out_process_id, list)); } -void DebugMonitorService::AtmosphereGetProcessInfo(HLERequestContext& ctx) { +Result DebugMonitorService::AtmosphereGetProcessInfo( + OutCopyHandle out_process_handle, Out out_location, + Out out_status, ProcessId process_id) { // https://github.com/Atmosphere-NX/Atmosphere/blob/master/stratosphere/pm/source/impl/pm_process_manager.cpp#L614 // This implementation is incomplete; only a handle to the process is returned. - IPC::RequestParser rp{ctx}; - const auto pid = rp.PopRaw(); + const auto pid = process_id.pid; LOG_WARNING(Service_PM, "(Partial Implementation) called, pid={:016X}", pid); auto list = kernel.GetProcessList(); auto process = SearchProcessList(list, [pid](auto& p) { return p->GetProcessId() == pid; }); - - if (process.IsNull()) { - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultProcessNotFound); - return; - } - - struct ProgramLocation { - u64 program_id; - u8 storage_id; - }; - static_assert(sizeof(ProgramLocation) == 0x10, "ProgramLocation has an invalid size"); - - struct OverrideStatus { - u64 keys_held; - u64 flags; - }; - static_assert(sizeof(OverrideStatus) == 0x10, "OverrideStatus has an invalid size"); + R_UNLESS(!process.IsNull(), ResultProcessNotFound); OverrideStatus override_status{}; ProgramLocation program_location{ @@ -87,11 +64,11 @@ void DebugMonitorService::AtmosphereGetProcessInfo(HLERequestContext& ctx) { .storage_id = 0, }; - IPC::ResponseBuilder rb{ctx, 10, 1}; - rb.Push(ResultSuccess); - rb.PushCopyObjects(*process); - rb.PushRaw(program_location); - rb.PushRaw(override_status); + *out_process_handle = process.GetPointerUnsafe(); + *out_location = program_location; + *out_status = override_status; + + R_SUCCEED(); } } // namespace Service::PM diff --git a/src/core/hle/service/pm/debug_monitor_service.h b/src/core/hle/service/pm/debug_monitor_service.h index 4855a98580..5c65b7c85b 100644 --- a/src/core/hle/service/pm/debug_monitor_service.h +++ b/src/core/hle/service/pm/debug_monitor_service.h @@ -3,7 +3,8 @@ #pragma once -#include "core/hle/service/ipc_helpers.h" +#include "core/hle/service/cmif_types.h" +#include "core/hle/service/pm/pm_types.h" #include "core/hle/service/service.h" namespace Service::PM { @@ -13,8 +14,10 @@ public: explicit DebugMonitorService(Core::System& system_); private: - void GetProcessId(HLERequestContext& ctx); - void GetApplicationProcessId(HLERequestContext& ctx); - void AtmosphereGetProcessInfo(HLERequestContext& ctx); + Result GetProcessId(Out out_process_id, u64 program_id); + Result GetApplicationProcessId(Out out_process_id); + Result AtmosphereGetProcessInfo(OutCopyHandle out_process_handle, + Out out_location, + Out out_status, ProcessId process_id); }; } // namespace Service::PM diff --git a/src/core/hle/service/pm/information_service.cpp b/src/core/hle/service/pm/information_service.cpp index 8f418a50c9..f3f2f112cc 100644 --- a/src/core/hle/service/pm/information_service.cpp +++ b/src/core/hle/service/pm/information_service.cpp @@ -1,6 +1,7 @@ // SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later +#include "core/hle/service/cmif_serialization.h" #include "core/hle/service/pm/information_service.h" #include "core/hle/service/pm/pm_types.h" @@ -9,54 +10,40 @@ namespace Service::PM { InformationService::InformationService(Core::System& system_) : ServiceFramework{system_, "pm:info"} { static const FunctionInfo functions[] = { - {0, &InformationService::GetProgramId, "GetProgramId"}, - {65000, &InformationService::AtmosphereGetProcessId, "AtmosphereGetProcessId"}, + {0, C<&InformationService::GetProgramId>, "GetProgramId"}, + {65000, C<&InformationService::AtmosphereGetProcessId>, "AtmosphereGetProcessId"}, {65001, nullptr, "AtmosphereHasLaunchedProgram"}, {65002, nullptr, "AtmosphereGetProcessInfo"}, }; RegisterHandlers(functions); } -void InformationService::GetProgramId(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto process_id = rp.PopRaw(); - +Result InformationService::GetProgramId(Out out_program_id, u64 process_id) { LOG_DEBUG(Service_PM, "called, process_id={:016X}", process_id); auto list = kernel.GetProcessList(); auto process = SearchProcessList(list, [process_id](auto& p) { return p->GetProcessId() == process_id; }); - if (process.IsNull()) { - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultProcessNotFound); - return; - } + R_UNLESS(!process.IsNull(), ResultProcessNotFound); - IPC::ResponseBuilder rb{ctx, 4}; - rb.Push(ResultSuccess); - rb.Push(process->GetProgramId()); + *out_program_id = process->GetProgramId(); + + R_SUCCEED(); } -void InformationService::AtmosphereGetProcessId(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto program_id = rp.PopRaw(); - +Result InformationService::AtmosphereGetProcessId(Out out_process_id, u64 program_id) { LOG_DEBUG(Service_PM, "called, program_id={:016X}", program_id); auto list = system.Kernel().GetProcessList(); auto process = SearchProcessList(list, [program_id](auto& p) { return p->GetProgramId() == program_id; }); - if (process.IsNull()) { - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultProcessNotFound); - return; - } + R_UNLESS(!process.IsNull(), ResultProcessNotFound); - IPC::ResponseBuilder rb{ctx, 4}; - rb.Push(ResultSuccess); - rb.Push(process->GetProcessId()); + *out_process_id = ProcessId(process->GetProcessId()); + + R_SUCCEED(); } } // namespace Service::PM diff --git a/src/core/hle/service/pm/information_service.h b/src/core/hle/service/pm/information_service.h index 82d65302e2..06e7f785a7 100644 --- a/src/core/hle/service/pm/information_service.h +++ b/src/core/hle/service/pm/information_service.h @@ -3,7 +3,7 @@ #pragma once -#include "core/hle/service/ipc_helpers.h" +#include "core/hle/service/cmif_types.h" #include "core/hle/service/service.h" namespace Service::PM { @@ -13,8 +13,8 @@ public: explicit InformationService(Core::System& system_); private: - void GetProgramId(HLERequestContext& ctx); - void AtmosphereGetProcessId(HLERequestContext& ctx); + Result GetProgramId(Out out_program_id, u64 process_id); + Result AtmosphereGetProcessId(Out out_process_id, u64 program_id); }; } // namespace Service::PM diff --git a/src/core/hle/service/pm/pm_types.h b/src/core/hle/service/pm/pm_types.h index 1785e9d457..04c9650d2e 100644 --- a/src/core/hle/service/pm/pm_types.h +++ b/src/core/hle/service/pm/pm_types.h @@ -7,7 +7,7 @@ #include "core/hle/kernel/k_process.h" #include "core/hle/kernel/kernel.h" #include "core/hle/result.h" -#include "core/hle/service/ipc_helpers.h" +#include "core/hle/service/cmif_types.h" namespace Service::PM { @@ -26,6 +26,18 @@ enum class BootMode { SafeMode = 2, }; +struct ProgramLocation { + u64 program_id; + u8 storage_id; +}; +static_assert(sizeof(ProgramLocation) == 0x10, "ProgramLocation has an invalid size"); + +struct OverrideStatus { + u64 keys_held; + u64 flags; +}; +static_assert(sizeof(OverrideStatus) == 0x10, "OverrideStatus has an invalid size"); + using ProcessList = std::list>; template @@ -40,12 +52,14 @@ static inline Kernel::KScopedAutoObject SearchProcessList( return iter->GetPointerUnsafe(); } -static inline void GetApplicationPidGeneric(HLERequestContext& ctx, ProcessList& process_list) { +static inline Result GetApplicationPidGeneric(Out out_process_id, + ProcessList& process_list) { auto process = SearchProcessList(process_list, [](auto& p) { return p->IsApplication(); }); - IPC::ResponseBuilder rb{ctx, 4}; - rb.Push(ResultSuccess); - rb.Push(process.IsNull() ? NO_PROCESS_FOUND_PID : process->GetProcessId()); + *out_process_id = + process.IsNull() ? ProcessId(NO_PROCESS_FOUND_PID) : ProcessId(process->GetProcessId()); + + R_SUCCEED(); } } // namespace Service::PM diff --git a/src/core/hle/service/pm/shell_service.cpp b/src/core/hle/service/pm/shell_service.cpp index e40903664c..4e84c14e39 100644 --- a/src/core/hle/service/pm/shell_service.cpp +++ b/src/core/hle/service/pm/shell_service.cpp @@ -1,6 +1,7 @@ // SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later +#include "core/hle/service/cmif_serialization.h" #include "core/hle/service/pm/pm_types.h" #include "core/hle/service/pm/shell_service.h" @@ -15,7 +16,7 @@ ShellService::ShellService(Core::System& system_) : ServiceFramework{system_, "p {3, nullptr, "GetProcessEventHandle"}, {4, nullptr, "GetProcessEventInfo"}, {5, nullptr, "NotifyBootFinished"}, - {6, &ShellService::GetApplicationProcessIdForShell, "GetApplicationProcessIdForShell"}, + {6, C<&ShellService::GetApplicationProcessIdForShell>, "GetApplicationProcessIdForShell"}, {7, nullptr, "BoostSystemMemoryResourceLimit"}, {8, nullptr, "BoostApplicationThreadResourceLimit"}, {9, nullptr, "GetBootFinishedEventHandle"}, @@ -25,10 +26,12 @@ ShellService::ShellService(Core::System& system_) : ServiceFramework{system_, "p RegisterHandlers(functions); } -void ShellService::GetApplicationProcessIdForShell(HLERequestContext& ctx) { +Result ShellService::GetApplicationProcessIdForShell(Out out_process_id) { LOG_DEBUG(Service_PM, "called"); + auto list = kernel.GetProcessList(); - GetApplicationPidGeneric(ctx, list); + + R_RETURN(GetApplicationPidGeneric(out_process_id, list)); } } // namespace Service::PM diff --git a/src/core/hle/service/pm/shell_service.h b/src/core/hle/service/pm/shell_service.h index 81058abfd5..1f7473e89e 100644 --- a/src/core/hle/service/pm/shell_service.h +++ b/src/core/hle/service/pm/shell_service.h @@ -3,6 +3,7 @@ #pragma once +#include "core/hle/service/cmif_types.h" #include "core/hle/service/ipc_helpers.h" #include "core/hle/service/service.h" @@ -13,7 +14,7 @@ public: explicit ShellService(Core::System& system_); private: - void GetApplicationProcessIdForShell(HLERequestContext& ctx); + Result GetApplicationProcessIdForShell(Out out_process_id); }; } // namespace Service::PM