1 /* Copyright (c) 2007-2019. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 #ifndef SIMGRID_MC_REGION_SNAPSHOT_HPP
7 #define SIMGRID_MC_REGION_SNAPSHOT_HPP
9 #include "src/mc/remote/RemotePtr.hpp"
10 #include "src/mc/sosp/ChunkedData.hpp"
18 enum class RegionType { Unknown = 0, Heap = 1, Data = 2 };
20 /** A copy/snapshot of a given memory region, where identical pages are stored only once */
21 class RegionSnapshot {
23 static const RegionType UnknownRegion = RegionType::Unknown;
24 static const RegionType HeapRegion = RegionType::Heap;
25 static const RegionType DataRegion = RegionType::Data;
28 RegionType region_type_ = UnknownRegion;
29 simgrid::mc::ObjectInformation* object_info_ = nullptr;
31 /** @brief Virtual address of the region in the simulated process */
32 void* start_addr_ = nullptr;
34 /** @brief Size of the data region in bytes */
35 std::size_t size_ = 0;
40 RegionSnapshot(RegionType type, void* start_addr, size_t size);
41 ~RegionSnapshot() = default;
42 RegionSnapshot(RegionSnapshot const&) = delete;
43 RegionSnapshot& operator=(RegionSnapshot const&) = delete;
44 RegionSnapshot(RegionSnapshot&& that)
45 : region_type_(that.region_type_)
46 , object_info_(that.object_info_)
47 , start_addr_(that.start_addr_)
49 , chunks_(std::move(that.chunks_))
53 RegionSnapshot& operator=(RegionSnapshot&& that)
55 region_type_ = that.region_type_;
56 object_info_ = that.object_info_;
57 start_addr_ = that.start_addr_;
59 chunks_ = std::move(that.chunks_);
68 region_type_ = UnknownRegion;
70 object_info_ = nullptr;
71 start_addr_ = nullptr;
75 ChunkedData const& get_chunks() const { return chunks_; }
77 simgrid::mc::ObjectInformation* object_info() const { return object_info_; }
78 void object_info(simgrid::mc::ObjectInformation* info) { object_info_ = info; }
82 RemotePtr<void> start() const { return remote(start_addr_); }
83 RemotePtr<void> end() const { return remote((char*)start_addr_ + size_); }
84 std::size_t size() const { return size_; }
85 RegionType region_type() const { return region_type_; }
87 bool contain(RemotePtr<void> p) const { return p >= start() && p < end(); }
89 /** @brief Restore a region from a snapshot */
94 } // namespace simgrid