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