1 /* Copyright (c) 2008-2014. 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. */
16 #include "internal_config.h"
17 #include "mc_memory_map.h"
18 #include "mc_private.h"
19 #include "xbt/module.h"
20 #include <xbt/mmalloc.h>
21 #include "../smpi/private.h"
24 #include "xbt/mmalloc/mmprivate.h"
26 #include "../simix/smx_private.h"
28 #define UNW_LOCAL_ONLY
29 #include <libunwind.h>
32 #include "mc_private.h"
35 #include "mc_snapshot.h"
36 #include "mc_object_info.h"
39 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_checkpoint, mc,
40 "Logging specific to mc_checkpoint");
42 /************************************ Free functions **************************************/
43 /*****************************************************************************************/
45 static void MC_snapshot_stack_free(mc_snapshot_stack_t s)
48 xbt_dynar_free(&(s->local_variables));
49 xbt_dynar_free(&(s->stack_frames));
54 static void MC_snapshot_stack_free_voidp(void *s)
56 MC_snapshot_stack_free((mc_snapshot_stack_t) * (void **) s);
59 static void local_variable_free(local_variable_t v)
65 static void local_variable_free_voidp(void *v)
67 local_variable_free((local_variable_t) * (void **) v);
70 void MC_region_destroy(mc_mem_region_t region)
74 switch(region->storage_type) {
75 case MC_REGION_STORAGE_TYPE_NONE:
77 case MC_REGION_STORAGE_TYPE_FLAT:
78 xbt_free(region->flat.data);
80 case MC_REGION_STORAGE_TYPE_CHUNKED:
81 mc_free_page_snapshot_region(region->chunked.page_numbers, mc_page_count(region->size));
82 xbt_free(region->chunked.page_numbers);
84 case MC_REGION_STORAGE_TYPE_PRIVATIZED:
86 size_t regions_count = region->privatized.regions_count;
87 for (size_t i=0; i!=regions_count; ++i) {
88 MC_region_destroy(region->privatized.regions[i]);
90 free(region->privatized.regions);
97 void MC_free_snapshot(mc_snapshot_t snapshot)
99 for (size_t i = 0; i < snapshot->snapshot_regions_count; i++) {
100 MC_region_destroy(snapshot->snapshot_regions[i]);
102 xbt_free(snapshot->snapshot_regions);
103 xbt_free(snapshot->stack_sizes);
104 xbt_dynar_free(&(snapshot->stacks));
105 xbt_dynar_free(&(snapshot->to_ignore));
106 xbt_dynar_free(&snapshot->ignored_data);
110 /******************************* Snapshot regions ********************************/
111 /*********************************************************************************/
113 static mc_mem_region_t mc_region_new_dense(
114 mc_region_type_t region_type,
115 void *start_addr, void* permanent_addr, size_t size, mc_mem_region_t ref_reg)
117 mc_mem_region_t region = xbt_new(s_mc_mem_region_t, 1);
118 region->region_type = region_type;
119 region->storage_type = MC_REGION_STORAGE_TYPE_FLAT;
120 region->start_addr = start_addr;
121 region->permanent_addr = permanent_addr;
123 region->flat.data = xbt_malloc(size);
124 MC_process_read(&mc_model_checker->process, MC_ADDRESS_SPACE_READ_FLAGS_NONE,
125 region->flat.data, permanent_addr, size,
126 MC_PROCESS_INDEX_DISABLED);
127 XBT_DEBUG("New region : type : %d, data : %p (real addr %p), size : %zu",
128 region_type, region->flat.data, permanent_addr, size);
132 /** @brief Take a snapshot of a given region
135 * @param start_addr Address of the region in the simulated process
136 * @param permanent_addr Permanent address of this data (for privatized variables, this is the virtual address of the privatized mapping)
137 * @param size Size of the data*
138 * @param ref_reg Reference corresponding region
140 static mc_mem_region_t MC_region_new(mc_region_type_t type, void *start_addr, void* permanent_addr, size_t size, mc_mem_region_t ref_reg)
142 if (_sg_mc_sparse_checkpoint) {
143 return mc_region_new_sparse(type, start_addr, permanent_addr, size, ref_reg);
145 return mc_region_new_dense(type, start_addr, permanent_addr, size, ref_reg);
149 /** @brief Restore a region from a snapshot
151 * If we are using per page snapshots, it is possible to use the reference
152 * region in order to do an incremental restoration of the region: the
153 * softclean pages which are shared between the two snapshots do not need
156 * @param reg Target region
157 * @param reg_reg Current region (if not NULL), used for lazy per page restoration
159 static void MC_region_restore(mc_mem_region_t region, mc_mem_region_t ref_region)
161 switch(region->storage_type) {
162 case MC_REGION_STORAGE_TYPE_NONE:
164 xbt_die("Storage type not supported");
167 case MC_REGION_STORAGE_TYPE_FLAT:
168 MC_process_write(&mc_model_checker->process, region->flat.data,
169 region->permanent_addr, region->size);
172 case MC_REGION_STORAGE_TYPE_CHUNKED:
173 mc_region_restore_sparse(&mc_model_checker->process, region, ref_region);
176 case MC_REGION_STORAGE_TYPE_PRIVATIZED:
178 bool has_ref_regions = ref_region &&
179 ref_region->storage_type == MC_REGION_STORAGE_TYPE_PRIVATIZED;
180 size_t process_count = region->privatized.regions_count;
181 for (size_t i = 0; i < process_count; i++) {
182 MC_region_restore(region->privatized.regions[i],
183 has_ref_regions ? ref_region->privatized.regions[i] : NULL);
191 void* MC_privatization_address(mc_process_t process, int process_index)
193 xbt_assert(process_index >= 0);
194 return smpi_privatisation_regions[process_index].address;
197 static mc_mem_region_t MC_region_new_privatized(
198 mc_region_type_t region_type, void *start_addr, void* permanent_addr, size_t size,
199 mc_mem_region_t ref_reg)
201 size_t process_count = smpi_process_count();
202 mc_mem_region_t region = xbt_new(s_mc_mem_region_t, 1);
203 region->region_type = region_type;
204 region->storage_type = MC_REGION_STORAGE_TYPE_PRIVATIZED;
205 region->start_addr = start_addr;
206 region->permanent_addr = permanent_addr;
208 region->privatized.regions_count = process_count;
209 region->privatized.regions = xbt_new(mc_mem_region_t, process_count);
211 for (size_t i = 0; i < process_count; i++) {
212 mc_mem_region_t ref_subreg = NULL;
213 if (ref_reg && ref_reg->storage_type == MC_REGION_STORAGE_TYPE_PRIVATIZED)
214 ref_subreg = ref_reg->privatized.regions[i];
215 region->privatized.regions[i] =
216 MC_region_new(region_type, start_addr,
217 MC_privatization_address(&mc_model_checker->process, i), size,
224 static void MC_snapshot_add_region(int index, mc_snapshot_t snapshot, mc_region_type_t type,
225 mc_object_info_t object_info,
226 void *start_addr, void* permanent_addr, size_t size)
228 if (type == MC_REGION_TYPE_DATA)
229 xbt_assert(object_info, "Missing object info for object.");
230 else if (type == MC_REGION_TYPE_HEAP)
231 xbt_assert(!object_info, "Unexpected object info for heap region.");
233 mc_mem_region_t ref_reg = NULL;
234 if (mc_model_checker->parent_snapshot)
235 ref_reg = mc_model_checker->parent_snapshot->snapshot_regions[index];
237 mc_mem_region_t region;
238 const bool privatization_aware = MC_object_info_is_privatized(object_info);
239 if (privatization_aware && smpi_process_count())
240 region = MC_region_new_privatized(type, start_addr, permanent_addr, size, ref_reg);
242 region = MC_region_new(type, start_addr, permanent_addr, size, ref_reg);
244 region->object_info = object_info;
245 snapshot->snapshot_regions[index] = region;
249 static void MC_get_memory_regions(mc_process_t process, mc_snapshot_t snapshot)
251 const size_t n = process->object_infos_size;
252 snapshot->snapshot_regions_count = n + 1;
253 snapshot->snapshot_regions = xbt_new0(mc_mem_region_t, n + 1);
255 for (size_t i = 0; i!=n; ++i) {
256 mc_object_info_t object_info = process->object_infos[i];
257 MC_snapshot_add_region(i, snapshot, MC_REGION_TYPE_DATA, object_info,
258 object_info->start_rw, object_info->start_rw,
259 object_info->end_rw - object_info->start_rw);
262 xbt_mheap_t heap = MC_process_get_heap(process);
263 void *start_heap = heap->base;
264 void *end_heap = heap->breakval;
266 MC_snapshot_add_region(n, snapshot, MC_REGION_TYPE_HEAP, NULL,
267 start_heap, start_heap,
268 (char *) end_heap - (char *) start_heap);
269 snapshot->heap_bytes_used = mmalloc_get_bytes_used_remote(
271 MC_process_get_malloc_info(process));
274 if (smpi_privatize_global_variables && smpi_process_count()) {
275 snapshot->privatization_index = smpi_loaded_page;
279 snapshot->privatization_index = MC_PROCESS_INDEX_MISSING;
283 /** \brief Fills the position of the segments (executable, read-only, read/write).
285 * TODO, use dl_iterate_phdr to be more robust
287 void MC_find_object_address(memory_map_t maps, mc_object_info_t result)
291 const char *name = basename(result->file_name);
292 while (i < maps->mapsize) {
293 reg = maps->regions[i];
294 if (maps->regions[i].pathname == NULL
295 || strcmp(basename(maps->regions[i].pathname), name)) {
297 } else if ((reg.prot & PROT_WRITE)) {
298 xbt_assert(!result->start_rw,
299 "Multiple read-write segments for %s, not supported",
300 maps->regions[i].pathname);
301 result->start_rw = reg.start_addr;
302 result->end_rw = reg.end_addr;
303 // .bss is usually after the .data:
304 s_map_region_t *next = &(maps->regions[i + 1]);
305 if (next->pathname == NULL && (next->prot & PROT_WRITE)
306 && next->start_addr == reg.end_addr) {
307 result->end_rw = maps->regions[i + 1].end_addr;
309 } else if ((reg.prot & PROT_READ) && (reg.prot & PROT_EXEC)) {
310 xbt_assert(!result->start_exec,
311 "Multiple executable segments for %s, not supported",
312 maps->regions[i].pathname);
313 result->start_exec = reg.start_addr;
314 result->end_exec = reg.end_addr;
315 } else if ((reg.prot & PROT_READ) && !(reg.prot & PROT_EXEC)) {
316 xbt_assert(!result->start_ro,
317 "Multiple read only segments for %s, not supported",
318 maps->regions[i].pathname);
319 result->start_ro = reg.start_addr;
320 result->end_ro = reg.end_addr;
325 result->start = result->start_rw;
326 if ((const void*) result->start_ro > result->start)
327 result->start = result->start_ro;
328 if ((const void*) result->start_exec > result->start)
329 result->start = result->start_exec;
331 result->end = result->end_rw;
332 if (result->end_ro && (const void*) result->end_ro < result->end)
333 result->end = result->end_ro;
334 if (result->end_exec && (const void*) result->end_exec > result->end)
335 result->end = result->end_exec;
337 xbt_assert(result->file_name);
338 xbt_assert(result->start_rw);
339 xbt_assert(result->start_exec);
342 /************************************* Take Snapshot ************************************/
343 /****************************************************************************************/
345 /** \brief Checks whether the variable is in scope for a given IP.
347 * A variable may be defined only from a given value of IP.
349 * \param var Variable description
350 * \param frame Scope description
351 * \param ip Instruction pointer
352 * \return true if the variable is valid
354 static bool mc_valid_variable(dw_variable_t var, dw_frame_t scope,
357 // The variable is not yet valid:
358 if ((const void *) ((const char *) scope->low_pc + var->start_scope) > ip)
364 static void mc_fill_local_variables_values(mc_stack_frame_t stack_frame,
365 dw_frame_t scope, int process_index, xbt_dynar_t result)
367 mc_process_t process = &mc_model_checker->process;
369 void *ip = (void *) stack_frame->ip;
370 if (ip < scope->low_pc || ip >= scope->high_pc)
374 dw_variable_t current_variable;
375 xbt_dynar_foreach(scope->variables, cursor, current_variable) {
377 if (!mc_valid_variable(current_variable, scope, (void *) stack_frame->ip))
381 if ((long) stack_frame->ip > (long) process->libsimgrid_info->start_exec)
386 local_variable_t new_var = xbt_new0(s_local_variable_t, 1);
387 new_var->subprogram = stack_frame->frame;
388 new_var->ip = stack_frame->ip;
389 new_var->name = xbt_strdup(current_variable->name);
390 new_var->type = current_variable->type;
391 new_var->region = region_type;
393 if (current_variable->address != NULL) {
394 new_var->address = current_variable->address;
395 } else if (current_variable->locations.size != 0) {
396 s_mc_location_t location;
397 mc_dwarf_resolve_locations(&location, ¤t_variable->locations,
398 current_variable->object_info,
399 &(stack_frame->unw_cursor),
400 (void *) stack_frame->frame_base,
401 NULL, process_index);
403 switch(mc_get_location_type(&location)) {
404 case MC_LOCATION_TYPE_ADDRESS:
405 new_var->address = location.memory_location;
407 case MC_LOCATION_TYPE_REGISTER:
409 xbt_die("Cannot handle non-address variable");
413 xbt_die("No address");
416 xbt_dynar_push(result, &new_var);
419 // Recursive processing of nested scopes:
420 dw_frame_t nested_scope = NULL;
421 xbt_dynar_foreach(scope->scopes, cursor, nested_scope) {
422 mc_fill_local_variables_values(stack_frame, nested_scope, process_index, result);
426 static xbt_dynar_t MC_get_local_variables_values(xbt_dynar_t stack_frames, int process_index)
429 unsigned cursor1 = 0;
430 mc_stack_frame_t stack_frame;
431 xbt_dynar_t variables =
432 xbt_dynar_new(sizeof(local_variable_t), local_variable_free_voidp);
434 xbt_dynar_foreach(stack_frames, cursor1, stack_frame) {
435 mc_fill_local_variables_values(stack_frame, stack_frame->frame, process_index, variables);
441 static void MC_stack_frame_free_voipd(void *s)
443 mc_stack_frame_t stack_frame = *(mc_stack_frame_t *) s;
445 xbt_free(stack_frame->frame_name);
446 xbt_free(stack_frame);
450 static xbt_dynar_t MC_unwind_stack_frames(void *stack_context)
452 mc_process_t process = &mc_model_checker->process;
454 xbt_dynar_new(sizeof(mc_stack_frame_t), MC_stack_frame_free_voipd);
458 // TODO, check condition check (unw_init_local==0 means end of frame)
459 if (unw_init_local(&c, (unw_context_t *) stack_context) != 0) {
461 xbt_die("Could not initialize stack unwinding");
466 mc_stack_frame_t stack_frame = xbt_new(s_mc_stack_frame_t, 1);
467 xbt_dynar_push(result, &stack_frame);
469 stack_frame->unw_cursor = c;
473 unw_get_reg(&c, UNW_REG_IP, &ip);
474 unw_get_reg(&c, UNW_REG_SP, &sp);
476 stack_frame->ip = ip;
477 stack_frame->sp = sp;
479 // TODO, use real addresses in frame_t instead of fixing it here
481 dw_frame_t frame = MC_process_find_function(process, (void *) ip);
482 stack_frame->frame = frame;
485 stack_frame->frame_name = xbt_strdup(frame->name);
486 stack_frame->frame_base =
487 (unw_word_t) mc_find_frame_base(frame, frame->object_info, &c);
489 stack_frame->frame_base = 0;
490 stack_frame->frame_name = NULL;
493 /* Stop before context switch with maestro */
494 if (frame != NULL && frame->name != NULL
495 && !strcmp(frame->name, "smx_ctx_sysv_wrapper"))
498 int ret = ret = unw_step(&c);
500 xbt_die("Unexpected end of stack.");
501 } else if (ret < 0) {
502 xbt_die("Error while unwinding stack.");
506 if (xbt_dynar_length(result) == 0) {
507 XBT_INFO("unw_init_local failed");
514 static xbt_dynar_t MC_take_snapshot_stacks(mc_snapshot_t * snapshot)
518 xbt_dynar_new(sizeof(s_mc_snapshot_stack_t),
519 MC_snapshot_stack_free_voidp);
521 unsigned int cursor = 0;
522 stack_region_t current_stack;
524 xbt_dynar_foreach(stacks_areas, cursor, current_stack) {
525 mc_snapshot_stack_t st = xbt_new(s_mc_snapshot_stack_t, 1);
526 st->stack_frames = MC_unwind_stack_frames(current_stack->context);
527 st->local_variables = MC_get_local_variables_values(st->stack_frames, current_stack->process_index);
528 st->process_index = current_stack->process_index;
530 unw_word_t sp = xbt_dynar_get_as(st->stack_frames, 0, mc_stack_frame_t)->sp;
532 xbt_dynar_push(res, &st);
533 (*snapshot)->stack_sizes =
534 xbt_realloc((*snapshot)->stack_sizes, (cursor + 1) * sizeof(size_t));
535 (*snapshot)->stack_sizes[cursor] =
536 (char*) current_stack->address + current_stack->size - (char*) sp;
543 static xbt_dynar_t MC_take_snapshot_ignore()
546 if (mc_heap_comparison_ignore == NULL)
550 xbt_dynar_new(sizeof(mc_heap_ignore_region_t),
551 heap_ignore_region_free_voidp);
553 unsigned int cursor = 0;
554 mc_heap_ignore_region_t current_region;
556 xbt_dynar_foreach(mc_heap_comparison_ignore, cursor, current_region) {
557 mc_heap_ignore_region_t new_region = NULL;
558 new_region = xbt_new0(s_mc_heap_ignore_region_t, 1);
559 new_region->address = current_region->address;
560 new_region->size = current_region->size;
561 new_region->block = current_region->block;
562 new_region->fragment = current_region->fragment;
563 xbt_dynar_push(cpy, &new_region);
570 static void mc_free_snapshot_ignored_data_pvoid(void* data) {
571 mc_snapshot_ignored_data_t ignored_data = (mc_snapshot_ignored_data_t) data;
572 free(ignored_data->data);
575 static void MC_snapshot_handle_ignore(mc_snapshot_t snapshot)
577 xbt_assert(snapshot->process);
578 snapshot->ignored_data = xbt_dynar_new(sizeof(s_mc_snapshot_ignored_data_t), mc_free_snapshot_ignored_data_pvoid);
581 unsigned int cursor = 0;
582 mc_checkpoint_ignore_region_t region;
583 xbt_dynar_foreach (mc_checkpoint_ignore, cursor, region) {
584 s_mc_snapshot_ignored_data_t ignored_data;
585 ignored_data.start = region->addr;
586 ignored_data.size = region->size;
587 ignored_data.data = malloc(region->size);
588 // TODO, we should do this once per privatization segment:
589 MC_process_read(snapshot->process,
590 MC_ADDRESS_SPACE_READ_FLAGS_NONE,
591 ignored_data.data, region->addr, region->size, MC_PROCESS_INDEX_DISABLED);
592 xbt_dynar_push(snapshot->ignored_data, &ignored_data);
596 xbt_dynar_foreach (mc_checkpoint_ignore, cursor, region) {
597 MC_process_clear_memory(snapshot->process, region->addr, region->size);
602 static void MC_snapshot_ignore_restore(mc_snapshot_t snapshot)
604 unsigned int cursor = 0;
605 s_mc_snapshot_ignored_data_t ignored_data;
606 xbt_dynar_foreach (snapshot->ignored_data, cursor, ignored_data) {
607 MC_process_write(snapshot->process,
608 ignored_data.data, ignored_data.start, ignored_data.size);
612 /** @brief Can we remove this snapshot?
614 * Some snapshots cannot be removed (yet) because we need them
619 int mc_important_snapshot(mc_snapshot_t snapshot)
621 // We need this snapshot in order to know which
622 // pages needs to be stored in the next snapshot.
623 // This field is only non-NULL when using soft-dirty
625 if (snapshot == mc_model_checker->parent_snapshot)
631 static void MC_get_current_fd(mc_snapshot_t snapshot){
633 snapshot->total_fd = 0;
635 const size_t fd_dir_path_size = 20;
636 char fd_dir_path[fd_dir_path_size];
637 if (snprintf(fd_dir_path, fd_dir_path_size,
638 "/proc/%lli/fd", (long long int) getpid()) > fd_dir_path_size)
639 xbt_die("Unexpected buffer is too small for fd_dir_path");
641 DIR* fd_dir = opendir (fd_dir_path);
643 xbt_die("Cannot open directory '/proc/self/fd'\n");
646 struct dirent* fd_number;
647 while ((fd_number = readdir(fd_dir))) {
649 int fd_value = atoi(fd_number->d_name);
654 const size_t source_size = 25;
656 if (snprintf(source, source_size, "/proc/self/fd/%s", fd_number->d_name) > source_size)
657 xbt_die("Unexpected buffer is too small for fd %s", fd_number->d_name);
659 const size_t link_size = 200;
661 int res = readlink(source, link, link_size);
663 xbt_die("Could not read link for %s", source);
666 xbt_die("Buffer to small for link of %s", source);
670 if(smpi_is_privatisation_file(link))
673 // This is (probably) the DIR* we are reading:
674 // TODO, read all the file entries at once and close the DIR.*
675 if(strcmp(fd_dir_path, link) == 0)
678 // We don't handle them.
679 // It does not mean we should silently ignore them however.
680 if (strncmp(link, "pipe:", 5) == 0 || strncmp(link, "socket:", 7) == 0)
683 // This is probably a shared memory used by lttng-ust:
684 if(strncmp("/dev/shm/ust-shm-tmp-", link, 21)==0)
687 // Add an entry for this FD in the snapshot:
688 fd_infos_t fd = xbt_new0(s_fd_infos_t, 1);
689 fd->filename = strdup(link);
690 fd->number = fd_value;
691 fd->flags = fcntl(fd_value, F_GETFL) | fcntl(fd_value, F_GETFD) ;
692 fd->current_position = lseek(fd_value, 0, SEEK_CUR);
693 snapshot->current_fd = xbt_realloc(snapshot->current_fd, (total_fd + 1) * sizeof(fd_infos_t));
694 snapshot->current_fd[total_fd] = fd;
698 snapshot->total_fd = total_fd;
702 static s_mc_address_space_class_t mc_snapshot_class = {
703 .read = (void*) &MC_snapshot_read
706 mc_snapshot_t MC_take_snapshot(int num_state)
708 mc_process_t mc_process = &mc_model_checker->process;
709 mc_snapshot_t snapshot = xbt_new0(s_mc_snapshot_t, 1);
710 snapshot->process = mc_process;
711 snapshot->address_space.address_space_class = &mc_snapshot_class;
713 snapshot->enabled_processes = xbt_dynar_new(sizeof(int), NULL);
714 smx_process_t process;
715 xbt_swag_foreach(process, simix_global->process_list) {
716 xbt_dynar_push_as(snapshot->enabled_processes, int, (int)process->pid);
719 MC_snapshot_handle_ignore(snapshot);
721 MC_get_current_fd(snapshot);
723 const bool use_soft_dirty = _sg_mc_sparse_checkpoint
725 && MC_process_is_self(mc_process);
727 /* Save the std heap and the writable mapped pages of libsimgrid and binary */
728 MC_get_memory_regions(mc_process, snapshot);
730 mc_softdirty_reset();
732 snapshot->to_ignore = MC_take_snapshot_ignore();
734 if (_sg_mc_visited > 0 || strcmp(_sg_mc_property_file, "")) {
736 MC_take_snapshot_stacks(&snapshot);
737 if (_sg_mc_hash && snapshot->stacks != NULL) {
738 snapshot->hash = mc_hash_processes_state(num_state, snapshot->stacks);
746 MC_snapshot_ignore_restore(snapshot);
748 mc_model_checker->parent_snapshot = snapshot;
753 void MC_restore_snapshot_regions(mc_snapshot_t snapshot)
755 mc_snapshot_t parent_snapshot = mc_model_checker->parent_snapshot;
757 const size_t n = snapshot->snapshot_regions_count;
758 for (size_t i = 0; i < n; i++) {
759 // For privatized, variables we decided it was not necessary to take the snapshot:
760 if (snapshot->snapshot_regions[i])
761 MC_region_restore(snapshot->snapshot_regions[i],
762 parent_snapshot ? parent_snapshot->snapshot_regions[i] : NULL);
766 if(snapshot->privatization_index >= 0) {
767 // We just rewrote the global variables.
768 // The privatisation segment SMPI thinks
769 // is mapped might be inconsistent with the segment which
770 // is really mapped in memory (kernel state).
771 // We ask politely SMPI to map the segment anyway,
772 // even if it thinks it is the current one:
773 smpi_really_switch_data_segment(snapshot->privatization_index);
779 void MC_restore_snapshot_fds(mc_snapshot_t snapshot)
783 for(i=0; i < snapshot->total_fd; i++){
785 new_fd = open(snapshot->current_fd[i]->filename, snapshot->current_fd[i]->flags);
787 xbt_die("Could not reopen the file %s fo restoring the file descriptor",
788 snapshot->current_fd[i]->filename);
790 if(new_fd != -1 && new_fd != snapshot->current_fd[i]->number){
791 dup2(new_fd, snapshot->current_fd[i]->number);
792 //fprintf(stderr, "%p\n", fdopen(snapshot->current_fd[i]->number, "rw"));
795 lseek(snapshot->current_fd[i]->number, snapshot->current_fd[i]->current_position, SEEK_SET);
799 void MC_restore_snapshot(mc_snapshot_t snapshot)
801 const bool use_soft_dirty = _sg_mc_sparse_checkpoint
803 && MC_process_is_self(&mc_model_checker->process);
805 MC_restore_snapshot_regions(snapshot);
806 MC_restore_snapshot_fds(snapshot);
807 if (use_soft_dirty) {
808 mc_softdirty_reset();
810 MC_snapshot_ignore_restore(snapshot);
811 if (use_soft_dirty) {
812 mc_model_checker->parent_snapshot = snapshot;
815 mc_model_checker->process.cache_flags = 0;
818 mc_snapshot_t simcall_HANDLER_mc_snapshot(smx_simcall_t simcall)
820 return MC_take_snapshot(1);
823 void *MC_snapshot(void)
825 return simcall_mc_snapshot();