diff --git a/libraries/libmesosphere/include/mesosphere/kern_k_client_session.hpp b/libraries/libmesosphere/include/mesosphere/kern_k_client_session.hpp index 025a2a7ef..98f5ce005 100644 --- a/libraries/libmesosphere/include/mesosphere/kern_k_client_session.hpp +++ b/libraries/libmesosphere/include/mesosphere/kern_k_client_session.hpp @@ -29,6 +29,8 @@ namespace ams::kern { constexpr KClientSession() : parent() { /* ... */ } virtual ~KClientSession() { /* ... */ } + virtual void Destroy() override; + void Initialize(KSession *parent) { /* Set member variables. */ this->parent = parent; diff --git a/libraries/libmesosphere/include/mesosphere/kern_k_server_session.hpp b/libraries/libmesosphere/include/mesosphere/kern_k_server_session.hpp index 5d26f3bb5..5f8ad5881 100644 --- a/libraries/libmesosphere/include/mesosphere/kern_k_server_session.hpp +++ b/libraries/libmesosphere/include/mesosphere/kern_k_server_session.hpp @@ -36,6 +36,8 @@ namespace ams::kern { constexpr KServerSession() : parent(), request_list(), current_request(), lock() { /* ... */ } virtual ~KServerSession() { /* ... */ } + virtual void Destroy() override; + void Initialize(KSession *p) { this->parent = p; } constexpr const KSession *GetParent() const { return this->parent; } diff --git a/libraries/libmesosphere/source/kern_k_client_session.cpp b/libraries/libmesosphere/source/kern_k_client_session.cpp index 9e2c9967b..76c8aff66 100644 --- a/libraries/libmesosphere/source/kern_k_client_session.cpp +++ b/libraries/libmesosphere/source/kern_k_client_session.cpp @@ -17,6 +17,13 @@ namespace ams::kern { + void KClientSession::Destroy() { + MESOSPHERE_ASSERT_THIS(); + + this->parent->OnClientClosed(); + this->parent->Close(); + } + void KClientSession::OnServerClosed() { MESOSPHERE_ASSERT_THIS(); } diff --git a/libraries/libmesosphere/source/kern_k_server_session.cpp b/libraries/libmesosphere/source/kern_k_server_session.cpp index cb1e8c69c..d0db87603 100644 --- a/libraries/libmesosphere/source/kern_k_server_session.cpp +++ b/libraries/libmesosphere/source/kern_k_server_session.cpp @@ -17,6 +17,16 @@ namespace ams::kern { + void KServerSession::Destroy() { + MESOSPHERE_ASSERT_THIS(); + + this->parent->OnServerClosed(); + + /* TODO: this->CleanupRequests(); */ + + this->parent->Close(); + } + Result KServerSession::OnRequest(KSessionRequest *request) { MESOSPHERE_UNIMPLEMENTED(); } diff --git a/libraries/libmesosphere/source/kern_k_session.cpp b/libraries/libmesosphere/source/kern_k_session.cpp index 416810b42..7b56d268e 100644 --- a/libraries/libmesosphere/source/kern_k_session.cpp +++ b/libraries/libmesosphere/source/kern_k_session.cpp @@ -21,6 +21,9 @@ namespace ams::kern { MESOSPHERE_ASSERT_THIS(); /* Increment reference count. */ + /* Because reference count is one on creation, this will result */ + /* in a reference count of two. Thus, when both server and client are closed */ + /* this object will be destroyed. */ this->Open(); /* Create our sub sessions. */ diff --git a/libraries/libmesosphere/source/svc/kern_svc_synchronization.cpp b/libraries/libmesosphere/source/svc/kern_svc_synchronization.cpp index 7564da89a..33b150955 100644 --- a/libraries/libmesosphere/source/svc/kern_svc_synchronization.cpp +++ b/libraries/libmesosphere/source/svc/kern_svc_synchronization.cpp @@ -21,14 +21,18 @@ namespace ams::kern::svc { namespace { - + Result CloseHandle(ams::svc::Handle handle) { + /* Remove the handle. */ + R_UNLESS(GetCurrentProcess().GetHandleTable().Remove(handle), svc::ResultInvalidHandle()); + return ResultSuccess(); + } } /* ============================= 64 ABI ============================= */ Result CloseHandle64(ams::svc::Handle handle) { - MESOSPHERE_PANIC("Stubbed SvcCloseHandle64 was called."); + return CloseHandle(handle); } Result ResetSignal64(ams::svc::Handle handle) { @@ -50,7 +54,7 @@ namespace ams::kern::svc { /* ============================= 64From32 ABI ============================= */ Result CloseHandle64From32(ams::svc::Handle handle) { - MESOSPHERE_PANIC("Stubbed SvcCloseHandle64From32 was called."); + return CloseHandle(handle); } Result ResetSignal64From32(ams::svc::Handle handle) {