Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of git+ssh://scm.gforge.inria.fr//gitroot/simgrid/simgrid
[simgrid.git] / src / mc / mc_checkpoint.c
1 /* Copyright (c) 2008-2014. The SimGrid Team.
2  * All rights reserved.                                                     */
3
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. */
6
7 #define _GNU_SOURCE
8 #define UNW_LOCAL_ONLY
9
10
11 #include <string.h>
12 #include <link.h>
13
14 #include "internal_config.h"
15 #include "mc_private.h"
16 #include "xbt/module.h"
17 #include <xbt/mmalloc.h>
18 #include "../smpi/private.h"
19 #include <alloca.h>
20
21 #include "xbt/mmalloc/mmprivate.h"
22
23 #include "../simix/smx_private.h"
24
25 #include <libunwind.h>
26 #include <libelf.h>
27
28 #include "mc_private.h"
29 #include <mc/mc.h>
30
31 #include "mc_mmu.h"
32
33 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_checkpoint, mc,
34                                 "Logging specific to mc_checkpoint");
35
36 char *libsimgrid_path;
37
38 /************************************  Free functions **************************************/
39 /*****************************************************************************************/
40
41 static void MC_snapshot_stack_free(mc_snapshot_stack_t s)
42 {
43   if (s) {
44     xbt_dynar_free(&(s->local_variables));
45     xbt_dynar_free(&(s->stack_frames));
46     xbt_free(s);
47   }
48 }
49
50 static void MC_snapshot_stack_free_voidp(void *s)
51 {
52   MC_snapshot_stack_free((mc_snapshot_stack_t) * (void **) s);
53 }
54
55 static void local_variable_free(local_variable_t v)
56 {
57   xbt_free(v->name);
58   xbt_free(v);
59 }
60
61 static void local_variable_free_voidp(void *v)
62 {
63   local_variable_free((local_variable_t) * (void **) v);
64 }
65
66 void MC_region_destroy(mc_mem_region_t reg)
67 {
68   if (!reg)
69     return;
70
71   //munmap(reg->data, reg->size);
72   xbt_free(reg->data);
73   if (reg->page_numbers) {
74     mc_free_page_snapshot_region(reg->page_numbers, mc_page_count(reg->size));
75   }
76   xbt_free(reg);
77 }
78
79 void MC_free_snapshot(mc_snapshot_t snapshot)
80 {
81   unsigned int i;
82   for (i = 0; i < NB_REGIONS; i++) {
83     MC_region_destroy(snapshot->regions[i]);
84   }
85
86   xbt_free(snapshot->stack_sizes);
87   xbt_dynar_free(&(snapshot->stacks));
88   xbt_dynar_free(&(snapshot->to_ignore));
89   xbt_dynar_free(&snapshot->ignored_data);
90
91   if (snapshot->privatization_regions) {
92     size_t n = xbt_dynar_length(snapshot->enabled_processes);
93     for (i = 0; i != n; ++i) {
94       MC_region_destroy(snapshot->privatization_regions[i]);
95     }
96     xbt_free(snapshot->privatization_regions);
97   }
98
99   xbt_free(snapshot);
100 }
101
102 /*******************************  Snapshot regions ********************************/
103 /*********************************************************************************/
104
105   static mc_mem_region_t mc_region_new_dense(int type, void *start_addr, void* permanent_addr, size_t size, mc_mem_region_t ref_reg)
106 {
107   mc_mem_region_t new_reg = xbt_new(s_mc_mem_region_t, 1);
108   new_reg->start_addr = start_addr;
109   new_reg->permanent_addr = permanent_addr;
110   new_reg->data = NULL;
111   new_reg->size = size;
112   new_reg->page_numbers = NULL;
113   new_reg->data = xbt_malloc(size);
114   memcpy(new_reg->data, permanent_addr, size);
115   XBT_DEBUG("New region : type : %d, data : %p (real addr %p), size : %zu",
116             type, new_reg->data, permanent_addr, size);
117   return new_reg;
118
119 }
120
121 /** @brief Take a snapshot of a given region
122  *
123  * @param type
124  * @param start_addr   Address of the region in the simulated process
125  * @param permanent_addr Permanent address of this data (for privatized variables, this is the virtual address of the privatized mapping)
126  * @param size         Size of the data*
127  * @param ref_reg      Reference corresponding region
128  */
129 static mc_mem_region_t MC_region_new(int type, void *start_addr, void* permanent_addr, size_t size, mc_mem_region_t ref_reg)
130 {
131   if (_sg_mc_sparse_checkpoint) {
132     return mc_region_new_sparse(type, start_addr, permanent_addr, size, ref_reg);
133   } else  {
134     return mc_region_new_dense(type, start_addr, permanent_addr, size, ref_reg);
135   }
136 }
137
138 /** @brief Restore a region from a snapshot
139  *
140  *  If we are using per page snapshots, it is possible to use the reference
141  *  region in order to do an incremental restoration of the region: the
142  *  softclean pages which are shared between the two snapshots do not need
143  *  to be restored.
144  *
145  *  @param reg     Target region
146  *  @param reg_reg Current region (if not NULL), used for lazy per page restoration
147  */
148 static void MC_region_restore(mc_mem_region_t reg, mc_mem_region_t ref_reg)
149 {
150   /*FIXME: check if start_addr is still mapped, if it is not, then map it
151     before copying the data */
152   if (!reg->page_numbers) {
153     memcpy(reg->permanent_addr, reg->data, reg->size);
154   } else {
155     mc_region_restore_sparse(reg, ref_reg);
156   }
157   return;
158 }
159
160 static void MC_snapshot_add_region(mc_snapshot_t snapshot, int type,
161                                    void *start_addr, void* permanent_addr, size_t size)
162
163 {
164   mc_mem_region_t ref_reg =
165     mc_model_checker->parent_snapshot ? mc_model_checker->parent_snapshot->regions[type] : NULL;
166   mc_mem_region_t new_reg = MC_region_new(type, start_addr, permanent_addr, size, ref_reg);
167   snapshot->regions[type] = new_reg;
168   return;
169 }
170
171 static void MC_get_memory_regions(mc_snapshot_t snapshot)
172 {
173
174   void *start_heap = std_heap->base;
175   void *end_heap = std_heap->breakval;
176   MC_snapshot_add_region(snapshot, 0, start_heap, start_heap,
177                          (char *) end_heap - (char *) start_heap);
178   snapshot->heap_bytes_used = mmalloc_get_bytes_used(std_heap);
179   snapshot->privatization_regions = NULL;
180
181   MC_snapshot_add_region(snapshot, 1,
182       mc_libsimgrid_info->start_rw, mc_libsimgrid_info->start_rw,
183       mc_libsimgrid_info->end_rw - mc_libsimgrid_info->start_rw);
184
185 #ifdef HAVE_SMPI
186   size_t i;
187   if (smpi_privatize_global_variables && smpi_process_count()) {
188     // Snapshot the global variable of the application separately for each
189     // simulated process:
190     snapshot->privatization_regions =
191       xbt_new(mc_mem_region_t, smpi_process_count());
192     for (i = 0; i < smpi_process_count(); i++) {
193       mc_mem_region_t ref_reg =
194         mc_model_checker->parent_snapshot ? mc_model_checker->parent_snapshot->privatization_regions[i] : NULL;
195       snapshot->privatization_regions[i] =
196         MC_region_new(-1, mc_binary_info->start_rw, smpi_privatisation_regions[i].address, size_data_exe, ref_reg);
197     }
198     snapshot->privatization_index = smpi_loaded_page;
199     snapshot->regions[2] = NULL;
200   } else
201 #endif
202   {
203     MC_snapshot_add_region(snapshot, 2,
204                            mc_binary_info->start_rw, mc_binary_info->start_rw,
205                            mc_binary_info->end_rw - mc_binary_info->start_rw);
206     snapshot->privatization_regions = NULL;
207     snapshot->privatization_index = -1;
208   }
209 }
210
211 /** @brief Finds the range of the different memory segments and binary paths */
212 void MC_init_memory_map_info()
213 {
214
215   unsigned int i = 0;
216   s_map_region_t reg;
217   memory_map_t maps = MC_get_memory_map();
218
219   maestro_stack_start = NULL;
220   maestro_stack_end = NULL;
221   libsimgrid_path = NULL;
222
223   while (i < maps->mapsize) {
224     reg = maps->regions[i];
225     if (maps->regions[i].pathname == NULL) {
226       // Nothing to do
227     } else if ((reg.prot & PROT_WRITE)
228                && !memcmp(maps->regions[i].pathname, "[stack]", 7)) {
229       maestro_stack_start = reg.start_addr;
230       maestro_stack_end = reg.end_addr;
231     } else if ((reg.prot & PROT_READ) && (reg.prot & PROT_EXEC)
232                && !memcmp(basename(maps->regions[i].pathname), "libsimgrid",
233                           10)) {
234       if (libsimgrid_path == NULL)
235         libsimgrid_path = strdup(maps->regions[i].pathname);
236     }
237     i++;
238   }
239
240   xbt_assert(maestro_stack_start, "maestro_stack_start");
241   xbt_assert(maestro_stack_end, "maestro_stack_end");
242   xbt_assert(libsimgrid_path, "libsimgrid_path&");
243
244   MC_free_memory_map(maps);
245
246 }
247
248 /** \brief Fill/lookup the "subtype" field.
249  */
250 static void MC_resolve_subtype(mc_object_info_t info, dw_type_t type)
251 {
252
253   if (type->dw_type_id == NULL)
254     return;
255   type->subtype = xbt_dict_get_or_null(info->types, type->dw_type_id);
256   if (type->subtype == NULL)
257     return;
258   if (type->subtype->byte_size != 0)
259     return;
260   if (type->subtype->name == NULL)
261     return;
262   // Try to find a more complete description of the type:
263   // We need to fix in order to support C++.
264
265   dw_type_t subtype =
266       xbt_dict_get_or_null(info->full_types_by_name, type->subtype->name);
267   if (subtype != NULL) {
268     type->subtype = subtype;
269   }
270
271 }
272
273 void MC_post_process_types(mc_object_info_t info)
274 {
275   xbt_dict_cursor_t cursor = NULL;
276   char *origin;
277   dw_type_t type;
278
279   // Lookup "subtype" field:
280   xbt_dict_foreach(info->types, cursor, origin, type) {
281     MC_resolve_subtype(info, type);
282
283     dw_type_t member;
284     unsigned int i = 0;
285     if (type->members != NULL)
286       xbt_dynar_foreach(type->members, i, member) {
287       MC_resolve_subtype(info, member);
288       }
289   }
290 }
291
292 /** \brief Fills the position of the segments (executable, read-only, read/write).
293  *
294  * TODO, use dl_iterate_phdr to be more robust
295  * */
296 void MC_find_object_address(memory_map_t maps, mc_object_info_t result)
297 {
298
299   unsigned int i = 0;
300   s_map_region_t reg;
301   const char *name = basename(result->file_name);
302   while (i < maps->mapsize) {
303     reg = maps->regions[i];
304     if (maps->regions[i].pathname == NULL
305         || strcmp(basename(maps->regions[i].pathname), name)) {
306       // Nothing to do
307     } else if ((reg.prot & PROT_WRITE)) {
308       xbt_assert(!result->start_rw,
309                  "Multiple read-write segments for %s, not supported",
310                  maps->regions[i].pathname);
311       result->start_rw = reg.start_addr;
312       result->end_rw = reg.end_addr;
313       // .bss is usually after the .data:
314       s_map_region_t *next = &(maps->regions[i + 1]);
315       if (next->pathname == NULL && (next->prot & PROT_WRITE)
316           && next->start_addr == reg.end_addr) {
317         result->end_rw = maps->regions[i + 1].end_addr;
318       }
319     } else if ((reg.prot & PROT_READ) && (reg.prot & PROT_EXEC)) {
320       xbt_assert(!result->start_exec,
321                  "Multiple executable segments for %s, not supported",
322                  maps->regions[i].pathname);
323       result->start_exec = reg.start_addr;
324       result->end_exec = reg.end_addr;
325     } else if ((reg.prot & PROT_READ) && !(reg.prot & PROT_EXEC)) {
326       xbt_assert(!result->start_ro,
327                  "Multiple read only segments for %s, not supported",
328                  maps->regions[i].pathname);
329       result->start_ro = reg.start_addr;
330       result->end_ro = reg.end_addr;
331     }
332     i++;
333   }
334
335   xbt_assert(result->file_name);
336   xbt_assert(result->start_rw);
337   xbt_assert(result->start_exec);
338 }
339
340 /************************************* Take Snapshot ************************************/
341 /****************************************************************************************/
342
343 /** \brief Checks whether the variable is in scope for a given IP.
344  *
345  *  A variable may be defined only from a given value of IP.
346  *
347  *  \param var   Variable description
348  *  \param frame Scope description
349  *  \param ip    Instruction pointer
350  *  \return      true if the variable is valid
351  * */
352 static bool mc_valid_variable(dw_variable_t var, dw_frame_t scope,
353                               const void *ip)
354 {
355   // The variable is not yet valid:
356   if ((const void *) ((const char *) scope->low_pc + var->start_scope) > ip)
357     return false;
358   else
359     return true;
360 }
361
362 static void mc_fill_local_variables_values(mc_stack_frame_t stack_frame,
363                                            dw_frame_t scope, int process_index, xbt_dynar_t result)
364 {
365   void *ip = (void *) stack_frame->ip;
366   if (ip < scope->low_pc || ip >= scope->high_pc)
367     return;
368
369   unsigned cursor = 0;
370   dw_variable_t current_variable;
371   xbt_dynar_foreach(scope->variables, cursor, current_variable) {
372
373     if (!mc_valid_variable(current_variable, scope, (void *) stack_frame->ip))
374       continue;
375
376     int region_type;
377     if ((long) stack_frame->ip > (long) mc_libsimgrid_info->start_exec)
378       region_type = 1;
379     else
380       region_type = 2;
381
382     local_variable_t new_var = xbt_new0(s_local_variable_t, 1);
383     new_var->subprogram = stack_frame->frame;
384     new_var->ip = stack_frame->ip;
385     new_var->name = xbt_strdup(current_variable->name);
386     new_var->type = current_variable->type;
387     new_var->region = region_type;
388
389     if (current_variable->address != NULL) {
390       new_var->address = current_variable->address;
391     } else if (current_variable->locations.size != 0) {
392       s_mc_location_t location;
393       mc_dwarf_resolve_locations(&location, &current_variable->locations,
394                                               current_variable->object_info,
395                                               &(stack_frame->unw_cursor),
396                                               (void *) stack_frame->frame_base,
397                                               NULL, process_index);
398
399       switch(mc_get_location_type(&location)) {
400       case MC_LOCATION_TYPE_ADDRESS:
401         new_var->address = location.memory_location;
402         break;
403       case MC_LOCATION_TYPE_REGISTER:
404       default:
405         xbt_die("Cannot handle non-address variable");
406       }
407
408     } else {
409       xbt_die("No address");
410     }
411
412     xbt_dynar_push(result, &new_var);
413   }
414
415   // Recursive processing of nested scopes:
416   dw_frame_t nested_scope = NULL;
417   xbt_dynar_foreach(scope->scopes, cursor, nested_scope) {
418     mc_fill_local_variables_values(stack_frame, nested_scope, process_index, result);
419   }
420 }
421
422 static xbt_dynar_t MC_get_local_variables_values(xbt_dynar_t stack_frames, int process_index)
423 {
424
425   unsigned cursor1 = 0;
426   mc_stack_frame_t stack_frame;
427   xbt_dynar_t variables =
428       xbt_dynar_new(sizeof(local_variable_t), local_variable_free_voidp);
429
430   xbt_dynar_foreach(stack_frames, cursor1, stack_frame) {
431     mc_fill_local_variables_values(stack_frame, stack_frame->frame, process_index, variables);
432   }
433
434   return variables;
435 }
436
437 static void MC_stack_frame_free_voipd(void *s)
438 {
439   mc_stack_frame_t stack_frame = *(mc_stack_frame_t *) s;
440   if (stack_frame) {
441     xbt_free(stack_frame->frame_name);
442     xbt_free(stack_frame);
443   }
444 }
445
446 static xbt_dynar_t MC_unwind_stack_frames(void *stack_context)
447 {
448   xbt_dynar_t result =
449       xbt_dynar_new(sizeof(mc_stack_frame_t), MC_stack_frame_free_voipd);
450
451   unw_cursor_t c;
452
453   // TODO, check condition check (unw_init_local==0 means end of frame)
454   if (unw_init_local(&c, (unw_context_t *) stack_context) != 0) {
455
456     xbt_die("Could not initialize stack unwinding");
457
458   } else
459     while (1) {
460
461       mc_stack_frame_t stack_frame = xbt_new(s_mc_stack_frame_t, 1);
462       xbt_dynar_push(result, &stack_frame);
463
464       stack_frame->unw_cursor = c;
465
466       unw_word_t ip, sp;
467
468       unw_get_reg(&c, UNW_REG_IP, &ip);
469       unw_get_reg(&c, UNW_REG_SP, &sp);
470
471       stack_frame->ip = ip;
472       stack_frame->sp = sp;
473
474       // TODO, use real addresses in frame_t instead of fixing it here
475
476       dw_frame_t frame = MC_find_function_by_ip((void *) ip);
477       stack_frame->frame = frame;
478
479       if (frame) {
480         stack_frame->frame_name = xbt_strdup(frame->name);
481         stack_frame->frame_base =
482             (unw_word_t) mc_find_frame_base(frame, frame->object_info, &c);
483       } else {
484         stack_frame->frame_base = 0;
485         stack_frame->frame_name = NULL;
486       }
487
488       /* Stop before context switch with maestro */
489       if (frame != NULL && frame->name != NULL
490           && !strcmp(frame->name, "smx_ctx_sysv_wrapper"))
491         break;
492
493       int ret = ret = unw_step(&c);
494       if (ret == 0) {
495         xbt_die("Unexpected end of stack.");
496       } else if (ret < 0) {
497         xbt_die("Error while unwinding stack.");
498       }
499     }
500
501   if (xbt_dynar_length(result) == 0) {
502     XBT_INFO("unw_init_local failed");
503     xbt_abort();
504   }
505
506   return result;
507 };
508
509 static xbt_dynar_t MC_take_snapshot_stacks(mc_snapshot_t * snapshot)
510 {
511
512   xbt_dynar_t res =
513       xbt_dynar_new(sizeof(s_mc_snapshot_stack_t),
514                     MC_snapshot_stack_free_voidp);
515
516   unsigned int cursor = 0;
517   stack_region_t current_stack;
518
519   xbt_dynar_foreach(stacks_areas, cursor, current_stack) {
520     mc_snapshot_stack_t st = xbt_new(s_mc_snapshot_stack_t, 1);
521     st->stack_frames = MC_unwind_stack_frames(current_stack->context);
522     st->local_variables = MC_get_local_variables_values(st->stack_frames, current_stack->process_index);
523     st->process_index = current_stack->process_index;
524
525     unw_word_t sp = xbt_dynar_get_as(st->stack_frames, 0, mc_stack_frame_t)->sp;
526
527     xbt_dynar_push(res, &st);
528     (*snapshot)->stack_sizes =
529         xbt_realloc((*snapshot)->stack_sizes, (cursor + 1) * sizeof(size_t));
530     (*snapshot)->stack_sizes[cursor] =
531       (char*) current_stack->address + current_stack->size - (char*) sp;
532   }
533
534   return res;
535
536 }
537
538 static xbt_dynar_t MC_take_snapshot_ignore()
539 {
540
541   if (mc_heap_comparison_ignore == NULL)
542     return NULL;
543
544   xbt_dynar_t cpy =
545       xbt_dynar_new(sizeof(mc_heap_ignore_region_t),
546                     heap_ignore_region_free_voidp);
547
548   unsigned int cursor = 0;
549   mc_heap_ignore_region_t current_region;
550
551   xbt_dynar_foreach(mc_heap_comparison_ignore, cursor, current_region) {
552     mc_heap_ignore_region_t new_region = NULL;
553     new_region = xbt_new0(s_mc_heap_ignore_region_t, 1);
554     new_region->address = current_region->address;
555     new_region->size = current_region->size;
556     new_region->block = current_region->block;
557     new_region->fragment = current_region->fragment;
558     xbt_dynar_push(cpy, &new_region);
559   }
560
561   return cpy;
562
563 }
564
565 static void mc_free_snapshot_ignored_data_pvoid(void* data) {
566   mc_snapshot_ignored_data_t ignored_data = (mc_snapshot_ignored_data_t) data;
567   free(ignored_data->data);
568 }
569
570 static void MC_snapshot_handle_ignore(mc_snapshot_t snapshot)
571 {
572   snapshot->ignored_data = xbt_dynar_new(sizeof(s_mc_snapshot_ignored_data_t), mc_free_snapshot_ignored_data_pvoid);
573
574   // Copy the memory:
575   unsigned int cursor = 0;
576   mc_checkpoint_ignore_region_t region;
577   xbt_dynar_foreach (mc_checkpoint_ignore, cursor, region) {
578     s_mc_snapshot_ignored_data_t ignored_data;
579     ignored_data.start = region->addr;
580     ignored_data.size = region->size;
581     ignored_data.data = malloc(region->size);
582     memcpy(ignored_data.data, region->addr, region->size);
583     xbt_dynar_push(snapshot->ignored_data, &ignored_data);
584   }
585
586   // Zero the memory:
587   xbt_dynar_foreach (mc_checkpoint_ignore, cursor, region) {
588     memset(region->addr, 0, region->size);
589   }
590
591 }
592
593 static void MC_snapshot_ignore_restore(mc_snapshot_t snapshot)
594 {
595   unsigned int cursor = 0;
596   s_mc_snapshot_ignored_data_t ignored_data;
597   xbt_dynar_foreach (snapshot->ignored_data, cursor, ignored_data) {
598     memcpy(ignored_data.start, ignored_data.data, ignored_data.size);
599   }
600 }
601
602 /** @brief Can we remove this snapshot?
603  *
604  * Some snapshots cannot be removed (yet) because we need them
605  * at this point.
606  *
607  * @param snapshot
608  */
609 int mc_important_snapshot(mc_snapshot_t snapshot)
610 {
611   // We need this snapshot in order to know which
612   // pages needs to be stored in the next snapshot:
613   if (snapshot == mc_model_checker->parent_snapshot)
614     return true;
615
616   return false;
617 }
618
619 mc_snapshot_t MC_take_snapshot(int num_state)
620 {
621
622   mc_snapshot_t snapshot = xbt_new0(s_mc_snapshot_t, 1);
623   snapshot->enabled_processes = xbt_dynar_new(sizeof(int), NULL);
624   smx_process_t process;
625   xbt_swag_foreach(process, simix_global->process_list) {
626     xbt_dynar_push_as(snapshot->enabled_processes, int, (int)process->pid);
627   }
628
629   MC_snapshot_handle_ignore(snapshot);
630
631   /* Save the std heap and the writable mapped pages of libsimgrid and binary */
632   MC_get_memory_regions(snapshot);
633   if (_sg_mc_sparse_checkpoint && _sg_mc_soft_dirty) {
634     mc_softdirty_reset();
635   }
636
637   snapshot->to_ignore = MC_take_snapshot_ignore();
638
639   if (_sg_mc_visited > 0 || strcmp(_sg_mc_property_file, "")) {
640     snapshot->stacks =
641         MC_take_snapshot_stacks(&snapshot);
642     if (_sg_mc_hash && snapshot->stacks != NULL) {
643       snapshot->hash = mc_hash_processes_state(num_state, snapshot->stacks);
644     } else {
645       snapshot->hash = 0;
646     }
647   } else {
648     snapshot->hash = 0;
649   }
650
651   MC_snapshot_ignore_restore(snapshot);
652   if (_sg_mc_sparse_checkpoint && _sg_mc_soft_dirty) {
653     mc_model_checker->parent_snapshot = snapshot;
654   }
655   return snapshot;
656 }
657
658 void MC_restore_snapshot(mc_snapshot_t snapshot)
659 {
660   mc_snapshot_t parent_snapshot = mc_model_checker->parent_snapshot;
661
662   unsigned int i;
663   for (i = 0; i < NB_REGIONS; i++) {
664     // For privatized, variables we decided it was not necessary to take the snapshot:
665     if (snapshot->regions[i])
666       MC_region_restore(snapshot->regions[i],
667         parent_snapshot ? parent_snapshot->regions[i] : NULL);
668   }
669
670 #ifdef HAVE_SMPI
671   if (snapshot->privatization_regions) {
672     // Restore the global variables of the application separately for each
673     // simulated process:
674     for (i = 0; i < smpi_process_count(); i++) {
675       if (snapshot->privatization_regions[i]) {
676         MC_region_restore(snapshot->privatization_regions[i],
677           parent_snapshot ? parent_snapshot->privatization_regions[i] : NULL);
678       }
679     }
680   }
681   if(snapshot->privatization_index >= 0) {
682     smpi_switch_data_segment(snapshot->privatization_index);
683   }
684 #endif
685
686   if (_sg_mc_sparse_checkpoint && _sg_mc_soft_dirty) {
687     mc_softdirty_reset();
688   }
689
690   MC_snapshot_ignore_restore(snapshot);
691   if (_sg_mc_sparse_checkpoint && _sg_mc_soft_dirty) {
692     mc_model_checker->parent_snapshot = snapshot;
693   }
694 }
695
696 mc_snapshot_t SIMIX_pre_mc_snapshot(smx_simcall_t simcall)
697 {
698   return MC_take_snapshot(1);
699 }
700
701 void *MC_snapshot(void)
702 {
703   return simcall_mc_snapshot();
704 }