From 073653e858abf377fd1ebbdb071809c8830ce99d Mon Sep 17 00:00:00 2001 From: Subv Date: Tue, 14 Jun 2016 18:03:30 -0500 Subject: Kernel/IPC: Use Ports and Sessions as the fundamental building block of Inter Process Communication. All handles obtained via srv::GetServiceHandle or svcConnectToPort are references to ClientSessions. Service modules will wait on the counterpart of those ClientSessions (Called ServerSessions) using svcReplyAndReceive or svcWaitSynchronization[1|N], and will be awoken when a SyncRequest is performed. HLE Interfaces are now ClientPorts which override the HandleSyncRequest virtual member function to perform command handling immediately. --- src/core/hle/service/srv.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'src/core/hle/service/srv.cpp') diff --git a/src/core/hle/service/srv.cpp b/src/core/hle/service/srv.cpp index b25be413a..eb2e06041 100644 --- a/src/core/hle/service/srv.cpp +++ b/src/core/hle/service/srv.cpp @@ -2,8 +2,12 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. +#include + #include "common/common_types.h" #include "common/logging/log.h" +#include "core/hle/service/srv.h" +#include "core/hle/kernel/client_session.h" #include "core/hle/kernel/event.h" #include "core/hle/service/srv.h" @@ -81,7 +85,18 @@ static void GetServiceHandle(Service::Interface* self) { auto it = Service::g_srv_services.find(port_name); if (it != Service::g_srv_services.end()) { - cmd_buff[3] = Kernel::g_handle_table.Create(it->second).MoveFrom(); + auto client_port = it->second; + + // Create a new session pair + auto sessions = Kernel::ServerSession::CreateSessionPair(client_port, port_name); + auto client_session = std::get>(sessions); + auto server_session = std::get>(sessions); + + // Add the server session to the port's queue + client_port->AddWaitingSession(server_session); + + // Return the client session + cmd_buff[3] = Kernel::g_handle_table.Create(client_session).MoveFrom(); LOG_TRACE(Service_SRV, "called port=%s, handle=0x%08X", port_name.c_str(), cmd_buff[3]); } else { LOG_ERROR(Service_SRV, "(UNIMPLEMENTED) called port=%s", port_name.c_str()); -- cgit v1.2.3 From 009b15b3aa9858930f461d825f7dd030fc963801 Mon Sep 17 00:00:00 2001 From: Subv Date: Wed, 30 Nov 2016 22:50:13 -0500 Subject: A bit of a redesign. Sessions and Ports are now detached from each other. HLE services are handled by means of a SessionRequestHandler class, Interface now inherits from this class. The File and Directory classes are no longer kernel objects, but SessionRequestHandlers instead, bound to a ServerSession when requested. File::OpenLinkFile now creates a new session pair and binds the File instance to it. --- src/core/hle/service/srv.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src/core/hle/service/srv.cpp') diff --git a/src/core/hle/service/srv.cpp b/src/core/hle/service/srv.cpp index eb2e06041..6731afc22 100644 --- a/src/core/hle/service/srv.cpp +++ b/src/core/hle/service/srv.cpp @@ -10,6 +10,7 @@ #include "core/hle/kernel/client_session.h" #include "core/hle/kernel/event.h" #include "core/hle/service/srv.h" +#include "core/hle/kernel/server_session.h" //////////////////////////////////////////////////////////////////////////////////////////////////// // Namespace SRV @@ -85,13 +86,18 @@ static void GetServiceHandle(Service::Interface* self) { auto it = Service::g_srv_services.find(port_name); if (it != Service::g_srv_services.end()) { - auto client_port = it->second; + auto client_port = std::get>(it->second); + // The hle_handler will be nullptr if this port was registered by the emulated + // application by means of srv:RegisterService. + auto hle_handler = std::get>(it->second); // Create a new session pair - auto sessions = Kernel::ServerSession::CreateSessionPair(client_port, port_name); + auto sessions = Kernel::ServerSession::CreateSessionPair(port_name, hle_handler); auto client_session = std::get>(sessions); auto server_session = std::get>(sessions); + // TODO(Subv): Wait the current thread until the ServerPort calls AcceptSession. + // Add the server session to the port's queue client_port->AddWaitingSession(server_session); -- cgit v1.2.3 From 2eceee3a4cc2786dae4e9b80a8b5f3bb666d3fc6 Mon Sep 17 00:00:00 2001 From: Subv Date: Wed, 30 Nov 2016 23:28:31 -0500 Subject: Fixed the rebase mistakes. --- src/core/hle/service/srv.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/core/hle/service/srv.cpp') diff --git a/src/core/hle/service/srv.cpp b/src/core/hle/service/srv.cpp index 6731afc22..d228e3523 100644 --- a/src/core/hle/service/srv.cpp +++ b/src/core/hle/service/srv.cpp @@ -6,11 +6,10 @@ #include "common/common_types.h" #include "common/logging/log.h" -#include "core/hle/service/srv.h" #include "core/hle/kernel/client_session.h" +#include "core/hle/kernel/server_session.h" #include "core/hle/kernel/event.h" #include "core/hle/service/srv.h" -#include "core/hle/kernel/server_session.h" //////////////////////////////////////////////////////////////////////////////////////////////////// // Namespace SRV -- cgit v1.2.3 From ed210c32b3820c77845c27d1f73e6ff2f0828505 Mon Sep 17 00:00:00 2001 From: Subv Date: Thu, 1 Dec 2016 10:47:06 -0500 Subject: Threads do not wait for the server endpoint to call AcceptSession before returning from a ConnectToPort or GetServiceHandle call. --- src/core/hle/service/srv.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/core/hle/service/srv.cpp') diff --git a/src/core/hle/service/srv.cpp b/src/core/hle/service/srv.cpp index d228e3523..c0abfd711 100644 --- a/src/core/hle/service/srv.cpp +++ b/src/core/hle/service/srv.cpp @@ -95,7 +95,8 @@ static void GetServiceHandle(Service::Interface* self) { auto client_session = std::get>(sessions); auto server_session = std::get>(sessions); - // TODO(Subv): Wait the current thread until the ServerPort calls AcceptSession. + // Note: Threads do not wait for the server endpoint to call + // AcceptSession before returning from this call. // Add the server session to the port's queue client_port->AddWaitingSession(server_session); -- cgit v1.2.3 From dd8887c8cfbb6d3010dde240278a3d4018c5dd85 Mon Sep 17 00:00:00 2001 From: Subv Date: Mon, 5 Dec 2016 11:02:08 -0500 Subject: KServerPorts now have an HLE handler "template", which is inherited by all ServerSessions created from it. --- src/core/hle/service/srv.cpp | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) (limited to 'src/core/hle/service/srv.cpp') diff --git a/src/core/hle/service/srv.cpp b/src/core/hle/service/srv.cpp index c0abfd711..bb2c8fcc4 100644 --- a/src/core/hle/service/srv.cpp +++ b/src/core/hle/service/srv.cpp @@ -85,21 +85,13 @@ static void GetServiceHandle(Service::Interface* self) { auto it = Service::g_srv_services.find(port_name); if (it != Service::g_srv_services.end()) { - auto client_port = std::get>(it->second); - // The hle_handler will be nullptr if this port was registered by the emulated - // application by means of srv:RegisterService. - auto hle_handler = std::get>(it->second); - - // Create a new session pair - auto sessions = Kernel::ServerSession::CreateSessionPair(port_name, hle_handler); - auto client_session = std::get>(sessions); - auto server_session = std::get>(sessions); + auto client_port = it->second; // Note: Threads do not wait for the server endpoint to call // AcceptSession before returning from this call. - // Add the server session to the port's queue - client_port->AddWaitingSession(server_session); + // Connect to the port and retrieve the client endpoint of the connection Session. + auto client_session = client_port->Connect(); // Return the client session cmd_buff[3] = Kernel::g_handle_table.Create(client_session).MoveFrom(); -- cgit v1.2.3 From c93c5a72bb46796e898f54a7c13dfb8d941ddd4d Mon Sep 17 00:00:00 2001 From: Subv Date: Mon, 5 Dec 2016 13:59:57 -0500 Subject: Return an error code when connecting to a saturated port. The error code was taken from the 3DS kernel. --- src/core/hle/service/srv.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/core/hle/service/srv.cpp') diff --git a/src/core/hle/service/srv.cpp b/src/core/hle/service/srv.cpp index bb2c8fcc4..ff7a84347 100644 --- a/src/core/hle/service/srv.cpp +++ b/src/core/hle/service/srv.cpp @@ -93,8 +93,12 @@ static void GetServiceHandle(Service::Interface* self) { // Connect to the port and retrieve the client endpoint of the connection Session. auto client_session = client_port->Connect(); - // Return the client session - cmd_buff[3] = Kernel::g_handle_table.Create(client_session).MoveFrom(); + res = client_session.Code(); + + if (client_session.Succeeded()) { + // Return the client session + cmd_buff[3] = Kernel::g_handle_table.Create(*client_session).MoveFrom(); + } LOG_TRACE(Service_SRV, "called port=%s, handle=0x%08X", port_name.c_str(), cmd_buff[3]); } else { LOG_ERROR(Service_SRV, "(UNIMPLEMENTED) called port=%s", port_name.c_str()); -- cgit v1.2.3 From f9bcf895103e5a6d99f5fe755bcac92b7781fd38 Mon Sep 17 00:00:00 2001 From: Subv Date: Thu, 8 Dec 2016 11:06:19 -0500 Subject: Use std::move where appropriate. --- src/core/hle/service/srv.cpp | 5 ----- 1 file changed, 5 deletions(-) (limited to 'src/core/hle/service/srv.cpp') diff --git a/src/core/hle/service/srv.cpp b/src/core/hle/service/srv.cpp index ff7a84347..37420201b 100644 --- a/src/core/hle/service/srv.cpp +++ b/src/core/hle/service/srv.cpp @@ -87,12 +87,7 @@ static void GetServiceHandle(Service::Interface* self) { if (it != Service::g_srv_services.end()) { auto client_port = it->second; - // Note: Threads do not wait for the server endpoint to call - // AcceptSession before returning from this call. - - // Connect to the port and retrieve the client endpoint of the connection Session. auto client_session = client_port->Connect(); - res = client_session.Code(); if (client_session.Succeeded()) { -- cgit v1.2.3 From 016307ae656afc85ab59a5c2598205ef81f99231 Mon Sep 17 00:00:00 2001 From: Subv Date: Wed, 14 Dec 2016 12:33:49 -0500 Subject: Fixed the codestyle to match our clang-format rules. --- src/core/hle/service/srv.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/core/hle/service/srv.cpp') diff --git a/src/core/hle/service/srv.cpp b/src/core/hle/service/srv.cpp index 37420201b..18d0a699d 100644 --- a/src/core/hle/service/srv.cpp +++ b/src/core/hle/service/srv.cpp @@ -7,8 +7,8 @@ #include "common/common_types.h" #include "common/logging/log.h" #include "core/hle/kernel/client_session.h" -#include "core/hle/kernel/server_session.h" #include "core/hle/kernel/event.h" +#include "core/hle/kernel/server_session.h" #include "core/hle/service/srv.h" //////////////////////////////////////////////////////////////////////////////////////////////////// -- cgit v1.2.3