|
|
@ -23,7 +23,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
namespace Kernel {
|
|
|
|
namespace Kernel {
|
|
|
|
|
|
|
|
|
|
|
|
KServerSession::KServerSession(KernelCore& kernel_) : KSynchronizationObject{kernel_} {}
|
|
|
|
KServerSession::KServerSession(KernelCore& kernel_)
|
|
|
|
|
|
|
|
: KSynchronizationObject{kernel_}, manager{std::make_shared<SessionRequestManager>()} {}
|
|
|
|
|
|
|
|
|
|
|
|
KServerSession::~KServerSession() {
|
|
|
|
KServerSession::~KServerSession() {
|
|
|
|
kernel.ReleaseServiceThread(service_thread);
|
|
|
|
kernel.ReleaseServiceThread(service_thread);
|
|
|
@ -43,14 +44,8 @@ void KServerSession::Destroy() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void KServerSession::OnClientClosed() {
|
|
|
|
void KServerSession::OnClientClosed() {
|
|
|
|
// We keep a shared pointer to the hle handler to keep it alive throughout
|
|
|
|
if (manager->HasSessionHandler()) {
|
|
|
|
// the call to ClientDisconnected, as ClientDisconnected invalidates the
|
|
|
|
manager->SessionHandler().ClientDisconnected(this);
|
|
|
|
// hle_handler member itself during the course of the function executing.
|
|
|
|
|
|
|
|
std::shared_ptr<SessionRequestHandler> handler = hle_handler;
|
|
|
|
|
|
|
|
if (handler) {
|
|
|
|
|
|
|
|
// Note that after this returns, this server session's hle_handler is
|
|
|
|
|
|
|
|
// invalidated (set to null).
|
|
|
|
|
|
|
|
handler->ClientDisconnected(this);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -66,12 +61,12 @@ bool KServerSession::IsSignaled() const {
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void KServerSession::AppendDomainRequestHandler(std::shared_ptr<SessionRequestHandler> handler) {
|
|
|
|
void KServerSession::AppendDomainHandler(SessionRequestHandlerPtr handler) {
|
|
|
|
domain_request_handlers.push_back(std::move(handler));
|
|
|
|
manager->AppendDomainHandler(std::move(handler));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::size_t KServerSession::NumDomainRequestHandlers() const {
|
|
|
|
std::size_t KServerSession::NumDomainRequestHandlers() const {
|
|
|
|
return domain_request_handlers.size();
|
|
|
|
return manager->DomainHandlerCount();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ResultCode KServerSession::HandleDomainSyncRequest(Kernel::HLERequestContext& context) {
|
|
|
|
ResultCode KServerSession::HandleDomainSyncRequest(Kernel::HLERequestContext& context) {
|
|
|
@ -80,14 +75,14 @@ ResultCode KServerSession::HandleDomainSyncRequest(Kernel::HLERequestContext& co
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Set domain handlers in HLE context, used for domain objects (IPC interfaces) as inputs
|
|
|
|
// Set domain handlers in HLE context, used for domain objects (IPC interfaces) as inputs
|
|
|
|
context.SetDomainRequestHandlers(domain_request_handlers);
|
|
|
|
context.SetSessionRequestManager(manager);
|
|
|
|
|
|
|
|
|
|
|
|
// If there is a DomainMessageHeader, then this is CommandType "Request"
|
|
|
|
// If there is a DomainMessageHeader, then this is CommandType "Request"
|
|
|
|
const auto& domain_message_header = context.GetDomainMessageHeader();
|
|
|
|
const auto& domain_message_header = context.GetDomainMessageHeader();
|
|
|
|
const u32 object_id{domain_message_header.object_id};
|
|
|
|
const u32 object_id{domain_message_header.object_id};
|
|
|
|
switch (domain_message_header.command) {
|
|
|
|
switch (domain_message_header.command) {
|
|
|
|
case IPC::DomainMessageHeader::CommandType::SendMessage:
|
|
|
|
case IPC::DomainMessageHeader::CommandType::SendMessage:
|
|
|
|
if (object_id > domain_request_handlers.size()) {
|
|
|
|
if (object_id > manager->DomainHandlerCount()) {
|
|
|
|
LOG_CRITICAL(IPC,
|
|
|
|
LOG_CRITICAL(IPC,
|
|
|
|
"object_id {} is too big! This probably means a recent service call "
|
|
|
|
"object_id {} is too big! This probably means a recent service call "
|
|
|
|
"to {} needed to return a new interface!",
|
|
|
|
"to {} needed to return a new interface!",
|
|
|
@ -95,12 +90,12 @@ ResultCode KServerSession::HandleDomainSyncRequest(Kernel::HLERequestContext& co
|
|
|
|
UNREACHABLE();
|
|
|
|
UNREACHABLE();
|
|
|
|
return RESULT_SUCCESS; // Ignore error if asserts are off
|
|
|
|
return RESULT_SUCCESS; // Ignore error if asserts are off
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return domain_request_handlers[object_id - 1]->HandleSyncRequest(*this, context);
|
|
|
|
return manager->DomainHandler(object_id - 1)->HandleSyncRequest(*this, context);
|
|
|
|
|
|
|
|
|
|
|
|
case IPC::DomainMessageHeader::CommandType::CloseVirtualHandle: {
|
|
|
|
case IPC::DomainMessageHeader::CommandType::CloseVirtualHandle: {
|
|
|
|
LOG_DEBUG(IPC, "CloseVirtualHandle, object_id=0x{:08X}", object_id);
|
|
|
|
LOG_DEBUG(IPC, "CloseVirtualHandle, object_id=0x{:08X}", object_id);
|
|
|
|
|
|
|
|
|
|
|
|
domain_request_handlers[object_id - 1] = nullptr;
|
|
|
|
manager->CloseDomainHandler(object_id - 1);
|
|
|
|
|
|
|
|
|
|
|
|
IPC::ResponseBuilder rb{context, 2};
|
|
|
|
IPC::ResponseBuilder rb{context, 2};
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
@ -133,14 +128,14 @@ ResultCode KServerSession::CompleteSyncRequest(HLERequestContext& context) {
|
|
|
|
if (IsDomain() && context.HasDomainMessageHeader()) {
|
|
|
|
if (IsDomain() && context.HasDomainMessageHeader()) {
|
|
|
|
result = HandleDomainSyncRequest(context);
|
|
|
|
result = HandleDomainSyncRequest(context);
|
|
|
|
// If there is no domain header, the regular session handler is used
|
|
|
|
// If there is no domain header, the regular session handler is used
|
|
|
|
} else if (hle_handler != nullptr) {
|
|
|
|
} else if (manager->HasSessionHandler()) {
|
|
|
|
// If this ServerSession has an associated HLE handler, forward the request to it.
|
|
|
|
// If this ServerSession has an associated HLE handler, forward the request to it.
|
|
|
|
result = hle_handler->HandleSyncRequest(*this, context);
|
|
|
|
result = manager->SessionHandler().HandleSyncRequest(*this, context);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (convert_to_domain) {
|
|
|
|
if (convert_to_domain) {
|
|
|
|
ASSERT_MSG(IsSession(), "ServerSession is already a domain instance.");
|
|
|
|
ASSERT_MSG(!IsDomain(), "ServerSession is already a domain instance.");
|
|
|
|
domain_request_handlers = {hle_handler};
|
|
|
|
manager->ConvertToDomain();
|
|
|
|
convert_to_domain = false;
|
|
|
|
convert_to_domain = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|