early-access version 1647

This commit is contained in:
pineappleEA
2021-05-02 08:03:43 +02:00
parent 67c21bcba9
commit 60c88a3cf8
172 changed files with 5952 additions and 1741 deletions

View File

@@ -5,16 +5,16 @@
#include "common/assert.h"
#include "common/logging/log.h"
#include "core/hle/ipc_helpers.h"
#include "core/hle/kernel/client_session.h"
#include "core/hle/kernel/server_session.h"
#include "core/hle/kernel/session.h"
#include "core/hle/kernel/k_client_session.h"
#include "core/hle/kernel/k_server_session.h"
#include "core/hle/kernel/k_session.h"
#include "core/hle/service/sm/controller.h"
namespace Service::SM {
void Controller::ConvertCurrentObjectToDomain(Kernel::HLERequestContext& ctx) {
ASSERT_MSG(ctx.Session()->IsSession(), "Session is already a domain");
LOG_DEBUG(Service, "called, server_session={}", ctx.Session()->GetObjectId());
LOG_DEBUG(Service, "called, server_session={}", ctx.Session()->GetId());
ctx.Session()->ConvertToDomain();
IPC::ResponseBuilder rb{ctx, 3};
@@ -30,7 +30,7 @@ void Controller::CloneCurrentObject(Kernel::HLERequestContext& ctx) {
IPC::ResponseBuilder rb{ctx, 2, 0, 1, IPC::ResponseBuilder::Flags::AlwaysMoveHandles};
rb.Push(RESULT_SUCCESS);
rb.PushMoveObjects(ctx.Session()->GetParent()->Client());
rb.PushMoveObjects(ctx.Session()->GetParent()->GetClientSession());
}
void Controller::CloneCurrentObjectEx(Kernel::HLERequestContext& ctx) {

View File

@@ -6,9 +6,12 @@
#include "common/assert.h"
#include "core/core.h"
#include "core/hle/ipc_helpers.h"
#include "core/hle/kernel/client_port.h"
#include "core/hle/kernel/client_session.h"
#include "core/hle/kernel/server_port.h"
#include "core/hle/kernel/k_client_port.h"
#include "core/hle/kernel/k_client_session.h"
#include "core/hle/kernel/k_port.h"
#include "core/hle/kernel/k_server_port.h"
#include "core/hle/kernel/k_server_session.h"
#include "core/hle/kernel/k_session.h"
#include "core/hle/result.h"
#include "core/hle/service/sm/controller.h"
#include "core/hle/service/sm/sm.h"
@@ -47,8 +50,8 @@ void ServiceManager::InstallInterfaces(std::shared_ptr<ServiceManager> self, Cor
self->controller_interface = std::make_unique<Controller>(system);
}
ResultVal<std::shared_ptr<Kernel::ServerPort>> ServiceManager::RegisterService(std::string name,
u32 max_sessions) {
ResultVal<Kernel::KServerPort*> ServiceManager::RegisterService(std::string name,
u32 max_sessions) {
CASCADE_CODE(ValidateServiceName(name));
@@ -57,11 +60,12 @@ ResultVal<std::shared_ptr<Kernel::ServerPort>> ServiceManager::RegisterService(s
return ERR_ALREADY_REGISTERED;
}
auto [server_port, client_port] =
Kernel::ServerPort::CreatePortPair(kernel, max_sessions, name);
auto* port = Kernel::KPort::Create(kernel);
port->Initialize(max_sessions, false, name);
registered_services.emplace(std::move(name), std::move(client_port));
return MakeResult(std::move(server_port));
registered_services.emplace(std::move(name), port);
return MakeResult(&port->GetServerPort());
}
ResultCode ServiceManager::UnregisterService(const std::string& name) {
@@ -72,12 +76,14 @@ ResultCode ServiceManager::UnregisterService(const std::string& name) {
LOG_ERROR(Service_SM, "Server is not registered! service={}", name);
return ERR_SERVICE_NOT_REGISTERED;
}
iter->second->Close();
registered_services.erase(iter);
return RESULT_SUCCESS;
}
ResultVal<std::shared_ptr<Kernel::ClientPort>> ServiceManager::GetServicePort(
const std::string& name) {
ResultVal<Kernel::KPort*> ServiceManager::GetServicePort(const std::string& name) {
CASCADE_CODE(ValidateServiceName(name));
auto it = registered_services.find(name);
@@ -89,13 +95,6 @@ ResultVal<std::shared_ptr<Kernel::ClientPort>> ServiceManager::GetServicePort(
return MakeResult(it->second);
}
ResultVal<std::shared_ptr<Kernel::ClientSession>> ServiceManager::ConnectToService(
const std::string& name) {
CASCADE_RESULT(auto client_port, GetServicePort(name));
return client_port->Connect();
}
SM::~SM() = default;
/**
@@ -119,30 +118,32 @@ void SM::GetService(Kernel::HLERequestContext& ctx) {
std::string name(name_buf.begin(), end);
auto client_port = service_manager->GetServicePort(name);
if (client_port.Failed()) {
auto result = service_manager->GetServicePort(name);
if (result.Failed()) {
IPC::ResponseBuilder rb{ctx, 2};
rb.Push(client_port.Code());
LOG_ERROR(Service_SM, "called service={} -> error 0x{:08X}", name, client_port.Code().raw);
rb.Push(result.Code());
LOG_ERROR(Service_SM, "called service={} -> error 0x{:08X}", name, result.Code().raw);
if (name.length() == 0)
return; // LibNX Fix
UNIMPLEMENTED();
return;
}
auto [client, server] = Kernel::Session::Create(kernel, name);
auto* port = result.Unwrap();
const auto& server_port = client_port.Unwrap()->GetServerPort();
if (server_port->GetHLEHandler()) {
server_port->GetHLEHandler()->ClientConnected(server);
auto* session = Kernel::KSession::Create(kernel);
session->Initialize(&port->GetClientPort(), std::move(name));
if (port->GetServerPort().GetHLEHandler()) {
port->GetServerPort().GetHLEHandler()->ClientConnected(&session->GetServerSession());
} else {
server_port->AppendPendingSession(server);
port->EnqueueSession(&session->GetServerSession());
}
LOG_DEBUG(Service_SM, "called service={} -> session={}", name, client->GetObjectId());
LOG_DEBUG(Service_SM, "called service={} -> session={}", name, session->GetId());
IPC::ResponseBuilder rb{ctx, 2, 0, 1, IPC::ResponseBuilder::Flags::AlwaysMoveHandles};
rb.Push(RESULT_SUCCESS);
rb.PushMoveObjects(std::move(client));
rb.PushMoveObjects(session->GetClientSession());
}
void SM::RegisterService(Kernel::HLERequestContext& ctx) {
@@ -170,7 +171,9 @@ void SM::RegisterService(Kernel::HLERequestContext& ctx) {
IPC::ResponseBuilder rb{ctx, 2, 0, 1, IPC::ResponseBuilder::Flags::AlwaysMoveHandles};
rb.Push(handle.Code());
rb.PushMoveObjects(std::move(handle).Unwrap());
auto server_port = handle.Unwrap();
rb.PushMoveObjects(server_port);
}
void SM::UnregisterService(Kernel::HLERequestContext& ctx) {

View File

@@ -10,9 +10,7 @@
#include <unordered_map>
#include "common/concepts.h"
#include "core/hle/kernel/client_port.h"
#include "core/hle/kernel/object.h"
#include "core/hle/kernel/server_port.h"
#include "core/hle/kernel/k_port.h"
#include "core/hle/result.h"
#include "core/hle/service/service.h"
@@ -21,10 +19,11 @@ class System;
}
namespace Kernel {
class ClientPort;
class ClientSession;
class KClientPort;
class KClientSession;
class KernelCore;
class ServerPort;
class KPort;
class KServerPort;
class SessionRequestHandler;
} // namespace Kernel
@@ -55,11 +54,9 @@ public:
explicit ServiceManager(Kernel::KernelCore& kernel_);
~ServiceManager();
ResultVal<std::shared_ptr<Kernel::ServerPort>> RegisterService(std::string name,
u32 max_sessions);
ResultVal<Kernel::KServerPort*> RegisterService(std::string name, u32 max_sessions);
ResultCode UnregisterService(const std::string& name);
ResultVal<std::shared_ptr<Kernel::ClientPort>> GetServicePort(const std::string& name);
ResultVal<std::shared_ptr<Kernel::ClientSession>> ConnectToService(const std::string& name);
ResultVal<Kernel::KPort*> GetServicePort(const std::string& name);
template <Common::DerivedFrom<Kernel::SessionRequestHandler> T>
std::shared_ptr<T> GetService(const std::string& service_name) const {
@@ -68,11 +65,11 @@ public:
LOG_DEBUG(Service, "Can't find service: {}", service_name);
return nullptr;
}
auto port = service->second->GetServerPort();
auto* port = service->second;
if (port == nullptr) {
return nullptr;
}
return std::static_pointer_cast<T>(port->GetHLEHandler());
return std::static_pointer_cast<T>(port->GetServerPort().GetHLEHandler());
}
void InvokeControlRequest(Kernel::HLERequestContext& context);
@@ -81,8 +78,8 @@ private:
std::weak_ptr<SM> sm_interface;
std::unique_ptr<Controller> controller_interface;
/// Map of registered services, retrieved using GetServicePort or ConnectToService.
std::unordered_map<std::string, std::shared_ptr<Kernel::ClientPort>> registered_services;
/// Map of registered services, retrieved using GetServicePort.
std::unordered_map<std::string, Kernel::KPort*> registered_services;
/// Kernel context
Kernel::KernelCore& kernel;