From 49af3bcdcba76decc8aec5b6812eac04e488e47f Mon Sep 17 00:00:00 2001 From: Zach Hilman Date: Wed, 26 Jun 2019 19:05:04 -0400 Subject: pm: Implement pm:info GetTitleId Searches the process list for a process with the specified ID, returning the title ID if it exists. --- src/core/hle/service/pm/pm.cpp | 49 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) (limited to 'src/core/hle/service/pm/pm.cpp') diff --git a/src/core/hle/service/pm/pm.cpp b/src/core/hle/service/pm/pm.cpp index ebcc41a43..b6a7d3474 100644 --- a/src/core/hle/service/pm/pm.cpp +++ b/src/core/hle/service/pm/pm.cpp @@ -8,6 +8,26 @@ namespace Service::PM { +namespace { + +constexpr ResultCode ERROR_PROCESS_NOT_FOUND{ErrorModule::PM, 1}; + +constexpr u64 NO_PROCESS_FOUND_PID{0}; + +std::optional> SearchProcessList( + const std::vector>& process_list, + std::function&)> predicate) { + const auto iter = std::find_if(process_list.begin(), process_list.end(), predicate); + + if (iter == process_list.end()) { + return std::nullopt; + } + + return *iter; +} + +} // Anonymous namespace + class BootMode final : public ServiceFramework { public: explicit BootMode() : ServiceFramework{"pm:bm"} { @@ -60,12 +80,37 @@ public: class Info final : public ServiceFramework { public: - explicit Info() : ServiceFramework{"pm:info"} { + explicit Info(const std::vector>& process_list) + : ServiceFramework{"pm:info"}, process_list(process_list) { static const FunctionInfo functions[] = { - {0, nullptr, "GetTitleId"}, + {0, &Info::GetTitleId, "GetTitleId"}, }; RegisterHandlers(functions); } + +private: + void GetTitleId(Kernel::HLERequestContext& ctx) { + IPC::RequestParser rp{ctx}; + const auto process_id = rp.PopRaw(); + + LOG_DEBUG(Service_PM, "called, process_id={:016X}", process_id); + + const auto process = SearchProcessList(process_list, [process_id](const auto& process) { + return process->GetProcessID() == process_id; + }); + + if (!process.has_value()) { + IPC::ResponseBuilder rb{ctx, 2}; + rb.Push(ERROR_PROCESS_NOT_FOUND); + return; + } + + IPC::ResponseBuilder rb{ctx, 4}; + rb.Push(RESULT_SUCCESS); + rb.Push((*process)->GetTitleID()); + } + + const std::vector>& process_list; }; class Shell final : public ServiceFramework { -- cgit v1.2.3