Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
c2cc6de642b934c908df7d20c8c64c1d5dcd9a35
[simgrid.git] / src / mc / mc_compare.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 "mc_private.h"
7
8 #include "xbt/mmalloc.h"
9
10 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_compare, mc,
11                                 "Logging specific to mc_compare");
12
13 static int heap_region_compare(void *d1, void *d2, size_t size);
14
15 static int compare_stack(stack_region_t s1, stack_region_t s2, void *sp1, void *sp2, void *heap1, void *heap2, xbt_dynar_t equals);
16 static int is_heap_equality(xbt_dynar_t equals, void *a1, void *a2);
17 static size_t heap_ignore_size(void *address);
18
19 static void stack_region_free(stack_region_t s);
20 static void heap_equality_free(heap_equality_t e);
21
22 static int is_stack_ignore_variable(char *frame, char *var_name);
23 static int compare_local_variables(char *s1, char *s2, xbt_dynar_t heap_equals);
24
25 static size_t heap_ignore_size(void *address){
26   unsigned int cursor = 0;
27   int start = 0;
28   int end = xbt_dynar_length(mc_heap_comparison_ignore) - 1;
29   mc_heap_ignore_region_t region;
30
31   while(start <= end){
32     cursor = (start + end) / 2;
33     region = (mc_heap_ignore_region_t)xbt_dynar_get_as(mc_heap_comparison_ignore, cursor, mc_heap_ignore_region_t);
34     if(region->address == address)
35       return region->size;
36     if(region->address < address)
37       start = cursor + 1;
38     if(region->address > address)
39       end = cursor - 1;   
40   }
41
42   return 0;
43 }
44
45 static int compare_global_variables(int region_type, void *d1, void *d2, xbt_dynar_t equals){
46
47   unsigned int cursor = 0;
48   size_t offset; 
49   int i = 0;
50   global_variable_t current_var; 
51   int pointer_align; 
52   void *addr_pointed1 = NULL, *addr_pointed2 = NULL;
53   int res_compare = 0;
54
55   if(region_type == 1){ /* libsimgrid */
56     xbt_dynar_foreach(mc_global_variables, cursor, current_var){
57       if(current_var->address < start_data_libsimgrid)
58         continue;
59       offset = (char *)current_var->address - (char *)start_data_libsimgrid;
60       i = 0;
61       while(i < current_var->size){
62         if(memcmp((char*)d1 + offset + i, (char*)d2 + offset + i, 1) != 0){
63           pointer_align = (i / sizeof(void*)) * sizeof(void*); 
64           addr_pointed1 = *((void **)((char *)d1 + offset + pointer_align));
65           addr_pointed2 = *((void **)((char *)d2 + offset + pointer_align));
66           if((addr_pointed1 > start_plt_libsimgrid && addr_pointed1 < end_plt_libsimgrid) || (addr_pointed2 > start_plt_libsimgrid && addr_pointed2 < end_plt_libsimgrid)){
67             i = current_var->size;
68             continue;
69           }else{
70             if((addr_pointed1 > std_heap) && ((char *)addr_pointed1 < (char *)std_heap + STD_HEAP_SIZE) && (addr_pointed2 > std_heap) && ((char *)addr_pointed2 < (char *)std_heap + STD_HEAP_SIZE)){
71               res_compare = compare_area(addr_pointed1, addr_pointed2, NULL, equals);
72               if(res_compare == 1){
73                 #ifdef MC_VERBOSE
74                   XBT_VERB("Different global variable in libsimgrid : %s at addresses %p - %p (size = %zu)", current_var->name, (char *)d1+offset, (char *)d2+offset, current_var->size);
75                 #endif
76                 return 1;
77               }
78             }else{
79               #ifdef MC_VERBOSE
80                 XBT_VERB("Different global variable in libsimgrid : %s at addresses %p - %p (size = %zu)", current_var->name, (char *)d1+offset, (char *)d2+offset, current_var->size);
81               #endif
82               return 1;
83             }
84            
85           }
86         } 
87         i++;
88       }
89     }
90   }else{ /* binary */
91     xbt_dynar_foreach(mc_global_variables, cursor, current_var){
92       if(current_var->address > start_data_libsimgrid)
93         break;
94       offset = (char *)current_var->address - (char *)start_data_binary;
95       i = 0;
96       while(i < current_var->size){
97         if(memcmp((char*)d1 + offset + i, (char*)d2 + offset + i, 1) != 0){
98           pointer_align = (i / sizeof(void*)) * sizeof(void*); 
99           addr_pointed1 = *((void **)((char *)d1 + offset + pointer_align));
100           addr_pointed2 = *((void **)((char *)d2 + offset + pointer_align));
101           if((addr_pointed1 > start_plt_binary && addr_pointed1 < end_plt_binary) || (addr_pointed2 > start_plt_binary && addr_pointed2 < end_plt_binary)){
102             i = current_var->size;
103             continue;
104           }else{
105             if((addr_pointed1 > std_heap) && ((char *)addr_pointed1 < (char *)std_heap + STD_HEAP_SIZE) && (addr_pointed2 > std_heap) && ((char *)addr_pointed2 < (char *)std_heap + STD_HEAP_SIZE)){
106               res_compare = compare_area(addr_pointed1, addr_pointed2, NULL, equals);
107               if(res_compare == 1){
108                 #ifdef MC_VERBOSE
109                   XBT_VERB("Different global variable in binary : %s at addresses %p - %p (size = %zu)", current_var->name, (char *)d1+offset, (char *)d2+offset, current_var->size);
110                 #endif
111                 return 1;
112               }else{
113                 XBT_VERB("False pointer differences for variable : %s", current_var->name);
114               }
115             }else{
116               #ifdef MC_VERBOSE
117                 XBT_VERB("Different global variable in binary : %s at addresses %p - %p (size = %zu)", current_var->name, (char *)d1+offset, (char *)d2+offset, current_var->size);
118               #endif
119               return 1;
120             }
121           }
122         } 
123         i++;
124       }
125       
126     }
127   }
128
129   return 0;
130 }
131
132 static int heap_region_compare(void *d1, void *d2, size_t size){
133   
134   size_t i = 0;
135   
136   for(i=0; i<size; i++){
137     if(memcmp(((char *)d1) + i, ((char *)d2) + i, 1) != 0){
138       if(XBT_LOG_ISENABLED(mc_compare, xbt_log_priority_verbose)){
139         XBT_VERB("Different byte (offset=%zu) (%p - %p) in heap region", i, (char *)d1 + i, (char *)d2 + i);
140       }
141       return 1;
142     }
143   }
144   
145   return 0;
146 }
147
148 static void stack_region_free(stack_region_t s){
149   if(s){
150     xbt_free(s->process_name);
151     xbt_free(s);
152   }
153 }
154
155 void stack_region_free_voidp(void *s){
156   stack_region_free((stack_region_t) * (void **) s);
157 }
158
159 static void heap_equality_free(heap_equality_t e){
160   if(e){
161     xbt_free(e);
162   }
163 }
164
165 void heap_equality_free_voidp(void *e){
166   heap_equality_free((heap_equality_t) * (void **) e);
167 }
168
169 int SIMIX_pre_mc_compare_snapshots(smx_simcall_t simcall,
170                                    mc_snapshot_t s1, mc_snapshot_t s2){
171   return snapshot_compare(s1, s2);
172 }
173
174 int get_heap_region_index(mc_snapshot_t s){
175   int i = 0;
176   while(i < s->num_reg){
177     switch(s->regions[i]->type){
178     case 0:
179       return i;
180       break;
181     default:
182       i++;
183       break;
184     }
185   }
186   return -1;
187 }
188
189 int snapshot_compare(mc_snapshot_t s1, mc_snapshot_t s2){
190
191   int raw_mem = (mmalloc_get_current_heap() == raw_heap);
192   
193   MC_SET_RAW_MEM;
194       
195   int errors = 0;
196
197   xbt_os_timer_t global_timer = xbt_os_timer_new();
198   xbt_os_timer_t timer = xbt_os_timer_new();
199
200   xbt_os_timer_start(global_timer);
201
202   #ifdef MC_DEBUG
203     xbt_os_timer_start(timer);
204   #endif
205
206   /* Compare number of processes */
207   if(s1->nb_processes != s2->nb_processes){
208     #ifdef MC_DEBUG
209       xbt_os_timer_stop(timer);
210       mc_comp_times->nb_processes_comparison_time =  xbt_os_timer_elapsed(timer);
211       XBT_DEBUG("Different number of processes : %d - %d", s1->nb_processes, s2->nb_processes);
212       errors++;
213     #else
214       #ifdef MC_VERBOSE
215         XBT_VERB("Different number of processes : %d - %d", s1->nb_processes, s2->nb_processes);
216       #endif
217      
218       xbt_os_timer_free(timer);
219       xbt_os_timer_stop(global_timer);
220       mc_snapshot_comparison_time = xbt_os_timer_elapsed(global_timer);
221       xbt_os_timer_free(global_timer);
222
223       if(!raw_mem)
224         MC_UNSET_RAW_MEM;
225
226       return 1;
227     #endif
228   }
229
230   /* Compare number of blocks/fragments used in each heap */
231   if(s1->heap_chunks_used != s2->heap_chunks_used){
232     #ifdef MC_DEBUG
233       xbt_os_timer_stop(timer);
234       mc_comp_times->chunks_used_comparison_time = xbt_os_timer_elapsed(timer);
235       XBT_DEBUG("Different number of chunks used in each heap : %zu - %zu", s1->heap_chunks_used, s2->heap_chunks_used);
236       errors++;
237     #else
238       #ifdef MC_VERBOSE
239         XBT_VERB("Different number of chunks used in each heap : %zu - %zu", s1->heap_chunks_used, s2->heap_chunks_used);
240       #endif
241
242       xbt_os_timer_free(timer);
243       xbt_os_timer_stop(global_timer);
244       mc_snapshot_comparison_time = xbt_os_timer_elapsed(global_timer);
245       xbt_os_timer_free(global_timer);
246
247       if(!raw_mem)
248         MC_UNSET_RAW_MEM;
249
250       return 1;
251     #endif
252   }else{
253     #ifdef MC_DEBUG
254       xbt_os_timer_stop(timer);
255     #endif
256   }
257   
258   #ifdef MC_DEBUG
259     xbt_os_timer_start(timer);
260   #endif
261   
262   /* Compare size of stacks */
263   int i = 0;
264   size_t size_used1, size_used2;
265   int is_diff = 0;
266   while(i < xbt_dynar_length(s1->stacks)){
267     size_used1 = s1->stack_sizes[i];
268     size_used2 = s2->stack_sizes[i];
269     if(size_used1 != size_used2){
270     #ifdef MC_DEBUG
271       if(is_diff == 0){
272         xbt_os_timer_stop(timer);
273         mc_comp_times->stacks_sizes_comparison_time = xbt_os_timer_elapsed(timer);
274       }
275       XBT_DEBUG("Different size used in stacks : %zu - %zu", size_used1, size_used2);
276       errors++;
277       is_diff = 1;
278     #else
279       #ifdef MC_VERBOSE
280         XBT_VERB("Different size used in stacks : %zu - %zu", size_used1, size_used2);
281       #endif
282  
283       xbt_os_timer_free(timer);
284       xbt_os_timer_stop(global_timer);
285       mc_snapshot_comparison_time = xbt_os_timer_elapsed(global_timer);
286       xbt_os_timer_free(global_timer);
287
288       if(!raw_mem)
289         MC_UNSET_RAW_MEM;
290
291       return 1;
292     #endif  
293     }
294     i++;
295   }
296
297   #ifdef MC_DEBUG
298     if(is_diff == 0)
299       xbt_os_timer_stop(timer);
300     xbt_os_timer_start(timer);
301   #endif
302
303   int heap_index = 0, data_libsimgrid_index = 0, data_program_index = 0;
304   i = 0;
305   
306   /* Get index of regions */
307   while(i < s1->num_reg){
308     switch(s1->region_type[i]){
309     case 0:
310       heap_index = i;
311       i++;
312       break;
313     case 1:
314       data_libsimgrid_index = i;
315       i++;
316       while( i < s1->num_reg && s1->region_type[i] == 1)
317         i++;
318       break;
319     case 2:
320       data_program_index = i;
321       i++;
322       while( i < s1->num_reg && s1->region_type[i] == 2)
323         i++;
324       break;
325     }
326   }
327
328   /* Init heap information used in heap comparison algorithm */
329   init_heap_information((xbt_mheap_t)s1->regions[heap_index]->data, (xbt_mheap_t)s2->regions[heap_index]->data);
330
331   xbt_dynar_t equals = xbt_dynar_new(sizeof(heap_equality_t), heap_equality_free_voidp);
332
333   /* Compare binary global variables */
334   is_diff = compare_global_variables(s1->region_type[data_program_index], s1->regions[data_program_index]->data, s2->regions[data_program_index]->data, equals);
335   if(is_diff != 0){
336     #ifdef MC_DEBUG
337       xbt_os_timer_stop(timer);
338       mc_comp_times->binary_global_variables_comparison_time = xbt_os_timer_elapsed(timer);
339       XBT_DEBUG("Different global variables in binary"); 
340       errors++; 
341     #else
342       #ifdef MC_VERBOSE
343         XBT_VERB("Different global variables in binary"); 
344       #endif
345     
346       xbt_os_timer_free(timer);
347       xbt_os_timer_stop(global_timer);
348       mc_snapshot_comparison_time = xbt_os_timer_elapsed(global_timer);
349       xbt_os_timer_free(global_timer);
350     
351       if(!raw_mem)
352         MC_UNSET_RAW_MEM;
353
354       return 1;
355     #endif
356   }
357
358   #ifdef MC_VERBOSE
359     if(is_diff == 0)
360       xbt_os_timer_stop(timer);
361     xbt_os_timer_start(timer);
362   #endif
363
364   /* Compare libsimgrid global variables */
365     is_diff = compare_global_variables(s1->region_type[data_libsimgrid_index], s1->regions[data_libsimgrid_index]->data, s2->regions[data_libsimgrid_index]->data, equals);
366   if(is_diff != 0){
367     #ifdef MC_DEBUG
368       xbt_os_timer_stop(timer);
369       mc_comp_times->libsimgrid_global_variables_comparison_time = xbt_os_timer_elapsed(timer); 
370       XBT_DEBUG("Different global variables in libsimgrid"); 
371       errors++; 
372     #else
373       #ifdef MC_VERBOSE
374         XBT_VERB("Different global variables in libsimgrid"); 
375       #endif
376     
377       xbt_os_timer_free(timer);
378       xbt_os_timer_stop(global_timer);
379       mc_snapshot_comparison_time = xbt_os_timer_elapsed(global_timer);
380       xbt_os_timer_free(global_timer);
381     
382       if(!raw_mem)
383         MC_UNSET_RAW_MEM;
384
385       return 1;
386     #endif
387   }  
388
389   #ifdef MC_DEBUG
390     if(is_diff == 0)
391       xbt_os_timer_stop(timer);
392     xbt_os_timer_start(timer);
393   #endif
394
395   /* Compare heap */
396   xbt_dynar_t stacks1 = xbt_dynar_new(sizeof(stack_region_t), stack_region_free_voidp);
397   xbt_dynar_t stacks2 = xbt_dynar_new(sizeof(stack_region_t), stack_region_free_voidp);
398   
399   void *heap1 = s1->regions[heap_index]->data, *heap2 = s2->regions[heap_index]->data;
400  
401   if(mmalloc_compare_heap((xbt_mheap_t)s1->regions[heap_index]->data, (xbt_mheap_t)s2->regions[heap_index]->data, &stacks1, &stacks2, equals)){
402
403     #ifdef MC_DEBUG
404       xbt_os_timer_stop(timer);
405       mc_comp_times->heap_comparison_time = xbt_os_timer_elapsed(timer); 
406       XBT_DEBUG("Different heap (mmalloc_compare)");
407       errors++;
408     #else
409
410       xbt_os_timer_free(timer);
411       xbt_dynar_free(&stacks1);
412       xbt_dynar_free(&stacks2);
413       xbt_dynar_free(&equals);
414  
415       #ifdef MC_VERBOSE
416         XBT_VERB("Different heap (mmalloc_compare)");
417       #endif
418        
419       xbt_os_timer_stop(global_timer);
420       mc_snapshot_comparison_time = xbt_os_timer_elapsed(global_timer);
421       xbt_os_timer_free(global_timer);
422
423       if(!raw_mem)
424         MC_UNSET_RAW_MEM;
425
426       return 1;
427     #endif
428   }else{
429     #ifdef MC_DEBUG
430       xbt_os_timer_stop(timer);
431     #endif
432   }
433
434   #ifdef MC_DEBUG
435     xbt_os_timer_start(timer);
436   #endif
437
438   /* Stacks comparison */
439   unsigned int  cursor = 0;
440   stack_region_t stack_region1, stack_region2;
441   int diff = 0, diff_local = 0;
442   void *sp1, *sp2;
443   is_diff = 0;
444
445   while(cursor < xbt_dynar_length(stacks1)){
446     stack_region1 = (stack_region_t)(xbt_dynar_get_as(stacks1, cursor, stack_region_t));
447     stack_region2 = (stack_region_t)(xbt_dynar_get_as(stacks2, cursor, stack_region_t));
448     sp1 = ((mc_snapshot_stack_t)xbt_dynar_get_as(s1->stacks, cursor, mc_snapshot_stack_t))->stack_pointer;
449     sp2 = ((mc_snapshot_stack_t)xbt_dynar_get_as(s2->stacks, cursor, mc_snapshot_stack_t))->stack_pointer;
450     diff = compare_stack(stack_region1, stack_region2, sp1, sp2, heap1, heap2, equals);
451
452     if(diff > 0){ /* Differences may be due to padding */  
453       diff_local = compare_local_variables(((mc_snapshot_stack_t)xbt_dynar_get_as(s1->stacks, cursor, mc_snapshot_stack_t))->local_variables->data, ((mc_snapshot_stack_t)xbt_dynar_get_as(s2->stacks, cursor, mc_snapshot_stack_t))->local_variables->data, equals);
454       if(diff_local > 0){
455         #ifdef MC_DEBUG
456           if(is_diff == 0){
457             xbt_os_timer_stop(timer);
458             mc_comp_times->stacks_comparison_time = xbt_os_timer_elapsed(timer); 
459           }
460           XBT_DEBUG("Different local variables between stacks %d", cursor + 1);
461           errors++;
462           is_diff = 1;
463         #else
464           xbt_dynar_free(&stacks1);
465           xbt_dynar_free(&stacks2);
466           xbt_dynar_free(&equals);
467
468           #ifdef MC_VERBOSE
469             XBT_VERB("Different local variables between stacks %d", cursor + 1);
470           #endif
471           
472           xbt_os_timer_free(timer);
473           xbt_os_timer_stop(global_timer);
474           mc_snapshot_comparison_time = xbt_os_timer_elapsed(global_timer);
475           xbt_os_timer_free(global_timer);
476           
477           if(!raw_mem)
478             MC_UNSET_RAW_MEM;
479
480           return 1;
481         #endif
482       }
483     }
484     cursor++;
485   }
486
487   xbt_dynar_free(&stacks1);
488   xbt_dynar_free(&stacks2);
489   xbt_dynar_free(&equals);
490    
491   xbt_os_timer_free(timer);
492
493   #ifdef MC_VERBOSE
494     xbt_os_timer_stop(global_timer);
495     mc_snapshot_comparison_time = xbt_os_timer_elapsed(global_timer);
496   #endif
497
498   xbt_os_timer_free(global_timer);
499
500   #ifdef MC_DEBUG
501     print_comparison_times();
502   #endif
503
504   if(!raw_mem)
505     MC_UNSET_RAW_MEM;
506
507   return errors > 0;
508   
509 }
510
511 static int is_stack_ignore_variable(char *frame, char *var_name){
512
513   unsigned int cursor = 0;
514   int start = 0;
515   int end = xbt_dynar_length(mc_stack_comparison_ignore) - 1;
516   mc_stack_ignore_variable_t current_var;
517
518   while(start <= end){
519     cursor = (start + end) / 2;
520     current_var = (mc_stack_ignore_variable_t)xbt_dynar_get_as(mc_stack_comparison_ignore, cursor, mc_stack_ignore_variable_t);
521     if(strcmp(current_var->frame, frame) == 0 || strcmp(current_var->frame, "*") == 0){
522       if(strcmp(current_var->var_name, var_name) == 0)
523         return 1;
524       if(strcmp(current_var->var_name, var_name) < 0)
525         start = cursor + 1;
526       if(strcmp(current_var->var_name, var_name) > 0)
527         end = cursor - 1;
528     }else if(strcmp(current_var->frame, frame) < 0){
529       start = cursor + 1;
530     }else if(strcmp(current_var->frame, frame) > 0){
531       end = cursor - 1; 
532     }
533   }
534
535   return 0;
536 }
537
538 static int compare_local_variables(char *s1, char *s2, xbt_dynar_t heap_equals){
539   
540   xbt_dynar_t tokens1 = xbt_str_split(s1, NULL);
541   xbt_dynar_t tokens2 = xbt_str_split(s2, NULL);
542
543   xbt_dynar_t s_tokens1, s_tokens2;
544   unsigned int cursor = 0;
545   void *addr1, *addr2;
546   char *ip1 = NULL, *ip2 = NULL;
547   
548   while(cursor < xbt_dynar_length(tokens1)){
549     s_tokens1 = xbt_str_split(xbt_dynar_get_as(tokens1, cursor, char *), "=");
550     s_tokens2 = xbt_str_split(xbt_dynar_get_as(tokens2, cursor, char *), "=");
551     if(xbt_dynar_length(s_tokens1) > 1 && xbt_dynar_length(s_tokens2) > 1){
552       if((strcmp(xbt_dynar_get_as(s_tokens1, 0, char *), "ip") == 0) && (strcmp(xbt_dynar_get_as(s_tokens2, 0, char *), "ip") == 0)){
553         xbt_free(ip1);
554         xbt_free(ip2);
555         ip1 = strdup(xbt_dynar_get_as(s_tokens1, 1, char *));
556         ip2 = strdup(xbt_dynar_get_as(s_tokens2, 1, char *));
557       }
558       if(strcmp(xbt_dynar_get_as(s_tokens1, 1, char *), xbt_dynar_get_as(s_tokens2, 1, char *)) != 0){   
559         /* Ignore this variable ?  */
560         if(is_stack_ignore_variable(ip1, xbt_dynar_get_as(s_tokens1, 0, char *)) && is_stack_ignore_variable(ip2, xbt_dynar_get_as(s_tokens2, 0, char *))){
561           xbt_dynar_free(&s_tokens1);
562           xbt_dynar_free(&s_tokens2);
563           cursor++;
564           continue;
565         }
566         addr1 = (void *) strtoul(xbt_dynar_get_as(s_tokens1, 1, char *), NULL, 16);
567         addr2 = (void *) strtoul(xbt_dynar_get_as(s_tokens2, 1, char *), NULL, 16);
568         if(is_heap_equality(heap_equals, addr1, addr2) == 0){
569           if(XBT_LOG_ISENABLED(mc_compare, xbt_log_priority_verbose))
570             XBT_VERB("Variable %s is different between stacks in %s : %s - %s", xbt_dynar_get_as(s_tokens1, 0, char *), ip1, xbt_dynar_get_as(s_tokens1, 1, char *), xbt_dynar_get_as(s_tokens2, 1, char *));
571           xbt_dynar_free(&s_tokens1);
572           xbt_dynar_free(&s_tokens2);
573           xbt_dynar_free(&tokens1);
574           xbt_dynar_free(&tokens2);
575           xbt_free(ip1);
576           xbt_free(ip2);
577           return 1;
578         }
579       }
580     }
581     xbt_dynar_free(&s_tokens1);
582     xbt_dynar_free(&s_tokens2);
583          
584     cursor++;
585   }
586
587   xbt_free(ip1);
588   xbt_free(ip2);
589   xbt_dynar_free(&tokens1);
590   xbt_dynar_free(&tokens2);
591   return 0;
592   
593 }
594
595 static int is_heap_equality(xbt_dynar_t equals, void *a1, void *a2){
596
597   unsigned int cursor = 0;
598   int start = 0;
599   int end = xbt_dynar_length(equals) - 1;
600   heap_equality_t current_equality;
601
602   while(start <= end){
603     cursor = (start + end) / 2;
604     current_equality = (heap_equality_t)xbt_dynar_get_as(equals, cursor, heap_equality_t);
605     if(current_equality->address1 == a1){
606       if(current_equality->address2 == a2)
607         return 1;
608       if(current_equality->address2 < a2)
609         start = cursor + 1;
610       if(current_equality->address2 > a2)
611         end = cursor - 1;
612     }
613     if(current_equality->address1 < a1)
614       start = cursor + 1;
615     if(current_equality->address1 > a1)
616       end = cursor - 1; 
617   }
618
619   return 0;
620
621 }
622
623
624 static int compare_stack(stack_region_t s1, stack_region_t s2, void *sp1, void *sp2, void *heap1, void *heap2, xbt_dynar_t equals){
625   
626   size_t k = 0;
627   size_t size_used1 = s1->size - ((char*)sp1 - (char*)s1->address);
628   size_t size_used2 = s2->size - ((char*)sp2 - (char*)s2->address);
629
630   int pointer_align;
631   void *addr_pointed1 = NULL, *addr_pointed2 = NULL;  
632   
633   while(k < size_used1){
634     if(memcmp((char *)s1->address + s1->size - k, (char *)s2->address + s2->size - k, 1) != 0){
635       pointer_align = ((size_used1 - k) / sizeof(void*)) * sizeof(void*);
636       addr_pointed1 = *((void **)(((char*)s1->address + (s1->size - size_used1)) + pointer_align));
637       addr_pointed2 = *((void **)(((char*)s2->address + (s2->size - size_used2)) + pointer_align));
638       if(is_heap_equality(equals, addr_pointed1, addr_pointed2) == 0){
639         if((addr_pointed1 > std_heap) && (addr_pointed1 < (void *)((char *)std_heap + STD_HEAP_SIZE)) && (addr_pointed2 > std_heap) && (addr_pointed2 < (void *)((char *)std_heap + STD_HEAP_SIZE))){
640           if(is_free_area(addr_pointed1, (xbt_mheap_t)heap1) == 0 || is_free_area(addr_pointed2, (xbt_mheap_t)heap2) == 0){
641             return 1;
642           }
643         }else{
644           return 1;
645         } 
646       }
647     } 
648     k++;
649   }
650  
651   return 0;
652 }
653
654 int MC_compare_snapshots(void *s1, void *s2){
655   
656   MC_ignore_stack("self", "simcall_BODY_mc_snapshot");
657
658   return simcall_mc_compare_snapshots(s1, s2);
659
660 }
661
662 void print_comparison_times(){
663   XBT_DEBUG("*** Comparison times ***");
664   XBT_DEBUG("- Nb processes : %f", mc_comp_times->nb_processes_comparison_time);
665   XBT_DEBUG("- Nb chunks used : %f", mc_comp_times->chunks_used_comparison_time);
666   XBT_DEBUG("- Stacks sizes : %f", mc_comp_times->stacks_sizes_comparison_time);
667   XBT_DEBUG("- Binary global variables : %f", mc_comp_times->binary_global_variables_comparison_time);
668   XBT_DEBUG("- Libsimgrid global variables : %f", mc_comp_times->libsimgrid_global_variables_comparison_time);
669   XBT_DEBUG("- Heap : %f", mc_comp_times->heap_comparison_time);
670   XBT_DEBUG("- Stacks : %f", mc_comp_times->stacks_comparison_time);
671 }