Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
44634488901c7bfa8f0281d52d1d8949b8245f4e
[simgrid.git] / src / mc / mc_page_snapshot.cpp
1 /* MC interface: definitions that non-MC modules must see, but not the user */
2
3 /* Copyright (c) 2014-2015. The SimGrid Team.
4  * All rights reserved.                                                     */
5
6 /* This program is free software; you can redistribute it and/or modify it
7  * under the terms of the license (GNU LGPL) which comes with this package. */
8
9 #include <unistd.h> // pread, pwrite
10
11 #include "PageStore.hpp"
12 #include "mc_mmu.h"
13 #include "mc_private.h"
14 #include "mc_snapshot.h"
15
16 #include <xbt/mmalloc.h>
17 #include "src/mc/ChunkedData.hpp"
18
19 using simgrid::mc::remote;
20
21 extern "C" {
22
23 /** @brief Restore a snapshot of a region
24  *
25  *  If possible, the restoration will be incremental
26  *  (the modified pages will not be touched).
27  *
28  *  @param start_addr
29  *  @param page_count       Number of pages of the region
30  *  @param pagenos
31  */
32 void mc_restore_page_snapshot_region(simgrid::mc::Process* process,
33   void* start_addr, simgrid::mc::ChunkedData const& pages_copy)
34 {
35   for (size_t i = 0; i != pages_copy.page_count(); ++i) {
36     // Otherwise, copy the page:
37     void* target_page = mc_page_from_number(start_addr, i);
38     const void* source_page = pages_copy.page(i);
39     process->write_bytes(source_page, xbt_pagesize, remote(target_page));
40   }
41 }
42
43 // ***** High level API
44
45 void mc_region_restore_sparse(simgrid::mc::Process* process, mc_mem_region_t reg)
46 {
47   xbt_assert(((reg->permanent_address().address()) & (xbt_pagesize-1)) == 0,
48     "Not at the beginning of a page");
49   xbt_assert(mc_page_count(reg->size()) == reg->page_data().page_count());
50   mc_restore_page_snapshot_region(process,
51     (void*) reg->permanent_address().address(), reg->page_data());
52 }
53
54 }