k_light_session.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #include "core/hle/kernel/k_client_port.h"
  4. #include "core/hle/kernel/k_light_client_session.h"
  5. #include "core/hle/kernel/k_light_server_session.h"
  6. #include "core/hle/kernel/k_light_session.h"
  7. #include "core/hle/kernel/k_process.h"
  8. namespace Kernel {
  9. KLightSession::KLightSession(KernelCore& kernel)
  10. : KAutoObjectWithSlabHeapAndContainer(kernel), m_server(kernel), m_client(kernel) {}
  11. KLightSession::~KLightSession() = default;
  12. void KLightSession::Initialize(KClientPort* client_port, uintptr_t name) {
  13. // Increment reference count.
  14. // Because reference count is one on creation, this will result
  15. // in a reference count of two. Thus, when both server and client are closed
  16. // this object will be destroyed.
  17. this->Open();
  18. // Create our sub sessions.
  19. KAutoObject::Create(std::addressof(m_server));
  20. KAutoObject::Create(std::addressof(m_client));
  21. // Initialize our sub sessions.
  22. m_server.Initialize(this);
  23. m_client.Initialize(this);
  24. // Set state and name.
  25. m_state = State::Normal;
  26. m_name = name;
  27. // Set our owner process.
  28. m_process = GetCurrentProcessPointer(m_kernel);
  29. m_process->Open();
  30. // Set our port.
  31. m_port = client_port;
  32. if (m_port != nullptr) {
  33. m_port->Open();
  34. }
  35. // Mark initialized.
  36. m_initialized = true;
  37. }
  38. void KLightSession::Finalize() {
  39. if (m_port != nullptr) {
  40. m_port->OnSessionFinalized();
  41. m_port->Close();
  42. }
  43. }
  44. void KLightSession::OnServerClosed() {
  45. if (m_state == State::Normal) {
  46. m_state = State::ServerClosed;
  47. m_client.OnServerClosed();
  48. }
  49. this->Close();
  50. }
  51. void KLightSession::OnClientClosed() {
  52. if (m_state == State::Normal) {
  53. m_state = State::ClientClosed;
  54. m_server.OnClientClosed();
  55. }
  56. this->Close();
  57. }
  58. void KLightSession::PostDestroy(uintptr_t arg) {
  59. // Release the session count resource the owner process holds.
  60. KProcess* owner = reinterpret_cast<KProcess*>(arg);
  61. owner->ReleaseResource(Svc::LimitableResource::SessionCountMax, 1);
  62. owner->Close();
  63. }
  64. } // namespace Kernel