forked from suyu/suyu
hle: kernel: Migrate KClientPort to KAutoObject.
This commit is contained in:
parent
aa2844bcf9
commit
0297448fbc
18 changed files with 92 additions and 63 deletions
|
@ -144,8 +144,6 @@ add_library(core STATIC
|
|||
hle/kernel/board/nintendo/nx/k_system_control.cpp
|
||||
hle/kernel/board/nintendo/nx/k_system_control.h
|
||||
hle/kernel/board/nintendo/nx/secure_monitor.h
|
||||
hle/kernel/client_port.cpp
|
||||
hle/kernel/client_port.h
|
||||
hle/kernel/code_set.cpp
|
||||
hle/kernel/code_set.h
|
||||
hle/kernel/svc_results.h
|
||||
|
@ -168,6 +166,8 @@ add_library(core STATIC
|
|||
hle/kernel/k_affinity_mask.h
|
||||
hle/kernel/k_class_token.cpp
|
||||
hle/kernel/k_class_token.h
|
||||
hle/kernel/k_client_port.cpp
|
||||
hle/kernel/k_client_port.h
|
||||
hle/kernel/k_client_session.cpp
|
||||
hle/kernel/k_client_session.h
|
||||
hle/kernel/k_condition_variable.cpp
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
#include "core/file_sys/vfs_concat.h"
|
||||
#include "core/file_sys/vfs_real.h"
|
||||
#include "core/hardware_interrupt_manager.h"
|
||||
#include "core/hle/kernel/client_port.h"
|
||||
#include "core/hle/kernel/k_client_port.h"
|
||||
#include "core/hle/kernel/k_scheduler.h"
|
||||
#include "core/hle/kernel/k_thread.h"
|
||||
#include "core/hle/kernel/kernel.h"
|
||||
|
|
|
@ -13,8 +13,8 @@
|
|||
#include "common/assert.h"
|
||||
#include "common/common_types.h"
|
||||
#include "core/hle/ipc.h"
|
||||
#include "core/hle/kernel/client_port.h"
|
||||
#include "core/hle/kernel/hle_ipc.h"
|
||||
#include "core/hle/kernel/k_client_port.h"
|
||||
#include "core/hle/kernel/k_session.h"
|
||||
#include "core/hle/kernel/object.h"
|
||||
#include "core/hle/result.h"
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
// Licensed under GPLv2 or any later version
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include "core/hle/kernel/client_port.h"
|
||||
#include "core/hle/kernel/hle_ipc.h"
|
||||
#include "core/hle/kernel/k_client_port.h"
|
||||
#include "core/hle/kernel/k_session.h"
|
||||
#include "core/hle/kernel/object.h"
|
||||
#include "core/hle/kernel/server_port.h"
|
||||
|
@ -11,18 +11,23 @@
|
|||
|
||||
namespace Kernel {
|
||||
|
||||
ClientPort::ClientPort(KernelCore& kernel) : Object{kernel} {}
|
||||
ClientPort::~ClientPort() = default;
|
||||
KClientPort::KClientPort(KernelCore& kernel) : KSynchronizationObject{kernel} {}
|
||||
KClientPort::~KClientPort() = default;
|
||||
|
||||
std::shared_ptr<ServerPort> ClientPort::GetServerPort() const {
|
||||
void KClientPort::Initialize(s32 max_sessions_, std::string&& name_) {
|
||||
max_sessions = max_sessions_;
|
||||
name = std::move(name_);
|
||||
}
|
||||
|
||||
std::shared_ptr<ServerPort> KClientPort::GetServerPort() const {
|
||||
return server_port;
|
||||
}
|
||||
|
||||
ResultVal<KClientSession*> ClientPort::Connect() {
|
||||
if (active_sessions >= max_sessions) {
|
||||
ResultVal<KClientSession*> KClientPort::Connect() {
|
||||
if (num_sessions >= max_sessions) {
|
||||
return ResultOutOfSessions;
|
||||
}
|
||||
active_sessions++;
|
||||
num_sessions++;
|
||||
|
||||
auto* session = Kernel::KSession::Create(kernel);
|
||||
session->Initialize(name + ":ClientPort");
|
||||
|
@ -36,12 +41,18 @@ ResultVal<KClientSession*> ClientPort::Connect() {
|
|||
return MakeResult(std::addressof(session->GetClientSession()));
|
||||
}
|
||||
|
||||
void ClientPort::ConnectionClosed() {
|
||||
if (active_sessions == 0) {
|
||||
void KClientPort::ConnectionClosed() {
|
||||
if (num_sessions == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
--active_sessions;
|
||||
--num_sessions;
|
||||
}
|
||||
|
||||
void KClientPort::Destroy() {}
|
||||
|
||||
bool KClientPort::IsSignaled() const {
|
||||
return num_sessions < max_sessions;
|
||||
}
|
||||
|
||||
} // namespace Kernel
|
|
@ -8,7 +8,7 @@
|
|||
#include <string>
|
||||
|
||||
#include "common/common_types.h"
|
||||
#include "core/hle/kernel/object.h"
|
||||
#include "core/hle/kernel/k_synchronization_object.h"
|
||||
#include "core/hle/result.h"
|
||||
|
||||
namespace Kernel {
|
||||
|
@ -17,23 +17,16 @@ class KClientSession;
|
|||
class KernelCore;
|
||||
class ServerPort;
|
||||
|
||||
class ClientPort final : public Object {
|
||||
class KClientPort final : public KSynchronizationObject {
|
||||
KERNEL_AUTOOBJECT_TRAITS(KClientPort, KSynchronizationObject);
|
||||
|
||||
public:
|
||||
explicit ClientPort(KernelCore& kernel);
|
||||
~ClientPort() override;
|
||||
explicit KClientPort(KernelCore& kernel);
|
||||
virtual ~KClientPort() override;
|
||||
|
||||
friend class ServerPort;
|
||||
std::string GetTypeName() const override {
|
||||
return "ClientPort";
|
||||
}
|
||||
std::string GetName() const override {
|
||||
return name;
|
||||
}
|
||||
|
||||
static constexpr HandleType HANDLE_TYPE = HandleType::ClientPort;
|
||||
HandleType GetHandleType() const override {
|
||||
return HANDLE_TYPE;
|
||||
}
|
||||
void Initialize(s32 max_sessions_, std::string&& name_);
|
||||
|
||||
std::shared_ptr<ServerPort> GetServerPort() const;
|
||||
|
||||
|
@ -51,13 +44,29 @@ public:
|
|||
*/
|
||||
void ConnectionClosed();
|
||||
|
||||
void Finalize() override {}
|
||||
// Overridden virtual functions.
|
||||
virtual void Destroy() override;
|
||||
virtual bool IsSignaled() const override;
|
||||
|
||||
// DEPRECATED
|
||||
|
||||
std::string GetTypeName() const override {
|
||||
return "ClientPort";
|
||||
}
|
||||
std::string GetName() const override {
|
||||
return name;
|
||||
}
|
||||
|
||||
static constexpr HandleType HANDLE_TYPE = HandleType::ClientPort;
|
||||
HandleType GetHandleType() const override {
|
||||
return HANDLE_TYPE;
|
||||
}
|
||||
|
||||
private:
|
||||
std::shared_ptr<ServerPort> server_port; ///< ServerPort associated with this client port.
|
||||
u32 max_sessions = 0; ///< Maximum number of simultaneous sessions the port can have
|
||||
u32 active_sessions = 0; ///< Number of currently open sessions to this port
|
||||
std::string name; ///< Name of client port (optional)
|
||||
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
|
||||
std::string name; ///< Name of client port (optional)
|
||||
};
|
||||
|
||||
} // namespace Kernel
|
|
@ -10,9 +10,9 @@
|
|||
#include "common/logging/log.h"
|
||||
#include "core/core_timing.h"
|
||||
#include "core/hle/ipc_helpers.h"
|
||||
#include "core/hle/kernel/client_port.h"
|
||||
#include "core/hle/kernel/handle_table.h"
|
||||
#include "core/hle/kernel/hle_ipc.h"
|
||||
#include "core/hle/kernel/k_client_port.h"
|
||||
#include "core/hle/kernel/k_scheduler.h"
|
||||
#include "core/hle/kernel/k_server_session.h"
|
||||
#include "core/hle/kernel/k_session.h"
|
||||
|
|
|
@ -70,7 +70,7 @@ public:
|
|||
return server;
|
||||
}
|
||||
|
||||
const ClientPort* GetParent() const {
|
||||
const KClientPort* GetParent() const {
|
||||
return port;
|
||||
}
|
||||
|
||||
|
@ -99,7 +99,7 @@ private:
|
|||
KClientSession client;
|
||||
std::atomic<std::underlying_type<State>::type> atomic_state{
|
||||
static_cast<std::underlying_type<State>::type>(State::Invalid)};
|
||||
ClientPort* port{};
|
||||
KClientPort* port{};
|
||||
std::string name;
|
||||
Process* process{};
|
||||
bool initialized{};
|
||||
|
|
|
@ -26,9 +26,9 @@
|
|||
#include "core/cpu_manager.h"
|
||||
#include "core/device_memory.h"
|
||||
#include "core/hardware_properties.h"
|
||||
#include "core/hle/kernel/client_port.h"
|
||||
#include "core/hle/kernel/handle_table.h"
|
||||
#include "core/hle/kernel/init/init_slab_setup.h"
|
||||
#include "core/hle/kernel/k_client_port.h"
|
||||
#include "core/hle/kernel/k_memory_layout.h"
|
||||
#include "core/hle/kernel/k_memory_manager.h"
|
||||
#include "core/hle/kernel/k_resource_limit.h"
|
||||
|
@ -122,6 +122,9 @@ struct KernelCore::Impl {
|
|||
|
||||
preemption_event = nullptr;
|
||||
|
||||
for (auto& iter : named_ports) {
|
||||
iter.second->Close();
|
||||
}
|
||||
named_ports.clear();
|
||||
|
||||
exclusive_monitor.reset();
|
||||
|
@ -843,8 +846,9 @@ void KernelCore::PrepareReschedule(std::size_t id) {
|
|||
// TODO: Reimplement, this
|
||||
}
|
||||
|
||||
void KernelCore::AddNamedPort(std::string name, std::shared_ptr<ClientPort> port) {
|
||||
impl->named_ports.emplace(std::move(name), std::move(port));
|
||||
void KernelCore::AddNamedPort(std::string name, KClientPort* port) {
|
||||
port->Open();
|
||||
impl->named_ports.emplace(std::move(name), port);
|
||||
}
|
||||
|
||||
KernelCore::NamedPortTable::iterator KernelCore::FindNamedPort(const std::string& name) {
|
||||
|
|
|
@ -29,7 +29,7 @@ struct EventType;
|
|||
|
||||
namespace Kernel {
|
||||
|
||||
class ClientPort;
|
||||
class KClientPort;
|
||||
class GlobalSchedulerContext;
|
||||
class HandleTable;
|
||||
class KAutoObjectWithListContainer;
|
||||
|
@ -60,7 +60,7 @@ constexpr EmuThreadHandle EmuThreadHandleReserved{1ULL << 63};
|
|||
/// Represents a single instance of the kernel.
|
||||
class KernelCore {
|
||||
private:
|
||||
using NamedPortTable = std::unordered_map<std::string, std::shared_ptr<ClientPort>>;
|
||||
using NamedPortTable = std::unordered_map<std::string, KClientPort*>;
|
||||
|
||||
public:
|
||||
/// Constructs an instance of the kernel using the given System
|
||||
|
@ -168,7 +168,7 @@ public:
|
|||
void InvalidateCpuInstructionCacheRange(VAddr addr, std::size_t size);
|
||||
|
||||
/// Adds a port to the named port table
|
||||
void AddNamedPort(std::string name, std::shared_ptr<ClientPort> port);
|
||||
void AddNamedPort(std::string name, KClientPort* port);
|
||||
|
||||
/// Finds a port within the named port table with the given name.
|
||||
NamedPortTable::iterator FindNamedPort(const std::string& name);
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
#include <tuple>
|
||||
#include "common/assert.h"
|
||||
#include "core/hle/kernel/client_port.h"
|
||||
#include "core/hle/kernel/k_client_port.h"
|
||||
#include "core/hle/kernel/k_server_session.h"
|
||||
#include "core/hle/kernel/k_thread.h"
|
||||
#include "core/hle/kernel/object.h"
|
||||
|
@ -40,15 +40,16 @@ bool ServerPort::IsSignaled() const {
|
|||
ServerPort::PortPair ServerPort::CreatePortPair(KernelCore& kernel, u32 max_sessions,
|
||||
std::string name) {
|
||||
std::shared_ptr<ServerPort> server_port = std::make_shared<ServerPort>(kernel);
|
||||
std::shared_ptr<ClientPort> client_port = std::make_shared<ClientPort>(kernel);
|
||||
KClientPort* client_port = new KClientPort(kernel);
|
||||
|
||||
KAutoObject::Create(client_port);
|
||||
|
||||
client_port->Initialize(max_sessions, name + "_Client");
|
||||
client_port->server_port = server_port;
|
||||
|
||||
server_port->name = name + "_Server";
|
||||
client_port->name = name + "_Client";
|
||||
client_port->server_port = server_port;
|
||||
client_port->max_sessions = max_sessions;
|
||||
client_port->active_sessions = 0;
|
||||
|
||||
return std::make_pair(std::move(server_port), std::move(client_port));
|
||||
return std::make_pair(std::move(server_port), client_port);
|
||||
}
|
||||
|
||||
} // namespace Kernel
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
|
||||
namespace Kernel {
|
||||
|
||||
class ClientPort;
|
||||
class KClientPort;
|
||||
class KernelCore;
|
||||
class KServerSession;
|
||||
class SessionRequestHandler;
|
||||
|
@ -26,7 +26,7 @@ public:
|
|||
~ServerPort() override;
|
||||
|
||||
using HLEHandler = std::shared_ptr<SessionRequestHandler>;
|
||||
using PortPair = std::pair<std::shared_ptr<ServerPort>, std::shared_ptr<ClientPort>>;
|
||||
using PortPair = std::pair<std::shared_ptr<ServerPort>, KClientPort*>;
|
||||
|
||||
/**
|
||||
* Creates a pair of ServerPort and an associated ClientPort.
|
||||
|
|
|
@ -21,9 +21,9 @@
|
|||
#include "core/core_timing.h"
|
||||
#include "core/core_timing_util.h"
|
||||
#include "core/cpu_manager.h"
|
||||
#include "core/hle/kernel/client_port.h"
|
||||
#include "core/hle/kernel/handle_table.h"
|
||||
#include "core/hle/kernel/k_address_arbiter.h"
|
||||
#include "core/hle/kernel/k_client_port.h"
|
||||
#include "core/hle/kernel/k_client_session.h"
|
||||
#include "core/hle/kernel/k_condition_variable.h"
|
||||
#include "core/hle/kernel/k_event.h"
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
#include "core/frontend/input.h"
|
||||
#include "core/hardware_properties.h"
|
||||
#include "core/hle/ipc_helpers.h"
|
||||
#include "core/hle/kernel/client_port.h"
|
||||
#include "core/hle/kernel/k_client_port.h"
|
||||
#include "core/hle/kernel/k_readable_event.h"
|
||||
#include "core/hle/kernel/k_shared_memory.h"
|
||||
#include "core/hle/kernel/k_transfer_memory.h"
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
#include "core/core.h"
|
||||
#include "core/hle/ipc.h"
|
||||
#include "core/hle/ipc_helpers.h"
|
||||
#include "core/hle/kernel/client_port.h"
|
||||
#include "core/hle/kernel/k_client_port.h"
|
||||
#include "core/hle/kernel/k_thread.h"
|
||||
#include "core/hle/kernel/kernel.h"
|
||||
#include "core/hle/kernel/process.h"
|
||||
|
@ -119,7 +119,7 @@ void ServiceFrameworkBase::InstallAsNamedPort(Kernel::KernelCore& kernel) {
|
|||
auto [server_port, client_port] =
|
||||
Kernel::ServerPort::CreatePortPair(kernel, max_sessions, service_name);
|
||||
server_port->SetHleHandler(shared_from_this());
|
||||
kernel.AddNamedPort(service_name, std::move(client_port));
|
||||
kernel.AddNamedPort(service_name, client_port);
|
||||
port_installed = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
#include "core/file_sys/errors.h"
|
||||
#include "core/file_sys/system_archive/system_version.h"
|
||||
#include "core/hle/ipc_helpers.h"
|
||||
#include "core/hle/kernel/client_port.h"
|
||||
#include "core/hle/kernel/k_client_port.h"
|
||||
#include "core/hle/service/filesystem/filesystem.h"
|
||||
#include "core/hle/service/set/set_sys.h"
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
#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/k_client_port.h"
|
||||
#include "core/hle/kernel/k_client_session.h"
|
||||
#include "core/hle/kernel/k_server_session.h"
|
||||
#include "core/hle/kernel/k_session.h"
|
||||
|
@ -62,6 +62,8 @@ ResultVal<std::shared_ptr<Kernel::ServerPort>> ServiceManager::RegisterService(s
|
|||
auto [server_port, client_port] =
|
||||
Kernel::ServerPort::CreatePortPair(kernel, max_sessions, name);
|
||||
|
||||
client_port->Open();
|
||||
|
||||
registered_services.emplace(std::move(name), std::move(client_port));
|
||||
return MakeResult(std::move(server_port));
|
||||
}
|
||||
|
@ -74,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::KClientPort*> ServiceManager::GetServicePort(const std::string& name) {
|
||||
|
||||
CASCADE_CODE(ValidateServiceName(name));
|
||||
auto it = registered_services.find(name);
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
#include <unordered_map>
|
||||
|
||||
#include "common/concepts.h"
|
||||
#include "core/hle/kernel/client_port.h"
|
||||
#include "core/hle/kernel/k_client_port.h"
|
||||
#include "core/hle/kernel/object.h"
|
||||
#include "core/hle/kernel/server_port.h"
|
||||
#include "core/hle/result.h"
|
||||
|
@ -21,7 +21,7 @@ class System;
|
|||
}
|
||||
|
||||
namespace Kernel {
|
||||
class ClientPort;
|
||||
class KClientPort;
|
||||
class KClientSession;
|
||||
class KernelCore;
|
||||
class ServerPort;
|
||||
|
@ -58,7 +58,7 @@ public:
|
|||
ResultVal<std::shared_ptr<Kernel::ServerPort>> 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<Kernel::KClientPort*> GetServicePort(const std::string& name);
|
||||
|
||||
template <Common::DerivedFrom<Kernel::SessionRequestHandler> T>
|
||||
std::shared_ptr<T> GetService(const std::string& service_name) const {
|
||||
|
@ -81,7 +81,7 @@ private:
|
|||
std::unique_ptr<Controller> controller_interface;
|
||||
|
||||
/// Map of registered services, retrieved using GetServicePort.
|
||||
std::unordered_map<std::string, std::shared_ptr<Kernel::ClientPort>> registered_services;
|
||||
std::unordered_map<std::string, Kernel::KClientPort*> registered_services;
|
||||
|
||||
/// Kernel context
|
||||
Kernel::KernelCore& kernel;
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
#include "core/core_timing_util.h"
|
||||
#include "core/hardware_properties.h"
|
||||
#include "core/hle/ipc_helpers.h"
|
||||
#include "core/hle/kernel/client_port.h"
|
||||
#include "core/hle/kernel/k_client_port.h"
|
||||
#include "core/hle/kernel/k_scheduler.h"
|
||||
#include "core/hle/kernel/kernel.h"
|
||||
#include "core/hle/service/time/interface.h"
|
||||
|
|
Loading…
Reference in a new issue