pgl: update to use tipc (untested)
This commit is contained in:
@@ -19,19 +19,79 @@
|
||||
#include <stratosphere/pm.hpp>
|
||||
#include <stratosphere/pgl/pgl_types.hpp>
|
||||
#include <stratosphere/pgl/sf/pgl_sf_i_event_observer.hpp>
|
||||
#include <stratosphere/pgl/tipc/pgl_tipc_i_event_observer.hpp>
|
||||
|
||||
namespace ams::pgl {
|
||||
|
||||
namespace impl {
|
||||
|
||||
class EventObserverInterface {
|
||||
NON_COPYABLE(EventObserverInterface);
|
||||
NON_MOVEABLE(EventObserverInterface);
|
||||
public:
|
||||
constexpr EventObserverInterface() = default;
|
||||
|
||||
virtual ~EventObserverInterface() { /* ... */ }
|
||||
|
||||
virtual Result GetSystemEvent(os::SystemEventType *out) = 0;
|
||||
virtual Result GetProcessEventInfo(pm::ProcessEventInfo *out) = 0;
|
||||
};
|
||||
|
||||
class EventObserverByCmif final : public EventObserverInterface {
|
||||
NON_COPYABLE(EventObserverByCmif);
|
||||
NON_MOVEABLE(EventObserverByCmif);
|
||||
private:
|
||||
ams::sf::SharedPointer<pgl::sf::IEventObserver> m_cmif_interface;
|
||||
public:
|
||||
explicit EventObserverByCmif(ams::sf::SharedPointer<pgl::sf::IEventObserver> intf) : m_cmif_interface(intf) { /* ... */ }
|
||||
public:
|
||||
virtual Result GetSystemEvent(os::SystemEventType *out) override {
|
||||
ams::sf::CopyHandle handle;
|
||||
R_TRY(m_cmif_interface->GetProcessEventHandle(std::addressof(handle)));
|
||||
os::AttachSystemEvent(out, handle.GetValue(), true, svc::InvalidHandle, false, os::EventClearMode_AutoClear);
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
virtual Result GetProcessEventInfo(pm::ProcessEventInfo *out) override {
|
||||
return m_cmif_interface->GetProcessEventInfo(out);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T> requires tipc::IsIEventObserver<T>
|
||||
class EventObserverByTipc final : public EventObserverInterface {
|
||||
NON_COPYABLE(EventObserverByTipc);
|
||||
NON_MOVEABLE(EventObserverByTipc);
|
||||
private:
|
||||
T m_tipc_interface;
|
||||
public:
|
||||
template<typename... Args>
|
||||
explicit EventObserverByTipc(Args &&... args) : m_tipc_interface(std::forward<Args>(args)...) { /* ... */ }
|
||||
public:
|
||||
virtual Result GetSystemEvent(os::SystemEventType *out) override {
|
||||
ams::tipc::CopyHandle handle;
|
||||
R_TRY(m_tipc_interface.GetProcessEventHandle(std::addressof(handle)));
|
||||
os::AttachSystemEvent(out, handle.GetValue(), true, svc::InvalidHandle, false, os::EventClearMode_AutoClear);
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
virtual Result GetProcessEventInfo(pm::ProcessEventInfo *out) override {
|
||||
return m_tipc_interface.GetProcessEventInfo(ams::tipc::Out<pm::ProcessEventInfo>(out));
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
class EventObserver {
|
||||
NON_COPYABLE(EventObserver);
|
||||
private:
|
||||
ams::sf::SharedPointer<pgl::sf::IEventObserver> interface;
|
||||
std::unique_ptr<impl::EventObserverInterface> m_impl;
|
||||
public:
|
||||
EventObserver() { /* ... */ }
|
||||
explicit EventObserver(ams::sf::SharedPointer<pgl::sf::IEventObserver> intf) : interface(intf) { /* ... */ }
|
||||
|
||||
explicit EventObserver(std::unique_ptr<impl::EventObserverInterface> impl) : m_impl(std::move(impl)) { /* ... */ }
|
||||
|
||||
EventObserver(EventObserver &&rhs) {
|
||||
this->interface = std::move(rhs.interface);
|
||||
m_impl = std::move(rhs.m_impl);
|
||||
}
|
||||
|
||||
EventObserver &operator=(EventObserver &&rhs) {
|
||||
@@ -40,18 +100,15 @@ namespace ams::pgl {
|
||||
}
|
||||
|
||||
void Swap(EventObserver &rhs) {
|
||||
std::swap(this->interface, rhs.interface);
|
||||
std::swap(m_impl, rhs.m_impl);
|
||||
}
|
||||
public:
|
||||
Result GetSystemEvent(os::SystemEventType *out) {
|
||||
ams::sf::CopyHandle handle;
|
||||
R_TRY(this->interface->GetProcessEventHandle(std::addressof(handle)));
|
||||
os::AttachSystemEvent(out, handle.GetValue(), true, svc::InvalidHandle, false, os::EventClearMode_AutoClear);
|
||||
return ResultSuccess();
|
||||
return m_impl->GetSystemEvent(out);
|
||||
}
|
||||
|
||||
Result GetProcessEventInfo(pm::ProcessEventInfo *out) {
|
||||
return this->interface->GetProcessEventInfo(out);
|
||||
return m_impl->GetProcessEventInfo(out);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -20,8 +20,9 @@
|
||||
#include <stratosphere/pm.hpp>
|
||||
#include <stratosphere/pgl/pgl_types.hpp>
|
||||
|
||||
#define AMS_PGL_I_EVENT_OBSERVER_INTERFACE_INFO(C, H) \
|
||||
#define AMS_PGL_SF_I_EVENT_OBSERVER_INTERFACE_INFO(C, H) \
|
||||
AMS_SF_METHOD_INFO(C, H, 0, Result, GetProcessEventHandle, (ams::sf::OutCopyHandle out), (out)) \
|
||||
AMS_SF_METHOD_INFO(C, H, 1, Result, GetProcessEventInfo, (ams::sf::Out<pm::ProcessEventInfo> out), (out))
|
||||
|
||||
AMS_SF_DEFINE_INTERFACE(ams::pgl::sf, IEventObserver, AMS_PGL_I_EVENT_OBSERVER_INTERFACE_INFO);
|
||||
AMS_SF_DEFINE_INTERFACE(ams::pgl::sf, IEventObserver, AMS_PGL_SF_I_EVENT_OBSERVER_INTERFACE_INFO);
|
||||
|
||||
|
||||
@@ -20,6 +20,10 @@
|
||||
|
||||
namespace ams::pgl::srv {
|
||||
|
||||
void Initialize();
|
||||
void InitializeHeap();
|
||||
void *Allocate(size_t size);
|
||||
void Deallocate(void *p, size_t size);
|
||||
|
||||
void StartServer();
|
||||
|
||||
}
|
||||
|
||||
@@ -17,19 +17,39 @@
|
||||
#include <vapours.hpp>
|
||||
#include <stratosphere/pgl/pgl_types.hpp>
|
||||
#include <stratosphere/pgl/sf/pgl_sf_i_shell_interface.hpp>
|
||||
#include <stratosphere/pgl/tipc/pgl_tipc_i_shell_interface.hpp>
|
||||
|
||||
namespace ams::pgl::srv {
|
||||
|
||||
class ShellInterface {
|
||||
NON_COPYABLE(ShellInterface);
|
||||
NON_MOVEABLE(ShellInterface);
|
||||
class ShellInterfaceCommon {
|
||||
NON_COPYABLE(ShellInterfaceCommon);
|
||||
NON_MOVEABLE(ShellInterfaceCommon);
|
||||
public:
|
||||
constexpr ShellInterfaceCommon() = default;
|
||||
public:
|
||||
Result LaunchProgramImpl(os::ProcessId *out, const ncm::ProgramLocation &loc, u32 pm_flags, u8 pgl_flags);
|
||||
Result TerminateProcessImpl(os::ProcessId process_id);
|
||||
Result LaunchProgramFromHostImpl(os::ProcessId *out, const void *content_path, size_t content_path_size, u32 pm_flags);
|
||||
Result GetHostContentMetaInfoImpl(pgl::ContentMetaInfo *out, const void *content_path, size_t content_path_size);
|
||||
Result GetApplicationProcessIdImpl(os::ProcessId *out);
|
||||
Result BoostSystemMemoryResourceLimitImpl(u64 size);
|
||||
Result IsProcessTrackedImpl(bool *out, os::ProcessId process_id);
|
||||
Result EnableApplicationCrashReportImpl(bool enabled);
|
||||
Result IsApplicationCrashReportEnabledImpl(bool *out);
|
||||
Result EnableApplicationAllThreadDumpOnCrashImpl(bool enabled);
|
||||
Result TriggerApplicationSnapShotDumperImpl(SnapShotDumpType dump_type, const void *arg, size_t arg_size);
|
||||
};
|
||||
|
||||
class ShellInterfaceCmif : public ShellInterfaceCommon {
|
||||
NON_COPYABLE(ShellInterfaceCmif);
|
||||
NON_MOVEABLE(ShellInterfaceCmif);
|
||||
private:
|
||||
using Allocator = ams::sf::ExpHeapAllocator;
|
||||
using ObjectFactory = ams::sf::ObjectFactory<ams::sf::ExpHeapAllocator::Policy>;
|
||||
private:
|
||||
Allocator *m_allocator;
|
||||
public:
|
||||
constexpr ShellInterface(Allocator *a) : m_allocator(a) { /* ... */ }
|
||||
constexpr ShellInterfaceCmif(Allocator *a) : ShellInterfaceCommon(), m_allocator(a) { /* ... */ }
|
||||
public:
|
||||
/* Interface commands. */
|
||||
Result LaunchProgram(ams::sf::Out<os::ProcessId> out, const ncm::ProgramLocation &loc, u32 pm_flags, u8 pgl_flags);
|
||||
@@ -47,6 +67,27 @@ namespace ams::pgl::srv {
|
||||
Result GetShellEventObserver(ams::sf::Out<ams::sf::SharedPointer<pgl::sf::IEventObserver>> out);
|
||||
Result Command21NotImplemented(ams::sf::Out<u64> out, u32 in, const ams::sf::InBuffer &buf1, const ams::sf::InBuffer &buf2);
|
||||
};
|
||||
static_assert(pgl::sf::IsIShellInterface<ShellInterface>);
|
||||
static_assert(pgl::sf::IsIShellInterface<ShellInterfaceCmif>);
|
||||
|
||||
class ShellInterfaceTipc : public ShellInterfaceCommon {
|
||||
NON_COPYABLE(ShellInterfaceTipc);
|
||||
NON_MOVEABLE(ShellInterfaceTipc);
|
||||
public:
|
||||
constexpr ShellInterfaceTipc() : ShellInterfaceCommon() { /* ... */ }
|
||||
public:
|
||||
/* Interface commands. */
|
||||
Result LaunchProgram(ams::tipc::Out<os::ProcessId> out, const ncm::ProgramLocation loc, u32 pm_flags, u8 pgl_flags);
|
||||
Result TerminateProcess(os::ProcessId process_id);
|
||||
Result LaunchProgramFromHost(ams::tipc::Out<os::ProcessId> out, const ams::tipc::InBuffer content_path, u32 pm_flags);
|
||||
Result GetHostContentMetaInfo(ams::tipc::Out<pgl::ContentMetaInfo> out, const ams::tipc::InBuffer content_path);
|
||||
Result GetApplicationProcessId(ams::tipc::Out<os::ProcessId> out);
|
||||
Result BoostSystemMemoryResourceLimit(u64 size);
|
||||
Result IsProcessTracked(ams::tipc::Out<bool> out, os::ProcessId process_id);
|
||||
Result EnableApplicationCrashReport(bool enabled);
|
||||
Result IsApplicationCrashReportEnabled(ams::tipc::Out<bool> out);
|
||||
Result EnableApplicationAllThreadDumpOnCrash(bool enabled);
|
||||
Result GetShellEventObserver(ams::tipc::OutMoveHandle out);
|
||||
};
|
||||
static_assert(pgl::tipc::IsIShellInterface<ShellInterfaceTipc>);
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2020 Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
#include <stratosphere/os.hpp>
|
||||
#include <stratosphere/pm.hpp>
|
||||
#include <stratosphere/tipc.hpp>
|
||||
#include <stratosphere/pgl/pgl_types.hpp>
|
||||
|
||||
#define AMS_PGL_TIPC_I_EVENT_OBSERVER_INTERFACE_INFO(C, H) \
|
||||
AMS_TIPC_METHOD_INFO(C, H, 0, Result, GetProcessEventHandle, (ams::tipc::OutCopyHandle out), (out)) \
|
||||
AMS_TIPC_METHOD_INFO(C, H, 1, Result, GetProcessEventInfo, (ams::tipc::Out<pm::ProcessEventInfo> out), (out))
|
||||
|
||||
AMS_TIPC_DEFINE_INTERFACE(ams::pgl::tipc, IEventObserver, AMS_PGL_TIPC_I_EVENT_OBSERVER_INTERFACE_INFO);
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2020 Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
#include <stratosphere/os.hpp>
|
||||
#include <stratosphere/pm.hpp>
|
||||
#include <stratosphere/tipc.hpp>
|
||||
#include <stratosphere/pgl/pgl_types.hpp>
|
||||
#include <stratosphere/pgl/tipc/pgl_tipc_i_event_observer.hpp>
|
||||
|
||||
#define AMS_PGL_TIPC_I_SHELL_INTERFACE_INTERFACE_INFO(C, H) \
|
||||
AMS_TIPC_METHOD_INFO(C, H, 0, Result, LaunchProgram, (ams::tipc::Out<os::ProcessId> out, const ncm::ProgramLocation loc, u32 pm_flags, u8 pgl_flags), (out, loc, pm_flags, pgl_flags)) \
|
||||
AMS_TIPC_METHOD_INFO(C, H, 1, Result, TerminateProcess, (os::ProcessId process_id), (process_id)) \
|
||||
AMS_TIPC_METHOD_INFO(C, H, 2, Result, LaunchProgramFromHost, (ams::tipc::Out<os::ProcessId> out, const ams::tipc::InBuffer content_path, u32 pm_flags), (out, content_path, pm_flags)) \
|
||||
AMS_TIPC_METHOD_INFO(C, H, 4, Result, GetHostContentMetaInfo, (ams::tipc::Out<pgl::ContentMetaInfo> out, const ams::tipc::InBuffer content_path), (out, content_path)) \
|
||||
AMS_TIPC_METHOD_INFO(C, H, 5, Result, GetApplicationProcessId, (ams::tipc::Out<os::ProcessId> out), (out)) \
|
||||
AMS_TIPC_METHOD_INFO(C, H, 6, Result, BoostSystemMemoryResourceLimit, (u64 size), (size)) \
|
||||
AMS_TIPC_METHOD_INFO(C, H, 7, Result, IsProcessTracked, (ams::tipc::Out<bool> out, os::ProcessId process_id), (out, process_id)) \
|
||||
AMS_TIPC_METHOD_INFO(C, H, 8, Result, EnableApplicationCrashReport, (bool enabled), (enabled)) \
|
||||
AMS_TIPC_METHOD_INFO(C, H, 9, Result, IsApplicationCrashReportEnabled, (ams::tipc::Out<bool> out), (out)) \
|
||||
AMS_TIPC_METHOD_INFO(C, H, 10, Result, EnableApplicationAllThreadDumpOnCrash, (bool enabled), (enabled)) \
|
||||
AMS_TIPC_METHOD_INFO(C, H, 20, Result, GetShellEventObserver, (ams::tipc::OutMoveHandle out), (out))
|
||||
|
||||
AMS_TIPC_DEFINE_INTERFACE(ams::pgl::tipc, IShellInterface, AMS_PGL_TIPC_I_SHELL_INTERFACE_INTERFACE_INFO);
|
||||
@@ -59,7 +59,7 @@ namespace ams::tipc {
|
||||
}
|
||||
}
|
||||
|
||||
AMS_ABORT("Failed to allocate entry in SlabAllocator<T, N>");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void Deallocate(ServiceObjectBase *object) {
|
||||
|
||||
@@ -165,6 +165,17 @@ namespace ams::tipc {
|
||||
return m_object_manager->ReplyAndReceive(out_holder, out_object, reply_target, std::addressof(m_waitable_manager));
|
||||
}
|
||||
|
||||
void AddSession(svc::Handle session_handle, tipc::ServiceObjectBase *service_object) {
|
||||
/* Create a waitable object for the session. */
|
||||
tipc::WaitableObject object;
|
||||
|
||||
/* Setup the object. */
|
||||
object.InitializeAsSession(session_handle, true, service_object);
|
||||
|
||||
/* Register the object. */
|
||||
m_object_manager->AddObject(object);
|
||||
}
|
||||
|
||||
void ProcessMessages() {
|
||||
/* While we have messages in our queue, receive and handle them. */
|
||||
uintptr_t message_type, message_data;
|
||||
@@ -182,14 +193,8 @@ namespace ams::tipc {
|
||||
/* Allocate a service object for the port. */
|
||||
auto *service_object = m_server_manager->AllocateObject(static_cast<size_t>(message_data));
|
||||
|
||||
/* Create a waitable object for the session. */
|
||||
tipc::WaitableObject object;
|
||||
|
||||
/* Setup the object. */
|
||||
object.InitializeAsSession(session_handle, true, service_object);
|
||||
|
||||
/* Register the object. */
|
||||
m_object_manager->AddObject(object);
|
||||
/* Add the newly-created service object. */
|
||||
this->AddSession(session_handle, service_object);
|
||||
}
|
||||
break;
|
||||
case MessageType_TriggerResume:
|
||||
@@ -402,6 +407,16 @@ namespace ams::tipc {
|
||||
this->GetPortManager<Ix>().RegisterPort(static_cast<s32>(Ix), port_handle);
|
||||
}
|
||||
|
||||
template<size_t Ix>
|
||||
void RegisterPort(sm::ServiceName service_name, size_t max_sessions) {
|
||||
/* Register service. */
|
||||
svc::Handle port_handle = svc::InvalidHandle;
|
||||
R_ABORT_UNLESS(sm::RegisterService(std::addressof(port_handle), service_name, max_sessions, false));
|
||||
|
||||
/* Register the port handle. */
|
||||
this->RegisterPort<Ix>(port_handle);
|
||||
}
|
||||
|
||||
void LoopAuto() {
|
||||
/* If we have additional threads, create and start them. */
|
||||
if constexpr (NumPorts > 1) {
|
||||
@@ -441,6 +456,27 @@ namespace ams::tipc {
|
||||
(this->TriggerResumeImpl<Ix>(resume_key), ...);
|
||||
}(std::make_index_sequence<NumPorts>());
|
||||
}
|
||||
|
||||
Result AddSession(svc::Handle *out, tipc::ServiceObjectBase *object) {
|
||||
/* Acquire exclusive access to ourselves. */
|
||||
std::scoped_lock lk(m_mutex);
|
||||
|
||||
/* Create a handle for the session. */
|
||||
svc::Handle session_handle;
|
||||
R_TRY(svc::CreateSession(std::addressof(session_handle), out, false, 0));
|
||||
|
||||
/* Select the best port manager. */
|
||||
PortManagerBase *best_manager = nullptr;
|
||||
s32 best_sessions = -1;
|
||||
[this, &best_manager, &best_sessions]<size_t... Ix>(std::index_sequence<Ix...>) ALWAYS_INLINE_LAMBDA {
|
||||
(this->TrySelectBetterPort<Ix>(best_manager, best_sessions), ...);
|
||||
}(std::make_index_sequence<NumPorts>());
|
||||
|
||||
/* Add the session to the least burdened manager. */
|
||||
best_manager->AddSession(session_handle, object);
|
||||
|
||||
return ResultSuccess();
|
||||
}
|
||||
private:
|
||||
template<size_t Ix> requires (Ix < NumPorts)
|
||||
void TryAllocateObject(size_t port_index, tipc::ServiceObjectBase *&allocated) {
|
||||
|
||||
Reference in New Issue
Block a user