Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
043bb8827e2b276faeb9ea02e7b55f955ddba2c2
[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 #include "xbt/mmalloc.h"
12
13 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mm_diff, xbt,
14                                 "Logging specific to mm_diff in mmalloc");
15
16 extern char *xbt_binary_name;
17
18 xbt_dynar_t mc_heap_comparison_ignore;
19 xbt_dynar_t stacks_areas;
20
21 static void heap_area_pair_free(heap_area_pair_t pair);
22 static void heap_area_pair_free_voidp(void *d);
23 static int add_heap_area_pair(xbt_dynar_t list, int block1, int fragment1, int block2, int fragment2);
24 static int is_new_heap_area_pair(xbt_dynar_t list, int block1, int fragment1, int block2, int fragment2);
25 static heap_area_t new_heap_area(int block, int fragment);
26
27 static int compare_area(void *area1, void* area2, size_t size, xbt_dynar_t previous, int check_ignore);
28 static void match_equals(xbt_dynar_t list, xbt_dynar_t *equals);
29
30 static int in_mc_comparison_ignore(int block, int fragment);
31 static size_t heap_comparison_ignore_size(void *address);
32 static void add_heap_equality(xbt_dynar_t *equals, void *a1, void *a2);
33 static void remove_heap_equality(xbt_dynar_t *equals, int address, void *a);
34
35 static char* is_stack(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     fprintf(stderr, "No backtrace available for that block, sorry.\n");
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     fprintf(stderr, "(backtrace not set)\n");
52   } else if (e.bt_strings == NULL) {
53     fprintf(stderr, "(backtrace not ready to be computed. %s)\n",xbt_binary_name?"Dunno why":"xbt_binary_name not setup yet");
54   } else {
55     int i;
56
57     fprintf(stderr, "Backtrace of where the block %d was malloced (%d frames):\n", block ,e.used);
58     for (i = 0; i < e.used; i++)       /* no need to display "xbt_backtrace_display" */{
59       fprintf(stderr, "%d ---> %s\n",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     fprintf(stderr, "(backtrace not set)\n");
75   } else if (e.bt_strings == NULL) {
76     fprintf(stderr, "(backtrace not ready to be computed. %s)\n",xbt_binary_name?"Dunno why":"xbt_binary_name not setup yet");
77   } else {
78     int i;
79
80     fprintf(stderr, "Backtrace of where the fragment %d in block %d was malloced (%d frames):\n", frag, block ,e.used);
81     for (i = 0; i < e.used; i++)       /* no need to display "xbt_backtrace_display" */{
82       fprintf(stderr, "%d ---> %s\n",i, e.bt_strings[i] + 4);
83     }
84   }
85
86 }
87
88 void mmalloc_backtrace_display(void *addr){
89
90   size_t block, frag_nb;
91   int type;
92   
93   xbt_mheap_t heap = __mmalloc_current_heap ?: (xbt_mheap_t) mmalloc_preinit();
94
95   block = (((char*) (addr) - (char*) heap -> heapbase) / BLOCKSIZE + 1);
96
97   type = heap->heapinfo[block].type;
98
99   switch(type){
100   case -1 : /* Free block */
101     fprintf(stderr, "Asked to display the backtrace of a block that is free. I'm puzzled\n");
102     xbt_abort();
103     break; 
104   case 0: /* Large block */
105     mmalloc_backtrace_block_display(heap->heapinfo, block);
106     break;
107   default: /* Fragmented block */
108     frag_nb = RESIDUAL(addr, BLOCKSIZE) >> type;
109     if(heap->heapinfo[block].busy_frag.frag_size[frag_nb] == -1){
110       fprintf(stderr , "Asked to display the backtrace of a fragment that is free. I'm puzzled\n");
111       xbt_abort();
112     }
113     mmalloc_backtrace_fragment_display(heap->heapinfo, block, frag_nb);
114     break;
115   }
116
117 }
118
119
120 void *s_heap = NULL, *heapbase1 = NULL, *heapbase2 = NULL;
121 malloc_info *heapinfo1 = NULL, *heapinfo2 = NULL;
122 size_t heaplimit = 0, heapsize1 = 0, heapsize2 = 0;
123
124 int ignore_done = 0;
125
126 int mmalloc_compare_heap(xbt_mheap_t heap1, xbt_mheap_t heap2, xbt_dynar_t *stack1, xbt_dynar_t *stack2, xbt_dynar_t *equals){
127
128   if(heap1 == NULL && heap1 == NULL){
129     XBT_DEBUG("Malloc descriptors null");
130     return 0;
131   }
132
133   if(heap1->heaplimit != heap2->heaplimit){
134     XBT_DEBUG("Different limit of valid info table indices");
135     return 1;
136   }
137
138   /* Heap information */
139   heaplimit = ((struct mdesc *)heap1)->heaplimit;
140
141   s_heap = (char *)mmalloc_get_current_heap() - STD_HEAP_SIZE - getpagesize();
142
143   heapbase1 = (char *)heap1 + BLOCKSIZE;
144   heapbase2 = (char *)heap2 + BLOCKSIZE;
145
146   heapinfo1 = (malloc_info *)((char *)heap1 + ((uintptr_t)((char *)heap1->heapinfo - (char *)s_heap)));
147   heapinfo2 = (malloc_info *)((char *)heap2 + ((uintptr_t)((char *)heap2->heapinfo - (char *)s_heap)));
148
149   heapsize1 = heap1->heapsize;
150   heapsize2 = heap2->heapsize;
151
152   /* Start comparison */
153   size_t i1, i2, j1, j2, k, current_block, current_fragment;
154   void *addr_block1, *addr_block2, *addr_frag1, *addr_frag2;
155   void *real_addr_block1, *real_addr_block2;
156   char *stack_name;
157   int nb_block1=0, nb_frag1=0, nb_block2=0, nb_frag2=0;
158
159   xbt_dynar_t previous = xbt_dynar_new(sizeof(heap_area_pair_t), heap_area_pair_free_voidp);
160
161   int equal, res_compare;
162
163   /* Init equal information */
164   i1 = 1;
165
166   while(i1<=heaplimit){
167     if(heapinfo1[i1].type == 0){
168       if(heapinfo1[i1].busy_block.busy_size > 0)
169         nb_block1++;
170       heapinfo1[i1].busy_block.equal_to = NULL;
171     }
172     if(heapinfo1[i1].type > 0){
173       for(j1=0; j1 < (size_t) (BLOCKSIZE >> heapinfo1[i1].type); j1++){
174         if(heapinfo1[i1].busy_frag.frag_size[j1] > 0)
175           nb_frag1++;
176         heapinfo1[i1].busy_frag.equal_to[j1] = NULL;
177       }
178     }
179     i1++; 
180   }
181
182   i2 = 1;
183
184   while(i2<=heaplimit){
185     if(heapinfo2[i2].type == 0){
186       if(heapinfo2[i2].busy_block.busy_size > 0)
187         nb_block2++;
188       heapinfo2[i2].busy_block.equal_to = NULL;
189     }
190     if(heapinfo2[i2].type > 0){
191       for(j2=0; j2 < (size_t) (BLOCKSIZE >> heapinfo2[i2].type); j2++){
192         if(heapinfo2[i2].busy_frag.frag_size[j2] > 0)
193           nb_frag2++;
194         heapinfo2[i2].busy_frag.equal_to[j2] = NULL;
195       }
196     }
197     i2++; 
198   }
199
200   if(nb_block1 != nb_block2 || nb_frag1 != nb_frag2){
201     XBT_DEBUG("Different number of busy blocks (%d - %d) or busy fragments (%d - %d)", nb_block1, nb_block2, nb_frag1, nb_frag2);
202     return 1;
203   }
204
205   /* Check busy blocks*/
206
207   i1 = 1;
208
209   while(i1 <= heaplimit){
210
211     current_block = i1;
212
213     if(heapinfo1[i1].type == -1){ /* Free block */
214       i1++;
215       continue;
216     }
217
218     addr_block1 = ((void*) (((ADDR2UINT(i1)) - 1) * BLOCKSIZE + (char*)heapbase1));
219     real_addr_block1 = (char*)((xbt_mheap_t)s_heap)->heapbase + (((char *)addr_block1) - (char *)heapbase1);
220
221     if(heapinfo1[i1].type == 0){  /* Large block */
222       
223       if((stack_name = is_stack(real_addr_block1)) != NULL){
224         stack_region_t stack = xbt_new0(s_stack_region_t, 1);
225         stack->address = addr_block1;
226         stack->process_name = strdup(stack_name);
227         stack->size = heapinfo1[i1].busy_block.busy_size;
228         xbt_dynar_push(*stack1, &stack);
229       }
230
231       if(heapinfo1[i1].busy_block.busy_size == 0){
232         i1++;
233         continue;
234       }
235
236       if(heapinfo1[i1].busy_block.equal_to != NULL){
237         i1++;
238         continue;
239       }
240     
241       i2 = 1;
242       equal = 0;
243   
244       /* Try first to associate to same block in the other heap */
245       if(heapinfo2[current_block].type == heapinfo1[current_block].type){
246
247         if(heapinfo2[current_block].busy_block.equal_to == NULL){  
248         
249           if(heapinfo1[current_block].busy_block.busy_size == heapinfo2[current_block].busy_block.busy_size){
250
251             addr_block2 = ((void*) (((ADDR2UINT(current_block)) - 1) * BLOCKSIZE + (char*)heapbase2));
252             real_addr_block2 = (char*)((xbt_mheap_t)s_heap)->heapbase + (((char *)addr_block2) - (char *)heapbase2);
253           
254             if((stack_name = is_stack(real_addr_block2)) != NULL){
255               stack_region_t stack = xbt_new0(s_stack_region_t, 1);
256               stack->address = addr_block2;
257               stack->process_name = strdup(stack_name);
258               stack->size = heapinfo2[current_block].busy_block.busy_size;
259               xbt_dynar_push(*stack2, &stack);
260             }
261         
262             add_heap_area_pair(previous, current_block, -1, current_block, -1);
263         
264             if(ignore_done < xbt_dynar_length(mc_heap_comparison_ignore)){
265               if(in_mc_comparison_ignore((int)current_block, -1))
266                 res_compare = compare_area(addr_block1, addr_block2, heapinfo1[current_block].busy_block.busy_size, previous, 1);
267               else
268                 res_compare = compare_area(addr_block1, addr_block2, heapinfo1[current_block].busy_block.busy_size, previous, 0);
269             }else{
270               res_compare = compare_area(addr_block1, addr_block2, heapinfo1[current_block].busy_block.busy_size, previous, 0);
271             }
272         
273             if(res_compare == 0){
274               for(k=1; k < heapinfo2[current_block].busy_block.size; k++)
275                 heapinfo2[current_block+k].busy_block.equal_to = new_heap_area(i1, -1);
276               for(k=1; k < heapinfo1[current_block].busy_block.size; k++)
277                 heapinfo1[current_block+k].busy_block.equal_to = new_heap_area(i1, -1);
278               equal = 1;
279               match_equals(previous, equals);
280               i1 = i1 + heapinfo1[current_block].busy_block.size;
281             }
282         
283             xbt_dynar_reset(previous);
284         
285           }
286
287         }
288         
289       }
290
291       while(i2 <= heaplimit && !equal){
292
293         addr_block2 = ((void*) (((ADDR2UINT(i2)) - 1) * BLOCKSIZE + (char*)heapbase2));        
294         real_addr_block2 = (char*)((xbt_mheap_t)s_heap)->heapbase + (((char *)addr_block2) - (char *)heapbase2);
295         
296         if((stack_name = is_stack(real_addr_block2)) != NULL){
297           stack_region_t stack = xbt_new0(s_stack_region_t, 1);
298           stack->address = addr_block2;
299           stack->process_name = strdup(stack_name);
300           stack->size = heapinfo2[i2].busy_block.busy_size;
301           xbt_dynar_push(*stack2, &stack);
302         }
303            
304         if(i2 == current_block){
305           i2++;
306           continue;
307         }
308
309         if(heapinfo2[i2].type != 0){
310           i2++;
311           continue;
312         }
313
314         if(heapinfo2[i2].busy_block.equal_to != NULL){         
315           i2++;
316           continue;
317         }
318         
319         if(heapinfo1[i1].busy_block.size != heapinfo2[i2].busy_block.size){
320           i2++;
321           continue;
322         }
323         
324         if(heapinfo1[i1].busy_block.busy_size != heapinfo2[i2].busy_block.busy_size){
325           i2++;
326           continue;
327         }
328
329         /* Comparison */
330         add_heap_area_pair(previous, i1, -1, i2, -1);
331         
332         if(ignore_done < xbt_dynar_length(mc_heap_comparison_ignore)){
333           if(in_mc_comparison_ignore((int)i1, -1))
334             res_compare = compare_area(addr_block1, addr_block2, heapinfo1[i1].busy_block.busy_size, previous, 1);
335           else
336             res_compare = compare_area(addr_block1, addr_block2, heapinfo1[i1].busy_block.busy_size, previous, 0);
337         }else{
338           res_compare = compare_area(addr_block1, addr_block2, heapinfo1[i1].busy_block.busy_size, previous, 0);
339         }
340         
341         if(res_compare == 0){
342           for(k=1; k < heapinfo2[i2].busy_block.size; k++)
343             heapinfo2[i2+k].busy_block.equal_to = new_heap_area(i1, -1);
344           for(k=1; k < heapinfo1[i1].busy_block.size; k++)
345             heapinfo1[i1+k].busy_block.equal_to = new_heap_area(i2, -1);
346           equal = 1;
347           match_equals(previous, equals);
348           i1 = i1 + heapinfo1[i1].busy_block.size;
349         }
350
351         xbt_dynar_reset(previous);
352
353         i2++;
354
355       }
356
357       if(!equal)
358         i1++;
359       
360     }else{ /* Fragmented block */
361
362       for(j1=0; j1 < (size_t) (BLOCKSIZE >> heapinfo1[i1].type); j1++){
363
364         current_fragment = j1;
365
366         if(heapinfo1[i1].busy_frag.frag_size[j1] == -1) /* Free fragment */
367           continue;
368
369         if(heapinfo1[i1].busy_frag.equal_to[j1] != NULL)
370           continue;
371
372         addr_frag1 = (void*) ((char *)addr_block1 + (j1 << heapinfo1[i1].type));
373
374         i2 = 1;
375         equal = 0;
376         
377         /* Try first to associate to same fragment in the other heap */
378         if(heapinfo2[current_block].type == heapinfo1[current_block].type){
379
380           if(heapinfo2[current_block].busy_frag.equal_to[current_fragment] == NULL){  
381           
382               if(heapinfo1[current_block].busy_frag.frag_size[current_fragment] == heapinfo2[current_block].busy_frag.frag_size[current_fragment]){
383
384                 addr_block2 = ((void*) (((ADDR2UINT(current_block)) - 1) * BLOCKSIZE + (char*)heapbase2));
385                 addr_frag2 = (void*) ((char *)addr_block2 + (current_fragment << heapinfo2[current_block].type));
386                
387                 add_heap_area_pair(previous, current_block, current_fragment, current_block, current_fragment);
388             
389                 if(ignore_done < xbt_dynar_length(mc_heap_comparison_ignore)){
390                   if(in_mc_comparison_ignore((int)current_block, (int)current_fragment))
391                     res_compare = compare_area(addr_frag1, addr_frag2, heapinfo1[current_block].busy_frag.frag_size[current_fragment], previous, 1);
392                   else
393                     res_compare = compare_area(addr_frag1, addr_frag2, heapinfo1[current_block].busy_frag.frag_size[current_fragment], previous, 0);
394                 }else{
395                   res_compare = compare_area(addr_frag1, addr_frag2, heapinfo1[current_block].busy_frag.frag_size[current_fragment], previous, 0);
396                 }
397
398                 if(res_compare == 0){
399                   equal = 1;
400                   match_equals(previous, equals);
401                 }
402             
403                 xbt_dynar_reset(previous);
404             
405               }
406
407             }
408
409         }
410
411         while(i2 <= heaplimit && !equal){
412
413           
414           if(heapinfo2[i2].type <= 0){
415             i2++;
416             continue;
417           }
418
419           for(j2=0; j2 < (size_t) (BLOCKSIZE >> heapinfo2[i2].type); j2++){
420
421             if(heapinfo2[i2].type == heapinfo1[i1].type && i2 == current_block && j2 == current_fragment)
422               continue;
423
424             if(heapinfo2[i2].busy_frag.equal_to[j2] != NULL)                
425               continue;              
426              
427             if(heapinfo1[i1].busy_frag.frag_size[j1] != heapinfo2[i2].busy_frag.frag_size[j2]) /* Different size_used */    
428               continue;
429              
430             addr_block2 = ((void*) (((ADDR2UINT(i2)) - 1) * BLOCKSIZE + (char*)heapbase2));
431             addr_frag2 = (void*) ((char *)addr_block2 + (j2 << heapinfo2[i2].type));
432              
433             /* Comparison */
434             add_heap_area_pair(previous, i1, j1, i2, j2);
435             
436             if(ignore_done < xbt_dynar_length(mc_heap_comparison_ignore)){
437               if(in_mc_comparison_ignore((int)i1, (int)j1))
438                 res_compare = compare_area(addr_frag1, addr_frag2, heapinfo1[i1].busy_frag.frag_size[j1], previous, 1);
439               else
440                 res_compare = compare_area(addr_frag1, addr_frag2, heapinfo1[i1].busy_frag.frag_size[j1], previous, 0);
441             }else{
442               res_compare = compare_area(addr_frag1, addr_frag2, heapinfo1[i1].busy_frag.frag_size[j1], previous, 0);
443             }
444
445             if(res_compare == 0){
446               equal = 1;
447               match_equals(previous, equals);
448               break;
449             }
450
451             xbt_dynar_reset(previous);
452
453           }
454
455           i2++;
456
457         }
458
459       }
460
461       i1++;
462       
463     }
464
465   }
466
467   /* All blocks/fragments are equal to another block/fragment ? */
468   size_t i = 1, j = 0;
469   int nb_diff1 = 0, nb_diff2 = 0;
470  
471   while(i<heaplimit){
472     if(heapinfo1[i].type == 0){
473       if(heapinfo1[i].busy_block.busy_size > 0){
474         if(heapinfo1[i].busy_block.equal_to == NULL){
475           if(XBT_LOG_ISENABLED(mm_diff, xbt_log_priority_debug)){
476             addr_block1 = ((void*) (((ADDR2UINT(i)) - 1) * BLOCKSIZE + (char*)heapbase1));
477             XBT_DEBUG("Block %zu (%p) not found (size used = %zu)", i, addr_block1, heapinfo1[i].busy_block.busy_size);
478             mmalloc_backtrace_block_display((void*)heapinfo1, i);
479           }
480           nb_diff1++;
481         }else{
482           xbt_free(heapinfo1[i].busy_block.equal_to);
483         }
484       }
485     }
486     if(heapinfo1[i].type > 0){
487       addr_block1 = ((void*) (((ADDR2UINT(i)) - 1) * BLOCKSIZE + (char*)heapbase1));
488       for(j=0; j < (size_t) (BLOCKSIZE >> heapinfo1[i].type); j++){
489         if(heapinfo1[i].busy_frag.frag_size[j] > 0){
490           if(heapinfo1[i].busy_frag.equal_to[j] == NULL){
491             if(XBT_LOG_ISENABLED(mm_diff, xbt_log_priority_debug)){
492               addr_frag1 = (void*) ((char *)addr_block1 + (j << heapinfo1[i].type));
493               XBT_DEBUG("Block %zu, Fragment %zu (%p) not found (size used = %d)", i, j, addr_frag1, heapinfo1[i].busy_frag.frag_size[j]);
494               mmalloc_backtrace_fragment_display((void*)heapinfo1, i, j);
495             }
496             nb_diff1++;
497           }else{
498             xbt_free(heapinfo1[i].busy_frag.equal_to[j]);
499           }
500         }
501       }
502     }
503     
504     i++; 
505   }
506
507   XBT_DEBUG("Different blocks or fragments in heap1 : %d", nb_diff1);
508
509   i = 1;
510
511   while(i<heaplimit){
512     if(heapinfo2[i].type == 0){
513       if(heapinfo2[i].busy_block.busy_size > 0){
514         if(heapinfo2[i].busy_block.equal_to == NULL){
515           if(XBT_LOG_ISENABLED(mm_diff, xbt_log_priority_debug)){
516             addr_block2 = ((void*) (((ADDR2UINT(i)) - 1) * BLOCKSIZE + (char*)heapbase2));
517             XBT_DEBUG("Block %zu (%p) not found (size used = %zu)", i, addr_block2, heapinfo2[i].busy_block.busy_size);
518             mmalloc_backtrace_block_display((void*)heapinfo2, i);
519           }
520           nb_diff2++;
521         }else{
522           xbt_free(heapinfo2[i].busy_block.equal_to);
523         }
524       }
525     }
526     if(heapinfo2[i].type > 0){
527       addr_block2 = ((void*) (((ADDR2UINT(i)) - 1) * BLOCKSIZE + (char*)heapbase2));
528       for(j=0; j < (size_t) (BLOCKSIZE >> heapinfo2[i].type); j++){
529         if(heapinfo2[i].busy_frag.frag_size[j] > 0){
530           if(heapinfo2[i].busy_frag.equal_to[j] == NULL){
531             if(XBT_LOG_ISENABLED(mm_diff, xbt_log_priority_debug)){
532               addr_frag2 = (void*) ((char *)addr_block2 + (j << heapinfo2[i].type));
533               XBT_DEBUG( "Block %zu, Fragment %zu (%p) not found (size used = %d)", i, j, addr_frag2, heapinfo2[i].busy_frag.frag_size[j]);
534               mmalloc_backtrace_fragment_display((void*)heapinfo2, i, j);
535             }
536             nb_diff2++;
537           }else{
538             xbt_free(heapinfo2[i].busy_frag.equal_to[j]);
539           }
540         }
541       }
542     }
543     i++; 
544   }
545
546   XBT_DEBUG("Different blocks or fragments in heap2 : %d", nb_diff2);
547
548   xbt_dynar_free(&previous);
549   ignore_done = 0;
550   s_heap = NULL, heapbase1 = NULL, heapbase2 = NULL;
551   heapinfo1 = NULL, heapinfo2 = NULL;
552   heaplimit = 0, heapsize1 = 0, heapsize2 = 0;
553
554   return ((nb_diff1 > 0) || (nb_diff2 > 0));
555
556 }
557
558 static heap_area_t new_heap_area(int block, int fragment){
559   heap_area_t area = NULL;
560   area = xbt_new0(s_heap_area_t, 1);
561   area->block = block;
562   area->fragment = fragment;
563   return area;
564 }
565
566 static int in_mc_comparison_ignore(int block, int fragment){
567
568   unsigned int cursor = 0;
569   int start = 0;
570   int end = xbt_dynar_length(mc_heap_comparison_ignore) - 1;
571   mc_heap_ignore_region_t region;
572
573   while(start <= end){
574     cursor = (start + end) / 2;
575     region = (mc_heap_ignore_region_t)xbt_dynar_get_as(mc_heap_comparison_ignore, cursor, mc_heap_ignore_region_t);
576     if(region->block == block){
577       if(region->fragment == fragment)
578         return 1;
579       if(region->fragment < fragment)
580         start = cursor + 1;
581       if(region->fragment > fragment)
582         end = cursor - 1;
583     }
584     if(region->block < block)
585       start = cursor + 1;
586     if(region->block > block)
587       end = cursor - 1; 
588   }
589
590   return 0;
591 }
592
593 static size_t heap_comparison_ignore_size(void *address){
594   unsigned int cursor = 0;
595   int start = 0;
596   int end = xbt_dynar_length(mc_heap_comparison_ignore) - 1;
597   mc_heap_ignore_region_t region;
598
599   while(start <= end){
600     cursor = (start + end) / 2;
601     region = (mc_heap_ignore_region_t)xbt_dynar_get_as(mc_heap_comparison_ignore, cursor, mc_heap_ignore_region_t);
602     if(region->address == address)
603       return region->size;
604     if(region->address < address)
605       start = cursor + 1;
606     if(region->address > address)
607       end = cursor - 1;   
608   }
609
610   return 0;
611 }
612
613
614 static int compare_area(void *area1, void* area2, size_t size, xbt_dynar_t previous, int check_ignore){
615
616   size_t i = 0, pointer_align = 0, ignore1 = 0, ignore2 = 0;
617   void *address_pointed1, *address_pointed2, *addr_block_pointed1, *addr_block_pointed2, *addr_frag_pointed1, *addr_frag_pointed2;
618   size_t block_pointed1, block_pointed2, frag_pointed1, frag_pointed2;
619   int res_compare;
620   void *current_area1, *current_area2;
621  
622   while(i<size){
623
624     if(check_ignore){
625
626       current_area1 = (char*)((xbt_mheap_t)s_heap)->heapbase + ((((char *)area1) + i) - (char *)heapbase1);
627       if((ignore1 = heap_comparison_ignore_size(current_area1)) > 0){
628         current_area2 = (char*)((xbt_mheap_t)s_heap)->heapbase + ((((char *)area2) + i) - (char *)heapbase2);
629         if((ignore2 = heap_comparison_ignore_size(current_area2))  == ignore1){
630           i = i + ignore2;
631           ignore_done++;
632           continue;
633         }
634       }
635
636     }
637    
638     if(memcmp(((char *)area1) + i, ((char *)area2) + i, 1) != 0){
639
640       /* Check pointer difference */
641       pointer_align = (i / sizeof(void*)) * sizeof(void*);
642       address_pointed1 = *((void **)((char *)area1 + pointer_align));
643       address_pointed2 = *((void **)((char *)area2 + pointer_align));
644
645       /* Get pointed blocks number */ 
646       block_pointed1 = ((char*)address_pointed1 - (char*)((xbt_mheap_t)s_heap)->heapbase) / BLOCKSIZE + 1;
647       block_pointed2 = ((char*)address_pointed2 - (char*)((xbt_mheap_t)s_heap)->heapbase) / BLOCKSIZE + 1;
648
649       /* Check if valid blocks number */
650       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)
651         return 1;
652
653       if(heapinfo1[block_pointed1].type == heapinfo2[block_pointed2].type){ /* Same type of block (large or fragmented) */
654
655         addr_block_pointed1 = ((void*) (((ADDR2UINT(block_pointed1)) - 1) * BLOCKSIZE + (char*)heapbase1));
656         addr_block_pointed2 = ((void*) (((ADDR2UINT(block_pointed2)) - 1) * BLOCKSIZE + (char*)heapbase2));
657         
658         if(heapinfo1[block_pointed1].type == 0){ /* Large block */
659
660           if(heapinfo1[block_pointed1].busy_block.size != heapinfo2[block_pointed2].busy_block.size){
661             return 1;
662           }
663
664           if(heapinfo1[block_pointed1].busy_block.busy_size != heapinfo2[block_pointed2].busy_block.busy_size){
665             return 1;
666           }
667
668           if(add_heap_area_pair(previous, block_pointed1, -1, block_pointed2, -1)){
669
670             if(ignore_done < xbt_dynar_length(mc_heap_comparison_ignore)){
671               if(in_mc_comparison_ignore(block_pointed1, -1))
672                 res_compare = compare_area(addr_block_pointed1, addr_block_pointed2, heapinfo1[block_pointed1].busy_block.busy_size, previous, 1);
673               else
674                 res_compare = compare_area(addr_block_pointed1, addr_block_pointed2, heapinfo1[block_pointed1].busy_block.busy_size, previous, 0);
675             }else{
676               res_compare = compare_area(addr_block_pointed1, addr_block_pointed2, heapinfo1[block_pointed1].busy_block.busy_size, previous, 0);
677             }
678             
679             if(res_compare == 1)    
680               return 1;
681            
682           }
683           
684         }else{ /* Fragmented block */
685
686           /* Get pointed fragments number */ 
687           frag_pointed1 = ((uintptr_t) (ADDR2UINT (address_pointed1) % (BLOCKSIZE))) >> heapinfo1[block_pointed1].type;
688           frag_pointed2 = ((uintptr_t) (ADDR2UINT (address_pointed2) % (BLOCKSIZE))) >> heapinfo2[block_pointed2].type;
689          
690           if(heapinfo1[block_pointed1].busy_frag.frag_size[frag_pointed1] != heapinfo2[block_pointed2].busy_frag.frag_size[frag_pointed2]) /* Different size_used */    
691             return 1;
692             
693           addr_frag_pointed1 = (void*) ((char *)addr_block_pointed1 + (frag_pointed1 << heapinfo1[block_pointed1].type));
694           addr_frag_pointed2 = (void*) ((char *)addr_block_pointed2 + (frag_pointed2 << heapinfo2[block_pointed2].type));
695
696           if(add_heap_area_pair(previous, block_pointed1, frag_pointed1, block_pointed2, frag_pointed2)){
697
698             if(ignore_done < xbt_dynar_length(mc_heap_comparison_ignore)){
699               if(in_mc_comparison_ignore(block_pointed1, frag_pointed1))
700                 res_compare = compare_area(addr_frag_pointed1, addr_frag_pointed2, heapinfo1[block_pointed1].busy_frag.frag_size[frag_pointed1], previous, 1);
701               else
702                 res_compare = compare_area(addr_frag_pointed1, addr_frag_pointed2, heapinfo1[block_pointed1].busy_frag.frag_size[frag_pointed1], previous, 0);
703             }else{
704               res_compare = compare_area(addr_frag_pointed1, addr_frag_pointed2, heapinfo1[block_pointed1].busy_frag.frag_size[frag_pointed1], previous, 0);
705             }
706
707             if(res_compare == 1)
708               return 1;
709            
710           }
711           
712         }
713           
714       }else{
715
716         if((heapinfo1[block_pointed1].type > 0) && (heapinfo2[block_pointed2].type > 0)){
717           
718           addr_block_pointed1 = ((void*) (((ADDR2UINT(block_pointed1)) - 1) * BLOCKSIZE + (char*)heapbase1));
719           addr_block_pointed2 = ((void*) (((ADDR2UINT(block_pointed2)) - 1) * BLOCKSIZE + (char*)heapbase2));
720        
721           frag_pointed1 = ((uintptr_t) (ADDR2UINT (address_pointed1) % (BLOCKSIZE))) >> heapinfo1[block_pointed1].type;
722           frag_pointed2 = ((uintptr_t) (ADDR2UINT (address_pointed2) % (BLOCKSIZE))) >> heapinfo2[block_pointed2].type;
723
724           if(heapinfo1[block_pointed1].busy_frag.frag_size[frag_pointed1] != heapinfo2[block_pointed2].busy_frag.frag_size[frag_pointed2]) /* Different size_used */  
725             return 1;
726
727           addr_frag_pointed1 = (void*) ((char *)addr_block_pointed1 + (frag_pointed1 << heapinfo1[block_pointed1].type));
728           addr_frag_pointed2 = (void*) ((char *)addr_block_pointed2 + (frag_pointed2 << heapinfo2[block_pointed2].type));
729
730           if(add_heap_area_pair(previous, block_pointed1, frag_pointed1, block_pointed2, frag_pointed2)){
731
732             if(ignore_done < xbt_dynar_length(mc_heap_comparison_ignore)){
733               if(in_mc_comparison_ignore(block_pointed1, frag_pointed1))
734                 res_compare = compare_area(addr_frag_pointed1, addr_frag_pointed2, heapinfo1[block_pointed1].busy_frag.frag_size[frag_pointed1], previous, 1);
735               else
736                 res_compare = compare_area(addr_frag_pointed1, addr_frag_pointed2, heapinfo1[block_pointed1].busy_frag.frag_size[frag_pointed1], previous, 0);
737             }else{
738               res_compare = compare_area(addr_frag_pointed1, addr_frag_pointed2, heapinfo1[block_pointed1].busy_frag.frag_size[frag_pointed1], previous, 0);
739             }
740             
741             if(res_compare == 1)
742               return 1;
743            
744           }
745
746         }else{
747           return 1;
748         }
749
750       }
751
752       i = pointer_align + sizeof(void *);
753       
754     }else{
755
756       i++;
757
758     }
759   }
760
761   return 0;
762   
763
764 }
765
766 static void heap_area_pair_free(heap_area_pair_t pair){
767   if (pair){
768     free(pair);
769     pair = NULL;
770   }
771 }
772
773 static void heap_area_pair_free_voidp(void *d)
774 {
775   heap_area_pair_free((heap_area_pair_t) * (void **) d);
776 }
777
778 static int add_heap_area_pair(xbt_dynar_t list, int block1, int fragment1, int block2, int fragment2){
779
780   if(is_new_heap_area_pair(list, block1, fragment1, block2, fragment2)){
781     heap_area_pair_t pair = NULL;
782     pair = xbt_new0(s_heap_area_pair_t, 1);
783     pair->block1 = block1;
784     pair->fragment1 = fragment1;
785     pair->block2 = block2;
786     pair->fragment2 = fragment2;
787     
788     xbt_dynar_push(list, &pair); 
789
790     return 1;
791   }
792
793   return 0;
794 }
795  
796 static int is_new_heap_area_pair(xbt_dynar_t list, int block1, int fragment1, int block2, int fragment2){
797   
798   unsigned int cursor = 0;
799   heap_area_pair_t current_pair;
800
801   xbt_dynar_foreach(list, cursor, current_pair){
802     if(current_pair->block1 == block1 && current_pair->block2 == block2 && current_pair->fragment1 == fragment1 && current_pair->fragment2 == fragment2)
803       return 0; 
804   }
805   
806   return 1;
807 }
808
809 static void match_equals(xbt_dynar_t list, xbt_dynar_t *equals){
810
811   unsigned int cursor = 0;
812   heap_area_pair_t current_pair;
813   heap_area_t previous_area;
814
815   void *real_addr_block1, *real_addr_block2, *real_addr_frag1, *real_addr_frag2;
816
817   xbt_dynar_foreach(list, cursor, current_pair){
818
819     if(current_pair->fragment1 != -1){
820
821       real_addr_block1 = ((void*) (((ADDR2UINT((size_t)current_pair->block1)) - 1) * BLOCKSIZE + (char*)((xbt_mheap_t)s_heap)->heapbase));
822       real_addr_frag1 = (void*) ((char *)real_addr_block1 + (current_pair->fragment1 << heapinfo1[current_pair->block1].type));
823       real_addr_block2 = ((void*) (((ADDR2UINT((size_t)current_pair->block2)) - 1) * BLOCKSIZE + (char*)((xbt_mheap_t)s_heap)->heapbase));
824       real_addr_frag2 = (void*) ((char *)real_addr_block2 + (current_pair->fragment2 << heapinfo2[current_pair->block2].type));
825
826       if(heapinfo1[current_pair->block1].busy_frag.equal_to[current_pair->fragment1] != NULL){    
827         remove_heap_equality(equals, 1, real_addr_frag1);
828         previous_area = heapinfo1[current_pair->block1].busy_frag.equal_to[current_pair->fragment1];
829         xbt_free( heapinfo2[previous_area->block].busy_frag.equal_to[previous_area->fragment]);
830         heapinfo2[previous_area->block].busy_frag.equal_to[previous_area->fragment] = NULL;
831         xbt_free(heapinfo1[current_pair->block1].busy_frag.equal_to[current_pair->fragment1]); 
832       }
833       if(heapinfo2[current_pair->block2].busy_frag.equal_to[current_pair->fragment2] != NULL){        
834         remove_heap_equality(equals, 2, real_addr_frag2); 
835         previous_area = heapinfo2[current_pair->block2].busy_frag.equal_to[current_pair->fragment2];
836         xbt_free(heapinfo1[previous_area->block].busy_frag.equal_to[previous_area->fragment]);
837         heapinfo1[previous_area->block].busy_frag.equal_to[previous_area->fragment] = NULL;
838         xbt_free(heapinfo2[current_pair->block2].busy_frag.equal_to[current_pair->fragment2]);
839       }
840       
841       if(real_addr_frag1 != real_addr_frag2)
842         add_heap_equality(equals, real_addr_frag1, real_addr_frag2);
843
844       heapinfo1[current_pair->block1].busy_frag.equal_to[current_pair->fragment1] = new_heap_area(current_pair->block2, current_pair->fragment2);
845       heapinfo2[current_pair->block2].busy_frag.equal_to[current_pair->fragment2] = new_heap_area(current_pair->block1, current_pair->fragment1);
846
847     }else{
848
849       real_addr_block1 = ((void*) (((ADDR2UINT((size_t)current_pair->block1)) - 1) * BLOCKSIZE + (char*)((xbt_mheap_t)s_heap)->heapbase));
850       real_addr_block2 = ((void*) (((ADDR2UINT((size_t)current_pair->block2)) - 1) * BLOCKSIZE + (char*)((xbt_mheap_t)s_heap)->heapbase));
851
852       if(heapinfo1[current_pair->block1].busy_block.equal_to != NULL){
853         remove_heap_equality(equals, 1, real_addr_block1);
854         previous_area = heapinfo1[current_pair->block1].busy_block.equal_to;
855         xbt_free(heapinfo2[previous_area->block].busy_block.equal_to);
856         heapinfo2[previous_area->block].busy_block.equal_to = NULL; 
857         xbt_free(heapinfo1[current_pair->block1].busy_block.equal_to);
858       }
859       if(heapinfo2[current_pair->block2].busy_block.equal_to != NULL){
860         remove_heap_equality(equals, 2, real_addr_block2);
861         previous_area = heapinfo2[current_pair->block2].busy_block.equal_to;
862         xbt_free(heapinfo1[previous_area->block].busy_block.equal_to);
863         heapinfo1[previous_area->block].busy_block.equal_to = NULL;
864         xbt_free(heapinfo2[current_pair->block2].busy_block.equal_to);
865       }
866       
867       if(real_addr_block1 != real_addr_block2)
868         add_heap_equality(equals, real_addr_block1, real_addr_block2);
869
870       heapinfo1[current_pair->block1].busy_block.equal_to = new_heap_area(current_pair->block2, current_pair->fragment2);
871       heapinfo2[current_pair->block2].busy_block.equal_to = new_heap_area(current_pair->block1, current_pair->fragment1);
872
873     }
874   }
875
876
877 }
878
879 #ifndef max
880 #define max( a, b ) ( ((a) > (b)) ? (a) : (b) )
881 #endif
882
883 int mmalloc_linear_compare_heap(xbt_mheap_t heap1, xbt_mheap_t heap2){
884
885   if(heap1 == NULL && heap1 == NULL){
886     XBT_DEBUG("Malloc descriptors null");
887     return 0;
888   }
889
890   if(heap1->heaplimit != heap2->heaplimit){
891     XBT_DEBUG("Different limit of valid info table indices");
892     return 1;
893   }
894
895   /* Heap information */
896   heaplimit = ((struct mdesc *)heap1)->heaplimit;
897
898   s_heap = (char *)mmalloc_get_current_heap() - STD_HEAP_SIZE - getpagesize();
899
900   heapbase1 = (char *)heap1 + BLOCKSIZE;
901   heapbase2 = (char *)heap2 + BLOCKSIZE;
902
903   heapinfo1 = (malloc_info *)((char *)heap1 + ((uintptr_t)((char *)heap1->heapinfo - (char *)s_heap)));
904   heapinfo2 = (malloc_info *)((char *)heap2 + ((uintptr_t)((char *)heap2->heapinfo - (char *)s_heap)));
905
906   heapsize1 = heap1->heapsize;
907   heapsize2 = heap2->heapsize;
908
909   /* Start comparison */
910   size_t i, j, k;
911   void *addr_block1, *addr_block2, *addr_frag1, *addr_frag2;
912
913   int distance = 0;
914
915   /* Check busy blocks*/
916
917   i = 1;
918
919   while(i <= heaplimit){
920
921     addr_block1 = ((void*) (((ADDR2UINT(i)) - 1) * BLOCKSIZE + (char*)heapbase1));
922     addr_block2 = ((void*) (((ADDR2UINT(i)) - 1) * BLOCKSIZE + (char*)heapbase2));
923
924     if(heapinfo1[i].type != heapinfo2[i].type){
925   
926       distance += BLOCKSIZE;
927       XBT_DEBUG("Different type of blocks (%zu) : %d - %d -> distance = %d", i, heapinfo1[i].type, heapinfo2[i].type, distance);
928       i++;
929     
930     }else{
931
932       if(heapinfo1[i].type == -1){ /* Free block */
933         i++;
934         continue;
935       }
936
937       if(heapinfo1[i].type == 0){ /* Large block */
938        
939         if(heapinfo1[i].busy_block.size != heapinfo2[i].busy_block.size){
940           distance += BLOCKSIZE * max(heapinfo1[i].busy_block.size, heapinfo2[i].busy_block.size);
941           i += max(heapinfo1[i].busy_block.size, heapinfo2[i].busy_block.size);
942           XBT_DEBUG("Different larger of cluster at block %zu : %zu - %zu -> distance = %d", i, heapinfo1[i].busy_block.size, heapinfo2[i].busy_block.size, distance);
943           continue;
944         }
945
946         /*if(heapinfo1[i].busy_block.busy_size != heapinfo2[i].busy_block.busy_size){
947           distance += max(heapinfo1[i].busy_block.busy_size, heapinfo2[i].busy_block.busy_size);
948           i += max(heapinfo1[i].busy_block.size, heapinfo2[i].busy_block.size);
949           XBT_DEBUG("Different size used oin large cluster at block %zu : %zu - %zu -> distance = %d", i, heapinfo1[i].busy_block.busy_size, heapinfo2[i].busy_block.busy_size, distance);
950           continue;
951           }*/
952
953         k = 0;
954
955         //while(k < (heapinfo1[i].busy_block.busy_size)){
956         while(k < heapinfo1[i].busy_block.size * BLOCKSIZE){
957           if(memcmp((char *)addr_block1 + k, (char *)addr_block2 + k, 1) != 0){
958             distance ++;
959           }
960           k++;
961         } 
962
963         i++;
964
965       }else { /* Fragmented block */
966
967         for(j=0; j < (size_t) (BLOCKSIZE >> heapinfo1[i].type); j++){
968
969           addr_frag1 = (void*) ((char *)addr_block1 + (j << heapinfo1[i].type));
970           addr_frag2 = (void*) ((char *)addr_block2 + (j << heapinfo2[i].type));
971
972           if(heapinfo1[i].busy_frag.frag_size[j] == 0 && heapinfo2[i].busy_frag.frag_size[j] == 0){
973             continue;
974           }
975           
976           
977           /*if(heapinfo1[i].busy_frag.frag_size[j] != heapinfo2[i].busy_frag.frag_size[j]){
978             distance += max(heapinfo1[i].busy_frag.frag_size[j], heapinfo2[i].busy_frag.frag_size[j]);
979             XBT_DEBUG("Different size used in fragment %zu in block %zu : %d - %d -> distance = %d", j, i, heapinfo1[i].busy_frag.frag_size[j], heapinfo2[i].busy_frag.frag_size[j], distance); 
980             continue;
981             }*/
982    
983           k=0;
984
985           //while(k < max(heapinfo1[i].busy_frag.frag_size[j], heapinfo2[i].busy_frag.frag_size[j])){
986           while(k < (BLOCKSIZE / (BLOCKSIZE >> heapinfo1[i].type))){
987             if(memcmp((char *)addr_frag1 + k, (char *)addr_frag2 + k, 1) != 0){
988               distance ++;
989             }
990             k++;
991           }
992
993         }
994
995         i++;
996
997       }
998       
999     }
1000
1001   }
1002
1003   return distance;
1004   
1005 }
1006
1007 static char * is_stack(void *address){
1008   unsigned int cursor = 0;
1009   stack_region_t stack;
1010
1011   xbt_dynar_foreach(stacks_areas, cursor, stack){
1012     if(address == stack->address)
1013       return stack->process_name;
1014   }
1015
1016   return NULL;
1017 }
1018
1019 static void add_heap_equality(xbt_dynar_t *equals, void *a1, void *a2){
1020   
1021   if(xbt_dynar_is_empty(*equals)){
1022
1023     heap_equality_t he = xbt_new0(s_heap_equality_t, 1);
1024     he->address1 = a1;
1025     he->address2 = a2;
1026
1027     xbt_dynar_insert_at(*equals, 0, &he);
1028   
1029   }else{
1030
1031     unsigned int cursor = 0;
1032     int start = 0;
1033     int end = xbt_dynar_length(*equals) - 1;
1034     heap_equality_t current_equality = NULL;
1035
1036     while(start <= end){
1037       cursor = (start + end) / 2;
1038       current_equality = (heap_equality_t)xbt_dynar_get_as(*equals, cursor, heap_equality_t);
1039       if(current_equality->address1 == a1){
1040         if(current_equality->address2 == a2)
1041           return;
1042         if(current_equality->address2 < a2)
1043           start = cursor + 1;
1044         if(current_equality->address2 > a2)
1045           end = cursor - 1;
1046       }
1047       if(current_equality->address1 < a1)
1048         start = cursor + 1;
1049       if(current_equality->address1 > a1)
1050         end = cursor - 1; 
1051     }
1052
1053     heap_equality_t he = xbt_new0(s_heap_equality_t, 1);
1054     he->address1 = a1;
1055     he->address2 = a2;
1056   
1057     if(current_equality->address1 < a1)
1058       xbt_dynar_insert_at(*equals, cursor + 1 , &he);
1059     else
1060        xbt_dynar_insert_at(*equals, cursor, &he); 
1061
1062   }
1063
1064 }
1065
1066 static void remove_heap_equality(xbt_dynar_t *equals, int address, void *a){
1067   
1068   unsigned int cursor = 0;
1069   heap_equality_t current_equality;
1070   int found = 0;
1071
1072   if(address == 1){
1073
1074     int start = 0;
1075     int end = xbt_dynar_length(*equals) - 1;
1076
1077
1078     while(start <= end && found == 0){
1079       cursor = (start + end) / 2;
1080       current_equality = (heap_equality_t)xbt_dynar_get_as(*equals, cursor, heap_equality_t);
1081       if(current_equality->address1 == a)
1082         found = 1;
1083       if(current_equality->address1 < a)
1084         start = cursor + 1;
1085       if(current_equality->address1 > a)
1086         end = cursor - 1; 
1087     }
1088
1089     if(found == 1)
1090       xbt_dynar_remove_at(*equals, cursor, NULL);
1091   
1092   }else{
1093
1094     xbt_dynar_foreach(*equals, cursor, current_equality){
1095       if(current_equality->address2 == a){
1096         found = 1;
1097         break;
1098       }
1099     }
1100
1101     if(found == 1)
1102       xbt_dynar_remove_at(*equals, cursor, NULL);
1103
1104   }
1105
1106   
1107 }
1108
1109 int is_free_area(void *area, xbt_mheap_t heap){
1110
1111   void *sheap = (char *)mmalloc_get_current_heap() - STD_HEAP_SIZE - getpagesize();
1112   malloc_info *heapinfo = (malloc_info *)((char *)heap + ((uintptr_t)((char *)heap->heapinfo - (char *)sheap)));
1113   size_t heapsize = heap->heapsize;
1114
1115   /* Get block number */ 
1116   size_t block = ((char*)area - (char*)((xbt_mheap_t)sheap)->heapbase) / BLOCKSIZE + 1;
1117   size_t fragment;
1118
1119   /* Check if valid block number */
1120   if((char *)area < (char*)((xbt_mheap_t)sheap)->heapbase || block > heapsize || block < 1)
1121     return 0;
1122
1123   if(heapinfo[block].type < 0)
1124     return 1;
1125
1126   if(heapinfo[block].type == 0)
1127     return 0;
1128
1129   if(heapinfo[block].type > 0){
1130     fragment = ((uintptr_t) (ADDR2UINT(area) % (BLOCKSIZE))) >> heapinfo[block].type;
1131     if(heapinfo[block].busy_frag.frag_size[fragment] == 0)
1132       return 1;  
1133   }
1134
1135   return 0;
1136   
1137
1138
1139 }