}
// TODO, have a robust way to find it in O(1)
-static inline RegionSnapshot* MC_get_heap_region(Snapshot* snapshot)
+static inline Region* MC_get_heap_region(Snapshot* snapshot)
{
for (auto const& region : snapshot->snapshot_regions_)
if (region->region_type() == simgrid::mc::RegionType::Heap)
malloc_info heapinfo_temp2;
malloc_info heapinfo_temp2b;
- simgrid::mc::RegionSnapshot* heap_region1 = MC_get_heap_region(snapshot1);
- simgrid::mc::RegionSnapshot* heap_region2 = MC_get_heap_region(snapshot2);
+ simgrid::mc::Region* heap_region1 = MC_get_heap_region(snapshot1);
+ simgrid::mc::Region* heap_region2 = MC_get_heap_region(snapshot2);
// This is the address of std_heap->heapinfo in the application process:
void* heapinfo_address = &((xbt_mheap_t) process->heap_address)->heapinfo;
int check_ignore)
{
simgrid::mc::RemoteClient* process = &mc_model_checker->process();
- simgrid::mc::RegionSnapshot* heap_region1 = MC_get_heap_region(snapshot1);
- simgrid::mc::RegionSnapshot* heap_region2 = MC_get_heap_region(snapshot2);
+ simgrid::mc::Region* heap_region1 = MC_get_heap_region(snapshot1);
+ simgrid::mc::Region* heap_region2 = MC_get_heap_region(snapshot2);
for (int i = 0; i < size; ) {
const void* addr_pointed1;
const void* addr_pointed2;
- simgrid::mc::RegionSnapshot* heap_region1 = MC_get_heap_region(snapshot1);
- simgrid::mc::RegionSnapshot* heap_region2 = MC_get_heap_region(snapshot2);
+ simgrid::mc::Region* heap_region1 = MC_get_heap_region(snapshot1);
+ simgrid::mc::Region* heap_region2 = MC_get_heap_region(snapshot2);
switch (type->type) {
case DW_TAG_unspecified_type:
}
- simgrid::mc::RegionSnapshot* heap_region1 = MC_get_heap_region(snapshot1);
- simgrid::mc::RegionSnapshot* heap_region2 = MC_get_heap_region(snapshot2);
+ simgrid::mc::Region* heap_region1 = MC_get_heap_region(snapshot1);
+ simgrid::mc::Region* heap_region2 = MC_get_heap_region(snapshot2);
const malloc_info* heapinfo1 = (const malloc_info*) MC_region_read(
heap_region1, &heapinfo_temp1, &heapinfos1[block1], sizeof(malloc_info));
/******************************************************************************/
static int compare_areas_with_type(simgrid::mc::StateComparator& state, void* real_area1,
- simgrid::mc::Snapshot* snapshot1, simgrid::mc::RegionSnapshot* region1,
- void* real_area2, simgrid::mc::Snapshot* snapshot2,
- simgrid::mc::RegionSnapshot* region2, simgrid::mc::Type* type, int pointer_level)
+ simgrid::mc::Snapshot* snapshot1, simgrid::mc::Region* region1, void* real_area2,
+ simgrid::mc::Snapshot* snapshot2, simgrid::mc::Region* region2,
+ simgrid::mc::Type* type, int pointer_level)
{
simgrid::mc::RemoteClient* process = &mc_model_checker->process();
for (simgrid::mc::Member& member : type->members) {
void* member1 = simgrid::dwarf::resolve_member(real_area1, type, &member, snapshot1);
void* member2 = simgrid::dwarf::resolve_member(real_area2, type, &member, snapshot2);
- simgrid::mc::RegionSnapshot* subregion1 = snapshot1->get_region(member1, region1); // region1 is hinted
- simgrid::mc::RegionSnapshot* subregion2 = snapshot2->get_region(member2, region2); // region2 is hinted
+ simgrid::mc::Region* subregion1 = snapshot1->get_region(member1, region1); // region1 is hinted
+ simgrid::mc::Region* subregion2 = snapshot2->get_region(member2, region2); // region2 is hinted
res = compare_areas_with_type(state, member1, snapshot1, subregion1, member2, snapshot2, subregion2,
member.type, pointer_level);
if (res == 1)
}
static int compare_global_variables(simgrid::mc::StateComparator& state, simgrid::mc::ObjectInformation* object_info,
- simgrid::mc::RegionSnapshot* r1, simgrid::mc::RegionSnapshot* r2,
- simgrid::mc::Snapshot* snapshot1, simgrid::mc::Snapshot* snapshot2)
+ simgrid::mc::Region* r1, simgrid::mc::Region* r2, simgrid::mc::Snapshot* snapshot1,
+ simgrid::mc::Snapshot* snapshot2)
{
xbt_assert(r1 && r2, "Missing region.");
xbt_assert(regions_count == s2->snapshot_regions_.size());
for (size_t k = 0; k != regions_count; ++k) {
- RegionSnapshot* region1 = s1->snapshot_regions_[k].get();
- RegionSnapshot* region2 = s2->snapshot_regions_[k].get();
+ Region* region1 = s1->snapshot_regions_[k].get();
+ Region* region2 = s2->snapshot_regions_[k].get();
// Preconditions:
if (region1->region_type() != RegionType::Data)
namespace simgrid {
namespace mc {
-RegionSnapshot::RegionSnapshot(RegionType region_type, void* start_addr, size_t size)
+Region::Region(RegionType region_type, void* start_addr, size_t size)
: region_type_(region_type), start_addr_(start_addr), size_(size)
{
- simgrid::mc::RemoteClient* process = &mc_model_checker->process();
-
xbt_assert((((uintptr_t)start_addr) & (xbt_pagesize - 1)) == 0, "Start address not at the beginning of a page");
- chunks_ = ChunkedData(mc_model_checker->page_store(), *process, RemotePtr<void>(start_addr), mmu::chunk_count(size));
+ chunks_ = ChunkedData(mc_model_checker->page_store(), mc_model_checker->process(), RemotePtr<void>(start_addr),
+ mmu::chunk_count(size));
}
/** @brief Restore a region from a snapshot
*
* @param region Target region
*/
-void RegionSnapshot::restore()
+void Region::restore()
{
xbt_assert(((start().address()) & (xbt_pagesize - 1)) == 0, "Not at the beginning of a page");
xbt_assert(simgrid::mc::mmu::chunk_count(size()) == get_chunks().page_count());
/* This program is free software; you can redistribute it and/or modify it
* under the terms of the license (GNU LGPL) which comes with this package. */
-#ifndef SIMGRID_MC_REGION_SNAPSHOT_HPP
-#define SIMGRID_MC_REGION_SNAPSHOT_HPP
+#ifndef SIMGRID_MC_SOSP_REGION_HPP
+#define SIMGRID_MC_SOSP_REGION_HPP
#include "src/mc/remote/RemotePtr.hpp"
#include "src/mc/sosp/ChunkedData.hpp"
namespace simgrid {
namespace mc {
-enum class RegionType { Unknown = 0, Heap = 1, Data = 2 };
+enum class RegionType { Heap = 1, Data = 2 };
/** A copy/snapshot of a given memory region, where identical pages are stored only once */
-class RegionSnapshot {
+class Region {
public:
- static const RegionType UnknownRegion = RegionType::Unknown;
static const RegionType HeapRegion = RegionType::Heap;
static const RegionType DataRegion = RegionType::Data;
-protected:
- RegionType region_type_ = UnknownRegion;
+private:
+ RegionType region_type_;
simgrid::mc::ObjectInformation* object_info_ = nullptr;
/** @brief Virtual address of the region in the simulated process */
ChunkedData chunks_;
public:
- RegionSnapshot(RegionType type, void* start_addr, size_t size);
- ~RegionSnapshot() = default;
- RegionSnapshot(RegionSnapshot const&) = delete;
- RegionSnapshot& operator=(RegionSnapshot const&) = delete;
- RegionSnapshot(RegionSnapshot&& that)
- : region_type_(that.region_type_)
- , object_info_(that.object_info_)
- , start_addr_(that.start_addr_)
- , size_(that.size_)
- , chunks_(std::move(that.chunks_))
- {
- that.clear();
- }
- RegionSnapshot& operator=(RegionSnapshot&& that)
- {
- region_type_ = that.region_type_;
- object_info_ = that.object_info_;
- start_addr_ = that.start_addr_;
- size_ = that.size_;
- chunks_ = std::move(that.chunks_);
- that.clear();
- return *this;
- }
+ Region(RegionType type, void* start_addr, size_t size);
+ ~Region() = default;
+ Region(Region const&) = delete;
+ Region& operator=(Region const&) = delete;
+ Region(Region&& that) = delete;
+ Region& operator=(Region&& that) = delete;
// Data
- void clear()
- {
- region_type_ = UnknownRegion;
- chunks_.clear();
- object_info_ = nullptr;
- start_addr_ = nullptr;
- size_ = 0;
- }
-
ChunkedData const& get_chunks() const { return chunks_; }
simgrid::mc::ObjectInformation* object_info() const { return object_info_; }
* @param size Size of the data to read in bytes
* @return Pointer where the data is located (target buffer of original location)
*/
-const void* MC_region_read_fragmented(simgrid::mc::RegionSnapshot* region, void* target, const void* addr, size_t size)
+const void* MC_region_read_fragmented(simgrid::mc::Region* region, void* target, const void* addr, size_t size)
{
// Last byte of the memory area:
void* end = (char*)addr + size - 1;
* @param region2 Region of the address in the second snapshot
* @return same semantic as memcmp
*/
-int MC_snapshot_region_memcmp(const void* addr1, simgrid::mc::RegionSnapshot* region1, const void* addr2,
- simgrid::mc::RegionSnapshot* region2, size_t size)
+int MC_snapshot_region_memcmp(const void* addr1, simgrid::mc::Region* region1, const void* addr2,
+ simgrid::mc::Region* region2, size_t size)
{
// Using alloca() for large allocations may trigger stack overflow:
// use malloc if the buffer is too big.
else if (type == simgrid::mc::RegionType::Heap)
xbt_assert(not object_info, "Unexpected object info for heap region.");
- simgrid::mc::RegionSnapshot* region = new RegionSnapshot(type, start_addr, size);
+ simgrid::mc::Region* region = new Region(type, start_addr, size);
region->object_info(object_info);
- snapshot_regions_.push_back(std::unique_ptr<simgrid::mc::RegionSnapshot>(std::move(region)));
+ snapshot_regions_.push_back(std::unique_ptr<simgrid::mc::Region>(std::move(region)));
}
const void* Snapshot::read_bytes(void* buffer, std::size_t size, RemotePtr<void> address, ReadOptions options) const
{
- RegionSnapshot* region = this->get_region((void*)address.address());
+ Region* region = this->get_region((void*)address.address());
if (region) {
const void* res = MC_region_read(region, buffer, (void*)address.address(), size);
if (buffer == res || options & ReadOptions::lazy())
*
* @param addr Pointer
* */
-RegionSnapshot* Snapshot::get_region(const void* addr) const
+Region* Snapshot::get_region(const void* addr) const
{
size_t n = snapshot_regions_.size();
for (size_t i = 0; i != n; ++i) {
- RegionSnapshot* region = snapshot_regions_[i].get();
+ Region* region = snapshot_regions_[i].get();
if (not(region && region->contain(simgrid::mc::remote(addr))))
continue;
}
/** @brief Find the snapshoted region from a pointer, with a hinted_region */
-RegionSnapshot* Snapshot::get_region(const void* addr, RegionSnapshot* hinted_region) const
+Region* Snapshot::get_region(const void* addr, Region* hinted_region) const
{
if (hinted_region->contain(simgrid::mc::remote(addr)))
return hinted_region;
XBT_DEBUG("Restore snapshot %i", num_state_);
// Restore regions
- for (std::unique_ptr<simgrid::mc::RegionSnapshot> const& region : snapshot_regions_) {
+ for (std::unique_ptr<simgrid::mc::Region> const& region : snapshot_regions_) {
if (region) // privatized variables are not snapshoted
region.get()->restore();
}
// ***** Snapshot region
-static XBT_ALWAYS_INLINE void* mc_translate_address_region(uintptr_t addr, simgrid::mc::RegionSnapshot* region)
+static XBT_ALWAYS_INLINE void* mc_translate_address_region(uintptr_t addr, simgrid::mc::Region* region)
{
auto split = simgrid::mc::mmu::split(addr - region->start().address());
auto pageno = split.first;
/* Regular use */
const void* read_bytes(void* buffer, std::size_t size, RemotePtr<void> address,
ReadOptions options = ReadOptions::none()) const override;
- RegionSnapshot* get_region(const void* addr) const;
- RegionSnapshot* get_region(const void* addr, RegionSnapshot* hinted_region) const;
+ Region* get_region(const void* addr) const;
+ Region* get_region(const void* addr, Region* hinted_region) const;
void restore(RemoteClient* process);
// To be private
int num_state_;
std::size_t heap_bytes_used_;
- std::vector<std::unique_ptr<RegionSnapshot>> snapshot_regions_;
+ std::vector<std::unique_ptr<Region>> snapshot_regions_;
std::set<pid_t> enabled_processes_;
std::vector<std::size_t> stack_sizes_;
std::vector<s_mc_snapshot_stack_t> stacks_;
static const void* mc_snapshot_get_heap_end(simgrid::mc::Snapshot* snapshot);
-const void* MC_region_read_fragmented(simgrid::mc::RegionSnapshot* region, void* target, const void* addr,
- std::size_t size);
+const void* MC_region_read_fragmented(simgrid::mc::Region* region, void* target, const void* addr, std::size_t size);
-int MC_snapshot_region_memcmp(const void* addr1, simgrid::mc::RegionSnapshot* region1, const void* addr2,
- simgrid::mc::RegionSnapshot* region2, std::size_t size);
+int MC_snapshot_region_memcmp(const void* addr1, simgrid::mc::Region* region1, const void* addr2,
+ simgrid::mc::Region* region2, std::size_t size);
static XBT_ALWAYS_INLINE const void* mc_snapshot_get_heap_end(simgrid::mc::Snapshot* snapshot)
{
* @param size Size of the data to read in bytes
* @return Pointer where the data is located (target buffer of original location)
*/
-static XBT_ALWAYS_INLINE const void* MC_region_read(simgrid::mc::RegionSnapshot* region, void* target, const void* addr,
+static XBT_ALWAYS_INLINE const void* MC_region_read(simgrid::mc::Region* region, void* target, const void* addr,
std::size_t size)
{
xbt_assert(region);
return MC_region_read_fragmented(region, target, addr, size);
}
-static XBT_ALWAYS_INLINE void* MC_region_read_pointer(simgrid::mc::RegionSnapshot* region, const void* addr)
+static XBT_ALWAYS_INLINE void* MC_region_read_pointer(simgrid::mc::Region* region, const void* addr)
{
void* res;
return *(void**)MC_region_read(region, &res, addr, sizeof(void*));
#include <sys/mman.h>
/**************** Class BOOST_tests *************************/
-using simgrid::mc::RegionSnapshot;
+using simgrid::mc::Region;
class snap_test_helper {
public:
static void init_memory(void* mem, size_t size);
size_t size;
void* src;
void* dstn;
- RegionSnapshot* region0;
- RegionSnapshot* region;
+ Region* region0;
+ Region* region;
} prologue_return;
static prologue_return prologue(int n); // common to the below 5 fxs
static void read_whole_region();
// Init memory and take snapshots:
init_memory(source, byte_size);
- simgrid::mc::RegionSnapshot* region0 =
- new simgrid::mc::RegionSnapshot(simgrid::mc::RegionType::Unknown, source, byte_size);
+ simgrid::mc::Region* region0 = new simgrid::mc::Region(simgrid::mc::RegionType::Data, source, byte_size);
for (int i = 0; i < n; i += 2) {
init_memory((char*)source + i * xbt_pagesize, xbt_pagesize);
}
- simgrid::mc::RegionSnapshot* region =
- new simgrid::mc::RegionSnapshot(simgrid::mc::RegionType::Unknown, source, byte_size);
+ simgrid::mc::Region* region = new simgrid::mc::Region(simgrid::mc::RegionType::Data, source, byte_size);
void* destination = mmap(nullptr, byte_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
INFO("Could not allocate destination memory");
prologue_return ret = prologue(1);
memcpy(ret.src, &mc_model_checker, sizeof(void*));
- simgrid::mc::RegionSnapshot* region2 =
- new simgrid::mc::RegionSnapshot(simgrid::mc::RegionType::Unknown, ret.src, ret.size);
+ simgrid::mc::Region* region2 = new simgrid::mc::Region(simgrid::mc::RegionType::Data, ret.src, ret.size);
INFO("Mismtach in MC_region_read_pointer()");
REQUIRE(MC_region_read_pointer(region2, ret.src) == mc_model_checker);