Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Cleanups in class mc::Region
[simgrid.git] / src / mc / sosp / Region.cpp
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 #include "src/mc/ModelChecker.hpp"
7 #include "src/mc/mc_config.hpp"
8 #include "src/mc/mc_forward.hpp"
9
10 #include "src/mc/mc_smx.hpp"
11 #include "src/mc/sosp/Region.hpp"
12
13 #include <cstdlib>
14 #include <sys/mman.h>
15 #ifdef __FreeBSD__
16 #define MAP_POPULATE MAP_PREFAULT_READ
17 #endif
18
19 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_RegionSnaphot, mc, "Logging specific to region snapshots");
20
21 namespace simgrid {
22 namespace mc {
23
24 Region::Region(RegionType region_type, void* start_addr, size_t size)
25     : region_type_(region_type), start_addr_(start_addr), size_(size)
26 {
27   xbt_assert((((uintptr_t)start_addr) & (xbt_pagesize - 1)) == 0, "Start address not at the beginning of a page");
28
29   chunks_ = ChunkedData(mc_model_checker->page_store(), mc_model_checker->process(), RemotePtr<void>(start_addr),
30                         mmu::chunk_count(size));
31 }
32
33 /** @brief Restore a region from a snapshot
34  *
35  *  @param region     Target region
36  */
37 void Region::restore()
38 {
39   xbt_assert(((start().address()) & (xbt_pagesize - 1)) == 0, "Not at the beginning of a page");
40   xbt_assert(simgrid::mc::mmu::chunk_count(size()) == get_chunks().page_count());
41
42   for (size_t i = 0; i != get_chunks().page_count(); ++i) {
43     void* target_page       = (void*)simgrid::mc::mmu::join(i, (std::uintptr_t)(void*)start().address());
44     const void* source_page = get_chunks().page(i);
45     mc_model_checker->process().write_bytes(source_page, xbt_pagesize, remote(target_page));
46   }
47 }
48
49 } // namespace mc
50 } // namespace simgrid