Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
MC: rename some files
[simgrid.git] / src / mc / sosp / Region.hpp
1 /* Copyright (c) 2007-2019. The SimGrid Team. All rights reserved.          */
2
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. */
5
6 #ifndef SIMGRID_MC_REGION_SNAPSHOT_HPP
7 #define SIMGRID_MC_REGION_SNAPSHOT_HPP
8
9 #include "src/mc/remote/RemotePtr.hpp"
10 #include "src/mc/sosp/ChunkedData.hpp"
11
12 #include <memory>
13 #include <vector>
14
15 namespace simgrid {
16 namespace mc {
17
18 enum class RegionType { Unknown = 0, Heap = 1, Data = 2 };
19
20 /** A copy/snapshot of a given memory region, where identical pages are stored only once */
21 class RegionSnapshot {
22 public:
23   static const RegionType UnknownRegion = RegionType::Unknown;
24   static const RegionType HeapRegion    = RegionType::Heap;
25   static const RegionType DataRegion    = RegionType::Data;
26
27 protected:
28   RegionType region_type_                      = UnknownRegion;
29   simgrid::mc::ObjectInformation* object_info_ = nullptr;
30
31   /** @brief  Virtual address of the region in the simulated process */
32   void* start_addr_ = nullptr;
33
34   /** @brief Size of the data region in bytes */
35   std::size_t size_ = 0;
36
37   ChunkedData chunks_;
38
39 public:
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_)
48       , size_(that.size_)
49       , chunks_(std::move(that.chunks_))
50   {
51     that.clear();
52   }
53   RegionSnapshot& operator=(RegionSnapshot&& that)
54   {
55     region_type_ = that.region_type_;
56     object_info_ = that.object_info_;
57     start_addr_  = that.start_addr_;
58     size_        = that.size_;
59     chunks_      = std::move(that.chunks_);
60     that.clear();
61     return *this;
62   }
63
64   // Data
65
66   void clear()
67   {
68     region_type_ = UnknownRegion;
69     chunks_.clear();
70     object_info_ = nullptr;
71     start_addr_  = nullptr;
72     size_        = 0;
73   }
74
75   ChunkedData const& get_chunks() const { return chunks_; }
76
77   simgrid::mc::ObjectInformation* object_info() const { return object_info_; }
78   void object_info(simgrid::mc::ObjectInformation* info) { object_info_ = info; }
79
80   // Other getters
81
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_; }
86
87   bool contain(RemotePtr<void> p) const { return p >= start() && p < end(); }
88
89   /** @brief Restore a region from a snapshot */
90   void restore();
91 };
92
93 } // namespace mc
94 } // namespace simgrid
95
96 #endif