1
0
Fork 0
mirror of https://github.com/Atmosphere-NX/Atmosphere.git synced 2024-12-18 00:12:03 +00:00

kern: implement SvcAcceptSession

This commit is contained in:
Michael Scire 2020-07-09 17:49:33 -07:00
parent f52232f0f2
commit 78da7422ae
4 changed files with 67 additions and 3 deletions

View file

@ -41,6 +41,9 @@ namespace ams::kern {
void EnqueueSession(KServerSession *session);
void EnqueueSession(KLightServerSession *session);
KServerSession *AcceptSession();
KLightServerSession *AcceptLightSession();
constexpr const KPort *GetParent() const { return this->parent; }
bool IsLight() const;

View file

@ -119,4 +119,36 @@ namespace ams::kern {
}
}
KServerSession *KServerPort::AcceptSession() {
MESOSPHERE_ASSERT_THIS();
MESOSPHERE_ASSERT(!this->IsLight());
KScopedSchedulerLock sl;
/* Return the first session in the list. */
if (this->session_list.empty()) {
return nullptr;
}
KServerSession *session = std::addressof(this->session_list.front());
this->session_list.pop_front();
return session;
}
KLightServerSession *KServerPort::AcceptLightSession() {
MESOSPHERE_ASSERT_THIS();
MESOSPHERE_ASSERT(this->IsLight());
KScopedSchedulerLock sl;
/* Return the first session in the list. */
if (this->light_session_list.empty()) {
return nullptr;
}
KLightServerSession *session = std::addressof(this->light_session_list.front());
this->light_session_list.pop_front();
return session;
}
}

View file

@ -43,7 +43,7 @@ namespace ams::kern {
this->process->Open();
/* Set our port. */
this->port = port;
this->port = client_port;
if (this->port != nullptr) {
this->port->Open();
}

View file

@ -21,7 +21,36 @@ namespace ams::kern::svc {
namespace {
Result AcceptSession(ams::svc::Handle *out, ams::svc::Handle port_handle) {
/* Get the current handle table. */
auto &handle_table = GetCurrentProcess().GetHandleTable();
/* Get the server port. */
KScopedAutoObject port = handle_table.GetObject<KServerPort>(port_handle);
R_UNLESS(port.IsNotNull(), svc::ResultInvalidHandle());
/* Reserve an entry for the new session. */
R_TRY(handle_table.Reserve(out));
auto handle_guard = SCOPE_GUARD { handle_table.Unreserve(*out); };
/* Accept the session. */
KAutoObject *session;
if (port->IsLight()) {
session = port->AcceptLightSession();
} else {
session = port->AcceptSession();
}
/* Ensure we accepted successfully. */
R_UNLESS(session != nullptr, svc::ResultNotFound());
/* Register the session. */
handle_table.Register(*out, session);
handle_guard.Cancel();
session->Close();
return ResultSuccess();
}
}
@ -32,7 +61,7 @@ namespace ams::kern::svc {
}
Result AcceptSession64(ams::svc::Handle *out_handle, ams::svc::Handle port) {
MESOSPHERE_PANIC("Stubbed SvcAcceptSession64 was called.");
return AcceptSession(out_handle, port);
}
/* ============================= 64From32 ABI ============================= */
@ -42,7 +71,7 @@ namespace ams::kern::svc {
}
Result AcceptSession64From32(ams::svc::Handle *out_handle, ams::svc::Handle port) {
MESOSPHERE_PANIC("Stubbed SvcAcceptSession64From32 was called.");
return AcceptSession(out_handle, port);
}
}