1 /* Copyright (c) 2007-2015. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
10 #include "mc_snapshot.h"
11 #include "RegionSnapshot.hpp"
15 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_RegionSnaphot, mc,
16 "Logging specific to region snapshots");
24 const char* to_cstr(RegionType region)
27 case RegionType::Unknown:
29 case RegionType::Heap:
31 case RegionType::Data:
38 void data_deleter::operator()(void* p) const
50 RegionSnapshot dense_region(
51 RegionType region_type,
52 void *start_addr, void* permanent_addr, size_t size)
54 simgrid::mc::RegionSnapshot::flat_data_ptr data((char*) malloc(size));
55 mc_model_checker->process().read_bytes(data.get(), size,
56 remote(permanent_addr),
57 simgrid::mc::ProcessIndexDisabled);
59 simgrid::mc::RegionSnapshot region(
60 region_type, start_addr, permanent_addr, size);
61 region.flat_data(std::move(data));
63 XBT_DEBUG("New region : type : %s, data : %p (real addr %p), size : %zu",
64 to_cstr(region_type), region.flat_data(), permanent_addr, size);
65 return std::move(region);
68 /** @brief Take a snapshot of a given region
71 * @param start_addr Address of the region in the simulated process
72 * @param permanent_addr Permanent address of this data (for privatized variables, this is the virtual address of the privatized mapping)
73 * @param size Size of the data*
75 RegionSnapshot region(
76 RegionType type, void *start_addr, void* permanent_addr, size_t size)
78 if (_sg_mc_sparse_checkpoint) {
79 return sparse_region(type, start_addr, permanent_addr, size);
81 return dense_region(type, start_addr, permanent_addr, size);
85 RegionSnapshot sparse_region(RegionType region_type,
86 void *start_addr, void* permanent_addr, size_t size)
88 simgrid::mc::Process* process = &mc_model_checker->process();
90 xbt_assert((((uintptr_t)start_addr) & (xbt_pagesize-1)) == 0,
91 "Not at the beginning of a page");
92 xbt_assert((((uintptr_t)permanent_addr) & (xbt_pagesize-1)) == 0,
93 "Not at the beginning of a page");
94 size_t page_count = mc_page_count(size);
96 simgrid::mc::PerPageCopy page_data(mc_model_checker->page_store(), *process,
97 permanent_addr, page_count);
99 simgrid::mc::RegionSnapshot region(
100 region_type, start_addr, permanent_addr, size);
101 region.page_data(std::move(page_data));
102 return std::move(region);