1
0
Fork 0
mirror of https://github.com/Atmosphere-NX/Atmosphere.git synced 2024-11-26 05:42:17 +00:00

sf: fixes (basic mitm service functionality now confirmed working)

This commit is contained in:
Michael Scire 2019-11-20 22:03:22 -08:00 committed by SciresM
parent 122f3e4403
commit 2c5ef434f0
4 changed files with 24 additions and 15 deletions

View file

@ -46,4 +46,4 @@ namespace ams::util {
return *GetPointer(ts);
}
}
}

View file

@ -18,12 +18,6 @@
#include "sf_hipc_server_domain_session_manager.hpp"
#include "../../sm.hpp"
namespace ams::ncm {
struct ProgramId;
}
namespace ams::sf::hipc {
struct DefaultServerManagerOptions {
@ -116,7 +110,7 @@ namespace ams::sf::hipc {
ncm::ProgramId client_program_id;
R_ASSERT(sm::mitm::AcknowledgeSession(forward_service.get(), &client_process_id, &client_program_id, this->service_name));
*out_obj = std::move(cmif::ServiceObjectHolder(std::move(MakeShared(forward_service))));
*out_obj = std::move(cmif::ServiceObjectHolder(std::move(MakeShared(std::shared_ptr<::Service>(forward_service), client_process_id, client_program_id))));
*out_fsrv = std::move(forward_service);
} else {
*out_obj = std::move(cmif::ServiceObjectHolder(std::move(MakeShared())));
@ -171,6 +165,11 @@ namespace ams::sf::hipc {
this->waitable_manager.LinkWaitableHolder(server);
}
template<typename ServiceImpl>
static constexpr inline std::shared_ptr<ServiceImpl> MakeSharedMitm(std::shared_ptr<::Service> &&s, os::ProcessId p, ncm::ProgramId r) {
return std::make_shared<ServiceImpl>(std::forward<std::shared_ptr<::Service>>(s), p, r);
}
Result InstallMitmServerImpl(Handle *out_port_handle, sm::ServiceName service_name, MitmQueryFunction query_func);
protected:
virtual ServerBase *AllocateServer() = 0;
@ -214,13 +213,13 @@ namespace ams::sf::hipc {
return ResultSuccess();
}
template<typename ServiceImpl, auto MakeShared = std::make_shared<ServiceImpl>>
Result RegisterMitmServer(sm::ServiceName service_name, size_t max_sessions) {
template<typename ServiceImpl, auto MakeShared = MakeSharedMitm<ServiceImpl>>
Result RegisterMitmServer(sm::ServiceName service_name) {
static_assert(ServiceObjectTraits<ServiceImpl>::IsMitmServiceObject, "RegisterMitmServer requires mitm object. Use RegisterServer instead.");
/* Install mitm service. */
Handle port_handle;
R_TRY(this->InstallMitmServerImpl(&port_handle, service_name, max_sessions, &ServiceImpl::ShouldMitm));
R_TRY(this->InstallMitmServerImpl(&port_handle, service_name, &ServiceImpl::ShouldMitm));
this->RegisterServerImpl<ServiceImpl, MakeShared>(port_handle, service_name, true, cmif::ServiceObjectHolder());
return ResultSuccess();

View file

@ -33,6 +33,9 @@ namespace ams::sf {
static bool ShouldMitm(os::ProcessId process_id, ncm::ProgramId program_id);
};
/* Utility. */
#define SF_MITM_SERVICE_OBJECT_CTOR(cls) cls(std::shared_ptr<::Service> &&s, os::ProcessId p, ncm::ProgramId r) : ::ams::sf::IMitmServiceObject(std::forward<std::shared_ptr<::Service>>(s), p, r)
template<typename T>
struct ServiceObjectTraits {
static_assert(std::is_base_of<ams::sf::IServiceObject, T>::value, "ServiceObjectTraits requires ServiceObject");

View file

@ -41,6 +41,7 @@ namespace ams::sf::hipc::impl {
/* Globals. */
os::Mutex g_query_server_lock;
bool g_constructed_server = false;
bool g_registered_any = false;
void QueryServerProcessThreadMain(void *query_server) {
@ -51,18 +52,24 @@ namespace ams::sf::hipc::impl {
constexpr int QueryServerProcessThreadPriority = 27;
os::StaticThread<QueryServerProcessThreadStackSize> g_query_server_process_thread;
constexpr size_t MaxServers = 0;
TYPED_STORAGE(sf::hipc::ServerManager<MaxServers>) g_query_server_storage;
}
void RegisterMitmQueryHandle(Handle query_handle, ServerManagerBase::MitmQueryFunction query_func) {
std::scoped_lock lk(g_query_server_lock);
constexpr size_t MaxServers = 0;
sf::hipc::ServerManager<MaxServers> s_query_server;
R_ASSERT(s_query_server.RegisterSession(query_handle, cmif::ServiceObjectHolder(std::make_shared<MitmQueryService>(query_func))));
if (!g_constructed_server) {
new (GetPointer(g_query_server_storage)) sf::hipc::ServerManager<MaxServers>();
g_constructed_server = true;
}
R_ASSERT(GetPointer(g_query_server_storage)->RegisterSession(query_handle, cmif::ServiceObjectHolder(std::make_shared<MitmQueryService>(query_func))));
if (!g_registered_any) {
R_ASSERT(g_query_server_process_thread.Initialize(&QueryServerProcessThreadMain, &s_query_server, QueryServerProcessThreadPriority));
R_ASSERT(g_query_server_process_thread.Initialize(&QueryServerProcessThreadMain, GetPointer(g_query_server_storage), QueryServerProcessThreadPriority));
R_ASSERT(g_query_server_process_thread.Start());
g_registered_any = true;
}