Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of https://github.com/Onesphore/simgrid into Onesphore-master
[simgrid.git] / src / mc / sosp / mc_page_snapshot.cpp
1 /* Copyright (c) 2014-2018. 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 /* MC interface: definitions that non-MC modules must see, but not the user */
7
8 #include <unistd.h> // pread, pwrite
9
10 #include "src/mc/mc_mmu.hpp"
11 #include "src/mc/mc_private.hpp"
12 #include "src/mc/sosp/PageStore.hpp"
13 #include "src/mc/sosp/mc_snapshot.hpp"
14
15 #include "src/mc/sosp/ChunkedData.hpp"
16 #include <xbt/mmalloc.h>
17
18 using simgrid::mc::remote;
19
20 /** @brief Restore a snapshot of a region
21  *
22  *  If possible, the restoration will be incremental
23  *  (the modified pages will not be touched).
24  *
25  *  @param start_addr
26  *  @param page_count       Number of pages of the region
27  *  @param pagenos
28  */
29 void mc_restore_page_snapshot_region(simgrid::mc::RemoteClient* process, void* start_addr,
30                                      simgrid::mc::ChunkedData const& pages_copy)
31 {
32   for (size_t i = 0; i != pages_copy.page_count(); ++i) {
33     // Otherwise, copy the page:
34     void* target_page       = (void*)simgrid::mc::mmu::join(i, (std::uintptr_t)start_addr);
35     const void* source_page = pages_copy.page(i);
36     process->write_bytes(source_page, xbt_pagesize, remote(target_page));
37   }
38 }
39
40 // ***** High level API
41
42 void mc_region_restore_sparse(simgrid::mc::RemoteClient* process, mc_mem_region_t reg)
43 {
44   xbt_assert(((reg->permanent_address().address()) & (xbt_pagesize - 1)) == 0, "Not at the beginning of a page");
45   xbt_assert(simgrid::mc::mmu::chunkCount(reg->size()) == reg->page_data().page_count());
46   mc_restore_page_snapshot_region(process, (void*)reg->permanent_address().address(), reg->page_data());
47 }