mirror of
https://github.com/yuzu-emu/yuzu.git
synced 2024-07-04 23:31:19 +01:00
hle: kernel: Migrate KServerPort to KAutoObject.
This commit is contained in:
parent
0297448fbc
commit
7a06864100
8 changed files with 67 additions and 52 deletions
|
@ -205,6 +205,8 @@ add_library(core STATIC
|
|||
hle/kernel/k_scoped_lock.h
|
||||
hle/kernel/k_scoped_resource_reservation.h
|
||||
hle/kernel/k_scoped_scheduler_lock_and_sleep.h
|
||||
hle/kernel/k_server_port.cpp
|
||||
hle/kernel/k_server_port.h
|
||||
hle/kernel/k_server_session.cpp
|
||||
hle/kernel/k_server_session.h
|
||||
hle/kernel/k_session.cpp
|
||||
|
@ -237,8 +239,6 @@ add_library(core STATIC
|
|||
hle/kernel/process.h
|
||||
hle/kernel/process_capability.cpp
|
||||
hle/kernel/process_capability.h
|
||||
hle/kernel/server_port.cpp
|
||||
hle/kernel/server_port.h
|
||||
hle/kernel/service_thread.cpp
|
||||
hle/kernel/service_thread.h
|
||||
hle/kernel/slab_helpers.h
|
||||
|
|
|
@ -4,9 +4,9 @@
|
|||
|
||||
#include "core/hle/kernel/hle_ipc.h"
|
||||
#include "core/hle/kernel/k_client_port.h"
|
||||
#include "core/hle/kernel/k_server_port.h"
|
||||
#include "core/hle/kernel/k_session.h"
|
||||
#include "core/hle/kernel/object.h"
|
||||
#include "core/hle/kernel/server_port.h"
|
||||
#include "core/hle/kernel/svc_results.h"
|
||||
|
||||
namespace Kernel {
|
||||
|
@ -19,7 +19,7 @@ void KClientPort::Initialize(s32 max_sessions_, std::string&& name_) {
|
|||
name = std::move(name_);
|
||||
}
|
||||
|
||||
std::shared_ptr<ServerPort> KClientPort::GetServerPort() const {
|
||||
KServerPort* KClientPort::GetServerPort() const {
|
||||
return server_port;
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ namespace Kernel {
|
|||
|
||||
class KClientSession;
|
||||
class KernelCore;
|
||||
class ServerPort;
|
||||
class KServerPort;
|
||||
|
||||
class KClientPort final : public KSynchronizationObject {
|
||||
KERNEL_AUTOOBJECT_TRAITS(KClientPort, KSynchronizationObject);
|
||||
|
@ -24,11 +24,11 @@ public:
|
|||
explicit KClientPort(KernelCore& kernel);
|
||||
virtual ~KClientPort() override;
|
||||
|
||||
friend class ServerPort;
|
||||
friend class KServerPort;
|
||||
|
||||
void Initialize(s32 max_sessions_, std::string&& name_);
|
||||
|
||||
std::shared_ptr<ServerPort> GetServerPort() const;
|
||||
KServerPort* GetServerPort() const;
|
||||
|
||||
/**
|
||||
* Creates a new Session pair, adds the created ServerSession to the associated ServerPort's
|
||||
|
@ -63,9 +63,9 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
std::shared_ptr<ServerPort> server_port; ///< ServerPort associated with this client port.
|
||||
s32 max_sessions = 0; ///< Maximum number of simultaneous sessions the port can have
|
||||
std::atomic<s32> num_sessions = 0; ///< Number of currently open sessions to this port
|
||||
KServerPort* server_port{}; ///< ServerPort associated with this client port.
|
||||
s32 max_sessions{}; ///< Maximum number of simultaneous sessions the port can have
|
||||
std::atomic<s32> num_sessions{}; ///< Number of currently open sessions to this port
|
||||
std::string name; ///< Name of client port (optional)
|
||||
};
|
||||
|
||||
|
|
|
@ -5,18 +5,23 @@
|
|||
#include <tuple>
|
||||
#include "common/assert.h"
|
||||
#include "core/hle/kernel/k_client_port.h"
|
||||
#include "core/hle/kernel/k_server_port.h"
|
||||
#include "core/hle/kernel/k_server_session.h"
|
||||
#include "core/hle/kernel/k_thread.h"
|
||||
#include "core/hle/kernel/object.h"
|
||||
#include "core/hle/kernel/server_port.h"
|
||||
#include "core/hle/kernel/svc_results.h"
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
ServerPort::ServerPort(KernelCore& kernel) : KSynchronizationObject{kernel} {}
|
||||
ServerPort::~ServerPort() = default;
|
||||
KServerPort::KServerPort(KernelCore& kernel) : KSynchronizationObject{kernel} {}
|
||||
KServerPort::~KServerPort() = default;
|
||||
|
||||
ResultVal<KServerSession*> ServerPort::Accept() {
|
||||
void KServerPort::Initialize(std::string&& name_) {
|
||||
// Set member variables.
|
||||
name = std::move(name_);
|
||||
}
|
||||
|
||||
ResultVal<KServerSession*> KServerPort::Accept() {
|
||||
if (pending_sessions.empty()) {
|
||||
return ResultNotFound;
|
||||
}
|
||||
|
@ -26,30 +31,35 @@ ResultVal<KServerSession*> ServerPort::Accept() {
|
|||
return MakeResult(session);
|
||||
}
|
||||
|
||||
void ServerPort::AppendPendingSession(KServerSession* pending_session) {
|
||||
void KServerPort::AppendPendingSession(KServerSession* pending_session) {
|
||||
pending_sessions.push_back(std::move(pending_session));
|
||||
if (pending_sessions.size() == 1) {
|
||||
NotifyAvailable();
|
||||
}
|
||||
}
|
||||
|
||||
bool ServerPort::IsSignaled() const {
|
||||
void KServerPort::Destroy() {}
|
||||
|
||||
bool KServerPort::IsSignaled() const {
|
||||
return !pending_sessions.empty();
|
||||
}
|
||||
|
||||
ServerPort::PortPair ServerPort::CreatePortPair(KernelCore& kernel, u32 max_sessions,
|
||||
KServerPort::PortPair KServerPort::CreatePortPair(KernelCore& kernel, u32 max_sessions,
|
||||
std::string name) {
|
||||
std::shared_ptr<ServerPort> server_port = std::make_shared<ServerPort>(kernel);
|
||||
KServerPort* server_port = new KServerPort(kernel);
|
||||
KClientPort* client_port = new KClientPort(kernel);
|
||||
|
||||
KAutoObject::Create(server_port);
|
||||
KAutoObject::Create(client_port);
|
||||
|
||||
server_port->Initialize(name + "_Server");
|
||||
client_port->Initialize(max_sessions, name + "_Client");
|
||||
|
||||
client_port->server_port = server_port;
|
||||
|
||||
server_port->name = name + "_Server";
|
||||
|
||||
return std::make_pair(std::move(server_port), client_port);
|
||||
return std::make_pair(server_port, client_port);
|
||||
}
|
||||
|
||||
} // namespace Kernel
|
|
@ -20,13 +20,17 @@ class KernelCore;
|
|||
class KServerSession;
|
||||
class SessionRequestHandler;
|
||||
|
||||
class ServerPort final : public KSynchronizationObject {
|
||||
class KServerPort final : public KSynchronizationObject {
|
||||
KERNEL_AUTOOBJECT_TRAITS(KServerPort, KSynchronizationObject);
|
||||
|
||||
public:
|
||||
explicit ServerPort(KernelCore& kernel);
|
||||
~ServerPort() override;
|
||||
explicit KServerPort(KernelCore& kernel);
|
||||
virtual ~KServerPort() override;
|
||||
|
||||
using HLEHandler = std::shared_ptr<SessionRequestHandler>;
|
||||
using PortPair = std::pair<std::shared_ptr<ServerPort>, KClientPort*>;
|
||||
using PortPair = std::pair<KServerPort*, KClientPort*>;
|
||||
|
||||
void Initialize(std::string&& name_);
|
||||
|
||||
/**
|
||||
* Creates a pair of ServerPort and an associated ClientPort.
|
||||
|
@ -39,18 +43,6 @@ public:
|
|||
static PortPair CreatePortPair(KernelCore& kernel, u32 max_sessions,
|
||||
std::string name = "UnknownPort");
|
||||
|
||||
std::string GetTypeName() const override {
|
||||
return "ServerPort";
|
||||
}
|
||||
std::string GetName() const override {
|
||||
return name;
|
||||
}
|
||||
|
||||
static constexpr HandleType HANDLE_TYPE = HandleType::ServerPort;
|
||||
HandleType GetHandleType() const override {
|
||||
return HANDLE_TYPE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepts a pending incoming connection on this port. If there are no pending sessions, will
|
||||
* return ERR_NO_PENDING_SESSIONS.
|
||||
|
@ -79,9 +71,23 @@ public:
|
|||
/// waiting to be accepted by this port.
|
||||
void AppendPendingSession(KServerSession* pending_session);
|
||||
|
||||
bool IsSignaled() const override;
|
||||
// Overridden virtual functions.
|
||||
virtual void Destroy() override;
|
||||
virtual bool IsSignaled() const override;
|
||||
|
||||
void Finalize() override {}
|
||||
// DEPRECATED
|
||||
|
||||
std::string GetTypeName() const override {
|
||||
return "ServerPort";
|
||||
}
|
||||
std::string GetName() const override {
|
||||
return name;
|
||||
}
|
||||
|
||||
static constexpr HandleType HANDLE_TYPE = HandleType::ServerPort;
|
||||
HandleType GetHandleType() const override {
|
||||
return HANDLE_TYPE;
|
||||
}
|
||||
|
||||
private:
|
||||
/// ServerSessions waiting to be accepted by the port
|
|
@ -12,10 +12,10 @@
|
|||
#include "core/hle/ipc.h"
|
||||
#include "core/hle/ipc_helpers.h"
|
||||
#include "core/hle/kernel/k_client_port.h"
|
||||
#include "core/hle/kernel/k_server_port.h"
|
||||
#include "core/hle/kernel/k_thread.h"
|
||||
#include "core/hle/kernel/kernel.h"
|
||||
#include "core/hle/kernel/process.h"
|
||||
#include "core/hle/kernel/server_port.h"
|
||||
#include "core/hle/service/acc/acc.h"
|
||||
#include "core/hle/service/am/am.h"
|
||||
#include "core/hle/service/aoc/aoc_u.h"
|
||||
|
@ -117,7 +117,7 @@ void ServiceFrameworkBase::InstallAsNamedPort(Kernel::KernelCore& kernel) {
|
|||
ASSERT(!port_installed);
|
||||
|
||||
auto [server_port, client_port] =
|
||||
Kernel::ServerPort::CreatePortPair(kernel, max_sessions, service_name);
|
||||
Kernel::KServerPort::CreatePortPair(kernel, max_sessions, service_name);
|
||||
server_port->SetHleHandler(shared_from_this());
|
||||
kernel.AddNamedPort(service_name, client_port);
|
||||
port_installed = true;
|
||||
|
|
|
@ -8,9 +8,9 @@
|
|||
#include "core/hle/ipc_helpers.h"
|
||||
#include "core/hle/kernel/k_client_port.h"
|
||||
#include "core/hle/kernel/k_client_session.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/kernel/server_port.h"
|
||||
#include "core/hle/result.h"
|
||||
#include "core/hle/service/sm/controller.h"
|
||||
#include "core/hle/service/sm/sm.h"
|
||||
|
@ -49,7 +49,7 @@ 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,
|
||||
ResultVal<Kernel::KServerPort*> ServiceManager::RegisterService(std::string name,
|
||||
u32 max_sessions) {
|
||||
|
||||
CASCADE_CODE(ValidateServiceName(name));
|
||||
|
@ -60,12 +60,12 @@ ResultVal<std::shared_ptr<Kernel::ServerPort>> ServiceManager::RegisterService(s
|
|||
}
|
||||
|
||||
auto [server_port, client_port] =
|
||||
Kernel::ServerPort::CreatePortPair(kernel, max_sessions, name);
|
||||
Kernel::KServerPort::CreatePortPair(kernel, max_sessions, name);
|
||||
|
||||
client_port->Open();
|
||||
|
||||
registered_services.emplace(std::move(name), std::move(client_port));
|
||||
return MakeResult(std::move(server_port));
|
||||
registered_services.emplace(std::move(name), client_port);
|
||||
return MakeResult(server_port);
|
||||
}
|
||||
|
||||
ResultCode ServiceManager::UnregisterService(const std::string& name) {
|
||||
|
@ -172,7 +172,7 @@ void SM::RegisterService(Kernel::HLERequestContext& ctx) {
|
|||
rb.Push(handle.Code());
|
||||
|
||||
auto server_port = handle.Unwrap();
|
||||
rb.PushMoveObjects(server_port.get());
|
||||
rb.PushMoveObjects(server_port);
|
||||
}
|
||||
|
||||
void SM::UnregisterService(Kernel::HLERequestContext& ctx) {
|
||||
|
|
|
@ -11,8 +11,8 @@
|
|||
|
||||
#include "common/concepts.h"
|
||||
#include "core/hle/kernel/k_client_port.h"
|
||||
#include "core/hle/kernel/k_server_port.h"
|
||||
#include "core/hle/kernel/object.h"
|
||||
#include "core/hle/kernel/server_port.h"
|
||||
#include "core/hle/result.h"
|
||||
#include "core/hle/service/service.h"
|
||||
|
||||
|
@ -24,7 +24,7 @@ namespace Kernel {
|
|||
class KClientPort;
|
||||
class KClientSession;
|
||||
class KernelCore;
|
||||
class ServerPort;
|
||||
class KServerPort;
|
||||
class SessionRequestHandler;
|
||||
} // namespace Kernel
|
||||
|
||||
|
@ -55,8 +55,7 @@ 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<Kernel::KClientPort*> GetServicePort(const std::string& name);
|
||||
|
||||
|
|
Loading…
Reference in a new issue