pm: Migrate to cmif serialization

This commit is contained in:
FearlessTobi 2024-02-27 19:42:47 +01:00
parent a05c0eac2f
commit 1e0010e8aa
9 changed files with 84 additions and 99 deletions

View File

@ -1,33 +1,33 @@
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project // SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later // SPDX-License-Identifier: GPL-2.0-or-later
#include "core/hle/service/cmif_serialization.h"
#include "core/hle/service/pm/boot_mode_service.h" #include "core/hle/service/pm/boot_mode_service.h"
namespace Service::PM { namespace Service::PM {
BootModeService::BootModeService(Core::System& system_) : ServiceFramework{system_, "pm:bm"} { BootModeService::BootModeService(Core::System& system_) : ServiceFramework{system_, "pm:bm"} {
static const FunctionInfo functions[] = { static const FunctionInfo functions[] = {
{0, &BootModeService::GetBootMode, "GetBootMode"}, {0, C<&BootModeService::GetBootMode>, "GetBootMode"},
{1, &BootModeService::SetMaintenanceBoot, "SetMaintenanceBoot"}, {1, C<&BootModeService::SetMaintenanceBoot>, "SetMaintenanceBoot"},
}; };
RegisterHandlers(functions); RegisterHandlers(functions);
} }
void BootModeService::GetBootMode(HLERequestContext& ctx) { Result BootModeService::GetBootMode(Out<u32> out_boot_mode) {
LOG_DEBUG(Service_PM, "called"); LOG_DEBUG(Service_PM, "called");
IPC::ResponseBuilder rb{ctx, 3}; *out_boot_mode = static_cast<u32>(boot_mode);
rb.Push(ResultSuccess);
rb.PushEnum(boot_mode); R_SUCCEED();
} }
void BootModeService::SetMaintenanceBoot(HLERequestContext& ctx) { Result BootModeService::SetMaintenanceBoot() {
LOG_DEBUG(Service_PM, "called"); LOG_DEBUG(Service_PM, "called");
boot_mode = BootMode::Maintenance; boot_mode = BootMode::Maintenance;
IPC::ResponseBuilder rb{ctx, 2}; R_SUCCEED();
rb.Push(ResultSuccess);
} }
} // namespace Service::PM } // namespace Service::PM

View File

@ -3,7 +3,7 @@
#pragma once #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/pm/pm_types.h"
#include "core/hle/service/service.h" #include "core/hle/service/service.h"
@ -14,8 +14,8 @@ public:
explicit BootModeService(Core::System& system_); explicit BootModeService(Core::System& system_);
private: private:
void GetBootMode(HLERequestContext& ctx); Result GetBootMode(Out<u32> out_boot_mode);
void SetMaintenanceBoot(HLERequestContext& ctx); Result SetMaintenanceBoot();
BootMode boot_mode = BootMode::Normal; BootMode boot_mode = BootMode::Normal;
}; };

View File

@ -1,8 +1,8 @@
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project // SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later // 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/debug_monitor_service.h"
#include "core/hle/service/pm/pm_types.h"
namespace Service::PM { namespace Service::PM {
@ -10,14 +10,14 @@ DebugMonitorService::DebugMonitorService(Core::System& system_)
: ServiceFramework{system_, "pm:dmnt"} { : ServiceFramework{system_, "pm:dmnt"} {
// clang-format off // clang-format off
static const FunctionInfo functions[] = { static const FunctionInfo functions[] = {
{0, nullptr, "GetJitDebugProcessIdList"}, {0, nullptr, "GetExceptionProcessIdList"},
{1, nullptr, "StartProcess"}, {1, nullptr, "StartProcess"},
{2, &DebugMonitorService::GetProcessId, "GetProcessId"}, {2, C<&DebugMonitorService::GetProcessId>, "GetProcessId"},
{3, nullptr, "HookToCreateProcess"}, {3, nullptr, "HookToCreateProcess"},
{4, &DebugMonitorService::GetApplicationProcessId, "GetApplicationProcessId"}, {4, C<&DebugMonitorService::GetApplicationProcessId>, "GetApplicationProcessId"},
{5, nullptr, "HookToCreateApplicationProgress"}, {5, nullptr, "HookToCreateApplicationProgress"},
{6, nullptr, "ClearHook"}, {6, nullptr, "ClearHook"},
{65000, &DebugMonitorService::AtmosphereGetProcessInfo, "AtmosphereGetProcessInfo"}, {65000, C<&DebugMonitorService::AtmosphereGetProcessInfo>, "AtmosphereGetProcessInfo"},
{65001, nullptr, "AtmosphereGetCurrentLimitInfo"}, {65001, nullptr, "AtmosphereGetCurrentLimitInfo"},
}; };
// clang-format on // clang-format on
@ -25,61 +25,38 @@ DebugMonitorService::DebugMonitorService(Core::System& system_)
RegisterHandlers(functions); RegisterHandlers(functions);
} }
void DebugMonitorService::GetProcessId(HLERequestContext& ctx) { Result DebugMonitorService::GetProcessId(Out<ProcessId> out_process_id, u64 program_id) {
IPC::RequestParser rp{ctx};
const auto program_id = rp.PopRaw<u64>();
LOG_DEBUG(Service_PM, "called, program_id={:016X}", program_id); LOG_DEBUG(Service_PM, "called, program_id={:016X}", program_id);
auto list = kernel.GetProcessList(); auto list = kernel.GetProcessList();
auto process = auto process =
SearchProcessList(list, [program_id](auto& p) { return p->GetProgramId() == program_id; }); SearchProcessList(list, [program_id](auto& p) { return p->GetProgramId() == program_id; });
if (process.IsNull()) { R_UNLESS(!process.IsNull(), ResultProcessNotFound);
IPC::ResponseBuilder rb{ctx, 2};
rb.Push(ResultProcessNotFound); *out_process_id = ProcessId(process->GetProcessId());
return;
R_SUCCEED();
} }
IPC::ResponseBuilder rb{ctx, 4}; Result DebugMonitorService::GetApplicationProcessId(Out<ProcessId> out_process_id) {
rb.Push(ResultSuccess);
rb.Push(process->GetProcessId());
}
void DebugMonitorService::GetApplicationProcessId(HLERequestContext& ctx) {
LOG_DEBUG(Service_PM, "called"); LOG_DEBUG(Service_PM, "called");
auto list = kernel.GetProcessList(); auto list = kernel.GetProcessList();
GetApplicationPidGeneric(ctx, list); R_RETURN(GetApplicationPidGeneric(out_process_id, list));
} }
void DebugMonitorService::AtmosphereGetProcessInfo(HLERequestContext& ctx) { Result DebugMonitorService::AtmosphereGetProcessInfo(
OutCopyHandle<Kernel::KProcess> out_process_handle, Out<ProgramLocation> out_location,
Out<OverrideStatus> out_status, ProcessId process_id) {
// https://github.com/Atmosphere-NX/Atmosphere/blob/master/stratosphere/pm/source/impl/pm_process_manager.cpp#L614 // 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. // This implementation is incomplete; only a handle to the process is returned.
IPC::RequestParser rp{ctx}; const auto pid = process_id.pid;
const auto pid = rp.PopRaw<u64>();
LOG_WARNING(Service_PM, "(Partial Implementation) called, pid={:016X}", pid); LOG_WARNING(Service_PM, "(Partial Implementation) called, pid={:016X}", pid);
auto list = kernel.GetProcessList(); auto list = kernel.GetProcessList();
auto process = SearchProcessList(list, [pid](auto& p) { return p->GetProcessId() == pid; }); auto process = SearchProcessList(list, [pid](auto& p) { return p->GetProcessId() == pid; });
R_UNLESS(!process.IsNull(), ResultProcessNotFound);
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");
OverrideStatus override_status{}; OverrideStatus override_status{};
ProgramLocation program_location{ ProgramLocation program_location{
@ -87,11 +64,11 @@ void DebugMonitorService::AtmosphereGetProcessInfo(HLERequestContext& ctx) {
.storage_id = 0, .storage_id = 0,
}; };
IPC::ResponseBuilder rb{ctx, 10, 1}; *out_process_handle = process.GetPointerUnsafe();
rb.Push(ResultSuccess); *out_location = program_location;
rb.PushCopyObjects(*process); *out_status = override_status;
rb.PushRaw(program_location);
rb.PushRaw(override_status); R_SUCCEED();
} }
} // namespace Service::PM } // namespace Service::PM

View File

@ -3,7 +3,8 @@
#pragma once #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" #include "core/hle/service/service.h"
namespace Service::PM { namespace Service::PM {
@ -13,8 +14,10 @@ public:
explicit DebugMonitorService(Core::System& system_); explicit DebugMonitorService(Core::System& system_);
private: private:
void GetProcessId(HLERequestContext& ctx); Result GetProcessId(Out<ProcessId> out_process_id, u64 program_id);
void GetApplicationProcessId(HLERequestContext& ctx); Result GetApplicationProcessId(Out<ProcessId> out_process_id);
void AtmosphereGetProcessInfo(HLERequestContext& ctx); Result AtmosphereGetProcessInfo(OutCopyHandle<Kernel::KProcess> out_process_handle,
Out<ProgramLocation> out_location,
Out<OverrideStatus> out_status, ProcessId process_id);
}; };
} // namespace Service::PM } // namespace Service::PM

View File

@ -1,6 +1,7 @@
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project // SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later // 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/information_service.h"
#include "core/hle/service/pm/pm_types.h" #include "core/hle/service/pm/pm_types.h"
@ -9,54 +10,40 @@ namespace Service::PM {
InformationService::InformationService(Core::System& system_) InformationService::InformationService(Core::System& system_)
: ServiceFramework{system_, "pm:info"} { : ServiceFramework{system_, "pm:info"} {
static const FunctionInfo functions[] = { static const FunctionInfo functions[] = {
{0, &InformationService::GetProgramId, "GetProgramId"}, {0, C<&InformationService::GetProgramId>, "GetProgramId"},
{65000, &InformationService::AtmosphereGetProcessId, "AtmosphereGetProcessId"}, {65000, C<&InformationService::AtmosphereGetProcessId>, "AtmosphereGetProcessId"},
{65001, nullptr, "AtmosphereHasLaunchedProgram"}, {65001, nullptr, "AtmosphereHasLaunchedProgram"},
{65002, nullptr, "AtmosphereGetProcessInfo"}, {65002, nullptr, "AtmosphereGetProcessInfo"},
}; };
RegisterHandlers(functions); RegisterHandlers(functions);
} }
void InformationService::GetProgramId(HLERequestContext& ctx) { Result InformationService::GetProgramId(Out<u64> out_program_id, u64 process_id) {
IPC::RequestParser rp{ctx};
const auto process_id = rp.PopRaw<u64>();
LOG_DEBUG(Service_PM, "called, process_id={:016X}", process_id); LOG_DEBUG(Service_PM, "called, process_id={:016X}", process_id);
auto list = kernel.GetProcessList(); auto list = kernel.GetProcessList();
auto process = auto process =
SearchProcessList(list, [process_id](auto& p) { return p->GetProcessId() == process_id; }); SearchProcessList(list, [process_id](auto& p) { return p->GetProcessId() == process_id; });
if (process.IsNull()) { R_UNLESS(!process.IsNull(), ResultProcessNotFound);
IPC::ResponseBuilder rb{ctx, 2};
rb.Push(ResultProcessNotFound); *out_program_id = process->GetProgramId();
return;
R_SUCCEED();
} }
IPC::ResponseBuilder rb{ctx, 4}; Result InformationService::AtmosphereGetProcessId(Out<ProcessId> out_process_id, u64 program_id) {
rb.Push(ResultSuccess);
rb.Push(process->GetProgramId());
}
void InformationService::AtmosphereGetProcessId(HLERequestContext& ctx) {
IPC::RequestParser rp{ctx};
const auto program_id = rp.PopRaw<u64>();
LOG_DEBUG(Service_PM, "called, program_id={:016X}", program_id); LOG_DEBUG(Service_PM, "called, program_id={:016X}", program_id);
auto list = system.Kernel().GetProcessList(); auto list = system.Kernel().GetProcessList();
auto process = auto process =
SearchProcessList(list, [program_id](auto& p) { return p->GetProgramId() == program_id; }); SearchProcessList(list, [program_id](auto& p) { return p->GetProgramId() == program_id; });
if (process.IsNull()) { R_UNLESS(!process.IsNull(), ResultProcessNotFound);
IPC::ResponseBuilder rb{ctx, 2};
rb.Push(ResultProcessNotFound);
return;
}
IPC::ResponseBuilder rb{ctx, 4}; *out_process_id = ProcessId(process->GetProcessId());
rb.Push(ResultSuccess);
rb.Push(process->GetProcessId()); R_SUCCEED();
} }
} // namespace Service::PM } // namespace Service::PM

View File

@ -3,7 +3,7 @@
#pragma once #pragma once
#include "core/hle/service/ipc_helpers.h" #include "core/hle/service/cmif_types.h"
#include "core/hle/service/service.h" #include "core/hle/service/service.h"
namespace Service::PM { namespace Service::PM {
@ -13,8 +13,8 @@ public:
explicit InformationService(Core::System& system_); explicit InformationService(Core::System& system_);
private: private:
void GetProgramId(HLERequestContext& ctx); Result GetProgramId(Out<u64> out_program_id, u64 process_id);
void AtmosphereGetProcessId(HLERequestContext& ctx); Result AtmosphereGetProcessId(Out<ProcessId> out_process_id, u64 program_id);
}; };
} // namespace Service::PM } // namespace Service::PM

View File

@ -7,7 +7,7 @@
#include "core/hle/kernel/k_process.h" #include "core/hle/kernel/k_process.h"
#include "core/hle/kernel/kernel.h" #include "core/hle/kernel/kernel.h"
#include "core/hle/result.h" #include "core/hle/result.h"
#include "core/hle/service/ipc_helpers.h" #include "core/hle/service/cmif_types.h"
namespace Service::PM { namespace Service::PM {
@ -26,6 +26,18 @@ enum class BootMode {
SafeMode = 2, 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<Kernel::KScopedAutoObject<Kernel::KProcess>>; using ProcessList = std::list<Kernel::KScopedAutoObject<Kernel::KProcess>>;
template <typename F> template <typename F>
@ -40,12 +52,14 @@ static inline Kernel::KScopedAutoObject<Kernel::KProcess> SearchProcessList(
return iter->GetPointerUnsafe(); return iter->GetPointerUnsafe();
} }
static inline void GetApplicationPidGeneric(HLERequestContext& ctx, ProcessList& process_list) { static inline Result GetApplicationPidGeneric(Out<ProcessId> out_process_id,
ProcessList& process_list) {
auto process = SearchProcessList(process_list, [](auto& p) { return p->IsApplication(); }); auto process = SearchProcessList(process_list, [](auto& p) { return p->IsApplication(); });
IPC::ResponseBuilder rb{ctx, 4}; *out_process_id =
rb.Push(ResultSuccess); process.IsNull() ? ProcessId(NO_PROCESS_FOUND_PID) : ProcessId(process->GetProcessId());
rb.Push(process.IsNull() ? NO_PROCESS_FOUND_PID : process->GetProcessId());
R_SUCCEED();
} }
} // namespace Service::PM } // namespace Service::PM

View File

@ -1,6 +1,7 @@
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project // SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later // 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/pm_types.h"
#include "core/hle/service/pm/shell_service.h" #include "core/hle/service/pm/shell_service.h"
@ -15,7 +16,7 @@ ShellService::ShellService(Core::System& system_) : ServiceFramework{system_, "p
{3, nullptr, "GetProcessEventHandle"}, {3, nullptr, "GetProcessEventHandle"},
{4, nullptr, "GetProcessEventInfo"}, {4, nullptr, "GetProcessEventInfo"},
{5, nullptr, "NotifyBootFinished"}, {5, nullptr, "NotifyBootFinished"},
{6, &ShellService::GetApplicationProcessIdForShell, "GetApplicationProcessIdForShell"}, {6, C<&ShellService::GetApplicationProcessIdForShell>, "GetApplicationProcessIdForShell"},
{7, nullptr, "BoostSystemMemoryResourceLimit"}, {7, nullptr, "BoostSystemMemoryResourceLimit"},
{8, nullptr, "BoostApplicationThreadResourceLimit"}, {8, nullptr, "BoostApplicationThreadResourceLimit"},
{9, nullptr, "GetBootFinishedEventHandle"}, {9, nullptr, "GetBootFinishedEventHandle"},
@ -25,10 +26,12 @@ ShellService::ShellService(Core::System& system_) : ServiceFramework{system_, "p
RegisterHandlers(functions); RegisterHandlers(functions);
} }
void ShellService::GetApplicationProcessIdForShell(HLERequestContext& ctx) { Result ShellService::GetApplicationProcessIdForShell(Out<ProcessId> out_process_id) {
LOG_DEBUG(Service_PM, "called"); LOG_DEBUG(Service_PM, "called");
auto list = kernel.GetProcessList(); auto list = kernel.GetProcessList();
GetApplicationPidGeneric(ctx, list);
R_RETURN(GetApplicationPidGeneric(out_process_id, list));
} }
} // namespace Service::PM } // namespace Service::PM

View File

@ -3,6 +3,7 @@
#pragma once #pragma once
#include "core/hle/service/cmif_types.h"
#include "core/hle/service/ipc_helpers.h" #include "core/hle/service/ipc_helpers.h"
#include "core/hle/service/service.h" #include "core/hle/service/service.h"
@ -13,7 +14,7 @@ public:
explicit ShellService(Core::System& system_); explicit ShellService(Core::System& system_);
private: private:
void GetApplicationProcessIdForShell(HLERequestContext& ctx); Result GetApplicationProcessIdForShell(Out<ProcessId> out_process_id);
}; };
} // namespace Service::PM } // namespace Service::PM