Logo AND Algorithmique Numérique Distribuée

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