Added boost serialization

This commit is contained in:
Hamish Milne 2019-08-06 15:59:31 +01:00 committed by zhupengfei
parent f106e76132
commit 6940c99ed6
8 changed files with 89 additions and 3 deletions

2
.gitmodules vendored
View file

@ -1,6 +1,6 @@
[submodule "boost"] [submodule "boost"]
path = externals/boost path = externals/boost
url = https://github.com/citra-emu/ext-boost.git url = https://github.com/hamish-milne/ext-boost.git
[submodule "nihstro"] [submodule "nihstro"]
path = externals/nihstro path = externals/nihstro
url = https://github.com/neobrain/nihstro.git url = https://github.com/neobrain/nihstro.git

View file

@ -124,6 +124,8 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
# System imported libraries # System imported libraries
# ====================== # ======================
add_library(boost_libs INTERFACE)
find_package(Boost 1.66.0 QUIET) find_package(Boost 1.66.0 QUIET)
if (NOT Boost_FOUND) if (NOT Boost_FOUND)
message(STATUS "Boost 1.66.0 or newer not found, falling back to externals") 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_ROOT "${PROJECT_SOURCE_DIR}/externals/boost")
set(Boost_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/externals/boost") set(Boost_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/externals/boost")
set(Boost_NO_SYSTEM_PATHS OFF) set(Boost_NO_SYSTEM_PATHS OFF)
add_definitions( -DBOOST_ALL_NO_LIB )
find_package(Boost QUIET REQUIRED) 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() endif()
# Prefer the -pthread flag on Linux. # Prefer the -pthread flag on Linux.

2
externals/boost vendored

@ -1 +1 @@
Subproject commit 502437b2ae3f1da821aa7d5d5174ec356fa89269 Subproject commit 1acb9699ac8e91654331504cf3524b26463eeee4

11
src/common/archives.h Normal file
View file

@ -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>( \
boost::archive::binary_iarchive & ar, \
const unsigned int file_version \
); \
template void A::serialize<boost::archive::binary_oarchive>( \
boost::archive::binary_oarchive & ar, \
const unsigned int file_version \
);

View file

@ -465,7 +465,7 @@ endif()
create_target_directory_groups(core) create_target_directory_groups(core)
target_link_libraries(core PUBLIC common PRIVATE audio_core network video_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) if (ENABLE_WEB_SERVICE)
target_compile_definitions(core PRIVATE -DENABLE_WEB_SERVICE) target_compile_definitions(core PRIVATE -DENABLE_WEB_SERVICE)
target_link_libraries(core PRIVATE web_service) target_link_libraries(core PRIVATE web_service)

View file

@ -8,6 +8,7 @@
#include <memory> #include <memory>
#include <utility> #include <utility>
#include <vector> #include <vector>
#include "boost/serialization/split_member.hpp"
#include "common/common_types.h" #include "common/common_types.h"
#include "core/hle/result.h" #include "core/hle/result.h"
#include "core/memory.h" #include "core/memory.h"
@ -193,6 +194,31 @@ public:
Memory::PageTable page_table; Memory::PageTable page_table;
private: private:
friend class boost::serialization::access;
template<class Archive>
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<class Archive>
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; using VMAIter = decltype(vma_map)::iterator;
/// Converts a VMAHandle to a mutable VMAIter. /// Converts a VMAHandle to a mutable VMAIter.

View file

@ -4,7 +4,9 @@
#include <array> #include <array>
#include <cstring> #include <cstring>
#include "boost/serialization/split_member.hpp"
#include "audio_core/dsp_interface.h" #include "audio_core/dsp_interface.h"
#include "common/archives.h"
#include "common/assert.h" #include "common/assert.h"
#include "common/common_types.h" #include "common/common_types.h"
#include "common/logging/log.h" #include "common/logging/log.h"
@ -67,8 +69,37 @@ public:
std::vector<PageTable*> page_table_list; std::vector<PageTable*> page_table_list;
AudioCore::DspInterface* dsp = nullptr; AudioCore::DspInterface* dsp = nullptr;
private:
friend class boost::serialization::access;
template<class Archive>
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<class Archive>
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<Impl>()) {} MemorySystem::MemorySystem() : impl(std::make_unique<Impl>()) {}
MemorySystem::~MemorySystem() = default; MemorySystem::~MemorySystem() = default;

View file

@ -9,6 +9,7 @@
#include <memory> #include <memory>
#include <string> #include <string>
#include <vector> #include <vector>
#include "boost/serialization/split_member.hpp"
#include "common/common_types.h" #include "common/common_types.h"
#include "core/mmio.h" #include "core/mmio.h"
@ -52,6 +53,14 @@ struct SpecialRegion {
VAddr base; VAddr base;
u32 size; u32 size;
MMIORegionPointer handler; MMIORegionPointer handler;
template<class Archive>
void serialize(Archive & ar, const unsigned int file_version)
{
ar & base;
ar & size;
ar & handler;
}
}; };
/** /**