mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2024-12-02 00:32:19 +00:00
sf: fixes (basic mitm service functionality now confirmed working)
This commit is contained in:
parent
122f3e4403
commit
2c5ef434f0
4 changed files with 24 additions and 15 deletions
|
@ -18,12 +18,6 @@
|
||||||
#include "sf_hipc_server_domain_session_manager.hpp"
|
#include "sf_hipc_server_domain_session_manager.hpp"
|
||||||
#include "../../sm.hpp"
|
#include "../../sm.hpp"
|
||||||
|
|
||||||
namespace ams::ncm {
|
|
||||||
|
|
||||||
struct ProgramId;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace ams::sf::hipc {
|
namespace ams::sf::hipc {
|
||||||
|
|
||||||
struct DefaultServerManagerOptions {
|
struct DefaultServerManagerOptions {
|
||||||
|
@ -116,7 +110,7 @@ namespace ams::sf::hipc {
|
||||||
ncm::ProgramId client_program_id;
|
ncm::ProgramId client_program_id;
|
||||||
R_ASSERT(sm::mitm::AcknowledgeSession(forward_service.get(), &client_process_id, &client_program_id, this->service_name));
|
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);
|
*out_fsrv = std::move(forward_service);
|
||||||
} else {
|
} else {
|
||||||
*out_obj = std::move(cmif::ServiceObjectHolder(std::move(MakeShared())));
|
*out_obj = std::move(cmif::ServiceObjectHolder(std::move(MakeShared())));
|
||||||
|
@ -171,6 +165,11 @@ namespace ams::sf::hipc {
|
||||||
this->waitable_manager.LinkWaitableHolder(server);
|
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);
|
Result InstallMitmServerImpl(Handle *out_port_handle, sm::ServiceName service_name, MitmQueryFunction query_func);
|
||||||
protected:
|
protected:
|
||||||
virtual ServerBase *AllocateServer() = 0;
|
virtual ServerBase *AllocateServer() = 0;
|
||||||
|
@ -214,13 +213,13 @@ namespace ams::sf::hipc {
|
||||||
return ResultSuccess();
|
return ResultSuccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename ServiceImpl, auto MakeShared = std::make_shared<ServiceImpl>>
|
template<typename ServiceImpl, auto MakeShared = MakeSharedMitm<ServiceImpl>>
|
||||||
Result RegisterMitmServer(sm::ServiceName service_name, size_t max_sessions) {
|
Result RegisterMitmServer(sm::ServiceName service_name) {
|
||||||
static_assert(ServiceObjectTraits<ServiceImpl>::IsMitmServiceObject, "RegisterMitmServer requires mitm object. Use RegisterServer instead.");
|
static_assert(ServiceObjectTraits<ServiceImpl>::IsMitmServiceObject, "RegisterMitmServer requires mitm object. Use RegisterServer instead.");
|
||||||
|
|
||||||
/* Install mitm service. */
|
/* Install mitm service. */
|
||||||
Handle port_handle;
|
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());
|
this->RegisterServerImpl<ServiceImpl, MakeShared>(port_handle, service_name, true, cmif::ServiceObjectHolder());
|
||||||
return ResultSuccess();
|
return ResultSuccess();
|
||||||
|
|
|
@ -33,6 +33,9 @@ namespace ams::sf {
|
||||||
static bool ShouldMitm(os::ProcessId process_id, ncm::ProgramId program_id);
|
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>
|
template<typename T>
|
||||||
struct ServiceObjectTraits {
|
struct ServiceObjectTraits {
|
||||||
static_assert(std::is_base_of<ams::sf::IServiceObject, T>::value, "ServiceObjectTraits requires ServiceObject");
|
static_assert(std::is_base_of<ams::sf::IServiceObject, T>::value, "ServiceObjectTraits requires ServiceObject");
|
||||||
|
|
|
@ -41,6 +41,7 @@ namespace ams::sf::hipc::impl {
|
||||||
|
|
||||||
/* Globals. */
|
/* Globals. */
|
||||||
os::Mutex g_query_server_lock;
|
os::Mutex g_query_server_lock;
|
||||||
|
bool g_constructed_server = false;
|
||||||
bool g_registered_any = false;
|
bool g_registered_any = false;
|
||||||
|
|
||||||
void QueryServerProcessThreadMain(void *query_server) {
|
void QueryServerProcessThreadMain(void *query_server) {
|
||||||
|
@ -51,18 +52,24 @@ namespace ams::sf::hipc::impl {
|
||||||
constexpr int QueryServerProcessThreadPriority = 27;
|
constexpr int QueryServerProcessThreadPriority = 27;
|
||||||
os::StaticThread<QueryServerProcessThreadStackSize> g_query_server_process_thread;
|
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) {
|
void RegisterMitmQueryHandle(Handle query_handle, ServerManagerBase::MitmQueryFunction query_func) {
|
||||||
std::scoped_lock lk(g_query_server_lock);
|
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) {
|
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());
|
R_ASSERT(g_query_server_process_thread.Start());
|
||||||
g_registered_any = true;
|
g_registered_any = true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue