#define MAP_POPULATE MAP_PREFAULT_READ
#endif
-#include "mc/mc.h"
+#include "src/mc/ModelChecker.hpp"
#include "src/mc/mc_config.hpp"
-#include "src/mc/sosp/mc_snapshot.hpp"
+#include "src/mc/mc_forward.hpp"
-#include "src/mc/sosp/ChunkedData.hpp"
+#include "src/mc/mc_smx.hpp"
#include "src/mc/sosp/RegionSnapshot.hpp"
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_RegionSnaphot, mc, "Logging specific to region snapshots");
namespace simgrid {
namespace mc {
-RegionSnapshot dense_region(RegionType region_type, void* start_addr, void* permanent_addr, size_t size)
+RegionSnapshot::RegionSnapshot(RegionType region_type, void* start_addr, size_t size)
+ : region_type_(region_type), start_addr_(start_addr), size_(size)
{
- simgrid::mc::Buffer data = Buffer::malloc(size);
-
- mc_model_checker->process().read_bytes(data.get(), size, remote(permanent_addr), simgrid::mc::ProcessIndexDisabled);
+ simgrid::mc::RemoteClient* process = &mc_model_checker->process();
- simgrid::mc::RegionSnapshot region(region_type, start_addr, permanent_addr, size);
- region.flat_data(std::move(data));
+ xbt_assert((((uintptr_t)start_addr) & (xbt_pagesize - 1)) == 0, "Start address not at the beginning of a page");
- XBT_DEBUG("New region : type : %s, data : %p (real addr %p), size : %zu",
- (region_type == RegionType::Heap ? "Heap" : (region_type == RegionType::Data ? "Data" : "?")),
- region.flat_data().get(), permanent_addr, size);
- return region;
+ chunks_ = ChunkedData(mc_model_checker->page_store(), *process, RemotePtr<void>(start_addr), mmu::chunk_count(size));
}
-/** @brief Take a snapshot of a given region
+/** @brief Restore a region from a snapshot
*
- * @param type
- * @param start_addr Address of the region in the simulated process
- * @param permanent_addr Permanent address of this data (for privatized variables, this is the virtual address of the
- * privatized mapping)
- * @param size Size of the data*
+ * @param region Target region
*/
-RegionSnapshot region(RegionType type, void* start_addr, void* permanent_addr, size_t size)
-{
- if (_sg_mc_sparse_checkpoint)
- return sparse_region(type, start_addr, permanent_addr, size);
- else
- return dense_region(type, start_addr, permanent_addr, size);
-}
-
-RegionSnapshot sparse_region(RegionType region_type, void* start_addr, void* permanent_addr, size_t size)
+void RegionSnapshot::restore()
{
- simgrid::mc::RemoteClient* process = &mc_model_checker->process();
- assert(process != nullptr);
-
- xbt_assert((((uintptr_t)start_addr) & (xbt_pagesize - 1)) == 0, "Start address not at the beginning of a page");
- xbt_assert((((uintptr_t)permanent_addr) & (xbt_pagesize - 1)) == 0,
- "Permanent address not at the beginning of a page");
- size_t page_count = simgrid::mc::mmu::chunk_count(size);
-
- simgrid::mc::ChunkedData page_data(mc_model_checker->page_store(), *process, RemotePtr<void>(permanent_addr),
- page_count);
-
- simgrid::mc::RegionSnapshot region(region_type, start_addr, permanent_addr, size);
- region.page_data(std::move(page_data));
- return region;
+ 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());
+
+ for (size_t i = 0; i != get_chunks().page_count(); ++i) {
+ void* target_page = (void*)simgrid::mc::mmu::join(i, (std::uintptr_t)(void*)start().address());
+ const void* source_page = get_chunks().page(i);
+ mc_model_checker->process().write_bytes(source_page, xbt_pagesize, remote(target_page));
+ }
}
} // namespace mc