From 06891d94542fcf5ec6e1c45435df097d48b8ca77 Mon Sep 17 00:00:00 2001 From: Hamish Milne Date: Sun, 11 Aug 2019 22:29:00 +0100 Subject: [PATCH] Added client/server objects --- src/core/CMakeLists.txt | 1 + src/core/hle/kernel/client_port.cpp | 3 +++ src/core/hle/kernel/client_port.h | 3 +++ src/core/hle/kernel/client_session.cpp | 6 ++++-- src/core/hle/kernel/client_session.h | 17 ++++++++++++++++- src/core/hle/kernel/server_port.cpp | 3 +++ src/core/hle/kernel/server_port.h | 18 ++++++++++++++++++ src/core/hle/kernel/server_session.cpp | 7 +++++-- src/core/hle/kernel/server_session.h | 19 +++++++++++++++++++ src/core/hle/kernel/session.cpp | 18 +++++++++++++++--- src/core/hle/kernel/session.h | 6 ++++++ 11 files changed, 93 insertions(+), 8 deletions(-) diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index ed2642431..9ed9a856d 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -162,6 +162,7 @@ add_library(core STATIC hle/kernel/server_session.cpp hle/kernel/server_session.h hle/kernel/session.h + hle/kernel/session.cpp hle/kernel/shared_memory.cpp hle/kernel/shared_memory.h hle/kernel/shared_page.cpp diff --git a/src/core/hle/kernel/client_port.cpp b/src/core/hle/kernel/client_port.cpp index dc0e08d9d..3334a278b 100644 --- a/src/core/hle/kernel/client_port.cpp +++ b/src/core/hle/kernel/client_port.cpp @@ -2,6 +2,7 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. +#include "common/archives.h" #include "common/assert.h" #include "core/hle/kernel/client_port.h" #include "core/hle/kernel/client_session.h" @@ -11,6 +12,8 @@ #include "core/hle/kernel/server_port.h" #include "core/hle/kernel/server_session.h" +SERIALIZE_EXPORT_IMPL(Kernel::ClientPort) + namespace Kernel { ResultVal> ClientPort::Connect() { diff --git a/src/core/hle/kernel/client_port.h b/src/core/hle/kernel/client_port.h index 35544e37e..72cae85c3 100644 --- a/src/core/hle/kernel/client_port.h +++ b/src/core/hle/kernel/client_port.h @@ -6,6 +6,7 @@ #include #include +#include #include "common/common_types.h" #include "core/hle/kernel/object.h" #include "core/hle/kernel/server_port.h" @@ -72,3 +73,5 @@ private: }; } // namespace Kernel + +BOOST_CLASS_EXPORT_KEY(Kernel::ClientPort) diff --git a/src/core/hle/kernel/client_session.cpp b/src/core/hle/kernel/client_session.cpp index 3e76f1a4e..ba9c2ec50 100644 --- a/src/core/hle/kernel/client_session.cpp +++ b/src/core/hle/kernel/client_session.cpp @@ -3,7 +3,7 @@ // Refer to the license.txt file included. #include "common/assert.h" - +#include "common/archives.h" #include "core/hle/kernel/client_session.h" #include "core/hle/kernel/errors.h" #include "core/hle/kernel/hle_ipc.h" @@ -11,9 +11,11 @@ #include "core/hle/kernel/session.h" #include "core/hle/kernel/thread.h" +SERIALIZE_EXPORT_IMPL(Kernel::ClientSession) + namespace Kernel { -ClientSession::ClientSession(KernelSystem& kernel) : Object(kernel) {} +ClientSession::ClientSession() = default; ClientSession::~ClientSession() { // This destructor will be called automatically when the last ClientSession handle is closed by // the emulated application. diff --git a/src/core/hle/kernel/client_session.h b/src/core/hle/kernel/client_session.h index de2c7b0ba..2ffe68f8b 100644 --- a/src/core/hle/kernel/client_session.h +++ b/src/core/hle/kernel/client_session.h @@ -6,6 +6,9 @@ #include #include +#include +#include +#include #include "common/common_types.h" #include "core/hle/kernel/object.h" #include "core/hle/result.h" @@ -17,7 +20,7 @@ class Thread; class ClientSession final : public Object { public: - explicit ClientSession(KernelSystem& kernel); + explicit ClientSession(); ~ClientSession() override; friend class KernelSystem; @@ -46,6 +49,18 @@ public: /// The parent session, which links to the server endpoint. std::shared_ptr parent; + +private: + friend class boost::serialization::access; + template + void serialize(Archive& ar, const unsigned int file_version) + { + ar & boost::serialization::base_object(*this); + ar & name; + ar & parent; + } }; } // namespace Kernel + +BOOST_CLASS_EXPORT_KEY(Kernel::ClientSession) diff --git a/src/core/hle/kernel/server_port.cpp b/src/core/hle/kernel/server_port.cpp index ca4cded3d..191b43ea8 100644 --- a/src/core/hle/kernel/server_port.cpp +++ b/src/core/hle/kernel/server_port.cpp @@ -3,6 +3,7 @@ // Refer to the license.txt file included. #include +#include "common/archives.h" #include "common/assert.h" #include "core/hle/kernel/client_port.h" #include "core/hle/kernel/errors.h" @@ -11,6 +12,8 @@ #include "core/hle/kernel/server_session.h" #include "core/hle/kernel/thread.h" +SERIALIZE_EXPORT_IMPL(Kernel::ServerPort) + namespace Kernel { ResultVal> ServerPort::Accept() { diff --git a/src/core/hle/kernel/server_port.h b/src/core/hle/kernel/server_port.h index c500fd1b2..e0014ee7c 100644 --- a/src/core/hle/kernel/server_port.h +++ b/src/core/hle/kernel/server_port.h @@ -7,8 +7,13 @@ #include #include #include +#include +#include +#include +#include #include "common/common_types.h" #include "core/hle/kernel/object.h" +#include "core/hle/kernel/server_session.h" #include "core/hle/kernel/wait_object.h" #include "core/hle/result.h" @@ -58,6 +63,19 @@ public: bool ShouldWait(const Thread* thread) const override; void Acquire(Thread* thread) override; + +private: + friend class boost::serialization::access; + template + void serialize(Archive& ar, const unsigned int file_version) + { + ar & boost::serialization::base_object(*this); + ar & name; + ar & pending_sessions; + //ar & hle_handler; + } }; } // namespace Kernel + +BOOST_CLASS_EXPORT_KEY(Kernel::ServerPort) diff --git a/src/core/hle/kernel/server_session.cpp b/src/core/hle/kernel/server_session.cpp index c6a6261a5..f2ceb899e 100644 --- a/src/core/hle/kernel/server_session.cpp +++ b/src/core/hle/kernel/server_session.cpp @@ -3,7 +3,7 @@ // Refer to the license.txt file included. #include - +#include "common/archives.h" #include "core/hle/kernel/client_port.h" #include "core/hle/kernel/client_session.h" #include "core/hle/kernel/hle_ipc.h" @@ -11,6 +11,8 @@ #include "core/hle/kernel/session.h" #include "core/hle/kernel/thread.h" +SERIALIZE_EXPORT_IMPL(Kernel::ServerSession) + namespace Kernel { ServerSession::ServerSession() : kernel(*g_kernel) {} @@ -124,7 +126,8 @@ ResultCode ServerSession::HandleSyncRequest(std::shared_ptr thread) { KernelSystem::SessionPair KernelSystem::CreateSessionPair(const std::string& name, std::shared_ptr port) { auto server_session = ServerSession::Create(*this, name + "_Server").Unwrap(); - auto client_session{std::make_shared(*this)}; + auto client_session{std::make_shared()}; + client_session->Init(*this); client_session->name = name + "_Client"; std::shared_ptr parent(new Session); diff --git a/src/core/hle/kernel/server_session.h b/src/core/hle/kernel/server_session.h index 3536bcbd1..6112eefac 100644 --- a/src/core/hle/kernel/server_session.h +++ b/src/core/hle/kernel/server_session.h @@ -6,10 +6,14 @@ #include #include +#include +#include +#include #include "common/assert.h" #include "common/common_types.h" #include "core/hle/kernel/ipc.h" #include "core/hle/kernel/object.h" +#include "core/hle/kernel/session.h" #include "core/hle/kernel/wait_object.h" #include "core/hle/result.h" #include "core/memory.h" @@ -103,6 +107,21 @@ private: friend class KernelSystem; KernelSystem& kernel; + + friend class boost::serialization::access; + template + void serialize(Archive& ar, const unsigned int file_version) + { + ar & boost::serialization::base_object(*this); + ar & name; + ar & parent; + //ar & hle_handler; + ar & pending_requesting_threads; + ar & currently_handling; + //ar & mapped_buffer_context; + } }; } // namespace Kernel + +BOOST_CLASS_EXPORT_KEY(Kernel::ServerSession) diff --git a/src/core/hle/kernel/session.cpp b/src/core/hle/kernel/session.cpp index 642914744..f264c49bd 100644 --- a/src/core/hle/kernel/session.cpp +++ b/src/core/hle/kernel/session.cpp @@ -2,11 +2,23 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. +#include +#include "common/archives.h" #include "core/hle/kernel/session.h" -#include "core/hle/kernel/thread.h" +#include "core/hle/kernel/client_session.h" +#include "core/hle/kernel/server_session.h" +#include "core/hle/kernel/client_port.h" + +SERIALIZE_IMPL(Kernel::Session) namespace Kernel { -Session::Session() {} -Session::~Session() {} +template +void Session::serialize(Archive& ar, const unsigned int file_version) +{ + ar & client; + ar & server; + ar & port; +} + } // namespace Kernel diff --git a/src/core/hle/kernel/session.h b/src/core/hle/kernel/session.h index 17bb4d6c6..eca1a9252 100644 --- a/src/core/hle/kernel/session.h +++ b/src/core/hle/kernel/session.h @@ -5,6 +5,7 @@ #pragma once #include +#include #include "core/hle/kernel/object.h" namespace Kernel { @@ -24,5 +25,10 @@ public: ClientSession* client = nullptr; ///< The client endpoint of the session. ServerSession* server = nullptr; ///< The server endpoint of the session. std::shared_ptr port; ///< The port that this session is associated with (optional). + +private: + friend class boost::serialization::access; + template + void serialize(Archive& ar, const unsigned int file_version); }; } // namespace Kernel