summaryrefslogtreecommitdiffstats
path: root/src/core/hle/kernel/k_light_session.cpp
diff options
context:
space:
mode:
authorliamwhite <liamwhite@users.noreply.github.com>2023-12-10 01:03:50 +0100
committerGitHub <noreply@github.com>2023-12-10 01:03:50 +0100
commit988e557ec81a9f4b883e9089fedd6079f76e07e9 (patch)
tree2c223ebd34794fc8954d09a7f96fee132d749407 /src/core/hle/kernel/k_light_session.cpp
parentMerge pull request #12323 from liamwhite/buffer-format (diff)
parentkernel: implement light IPC (diff)
downloadyuzu-988e557ec81a9f4b883e9089fedd6079f76e07e9.tar
yuzu-988e557ec81a9f4b883e9089fedd6079f76e07e9.tar.gz
yuzu-988e557ec81a9f4b883e9089fedd6079f76e07e9.tar.bz2
yuzu-988e557ec81a9f4b883e9089fedd6079f76e07e9.tar.lz
yuzu-988e557ec81a9f4b883e9089fedd6079f76e07e9.tar.xz
yuzu-988e557ec81a9f4b883e9089fedd6079f76e07e9.tar.zst
yuzu-988e557ec81a9f4b883e9089fedd6079f76e07e9.zip
Diffstat (limited to 'src/core/hle/kernel/k_light_session.cpp')
-rw-r--r--src/core/hle/kernel/k_light_session.cpp81
1 files changed, 81 insertions, 0 deletions
diff --git a/src/core/hle/kernel/k_light_session.cpp b/src/core/hle/kernel/k_light_session.cpp
new file mode 100644
index 000000000..d8b1e6958
--- /dev/null
+++ b/src/core/hle/kernel/k_light_session.cpp
@@ -0,0 +1,81 @@
+// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#include "core/hle/kernel/k_client_port.h"
+#include "core/hle/kernel/k_light_client_session.h"
+#include "core/hle/kernel/k_light_server_session.h"
+#include "core/hle/kernel/k_light_session.h"
+#include "core/hle/kernel/k_process.h"
+
+namespace Kernel {
+
+KLightSession::KLightSession(KernelCore& kernel)
+ : KAutoObjectWithSlabHeapAndContainer(kernel), m_server(kernel), m_client(kernel) {}
+KLightSession::~KLightSession() = default;
+
+void KLightSession::Initialize(KClientPort* client_port, uintptr_t name) {
+ // 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.
+ KAutoObject::Create(std::addressof(m_server));
+ KAutoObject::Create(std::addressof(m_client));
+
+ // Initialize our sub sessions.
+ m_server.Initialize(this);
+ m_client.Initialize(this);
+
+ // Set state and name.
+ m_state = State::Normal;
+ m_name = name;
+
+ // Set our owner process.
+ m_process = GetCurrentProcessPointer(m_kernel);
+ m_process->Open();
+
+ // Set our port.
+ m_port = client_port;
+ if (m_port != nullptr) {
+ m_port->Open();
+ }
+
+ // Mark initialized.
+ m_initialized = true;
+}
+
+void KLightSession::Finalize() {
+ if (m_port != nullptr) {
+ m_port->OnSessionFinalized();
+ m_port->Close();
+ }
+}
+
+void KLightSession::OnServerClosed() {
+ if (m_state == State::Normal) {
+ m_state = State::ServerClosed;
+ m_client.OnServerClosed();
+ }
+
+ this->Close();
+}
+
+void KLightSession::OnClientClosed() {
+ if (m_state == State::Normal) {
+ m_state = State::ClientClosed;
+ m_server.OnClientClosed();
+ }
+
+ this->Close();
+}
+
+void KLightSession::PostDestroy(uintptr_t arg) {
+ // Release the session count resource the owner process holds.
+ KProcess* owner = reinterpret_cast<KProcess*>(arg);
+ owner->ReleaseResource(Svc::LimitableResource::SessionCountMax, 1);
+ owner->Close();
+}
+
+} // namespace Kernel