k_light_session.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  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/slab_helpers.h"
  7. #include "core/hle/result.h"
  8. namespace Kernel {
  9. class KClientPort;
  10. class KProcess;
  11. // TODO: SupportDynamicExpansion for SlabHeap
  12. class KLightSession final
  13. : public KAutoObjectWithSlabHeapAndContainer<KLightSession, KAutoObjectWithList> {
  14. KERNEL_AUTOOBJECT_TRAITS(KLightSession, KAutoObject);
  15. private:
  16. enum class State : u8 {
  17. Invalid = 0,
  18. Normal = 1,
  19. ClientClosed = 2,
  20. ServerClosed = 3,
  21. };
  22. public:
  23. static constexpr size_t DataSize = sizeof(u32) * 7;
  24. static constexpr u32 ReplyFlag = (1U << 31);
  25. private:
  26. KLightServerSession m_server;
  27. KLightClientSession m_client;
  28. State m_state{State::Invalid};
  29. KClientPort* m_port{};
  30. uintptr_t m_name{};
  31. KProcess* m_process{};
  32. bool m_initialized{};
  33. public:
  34. explicit KLightSession(KernelCore& kernel);
  35. ~KLightSession();
  36. void Initialize(KClientPort* client_port, uintptr_t name);
  37. void Finalize() override;
  38. bool IsInitialized() const override {
  39. return m_initialized;
  40. }
  41. uintptr_t GetPostDestroyArgument() const override {
  42. return reinterpret_cast<uintptr_t>(m_process);
  43. }
  44. static void PostDestroy(uintptr_t arg);
  45. void OnServerClosed();
  46. void OnClientClosed();
  47. bool IsServerClosed() const {
  48. return m_state != State::Normal;
  49. }
  50. bool IsClientClosed() const {
  51. return m_state != State::Normal;
  52. }
  53. Result OnRequest(KThread* request_thread) {
  54. R_RETURN(m_server.OnRequest(request_thread));
  55. }
  56. KLightClientSession& GetClientSession() {
  57. return m_client;
  58. }
  59. KLightServerSession& GetServerSession() {
  60. return m_server;
  61. }
  62. const KLightClientSession& GetClientSession() const {
  63. return m_client;
  64. }
  65. const KLightServerSession& GetServerSession() const {
  66. return m_server;
  67. }
  68. };
  69. } // namespace Kernel