+#include <libgen.h>
#include "private.h"
static mc_mem_region_t MC_region_new(void *start_addr, size_t size);
void MC_take_snapshot(mc_snapshot_t snapshot)
{
- unsigned int i;
+ unsigned int i = 0;
s_map_region reg;
memory_map_t maps = get_memory_map();
- /* Save all the writable mapped pages except the and the stack */
- for (i = 0; i < maps->mapsize; i++) {
+ /* Save the std heap and the writable mapped pages of libsimgrid */
+ while (i < maps->mapsize) {
reg = maps->regions[i];
- if((reg.prot & PROT_WRITE)
- && (reg.pathname == NULL
- || (strncmp(reg.pathname, "/dev/zero", 9)
- && strncmp(reg.pathname, "[stack]", 7)))){
- MC_snapshot_add_region(snapshot, reg.start_addr,
- (char*)reg.end_addr - (char*)reg.start_addr);
+ if ((reg.prot & PROT_WRITE)){
+ if (maps->regions[i].pathname == NULL){
+ if (reg.start_addr == std_heap){
+ MC_snapshot_add_region(snapshot, reg.start_addr, (char*)reg.end_addr - (char*)reg.start_addr);
+ }
+ } else {
+ if (!memcmp(basename(maps->regions[i].pathname), "libsimgrid", 10)){
+ MC_snapshot_add_region(snapshot, reg.start_addr, (char*)reg.end_addr - (char*)reg.start_addr);
+ }
+ }
}
+ i++;
}
+
+
+ /* FIXME: free the memory map */
}
void MC_restore_snapshot(mc_snapshot_t snapshot)