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/svc.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'src/core/hle/svc.cpp') diff --git a/src/core/hle/svc.cpp b/src/core/hle/svc.cpp index c6b80dc50..be03e53bc 100644 --- a/src/core/hle/svc.cpp +++ b/src/core/hle/svc.cpp @@ -13,6 +13,7 @@ #include "core/hle/function_wrappers.h" #include "core/hle/kernel/address_arbiter.h" #include "core/hle/kernel/client_port.h" +#include "core/hle/kernel/client_session.h" #include "core/hle/kernel/event.h" #include "core/hle/kernel/memory.h" #include "core/hle/kernel/mutex.h" @@ -222,20 +223,31 @@ static ResultCode ConnectToPort(Handle* out_handle, const char* port_name) { return ERR_NOT_FOUND; } - CASCADE_RESULT(*out_handle, Kernel::g_handle_table.Create(it->second)); + 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 + CASCADE_RESULT(*out_handle, Kernel::g_handle_table.Create(client_session)); return RESULT_SUCCESS; } /// Synchronize to an OS service static ResultCode SendSyncRequest(Handle handle) { - SharedPtr session = Kernel::g_handle_table.Get(handle); + SharedPtr session = Kernel::g_handle_table.Get(handle); if (session == nullptr) { return ERR_INVALID_HANDLE; } LOG_TRACE(Kernel_SVC, "called handle=0x%08X(%s)", handle, session->GetName().c_str()); - return session->SyncRequest().Code(); + return session->HandleSyncRequest(); } /// Close a handle -- 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/svc.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src/core/hle/svc.cpp') diff --git a/src/core/hle/svc.cpp b/src/core/hle/svc.cpp index be03e53bc..6d990b5f2 100644 --- a/src/core/hle/svc.cpp +++ b/src/core/hle/svc.cpp @@ -21,6 +21,7 @@ #include "core/hle/kernel/resource_limit.h" #include "core/hle/kernel/semaphore.h" #include "core/hle/kernel/server_port.h" +#include "core/hle/kernel/server_session.h" #include "core/hle/kernel/shared_memory.h" #include "core/hle/kernel/thread.h" #include "core/hle/kernel/timer.h" @@ -223,13 +224,18 @@ static ResultCode ConnectToPort(Handle* out_handle, const char* port_name) { return ERR_NOT_FOUND; } - 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 svcCreatePort with a defined name. + 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); @@ -247,6 +253,7 @@ static ResultCode SendSyncRequest(Handle handle) { LOG_TRACE(Kernel_SVC, "called handle=0x%08X(%s)", handle, session->GetName().c_str()); + // TODO(Subv): Wait the current thread and reschedule if this request is not going to be handled by HLE code. return session->HandleSyncRequest(); } -- 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/svc.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/core/hle/svc.cpp') diff --git a/src/core/hle/svc.cpp b/src/core/hle/svc.cpp index 6d990b5f2..ab0eb9d86 100644 --- a/src/core/hle/svc.cpp +++ b/src/core/hle/svc.cpp @@ -234,11 +234,12 @@ static ResultCode ConnectToPort(Handle* out_handle, const char* port_name) { 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); + // Note: Threads do not wait for the server endpoint to call + // AcceptSession before returning from this call. + // Return the client session CASCADE_RESULT(*out_handle, Kernel::g_handle_table.Create(client_session)); return RESULT_SUCCESS; -- 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/svc.cpp | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) (limited to 'src/core/hle/svc.cpp') diff --git a/src/core/hle/svc.cpp b/src/core/hle/svc.cpp index ab0eb9d86..4189d75ac 100644 --- a/src/core/hle/svc.cpp +++ b/src/core/hle/svc.cpp @@ -224,18 +224,10 @@ static ResultCode ConnectToPort(Handle* out_handle, const char* port_name) { return ERR_NOT_FOUND; } - 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 svcCreatePort with a defined name. - auto hle_handler = std::get>(it->second); + auto client_port = 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); - - // 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(); // Note: Threads do not wait for the server endpoint to call // AcceptSession before returning from this call. @@ -254,8 +246,8 @@ static ResultCode SendSyncRequest(Handle handle) { LOG_TRACE(Kernel_SVC, "called handle=0x%08X(%s)", handle, session->GetName().c_str()); - // TODO(Subv): Wait the current thread and reschedule if this request is not going to be handled by HLE code. - return session->HandleSyncRequest(); + // TODO(Subv): svcSendSyncRequest should put the caller thread to sleep while the server responds and cause a reschedule. + return session->SendSyncRequest(); } /// Close a handle -- 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/svc.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/core/hle/svc.cpp') diff --git a/src/core/hle/svc.cpp b/src/core/hle/svc.cpp index 4189d75ac..0a2b474ee 100644 --- a/src/core/hle/svc.cpp +++ b/src/core/hle/svc.cpp @@ -227,7 +227,8 @@ static ResultCode ConnectToPort(Handle* out_handle, const char* port_name) { auto client_port = it->second; // Connect to the port and retrieve the client endpoint of the connection Session. - auto client_session = client_port->Connect(); + SharedPtr client_session; + CASCADE_RESULT(client_session, client_port->Connect()); // Note: Threads do not wait for the server endpoint to call // AcceptSession before returning from this call. -- 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/svc.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'src/core/hle/svc.cpp') diff --git a/src/core/hle/svc.cpp b/src/core/hle/svc.cpp index 0a2b474ee..f24b5c91a 100644 --- a/src/core/hle/svc.cpp +++ b/src/core/hle/svc.cpp @@ -226,19 +226,15 @@ static ResultCode ConnectToPort(Handle* out_handle, const char* port_name) { auto client_port = it->second; - // Connect to the port and retrieve the client endpoint of the connection Session. SharedPtr client_session; CASCADE_RESULT(client_session, client_port->Connect()); - // Note: Threads do not wait for the server endpoint to call - // AcceptSession before returning from this call. - // Return the client session CASCADE_RESULT(*out_handle, Kernel::g_handle_table.Create(client_session)); return RESULT_SUCCESS; } -/// Synchronize to an OS service +/// Makes a blocking IPC call to an OS service. static ResultCode SendSyncRequest(Handle handle) { SharedPtr session = Kernel::g_handle_table.Get(handle); if (session == nullptr) { -- 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/svc.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/core/hle/svc.cpp') diff --git a/src/core/hle/svc.cpp b/src/core/hle/svc.cpp index f24b5c91a..e5ba9a484 100644 --- a/src/core/hle/svc.cpp +++ b/src/core/hle/svc.cpp @@ -236,14 +236,16 @@ static ResultCode ConnectToPort(Handle* out_handle, const char* port_name) { /// Makes a blocking IPC call to an OS service. static ResultCode SendSyncRequest(Handle handle) { - SharedPtr session = Kernel::g_handle_table.Get(handle); + SharedPtr session = + Kernel::g_handle_table.Get(handle); if (session == nullptr) { return ERR_INVALID_HANDLE; } LOG_TRACE(Kernel_SVC, "called handle=0x%08X(%s)", handle, session->GetName().c_str()); - // TODO(Subv): svcSendSyncRequest should put the caller thread to sleep while the server responds and cause a reschedule. + // TODO(Subv): svcSendSyncRequest should put the caller thread to sleep while the server + // responds and cause a reschedule. return session->SendSyncRequest(); } -- cgit v1.2.3