mirror of
https://github.com/momo5502/emulator.git
synced 2026-01-23 13:41:02 +00:00
Serialization fixes
This commit is contained in:
@@ -55,6 +55,11 @@ class emulator : public cpu_interface, public memory_manager, public hook_interf
|
||||
|
||||
void perform_deserialization(utils::buffer_deserializer& buffer, const bool is_snapshot)
|
||||
{
|
||||
if (!is_snapshot)
|
||||
{
|
||||
this->unmap_all_memory();
|
||||
}
|
||||
|
||||
this->deserialize_state(buffer, is_snapshot);
|
||||
this->deserialize_memory_state(buffer, is_snapshot);
|
||||
}
|
||||
|
||||
@@ -94,6 +94,7 @@ namespace utils
|
||||
|
||||
void memory_manager::serialize_memory_state(utils::buffer_serializer& buffer, const bool is_snapshot) const
|
||||
{
|
||||
buffer.write_atomic(this->memory_layout_state_version_);
|
||||
buffer.write_map(this->reserved_regions_);
|
||||
|
||||
if (is_snapshot)
|
||||
@@ -125,15 +126,10 @@ void memory_manager::deserialize_memory_state(utils::buffer_deserializer& buffer
|
||||
{
|
||||
if (!is_snapshot)
|
||||
{
|
||||
for (const auto& reserved_region : this->reserved_regions_)
|
||||
{
|
||||
for (const auto& region : reserved_region.second.committed_regions)
|
||||
{
|
||||
this->unmap_memory(region.first, region.second.length);
|
||||
}
|
||||
}
|
||||
assert(this->reserved_regions_.empty());
|
||||
}
|
||||
|
||||
buffer.read_atomic(this->memory_layout_state_version_);
|
||||
buffer.read_map(this->reserved_regions_);
|
||||
|
||||
if (is_snapshot)
|
||||
@@ -434,6 +430,19 @@ bool memory_manager::release_memory(const uint64_t address, size_t size)
|
||||
return true;
|
||||
}
|
||||
|
||||
void memory_manager::unmap_all_memory()
|
||||
{
|
||||
for (const auto& reserved_region : this->reserved_regions_)
|
||||
{
|
||||
for (const auto& region : reserved_region.second.committed_regions)
|
||||
{
|
||||
this->unmap_memory(region.first, region.second.length);
|
||||
}
|
||||
}
|
||||
|
||||
this->reserved_regions_.clear();
|
||||
}
|
||||
|
||||
uint64_t memory_manager::find_free_allocation_base(const size_t size, const uint64_t start) const
|
||||
{
|
||||
uint64_t start_address = std::max(MIN_ALLOCATION_ADDRESS, start ? start : 0x100000000ULL);
|
||||
|
||||
@@ -101,6 +101,8 @@ class memory_manager
|
||||
|
||||
bool release_memory(uint64_t address, size_t size);
|
||||
|
||||
void unmap_all_memory();
|
||||
|
||||
uint64_t allocate_memory(const size_t size, const memory_permission permissions, const bool reserve_only = false)
|
||||
{
|
||||
const auto allocation_base = this->find_free_allocation_base(size);
|
||||
|
||||
@@ -157,6 +157,12 @@ namespace utils
|
||||
return object;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void read_atomic(std::atomic<T>& val)
|
||||
{
|
||||
val = this->read<T>();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void read_optional(std::optional<T>& val)
|
||||
{
|
||||
@@ -390,6 +396,12 @@ namespace utils
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void write_atomic(const std::atomic<T>& val)
|
||||
{
|
||||
this->write(val.load());
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void write_optional(const std::optional<T>& val)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user