k_server_session.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // SPDX-FileCopyrightText: Copyright 2019 yuzu Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. #include <list>
  5. #include <memory>
  6. #include <string>
  7. #include <utility>
  8. #include <boost/intrusive/list.hpp>
  9. #include "core/hle/kernel/hle_ipc.h"
  10. #include "core/hle/kernel/k_light_lock.h"
  11. #include "core/hle/kernel/k_session_request.h"
  12. #include "core/hle/kernel/k_synchronization_object.h"
  13. #include "core/hle/result.h"
  14. namespace Core::Memory {
  15. class Memory;
  16. }
  17. namespace Core::Timing {
  18. class CoreTiming;
  19. struct EventType;
  20. } // namespace Core::Timing
  21. namespace Kernel {
  22. class HLERequestContext;
  23. class KernelCore;
  24. class KSession;
  25. class SessionRequestHandler;
  26. class SessionRequestManager;
  27. class KThread;
  28. class KServerSession final : public KSynchronizationObject,
  29. public boost::intrusive::list_base_hook<> {
  30. KERNEL_AUTOOBJECT_TRAITS(KServerSession, KSynchronizationObject);
  31. friend class ServiceThread;
  32. public:
  33. explicit KServerSession(KernelCore& kernel_);
  34. ~KServerSession() override;
  35. void Destroy() override;
  36. void Initialize(KSession* parent_session_, std::string&& name_,
  37. std::shared_ptr<SessionRequestManager> manager_);
  38. KSession* GetParent() {
  39. return parent;
  40. }
  41. const KSession* GetParent() const {
  42. return parent;
  43. }
  44. bool IsSignaled() const override;
  45. void OnClientClosed();
  46. /// Gets the session request manager, which forwards requests to the underlying service
  47. std::shared_ptr<SessionRequestManager>& GetSessionRequestManager() {
  48. return manager;
  49. }
  50. /// TODO: flesh these out to match the real kernel
  51. Result OnRequest(KSessionRequest* request);
  52. Result SendReply();
  53. Result ReceiveRequest();
  54. private:
  55. /// Frees up waiting client sessions when this server session is about to die
  56. void CleanupRequests();
  57. /// Queues a sync request from the emulated application.
  58. Result QueueSyncRequest(KThread* thread, Core::Memory::Memory& memory);
  59. /// Completes a sync request from the emulated application.
  60. Result CompleteSyncRequest(HLERequestContext& context);
  61. /// This session's HLE request handlers; if nullptr, this is not an HLE server
  62. std::shared_ptr<SessionRequestManager> manager;
  63. /// When set to True, converts the session to a domain at the end of the command
  64. bool convert_to_domain{};
  65. /// KSession that owns this KServerSession
  66. KSession* parent{};
  67. /// List of threads which are pending a reply.
  68. boost::intrusive::list<KSessionRequest> m_request_list;
  69. KSessionRequest* m_current_request{};
  70. KLightLock m_lock;
  71. };
  72. } // namespace Kernel