2019-11-26 00:28:48 +01:00
|
|
|
// Copyright 2019 yuzu emulator team
|
2014-12-17 06:38:14 +01:00
|
|
|
// Licensed under GPLv2 or any later version
|
2014-12-14 06:30:11 +01:00
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
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
|
|
|
#include <vector>
|
|
|
|
|
2021-04-24 02:00:15 +02:00
|
|
|
#include <boost/intrusive/list.hpp>
|
|
|
|
|
2019-11-26 00:28:48 +01:00
|
|
|
#include "common/threadsafe_queue.h"
|
2021-05-16 08:49:03 +02:00
|
|
|
#include "core/hle/kernel/hle_ipc.h"
|
2020-12-22 07:36:53 +01:00
|
|
|
#include "core/hle/kernel/k_synchronization_object.h"
|
2020-12-10 06:27:05 +01:00
|
|
|
#include "core/hle/kernel/service_thread.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;
|
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-04-14 02:48:37 +02:00
|
|
|
void Initialize(KSession* parent_, std::string&& name_);
|
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;
|
2019-03-06 00:51:16 +01:00
|
|
|
|
2021-04-14 02:48:37 +02:00
|
|
|
void OnClientClosed();
|
2019-03-06 00:51:16 +01:00
|
|
|
|
2017-06-06 07:39:26 +02:00
|
|
|
/**
|
|
|
|
* Sets the HLE handler for the session. This handler will be called to service IPC requests
|
|
|
|
* instead of the regular IPC machinery. (The regular IPC machinery is currently not
|
|
|
|
* implemented.)
|
|
|
|
*/
|
2021-05-16 08:49:03 +02:00
|
|
|
void SetSessionHandler(SessionRequestHandlerPtr handler) {
|
|
|
|
manager->SetSessionHandler(std::move(handler));
|
2017-06-06 07:39:26 +02:00
|
|
|
}
|
2014-12-14 06:30:11 +01:00
|
|
|
|
|
|
|
/**
|
2016-06-15 01:03:30 +02:00
|
|
|
* Handle a sync request from the emulated application.
|
2019-11-26 20:10:49 +01:00
|
|
|
*
|
2020-09-14 20:03:10 +02:00
|
|
|
* @param thread Thread that initiated the request.
|
|
|
|
* @param memory Memory context to handle the sync request under.
|
|
|
|
* @param core_timing Core timing context to schedule the request event under.
|
2019-11-26 20:10:49 +01:00
|
|
|
*
|
2016-06-15 01:03:30 +02:00
|
|
|
* @returns ResultCode from the operation.
|
2014-12-14 06:30:11 +01:00
|
|
|
*/
|
2021-04-03 03:02:10 +02:00
|
|
|
ResultCode HandleSyncRequest(KThread* thread, Core::Memory::Memory& memory,
|
2020-09-14 20:03:10 +02:00
|
|
|
Core::Timing::CoreTiming& core_timing);
|
2015-01-19 02:40:53 +01:00
|
|
|
|
2019-03-06 00:51:16 +01:00
|
|
|
/// Adds a new domain request handler to the collection of request handlers within
|
|
|
|
/// this ServerSession instance.
|
2021-05-16 08:49:03 +02:00
|
|
|
void AppendDomainHandler(SessionRequestHandlerPtr handler);
|
2017-06-21 00:33:28 +02:00
|
|
|
|
2019-03-06 00:51:16 +01:00
|
|
|
/// Retrieves the total number of domain request handlers that have been
|
|
|
|
/// appended to this ServerSession instance.
|
|
|
|
std::size_t NumDomainRequestHandlers() const;
|
2017-06-21 00:33:28 +02:00
|
|
|
|
2018-01-24 00:03:09 +01:00
|
|
|
/// Returns true if the session has been converted to a domain, otherwise False
|
|
|
|
bool IsDomain() const {
|
2021-05-16 08:49:03 +02:00
|
|
|
return manager->IsDomain();
|
2018-01-24 00:03:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Converts the session to a domain at the end of the current command
|
|
|
|
void ConvertToDomain() {
|
|
|
|
convert_to_domain = true;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Gets the session request manager, which forwards requests to the underlying service
|
|
|
|
const std::shared_ptr<SessionRequestManager>& GetSessionRequestManager() const {
|
|
|
|
return manager;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Sets the session request manager, which forwards requests to the underlying service
|
|
|
|
void SetSessionRequestManager(std::shared_ptr<SessionRequestManager> manager_) {
|
|
|
|
manager = std::move(manager_);
|
|
|
|
}
|
|
|
|
|
2016-12-05 17:02:08 +01:00
|
|
|
private:
|
2019-11-26 00:28:48 +01:00
|
|
|
/// Queues a sync request from the emulated application.
|
2021-04-03 03:02:10 +02:00
|
|
|
ResultCode QueueSyncRequest(KThread* thread, Core::Memory::Memory& memory);
|
2019-11-26 00:28:48 +01:00
|
|
|
|
|
|
|
/// Completes a sync request from the emulated application.
|
2020-12-10 06:27:05 +01:00
|
|
|
ResultCode CompleteSyncRequest(HLERequestContext& context);
|
2018-01-24 00:03:09 +01:00
|
|
|
|
2018-02-18 19:22:19 +01:00
|
|
|
/// Handles a SyncRequest to a domain, forwarding the request to the proper object or closing an
|
|
|
|
/// object handle.
|
|
|
|
ResultCode HandleDomainSyncRequest(Kernel::HLERequestContext& context);
|
|
|
|
|
2021-05-16 08:49:03 +02:00
|
|
|
/// This session's HLE request handlers
|
|
|
|
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
|
|
|
|
2020-12-10 06:27:05 +01:00
|
|
|
/// Thread to dispatch service requests
|
2020-12-15 09:41:48 +01:00
|
|
|
std::weak_ptr<ServiceThread> service_thread;
|
2021-04-14 02:48:37 +02:00
|
|
|
|
|
|
|
/// KSession that owns this KServerSession
|
|
|
|
KSession* parent{};
|
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
|