Kernel: Implement AcceptSession SVC

master
Yuri Kunde Schlesner 2017-06-22 23:57:05 +07:00
parent 8c6a8edaca
commit e192d417ec
4 changed files with 38 additions and 3 deletions

@ -13,6 +13,7 @@ enum {
OutOfHandles = 19, OutOfHandles = 19,
SessionClosedByRemote = 26, SessionClosedByRemote = 26,
PortNameTooLong = 30, PortNameTooLong = 30,
NoPendingSessions = 35,
WrongPermission = 46, WrongPermission = 46,
InvalidBufferDescriptor = 48, InvalidBufferDescriptor = 48,
MaxConnectionsReached = 52, MaxConnectionsReached = 52,
@ -94,5 +95,9 @@ constexpr ResultCode ERR_OUT_OF_RANGE_KERNEL(ErrorDescription::OutOfRange, Error
ErrorLevel::Permanent); // 0xD8E007FD ErrorLevel::Permanent); // 0xD8E007FD
constexpr ResultCode RESULT_TIMEOUT(ErrorDescription::Timeout, ErrorModule::OS, constexpr ResultCode RESULT_TIMEOUT(ErrorDescription::Timeout, ErrorModule::OS,
ErrorSummary::StatusChanged, ErrorLevel::Info); 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 } // namespace Kernel

@ -5,8 +5,10 @@
#include <tuple> #include <tuple>
#include "common/assert.h" #include "common/assert.h"
#include "core/hle/kernel/client_port.h" #include "core/hle/kernel/client_port.h"
#include "core/hle/kernel/errors.h"
#include "core/hle/kernel/kernel.h" #include "core/hle/kernel/kernel.h"
#include "core/hle/kernel/server_port.h" #include "core/hle/kernel/server_port.h"
#include "core/hle/kernel/server_session.h"
#include "core/hle/kernel/thread.h" #include "core/hle/kernel/thread.h"
namespace Kernel { namespace Kernel {
@ -14,6 +16,16 @@ namespace Kernel {
ServerPort::ServerPort() {} ServerPort::ServerPort() {}
ServerPort::~ServerPort() {} ServerPort::~ServerPort() {}
ResultVal<SharedPtr<ServerSession>> 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 { bool ServerPort::ShouldWait(Thread* thread) const {
// If there are no pending sessions, we wait until a new one is added. // If there are no pending sessions, we wait until a new one is added.
return pending_sessions.size() == 0; return pending_sessions.size() == 0;

@ -14,6 +14,7 @@
namespace Kernel { namespace Kernel {
class ClientPort; class ClientPort;
class ServerSession;
class SessionRequestHandler; class SessionRequestHandler;
class ServerPort final : public WaitObject { class ServerPort final : public WaitObject {
@ -40,6 +41,12 @@ public:
return HANDLE_TYPE; return HANDLE_TYPE;
} }
/**
* Accepts a pending incoming connection on this port. If there are no pending sessions, will
* return ERR_NO_PENDING_SESSIONS.
*/
ResultVal<SharedPtr<ServerSession>> Accept();
/** /**
* Sets the HLE handler template for the port. ServerSessions crated by connecting to this port * Sets the HLE handler template for the port. ServerSessions crated by connecting to this port
* will inherit a reference to this handler. * will inherit a reference to this handler.
@ -50,8 +57,8 @@ public:
std::string name; ///< Name of port (optional) std::string name; ///< Name of port (optional)
std::vector<SharedPtr<WaitObject>> /// ServerSessions waiting to be accepted by the port
pending_sessions; ///< ServerSessions waiting to be accepted by the port std::vector<SharedPtr<ServerSession>> pending_sessions;
/// This session's HLE request handler template (optional) /// This session's HLE request handler template (optional)
/// ServerSessions created from this port inherit a reference to this handler. /// ServerSessions created from this port inherit a reference to this handler.

@ -971,6 +971,17 @@ static ResultCode CreateSession(Handle* server_session, Handle* client_session)
return RESULT_SUCCESS; return RESULT_SUCCESS;
} }
static ResultCode AcceptSession(Handle* out_server_session, Handle server_port_handle) {
using Kernel::ServerPort;
SharedPtr<ServerPort> server_port = Kernel::g_handle_table.Get<ServerPort>(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) { static ResultCode GetSystemInfo(s64* out, u32 type, s32 param) {
using Kernel::MemoryRegion; using Kernel::MemoryRegion;
@ -1147,7 +1158,7 @@ static const FunctionDef SVC_Table[] = {
{0x47, HLE::Wrap<CreatePort>, "CreatePort"}, {0x47, HLE::Wrap<CreatePort>, "CreatePort"},
{0x48, HLE::Wrap<CreateSessionToPort>, "CreateSessionToPort"}, {0x48, HLE::Wrap<CreateSessionToPort>, "CreateSessionToPort"},
{0x49, HLE::Wrap<CreateSession>, "CreateSession"}, {0x49, HLE::Wrap<CreateSession>, "CreateSession"},
{0x4A, nullptr, "AcceptSession"}, {0x4A, HLE::Wrap<AcceptSession>, "AcceptSession"},
{0x4B, nullptr, "ReplyAndReceive1"}, {0x4B, nullptr, "ReplyAndReceive1"},
{0x4C, nullptr, "ReplyAndReceive2"}, {0x4C, nullptr, "ReplyAndReceive2"},
{0x4D, nullptr, "ReplyAndReceive3"}, {0x4D, nullptr, "ReplyAndReceive3"},