pm: Implement pm:shell and pm:dmnt GetApplicationPid

Returns the process ID of the current application or 0 if no app is running.
This commit is contained in:
Zach Hilman 2019-06-26 19:07:34 -04:00
parent 354c254cde
commit bce4bfffb6
3 changed files with 33 additions and 7 deletions

View file

@ -28,6 +28,17 @@ std::optional<Kernel::SharedPtr<Kernel::Process>> SearchProcessList(
return *iter; return *iter;
} }
void GetApplicationPidGeneric(Kernel::HLERequestContext& ctx,
const std::vector<Kernel::SharedPtr<Kernel::Process>>& process_list) {
const auto process = SearchProcessList(process_list, [](const auto& process) {
return process->GetProcessID() == Kernel::Process::ProcessIDMin;
});
IPC::ResponseBuilder rb{ctx, 4};
rb.Push(RESULT_SUCCESS);
rb.Push(process.has_value() ? (*process)->GetProcessID() : NO_PROCESS_FOUND_PID);
}
} // Anonymous namespace } // Anonymous namespace
class BootMode final : public ServiceFramework<BootMode> { class BootMode final : public ServiceFramework<BootMode> {
@ -71,7 +82,7 @@ public:
{1, nullptr, "StartDebugProcess"}, {1, nullptr, "StartDebugProcess"},
{2, &DebugMonitor::GetTitlePid, "GetTitlePid"}, {2, &DebugMonitor::GetTitlePid, "GetTitlePid"},
{3, nullptr, "EnableDebugForTitleId"}, {3, nullptr, "EnableDebugForTitleId"},
{4, nullptr, "GetApplicationPid"}, {4, &DebugMonitor::GetApplicationPid, "GetApplicationPid"},
{5, nullptr, "EnableDebugForApplication"}, {5, nullptr, "EnableDebugForApplication"},
{6, nullptr, "DisableDebug"}, {6, nullptr, "DisableDebug"},
}; };
@ -103,6 +114,11 @@ private:
rb.Push((*process)->GetProcessID()); rb.Push((*process)->GetProcessID());
} }
void GetApplicationPid(Kernel::HLERequestContext& ctx) {
LOG_DEBUG(Service_PM, "called");
GetApplicationPidGeneric(ctx, kernel.GetProcessList());
}
const Kernel::KernelCore& kernel; const Kernel::KernelCore& kernel;
}; };
@ -143,7 +159,8 @@ private:
class Shell final : public ServiceFramework<Shell> { class Shell final : public ServiceFramework<Shell> {
public: public:
explicit Shell() : ServiceFramework{"pm:shell"} { explicit Shell(const Kernel::KernelCore& kernel)
: ServiceFramework{"pm:shell"}, kernel(kernel) {
// clang-format off // clang-format off
static const FunctionInfo functions[] = { static const FunctionInfo functions[] = {
{0, nullptr, "LaunchProcess"}, {0, nullptr, "LaunchProcess"},
@ -152,14 +169,23 @@ public:
{3, nullptr, "GetProcessEventWaiter"}, {3, nullptr, "GetProcessEventWaiter"},
{4, nullptr, "GetProcessEventType"}, {4, nullptr, "GetProcessEventType"},
{5, nullptr, "NotifyBootFinished"}, {5, nullptr, "NotifyBootFinished"},
{6, nullptr, "GetApplicationPid"}, {6, &Shell::GetApplicationPid, "GetApplicationPid"},
{7, nullptr, "BoostSystemMemoryResourceLimit"}, {7, nullptr, "BoostSystemMemoryResourceLimit"},
{8, nullptr, "EnableAdditionalSystemThreads"}, {8, nullptr, "EnableAdditionalSystemThreads"},
{9, nullptr, "GetUnimplementedEventHandle"},
}; };
// clang-format on // clang-format on
RegisterHandlers(functions); RegisterHandlers(functions);
} }
private:
void GetApplicationPid(Kernel::HLERequestContext& ctx) {
LOG_DEBUG(Service_PM, "called");
GetApplicationPidGeneric(ctx, kernel.GetProcessList());
}
const Kernel::KernelCore& kernel;
}; };
void InstallInterfaces(Core::System& system) { void InstallInterfaces(Core::System& system) {

View file

@ -4,8 +4,8 @@
#pragma once #pragma once
namespace Service::SM { namespace Core {
class ServiceManager; class System;
} }
namespace Service::PM { namespace Service::PM {
@ -16,6 +16,6 @@ enum class SystemBootMode {
}; };
/// Registers all PM services with the specified service manager. /// Registers all PM services with the specified service manager.
void InstallInterfaces(SM::ServiceManager& service_manager); void InstallInterfaces(Core::System& system);
} // namespace Service::PM } // namespace Service::PM

View file

@ -242,7 +242,7 @@ void Init(std::shared_ptr<SM::ServiceManager>& sm, Core::System& system,
PCTL::InstallInterfaces(*sm); PCTL::InstallInterfaces(*sm);
PCV::InstallInterfaces(*sm); PCV::InstallInterfaces(*sm);
PlayReport::InstallInterfaces(*sm); PlayReport::InstallInterfaces(*sm);
PM::InstallInterfaces(*sm); PM::InstallInterfaces(system);
PSC::InstallInterfaces(*sm); PSC::InstallInterfaces(*sm);
PSM::InstallInterfaces(*sm); PSM::InstallInterfaces(*sm);
Set::InstallInterfaces(*sm); Set::InstallInterfaces(*sm);