Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
model-checker : init equal_to field to -1 for each allocated block/fragment at the...
[simgrid.git] / src / xbt / mmalloc / mm_diff.c
1 /* mm_diff - Memory snapshooting and comparison                             */
2
3 /* Copyright (c) 2008-2012. The SimGrid Team. All rights reserved.          */
4
5 /* This program is free software; you can redistribute it and/or modify it
6  * under the terms of the license (GNU LGPL) which comes with this package. */
7
8 #include "xbt/ex_interface.h" /* internals of backtrace setup */
9 #include "xbt/str.h"
10 #include "mc/mc.h"
11
12 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mm_diff, xbt,
13                                 "Logging specific to mm_diff in mmalloc");
14
15 extern char *xbt_binary_name;
16
17 xbt_dynar_t mmalloc_ignore;
18
19 typedef struct s_heap_area_pair{
20   int block1;
21   int fragment1;
22   int block2;
23   int fragment2;
24 }s_heap_area_pair_t, *heap_area_pair_t;
25
26 static void heap_area_pair_free(heap_area_pair_t pair);
27 static void heap_area_pair_free_voidp(void *d);
28 static int add_heap_area_pair(xbt_dynar_t list, int block1, int fragment1, int block2, int fragment2);
29 static int is_new_heap_area_pair(xbt_dynar_t list, int block1, int fragment1, int block2, int fragment2);
30
31 static int compare_area(void *area1, void* area2, size_t size, xbt_dynar_t previous, int check_ignore);
32 static void match_equals(xbt_dynar_t list);
33
34 static int in_mmalloc_ignore(int block, int fragment);
35 static size_t heap_comparison_ignore(void *address);
36
37 void mmalloc_backtrace_block_display(void* heapinfo, int block){
38
39   xbt_ex_t e;
40
41   if (((malloc_info *)heapinfo)[block].busy_block.bt_size == 0) {
42     XBT_DEBUG("No backtrace available for that block, sorry.");
43     return;
44   }
45
46   memcpy(&e.bt,&(((malloc_info *)heapinfo)[block].busy_block.bt),sizeof(void*)*XBT_BACKTRACE_SIZE);
47   e.used = ((malloc_info *)heapinfo)[block].busy_block.bt_size;
48
49   xbt_ex_setup_backtrace(&e);
50   if (e.used == 0) {
51     XBT_DEBUG("(backtrace not set)");
52   } else if (e.bt_strings == NULL) {
53     XBT_DEBUG("(backtrace not ready to be computed. %s)",xbt_binary_name?"Dunno why":"xbt_binary_name not setup yet");
54   } else {
55     int i;
56
57     XBT_DEBUG("Backtrace of where the block %d was malloced (%d frames):", block ,e.used);
58     for (i = 0; i < e.used; i++)       /* no need to display "xbt_backtrace_display" */{
59       XBT_DEBUG("%d ---> %s",i, e.bt_strings[i] + 4);
60     }
61   }
62
63 }
64
65 void mmalloc_backtrace_fragment_display(void* heapinfo, int block, int frag){
66
67   xbt_ex_t e;
68
69   memcpy(&e.bt,&(((malloc_info *)heapinfo)[block].busy_frag.bt[frag]),sizeof(void*)*XBT_BACKTRACE_SIZE);
70   e.used = XBT_BACKTRACE_SIZE;
71
72   xbt_ex_setup_backtrace(&e);
73   if (e.used == 0) {
74     XBT_DEBUG("(backtrace not set)");
75   } else if (e.bt_strings == NULL) {
76     XBT_DEBUG("(backtrace not ready to be computed. %s)",xbt_binary_name?"Dunno why":"xbt_binary_name not setup yet");
77   } else {
78     int i;
79
80     XBT_DEBUG("Backtrace of where the fragment %d in block %d was malloced (%d frames):", frag, block ,e.used);
81     for (i = 0; i < e.used; i++)       /* no need to display "xbt_backtrace_display" */{
82       XBT_DEBUG("%d ---> %s",i, e.bt_strings[i] + 4);
83     }
84   }
85
86 }
87
88 void *s_heap, *heapbase1, *heapbase2;
89 malloc_info *heapinfo1, *heapinfo2;
90 size_t heaplimit, heapsize1, heapsize2;
91
92 int ignore_done;
93
94 int mmalloc_compare_heap(xbt_mheap_t heap1, xbt_mheap_t heap2){
95
96   if(heap1 == NULL && heap1 == NULL){
97     XBT_DEBUG("Malloc descriptors null");
98     return 0;
99   }
100
101   if(heap1->heaplimit != heap2->heaplimit){
102     XBT_DEBUG("Different limit of valid info table indices");
103     return 1;
104   }
105
106   /* Heap information */
107   heaplimit = ((struct mdesc *)heap1)->heaplimit;
108
109   s_heap = (char *)mmalloc_get_current_heap() - STD_HEAP_SIZE - getpagesize();
110
111   heapbase1 = (char *)heap1 + BLOCKSIZE;
112   heapbase2 = (char *)heap2 + BLOCKSIZE;
113
114   heapinfo1 = (malloc_info *)((char *)heap1 + ((uintptr_t)((char *)heap1->heapinfo - (char *)s_heap)));
115   heapinfo2 = (malloc_info *)((char *)heap2 + ((uintptr_t)((char *)heap2->heapinfo - (char *)s_heap)));
116
117   heapsize1 = heap1->heapsize;
118   heapsize2 = heap2->heapsize;
119
120   /* Start comparison */
121   size_t i1, i2, j1, j2, k;
122   void *addr_block1, *addr_block2, *addr_frag1, *addr_frag2;
123   size_t frag_size1, frag_size2;
124
125   xbt_dynar_t previous = xbt_dynar_new(sizeof(heap_area_pair_t), heap_area_pair_free_voidp);
126
127   int equal, res_compare;
128
129   ignore_done = 0;
130
131   /* Init equal information */
132   i1 = 1;
133
134   while(i1<=heaplimit){
135     if(heapinfo1[i1].type == 0){
136       heapinfo1[i1].busy_block.equal_to = -1;
137     }
138     if(heapinfo1[i1].type > 0){
139       for(j1=0; j1 < MAX_FRAGMENT_PER_BLOCK; j1++){
140         heapinfo1[i1].busy_frag.equal_to[j1] = -1;
141       }
142     }
143     i1++; 
144   }
145
146   i2 = 1;
147
148   while(i2<=heaplimit){
149     if(heapinfo2[i2].type == 0){
150       heapinfo2[i2].busy_block.equal_to = -1;
151     }
152     if(heapinfo2[i2].type > 0){
153       for(j2=0; j2 < MAX_FRAGMENT_PER_BLOCK; j2++){
154         heapinfo2[i2].busy_frag.equal_to[j2] = -1;
155       }
156     }
157     i2++; 
158   }
159
160   /* Check busy blocks*/
161
162   i1 = 1;
163
164   while(i1 < heaplimit){
165
166     i2 = 1;
167     equal = 0;
168
169     if(heapinfo1[i1].type == -1){ /* Free block */
170       i1++;
171       continue;
172     }
173
174     addr_block1 = ((void*) (((ADDR2UINT(i1)) - 1) * BLOCKSIZE + (char*)heapbase1));
175
176     if(heapinfo1[i1].type == 0){  /* Large block */
177
178       while(i2 <= heaplimit && !equal){
179
180         if(heapinfo2[i2].type != 0){
181           i2++;
182           continue;
183         }
184
185         if(heapinfo2[i2].busy_block.equal_to == 1){         
186           i2++;
187           continue;
188         }
189         
190         if(heapinfo1[i1].busy_block.size != heapinfo2[i2].busy_block.size){
191           i2++;
192           continue;
193         }
194         
195         if(heapinfo1[i1].busy_block.busy_size != heapinfo2[i2].busy_block.busy_size){
196           i2++;
197           continue;
198         }
199
200         addr_block2 = ((void*) (((ADDR2UINT(i2)) - 1) * BLOCKSIZE + (char*)heapbase2));
201
202         /* Comparison */
203         add_heap_area_pair(previous, i1, -1, i2, -1);
204         
205         if(ignore_done < xbt_dynar_length(mmalloc_ignore)){
206           if(in_mmalloc_ignore((int)i1, -1))
207             res_compare = compare_area(addr_block1, addr_block2, heapinfo1[i1].busy_block.busy_size, previous, 1);
208           else
209             res_compare = compare_area(addr_block1, addr_block2, heapinfo1[i1].busy_block.busy_size, previous, 0);
210         }else{
211           res_compare = compare_area(addr_block1, addr_block2, heapinfo1[i1].busy_block.busy_size, previous, 0);
212         }
213         
214         if(!res_compare){
215           for(k=0; k < heapinfo2[i2].busy_block.size; k++)
216             heapinfo2[i2+k].busy_block.equal_to = 1;
217           for(k=0; k < heapinfo1[i1].busy_block.size; k++)
218             heapinfo1[i1+k].busy_block.equal_to = 1;
219           equal = 1;
220           match_equals(previous);
221         }
222         xbt_dynar_reset(previous);
223
224         i2++;
225
226       }
227
228     }else{ /* Fragmented block */
229
230       frag_size1 = 1 << heapinfo1[i1].type;
231
232       for(j1=0; j1 < (size_t) (BLOCKSIZE >> heapinfo1[i1].type); j1++){
233
234         if(heapinfo1[i1].busy_frag.frag_size[j1] == 0) /* Free fragment */
235           continue;
236         
237         addr_frag1 = (void*) ((char *)addr_block1 + (j1 * frag_size1));
238         
239         i2 = 1;
240         equal = 0;
241         
242         while(i2 <= heaplimit && !equal){
243           
244           if(heapinfo2[i2].type <= 0){
245             i2++;
246             continue;
247           }
248           
249           frag_size2 = 1 << heapinfo2[i2].type;
250
251           for(j2=0; j2 < (size_t) (BLOCKSIZE >> heapinfo2[i2].type); j2++){
252
253             if(heapinfo2[i2].busy_frag.equal_to[j2] == 1){                 
254               continue;              
255             }
256              
257             if(heapinfo1[i1].busy_frag.frag_size[j1] != heapinfo2[i2].busy_frag.frag_size[j2]){ /* Different size_used */    
258               continue;
259             }
260              
261             addr_block2 = ((void*) (((ADDR2UINT(i2)) - 1) * BLOCKSIZE + (char*)heapbase2));
262             addr_frag2 = (void*) ((char *)addr_block2 + (j2 * frag_size2));
263              
264             /* Comparison */
265             add_heap_area_pair(previous, i1, j1, i2, j2);
266             
267             if(ignore_done < xbt_dynar_length(mmalloc_ignore)){
268               if(in_mmalloc_ignore((int)i1, (int)j1))
269                 res_compare = compare_area(addr_frag1, addr_frag2, heapinfo1[i1].busy_frag.frag_size[j1], previous, 1);
270               else
271                 res_compare = compare_area(addr_frag1, addr_frag2, heapinfo1[i1].busy_frag.frag_size[j1], previous, 0);
272             }else{
273               res_compare = compare_area(addr_frag1, addr_frag2, heapinfo1[i1].busy_frag.frag_size[j1], previous, 0);
274             }
275
276             if(!res_compare){
277               heapinfo2[i2].busy_frag.equal_to[j2] = 1;
278               heapinfo1[i1].busy_frag.equal_to[j1] = 1;
279               equal = 1;
280               match_equals(previous);
281               break;
282             }
283             xbt_dynar_reset(previous);
284
285           }
286
287           i2++;
288
289         }
290
291       }
292
293     }
294
295     i1++;
296
297   }
298
299   /* All blocks/fragments are equal to another block/fragment ? */
300   size_t i = 1, j = 0;
301   int nb_diff1 = 0, nb_diff2 = 0;
302   size_t frag_size = 0;
303  
304   while(i<heaplimit){
305     if(heapinfo1[i].type == 0){
306       if(heapinfo1[i].busy_block.busy_size > 0){
307         if(heapinfo1[i].busy_block.equal_to == -1){
308           if(XBT_LOG_ISENABLED(mm_diff, xbt_log_priority_debug)){
309             addr_block1 = ((void*) (((ADDR2UINT(i)) - 1) * BLOCKSIZE + (char*)heapbase1));
310             XBT_DEBUG("Block %zu (%p) not found (size used = %zu)", i, addr_block1, heapinfo1[i].busy_block.busy_size);
311             mmalloc_backtrace_block_display((void*)heapinfo1, i);
312           }
313           nb_diff1++;
314         }
315       }
316     }
317     if(heapinfo1[i].type > 0){
318       frag_size = 1 << heapinfo1[i].type;
319       for(j=0; j < (size_t) (BLOCKSIZE >> heapinfo1[i].type); j++){
320         if(heapinfo1[i].busy_frag.frag_size[j] > 0){
321           if(heapinfo1[i].busy_frag.equal_to[j] == -1){
322             if(XBT_LOG_ISENABLED(mm_diff, xbt_log_priority_debug)){
323               addr_block1 = ((void*) (((ADDR2UINT(i)) - 1) * BLOCKSIZE + (char*)heapbase1));
324               addr_frag1 = (void*) ((char *)addr_block1 + (j * frag_size));
325               XBT_DEBUG("Block %zu, Fragment %zu (%p) not found (size used = %d)", i, j, addr_frag1, heapinfo1[i].busy_frag.frag_size[j]);
326               mmalloc_backtrace_fragment_display((void*)heapinfo1, i, j);
327             }
328             nb_diff1++;
329           }
330         }
331       }
332     }
333     
334     i++; 
335   }
336
337   XBT_DEBUG("Different blocks or fragments in heap1 : %d\n", nb_diff1);
338
339   i = 1;
340
341   while(i<heaplimit){
342     if(heapinfo2[i].type == 0){
343       if(heapinfo2[i].busy_block.busy_size > 0){
344         if(heapinfo2[i].busy_block.equal_to == -1){
345           if(XBT_LOG_ISENABLED(mm_diff, xbt_log_priority_debug)){
346             addr_block2 = ((void*) (((ADDR2UINT(i)) - 1) * BLOCKSIZE + (char*)heapbase2));
347             XBT_DEBUG("Block %zu (%p) not found (size used = %zu)", i, addr_block2, heapinfo2[i].busy_block.busy_size);
348             mmalloc_backtrace_block_display((void*)heapinfo2, i);
349           }
350           nb_diff2++;
351         }
352       }
353     }
354     if(heapinfo2[i].type > 0){
355       frag_size = 1 << heapinfo2[i].type;
356       for(j=0; j < (size_t) (BLOCKSIZE >> heapinfo2[i].type); j++){
357         if(heapinfo2[i].busy_frag.frag_size[j] > 0){
358           if(heapinfo2[i].busy_frag.equal_to[j] == -1){
359             if(XBT_LOG_ISENABLED(mm_diff, xbt_log_priority_debug)){
360               addr_block2 = ((void*) (((ADDR2UINT(i)) - 1) * BLOCKSIZE + (char*)heapbase2));
361               addr_frag2 = (void*) ((char *)addr_block2 + (j * frag_size));
362               XBT_DEBUG( "Block %zu, Fragment %zu (%p) not found (size used = %d)", i, j, addr_frag2, heapinfo2[i].busy_frag.frag_size[j]);
363               mmalloc_backtrace_fragment_display((void*)heapinfo2, i, j);
364             }
365             nb_diff2++;
366           }
367         }
368       }
369     }
370     i++; 
371   }
372
373   XBT_DEBUG("Different blocks or fragments in heap2 : %d\n", nb_diff2);
374
375   xbt_dynar_free(&previous);
376  
377   return ((nb_diff1 > 0) || (nb_diff2 > 0));
378
379 }
380
381 static int in_mmalloc_ignore(int block, int fragment){
382
383   unsigned int cursor = 0;
384   int start = 0;
385   int end = xbt_dynar_length(mmalloc_ignore) - 1;
386   mc_ignore_region_t region;
387
388   while(start <= end){
389     cursor = (start + end) / 2;
390     region = (mc_ignore_region_t)xbt_dynar_get_as(mmalloc_ignore, cursor, mc_ignore_region_t);
391     if(region->block == block){
392       if(region->fragment == fragment)
393         return 1;
394       if(region->fragment < fragment)
395         start = cursor + 1;
396       if(region->fragment > fragment)
397         end = cursor - 1;
398     }
399     if(region->block < block)
400       start = cursor + 1;
401     if(region->block > block)
402       end = cursor - 1; 
403   }
404
405   return 0;
406 }
407
408 static size_t heap_comparison_ignore(void *address){
409   unsigned int cursor = 0;
410   int start = 0;
411   int end = xbt_dynar_length(mmalloc_ignore) - 1;
412   mc_ignore_region_t region;
413
414   while(start <= end){
415     cursor = (start + end) / 2;
416     region = (mc_ignore_region_t)xbt_dynar_get_as(mmalloc_ignore, cursor, mc_ignore_region_t);
417     if(region->address == address)
418       return region->size;
419     if(region->address < address)
420       start = cursor + 1;
421     if(region->address > address)
422       end = cursor - 1;   
423   }
424
425   return 0;
426 }
427
428
429 static int compare_area(void *area1, void* area2, size_t size, xbt_dynar_t previous, int check_ignore){
430
431   size_t i = 0, pointer_align = 0, ignore1 = 0, ignore2 = 0;
432   void *address_pointed1, *address_pointed2, *addr_block_pointed1, *addr_block_pointed2, *addr_frag_pointed1, *addr_frag_pointed2;
433   size_t block_pointed1, block_pointed2, frag_pointed1, frag_pointed2;
434   size_t frag_size, frag_size1, frag_size2;
435   int res_compare;
436   void *current_area1, *current_area2;
437  
438   while(i<size){
439
440     if(check_ignore){
441
442       current_area1 = (char*)((xbt_mheap_t)s_heap)->heapbase + ((((char *)area1) + i) - (char *)heapbase1);
443       if((ignore1 = heap_comparison_ignore(current_area1)) > 0){
444         current_area2 = (char*)((xbt_mheap_t)s_heap)->heapbase + ((((char *)area2) + i) - (char *)heapbase2);
445         if((ignore2 = heap_comparison_ignore(current_area2))  == ignore1){
446           i = i + ignore2;
447           ignore_done++;
448           continue;
449         }
450       }
451
452     }
453    
454     if(memcmp(((char *)area1) + i, ((char *)area2) + i, 1) != 0){
455
456       /* Check pointer difference */
457       pointer_align = (i / sizeof(void*)) * sizeof(void*);
458       address_pointed1 = *((void **)((char *)area1 + pointer_align));
459       address_pointed2 = *((void **)((char *)area2 + pointer_align));
460
461       /* Get pointed blocks number */ 
462       block_pointed1 = ((char*)address_pointed1 - (char*)((xbt_mheap_t)s_heap)->heapbase) / BLOCKSIZE + 1;
463       block_pointed2 = ((char*)address_pointed2 - (char*)((xbt_mheap_t)s_heap)->heapbase) / BLOCKSIZE + 1;
464
465       /* Check if valid blocks number */
466       if((char *)address_pointed1 < (char*)((xbt_mheap_t)s_heap)->heapbase || block_pointed1 > heapsize1 || block_pointed1 < 1 || (char *)address_pointed2 < (char*)((xbt_mheap_t)s_heap)->heapbase || block_pointed2 > heapsize2 || block_pointed2 < 1)
467         return 1;
468
469       if(heapinfo1[block_pointed1].type == heapinfo2[block_pointed2].type){ /* Same type of block (large or fragmented) */
470
471         addr_block_pointed1 = ((void*) (((ADDR2UINT(block_pointed1)) - 1) * BLOCKSIZE + (char*)heapbase1));
472         addr_block_pointed2 = ((void*) (((ADDR2UINT(block_pointed2)) - 1) * BLOCKSIZE + (char*)heapbase2));
473         
474         if(heapinfo1[block_pointed1].type == 0){ /* Large block */
475
476           if(heapinfo1[block_pointed1].busy_block.size != heapinfo2[block_pointed2].busy_block.size){
477             return 1;
478           }
479
480           if(heapinfo1[block_pointed1].busy_block.busy_size != heapinfo2[block_pointed2].busy_block.busy_size){
481             return 1;
482           }
483
484           if(add_heap_area_pair(previous, block_pointed1, -1, block_pointed2, -1)){
485
486             if(ignore_done < xbt_dynar_length(mmalloc_ignore)){
487               if(in_mmalloc_ignore(block_pointed1, -1))
488                 res_compare = compare_area(addr_block_pointed1, addr_block_pointed2, heapinfo1[block_pointed1].busy_block.busy_size, previous, 1);
489               else
490                 res_compare = compare_area(addr_block_pointed1, addr_block_pointed2, heapinfo1[block_pointed1].busy_block.busy_size, previous, 0);
491             }else{
492               res_compare = compare_area(addr_block_pointed1, addr_block_pointed2, heapinfo1[block_pointed1].busy_block.busy_size, previous, 0);
493             }
494             
495             if(res_compare)    
496               return 1;
497            
498           }
499           
500         }else{ /* Fragmented block */
501
502            /* Get pointed fragments number */ 
503           frag_pointed1 = ((uintptr_t) (ADDR2UINT (address_pointed1) % (BLOCKSIZE))) >> heapinfo1[block_pointed1].type;
504           frag_pointed2 = ((uintptr_t) (ADDR2UINT (address_pointed2) % (BLOCKSIZE))) >> heapinfo2[block_pointed2].type;
505          
506           if(heapinfo1[block_pointed1].busy_frag.frag_size[frag_pointed1] != heapinfo2[block_pointed2].busy_frag.frag_size[frag_pointed2]) /* Different size_used */    
507             return 1;
508
509           frag_size = 1 << heapinfo1[block_pointed1].type;
510             
511           addr_frag_pointed1 = (void*) ((char *)addr_block_pointed1 + (frag_pointed1 * frag_size));
512           addr_frag_pointed2 = (void*) ((char *)addr_block_pointed2 + (frag_pointed2 * frag_size));
513
514           if(add_heap_area_pair(previous, block_pointed1, frag_pointed1, block_pointed2, frag_pointed2)){
515
516             if(ignore_done < xbt_dynar_length(mmalloc_ignore)){
517               if(in_mmalloc_ignore(block_pointed1, frag_pointed1))
518                 res_compare = compare_area(addr_frag_pointed1, addr_frag_pointed2, heapinfo1[block_pointed1].busy_frag.frag_size[frag_pointed1], previous, 1);
519               else
520                 res_compare = compare_area(addr_frag_pointed1, addr_frag_pointed2, heapinfo1[block_pointed1].busy_frag.frag_size[frag_pointed1], previous, 0);
521             }else{
522               res_compare = compare_area(addr_frag_pointed1, addr_frag_pointed2, heapinfo1[block_pointed1].busy_frag.frag_size[frag_pointed1], previous, 0);
523             }
524
525             if(res_compare)
526               return 1;
527            
528           }
529           
530         }
531           
532       }else{
533
534         if((heapinfo1[block_pointed1].type > 0) && (heapinfo2[block_pointed2].type > 0)){
535           
536           addr_block_pointed1 = ((void*) (((ADDR2UINT(block_pointed1)) - 1) * BLOCKSIZE + (char*)heapbase1));
537           addr_block_pointed2 = ((void*) (((ADDR2UINT(block_pointed2)) - 1) * BLOCKSIZE + (char*)heapbase2));
538        
539           frag_pointed1 = ((uintptr_t) (ADDR2UINT (address_pointed1) % (BLOCKSIZE))) >> heapinfo1[block_pointed1].type;
540           frag_pointed2 = ((uintptr_t) (ADDR2UINT (address_pointed2) % (BLOCKSIZE))) >> heapinfo2[block_pointed2].type;
541
542           if(heapinfo1[block_pointed1].busy_frag.frag_size[frag_pointed1] != heapinfo2[block_pointed2].busy_frag.frag_size[frag_pointed2]) /* Different size_used */    
543             return 1;
544           
545           frag_size1 = 1 << heapinfo1[block_pointed1].type;
546           frag_size2 = 1 << heapinfo1[block_pointed2].type;
547
548           addr_frag_pointed1 = (void*) ((char *)addr_block_pointed1 + (frag_pointed1 * frag_size1));
549           addr_frag_pointed2 = (void*) ((char *)addr_block_pointed2 + (frag_pointed2 * frag_size2));
550
551           if(add_heap_area_pair(previous, block_pointed1, frag_pointed1, block_pointed2, frag_pointed2)){
552
553             if(ignore_done < xbt_dynar_length(mmalloc_ignore)){
554               if(in_mmalloc_ignore(block_pointed1, frag_pointed1))
555                 res_compare = compare_area(addr_frag_pointed1, addr_frag_pointed2, heapinfo1[block_pointed1].busy_frag.frag_size[frag_pointed1], previous, 1);
556               else
557                 res_compare = compare_area(addr_frag_pointed1, addr_frag_pointed2, heapinfo1[block_pointed1].busy_frag.frag_size[frag_pointed1], previous, 0);
558             }else{
559               res_compare = compare_area(addr_frag_pointed1, addr_frag_pointed2, heapinfo1[block_pointed1].busy_frag.frag_size[frag_pointed1], previous, 0);
560             }
561             
562             if(res_compare)
563               return 1;
564            
565           }
566
567         }else{
568           return 1;
569         }
570
571       }
572
573       i = pointer_align + sizeof(void *);
574       
575     }else{
576
577       i++;
578
579     }
580   }
581
582   return 0;
583   
584
585 }
586
587 static void heap_area_pair_free(heap_area_pair_t pair){
588   if (pair){
589     free(pair);
590     pair = NULL;
591   }
592 }
593
594 static void heap_area_pair_free_voidp(void *d)
595 {
596   heap_area_pair_free((heap_area_pair_t) * (void **) d);
597 }
598
599 static int add_heap_area_pair(xbt_dynar_t list, int block1, int fragment1, int block2, int fragment2){
600
601   if(is_new_heap_area_pair(list, block1, fragment1, block2, fragment2)){
602     heap_area_pair_t pair = NULL;
603     pair = xbt_new0(s_heap_area_pair_t, 1);
604     pair->block1 = block1;
605     pair->fragment1 = fragment1;
606     pair->block2 = block2;
607     pair->fragment2 = fragment2;
608     
609     xbt_dynar_push(list, &pair); 
610
611     return 1;
612   }
613
614   return 0;
615 }
616  
617 static int is_new_heap_area_pair(xbt_dynar_t list, int block1, int fragment1, int block2, int fragment2){
618   
619   unsigned int cursor = 0;
620   heap_area_pair_t current_pair;
621
622   xbt_dynar_foreach(list, cursor, current_pair){
623     if(current_pair->block1 == block1 && current_pair->block2 == block2 && current_pair->fragment1 == fragment1 && current_pair->fragment2 == fragment2)
624       return 0; 
625   }
626   
627   return 1;
628 }
629
630 static void match_equals(xbt_dynar_t list){
631
632   unsigned int cursor = 0;
633   heap_area_pair_t current_pair;
634
635   xbt_dynar_foreach(list, cursor, current_pair){
636     if(current_pair->fragment1 != -1){
637       heapinfo1[current_pair->block1].busy_frag.equal_to[current_pair->fragment1] = 1;
638       heapinfo2[current_pair->block2].busy_frag.equal_to[current_pair->fragment2] = 1;
639     }else{
640       heapinfo1[current_pair->block1].busy_block.equal_to = 1;
641       heapinfo2[current_pair->block2].busy_block.equal_to = 1;
642     }
643   }
644
645 }
646