From e707685c2a1cfbede81e30594d865b11268a5362 Mon Sep 17 00:00:00 2001 From: Hamish Milne Date: Tue, 24 Dec 2019 23:53:51 +0000 Subject: [PATCH] Serialize AM services --- TODO | 2 +- src/core/hle/service/am/am.cpp | 8 +++++--- src/core/hle/service/am/am.h | 26 ++++++++++++++++++++++++-- src/core/hle/service/am/am_app.cpp | 3 +++ src/core/hle/service/am/am_app.h | 5 +++++ src/core/hle/service/am/am_net.cpp | 3 +++ src/core/hle/service/am/am_net.h | 5 +++++ src/core/hle/service/am/am_sys.cpp | 3 +++ src/core/hle/service/am/am_sys.h | 5 +++++ src/core/hle/service/am/am_u.cpp | 3 +++ src/core/hle/service/am/am_u.h | 5 +++++ src/core/hle/service/fs/archive.cpp | 3 ++- src/core/hle/service/fs/file.cpp | 10 +++++----- src/core/hle/service/fs/file.h | 4 ++-- 14 files changed, 71 insertions(+), 14 deletions(-) diff --git a/TODO b/TODO index a7488a20f..673ef0a14 100644 --- a/TODO +++ b/TODO @@ -63,7 +63,7 @@ ☐ Service @started(19-12-23 12:49) ✔ AC @started(19-12-23 12:48) @done(19-12-24 22:38) @lasted(1d9h50m3s) ✔ ACT @done(19-12-24 23:17) - ☐ AM + ✔ AM @started(19-12-24 23:17) @done(19-12-24 23:53) @lasted(36m8s) ☐ APT ☐ BOSS ☐ CAM diff --git a/src/core/hle/service/am/am.cpp b/src/core/hle/service/am/am.cpp index 65b9c3e01..45ed29e6c 100644 --- a/src/core/hle/service/am/am.cpp +++ b/src/core/hle/service/am/am.cpp @@ -1021,7 +1021,7 @@ void Module::Interface::BeginImportProgram(Kernel::HLERequestContext& ctx) { // Citra will store contents out to sdmc/nand const FileSys::Path cia_path = {}; auto file = std::make_shared( - am->system, std::make_unique(media_type), cia_path); + am->kernel, std::make_unique(media_type), cia_path); am->cia_installing = true; @@ -1048,7 +1048,7 @@ void Module::Interface::BeginImportProgramTemporarily(Kernel::HLERequestContext& // contents out to sdmc/nand const FileSys::Path cia_path = {}; auto file = std::make_shared( - am->system, std::make_unique(FS::MediaType::NAND), cia_path); + am->kernel, std::make_unique(FS::MediaType::NAND), cia_path); am->cia_installing = true; @@ -1450,11 +1450,13 @@ void Module::Interface::GetMetaDataFromCia(Kernel::HLERequestContext& ctx) { rb.PushMappedBuffer(output_buffer); } -Module::Module(Core::System& system) : system(system) { +Module::Module(Core::System& system) : kernel(system.Kernel()) { ScanForAllTitles(); system_updater_mutex = system.Kernel().CreateMutex(false, "AM::SystemUpdaterMutex"); } +Module::Module(Kernel::KernelSystem& kernel) : kernel(kernel) { } + Module::~Module() = default; void InstallInterfaces(Core::System& system) { diff --git a/src/core/hle/service/am/am.h b/src/core/hle/service/am/am.h index 0912dde40..88a70bf10 100644 --- a/src/core/hle/service/am/am.h +++ b/src/core/hle/service/am/am.h @@ -9,6 +9,9 @@ #include #include #include +#include +#include +#include #include "common/common_types.h" #include "core/file_sys/cia_container.h" #include "core/file_sys/file_backend.h" @@ -150,6 +153,8 @@ std::string GetMediaTitlePath(Service::FS::MediaType media_type); class Module final { public: explicit Module(Core::System& system); + explicit Module(Kernel::KernelSystem& kernel); + Module() = default; ~Module(); class Interface : public ServiceFramework { @@ -557,7 +562,7 @@ public: */ void GetMetaDataFromCia(Kernel::HLERequestContext& ctx); - private: + protected: std::shared_ptr am; }; @@ -573,12 +578,29 @@ private: */ void ScanForAllTitles(); - Core::System& system; + Kernel::KernelSystem& kernel; bool cia_installing = false; std::array, 3> am_title_list; std::shared_ptr system_updater_mutex; + + template + void serialize(Archive& ar, const unsigned int) + { + ar & cia_installing; + ar & am_title_list; + ar & system_updater_mutex; + } + friend class boost::serialization::access; }; void InstallInterfaces(Core::System& system); } // namespace Service::AM + +namespace boost::serialization { + template + inline void load_construct_data(Archive& ar, Service::AM::Module* t, const unsigned int) + { + ::new(t)Service::AM::Module(*Kernel::g_kernel); + } +} diff --git a/src/core/hle/service/am/am_app.cpp b/src/core/hle/service/am/am_app.cpp index cee1aa81b..52d256ca2 100644 --- a/src/core/hle/service/am/am_app.cpp +++ b/src/core/hle/service/am/am_app.cpp @@ -3,6 +3,7 @@ // Refer to the license.txt file included. #include "core/hle/service/am/am_app.h" +#include "common/archives.h" namespace Service::AM { @@ -26,3 +27,5 @@ AM_APP::AM_APP(std::shared_ptr am) : Module::Interface(std::move(am), "a } } // namespace Service::AM + +SERIALIZE_EXPORT_IMPL(Service::AM::AM_APP) diff --git a/src/core/hle/service/am/am_app.h b/src/core/hle/service/am/am_app.h index 67cf8ba2e..e78b5ef70 100644 --- a/src/core/hle/service/am/am_app.h +++ b/src/core/hle/service/am/am_app.h @@ -11,6 +11,11 @@ namespace Service::AM { class AM_APP final : public Module::Interface { public: explicit AM_APP(std::shared_ptr am); +private: + SERVICE_SERIALIZATION(AM_APP, am) }; } // namespace Service::AM + +BOOST_CLASS_EXPORT_KEY(Service::AM::AM_APP) +BOOST_SERIALIZATION_CONSTRUCT(Service::AM::AM_APP) diff --git a/src/core/hle/service/am/am_net.cpp b/src/core/hle/service/am/am_net.cpp index 120ee53e7..44c852c19 100644 --- a/src/core/hle/service/am/am_net.cpp +++ b/src/core/hle/service/am/am_net.cpp @@ -3,6 +3,7 @@ // Refer to the license.txt file included. #include "core/hle/service/am/am_net.h" +#include "common/archives.h" namespace Service::AM { @@ -123,3 +124,5 @@ AM_NET::AM_NET(std::shared_ptr am) : Module::Interface(std::move(am), "a } } // namespace Service::AM + +SERIALIZE_EXPORT_IMPL(Service::AM::AM_NET) diff --git a/src/core/hle/service/am/am_net.h b/src/core/hle/service/am/am_net.h index a5adbd7e5..74e335b76 100644 --- a/src/core/hle/service/am/am_net.h +++ b/src/core/hle/service/am/am_net.h @@ -11,6 +11,11 @@ namespace Service::AM { class AM_NET final : public Module::Interface { public: explicit AM_NET(std::shared_ptr am); +private: + SERVICE_SERIALIZATION(AM_NET, am) }; } // namespace Service::AM + +BOOST_CLASS_EXPORT_KEY(Service::AM::AM_NET) +BOOST_SERIALIZATION_CONSTRUCT(Service::AM::AM_NET) diff --git a/src/core/hle/service/am/am_sys.cpp b/src/core/hle/service/am/am_sys.cpp index ca4affbc2..c6817fe87 100644 --- a/src/core/hle/service/am/am_sys.cpp +++ b/src/core/hle/service/am/am_sys.cpp @@ -3,6 +3,7 @@ // Refer to the license.txt file included. #include "core/hle/service/am/am_sys.h" +#include "common/archives.h" namespace Service::AM { @@ -71,3 +72,5 @@ AM_SYS::AM_SYS(std::shared_ptr am) : Module::Interface(std::move(am), "a } } // namespace Service::AM + +SERIALIZE_EXPORT_IMPL(Service::AM::AM_SYS) diff --git a/src/core/hle/service/am/am_sys.h b/src/core/hle/service/am/am_sys.h index b142916ca..028837f3d 100644 --- a/src/core/hle/service/am/am_sys.h +++ b/src/core/hle/service/am/am_sys.h @@ -11,6 +11,11 @@ namespace Service::AM { class AM_SYS final : public Module::Interface { public: explicit AM_SYS(std::shared_ptr am); +private: + SERVICE_SERIALIZATION(AM_SYS, am) }; } // namespace Service::AM + +BOOST_CLASS_EXPORT_KEY(Service::AM::AM_SYS) +BOOST_SERIALIZATION_CONSTRUCT(Service::AM::AM_SYS) diff --git a/src/core/hle/service/am/am_u.cpp b/src/core/hle/service/am/am_u.cpp index 840860ec0..c9b80bf06 100644 --- a/src/core/hle/service/am/am_u.cpp +++ b/src/core/hle/service/am/am_u.cpp @@ -3,6 +3,7 @@ // Refer to the license.txt file included. #include "core/hle/service/am/am_u.h" +#include "common/archives.h" namespace Service::AM { @@ -83,3 +84,5 @@ AM_U::AM_U(std::shared_ptr am) : Module::Interface(std::move(am), "am:u" } } // namespace Service::AM + +SERIALIZE_EXPORT_IMPL(Service::AM::AM_U) diff --git a/src/core/hle/service/am/am_u.h b/src/core/hle/service/am/am_u.h index 1d732c90a..b19d48167 100644 --- a/src/core/hle/service/am/am_u.h +++ b/src/core/hle/service/am/am_u.h @@ -11,6 +11,11 @@ namespace Service::AM { class AM_U final : public Module::Interface { public: explicit AM_U(std::shared_ptr am); +private: + SERVICE_SERIALIZATION(AM_U, am) }; } // namespace Service::AM + +BOOST_CLASS_EXPORT_KEY(Service::AM::AM_U) +BOOST_SERIALIZATION_CONSTRUCT(Service::AM::AM_U) diff --git a/src/core/hle/service/fs/archive.cpp b/src/core/hle/service/fs/archive.cpp index 6e179978b..90dfad62f 100644 --- a/src/core/hle/service/fs/archive.cpp +++ b/src/core/hle/service/fs/archive.cpp @@ -27,6 +27,7 @@ #include "core/file_sys/file_backend.h" #include "core/hle/result.h" #include "core/hle/service/fs/archive.h" +#include "core/core.h" namespace Service::FS { @@ -90,7 +91,7 @@ ArchiveManager::OpenFileFromArchive(ArchiveHandle archive_handle, const FileSys: if (backend.Failed()) return std::make_tuple(backend.Code(), open_timeout_ns); - auto file = std::shared_ptr(new File(system, std::move(backend).Unwrap(), path)); + auto file = std::shared_ptr(new File(system.Kernel(), std::move(backend).Unwrap(), path)); return std::make_tuple(MakeResult>(std::move(file)), open_timeout_ns); } diff --git a/src/core/hle/service/fs/file.cpp b/src/core/hle/service/fs/file.cpp index e31f89d0e..946e27211 100644 --- a/src/core/hle/service/fs/file.cpp +++ b/src/core/hle/service/fs/file.cpp @@ -15,9 +15,9 @@ namespace Service::FS { -File::File(Core::System& system, std::unique_ptr&& backend, +File::File(Kernel::KernelSystem& kernel, std::unique_ptr&& backend, const FileSys::Path& path) - : ServiceFramework("", 1), path(path), backend(std::move(backend)), system(system) { + : ServiceFramework("", 1), path(path), backend(std::move(backend)), kernel(kernel) { static const FunctionInfo functions[] = { {0x08010100, &File::OpenSubFile, "OpenSubFile"}, {0x080200C2, &File::Read, "Read"}, @@ -197,7 +197,7 @@ void File::OpenLinkFile(Kernel::HLERequestContext& ctx) { using Kernel::ServerSession; IPC::RequestParser rp(ctx, 0x080C, 0, 0); IPC::RequestBuilder rb = rp.MakeBuilder(1, 2); - auto [server, client] = system.Kernel().CreateSessionPair(GetName()); + auto [server, client] = kernel.CreateSessionPair(GetName()); ClientConnected(server); FileSessionSlot* slot = GetSessionData(server); @@ -243,7 +243,7 @@ void File::OpenSubFile(Kernel::HLERequestContext& ctx) { using Kernel::ClientSession; using Kernel::ServerSession; - auto [server, client] = system.Kernel().CreateSessionPair(GetName()); + auto [server, client] = kernel.CreateSessionPair(GetName()); ClientConnected(server); FileSessionSlot* slot = GetSessionData(server); @@ -257,7 +257,7 @@ void File::OpenSubFile(Kernel::HLERequestContext& ctx) { } std::shared_ptr File::Connect() { - auto [server, client] = system.Kernel().CreateSessionPair(GetName()); + auto [server, client] = kernel.CreateSessionPair(GetName()); ClientConnected(server); FileSessionSlot* slot = GetSessionData(server); diff --git a/src/core/hle/service/fs/file.h b/src/core/hle/service/fs/file.h index 062fcd5e7..ff4a5670a 100644 --- a/src/core/hle/service/fs/file.h +++ b/src/core/hle/service/fs/file.h @@ -25,7 +25,7 @@ struct FileSessionSlot : public Kernel::SessionRequestHandler::SessionDataBase { // Consider splitting ServiceFramework interface. class File final : public ServiceFramework { public: - File(Core::System& system, std::unique_ptr&& backend, + File(Kernel::KernelSystem& kernel, std::unique_ptr&& backend, const FileSys::Path& path); ~File() = default; @@ -59,7 +59,7 @@ private: void OpenLinkFile(Kernel::HLERequestContext& ctx); void OpenSubFile(Kernel::HLERequestContext& ctx); - Core::System& system; + Kernel::KernelSystem& kernel; }; } // namespace Service::FS