diff options
| author | bunnei <bunneidev@gmail.com> | 2021-04-13 17:48:37 -0700 |
|---|---|---|
| committer | bunnei <bunneidev@gmail.com> | 2021-05-05 16:40:51 -0700 |
| commit | 7444963bbb300cff269e410948de7fa577f5ff16 (patch) | |
| tree | 6e0000cb345dc02c8f2ca38958b7c90383f45b03 /src/core/hle/kernel/k_session.cpp | |
| parent | 2cb6106523a87ae78d3a6b92c34b3b1d2817415e (diff) | |
hle: kernel: Migrate KSession, KClientSession, and KServerSession to KAutoObject.
Diffstat (limited to 'src/core/hle/kernel/k_session.cpp')
| -rw-r--r-- | src/core/hle/kernel/k_session.cpp | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/src/core/hle/kernel/k_session.cpp b/src/core/hle/kernel/k_session.cpp new file mode 100644 index 000000000..ca1cf18cd --- /dev/null +++ b/src/core/hle/kernel/k_session.cpp @@ -0,0 +1,67 @@ +// Copyright 2019 yuzu emulator team +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include "common/assert.h" +#include "core/hle/kernel/k_client_session.h" +#include "core/hle/kernel/k_scoped_resource_reservation.h" +#include "core/hle/kernel/k_server_session.h" +#include "core/hle/kernel/k_session.h" + +namespace Kernel { + +KSession::KSession(KernelCore& kernel) + : KAutoObjectWithSlabHeapAndContainer{kernel}, server{kernel}, client{kernel} {} +KSession::~KSession() = default; + +void KSession::Initialize(std::string&& 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. + Open(); + + // Create our sub sessions. + KAutoObject::Create(std::addressof(server)); + KAutoObject::Create(std::addressof(client)); + + // Initialize our sub sessions. + server.Initialize(this, name_ + ":Server"); + client.Initialize(this, name_ + ":Client"); + + // Set state and name. + SetState(State::Normal); + name = std::move(name_); + + // Set our owner process. + process = kernel.CurrentProcess(); + process->Open(); + + // Mark initialized. + initialized = true; +} + +void KSession::Finalize() {} + +void KSession::OnServerClosed() { + if (GetState() == State::Normal) { + SetState(State::ServerClosed); + client.OnServerClosed(); + } +} + +void KSession::OnClientClosed() { + if (GetState() == State::Normal) { + SetState(State::ClientClosed); + server.OnClientClosed(); + } +} + +void KSession::PostDestroy(uintptr_t arg) { + // Release the session count resource the owner process holds. + Process* owner = reinterpret_cast<Process*>(arg); + owner->GetResourceLimit()->Release(LimitableResource::Sessions, 1); + owner->Close(); +} + +} // namespace Kernel |
