Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[smpi,simix-network] remove a useless function
[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   /* Check busy blocks*/
132
133   i1 = 1;
134
135   while(i1 < heaplimit){
136
137     i2 = 1;
138     equal = 0;
139
140     if(heapinfo1[i1].type == -1){ /* Free block */
141       i1++;
142       continue;
143     }
144
145     addr_block1 = ((void*) (((ADDR2UINT(i1)) - 1) * BLOCKSIZE + (char*)heapbase1));
146
147     if(heapinfo1[i1].type == 0){  /* Large block */
148
149       while(i2 <= heaplimit && !equal){
150
151         if(heapinfo2[i2].type != 0){
152           i2++;
153           continue;
154         }
155
156         if(heapinfo2[i2].busy_block.equal_to == 1){         
157           i2++;
158           continue;
159         }
160         
161         if(heapinfo1[i1].busy_block.size != heapinfo2[i2].busy_block.size){
162           i2++;
163           continue;
164         }
165         
166         if(heapinfo1[i1].busy_block.busy_size != heapinfo2[i2].busy_block.busy_size){
167           i2++;
168           continue;
169         }
170
171         addr_block2 = ((void*) (((ADDR2UINT(i2)) - 1) * BLOCKSIZE + (char*)heapbase2));
172
173         /* Comparison */
174         add_heap_area_pair(previous, i1, -1, i2, -1);
175         
176         if(ignore_done < xbt_dynar_length(mmalloc_ignore)){
177           if(in_mmalloc_ignore((int)i1, -1))
178             res_compare = compare_area(addr_block1, addr_block2, heapinfo1[i1].busy_block.busy_size, previous, 1);
179           else
180             res_compare = compare_area(addr_block1, addr_block2, heapinfo1[i1].busy_block.busy_size, previous, 0);
181         }else{
182           res_compare = compare_area(addr_block1, addr_block2, heapinfo1[i1].busy_block.busy_size, previous, 0);
183         }
184         
185         if(!res_compare){
186           for(k=0; k < heapinfo2[i2].busy_block.size; k++)
187             heapinfo2[i2+k].busy_block.equal_to = 1;
188           for(k=0; k < heapinfo1[i1].busy_block.size; k++)
189             heapinfo1[i1+k].busy_block.equal_to = 1;
190           equal = 1;
191           match_equals(previous);
192         }
193         xbt_dynar_reset(previous);
194
195         i2++;
196
197       }
198
199     }else{ /* Fragmented block */
200
201       frag_size1 = 1 << heapinfo1[i1].type;
202
203       for(j1=0; j1 < (size_t) (BLOCKSIZE >> heapinfo1[i1].type); j1++){
204
205         if(heapinfo1[i1].busy_frag.frag_size[j1] == 0) /* Free fragment */
206           continue;
207         
208         addr_frag1 = (void*) ((char *)addr_block1 + (j1 * frag_size1));
209         
210         i2 = 1;
211         equal = 0;
212         
213         while(i2 <= heaplimit && !equal){
214           
215           if(heapinfo2[i2].type <= 0){
216             i2++;
217             continue;
218           }
219           
220           frag_size2 = 1 << heapinfo2[i2].type;
221
222           for(j2=0; j2 < (size_t) (BLOCKSIZE >> heapinfo2[i2].type); j2++){
223
224             if(heapinfo2[i2].busy_frag.equal_to[j2] == 1){                 
225               continue;              
226             }
227              
228             if(heapinfo1[i1].busy_frag.frag_size[j1] != heapinfo2[i2].busy_frag.frag_size[j2]){ /* Different size_used */    
229               continue;
230             }
231              
232             addr_block2 = ((void*) (((ADDR2UINT(i2)) - 1) * BLOCKSIZE + (char*)heapbase2));
233             addr_frag2 = (void*) ((char *)addr_block2 + (j2 * frag_size2));
234              
235             /* Comparison */
236             add_heap_area_pair(previous, i1, j1, i2, j2);
237             
238             if(ignore_done < xbt_dynar_length(mmalloc_ignore)){
239               if(in_mmalloc_ignore((int)i1, (int)j1))
240                 res_compare = compare_area(addr_frag1, addr_frag2, heapinfo1[i1].busy_frag.frag_size[j1], previous, 1);
241               else
242                 res_compare = compare_area(addr_frag1, addr_frag2, heapinfo1[i1].busy_frag.frag_size[j1], previous, 0);
243             }else{
244               res_compare = compare_area(addr_frag1, addr_frag2, heapinfo1[i1].busy_frag.frag_size[j1], previous, 0);
245             }
246
247             if(!res_compare){
248               heapinfo2[i2].busy_frag.equal_to[j2] = 1;
249               heapinfo1[i1].busy_frag.equal_to[j1] = 1;
250               equal = 1;
251               match_equals(previous);
252               break;
253             }
254             xbt_dynar_reset(previous);
255
256           }
257
258           i2++;
259
260         }
261
262       }
263
264     }
265
266     i1++;
267
268   }
269
270   /* All blocks/fragments are equal to another block/fragment ? */
271   size_t i = 1, j = 0;
272   int nb_diff1 = 0, nb_diff2 = 0;
273   size_t frag_size = 0;
274  
275   while(i<heaplimit){
276     if(heapinfo1[i].type == 0){
277       if(heapinfo1[i].busy_block.busy_size > 0){
278         if(heapinfo1[i].busy_block.equal_to == -1){
279           if(XBT_LOG_ISENABLED(mm_diff, xbt_log_priority_debug)){
280             addr_block1 = ((void*) (((ADDR2UINT(i)) - 1) * BLOCKSIZE + (char*)heapbase1));
281             XBT_DEBUG("Block %zu (%p) not found (size used = %zu)", i, addr_block1, heapinfo1[i].busy_block.busy_size);
282             mmalloc_backtrace_block_display((void*)heapinfo1, i);
283           }
284           nb_diff1++;
285         }
286       }
287     }
288     if(heapinfo1[i].type > 0){
289       frag_size = 1 << heapinfo1[i].type;
290       for(j=0; j < (size_t) (BLOCKSIZE >> heapinfo1[i].type); j++){
291         if(heapinfo1[i].busy_frag.frag_size[j] > 0){
292           if(heapinfo1[i].busy_frag.equal_to[j] == -1){
293             if(XBT_LOG_ISENABLED(mm_diff, xbt_log_priority_debug)){
294               addr_block1 = ((void*) (((ADDR2UINT(i)) - 1) * BLOCKSIZE + (char*)heapbase1));
295               addr_frag1 = (void*) ((char *)addr_block1 + (j * frag_size));
296               XBT_DEBUG("Block %zu, Fragment %zu (%p) not found (size used = %d)", i, j, addr_frag1, heapinfo1[i].busy_frag.frag_size[j]);
297               mmalloc_backtrace_fragment_display((void*)heapinfo1, i, j);
298             }
299             nb_diff1++;
300           }
301         }
302       }
303     }
304     
305     i++; 
306   }
307
308   XBT_DEBUG("Different blocks or fragments in heap1 : %d\n", nb_diff1);
309
310   i = 1;
311
312   while(i<heaplimit){
313     if(heapinfo2[i].type == 0){
314       if(heapinfo2[i].busy_block.busy_size > 0){
315         if(heapinfo2[i].busy_block.equal_to == -1){
316           if(XBT_LOG_ISENABLED(mm_diff, xbt_log_priority_debug)){
317             addr_block2 = ((void*) (((ADDR2UINT(i)) - 1) * BLOCKSIZE + (char*)heapbase2));
318             XBT_DEBUG("Block %zu (%p) not found (size used = %zu)", i, addr_block2, heapinfo2[i].busy_block.busy_size);
319             mmalloc_backtrace_block_display((void*)heapinfo2, i);
320           }
321           nb_diff2++;
322         }
323       }
324     }
325     if(heapinfo2[i].type > 0){
326       frag_size = 1 << heapinfo2[i].type;
327       for(j=0; j < (size_t) (BLOCKSIZE >> heapinfo2[i].type); j++){
328         if(heapinfo2[i].busy_frag.frag_size[j] > 0){
329           if(heapinfo2[i].busy_frag.equal_to[j] == -1){
330             if(XBT_LOG_ISENABLED(mm_diff, xbt_log_priority_debug)){
331               addr_block2 = ((void*) (((ADDR2UINT(i)) - 1) * BLOCKSIZE + (char*)heapbase2));
332               addr_frag2 = (void*) ((char *)addr_block2 + (j * frag_size));
333               XBT_DEBUG( "Block %zu, Fragment %zu (%p) not found (size used = %d)", i, j, addr_frag2, heapinfo2[i].busy_frag.frag_size[j]);
334               mmalloc_backtrace_fragment_display((void*)heapinfo2, i, j);
335             }
336             nb_diff2++;
337           }
338         }
339       }
340     }
341     i++; 
342   }
343
344   XBT_DEBUG("Different blocks or fragments in heap2 : %d\n", nb_diff2);
345   
346   
347   /* Reset equal information */
348   i = 1;
349
350   while(i<heaplimit){
351     if(heapinfo1[i].type == 0){
352       heapinfo1[i].busy_block.equal_to = -1;
353     }
354     if(heapinfo1[i].type > 0){
355       for(j=0; j < MAX_FRAGMENT_PER_BLOCK; j++){
356         heapinfo1[i].busy_frag.equal_to[j] = -1;
357       }
358     }
359     i++; 
360   }
361
362   i = 1;
363
364   while(i<heaplimit){
365     if(heapinfo2[i].type == 0){
366       heapinfo2[i].busy_block.equal_to = -1;
367     }
368     if(heapinfo2[i].type > 0){
369       for(j=0; j < MAX_FRAGMENT_PER_BLOCK; j++){
370         heapinfo2[i].busy_frag.equal_to[j] = -1;
371       }
372     }
373     i++; 
374   }
375
376   xbt_dynar_free(&previous);
377  
378   return ((nb_diff1 > 0) || (nb_diff2 > 0));
379
380 }
381
382 static int in_mmalloc_ignore(int block, int fragment){
383
384   unsigned int cursor = 0;
385   int start = 0;
386   int end = xbt_dynar_length(mmalloc_ignore) - 1;
387   mc_ignore_region_t region;
388
389   while(start <= end){
390     cursor = (start + end) / 2;
391     region = (mc_ignore_region_t)xbt_dynar_get_as(mmalloc_ignore, cursor, mc_ignore_region_t);
392     if(region->block == block){
393       if(region->fragment == fragment)
394         return 1;
395       if(region->fragment < fragment)
396         start = cursor + 1;
397       if(region->fragment > fragment)
398         end = cursor - 1;
399     }
400     if(region->block < block)
401       start = cursor + 1;
402     if(region->block > block)
403       end = cursor - 1; 
404   }
405
406   return 0;
407 }
408
409 static size_t heap_comparison_ignore(void *address){
410   unsigned int cursor = 0;
411   int start = 0;
412   int end = xbt_dynar_length(mmalloc_ignore) - 1;
413   mc_ignore_region_t region;
414
415   while(start <= end){
416     cursor = (start + end) / 2;
417     region = (mc_ignore_region_t)xbt_dynar_get_as(mmalloc_ignore, cursor, mc_ignore_region_t);
418     if(region->address == address)
419       return region->size;
420     if(region->address < address)
421       start = cursor + 1;
422     if(region->address > address)
423       end = cursor - 1;   
424   }
425
426   return 0;
427 }
428
429
430 static int compare_area(void *area1, void* area2, size_t size, xbt_dynar_t previous, int check_ignore){
431
432   size_t i = 0, pointer_align = 0, ignore1 = 0, ignore2 = 0;
433   void *address_pointed1, *address_pointed2, *addr_block_pointed1, *addr_block_pointed2, *addr_frag_pointed1, *addr_frag_pointed2;
434   size_t block_pointed1, block_pointed2, frag_pointed1, frag_pointed2;
435   size_t frag_size, frag_size1, frag_size2;
436   int res_compare;
437   void *current_area1, *current_area2;
438  
439   while(i<size){
440
441     if(check_ignore){
442
443       current_area1 = (char*)((xbt_mheap_t)s_heap)->heapbase + ((((char *)area1) + i) - (char *)heapbase1);
444       if((ignore1 = heap_comparison_ignore(current_area1)) > 0){
445         current_area2 = (char*)((xbt_mheap_t)s_heap)->heapbase + ((((char *)area2) + i) - (char *)heapbase2);
446         if((ignore2 = heap_comparison_ignore(current_area2))  == ignore1){
447           i = i + ignore2;
448           ignore_done++;
449           continue;
450         }
451       }
452
453     }
454    
455     if(memcmp(((char *)area1) + i, ((char *)area2) + i, 1) != 0){
456
457       /* Check pointer difference */
458       pointer_align = (i / sizeof(void*)) * sizeof(void*);
459       address_pointed1 = *((void **)((char *)area1 + pointer_align));
460       address_pointed2 = *((void **)((char *)area2 + pointer_align));
461
462       /* Get pointed blocks number */ 
463       block_pointed1 = ((char*)address_pointed1 - (char*)((xbt_mheap_t)s_heap)->heapbase) / BLOCKSIZE + 1;
464       block_pointed2 = ((char*)address_pointed2 - (char*)((xbt_mheap_t)s_heap)->heapbase) / BLOCKSIZE + 1;
465
466       /* Check if valid blocks number */
467       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)
468         return 1;
469
470       if(heapinfo1[block_pointed1].type == heapinfo2[block_pointed2].type){ /* Same type of block (large or fragmented) */
471
472         addr_block_pointed1 = ((void*) (((ADDR2UINT(block_pointed1)) - 1) * BLOCKSIZE + (char*)heapbase1));
473         addr_block_pointed2 = ((void*) (((ADDR2UINT(block_pointed2)) - 1) * BLOCKSIZE + (char*)heapbase2));
474         
475         if(heapinfo1[block_pointed1].type == 0){ /* Large block */
476
477           if(heapinfo1[block_pointed1].busy_block.size != heapinfo2[block_pointed2].busy_block.size){
478             return 1;
479           }
480
481           if(heapinfo1[block_pointed1].busy_block.busy_size != heapinfo2[block_pointed2].busy_block.busy_size){
482             return 1;
483           }
484
485           if(add_heap_area_pair(previous, block_pointed1, -1, block_pointed2, -1)){
486
487             if(ignore_done < xbt_dynar_length(mmalloc_ignore)){
488               if(in_mmalloc_ignore(block_pointed1, -1))
489                 res_compare = compare_area(addr_block_pointed1, addr_block_pointed2, heapinfo1[block_pointed1].busy_block.busy_size, previous, 1);
490               else
491                 res_compare = compare_area(addr_block_pointed1, addr_block_pointed2, heapinfo1[block_pointed1].busy_block.busy_size, previous, 0);
492             }else{
493               res_compare = compare_area(addr_block_pointed1, addr_block_pointed2, heapinfo1[block_pointed1].busy_block.busy_size, previous, 0);
494             }
495             
496             if(res_compare)    
497               return 1;
498            
499           }
500           
501         }else{ /* Fragmented block */
502
503            /* Get pointed fragments number */ 
504           frag_pointed1 = ((uintptr_t) (ADDR2UINT (address_pointed1) % (BLOCKSIZE))) >> heapinfo1[block_pointed1].type;
505           frag_pointed2 = ((uintptr_t) (ADDR2UINT (address_pointed2) % (BLOCKSIZE))) >> heapinfo2[block_pointed2].type;
506          
507           if(heapinfo1[block_pointed1].busy_frag.frag_size[frag_pointed1] != heapinfo2[block_pointed2].busy_frag.frag_size[frag_pointed2]) /* Different size_used */    
508             return 1;
509
510           frag_size = 1 << heapinfo1[block_pointed1].type;
511             
512           addr_frag_pointed1 = (void*) ((char *)addr_block_pointed1 + (frag_pointed1 * frag_size));
513           addr_frag_pointed2 = (void*) ((char *)addr_block_pointed2 + (frag_pointed2 * frag_size));
514
515           if(add_heap_area_pair(previous, block_pointed1, frag_pointed1, block_pointed2, frag_pointed2)){
516
517             if(ignore_done < xbt_dynar_length(mmalloc_ignore)){
518               if(in_mmalloc_ignore(block_pointed1, frag_pointed1))
519                 res_compare = compare_area(addr_frag_pointed1, addr_frag_pointed2, heapinfo1[block_pointed1].busy_frag.frag_size[frag_pointed1], previous, 1);
520               else
521                 res_compare = compare_area(addr_frag_pointed1, addr_frag_pointed2, heapinfo1[block_pointed1].busy_frag.frag_size[frag_pointed1], previous, 0);
522             }else{
523               res_compare = compare_area(addr_frag_pointed1, addr_frag_pointed2, heapinfo1[block_pointed1].busy_frag.frag_size[frag_pointed1], previous, 0);
524             }
525
526             if(res_compare)
527               return 1;
528            
529           }
530           
531         }
532           
533       }else{
534
535         if((heapinfo1[block_pointed1].type > 0) && (heapinfo2[block_pointed2].type > 0)){
536           
537           addr_block_pointed1 = ((void*) (((ADDR2UINT(block_pointed1)) - 1) * BLOCKSIZE + (char*)heapbase1));
538           addr_block_pointed2 = ((void*) (((ADDR2UINT(block_pointed2)) - 1) * BLOCKSIZE + (char*)heapbase2));
539        
540           frag_pointed1 = ((uintptr_t) (ADDR2UINT (address_pointed1) % (BLOCKSIZE))) >> heapinfo1[block_pointed1].type;
541           frag_pointed2 = ((uintptr_t) (ADDR2UINT (address_pointed2) % (BLOCKSIZE))) >> heapinfo2[block_pointed2].type;
542
543           if(heapinfo1[block_pointed1].busy_frag.frag_size[frag_pointed1] != heapinfo2[block_pointed2].busy_frag.frag_size[frag_pointed2]) /* Different size_used */    
544             return 1;
545           
546           frag_size1 = 1 << heapinfo1[block_pointed1].type;
547           frag_size2 = 1 << heapinfo1[block_pointed2].type;
548
549           addr_frag_pointed1 = (void*) ((char *)addr_block_pointed1 + (frag_pointed1 * frag_size1));
550           addr_frag_pointed2 = (void*) ((char *)addr_block_pointed2 + (frag_pointed2 * frag_size2));
551
552           if(add_heap_area_pair(previous, block_pointed1, frag_pointed1, block_pointed2, frag_pointed2)){
553
554             if(ignore_done < xbt_dynar_length(mmalloc_ignore)){
555               if(in_mmalloc_ignore(block_pointed1, frag_pointed1))
556                 res_compare = compare_area(addr_frag_pointed1, addr_frag_pointed2, heapinfo1[block_pointed1].busy_frag.frag_size[frag_pointed1], previous, 1);
557               else
558                 res_compare = compare_area(addr_frag_pointed1, addr_frag_pointed2, heapinfo1[block_pointed1].busy_frag.frag_size[frag_pointed1], previous, 0);
559             }else{
560               res_compare = compare_area(addr_frag_pointed1, addr_frag_pointed2, heapinfo1[block_pointed1].busy_frag.frag_size[frag_pointed1], previous, 0);
561             }
562             
563             if(res_compare)
564               return 1;
565            
566           }
567
568         }else{
569           return 1;
570         }
571
572       }
573
574       i = pointer_align + sizeof(void *);
575       
576     }else{
577
578       i++;
579
580     }
581   }
582
583   return 0;
584   
585
586 }
587
588 static void heap_area_pair_free(heap_area_pair_t pair){
589   if (pair){
590     free(pair);
591     pair = NULL;
592   }
593 }
594
595 static void heap_area_pair_free_voidp(void *d)
596 {
597   heap_area_pair_free((heap_area_pair_t) * (void **) d);
598 }
599
600 static int add_heap_area_pair(xbt_dynar_t list, int block1, int fragment1, int block2, int fragment2){
601
602   if(is_new_heap_area_pair(list, block1, fragment1, block2, fragment2)){
603     heap_area_pair_t pair = NULL;
604     pair = xbt_new0(s_heap_area_pair_t, 1);
605     pair->block1 = block1;
606     pair->fragment1 = fragment1;
607     pair->block2 = block2;
608     pair->fragment2 = fragment2;
609     
610     xbt_dynar_push(list, &pair); 
611
612     return 1;
613   }
614
615   return 0;
616 }
617  
618 static int is_new_heap_area_pair(xbt_dynar_t list, int block1, int fragment1, int block2, int fragment2){
619   
620   unsigned int cursor = 0;
621   heap_area_pair_t current_pair;
622
623   xbt_dynar_foreach(list, cursor, current_pair){
624     if(current_pair->block1 == block1 && current_pair->block2 == block2 && current_pair->fragment1 == fragment1 && current_pair->fragment2 == fragment2)
625       return 0; 
626   }
627   
628   return 1;
629 }
630
631 static void match_equals(xbt_dynar_t list){
632
633   unsigned int cursor = 0;
634   heap_area_pair_t current_pair;
635
636   xbt_dynar_foreach(list, cursor, current_pair){
637     if(current_pair->fragment1 != -1){
638       heapinfo1[current_pair->block1].busy_frag.equal_to[current_pair->fragment1] = 1;
639       heapinfo2[current_pair->block2].busy_frag.equal_to[current_pair->fragment2] = 1;
640     }else{
641       heapinfo1[current_pair->block1].busy_block.equal_to = 1;
642       heapinfo2[current_pair->block2].busy_block.equal_to = 1;
643     }
644   }
645
646 }
647