Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
mc: const seems wrong here.
[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_SOSP_REGION_HPP
7 #define SIMGRID_MC_SOSP_REGION_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 { Heap = 1, Data = 2 };
19
20 /** A copy/snapshot of a given memory region, where identical pages are stored only once */
21 class Region {
22 public:
23   static const RegionType HeapRegion    = RegionType::Heap;
24   static const RegionType DataRegion    = RegionType::Data;
25
26 private:
27   RegionType region_type_;
28   simgrid::mc::ObjectInformation* object_info_ = nullptr;
29
30   /** @brief  Virtual address of the region in the simulated process */
31   void* start_addr_ = nullptr;
32
33   /** @brief Size of the data region in bytes */
34   std::size_t size_ = 0;
35
36   ChunkedData chunks_;
37
38 public:
39   Region(RegionType type, void* start_addr, size_t size);
40   ~Region()             = default;
41   Region(Region const&) = delete;
42   Region& operator=(Region const&) = delete;
43   Region(Region&& that)            = delete;
44   Region& operator=(Region&& that) = delete;
45
46   // Data
47
48   ChunkedData const& get_chunks() const { return chunks_; }
49
50   simgrid::mc::ObjectInformation* object_info() const { return object_info_; }
51   void object_info(simgrid::mc::ObjectInformation* info) { object_info_ = info; }
52
53   // Other getters
54
55   RemotePtr<void> start() const { return remote(start_addr_); }
56   RemotePtr<void> end() const { return remote((char*)start_addr_ + size_); }
57   std::size_t size() const { return size_; }
58   RegionType region_type() const { return region_type_; }
59
60   bool contain(RemotePtr<void> p) const { return p >= start() && p < end(); }
61
62   /** @brief Restore a region from a snapshot */
63   void restore();
64
65   /** @brief Read memory that was snapshoted in this region
66    *
67    *  @param target  Buffer to store contiguously the value if it spans over several pages
68    *  @param addr    Process (non-snapshot) address of the data
69    *  @param size    Size of the data to read in bytes
70    *  @return Pointer where the data is located (either target buffer or original location)
71    */
72   void* read(void* target, const void* addr, std::size_t size);
73 };
74
75 } // namespace mc
76 } // namespace simgrid
77
78 int MC_snapshot_region_memcmp(const void* addr1, simgrid::mc::Region* region1, const void* addr2,
79                               simgrid::mc::Region* region2, std::size_t size);
80
81 static XBT_ALWAYS_INLINE void* MC_region_read_pointer(simgrid::mc::Region* region, const void* addr)
82 {
83   void* res;
84   return *(void**)region->read(&res, addr, sizeof(void*));
85 }
86
87 #endif