From e4f05884c3be6249a8ab03e8b2c6bb8cb9caa7ac Mon Sep 17 00:00:00 2001 From: Hamish Milne Date: Sat, 11 Jan 2020 16:33:48 +0000 Subject: [PATCH] Fixed serialization runtime exceptions --- TODO | 19 +++++++++---------- src/common/file_util.h | 1 + src/core/file_sys/archive_ncch.cpp | 1 + src/core/file_sys/archive_ncch.h | 14 +++++++++++--- src/core/file_sys/archive_selfncch.cpp | 21 +++++++++++++++++++++ src/core/file_sys/archive_selfncch.h | 18 ++++++++++++++++++ src/core/file_sys/ivfc_archive.cpp | 6 ++++++ src/core/file_sys/ivfc_archive.h | 22 ++++++++++++++++++++++ src/core/file_sys/romfs_reader.h | 21 ++++++++++++++++++--- src/core/hle/kernel/config_mem.cpp | 3 +++ src/core/hle/kernel/config_mem.h | 3 +++ src/core/hle/kernel/shared_page.cpp | 2 ++ src/core/hle/kernel/shared_page.h | 3 +++ src/core/hle/service/gsp/gsp_lcd.h | 3 +++ src/core/hle/service/ir/ir_rst.cpp | 1 - src/core/hle/service/ir/ir_u.h | 3 +++ src/core/hle/service/ir/ir_user.cpp | 11 +++++++++-- src/core/hle/service/ir/ir_user.h | 4 +++- src/core/hle/service/mic_u.cpp | 1 - src/core/hle/service/nwm/nwm_uds.cpp | 4 +++- src/core/hle/service/nwm/nwm_uds.h | 1 + src/core/hle/service/sm/srv.cpp | 1 - src/core/hle/service/y2r_u.cpp | 1 - 23 files changed, 140 insertions(+), 24 deletions(-) diff --git a/TODO b/TODO index a768901851..83603d1c6f 100644 --- a/TODO +++ b/TODO @@ -3,14 +3,15 @@ ☐ Multiple slots etc. ☐ Custom texture cache ☐ Review constructor/initialization code -☐ Review core timing events +☐ Core timing events +☐ Serialize codeset with an apploader reference instead ✔ Review base class serialization everywhere @done(20-01-10 23:47) Make sure that all base/derived relationships are registered -☐ Serialize codeset with an apploader reference instead -☐ Additional stuff to serialize - ☐ Self-NCCH archive - ☐ File backends - ☐ Directory backends +✔ Additional stuff to serialize @done(20-01-11 16:32) + ✔ Self-NCCH archive @done(20-01-11 16:32) + ✔ File backends @done(20-01-11 16:32) + ✘ Directory backends @cancelled(20-01-11 16:32) + Not needed for now ✔ File/directory 'services' @done(20-01-10 23:46) ✔ CPU @done(19-08-13 15:41) ✔ Memory @done(19-08-13 15:41) @@ -37,10 +38,8 @@ ✔ SDMC @done(20-01-02 23:34) ✔ Normal @done(20-01-02 23:34) ✔ Write-only @done(20-01-02 23:34) - ✘ IVFC @cancelled(20-01-03 13:22) - Seems IVFCArchive is never used.. which is good because it has a file reference! - ✘ File refs @cancelled(20-01-03 13:22) - Not needed as nothing serializes file buffers + ✔ IVFC @done(20-01-11 16:33) + ✔ File refs @done(20-01-11 16:33) ✘ Replace delay generator with virtual fns @cancelled(20-01-03 13:16) While they have no state, the extra refactoring here is unneeded ✘ MMIO @cancelled(20-01-01 01:06) diff --git a/src/common/file_util.h b/src/common/file_util.h index c09aa88d61..71f943ed30 100644 --- a/src/common/file_util.h +++ b/src/common/file_util.h @@ -334,6 +334,7 @@ private: } BOOST_SERIALIZATION_SPLIT_MEMBER() + friend class boost::serialization::access; }; } // namespace FileUtil diff --git a/src/core/file_sys/archive_ncch.cpp b/src/core/file_sys/archive_ncch.cpp index 636bb81ed6..789547f0e3 100644 --- a/src/core/file_sys/archive_ncch.cpp +++ b/src/core/file_sys/archive_ncch.cpp @@ -30,6 +30,7 @@ // FileSys namespace SERIALIZE_EXPORT_IMPL(FileSys::NCCHArchive) +SERIALIZE_EXPORT_IMPL(FileSys::NCCHFile) SERIALIZE_EXPORT_IMPL(FileSys::ArchiveFactory_NCCH) namespace FileSys { diff --git a/src/core/file_sys/archive_ncch.h b/src/core/file_sys/archive_ncch.h index d17fbc3a2e..2d38f9a2e2 100644 --- a/src/core/file_sys/archive_ncch.h +++ b/src/core/file_sys/archive_ncch.h @@ -95,9 +95,16 @@ public: void Flush() const override {} private: - NCCHFile() = default; // NOTE: If the public ctor has behaviour, need to replace this with - // *_construct_data - std::vector file_buffer; // TODO: Replace with file ref for serialization + std::vector file_buffer; + + NCCHFile() = default; + + template + void serialize(Archive& ar, const unsigned int) { + ar& boost::serialization::base_object(*this); + ar& file_buffer; // TODO: See about a more efficient way to do this + } + friend class boost::serialization::access; }; /// File system interface to the NCCH archive @@ -125,4 +132,5 @@ private: } // namespace FileSys BOOST_CLASS_EXPORT_KEY(FileSys::NCCHArchive) +BOOST_CLASS_EXPORT_KEY(FileSys::NCCHFile) BOOST_CLASS_EXPORT_KEY(FileSys::ArchiveFactory_NCCH) diff --git a/src/core/file_sys/archive_selfncch.cpp b/src/core/file_sys/archive_selfncch.cpp index 214ad7c084..e866e9bc0a 100644 --- a/src/core/file_sys/archive_selfncch.cpp +++ b/src/core/file_sys/archive_selfncch.cpp @@ -77,6 +77,15 @@ public: private: std::shared_ptr> data; + + ExeFSSectionFile() = default; + + template + void serialize(Archive& ar, const unsigned int) { + ar& boost::serialization::base_object(*this); + ar& data; + } + friend class boost::serialization::access; }; // SelfNCCHArchive represents the running application itself. From this archive the application can @@ -234,6 +243,15 @@ private: } NCCHData ncch_data; + + SelfNCCHArchive() = default; + + template + void serialize(Archive& ar, const unsigned int) { + ar& boost::serialization::base_object(*this); + ar& ncch_data; + } + friend class boost::serialization::access; }; void ArchiveFactory_SelfNCCH::Register(Loader::AppLoader& app_loader) { @@ -300,3 +318,6 @@ ResultVal ArchiveFactory_SelfNCCH::GetFormatInfo(const Path&, } } // namespace FileSys + +SERIALIZE_EXPORT_IMPL(FileSys::ExeFSSectionFile) +SERIALIZE_EXPORT_IMPL(FileSys::SelfNCCHArchive) diff --git a/src/core/file_sys/archive_selfncch.h b/src/core/file_sys/archive_selfncch.h index 571789b9fe..d7b1cf301d 100644 --- a/src/core/file_sys/archive_selfncch.h +++ b/src/core/file_sys/archive_selfncch.h @@ -9,6 +9,8 @@ #include #include #include +#include +#include #include "common/common_types.h" #include "core/file_sys/archive_backend.h" #include "core/hle/result.h" @@ -25,6 +27,17 @@ struct NCCHData { std::shared_ptr> banner; std::shared_ptr romfs_file; std::shared_ptr update_romfs_file; + +private: + template + void serialize(Archive& ar, const unsigned int) { + ar& icon; + ar& logo; + ar& banner; + ar& romfs_file; + ar& update_romfs_file; + } + friend class boost::serialization::access; }; /// File system interface to the SelfNCCH archive @@ -55,6 +68,11 @@ private: friend class boost::serialization::access; }; +class ExeFSSectionFile; +class SelfNCCHArchive; + } // namespace FileSys BOOST_CLASS_EXPORT_KEY(FileSys::ArchiveFactory_SelfNCCH) +BOOST_CLASS_EXPORT_KEY(FileSys::ExeFSSectionFile) +BOOST_CLASS_EXPORT_KEY(FileSys::SelfNCCHArchive) diff --git a/src/core/file_sys/ivfc_archive.cpp b/src/core/file_sys/ivfc_archive.cpp index ba16f8cd86..3dbef7049e 100644 --- a/src/core/file_sys/ivfc_archive.cpp +++ b/src/core/file_sys/ivfc_archive.cpp @@ -5,6 +5,7 @@ #include #include #include +#include "common/archives.h" #include "common/common_types.h" #include "common/logging/log.h" #include "core/file_sys/ivfc_archive.h" @@ -12,6 +13,11 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// // FileSys namespace +SERIALIZE_EXPORT_IMPL(FileSys::IVFCFile) +SERIALIZE_EXPORT_IMPL(FileSys::IVFCDelayGenerator) +SERIALIZE_EXPORT_IMPL(FileSys::RomFSDelayGenerator) +SERIALIZE_EXPORT_IMPL(FileSys::ExeFSDelayGenerator) + namespace FileSys { IVFCArchive::IVFCArchive(std::shared_ptr file, diff --git a/src/core/file_sys/ivfc_archive.h b/src/core/file_sys/ivfc_archive.h index 8168e04f4a..3926f5229d 100644 --- a/src/core/file_sys/ivfc_archive.h +++ b/src/core/file_sys/ivfc_archive.h @@ -8,6 +8,8 @@ #include #include #include +#include +#include #include "common/common_types.h" #include "common/file_util.h" #include "core/file_sys/archive_backend.h" @@ -38,6 +40,8 @@ class IVFCDelayGenerator : public DelayGenerator { static constexpr u64 IPCDelayNanoseconds(9438006); return IPCDelayNanoseconds; } + + SERIALIZE_DELAY_GENERATOR }; class RomFSDelayGenerator : public DelayGenerator { @@ -60,6 +64,8 @@ public: static constexpr u64 IPCDelayNanoseconds(9438006); return IPCDelayNanoseconds; } + + SERIALIZE_DELAY_GENERATOR }; class ExeFSDelayGenerator : public DelayGenerator { @@ -82,6 +88,8 @@ public: static constexpr u64 IPCDelayNanoseconds(9438006); return IPCDelayNanoseconds; } + + SERIALIZE_DELAY_GENERATOR }; /** @@ -128,6 +136,15 @@ public: private: std::shared_ptr romfs_file; + + IVFCFile() = default; + + template + void serialize(Archive& ar, const unsigned int) { + ar& boost::serialization::base_object(*this); + ar& romfs_file; + } + friend class boost::serialization::access; }; class IVFCDirectory : public DirectoryBackend { @@ -162,3 +179,8 @@ private: }; } // namespace FileSys + +BOOST_CLASS_EXPORT_KEY(FileSys::IVFCFile) +BOOST_CLASS_EXPORT_KEY(FileSys::IVFCDelayGenerator) +BOOST_CLASS_EXPORT_KEY(FileSys::RomFSDelayGenerator) +BOOST_CLASS_EXPORT_KEY(FileSys::ExeFSDelayGenerator) diff --git a/src/core/file_sys/romfs_reader.h b/src/core/file_sys/romfs_reader.h index 72a02cde3d..ab1986fe64 100644 --- a/src/core/file_sys/romfs_reader.h +++ b/src/core/file_sys/romfs_reader.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include "common/common_types.h" #include "common/file_util.h" @@ -29,9 +30,23 @@ private: FileUtil::IOFile file; std::array key; std::array ctr; - std::size_t file_offset; - std::size_t crypto_offset; - std::size_t data_size; + u64 file_offset; + u64 crypto_offset; + u64 data_size; + + RomFSReader() = default; + + template + void serialize(Archive& ar, const unsigned int) { + ar& is_encrypted; + ar& file; + ar& key; + ar& ctr; + ar& file_offset; + ar& crypto_offset; + ar& data_size; + } + friend class boost::serialization::access; }; } // namespace FileSys diff --git a/src/core/hle/kernel/config_mem.cpp b/src/core/hle/kernel/config_mem.cpp index 58bef4110b..4b262b5013 100644 --- a/src/core/hle/kernel/config_mem.cpp +++ b/src/core/hle/kernel/config_mem.cpp @@ -3,10 +3,13 @@ // Refer to the license.txt file included. #include +#include "common/archives.h" #include "core/hle/kernel/config_mem.h" //////////////////////////////////////////////////////////////////////////////////////////////////// +SERIALIZE_EXPORT_IMPL(ConfigMem::Handler) + namespace ConfigMem { Handler::Handler() { diff --git a/src/core/hle/kernel/config_mem.h b/src/core/hle/kernel/config_mem.h index 46595976ea..74d934345f 100644 --- a/src/core/hle/kernel/config_mem.h +++ b/src/core/hle/kernel/config_mem.h @@ -10,6 +10,7 @@ // putting this as a subset of HLE for now. #include +#include #include "common/common_funcs.h" #include "common/common_types.h" #include "common/memory_ref.h" @@ -76,3 +77,5 @@ private: }; } // namespace ConfigMem + +BOOST_CLASS_EXPORT_KEY(ConfigMem::Handler) diff --git a/src/core/hle/kernel/shared_page.cpp b/src/core/hle/kernel/shared_page.cpp index f7b02993ff..5456a48e05 100644 --- a/src/core/hle/kernel/shared_page.cpp +++ b/src/core/hle/kernel/shared_page.cpp @@ -14,6 +14,8 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// +SERIALIZE_EXPORT_IMPL(SharedPage::Handler) + namespace boost::serialization { template diff --git a/src/core/hle/kernel/shared_page.h b/src/core/hle/kernel/shared_page.h index c94cc079e4..b74470b4a3 100644 --- a/src/core/hle/kernel/shared_page.h +++ b/src/core/hle/kernel/shared_page.h @@ -14,6 +14,7 @@ #include #include #include +#include #include "common/bit_field.h" #include "common/common_funcs.h" #include "common/common_types.h" @@ -131,3 +132,5 @@ template void load_construct_data(Archive& ar, SharedPage::Handler* t, const unsigned int); } // namespace boost::serialization + +BOOST_CLASS_EXPORT_KEY(SharedPage::Handler) diff --git a/src/core/hle/service/gsp/gsp_lcd.h b/src/core/hle/service/gsp/gsp_lcd.h index 781d9dba8d..31d17f5400 100644 --- a/src/core/hle/service/gsp/gsp_lcd.h +++ b/src/core/hle/service/gsp/gsp_lcd.h @@ -12,6 +12,9 @@ class GSP_LCD final : public ServiceFramework { public: GSP_LCD(); ~GSP_LCD() = default; + +private: + SERVICE_SERIALIZATION_SIMPLE }; } // namespace Service::GSP diff --git a/src/core/hle/service/ir/ir_rst.cpp b/src/core/hle/service/ir/ir_rst.cpp index dc9612e624..751460a044 100644 --- a/src/core/hle/service/ir/ir_rst.cpp +++ b/src/core/hle/service/ir/ir_rst.cpp @@ -29,7 +29,6 @@ void IR_RST::serialize(Archive& ar, const unsigned int) { // update_callback_id and input devices are set separately ReloadInputDevices(); } -SERIALIZE_IMPL(IR_RST) struct PadDataEntry { PadState current_state; diff --git a/src/core/hle/service/ir/ir_u.h b/src/core/hle/service/ir/ir_u.h index eaa54c6578..ecaf1be285 100644 --- a/src/core/hle/service/ir/ir_u.h +++ b/src/core/hle/service/ir/ir_u.h @@ -12,6 +12,9 @@ namespace Service::IR { class IR_U final : public ServiceFramework { public: IR_U(); + +private: + SERVICE_SERIALIZATION_SIMPLE }; } // namespace Service::IR diff --git a/src/core/hle/service/ir/ir_user.cpp b/src/core/hle/service/ir/ir_user.cpp index 64a298103e..4bf6e74996 100644 --- a/src/core/hle/service/ir/ir_user.cpp +++ b/src/core/hle/service/ir/ir_user.cpp @@ -4,6 +4,8 @@ #include #include +#include +#include #include "common/string_util.h" #include "common/swap.h" #include "core/core.h" @@ -13,6 +15,9 @@ #include "core/hle/service/ir/extra_hid.h" #include "core/hle/service/ir/ir_user.h" +SERIALIZE_EXPORT_IMPL(Service::IR::IR_USER) +SERVICE_CONSTRUCT_IMPL(Service::IR::IR_USER) + namespace Service::IR { template @@ -23,10 +28,9 @@ void IR_USER::serialize(Archive& ar, const unsigned int) { ar& receive_event; ar& shared_memory; ar& connected_device; - ar&* receive_buffer.get(); + ar& receive_buffer; ar&* extra_hid.get(); } -SERIALIZE_IMPL(IR_USER) // This is a header that will present in the ir:USER shared memory if it is initialized with // InitializeIrNopShared service function. Otherwise the shared memory doesn't have this header if @@ -204,6 +208,8 @@ private: u32 max_data_size; private: + BufferManager() = default; + template void serialize(Archive& ar, const unsigned int) { ar& info; @@ -449,6 +455,7 @@ IR_USER::IR_USER(Core::System& system) : ServiceFramework("ir:USER", 1) { using namespace Kernel; + connected_device = false; conn_status_event = system.Kernel().CreateEvent(ResetType::OneShot, "IR:ConnectionStatusEvent"); send_event = system.Kernel().CreateEvent(ResetType::OneShot, "IR:SendEvent"); receive_event = system.Kernel().CreateEvent(ResetType::OneShot, "IR:ReceiveEvent"); diff --git a/src/core/hle/service/ir/ir_user.h b/src/core/hle/service/ir/ir_user.h index 75bbeb7791..afb9be4f7b 100644 --- a/src/core/hle/service/ir/ir_user.h +++ b/src/core/hle/service/ir/ir_user.h @@ -7,7 +7,6 @@ #include #include #include -#include #include "core/hle/service/service.h" namespace Kernel { @@ -177,3 +176,6 @@ private: }; } // namespace Service::IR + +BOOST_CLASS_EXPORT_KEY(Service::IR::IR_USER) +SERVICE_CONSTRUCT(Service::IR::IR_USER) diff --git a/src/core/hle/service/mic_u.cpp b/src/core/hle/service/mic_u.cpp index 478bf110fb..bd324ada25 100644 --- a/src/core/hle/service/mic_u.cpp +++ b/src/core/hle/service/mic_u.cpp @@ -28,7 +28,6 @@ void MIC_U::serialize(Archive& ar, const unsigned int) { ar& boost::serialization::base_object(*this); ar&* impl.get(); } -SERIALIZE_IMPL(MIC_U) /// Microphone audio encodings. enum class Encoding : u8 { diff --git a/src/core/hle/service/nwm/nwm_uds.cpp b/src/core/hle/service/nwm/nwm_uds.cpp index 01bdd821ed..b2793285f2 100644 --- a/src/core/hle/service/nwm/nwm_uds.cpp +++ b/src/core/hle/service/nwm/nwm_uds.cpp @@ -24,6 +24,9 @@ #include "core/hle/service/nwm/uds_data.h" #include "core/memory.h" +SERIALIZE_EXPORT_IMPL(Service::NWM::NWM_UDS) +SERVICE_CONSTRUCT_IMPL(Service::NWM::NWM_UDS) + namespace Service::NWM { template @@ -34,7 +37,6 @@ void NWM_UDS::serialize(Archive& ar, const unsigned int) { ar& received_beacons; // wifi_packet_received set in constructor } -SERIALIZE_IMPL(NWM_UDS) namespace ErrCodes { enum { diff --git a/src/core/hle/service/nwm/nwm_uds.h b/src/core/hle/service/nwm/nwm_uds.h index b2ab1d76a6..7ae471a538 100644 --- a/src/core/hle/service/nwm/nwm_uds.h +++ b/src/core/hle/service/nwm/nwm_uds.h @@ -557,6 +557,7 @@ private: template void serialize(Archive& ar, const unsigned int); + friend class boost::serialization::access; }; } // namespace Service::NWM diff --git a/src/core/hle/service/sm/srv.cpp b/src/core/hle/service/sm/srv.cpp index 91b26b497c..f9c62e9ad1 100644 --- a/src/core/hle/service/sm/srv.cpp +++ b/src/core/hle/service/sm/srv.cpp @@ -35,7 +35,6 @@ void SRV::serialize(Archive& ar, const unsigned int) { ar& notification_semaphore; ar& get_service_handle_delayed_map; } -SERIALIZE_IMPL(SRV) constexpr int MAX_PENDING_NOTIFICATIONS = 16; diff --git a/src/core/hle/service/y2r_u.cpp b/src/core/hle/service/y2r_u.cpp index 45e7da13d1..89da8058c4 100644 --- a/src/core/hle/service/y2r_u.cpp +++ b/src/core/hle/service/y2r_u.cpp @@ -28,7 +28,6 @@ void Y2R_U::serialize(Archive& ar, const unsigned int) { ar& transfer_end_interrupt_enabled; ar& spacial_dithering_enabled; } -SERIALIZE_IMPL(Y2R_U) static const CoefficientSet standard_coefficients[4] = { {{0x100, 0x166, 0xB6, 0x58, 0x1C5, -0x166F, 0x10EE, -0x1C5B}}, // ITU_Rec601