summaryrefslogtreecommitdiffstats
path: root/src/core/hle
diff options
context:
space:
mode:
authorbunnei <bunneidev@gmail.com>2021-04-22 06:43:25 +0200
committerbunnei <bunneidev@gmail.com>2021-05-06 01:40:52 +0200
commit0297448fbc6bf909b0bc061723c38208b9667b66 (patch)
tree7c21303536466b0a76331e4274ecb3e12eb40421 /src/core/hle
parenthle: kernel: HandleTable: Remove deprecated APIs. (diff)
downloadyuzu-0297448fbc6bf909b0bc061723c38208b9667b66.tar
yuzu-0297448fbc6bf909b0bc061723c38208b9667b66.tar.gz
yuzu-0297448fbc6bf909b0bc061723c38208b9667b66.tar.bz2
yuzu-0297448fbc6bf909b0bc061723c38208b9667b66.tar.lz
yuzu-0297448fbc6bf909b0bc061723c38208b9667b66.tar.xz
yuzu-0297448fbc6bf909b0bc061723c38208b9667b66.tar.zst
yuzu-0297448fbc6bf909b0bc061723c38208b9667b66.zip
Diffstat (limited to 'src/core/hle')
-rw-r--r--src/core/hle/ipc_helpers.h2
-rw-r--r--src/core/hle/kernel/k_client_port.cpp (renamed from src/core/hle/kernel/client_port.cpp)31
-rw-r--r--src/core/hle/kernel/k_client_port.h (renamed from src/core/hle/kernel/client_port.h)45
-rw-r--r--src/core/hle/kernel/k_server_session.cpp2
-rw-r--r--src/core/hle/kernel/k_session.h4
-rw-r--r--src/core/hle/kernel/kernel.cpp10
-rw-r--r--src/core/hle/kernel/kernel.h6
-rw-r--r--src/core/hle/kernel/server_port.cpp15
-rw-r--r--src/core/hle/kernel/server_port.h4
-rw-r--r--src/core/hle/kernel/svc.cpp2
-rw-r--r--src/core/hle/service/hid/hid.cpp2
-rw-r--r--src/core/hle/service/service.cpp4
-rw-r--r--src/core/hle/service/set/set_sys.cpp2
-rw-r--r--src/core/hle/service/sm/sm.cpp10
-rw-r--r--src/core/hle/service/sm/sm.h8
-rw-r--r--src/core/hle/service/time/time.cpp2
16 files changed, 89 insertions, 60 deletions
diff --git a/src/core/hle/ipc_helpers.h b/src/core/hle/ipc_helpers.h
index 99b7d3d82..18aebf6ea 100644
--- a/src/core/hle/ipc_helpers.h
+++ b/src/core/hle/ipc_helpers.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"
diff --git a/src/core/hle/kernel/client_port.cpp b/src/core/hle/kernel/k_client_port.cpp
index ce88da1c3..15bf0d4fc 100644
--- a/src/core/hle/kernel/client_port.cpp
+++ b/src/core/hle/kernel/k_client_port.cpp
@@ -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
diff --git a/src/core/hle/kernel/client_port.h b/src/core/hle/kernel/k_client_port.h
index 0b20fef40..04ee2d664 100644
--- a/src/core/hle/kernel/client_port.h
+++ b/src/core/hle/kernel/k_client_port.h
@@ -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
diff --git a/src/core/hle/kernel/k_server_session.cpp b/src/core/hle/kernel/k_server_session.cpp
index 8cd2c283c..46ba7081b 100644
--- a/src/core/hle/kernel/k_server_session.cpp
+++ b/src/core/hle/kernel/k_server_session.cpp
@@ -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"
diff --git a/src/core/hle/kernel/k_session.h b/src/core/hle/kernel/k_session.h
index 1d24e80cd..6a6fcb588 100644
--- a/src/core/hle/kernel/k_session.h
+++ b/src/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{};
diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp
index ada993f46..c939bb903 100644
--- a/src/core/hle/kernel/kernel.cpp
+++ b/src/core/hle/kernel/kernel.cpp
@@ -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) {
diff --git a/src/core/hle/kernel/kernel.h b/src/core/hle/kernel/kernel.h
index 43e49603b..19b3530b4 100644
--- a/src/core/hle/kernel/kernel.h
+++ b/src/core/hle/kernel/kernel.h
@@ -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);
diff --git a/src/core/hle/kernel/server_port.cpp b/src/core/hle/kernel/server_port.cpp
index 8626b56fd..addaaa5cf 100644
--- a/src/core/hle/kernel/server_port.cpp
+++ b/src/core/hle/kernel/server_port.cpp
@@ -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);
- server_port->name = name + "_Server";
- client_port->name = name + "_Client";
+ KAutoObject::Create(client_port);
+
+ client_port->Initialize(max_sessions, 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));
+ server_port->name = name + "_Server";
+
+ return std::make_pair(std::move(server_port), client_port);
}
} // namespace Kernel
diff --git a/src/core/hle/kernel/server_port.h b/src/core/hle/kernel/server_port.h
index eebceaa2a..f7d443df8 100644
--- a/src/core/hle/kernel/server_port.h
+++ b/src/core/hle/kernel/server_port.h
@@ -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.
diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp
index fa85bd631..8d8d3dd5a 100644
--- a/src/core/hle/kernel/svc.cpp
+++ b/src/core/hle/kernel/svc.cpp
@@ -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"
diff --git a/src/core/hle/service/hid/hid.cpp b/src/core/hle/service/hid/hid.cpp
index d831aa214..49c17fd14 100644
--- a/src/core/hle/service/hid/hid.cpp
+++ b/src/core/hle/service/hid/hid.cpp
@@ -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"
diff --git a/src/core/hle/service/service.cpp b/src/core/hle/service/service.cpp
index 41a502d8d..d8ad09b49 100644
--- a/src/core/hle/service/service.cpp
+++ b/src/core/hle/service/service.cpp
@@ -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;
}
diff --git a/src/core/hle/service/set/set_sys.cpp b/src/core/hle/service/set/set_sys.cpp
index 5909fdd85..4f1ffe55f 100644
--- a/src/core/hle/service/set/set_sys.cpp
+++ b/src/core/hle/service/set/set_sys.cpp
@@ -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"
diff --git a/src/core/hle/service/sm/sm.cpp b/src/core/hle/service/sm/sm.cpp
index 66e41277f..39575ce3d 100644
--- a/src/core/hle/service/sm/sm.cpp
+++ b/src/core/hle/service/sm/sm.cpp
@@ -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);
diff --git a/src/core/hle/service/sm/sm.h b/src/core/hle/service/sm/sm.h
index 8f6862fa9..aee9aefec 100644
--- a/src/core/hle/service/sm/sm.h
+++ b/src/core/hle/service/sm/sm.h
@@ -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;
diff --git a/src/core/hle/service/time/time.cpp b/src/core/hle/service/time/time.cpp
index 413a00ae0..e7991012b 100644
--- a/src/core/hle/service/time/time.cpp
+++ b/src/core/hle/service/time/time.cpp
@@ -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"