From 6940c99ed65c64f462efc082d31f238eac13ae25 Mon Sep 17 00:00:00 2001 From: Hamish Milne Date: Tue, 6 Aug 2019 15:59:31 +0100 Subject: [PATCH] Added boost serialization --- .gitmodules | 2 +- CMakeLists.txt | 9 +++++++++ externals/boost | 2 +- src/common/archives.h | 11 +++++++++++ src/core/CMakeLists.txt | 2 +- src/core/hle/kernel/vm_manager.h | 26 ++++++++++++++++++++++++++ src/core/memory.cpp | 31 +++++++++++++++++++++++++++++++ src/core/memory.h | 9 +++++++++ 8 files changed, 89 insertions(+), 3 deletions(-) create mode 100644 src/common/archives.h diff --git a/.gitmodules b/.gitmodules index b247ccdbe..b0bfcaee8 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,6 @@ [submodule "boost"] path = externals/boost - url = https://github.com/citra-emu/ext-boost.git + url = https://github.com/hamish-milne/ext-boost.git [submodule "nihstro"] path = externals/nihstro url = https://github.com/neobrain/nihstro.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 41d55f375..df8081f05 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -124,6 +124,8 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin) # System imported libraries # ====================== +add_library(boost_libs INTERFACE) + find_package(Boost 1.66.0 QUIET) if (NOT Boost_FOUND) message(STATUS "Boost 1.66.0 or newer not found, falling back to externals") @@ -131,7 +133,14 @@ if (NOT Boost_FOUND) set(BOOST_ROOT "${PROJECT_SOURCE_DIR}/externals/boost") set(Boost_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/externals/boost") set(Boost_NO_SYSTEM_PATHS OFF) + add_definitions( -DBOOST_ALL_NO_LIB ) find_package(Boost QUIET REQUIRED) + + # Boost external libraries + file(GLOB boost_serialization_SRC "externals/boost/libs/serialization/src/*.cpp") + add_library(boost_serialization STATIC ${boost_serialization_SRC}) + target_link_libraries(boost_serialization PUBLIC Boost::boost) + target_link_libraries(boost_libs INTERFACE boost_serialization) endif() # Prefer the -pthread flag on Linux. diff --git a/externals/boost b/externals/boost index 502437b2a..1acb9699a 160000 --- a/externals/boost +++ b/externals/boost @@ -1 +1 @@ -Subproject commit 502437b2ae3f1da821aa7d5d5174ec356fa89269 +Subproject commit 1acb9699ac8e91654331504cf3524b26463eeee4 diff --git a/src/common/archives.h b/src/common/archives.h new file mode 100644 index 000000000..76aa71054 --- /dev/null +++ b/src/common/archives.h @@ -0,0 +1,11 @@ +#include "boost/archive/binary_iarchive.hpp" +#include "boost/archive/binary_oarchive.hpp" + +#define SERIALIZE_IMPL(A) template void A::serialize( \ + boost::archive::binary_iarchive & ar, \ + const unsigned int file_version \ +); \ +template void A::serialize( \ + boost::archive::binary_oarchive & ar, \ + const unsigned int file_version \ +); diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 064e44f94..ed2642431 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -465,7 +465,7 @@ endif() create_target_directory_groups(core) target_link_libraries(core PUBLIC common PRIVATE audio_core network video_core) -target_link_libraries(core PUBLIC Boost::boost PRIVATE cryptopp fmt open_source_archives) +target_link_libraries(core PUBLIC Boost::boost PRIVATE cryptopp fmt open_source_archives boost_libs) if (ENABLE_WEB_SERVICE) target_compile_definitions(core PRIVATE -DENABLE_WEB_SERVICE) target_link_libraries(core PRIVATE web_service) diff --git a/src/core/hle/kernel/vm_manager.h b/src/core/hle/kernel/vm_manager.h index fbd9bf09b..0d3ae1e44 100644 --- a/src/core/hle/kernel/vm_manager.h +++ b/src/core/hle/kernel/vm_manager.h @@ -8,6 +8,7 @@ #include #include #include +#include "boost/serialization/split_member.hpp" #include "common/common_types.h" #include "core/hle/result.h" #include "core/memory.h" @@ -193,6 +194,31 @@ public: Memory::PageTable page_table; private: + friend class boost::serialization::access; + template + void save(Archive & ar, const unsigned int file_version) + { + for (int i = 0; i < page_table.pointers.size(); i++) { + ar << memory.GetFCRAMOffset(page_table.pointers[i]); + } + ar & page_table.special_regions; + ar & page_table.attributes; + } + + template + void load(Archive & ar, const unsigned int file_version) + { + for (int i = 0; i < page_table.pointers.size(); i++) { + u32 offset{}; + ar >> offset; + page_table.pointers[i] = memory.GetFCRAMPointer(offset); + } + ar & page_table.special_regions; + ar & page_table.attributes; + } + + BOOST_SERIALIZATION_SPLIT_MEMBER() + using VMAIter = decltype(vma_map)::iterator; /// Converts a VMAHandle to a mutable VMAIter. diff --git a/src/core/memory.cpp b/src/core/memory.cpp index 096f4c697..e5fb83f5a 100644 --- a/src/core/memory.cpp +++ b/src/core/memory.cpp @@ -4,7 +4,9 @@ #include #include +#include "boost/serialization/split_member.hpp" #include "audio_core/dsp_interface.h" +#include "common/archives.h" #include "common/assert.h" #include "common/common_types.h" #include "common/logging/log.h" @@ -67,8 +69,37 @@ public: std::vector page_table_list; AudioCore::DspInterface* dsp = nullptr; + +private: + friend class boost::serialization::access; + template + void save(Archive & ar, const unsigned int file_version) const + { + // TODO: Skip n3ds ram when not used? + ar.save_binary(fcram.get(), Memory::FCRAM_N3DS_SIZE); + ar.save_binary(vram.get(), Memory::VRAM_SIZE); + ar.save_binary(n3ds_extra_ram.get(), Memory::N3DS_EXTRA_RAM_SIZE); + // ar & cache_marker; + // ar & page_table_list; + // ar & current_page_table; + } + + template + void load(Archive & ar, const unsigned int file_version) + { + ar.load_binary(fcram.get(), Memory::FCRAM_N3DS_SIZE); + ar.load_binary(vram.get(), Memory::VRAM_SIZE); + ar.load_binary(n3ds_extra_ram.get(), Memory::N3DS_EXTRA_RAM_SIZE); + // ar & cache_marker; + // ar & page_table_list; + // ar & current_page_table; + } + + BOOST_SERIALIZATION_SPLIT_MEMBER() }; +SERIALIZE_IMPL(MemorySystem::Impl) + MemorySystem::MemorySystem() : impl(std::make_unique()) {} MemorySystem::~MemorySystem() = default; diff --git a/src/core/memory.h b/src/core/memory.h index 6caca5a2b..e5582d16d 100644 --- a/src/core/memory.h +++ b/src/core/memory.h @@ -9,6 +9,7 @@ #include #include #include +#include "boost/serialization/split_member.hpp" #include "common/common_types.h" #include "core/mmio.h" @@ -52,6 +53,14 @@ struct SpecialRegion { VAddr base; u32 size; MMIORegionPointer handler; + + template + void serialize(Archive & ar, const unsigned int file_version) + { + ar & base; + ar & size; + ar & handler; + } }; /**