Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
0725a9c129c6702cab44dafb4b885babda26f686
[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               xbt_dynar_reset(previous);
282               break;
283             }
284
285             xbt_dynar_reset(previous);
286
287           }
288
289           i2++;
290
291         }
292
293       }
294
295     }
296
297     i1++;
298
299   }
300
301   /* All blocks/fragments are equal to another block/fragment ? */
302   size_t i = 1, j = 0;
303   int nb_diff1 = 0, nb_diff2 = 0;
304   size_t frag_size = 0;
305  
306   while(i<heaplimit){
307     if(heapinfo1[i].type == 0){
308       if(heapinfo1[i].busy_block.busy_size > 0){
309         if(heapinfo1[i].busy_block.equal_to == -1){
310           if(XBT_LOG_ISENABLED(mm_diff, xbt_log_priority_debug)){
311             addr_block1 = ((void*) (((ADDR2UINT(i)) - 1) * BLOCKSIZE + (char*)heapbase1));
312             XBT_DEBUG("Block %zu (%p) not found (size used = %zu)", i, addr_block1, heapinfo1[i].busy_block.busy_size);
313             mmalloc_backtrace_block_display((void*)heapinfo1, i);
314           }
315           nb_diff1++;
316         }
317       }
318     }
319     if(heapinfo1[i].type > 0){
320       frag_size = 1 << heapinfo1[i].type;
321       for(j=0; j < (size_t) (BLOCKSIZE >> heapinfo1[i].type); j++){
322         if(heapinfo1[i].busy_frag.frag_size[j] > 0){
323           if(heapinfo1[i].busy_frag.equal_to[j] == -1){
324             if(XBT_LOG_ISENABLED(mm_diff, xbt_log_priority_debug)){
325               addr_block1 = ((void*) (((ADDR2UINT(i)) - 1) * BLOCKSIZE + (char*)heapbase1));
326               addr_frag1 = (void*) ((char *)addr_block1 + (j * frag_size));
327               XBT_DEBUG("Block %zu, Fragment %zu (%p) not found (size used = %d)", i, j, addr_frag1, heapinfo1[i].busy_frag.frag_size[j]);
328               mmalloc_backtrace_fragment_display((void*)heapinfo1, i, j);
329             }
330             nb_diff1++;
331           }
332         }
333       }
334     }
335     
336     i++; 
337   }
338
339   XBT_DEBUG("Different blocks or fragments in heap1 : %d\n", nb_diff1);
340
341   i = 1;
342
343   while(i<heaplimit){
344     if(heapinfo2[i].type == 0){
345       if(heapinfo2[i].busy_block.busy_size > 0){
346         if(heapinfo2[i].busy_block.equal_to == -1){
347           if(XBT_LOG_ISENABLED(mm_diff, xbt_log_priority_debug)){
348             addr_block2 = ((void*) (((ADDR2UINT(i)) - 1) * BLOCKSIZE + (char*)heapbase2));
349             XBT_DEBUG("Block %zu (%p) not found (size used = %zu)", i, addr_block2, heapinfo2[i].busy_block.busy_size);
350             mmalloc_backtrace_block_display((void*)heapinfo2, i);
351           }
352           nb_diff2++;
353         }
354       }
355     }
356     if(heapinfo2[i].type > 0){
357       frag_size = 1 << heapinfo2[i].type;
358       for(j=0; j < (size_t) (BLOCKSIZE >> heapinfo2[i].type); j++){
359         if(heapinfo2[i].busy_frag.frag_size[j] > 0){
360           if(heapinfo2[i].busy_frag.equal_to[j] == -1){
361             if(XBT_LOG_ISENABLED(mm_diff, xbt_log_priority_debug)){
362               addr_block2 = ((void*) (((ADDR2UINT(i)) - 1) * BLOCKSIZE + (char*)heapbase2));
363               addr_frag2 = (void*) ((char *)addr_block2 + (j * frag_size));
364               XBT_DEBUG( "Block %zu, Fragment %zu (%p) not found (size used = %d)", i, j, addr_frag2, heapinfo2[i].busy_frag.frag_size[j]);
365               mmalloc_backtrace_fragment_display((void*)heapinfo2, i, j);
366             }
367             nb_diff2++;
368           }
369         }
370       }
371     }
372     i++; 
373   }
374
375   XBT_DEBUG("Different blocks or fragments in heap2 : %d\n", nb_diff2);
376
377   xbt_dynar_free(&previous);
378  
379   return ((nb_diff1 > 0) || (nb_diff2 > 0));
380
381 }
382
383 static int in_mmalloc_ignore(int block, int fragment){
384
385   unsigned int cursor = 0;
386   int start = 0;
387   int end = xbt_dynar_length(mmalloc_ignore) - 1;
388   mc_ignore_region_t region;
389
390   while(start <= end){
391     cursor = (start + end) / 2;
392     region = (mc_ignore_region_t)xbt_dynar_get_as(mmalloc_ignore, cursor, mc_ignore_region_t);
393     if(region->block == block){
394       if(region->fragment == fragment)
395         return 1;
396       if(region->fragment < fragment)
397         start = cursor + 1;
398       if(region->fragment > fragment)
399         end = cursor - 1;
400     }
401     if(region->block < block)
402       start = cursor + 1;
403     if(region->block > block)
404       end = cursor - 1; 
405   }
406
407   return 0;
408 }
409
410 static size_t heap_comparison_ignore(void *address){
411   unsigned int cursor = 0;
412   int start = 0;
413   int end = xbt_dynar_length(mmalloc_ignore) - 1;
414   mc_ignore_region_t region;
415
416   while(start <= end){
417     cursor = (start + end) / 2;
418     region = (mc_ignore_region_t)xbt_dynar_get_as(mmalloc_ignore, cursor, mc_ignore_region_t);
419     if(region->address == address)
420       return region->size;
421     if(region->address < address)
422       start = cursor + 1;
423     if(region->address > address)
424       end = cursor - 1;   
425   }
426
427   return 0;
428 }
429
430
431 static int compare_area(void *area1, void* area2, size_t size, xbt_dynar_t previous, int check_ignore){
432
433   size_t i = 0, pointer_align = 0, ignore1 = 0, ignore2 = 0;
434   void *address_pointed1, *address_pointed2, *addr_block_pointed1, *addr_block_pointed2, *addr_frag_pointed1, *addr_frag_pointed2;
435   size_t block_pointed1, block_pointed2, frag_pointed1, frag_pointed2;
436   size_t frag_size, frag_size1, frag_size2;
437   int res_compare;
438   void *current_area1, *current_area2;
439  
440   while(i<size){
441
442     if(check_ignore){
443
444       current_area1 = (char*)((xbt_mheap_t)s_heap)->heapbase + ((((char *)area1) + i) - (char *)heapbase1);
445       if((ignore1 = heap_comparison_ignore(current_area1)) > 0){
446         current_area2 = (char*)((xbt_mheap_t)s_heap)->heapbase + ((((char *)area2) + i) - (char *)heapbase2);
447         if((ignore2 = heap_comparison_ignore(current_area2))  == ignore1){
448           i = i + ignore2;
449           ignore_done++;
450           continue;
451         }
452       }
453
454     }
455    
456     if(memcmp(((char *)area1) + i, ((char *)area2) + i, 1) != 0){
457
458       /* Check pointer difference */
459       pointer_align = (i / sizeof(void*)) * sizeof(void*);
460       address_pointed1 = *((void **)((char *)area1 + pointer_align));
461       address_pointed2 = *((void **)((char *)area2 + pointer_align));
462
463       /* Get pointed blocks number */ 
464       block_pointed1 = ((char*)address_pointed1 - (char*)((xbt_mheap_t)s_heap)->heapbase) / BLOCKSIZE + 1;
465       block_pointed2 = ((char*)address_pointed2 - (char*)((xbt_mheap_t)s_heap)->heapbase) / BLOCKSIZE + 1;
466
467       /* Check if valid blocks number */
468       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)
469         return 1;
470
471       if(heapinfo1[block_pointed1].type == heapinfo2[block_pointed2].type){ /* Same type of block (large or fragmented) */
472
473         addr_block_pointed1 = ((void*) (((ADDR2UINT(block_pointed1)) - 1) * BLOCKSIZE + (char*)heapbase1));
474         addr_block_pointed2 = ((void*) (((ADDR2UINT(block_pointed2)) - 1) * BLOCKSIZE + (char*)heapbase2));
475         
476         if(heapinfo1[block_pointed1].type == 0){ /* Large block */
477
478           if(heapinfo1[block_pointed1].busy_block.size != heapinfo2[block_pointed2].busy_block.size){
479             return 1;
480           }
481
482           if(heapinfo1[block_pointed1].busy_block.busy_size != heapinfo2[block_pointed2].busy_block.busy_size){
483             return 1;
484           }
485
486           if(add_heap_area_pair(previous, block_pointed1, -1, block_pointed2, -1)){
487
488             if(ignore_done < xbt_dynar_length(mmalloc_ignore)){
489               if(in_mmalloc_ignore(block_pointed1, -1))
490                 res_compare = compare_area(addr_block_pointed1, addr_block_pointed2, heapinfo1[block_pointed1].busy_block.busy_size, previous, 1);
491               else
492                 res_compare = compare_area(addr_block_pointed1, addr_block_pointed2, heapinfo1[block_pointed1].busy_block.busy_size, previous, 0);
493             }else{
494               res_compare = compare_area(addr_block_pointed1, addr_block_pointed2, heapinfo1[block_pointed1].busy_block.busy_size, previous, 0);
495             }
496             
497             if(res_compare)    
498               return 1;
499            
500           }
501           
502         }else{ /* Fragmented block */
503
504            /* Get pointed fragments number */ 
505           frag_pointed1 = ((uintptr_t) (ADDR2UINT (address_pointed1) % (BLOCKSIZE))) >> heapinfo1[block_pointed1].type;
506           frag_pointed2 = ((uintptr_t) (ADDR2UINT (address_pointed2) % (BLOCKSIZE))) >> heapinfo2[block_pointed2].type;
507          
508           if(heapinfo1[block_pointed1].busy_frag.frag_size[frag_pointed1] != heapinfo2[block_pointed2].busy_frag.frag_size[frag_pointed2]) /* Different size_used */    
509             return 1;
510
511           frag_size = 1 << heapinfo1[block_pointed1].type;
512             
513           addr_frag_pointed1 = (void*) ((char *)addr_block_pointed1 + (frag_pointed1 * frag_size));
514           addr_frag_pointed2 = (void*) ((char *)addr_block_pointed2 + (frag_pointed2 * frag_size));
515
516           if(add_heap_area_pair(previous, block_pointed1, frag_pointed1, block_pointed2, frag_pointed2)){
517
518             if(ignore_done < xbt_dynar_length(mmalloc_ignore)){
519               if(in_mmalloc_ignore(block_pointed1, frag_pointed1))
520                 res_compare = compare_area(addr_frag_pointed1, addr_frag_pointed2, heapinfo1[block_pointed1].busy_frag.frag_size[frag_pointed1], previous, 1);
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             }else{
524               res_compare = compare_area(addr_frag_pointed1, addr_frag_pointed2, heapinfo1[block_pointed1].busy_frag.frag_size[frag_pointed1], previous, 0);
525             }
526
527             if(res_compare)
528               return 1;
529            
530           }
531           
532         }
533           
534       }else{
535
536         if((heapinfo1[block_pointed1].type > 0) && (heapinfo2[block_pointed2].type > 0)){
537           
538           addr_block_pointed1 = ((void*) (((ADDR2UINT(block_pointed1)) - 1) * BLOCKSIZE + (char*)heapbase1));
539           addr_block_pointed2 = ((void*) (((ADDR2UINT(block_pointed2)) - 1) * BLOCKSIZE + (char*)heapbase2));
540        
541           frag_pointed1 = ((uintptr_t) (ADDR2UINT (address_pointed1) % (BLOCKSIZE))) >> heapinfo1[block_pointed1].type;
542           frag_pointed2 = ((uintptr_t) (ADDR2UINT (address_pointed2) % (BLOCKSIZE))) >> heapinfo2[block_pointed2].type;
543
544           if(heapinfo1[block_pointed1].busy_frag.frag_size[frag_pointed1] != heapinfo2[block_pointed2].busy_frag.frag_size[frag_pointed2]) /* Different size_used */    
545             return 1;
546           
547           frag_size1 = 1 << heapinfo1[block_pointed1].type;
548           frag_size2 = 1 << heapinfo1[block_pointed2].type;
549
550           addr_frag_pointed1 = (void*) ((char *)addr_block_pointed1 + (frag_pointed1 * frag_size1));
551           addr_frag_pointed2 = (void*) ((char *)addr_block_pointed2 + (frag_pointed2 * frag_size2));
552
553           if(add_heap_area_pair(previous, block_pointed1, frag_pointed1, block_pointed2, frag_pointed2)){
554
555             if(ignore_done < xbt_dynar_length(mmalloc_ignore)){
556               if(in_mmalloc_ignore(block_pointed1, frag_pointed1))
557                 res_compare = compare_area(addr_frag_pointed1, addr_frag_pointed2, heapinfo1[block_pointed1].busy_frag.frag_size[frag_pointed1], previous, 1);
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             }else{
561               res_compare = compare_area(addr_frag_pointed1, addr_frag_pointed2, heapinfo1[block_pointed1].busy_frag.frag_size[frag_pointed1], previous, 0);
562             }
563             
564             if(res_compare)
565               return 1;
566            
567           }
568
569         }else{
570           return 1;
571         }
572
573       }
574
575       i = pointer_align + sizeof(void *);
576       
577     }else{
578
579       i++;
580
581     }
582   }
583
584   return 0;
585   
586
587 }
588
589 static void heap_area_pair_free(heap_area_pair_t pair){
590   if (pair){
591     free(pair);
592     pair = NULL;
593   }
594 }
595
596 static void heap_area_pair_free_voidp(void *d)
597 {
598   heap_area_pair_free((heap_area_pair_t) * (void **) d);
599 }
600
601 static int add_heap_area_pair(xbt_dynar_t list, int block1, int fragment1, int block2, int fragment2){
602
603   if(is_new_heap_area_pair(list, block1, fragment1, block2, fragment2)){
604     heap_area_pair_t pair = NULL;
605     pair = xbt_new0(s_heap_area_pair_t, 1);
606     pair->block1 = block1;
607     pair->fragment1 = fragment1;
608     pair->block2 = block2;
609     pair->fragment2 = fragment2;
610     
611     xbt_dynar_push(list, &pair); 
612
613     return 1;
614   }
615
616   return 0;
617 }
618  
619 static int is_new_heap_area_pair(xbt_dynar_t list, int block1, int fragment1, int block2, int fragment2){
620   
621   unsigned int cursor = 0;
622   heap_area_pair_t current_pair;
623
624   xbt_dynar_foreach(list, cursor, current_pair){
625     if(current_pair->block1 == block1 && current_pair->block2 == block2 && current_pair->fragment1 == fragment1 && current_pair->fragment2 == fragment2)
626       return 0; 
627   }
628   
629   return 1;
630 }
631
632 static void match_equals(xbt_dynar_t list){
633
634   unsigned int cursor = 0;
635   heap_area_pair_t current_pair;
636
637   xbt_dynar_foreach(list, cursor, current_pair){
638     if(current_pair->fragment1 != -1){
639       heapinfo1[current_pair->block1].busy_frag.equal_to[current_pair->fragment1] = 1;
640       heapinfo2[current_pair->block2].busy_frag.equal_to[current_pair->fragment2] = 1;
641     }else{
642       heapinfo1[current_pair->block1].busy_block.equal_to = 1;
643       heapinfo2[current_pair->block2].busy_block.equal_to = 1;
644     }
645   }
646
647 }
648