diff options
Diffstat (limited to '')
-rw-r--r-- | src/core/hle/kernel/k_client_port.cpp | 1 | ||||
-rw-r--r-- | src/core/hle/kernel/k_client_port.h | 1 | ||||
-rw-r--r-- | src/core/hle/kernel/k_client_session.cpp | 1 | ||||
-rw-r--r-- | src/core/hle/kernel/k_port.cpp | 1 | ||||
-rw-r--r-- | src/core/hle/kernel/k_server_session.cpp | 11 | ||||
-rw-r--r-- | src/core/hle/kernel/k_server_session.h | 12 | ||||
-rw-r--r-- | src/core/hle/service/hle_ipc.cpp (renamed from src/core/hle/kernel/hle_ipc.cpp) | 33 | ||||
-rw-r--r-- | src/core/hle/service/hle_ipc.h (renamed from src/core/hle/kernel/hle_ipc.h) | 77 |
8 files changed, 62 insertions, 75 deletions
diff --git a/src/core/hle/kernel/k_client_port.cpp b/src/core/hle/kernel/k_client_port.cpp index c72a91a76..700ae71e3 100644 --- a/src/core/hle/kernel/k_client_port.cpp +++ b/src/core/hle/kernel/k_client_port.cpp @@ -2,7 +2,6 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include "common/scope_exit.h" -#include "core/hle/kernel/hle_ipc.h" #include "core/hle/kernel/k_client_port.h" #include "core/hle/kernel/k_port.h" #include "core/hle/kernel/k_scheduler.h" diff --git a/src/core/hle/kernel/k_client_port.h b/src/core/hle/kernel/k_client_port.h index 81046fb86..a757cf9cd 100644 --- a/src/core/hle/kernel/k_client_port.h +++ b/src/core/hle/kernel/k_client_port.h @@ -15,7 +15,6 @@ namespace Kernel { class KClientSession; class KernelCore; class KPort; -class SessionRequestManager; class KClientPort final : public KSynchronizationObject { KERNEL_AUTOOBJECT_TRAITS(KClientPort, KSynchronizationObject); diff --git a/src/core/hle/kernel/k_client_session.cpp b/src/core/hle/kernel/k_client_session.cpp index b4197a8d5..da0c9ac8c 100644 --- a/src/core/hle/kernel/k_client_session.cpp +++ b/src/core/hle/kernel/k_client_session.cpp @@ -2,7 +2,6 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include "common/scope_exit.h" -#include "core/hle/kernel/hle_ipc.h" #include "core/hle/kernel/k_client_session.h" #include "core/hle/kernel/k_server_session.h" #include "core/hle/kernel/k_session.h" diff --git a/src/core/hle/kernel/k_port.cpp b/src/core/hle/kernel/k_port.cpp index 77d00ae2c..0a45ffd57 100644 --- a/src/core/hle/kernel/k_port.cpp +++ b/src/core/hle/kernel/k_port.cpp @@ -1,7 +1,6 @@ // SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later -#include "core/hle/kernel/hle_ipc.h" #include "core/hle/kernel/k_port.h" #include "core/hle/kernel/k_scheduler.h" #include "core/hle/kernel/svc_results.h" diff --git a/src/core/hle/kernel/k_server_session.cpp b/src/core/hle/kernel/k_server_session.cpp index aa1941f01..01591af5b 100644 --- a/src/core/hle/kernel/k_server_session.cpp +++ b/src/core/hle/kernel/k_server_session.cpp @@ -10,8 +10,6 @@ #include "common/scope_exit.h" #include "core/core.h" #include "core/core_timing.h" -#include "core/hle/ipc_helpers.h" -#include "core/hle/kernel/hle_ipc.h" #include "core/hle/kernel/k_client_port.h" #include "core/hle/kernel/k_handle_table.h" #include "core/hle/kernel/k_process.h" @@ -22,6 +20,8 @@ #include "core/hle/kernel/k_thread.h" #include "core/hle/kernel/k_thread_queue.h" #include "core/hle/kernel/kernel.h" +#include "core/hle/service/hle_ipc.h" +#include "core/hle/service/ipc_helpers.h" #include "core/memory.h" namespace Kernel { @@ -281,8 +281,8 @@ Result KServerSession::SendReply(bool is_hle) { return result; } -Result KServerSession::ReceiveRequest(std::shared_ptr<HLERequestContext>* out_context, - std::weak_ptr<SessionRequestManager> manager) { +Result KServerSession::ReceiveRequest(std::shared_ptr<Service::HLERequestContext>* out_context, + std::weak_ptr<Service::SessionRequestManager> manager) { // Lock the session. KScopedLightLock lk{m_lock}; @@ -329,7 +329,8 @@ Result KServerSession::ReceiveRequest(std::shared_ptr<HLERequestContext>* out_co if (out_context != nullptr) { // HLE request. u32* cmd_buf{reinterpret_cast<u32*>(memory.GetPointer(client_message))}; - *out_context = std::make_shared<HLERequestContext>(kernel, memory, this, client_thread); + *out_context = + std::make_shared<Service::HLERequestContext>(kernel, memory, this, client_thread); (*out_context)->SetSessionRequestManager(manager); (*out_context) ->PopulateFromIncomingCommandBuffer(client_thread->GetOwnerProcess()->GetHandleTable(), diff --git a/src/core/hle/kernel/k_server_session.h b/src/core/hle/kernel/k_server_session.h index 6e189af8b..33f380352 100644 --- a/src/core/hle/kernel/k_server_session.h +++ b/src/core/hle/kernel/k_server_session.h @@ -10,18 +10,20 @@ #include <boost/intrusive/list.hpp> -#include "core/hle/kernel/hle_ipc.h" #include "core/hle/kernel/k_light_lock.h" #include "core/hle/kernel/k_session_request.h" #include "core/hle/kernel/k_synchronization_object.h" #include "core/hle/result.h" +namespace Service { +class HLERequestContext; +class SessionRequestManager; +} // namespace Service + namespace Kernel { -class HLERequestContext; class KernelCore; class KSession; -class SessionRequestManager; class KThread; class KServerSession final : public KSynchronizationObject, @@ -52,8 +54,8 @@ public: /// TODO: flesh these out to match the real kernel Result OnRequest(KSessionRequest* request); Result SendReply(bool is_hle = false); - Result ReceiveRequest(std::shared_ptr<HLERequestContext>* out_context = nullptr, - std::weak_ptr<SessionRequestManager> manager = {}); + Result ReceiveRequest(std::shared_ptr<Service::HLERequestContext>* out_context = nullptr, + std::weak_ptr<Service::SessionRequestManager> manager = {}); Result SendReplyHLE() { return SendReply(true); diff --git a/src/core/hle/kernel/hle_ipc.cpp b/src/core/hle/service/hle_ipc.cpp index 876fbbe53..c221ffe11 100644 --- a/src/core/hle/kernel/hle_ipc.cpp +++ b/src/core/hle/service/hle_ipc.cpp @@ -12,8 +12,6 @@ #include "common/common_types.h" #include "common/logging/log.h" #include "common/scratch_buffer.h" -#include "core/hle/ipc_helpers.h" -#include "core/hle/kernel/hle_ipc.h" #include "core/hle/kernel/k_auto_object.h" #include "core/hle/kernel/k_handle_table.h" #include "core/hle/kernel/k_process.h" @@ -21,17 +19,19 @@ #include "core/hle/kernel/k_server_session.h" #include "core/hle/kernel/k_thread.h" #include "core/hle/kernel/kernel.h" +#include "core/hle/service/hle_ipc.h" +#include "core/hle/service/ipc_helpers.h" #include "core/memory.h" -namespace Kernel { +namespace Service { -SessionRequestHandler::SessionRequestHandler(KernelCore& kernel_, const char* service_name_) +SessionRequestHandler::SessionRequestHandler(Kernel::KernelCore& kernel_, const char* service_name_) : kernel{kernel_} {} SessionRequestHandler::~SessionRequestHandler() = default; -SessionRequestManager::SessionRequestManager(KernelCore& kernel_, - Service::ServerManager& server_manager_) +SessionRequestManager::SessionRequestManager(Kernel::KernelCore& kernel_, + ServerManager& server_manager_) : kernel{kernel_}, server_manager{server_manager_} {} SessionRequestManager::~SessionRequestManager() = default; @@ -51,7 +51,7 @@ bool SessionRequestManager::HasSessionRequestHandler(const HLERequestContext& co } } -Result SessionRequestManager::CompleteSyncRequest(KServerSession* server_session, +Result SessionRequestManager::CompleteSyncRequest(Kernel::KServerSession* server_session, HLERequestContext& context) { Result result = ResultSuccess; @@ -79,7 +79,7 @@ Result SessionRequestManager::CompleteSyncRequest(KServerSession* server_session return result; } -Result SessionRequestManager::HandleDomainSyncRequest(KServerSession* server_session, +Result SessionRequestManager::HandleDomainSyncRequest(Kernel::KServerSession* server_session, HLERequestContext& context) { if (!context.HasDomainMessageHeader()) { return ResultSuccess; @@ -124,16 +124,17 @@ Result SessionRequestManager::HandleDomainSyncRequest(KServerSession* server_ses return ResultSuccess; } -HLERequestContext::HLERequestContext(KernelCore& kernel_, Core::Memory::Memory& memory_, - KServerSession* server_session_, KThread* thread_) +HLERequestContext::HLERequestContext(Kernel::KernelCore& kernel_, Core::Memory::Memory& memory_, + Kernel::KServerSession* server_session_, + Kernel::KThread* thread_) : server_session(server_session_), thread(thread_), kernel{kernel_}, memory{memory_} { cmd_buf[0] = 0; } HLERequestContext::~HLERequestContext() = default; -void HLERequestContext::ParseCommandBuffer(const KHandleTable& handle_table, u32_le* src_cmdbuf, - bool incoming) { +void HLERequestContext::ParseCommandBuffer(const Kernel::KHandleTable& handle_table, + u32_le* src_cmdbuf, bool incoming) { IPC::RequestParser rp(src_cmdbuf); command_header = rp.PopRaw<IPC::CommandHeader>(); @@ -253,8 +254,8 @@ void HLERequestContext::ParseCommandBuffer(const KHandleTable& handle_table, u32 rp.Skip(1, false); // The command is actually an u64, but we don't use the high part. } -Result HLERequestContext::PopulateFromIncomingCommandBuffer(const KHandleTable& handle_table, - u32_le* src_cmdbuf) { +Result HLERequestContext::PopulateFromIncomingCommandBuffer( + const Kernel::KHandleTable& handle_table, u32_le* src_cmdbuf) { ParseCommandBuffer(handle_table, src_cmdbuf, true); if (command_header->IsCloseCommand()) { @@ -267,7 +268,7 @@ Result HLERequestContext::PopulateFromIncomingCommandBuffer(const KHandleTable& return ResultSuccess; } -Result HLERequestContext::WriteToOutgoingCommandBuffer(KThread& requesting_thread) { +Result HLERequestContext::WriteToOutgoingCommandBuffer(Kernel::KThread& requesting_thread) { auto current_offset = handles_offset; auto& owner_process = *requesting_thread.GetOwnerProcess(); auto& handle_table = owner_process.GetHandleTable(); @@ -528,4 +529,4 @@ std::string HLERequestContext::Description() const { return s.str(); } -} // namespace Kernel +} // namespace Service diff --git a/src/core/hle/kernel/hle_ipc.h b/src/core/hle/service/hle_ipc.h index b4364f984..4bd24c899 100644 --- a/src/core/hle/kernel/hle_ipc.h +++ b/src/core/hle/service/hle_ipc.h @@ -35,20 +35,18 @@ class ServerManager; } // namespace Service namespace Kernel { - -class Domain; -class HLERequestContext; class KAutoObject; class KernelCore; -class KEvent; class KHandleTable; -class KServerPort; -class KProcess; class KServerSession; class KThread; -class KReadableEvent; -class KSession; -class SessionRequestManager; +} // namespace Kernel + +namespace Service { + +using Handle = Kernel::Handle; + +class HLERequestContext; /** * Interface implemented by HLE Session handlers. @@ -57,7 +55,7 @@ class SessionRequestManager; */ class SessionRequestHandler : public std::enable_shared_from_this<SessionRequestHandler> { public: - SessionRequestHandler(KernelCore& kernel_, const char* service_name_); + SessionRequestHandler(Kernel::KernelCore& kernel_, const char* service_name_); virtual ~SessionRequestHandler(); /** @@ -69,10 +67,10 @@ public: * @returns Result the result code of the translate operation. */ virtual Result HandleSyncRequest(Kernel::KServerSession& session, - Kernel::HLERequestContext& context) = 0; + HLERequestContext& context) = 0; protected: - KernelCore& kernel; + Kernel::KernelCore& kernel; }; using SessionRequestHandlerWeakPtr = std::weak_ptr<SessionRequestHandler>; @@ -85,7 +83,8 @@ using SessionRequestHandlerPtr = std::shared_ptr<SessionRequestHandler>; */ class SessionRequestManager final { public: - explicit SessionRequestManager(KernelCore& kernel, Service::ServerManager& server_manager); + explicit SessionRequestManager(Kernel::KernelCore& kernel, + Service::ServerManager& server_manager); ~SessionRequestManager(); bool IsDomain() const { @@ -140,8 +139,9 @@ public: bool HasSessionRequestHandler(const HLERequestContext& context) const; - Result HandleDomainSyncRequest(KServerSession* server_session, HLERequestContext& context); - Result CompleteSyncRequest(KServerSession* server_session, HLERequestContext& context); + Result HandleDomainSyncRequest(Kernel::KServerSession* server_session, + HLERequestContext& context); + Result CompleteSyncRequest(Kernel::KServerSession* server_session, HLERequestContext& context); Service::ServerManager& GetServerManager() { return server_manager; @@ -166,33 +166,18 @@ private: std::vector<SessionRequestHandlerPtr> domain_handlers; private: - KernelCore& kernel; + Kernel::KernelCore& kernel; Service::ServerManager& server_manager; }; /** * Class containing information about an in-flight IPC request being handled by an HLE service - * implementation. Services should avoid using old global APIs (e.g. Kernel::GetCommandBuffer()) and - * when possible use the APIs in this class to service the request. - * - * HLE handle protocol - * =================== - * - * To avoid needing HLE services to keep a separate handle table, or having to directly modify the - * requester's table, a tweaked protocol is used to receive and send handles in requests. The kernel - * will decode the incoming handles into object pointers and insert a id in the buffer where the - * handle would normally be. The service then calls GetIncomingHandle() with that id to get the - * pointer to the object. Similarly, instead of inserting a handle into the command buffer, the - * service calls AddOutgoingHandle() and stores the returned id where the handle would normally go. - * - * The end result is similar to just giving services their own real handle tables, but since these - * ids are local to a specific context, it avoids requiring services to manage handles for objects - * across multiple calls and ensuring that unneeded handles are cleaned up. + * implementation. */ class HLERequestContext { public: - explicit HLERequestContext(KernelCore& kernel, Core::Memory::Memory& memory, - KServerSession* session, KThread* thread); + explicit HLERequestContext(Kernel::KernelCore& kernel, Core::Memory::Memory& memory, + Kernel::KServerSession* session, Kernel::KThread* thread); ~HLERequestContext(); /// Returns a pointer to the IPC command buffer for this request. @@ -209,10 +194,11 @@ public: } /// Populates this context with data from the requesting process/thread. - Result PopulateFromIncomingCommandBuffer(const KHandleTable& handle_table, u32_le* src_cmdbuf); + Result PopulateFromIncomingCommandBuffer(const Kernel::KHandleTable& handle_table, + u32_le* src_cmdbuf); /// Writes data from this context back to the requesting process/thread. - Result WriteToOutgoingCommandBuffer(KThread& requesting_thread); + Result WriteToOutgoingCommandBuffer(Kernel::KThread& requesting_thread); [[nodiscard]] u32_le GetHipcCommand() const { return command; @@ -339,11 +325,11 @@ public: return incoming_move_handles.at(index); } - void AddMoveObject(KAutoObject* object) { + void AddMoveObject(Kernel::KAutoObject* object) { outgoing_move_objects.emplace_back(object); } - void AddCopyObject(KAutoObject* object) { + void AddCopyObject(Kernel::KAutoObject* object) { outgoing_copy_objects.emplace_back(object); } @@ -362,7 +348,7 @@ public: [[nodiscard]] std::string Description() const; - [[nodiscard]] KThread& GetThread() { + [[nodiscard]] Kernel::KThread& GetThread() { return *thread; } @@ -381,17 +367,18 @@ public: private: friend class IPC::ResponseBuilder; - void ParseCommandBuffer(const KHandleTable& handle_table, u32_le* src_cmdbuf, bool incoming); + void ParseCommandBuffer(const Kernel::KHandleTable& handle_table, u32_le* src_cmdbuf, + bool incoming); std::array<u32, IPC::COMMAND_BUFFER_LENGTH> cmd_buf; Kernel::KServerSession* server_session{}; - KThread* thread; + Kernel::KThread* thread; std::vector<Handle> incoming_move_handles; std::vector<Handle> incoming_copy_handles; - std::vector<KAutoObject*> outgoing_move_objects; - std::vector<KAutoObject*> outgoing_copy_objects; + std::vector<Kernel::KAutoObject*> outgoing_move_objects; + std::vector<Kernel::KAutoObject*> outgoing_copy_objects; std::vector<SessionRequestHandlerPtr> outgoing_domain_objects; std::optional<IPC::CommandHeader> command_header; @@ -414,8 +401,8 @@ private: std::weak_ptr<SessionRequestManager> manager{}; bool is_deferred{false}; - KernelCore& kernel; + Kernel::KernelCore& kernel; Core::Memory::Memory& memory; }; -} // namespace Kernel +} // namespace Service |