Files
eden/src/core/hle/kernel/k_session.cpp
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

81 lines
2.4 KiB
C++
Raw Normal View History

// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "core/hle/kernel/k_client_port.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 {
2023-03-07 10:49:41 -05:00
KSession::KSession(KernelCore& kernel)
: KAutoObjectWithSlabHeapAndContainer{kernel}, m_server{kernel}, m_client{kernel} {}
KSession::~KSession() = default;
void KSession::Initialize(KernelCore& kernel, 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(kernel);
// Create our sub sessions.
2023-03-06 20:34:25 -05:00
KAutoObject::Create(std::addressof(m_server));
KAutoObject::Create(std::addressof(m_client));
// Initialize our sub sessions.
2023-03-06 20:34:25 -05:00
m_server.Initialize(this);
m_client.Initialize(this);
// Set state and name.
2023-03-06 20:34:25 -05:00
this->SetState(State::Normal);
m_name = name;
// Set our owner process.
m_process = GetCurrentProcessPointer(kernel);
m_process->Open(kernel);
// Set our port.
2023-03-06 20:34:25 -05:00
m_port = client_port;
if (m_port != nullptr) {
m_port->Open(kernel);
}
// Mark initialized.
2023-03-06 20:34:25 -05:00
m_initialized = true;
}
void KSession::Finalize(KernelCore& kernel) {
2023-03-06 20:34:25 -05:00
if (m_port != nullptr) {
m_port->OnSessionFinalized(kernel);
m_port->Close(kernel);
}
}
void KSession::OnServerClosed(KernelCore& kernel) {
2023-03-06 20:34:25 -05:00
if (this->GetState() == State::Normal) {
this->SetState(State::ServerClosed);
m_client.OnServerClosed();
}
}
void KSession::OnClientClosed(KernelCore& kernel) {
2023-03-06 20:34:25 -05:00
if (this->GetState() == State::Normal) {
this->SetState(State::ClientClosed);
m_server.OnClientClosed(kernel);
}
}
void KSession::PostDestroy(KernelCore& kernel, uintptr_t arg) {
// Release the session count resource the owner process holds.
2021-04-23 22:04:28 -07:00
KProcess* owner = reinterpret_cast<KProcess*>(arg);
owner->GetResourceLimit()->Release(kernel, LimitableResource::SessionCountMax, 1);
owner->Close(kernel);
}
} // namespace Kernel