early-access version 3059

This commit is contained in:
pineappleEA
2022-10-28 04:12:11 +02:00
parent 6e35cb128e
commit ac60707093
25 changed files with 293 additions and 445 deletions

View File

@@ -43,10 +43,6 @@ Kernel::KClientPort& ServiceManager::InterfaceFactory(ServiceManager& self, Core
return self.sm_interface->CreatePort();
}
void ServiceManager::SessionHandler(ServiceManager& self, Kernel::KServerPort* server_port) {
self.sm_interface->AcceptSession(server_port);
}
Result ServiceManager::RegisterService(std::string name, u32 max_sessions,
Kernel::SessionRequestHandlerPtr handler) {
@@ -88,6 +84,7 @@ ResultVal<Kernel::KPort*> ServiceManager::GetServicePort(const std::string& name
port->Initialize(ServerSessionCountMax, false, name);
auto handler = it->second;
port->GetServerPort().SetSessionHandler(std::move(handler));
return port;
}
@@ -148,21 +145,23 @@ ResultVal<Kernel::KClientSession*> SM::GetServiceImpl(Kernel::HLERequestContext&
// Find the named port.
auto port_result = service_manager.GetServicePort(name);
auto service = service_manager.GetService<Kernel::SessionRequestHandler>(name);
if (port_result.Failed() || !service) {
if (port_result.Failed()) {
LOG_ERROR(Service_SM, "called service={} -> error 0x{:08X}", name, port_result.Code().raw);
return port_result.Code();
}
auto& port = port_result.Unwrap();
SCOPE_EXIT({ port->GetClientPort().Close(); });
kernel.RegisterServerObject(&port->GetServerPort());
// Create a new session.
Kernel::KClientSession* session{};
if (const auto result = port->GetClientPort().CreateSession(&session); result.IsError()) {
if (const auto result = port->GetClientPort().CreateSession(
std::addressof(session), std::make_shared<Kernel::SessionRequestManager>(kernel));
result.IsError()) {
LOG_ERROR(Service_SM, "called service={} -> error 0x{:08X}", name, result.raw);
return result;
}
service->AcceptSession(&port->GetServerPort());
LOG_DEBUG(Service_SM, "called service={} -> session={}", name, session->GetId());

View File

@@ -51,7 +51,6 @@ private:
class ServiceManager {
public:
static Kernel::KClientPort& InterfaceFactory(ServiceManager& self, Core::System& system);
static void SessionHandler(ServiceManager& self, Kernel::KServerPort* server_port);
explicit ServiceManager(Kernel::KernelCore& kernel_);
~ServiceManager();

View File

@@ -15,9 +15,10 @@
namespace Service::SM {
void Controller::ConvertCurrentObjectToDomain(Kernel::HLERequestContext& ctx) {
ASSERT_MSG(!ctx.GetManager()->IsDomain(), "Session is already a domain");
ASSERT_MSG(!ctx.Session()->GetSessionRequestManager()->IsDomain(),
"Session is already a domain");
LOG_DEBUG(Service, "called, server_session={}", ctx.Session()->GetId());
ctx.GetManager()->ConvertToDomainOnRequestEnd();
ctx.Session()->GetSessionRequestManager()->ConvertToDomainOnRequestEnd();
IPC::ResponseBuilder rb{ctx, 3};
rb.Push(ResultSuccess);
@@ -27,35 +28,23 @@ void Controller::ConvertCurrentObjectToDomain(Kernel::HLERequestContext& ctx) {
void Controller::CloneCurrentObject(Kernel::HLERequestContext& ctx) {
LOG_DEBUG(Service, "called");
auto& process = *ctx.GetThread().GetOwnerProcess();
auto session_manager = ctx.GetManager();
auto& parent_session = *ctx.Session()->GetParent();
auto& parent_port = parent_session.GetParent()->GetParent()->GetClientPort();
auto& session_manager = parent_session.GetServerSession().GetSessionRequestManager();
// FIXME: this is duplicated from the SVC, it should just call it instead
// once this is a proper process
// Reserve a new session from the process resource limit.
Kernel::KScopedResourceReservation session_reservation(&process,
Kernel::LimitableResource::Sessions);
ASSERT(session_reservation.Succeeded());
// Create the sessionn.
Kernel::KSession* session = Kernel::KSession::Create(system.Kernel());
ASSERT(session != nullptr);
// Initialize the session.
session->Initialize(nullptr, "");
// Commit the session reservation.
session_reservation.Commit();
// Register with manager.
session_manager->SessionHandler().RegisterSession(&session->GetServerSession(),
session_manager);
// Create a session.
Kernel::KClientSession* session{};
const Result result = parent_port.CreateSession(std::addressof(session), session_manager);
if (result.IsError()) {
LOG_CRITICAL(Service, "CreateSession failed with error 0x{:08X}", result.raw);
IPC::ResponseBuilder rb{ctx, 2};
rb.Push(result);
}
// We succeeded.
IPC::ResponseBuilder rb{ctx, 2, 0, 1, IPC::ResponseBuilder::Flags::AlwaysMoveHandles};
rb.Push(ResultSuccess);
rb.PushMoveObjects(session->GetClientSession());
rb.PushMoveObjects(session);
}
void Controller::CloneCurrentObjectEx(Kernel::HLERequestContext& ctx) {