From 8c81500deec2e8368c112fbce98770c7b518f40e Mon Sep 17 00:00:00 2001 From: Hamish Milne Date: Sun, 22 Dec 2019 18:35:03 +0000 Subject: [PATCH] Serialize kernel/hle/memory --- TODO | 4 +-- .../serialization/boost_discrete_interval.hpp | 33 +++++++++++++++++++ src/core/hle/kernel/kernel.cpp | 2 +- src/core/hle/kernel/memory.h | 5 ++- 4 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 src/common/serialization/boost_discrete_interval.hpp diff --git a/TODO b/TODO index 95bdaa9266..cad91b958d 100644 --- a/TODO +++ b/TODO @@ -11,7 +11,7 @@ ✔ HW @done(19-08-13 15:41) ✔ GPU regs @done(19-08-13 15:41) ✔ LCD regs @done(19-08-13 15:41) -☐ Video core @started(19-08-13 16:43) +✔ Video core @started(19-08-13 16:43) @done(19-12-22 16:06) ✔ Geometry pipeline @done(19-12-22 15:52) Required more use of g_state ✔ PICA state @done(19-08-13 15:41) @@ -28,7 +28,7 @@ ✔ Handle table @done(19-08-13 16:42) ☐ HLE IPC ☐ IPC - ☐ Memory @started(19-08-13 16:43) + ✔ Memory @started(19-08-13 16:43) @done(19-12-22 18:34) ☐ Mutex @started(19-08-13 16:43) ✔ Object @done(19-08-13 15:41) ☐ Process @started(19-08-13 16:43) diff --git a/src/common/serialization/boost_discrete_interval.hpp b/src/common/serialization/boost_discrete_interval.hpp new file mode 100644 index 0000000000..dc920e439f --- /dev/null +++ b/src/common/serialization/boost_discrete_interval.hpp @@ -0,0 +1,33 @@ +#pragma once + +#include "common/common_types.h" +#include + +namespace boost::serialization { + +template +void save(Archive& ar, const boost::icl::discrete_interval& obj, const unsigned int file_version) +{ + ar << obj.lower(); + ar << obj.upper(); + ar << obj.bounds()._bits; +} + +template +void load(Archive& ar, boost::icl::discrete_interval& obj, const unsigned int file_version) +{ + DomainT upper, lower; + boost::icl::bound_type bounds; + ar >> upper; + ar >> lower; + ar >> bounds; + obj = boost::icl::discrete_interval(upper, lower, boost::icl::interval_bounds(bounds)); +} + +template +void serialize(Archive& ar, boost::icl::discrete_interval& obj, const unsigned int file_version) +{ + boost::serialization::split_free(ar, obj, file_version); +} + +} diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp index 2dd0a34bf8..6248311b99 100644 --- a/src/core/hle/kernel/kernel.cpp +++ b/src/core/hle/kernel/kernel.cpp @@ -108,6 +108,7 @@ void KernelSystem::AddNamedPort(std::string name, std::shared_ptr po template void KernelSystem::serialize(Archive& ar, const unsigned int file_version) { + ar & memory_regions; ar & named_ports; ar & *current_cpu.get(); // NB: subsystem references and prepare_reschedule_callback are constant @@ -120,7 +121,6 @@ void KernelSystem::serialize(Archive& ar, const unsigned int file_version) ar & *thread_manager.get(); ar & *config_mem_handler.get(); // Shared page data is read-only at the moment, so doesn't need serializing - //ar & *shared_page_handler.get(); } SERIALIZE_IMPL(KernelSystem) diff --git a/src/core/hle/kernel/memory.h b/src/core/hle/kernel/memory.h index 9e9fe5eb43..ed4ea12965 100644 --- a/src/core/hle/kernel/memory.h +++ b/src/core/hle/kernel/memory.h @@ -6,6 +6,8 @@ #include #include +#include +#include "common/serialization/boost_discrete_interval.hpp" #include "common/common_types.h" namespace Kernel { @@ -69,7 +71,8 @@ private: ar & base; ar & size; ar & used; - // TODO: boost icl / free_blocks + // This works because interval_set has exactly one member of type ImplSetT + ar & *(reinterpret_cast(&free_blocks)); } };