1 /* Copyright (c) 2007-2019. The SimGrid Team. All rights reserved. */
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. */
10 #define MAP_POPULATE MAP_PREFAULT_READ
13 #include "src/mc/ModelChecker.hpp"
14 #include "src/mc/mc_config.hpp"
15 #include "src/mc/mc_forward.hpp"
17 #include "src/mc/mc_smx.hpp"
18 #include "src/mc/sosp/RegionSnapshot.hpp"
20 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_RegionSnaphot, mc, "Logging specific to region snapshots");
25 RegionSnapshot::RegionSnapshot(RegionType region_type, void* start_addr, size_t size)
26 : region_type_(region_type), start_addr_(start_addr), size_(size)
28 simgrid::mc::RemoteClient* process = &mc_model_checker->process();
30 xbt_assert((((uintptr_t)start_addr) & (xbt_pagesize - 1)) == 0, "Start address not at the beginning of a page");
32 chunks_ = ChunkedData(mc_model_checker->page_store(), *process, RemotePtr<void>(start_addr), mmu::chunk_count(size));
35 /** @brief Restore a region from a snapshot
37 * @param region Target region
39 void RegionSnapshot::restore()
41 xbt_assert(((start().address()) & (xbt_pagesize - 1)) == 0, "Not at the beginning of a page");
42 xbt_assert(simgrid::mc::mmu::chunk_count(size()) == get_chunks().page_count());
44 for (size_t i = 0; i != get_chunks().page_count(); ++i) {
45 void* target_page = (void*)simgrid::mc::mmu::join(i, (std::uintptr_t)(void*)start().address());
46 const void* source_page = get_chunks().page(i);
47 mc_model_checker->process().write_bytes(source_page, xbt_pagesize, remote(target_page));
52 } // namespace simgrid