2022-04-23 10:59:50 +02:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2019 yuzu Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2014-12-14 06:30:11 +01:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2022-10-12 00:16:56 +02:00
|
|
|
#include <list>
|
2017-02-20 03:37:14 +01:00
|
|
|
#include <memory>
|
2015-06-21 14:40:28 +02:00
|
|
|
#include <string>
|
2019-04-06 07:41:43 +02:00
|
|
|
#include <utility>
|
2018-07-31 14:06:09 +02:00
|
|
|
|
2021-04-24 02:00:15 +02:00
|
|
|
#include <boost/intrusive/list.hpp>
|
|
|
|
|
2021-05-16 08:49:03 +02:00
|
|
|
#include "core/hle/kernel/hle_ipc.h"
|
2022-10-12 00:16:56 +02:00
|
|
|
#include "core/hle/kernel/k_light_lock.h"
|
2022-10-15 03:24:25 +02:00
|
|
|
#include "core/hle/kernel/k_session_request.h"
|
2020-12-22 07:36:53 +01:00
|
|
|
#include "core/hle/kernel/k_synchronization_object.h"
|
2015-06-21 14:40:28 +02:00
|
|
|
#include "core/hle/result.h"
|
2014-12-14 06:30:11 +01:00
|
|
|
|
2020-03-31 21:10:44 +02:00
|
|
|
namespace Core::Memory {
|
2019-11-26 20:10:49 +01:00
|
|
|
class Memory;
|
|
|
|
}
|
|
|
|
|
2019-11-26 00:28:48 +01:00
|
|
|
namespace Core::Timing {
|
2020-09-14 20:03:10 +02:00
|
|
|
class CoreTiming;
|
2019-11-26 00:28:48 +01:00
|
|
|
struct EventType;
|
2020-09-14 20:03:10 +02:00
|
|
|
} // namespace Core::Timing
|
2019-11-26 00:28:48 +01:00
|
|
|
|
2014-12-14 06:30:11 +01:00
|
|
|
namespace Kernel {
|
|
|
|
|
2018-08-28 18:30:33 +02:00
|
|
|
class HLERequestContext;
|
|
|
|
class KernelCore;
|
2021-04-14 02:48:37 +02:00
|
|
|
class KSession;
|
2017-06-05 06:52:19 +02:00
|
|
|
class SessionRequestHandler;
|
2021-06-05 04:26:48 +02:00
|
|
|
class SessionRequestManager;
|
2020-12-31 08:01:08 +01:00
|
|
|
class KThread;
|
2016-06-15 01:03:30 +02:00
|
|
|
|
2021-04-24 02:00:15 +02:00
|
|
|
class KServerSession final : public KSynchronizationObject,
|
|
|
|
public boost::intrusive::list_base_hook<> {
|
2021-04-14 02:48:37 +02:00
|
|
|
KERNEL_AUTOOBJECT_TRAITS(KServerSession, KSynchronizationObject);
|
|
|
|
|
2020-12-10 06:27:05 +01:00
|
|
|
friend class ServiceThread;
|
|
|
|
|
2014-12-14 06:30:11 +01:00
|
|
|
public:
|
2021-05-08 18:11:36 +02:00
|
|
|
explicit KServerSession(KernelCore& kernel_);
|
2021-05-29 08:49:07 +02:00
|
|
|
~KServerSession() override;
|
2019-11-25 02:15:51 +01:00
|
|
|
|
2021-05-29 08:49:07 +02:00
|
|
|
void Destroy() override;
|
2019-11-26 00:28:48 +01:00
|
|
|
|
2021-06-07 00:39:11 +02:00
|
|
|
void Initialize(KSession* parent_session_, std::string&& name_,
|
2021-06-05 04:26:48 +02:00
|
|
|
std::shared_ptr<SessionRequestManager> manager_);
|
2019-11-26 00:28:48 +01:00
|
|
|
|
2021-05-01 21:48:41 +02:00
|
|
|
KSession* GetParent() {
|
2021-04-14 02:48:37 +02:00
|
|
|
return parent;
|
2019-04-03 16:35:09 +02:00
|
|
|
}
|
|
|
|
|
2021-05-01 21:48:41 +02:00
|
|
|
const KSession* GetParent() const {
|
2021-04-14 02:48:37 +02:00
|
|
|
return parent;
|
2016-12-01 05:28:31 +01:00
|
|
|
}
|
2016-06-15 01:03:30 +02:00
|
|
|
|
2021-05-29 08:49:07 +02:00
|
|
|
bool IsSignaled() const override;
|
2021-04-14 02:48:37 +02:00
|
|
|
void OnClientClosed();
|
2019-03-06 00:51:16 +01:00
|
|
|
|
2021-05-16 08:49:03 +02:00
|
|
|
/// Gets the session request manager, which forwards requests to the underlying service
|
|
|
|
std::shared_ptr<SessionRequestManager>& GetSessionRequestManager() {
|
|
|
|
return manager;
|
|
|
|
}
|
|
|
|
|
2022-10-12 00:16:56 +02:00
|
|
|
/// TODO: flesh these out to match the real kernel
|
2022-10-15 03:24:25 +02:00
|
|
|
Result OnRequest(KSessionRequest* request);
|
2022-10-12 00:16:56 +02:00
|
|
|
Result SendReply();
|
|
|
|
Result ReceiveRequest();
|
|
|
|
|
2016-12-05 17:02:08 +01:00
|
|
|
private:
|
2022-10-12 00:16:56 +02:00
|
|
|
/// Frees up waiting client sessions when this server session is about to die
|
|
|
|
void CleanupRequests();
|
|
|
|
|
2019-11-26 00:28:48 +01:00
|
|
|
/// Queues a sync request from the emulated application.
|
2022-06-26 05:44:19 +02:00
|
|
|
Result QueueSyncRequest(KThread* thread, Core::Memory::Memory& memory);
|
2019-11-26 00:28:48 +01:00
|
|
|
|
|
|
|
/// Completes a sync request from the emulated application.
|
2022-06-26 05:44:19 +02:00
|
|
|
Result CompleteSyncRequest(HLERequestContext& context);
|
2018-01-24 00:03:09 +01:00
|
|
|
|
2022-10-12 00:16:56 +02:00
|
|
|
/// This session's HLE request handlers; if nullptr, this is not an HLE server
|
2021-05-16 08:49:03 +02:00
|
|
|
std::shared_ptr<SessionRequestManager> manager;
|
2019-03-06 00:51:16 +01:00
|
|
|
|
2018-01-24 00:03:09 +01:00
|
|
|
/// When set to True, converts the session to a domain at the end of the command
|
|
|
|
bool convert_to_domain{};
|
2019-03-06 00:51:16 +01:00
|
|
|
|
2021-04-14 02:48:37 +02:00
|
|
|
/// KSession that owns this KServerSession
|
|
|
|
KSession* parent{};
|
2022-10-12 00:16:56 +02:00
|
|
|
|
|
|
|
/// List of threads which are pending a reply.
|
2022-10-15 03:24:25 +02:00
|
|
|
boost::intrusive::list<KSessionRequest> m_request_list;
|
|
|
|
KSessionRequest* m_current_request;
|
2022-10-12 00:16:56 +02:00
|
|
|
|
|
|
|
KLightLock m_lock;
|
2014-12-14 06:30:11 +01:00
|
|
|
};
|
2016-12-09 18:52:12 +01:00
|
|
|
|
2018-01-20 08:48:02 +01:00
|
|
|
} // namespace Kernel
|