From aa0f3047d367819acdd4333c8290992b99433073 Mon Sep 17 00:00:00 2001 From: Yuri Kunde Schlesner Date: Thu, 22 Jun 2017 23:54:36 -0700 Subject: Kernel: Implement CreateSessionToPort SVC --- src/core/hle/svc.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/core/hle/svc.cpp b/src/core/hle/svc.cpp index f459b1314..2e11d41ce 100644 --- a/src/core/hle/svc.cpp +++ b/src/core/hle/svc.cpp @@ -947,6 +947,17 @@ static ResultCode CreatePort(Kernel::Handle* server_port, Kernel::Handle* client return RESULT_SUCCESS; } +static ResultCode CreateSessionToPort(Handle* out_client_session, Handle client_port_handle) { + using Kernel::ClientPort; + SharedPtr client_port = Kernel::g_handle_table.Get(client_port_handle); + if (client_port == nullptr) + return ERR_INVALID_HANDLE; + + CASCADE_RESULT(auto session, client_port->Connect()); + CASCADE_RESULT(*out_client_session, Kernel::g_handle_table.Create(std::move(session))); + return RESULT_SUCCESS; +} + static ResultCode CreateSession(Handle* server_session, Handle* client_session) { auto sessions = Kernel::ServerSession::CreateSessionPair(); @@ -1134,7 +1145,7 @@ static const FunctionDef SVC_Table[] = { {0x45, nullptr, "Unknown"}, {0x46, nullptr, "Unknown"}, {0x47, HLE::Wrap, "CreatePort"}, - {0x48, nullptr, "CreateSessionToPort"}, + {0x48, HLE::Wrap, "CreateSessionToPort"}, {0x49, HLE::Wrap, "CreateSession"}, {0x4A, nullptr, "AcceptSession"}, {0x4B, nullptr, "ReplyAndReceive1"}, -- cgit v1.2.3 From 8c6a8edacac4657c8cb75be86b9c4e6e7d1b7604 Mon Sep 17 00:00:00 2001 From: Yuri Kunde Schlesner Date: Thu, 22 Jun 2017 23:56:17 -0700 Subject: Kernel: Fix SVC wrapper for CreatePort The return parameters were flipped. --- src/core/hle/function_wrappers.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/core/hle/function_wrappers.h b/src/core/hle/function_wrappers.h index b19b64509..410bb87ea 100644 --- a/src/core/hle/function_wrappers.h +++ b/src/core/hle/function_wrappers.h @@ -226,9 +226,8 @@ void Wrap() { u32 retval = func(¶m_1, ¶m_2, reinterpret_cast(Memory::GetPointer(PARAM(2))), PARAM(3)) .raw; - // The first out parameter is moved into R2 and the second is moved into R1. - Core::CPU().SetReg(1, param_2); - Core::CPU().SetReg(2, param_1); + Core::CPU().SetReg(1, param_1); + Core::CPU().SetReg(2, param_2); FuncReturn(retval); } -- cgit v1.2.3 From e192d417ecc24648106cf3d088bd715525f83e5e Mon Sep 17 00:00:00 2001 From: Yuri Kunde Schlesner Date: Thu, 22 Jun 2017 23:57:05 -0700 Subject: Kernel: Implement AcceptSession SVC --- src/core/hle/kernel/errors.h | 5 +++++ src/core/hle/kernel/server_port.cpp | 12 ++++++++++++ src/core/hle/kernel/server_port.h | 11 +++++++++-- src/core/hle/svc.cpp | 13 ++++++++++++- 4 files changed, 38 insertions(+), 3 deletions(-) diff --git a/src/core/hle/kernel/errors.h b/src/core/hle/kernel/errors.h index b3b60e7df..64aa61460 100644 --- a/src/core/hle/kernel/errors.h +++ b/src/core/hle/kernel/errors.h @@ -13,6 +13,7 @@ enum { OutOfHandles = 19, SessionClosedByRemote = 26, PortNameTooLong = 30, + NoPendingSessions = 35, WrongPermission = 46, InvalidBufferDescriptor = 48, MaxConnectionsReached = 52, @@ -94,5 +95,9 @@ constexpr ResultCode ERR_OUT_OF_RANGE_KERNEL(ErrorDescription::OutOfRange, Error ErrorLevel::Permanent); // 0xD8E007FD constexpr ResultCode RESULT_TIMEOUT(ErrorDescription::Timeout, ErrorModule::OS, ErrorSummary::StatusChanged, ErrorLevel::Info); +/// Returned when Accept() is called on a port with no sessions to be accepted. +constexpr ResultCode ERR_NO_PENDING_SESSIONS(ErrCodes::NoPendingSessions, ErrorModule::OS, + ErrorSummary::WouldBlock, + ErrorLevel::Permanent); // 0xD8401823 } // namespace Kernel diff --git a/src/core/hle/kernel/server_port.cpp b/src/core/hle/kernel/server_port.cpp index 4d20c39a1..49a9cdfa3 100644 --- a/src/core/hle/kernel/server_port.cpp +++ b/src/core/hle/kernel/server_port.cpp @@ -5,8 +5,10 @@ #include #include "common/assert.h" #include "core/hle/kernel/client_port.h" +#include "core/hle/kernel/errors.h" #include "core/hle/kernel/kernel.h" #include "core/hle/kernel/server_port.h" +#include "core/hle/kernel/server_session.h" #include "core/hle/kernel/thread.h" namespace Kernel { @@ -14,6 +16,16 @@ namespace Kernel { ServerPort::ServerPort() {} ServerPort::~ServerPort() {} +ResultVal> ServerPort::Accept() { + if (pending_sessions.empty()) { + return ERR_NO_PENDING_SESSIONS; + } + + auto session = std::move(pending_sessions.back()); + pending_sessions.pop_back(); + return MakeResult(std::move(session)); +} + bool ServerPort::ShouldWait(Thread* thread) const { // If there are no pending sessions, we wait until a new one is added. return pending_sessions.size() == 0; diff --git a/src/core/hle/kernel/server_port.h b/src/core/hle/kernel/server_port.h index f1419cd46..6fe7c7f2f 100644 --- a/src/core/hle/kernel/server_port.h +++ b/src/core/hle/kernel/server_port.h @@ -14,6 +14,7 @@ namespace Kernel { class ClientPort; +class ServerSession; class SessionRequestHandler; class ServerPort final : public WaitObject { @@ -40,6 +41,12 @@ public: return HANDLE_TYPE; } + /** + * Accepts a pending incoming connection on this port. If there are no pending sessions, will + * return ERR_NO_PENDING_SESSIONS. + */ + ResultVal> Accept(); + /** * Sets the HLE handler template for the port. ServerSessions crated by connecting to this port * will inherit a reference to this handler. @@ -50,8 +57,8 @@ public: std::string name; ///< Name of port (optional) - std::vector> - pending_sessions; ///< ServerSessions waiting to be accepted by the port + /// ServerSessions waiting to be accepted by the port + std::vector> pending_sessions; /// This session's HLE request handler template (optional) /// ServerSessions created from this port inherit a reference to this handler. diff --git a/src/core/hle/svc.cpp b/src/core/hle/svc.cpp index 2e11d41ce..c05401143 100644 --- a/src/core/hle/svc.cpp +++ b/src/core/hle/svc.cpp @@ -971,6 +971,17 @@ static ResultCode CreateSession(Handle* server_session, Handle* client_session) return RESULT_SUCCESS; } +static ResultCode AcceptSession(Handle* out_server_session, Handle server_port_handle) { + using Kernel::ServerPort; + SharedPtr server_port = Kernel::g_handle_table.Get(server_port_handle); + if (server_port == nullptr) + return ERR_INVALID_HANDLE; + + CASCADE_RESULT(auto session, server_port->Accept()); + CASCADE_RESULT(*out_server_session, Kernel::g_handle_table.Create(std::move(session))); + return RESULT_SUCCESS; +} + static ResultCode GetSystemInfo(s64* out, u32 type, s32 param) { using Kernel::MemoryRegion; @@ -1147,7 +1158,7 @@ static const FunctionDef SVC_Table[] = { {0x47, HLE::Wrap, "CreatePort"}, {0x48, HLE::Wrap, "CreateSessionToPort"}, {0x49, HLE::Wrap, "CreateSession"}, - {0x4A, nullptr, "AcceptSession"}, + {0x4A, HLE::Wrap, "AcceptSession"}, {0x4B, nullptr, "ReplyAndReceive1"}, {0x4C, nullptr, "ReplyAndReceive2"}, {0x4D, nullptr, "ReplyAndReceive3"}, -- cgit v1.2.3