Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
d816cdb70ae2b0d8cd87dab77a0fc054ebdc256f
[simgrid.git] / src / mc / mc_checkpoint.c
1 /* Copyright (c) 2008-2012 Da SimGrid Team. All rights reserved.            */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #include <libgen.h>
7 #include "mc_private.h"
8 #include "xbt/module.h"
9
10 #include "../simix/smx_private.h"
11
12 #include <libunwind.h>
13
14 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_checkpoint, mc,
15                                 "Logging specific to mc_checkpoint");
16
17 void *start_text_libsimgrid;
18 void *start_plt_libsimgrid, *end_plt_libsimgrid;
19 void *start_plt_binary, *end_plt_binary;
20 char *libsimgrid_path;
21 void *start_data_libsimgrid, *start_bss_libsimgrid;
22 void *start_data_binary, *start_bss_binary;
23 void *start_text_binary;
24 void *end_raw_heap;
25
26 static mc_mem_region_t MC_region_new(int type, void *start_addr, size_t size);
27 static void MC_region_restore(mc_mem_region_t reg);
28 static void MC_region_destroy(mc_mem_region_t reg);
29
30 static void MC_snapshot_add_region(mc_snapshot_t snapshot, int type, void *start_addr, size_t size);
31
32 static void add_value(xbt_dynar_t *list, const char *type, unsigned long int val);
33 static xbt_dynar_t take_snapshot_stacks(void *heap);
34 static xbt_strbuff_t get_local_variables_values(void *stack_context, void *heap);
35 static void print_local_variables_values(xbt_dynar_t all_variables);
36 static void *get_stack_pointer(void *stack_context, void *heap);
37
38 static void snapshot_stack_free(mc_snapshot_stack_t s);
39
40 static mc_mem_region_t MC_region_new(int type, void *start_addr, size_t size)
41 {
42   mc_mem_region_t new_reg = xbt_new0(s_mc_mem_region_t, 1);
43   new_reg->type = type;
44   new_reg->start_addr = start_addr;
45   new_reg->size = size;
46   new_reg->data = xbt_malloc0(size);
47   memcpy(new_reg->data, start_addr, size);
48
49   XBT_DEBUG("New region : type : %d, data : %p, size : %zu", type, new_reg->data, size);
50   
51   return new_reg;
52 }
53
54 static void MC_region_restore(mc_mem_region_t reg)
55 {
56   /*FIXME: check if start_addr is still mapped, if it is not, then map it
57     before copying the data */
58  
59   memcpy(reg->start_addr, reg->data, reg->size);
60  
61   return;
62 }
63
64 static void MC_region_destroy(mc_mem_region_t reg)
65 {
66   xbt_free(reg->data);
67   xbt_free(reg);
68 }
69
70 static void MC_snapshot_add_region(mc_snapshot_t snapshot, int type, void *start_addr, size_t size)
71 {
72   mc_mem_region_t new_reg = MC_region_new(type, start_addr, size);
73   snapshot->regions = xbt_realloc(snapshot->regions, (snapshot->num_reg + 1) * sizeof(mc_mem_region_t));
74   snapshot->regions[snapshot->num_reg] = new_reg;
75   snapshot->num_reg++;
76   return;
77
78
79 /* void MC_take_snapshot(mc_snapshot_t snapshot) */
80 /* { */
81 /*   unsigned int i = 0; */
82 /*   s_map_region_t reg; */
83 /*   memory_map_t maps = get_memory_map(); */
84
85 /*   /\* Save the std heap and the writable mapped pages of libsimgrid *\/ */
86 /*   while (i < maps->mapsize) { */
87 /*     reg = maps->regions[i]; */
88 /*     if ((reg.prot & PROT_WRITE)){ */
89 /*       if (maps->regions[i].pathname == NULL){ */
90 /*         if (reg.start_addr == std_heap){ // only save the std heap (and not the raw one) */
91 /*           MC_snapshot_add_region(snapshot, 0, reg.start_addr, (char*)reg.end_addr - (char*)reg.start_addr); */
92 /*         } */
93 /*         i++; */
94 /*       } else { */
95 /*         if (!memcmp(basename(maps->regions[i].pathname), "libsimgrid", 10)){ */
96 /*           MC_snapshot_add_region(snapshot, 1, reg.start_addr, (char*)reg.end_addr - (char*)reg.start_addr); */
97 /*           i++; */
98 /*           reg = maps->regions[i]; */
99 /*           while(reg.pathname == NULL && (reg.prot & PROT_WRITE) && i < maps->mapsize){ */
100 /*             MC_snapshot_add_region(snapshot, 1, reg.start_addr, (char*)reg.end_addr - (char*)reg.start_addr); */
101 /*             i++; */
102 /*             reg = maps->regions[i]; */
103 /*           } */
104 /*         }else{ */
105 /*           i++; */
106 /*         }  */
107 /*       } */
108 /*     }else{ */
109 /*       i++; */
110 /*     } */
111 /*   } */
112
113 /*   free_memory_map(maps); */
114 /* } */
115
116 void MC_init_memory_map_info(){
117
118   int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
119
120   MC_SET_RAW_MEM;
121   
122   unsigned int i = 0;
123   s_map_region_t reg;
124   memory_map_t maps = get_memory_map();
125
126   while (i < maps->mapsize) {
127     reg = maps->regions[i];
128     if ((reg.prot & PROT_WRITE)){
129       if (maps->regions[i].pathname == NULL){
130         if(reg.start_addr == raw_heap){
131           end_raw_heap = reg.end_addr;
132         }
133       } else {
134         if (!memcmp(basename(maps->regions[i].pathname), "libsimgrid", 10)){
135           start_data_libsimgrid = reg.start_addr;
136           i++;
137           reg = maps->regions[i];
138           if(reg.pathname == NULL && (reg.prot & PROT_WRITE) && i < maps->mapsize)
139             start_bss_libsimgrid = reg.start_addr;
140         }else if (!memcmp(basename(maps->regions[i].pathname), basename(xbt_binary_name), strlen(basename(xbt_binary_name)))){
141           start_data_binary = reg.start_addr;
142           i++;
143           reg = maps->regions[i];
144           if(reg.pathname == NULL && (reg.prot & PROT_WRITE) && reg.start_addr != std_heap && reg.start_addr != raw_heap && i < maps->mapsize){
145             start_bss_binary = reg.start_addr;
146             i++;
147           }
148         }
149       }
150     }else if ((reg.prot & PROT_READ)){
151       if (maps->regions[i].pathname != NULL){
152         if (!memcmp(basename(maps->regions[i].pathname), "libsimgrid", 10)){
153           start_text_libsimgrid = reg.start_addr;
154           libsimgrid_path = strdup(maps->regions[i].pathname);
155         }else{
156           if (!memcmp(basename(maps->regions[i].pathname), basename(xbt_binary_name), strlen(basename(xbt_binary_name)))){
157             start_text_binary = reg.start_addr;
158           }
159         }
160       }
161     }
162     i++;
163   }
164   
165   free_memory_map(maps);
166
167   MC_UNSET_RAW_MEM;
168
169   if(raw_mem_set)
170     MC_SET_RAW_MEM;
171
172 }
173
174 mc_snapshot_t MC_take_snapshot()
175 {
176
177   int raw_mem = (mmalloc_get_current_heap() == raw_heap);
178   
179   MC_SET_RAW_MEM;
180
181   mc_snapshot_t snapshot = xbt_new0(s_mc_snapshot_t, 1);
182
183   unsigned int i = 0;
184   s_map_region_t reg;
185   memory_map_t maps = get_memory_map();
186   int nb_reg = 0;
187   void *heap = NULL;
188
189   /* Save the std heap and the writable mapped pages of libsimgrid */
190   while (i < maps->mapsize) {
191     reg = maps->regions[i];
192     if ((reg.prot & PROT_WRITE)){
193       if (maps->regions[i].pathname == NULL){
194         if (reg.start_addr == std_heap){ // only save the std heap (and not the raw one)
195           MC_snapshot_add_region(snapshot, 0, reg.start_addr, (char*)reg.end_addr - (char*)reg.start_addr);
196           heap = snapshot->regions[nb_reg]->data;
197           nb_reg++;
198         }else if(reg.start_addr == raw_heap){
199           end_raw_heap = reg.end_addr;
200         }
201         i++;
202       } else {
203         if (!memcmp(basename(maps->regions[i].pathname), "libsimgrid", 10)){
204           MC_snapshot_add_region(snapshot, 1, reg.start_addr, (char*)reg.end_addr - (char*)reg.start_addr);
205           start_data_libsimgrid = reg.start_addr;
206           nb_reg++;
207           i++;
208           reg = maps->regions[i];
209           if(reg.pathname == NULL && (reg.prot & PROT_WRITE) && i < maps->mapsize){
210             MC_snapshot_add_region(snapshot, 1, reg.start_addr, (char*)reg.end_addr - (char*)reg.start_addr);
211             reg = maps->regions[i];
212             i++;
213             nb_reg++;
214           }
215         } else {
216           if (!memcmp(basename(maps->regions[i].pathname), basename(xbt_binary_name), strlen(basename(xbt_binary_name)))){
217             MC_snapshot_add_region(snapshot, 2, reg.start_addr, (char*)reg.end_addr - (char*)reg.start_addr);
218             nb_reg++;
219             i++;
220             reg = maps->regions[i];
221             if(reg.pathname == NULL && (reg.prot & PROT_WRITE) && reg.start_addr != std_heap && reg.start_addr != raw_heap && i < maps->mapsize){
222               MC_snapshot_add_region(snapshot, 2, reg.start_addr, (char*)reg.end_addr - (char*)reg.start_addr);
223               reg = maps->regions[i];
224               nb_reg++;
225             }
226           }else{
227             i++;
228           }
229         }
230       }
231     }else if ((reg.prot & PROT_READ)){
232       if (maps->regions[i].pathname != NULL){
233         if (!memcmp(basename(maps->regions[i].pathname), "libsimgrid", 10)){
234           start_text_libsimgrid = reg.start_addr;
235           libsimgrid_path = strdup(maps->regions[i].pathname);
236         }else{
237           if (!memcmp(basename(maps->regions[i].pathname), basename(xbt_binary_name), strlen(basename(xbt_binary_name)))){
238             start_text_binary = reg.start_addr;
239           }
240         }
241       }
242       i++;
243     }else{
244       i++;
245     }
246   }
247
248   if(_surf_mc_stateful > 0 || _surf_mc_property_file)
249     snapshot->stacks = take_snapshot_stacks(heap);
250   
251   free_memory_map(maps);
252
253   MC_UNSET_RAW_MEM;
254
255   if(raw_mem)
256     MC_SET_RAW_MEM;
257
258   return snapshot;
259
260 }
261
262 void MC_restore_snapshot(mc_snapshot_t snapshot)
263 {
264   unsigned int i;
265   for(i=0; i < snapshot->num_reg; i++){
266     MC_region_restore(snapshot->regions[i]);
267   }
268
269 }
270
271 void MC_free_snapshot(mc_snapshot_t snapshot)
272 {
273   unsigned int i;
274   for(i=0; i < snapshot->num_reg; i++)
275     MC_region_destroy(snapshot->regions[i]);
276
277   xbt_dynar_free(&(snapshot->stacks));
278   xbt_free(snapshot);
279 }
280
281
282 void get_libsimgrid_plt_section(){
283
284   FILE *fp;
285   char *line = NULL;            /* Temporal storage for each line that is readed */
286   ssize_t read;                 /* Number of bytes readed */
287   size_t n = 0;                 /* Amount of bytes to read by getline */
288
289   char *lfields[7];
290   int i, plt_not_found = 1;
291   unsigned long int size, offset;
292
293   if(libsimgrid_path == NULL)
294     libsimgrid_path = get_libsimgrid_path();
295
296   char *command = bprintf("objdump --section-headers %s", libsimgrid_path);
297
298   fp = popen(command, "r");
299
300   if(fp == NULL)
301     perror("popen failed");
302
303   while ((read = getline(&line, &n, fp)) != -1 && plt_not_found == 1) {
304
305     if(n == 0)
306       continue;
307
308     /* Wipeout the new line character */
309     line[read - 1] = '\0';
310
311     lfields[0] = strtok(line, " ");
312
313     if(lfields[0] == NULL)
314       continue;
315
316     if(strcmp(lfields[0], "Sections:") == 0 || strcmp(lfields[0], "Idx") == 0 || strncmp(lfields[0], libsimgrid_path, strlen(libsimgrid_path)) == 0)
317       continue;
318
319     for (i = 1; i < 7 && lfields[i - 1] != NULL; i++) {
320       lfields[i] = strtok(NULL, " ");
321     }
322
323     if(i>=6){
324       if(strcmp(lfields[1], ".plt") == 0){
325         size = strtoul(lfields[2], NULL, 16);
326         offset = strtoul(lfields[5], NULL, 16);
327         start_plt_libsimgrid = (char *)start_text_libsimgrid + offset;
328         end_plt_libsimgrid = (char *)start_plt_libsimgrid + size;
329         plt_not_found = 0;
330       }
331     }
332     
333   }
334
335   free(command);
336   free(line);
337   pclose(fp);
338
339 }
340
341 void get_binary_plt_section(){
342
343   FILE *fp;
344   char *line = NULL;            /* Temporal storage for each line that is readed */
345   ssize_t read;                 /* Number of bytes readed */
346   size_t n = 0;                 /* Amount of bytes to read by getline */
347
348   char *lfields[7];
349   int i, plt_not_found = 1;
350   unsigned long int size, offset;
351
352   char *command = bprintf( "objdump --section-headers %s", xbt_binary_name);
353
354   fp = popen(command, "r");
355
356   if(fp == NULL)
357     perror("popen failed");
358
359   while ((read = getline(&line, &n, fp)) != -1 && plt_not_found == 1) {
360
361     if(n == 0)
362       continue;
363
364     /* Wipeout the new line character */
365     line[read - 1] = '\0';
366
367     lfields[0] = strtok(line, " ");
368
369     if(lfields[0] == NULL)
370       continue;
371
372     if(strcmp(lfields[0], "Sections:") == 0 || strcmp(lfields[0], "Idx") == 0 || strncmp(lfields[0], basename(xbt_binary_name), strlen(xbt_binary_name)) == 0)
373       continue;
374
375     for (i = 1; i < 7 && lfields[i - 1] != NULL; i++) {
376       lfields[i] = strtok(NULL, " ");
377     }
378
379     if(i>=6){
380       if(strcmp(lfields[1], ".plt") == 0){
381         size = strtoul(lfields[2], NULL, 16);
382         offset = strtoul(lfields[5], NULL, 16);
383         start_plt_binary = (char *)start_text_binary + offset;
384         end_plt_binary = (char *)start_plt_binary + size;
385         plt_not_found = 0;
386       }
387     }
388     
389     
390   }
391
392   free(command);
393   free(line);
394   pclose(fp);
395
396 }
397
398 static void add_value(xbt_dynar_t *list, const char *type, unsigned long int val){
399   variable_value_t value = xbt_new0(s_variable_value_t, 1);
400   value->type = strdup(type);
401   if(strcmp(type, "value") == 0){
402     value->value.res = val;
403   }else{
404     value->value.address = (void *)val;
405   }
406   xbt_dynar_push(*list, &value);
407 }
408
409 static xbt_dynar_t take_snapshot_stacks(void *heap){
410
411   xbt_dynar_t res = xbt_dynar_new(sizeof(s_mc_snapshot_stack_t), NULL);
412
413   unsigned int cursor1 = 0;
414   stack_region_t current_stack;
415   
416   xbt_dynar_foreach(stacks_areas, cursor1, current_stack){
417     mc_snapshot_stack_t st = xbt_new(s_mc_snapshot_stack_t, 1);
418     st->local_variables = get_local_variables_values(current_stack->context, heap);
419     st->stack_pointer = get_stack_pointer(current_stack->context, heap);
420     xbt_dynar_push(res, &st);
421   }
422
423   return res;
424
425 }
426
427 static void *get_stack_pointer(void *stack_context, void *heap){
428
429   unw_cursor_t c;
430   int ret;
431   unw_word_t sp;
432
433   ret = unw_init_local(&c, (unw_context_t *)stack_context);
434   if(ret < 0){
435     XBT_INFO("unw_init_local failed");
436     xbt_abort();
437   }
438
439   unw_get_reg(&c, UNW_REG_SP, &sp);
440
441   return ((char *)heap + (size_t)(((char *)((long)sp) - (char*)std_heap)));
442
443 }
444
445 static xbt_strbuff_t get_local_variables_values(void *stack_context, void *heap){
446   
447   unw_cursor_t c;
448   int ret;
449   //char *stack_name;
450
451   char frame_name[256];
452   
453   ret = unw_init_local(&c, (unw_context_t *)stack_context);
454   if(ret < 0){
455     XBT_INFO("unw_init_local failed");
456     xbt_abort();
457   }
458
459   //stack_name = strdup(((smx_process_t)((smx_ctx_sysv_t)(stack->address))->super.data)->name);
460
461   unw_word_t ip, sp, off;
462   dw_frame_t frame;
463  
464   xbt_dynar_t compose = xbt_dynar_new(sizeof(variable_value_t), NULL);
465
466   xbt_strbuff_t variables = xbt_strbuff_new();
467   xbt_dict_cursor_t dict_cursor;
468   char *variable_name;
469   dw_local_variable_t current_variable;
470   unsigned int cursor = 0, cursor2 = 0;
471   dw_location_entry_t entry = NULL;
472   dw_location_t location_entry = NULL;
473   unw_word_t res;
474   int frame_found = 0;
475   void *frame_pointer_address = NULL;
476   long true_ip;
477
478   while(ret >= 0){
479
480     unw_get_reg(&c, UNW_REG_IP, &ip);
481     unw_get_reg(&c, UNW_REG_SP, &sp);
482
483     unw_get_proc_name (&c, frame_name, sizeof (frame_name), &off);
484
485     xbt_strbuff_append(variables, bprintf("ip=%s\n", frame_name));
486
487     frame = xbt_dict_get_or_null(mc_local_variables, frame_name);
488
489     if(frame == NULL){
490       ret = unw_step(&c);
491       continue;
492     }
493
494     true_ip = (long)frame->low_pc + (long)off;
495
496     /* Get frame pointer */
497     switch(frame->frame_base->type){
498     case e_dw_loclist:
499       while((cursor < xbt_dynar_length(frame->frame_base->location.loclist)) && frame_found == 0){
500         entry = xbt_dynar_get_as(frame->frame_base->location.loclist, cursor, dw_location_entry_t);
501         if((true_ip >= entry->lowpc) && (true_ip < entry->highpc)){
502           frame_found = 1;
503           switch(entry->location->type){
504           case e_dw_compose:
505             xbt_dynar_reset(compose);
506             cursor2 = 0;
507             while(cursor2 < xbt_dynar_length(entry->location->location.compose)){
508               location_entry = xbt_dynar_get_as(entry->location->location.compose, cursor2, dw_location_t);
509               switch(location_entry->type){
510               case e_dw_register:
511                 unw_get_reg(&c, location_entry->location.reg, &res);
512                 add_value(&compose, "address", (long)res);
513                 break;
514               case e_dw_bregister_op:
515                 unw_get_reg(&c, location_entry->location.breg_op.reg, &res);
516                 add_value(&compose, "address", (long)res + location_entry->location.breg_op.offset);
517                 break;
518               default:
519                 xbt_dynar_reset(compose);
520                 break;
521               }
522               cursor2++;
523             }
524
525             if(xbt_dynar_length(compose) > 0){
526               frame_pointer_address = xbt_dynar_get_as(compose, xbt_dynar_length(compose) - 1, variable_value_t)->value.address ; 
527             }
528             break;
529           default :
530             frame_pointer_address = NULL;
531             break;
532           }
533         }
534         cursor++;
535       }
536       break;
537     default :
538       frame_pointer_address = NULL;
539       break;
540     }
541
542     frame_found = 0;
543     cursor = 0;
544
545     //XBT_INFO("Frame %s", frame->name);
546
547     xbt_dict_foreach(frame->variables, dict_cursor, variable_name, current_variable){
548       if(current_variable->location != NULL){
549         switch(current_variable->location->type){
550         case e_dw_compose:
551           xbt_dynar_reset(compose);
552           cursor = 0;
553           while(cursor < xbt_dynar_length(current_variable->location->location.compose)){
554             location_entry = xbt_dynar_get_as(current_variable->location->location.compose, cursor, dw_location_t);
555             switch(location_entry->type){
556             case e_dw_register:
557               unw_get_reg(&c, location_entry->location.reg, &res);
558               add_value(&compose, "value", (long)res);
559               break;
560             case e_dw_bregister_op:
561               unw_get_reg(&c, location_entry->location.breg_op.reg, &res);
562               add_value(&compose, "address", (long)res + location_entry->location.breg_op.offset);
563               break;
564             case e_dw_fbregister_op:
565               if(frame_pointer_address != NULL)
566                 add_value(&compose, "address", (long)((char *)frame_pointer_address + location_entry->location.fbreg_op));
567               break;
568             default:
569               xbt_dynar_reset(compose);
570               break;
571             }
572             cursor++;
573           }
574           
575           if(xbt_dynar_length(compose) > 0){
576             //XBT_INFO("Variable : %s", current_variable->name);
577             if(strcmp(xbt_dynar_get_as(compose, xbt_dynar_length(compose) - 1, variable_value_t)->type, "value") == 0){
578               //XBT_INFO("Variable : %s - value : %lx", current_variable->name, xbt_dynar_get_as(compose, xbt_dynar_length(compose) - 1, variable_value_t)->value.res);
579               xbt_strbuff_append(variables, bprintf("%s=%lx\n", current_variable->name, xbt_dynar_get_as(compose, xbt_dynar_length(compose) - 1, variable_value_t)->value.res));
580             }else{
581               if((long)xbt_dynar_get_as(compose, xbt_dynar_length(compose) - 1,variable_value_t)->value.address < 0 || *((void**)xbt_dynar_get_as(compose, xbt_dynar_length(compose) - 1,variable_value_t)->value.address) == NULL){
582                 //XBT_INFO("Variable : %s - address : NULL", current_variable->name);
583                 xbt_strbuff_append(variables, bprintf("%s=NULL\n", current_variable->name));
584               }else if(((long)*((void**)xbt_dynar_get_as(compose, xbt_dynar_length(compose) - 1,variable_value_t)->value.address) > 0xffffffff) || ((long)*((void**)xbt_dynar_get_as(compose, xbt_dynar_length(compose) - 1,variable_value_t)->value.address) < (long)start_text_binary)){
585                 //XBT_INFO("Variable : %s - value : %zd", current_variable->name, (size_t)*((void**)xbt_dynar_get_as(compose, xbt_dynar_length(compose) - 1, variable_value_t)->value.address));
586                 xbt_strbuff_append(variables, bprintf("%s=%d\n", current_variable->name, (int)(long)*((void**)xbt_dynar_get_as(compose, xbt_dynar_length(compose) - 1, variable_value_t)->value.address)));
587               }else{
588                 //XBT_INFO("Variable : %s - address : %p", current_variable->name, *((void**)xbt_dynar_get_as(compose, xbt_dynar_length(compose) - 1, variable_value_t)->value.address));  
589                 xbt_strbuff_append(variables, bprintf("%s=%p\n", current_variable->name, *((void**)xbt_dynar_get_as(compose, xbt_dynar_length(compose) - 1, variable_value_t)->value.address)));
590               }
591             }
592           }else{
593             //XBT_INFO("Variable %s undefined", current_variable->name);
594             xbt_strbuff_append(variables, bprintf("%s=undefined\n", current_variable->name));
595           }
596           break;
597         default :
598           break;
599         }
600       }else{
601         //XBT_INFO("Variable : %s, no location", current_variable->name);
602         xbt_strbuff_append(variables, bprintf("%s=undefined\n", current_variable->name));
603       }
604     }    
605  
606     ret = unw_step(&c);
607
608     //XBT_INFO(" ");
609      
610   }
611
612   //free(stack_name);
613
614   return variables;
615
616 }
617
618 static void print_local_variables_values(xbt_dynar_t all_variables){
619
620   unsigned cursor = 0;
621   mc_snapshot_stack_t stack;
622
623   xbt_dynar_foreach(all_variables, cursor, stack){
624     XBT_INFO("%s", stack->local_variables->data);
625   }
626 }
627
628
629 static void snapshot_stack_free(mc_snapshot_stack_t s){
630   if(s){
631     xbt_free(s->local_variables->data);
632     xbt_free(s->local_variables);
633     xbt_free(s);
634   }
635 }
636
637 void snapshot_stack_free_voidp(void *s){
638   snapshot_stack_free((mc_snapshot_stack_t) * (void **) s);
639 }
640
641 void *MC_snapshot(void){
642
643   return simcall_mc_snapshot();
644   
645 }