Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
model-checker : get end heap with field breakval in struct mdesc ( old function get_e...
[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 void mmalloc_backtrace_display(xbt_mheap_t mdp, void *ptr){
18   size_t block = BLOCK(ptr);
19   int type;
20   xbt_ex_t e;
21
22   if ((char *) ptr < (char *) mdp->heapbase || block > mdp->heapsize) {
23     fprintf(stderr,"Ouch, this pointer is not mine. I cannot display its backtrace. I refuse it to death!!\n");
24     abort();
25   }
26
27   type = mdp->heapinfo[block].type;
28
29   if (type != 0) {
30     //fprintf(stderr,"Only full blocks are backtraced for now. Ignoring your request.\n");
31     return;
32   }
33   if (mdp->heapinfo[block].busy_block.bt_size == 0) {
34     fprintf(stderr,"No backtrace available for that block, sorry.\n");
35     return;
36   }
37
38   memcpy(&e.bt,&(mdp->heapinfo[block].busy_block.bt),sizeof(void*)*XBT_BACKTRACE_SIZE);
39   e.used = mdp->heapinfo[block].busy_block.bt_size;
40
41   xbt_ex_setup_backtrace(&e);
42   if (e.used == 0) {
43     fprintf(stderr, "(backtrace not set)\n");
44   } else if (e.bt_strings == NULL) {
45     fprintf(stderr, "(backtrace not ready to be computed. %s)\n",xbt_binary_name?"Dunno why":"xbt_binary_name not setup yet");
46   } else {
47     int i;
48
49     fprintf(stderr, "Backtrace of where the block %p was malloced (%d frames):\n",ptr,e.used);
50     for (i = 0; i < e.used; i++)       /* no need to display "xbt_backtrace_display" */{
51       fprintf(stderr,"%d",i);fflush(NULL);
52       fprintf(stderr, "---> %s\n", e.bt_strings[i] + 4);
53     }
54   }
55 }
56
57
58 void mmalloc_backtrace_block_display(xbt_mheap_t mdp, size_t block){
59
60   int type;
61   xbt_ex_t e;
62
63   type = mdp->heapinfo[block].type;
64
65   if (type != 0) {
66     fprintf(stderr,"Only full blocks are backtraced for now. Ignoring your request.\n");
67     return;
68   }
69   if (mdp->heapinfo[block].busy_block.bt_size == 0) {
70     fprintf(stderr,"No backtrace available for that block, sorry.\n");
71     return;
72   }
73
74   memcpy(&e.bt,&(mdp->heapinfo[block].busy_block.bt),sizeof(void*)*XBT_BACKTRACE_SIZE);
75   e.used = mdp->heapinfo[block].busy_block.bt_size;
76
77   xbt_ex_setup_backtrace(&e);
78   if (e.used == 0) {
79     fprintf(stderr, "(backtrace not set)\n");
80   } else if (e.bt_strings == NULL) {
81     fprintf(stderr, "(backtrace not ready to be computed. %s)\n",xbt_binary_name?"Dunno why":"xbt_binary_name not setup yet");
82   } else {
83     int i;
84
85     fprintf(stderr, "Backtrace of where the block %zu was malloced (%d frames):\n", block ,e.used);
86     for (i = 0; i < e.used; i++)       /* no need to display "xbt_backtrace_display" */{
87       fprintf(stderr,"%d",i);fflush(NULL);
88       fprintf(stderr, "---> %s\n", e.bt_strings[i] + 4);
89     }
90   }
91 }
92
93 void mmalloc_backtrace_fragment_display(xbt_mheap_t mdp, size_t block, size_t frag){
94   
95   xbt_ex_t e;
96
97   memcpy(&e.bt,&(mdp->heapinfo[block].busy_frag.bt[frag]),sizeof(void*)*XBT_BACKTRACE_SIZE);
98   e.used = XBT_BACKTRACE_SIZE;
99
100   xbt_ex_setup_backtrace(&e);
101   if (e.used == 0) {
102     fprintf(stderr, "(backtrace not set)\n");
103   } else if (e.bt_strings == NULL) {
104     fprintf(stderr, "(backtrace not ready to be computed. %s)\n",xbt_binary_name?"Dunno why":"xbt_binary_name not setup yet");
105   } else {
106     int i;
107
108     fprintf(stderr, "Backtrace of where the fragment %zu in block %zu was malloced (%d frames):\n", frag, block ,e.used);
109     for (i = 0; i < e.used; i++)       /* no need to display "xbt_backtrace_display" */{
110       fprintf(stderr,"%d",i);fflush(NULL);
111       fprintf(stderr, "---> %s\n", e.bt_strings[i] + 4);
112     }
113   }
114 }
115
116 int mmalloc_compare_heap(xbt_mheap_t mdp1, xbt_mheap_t mdp2){
117
118   if(mdp1 == NULL && mdp2 == NULL){
119     fprintf(stderr, "Malloc descriptors null\n");
120     return 0;
121   }
122
123   int errors = mmalloc_compare_mdesc(mdp1, mdp2);
124
125   return (errors > 0);
126
127 }
128
129 int mmalloc_compare_mdesc(struct mdesc *mdp1, struct mdesc *mdp2){
130
131   int errors = 0;
132
133   /*if(mdp1->headersize != mdp2->headersize){
134     fprintf(stderr, "Different size of the file header for the mapped files\n");
135     return 1;
136   }
137
138   if(mdp1->refcount != mdp2->refcount){
139     fprintf(stderr, "Different number of processes that attached the heap\n");
140     return 1;
141   }
142
143   if(strcmp(mdp1->magic, mdp2->magic) != 0){
144     fprintf(stderr,"Different magic number\n");
145     return 1;
146   }
147
148   if(mdp1->flags != mdp2->flags){
149     fprintf(stderr,"Different flags\n");  
150     return 1;
151   }
152
153   if(mdp1->heapsize != mdp2->heapsize){
154     fprintf(stderr,"Different number of info entries\n");
155     return 1;
156   }  
157
158   if(mdp1->heapbase != mdp2->heapbase){
159     fprintf(stderr,"Different first block of the heap\n");
160     return 1;
161   }
162
163   if(mdp1->heapindex != mdp2->heapindex){
164     fprintf(stderr,"Different index for the heap table : %zu - %zu\n", mdp1->heapindex, mdp2->heapindex);
165     return 1;
166   }
167
168   if(mdp1->base != mdp2->base){
169     fprintf(stderr,"Different base address of the memory region\n");
170     return 1;
171   }
172
173   if(mdp1->breakval != mdp2->breakval){
174     fprintf(stderr,"Different current location in the memory region\n");
175     return 1;
176   }
177
178   if(mdp1->top != mdp2->top){
179     fprintf(stderr,"Different end of the current location in the memory region\n");
180     return 1;
181   }
182
183   if(mdp1->heaplimit != mdp2->heaplimit){
184     fprintf(stderr,"Different limit of valid info table indices\n");
185     return 1;
186   }
187
188   if(mdp1->fd != mdp2->fd){
189     fprintf(stderr,"Different file descriptor for the file to which this malloc heap is mapped\n");
190     return 1;
191   }
192
193   if(mdp1->version != mdp2->version){
194     fprintf(stderr,"Different version of the mmalloc package\n");
195     return 1;
196     }*/
197
198   //void* heapbase1 = (char *)mdp1 + ((char *)mdp1->heapbase - (char *)s_heap);
199   //void* heapbase2 = (char *)mdp2 + ((char *)mdp2->heapbase - (char *)s_heap);
200
201   void* s_heap = (char *)mmalloc_get_current_heap() - STD_HEAP_SIZE - getpagesize();
202     
203   void *heapbase1 = (char *)mdp1 + BLOCKSIZE;
204   void *heapbase2 = (char *)mdp2 + BLOCKSIZE;
205
206   size_t i, j;
207   void *addr_block1, *addr_block2, *addr_frag1, *addr_frag2;
208   size_t frag_size = 0;         /* FIXME: arbitrary initialization */
209   /* size_t frag_size_pointed; FIXME: unused */
210
211   i = 1;
212
213   int k;
214   int distance = 0;
215   int total_distance = 0;
216
217   //void *end_heap = (char *)mdp1 + ((char*)mdp1->top - (char *)s_heap);
218   void *breakval1 = (char *)mdp1 + ((char*)mdp1->breakval - (char *)s_heap);
219   void *breakval2 = (char *)mdp2 + ((char*)mdp2->breakval - (char *)s_heap);
220
221   int pointer_align;
222   void *address_pointed1, *address_pointed2;
223
224   int block_pointed1, block_pointed2;
225   void *addr_block_pointed1, *addr_block_pointed2;
226   int frag_pointed1, frag_pointed2;
227
228   /* Check busy blocks*/
229
230   while(i < mdp1->heaplimit){
231
232     if(mdp1->heapinfo[i].type != mdp2->heapinfo[i].type){
233       fprintf(stderr,"Different type of block : %d - %d\n", mdp1->heapinfo[i].type, mdp2->heapinfo[i].type);
234       errors++;
235     }
236
237     //fprintf(stderr, "i = %zu, type = %d", i, mdp1->heapinfo[i].type);
238
239     //addr_block1 = (void*) (((ADDR2UINT(i)) - 1) * BLOCKSIZE + (char*)heapbase1);
240     //addr_block2 = (void*) (((ADDR2UINT(1)) - 1) * BLOCKSIZE + (char*)heapbase2);
241
242     addr_block1 = (char*)heapbase1 + ((i-1)*BLOCKSIZE);
243     addr_block2 = (char*)heapbase2 + ((i-1)*BLOCKSIZE);
244
245     if(mdp1->heapinfo[i].type == 0){ /* busy large block */
246
247       if(mdp1->heapinfo[i].busy_block.size != mdp2->heapinfo[i].busy_block.size){
248         fprintf(stderr,"Different size of a large cluster : %zu - %zu\n", mdp1->heapinfo[i].busy_block.size, mdp2->heapinfo[i].busy_block.size); 
249         fflush(NULL);
250         errors++;
251       } 
252
253       if(mdp1->heapinfo[i].busy_block.busy_size != mdp2->heapinfo[i].busy_block.busy_size){
254         fprintf(stderr,"Different busy_size of a large cluster : %zu - %zu\n", mdp1->heapinfo[i].busy_block.busy_size, mdp2->heapinfo[i].busy_block.busy_size); 
255         fflush(NULL);
256         errors++;
257       } 
258
259   
260       /* Hamming distance on different blocks */
261       distance = 0;
262
263       //for(k=0;k<mdp1->heapinfo[i].busy_block.size * BLOCKSIZE;k++){
264       for(k=0;k<mdp1->heapinfo[i].busy_block.busy_size;k++){
265         if(memcmp(((char *)addr_block1) + k, ((char *)addr_block2) + k, 1) != 0){
266           //fprintf(stderr, "Different byte (offset=%d) (%p - %p) in block %zu\n", k, (char *)addr_block1 + k, (char *)addr_block2 + k, i); fflush(NULL);
267           pointer_align = (k / sizeof(void*)) * sizeof(void*); 
268           address_pointed1 = *((void **)((char *)addr_block1 + pointer_align));
269           address_pointed2 = *((void **)((char *)addr_block2 + pointer_align));                            
270           if(((address_pointed1 > (void *)s_heap) && (address_pointed1 < mdp1->breakval)) && ((address_pointed2 > (void *)s_heap) && (address_pointed2 < mdp2->breakval))){
271             block_pointed1 = ((char*)address_pointed1 - (char*)((struct mdesc*)s_heap)->heapbase) / BLOCKSIZE + 1;
272             block_pointed2 = ((char*)address_pointed2 - (char*)((struct mdesc*)s_heap)->heapbase) / BLOCKSIZE + 1;
273             //fprintf(stderr, "Blocks pointed : %d - %d\n", block_pointed1, block_pointed2);
274             if(mdp1->heapinfo[block_pointed1].type == mdp2->heapinfo[block_pointed2].type){
275               if(mdp1->heapinfo[block_pointed1].type == 0){ // Large block
276                 while(mdp1->heapinfo[block_pointed1].busy_block.size == 0)
277                   block_pointed1--;
278                 while(mdp2->heapinfo[block_pointed2].busy_block.size == 0)
279                   block_pointed2--;
280                 if(mdp1->heapinfo[block_pointed1].busy_block.busy_size == mdp2->heapinfo[block_pointed2].busy_block.busy_size){
281                   //addr_block_pointed1 = (void*) (((ADDR2UINT((size_t)block_pointed1)) - 1) * BLOCKSIZE + (char*)heapbase1);
282                   //addr_block_pointed2 = (void*) (((ADDR2UINT((size_t)block_pointed2)) - 1) * BLOCKSIZE + (char*)heapbase2);
283                   addr_block_pointed1 = (char*)heapbase1 + ((block_pointed1 - 1)*BLOCKSIZE);
284                   addr_block_pointed2 = (char*)heapbase2 + ((block_pointed2 - 1)*BLOCKSIZE);
285                   
286                   fprintf(stderr, "Memcmp between blocks %d and %d (size = %zu)\n", block_pointed1, block_pointed2,  mdp1->heapinfo[block_pointed1].busy_block.busy_size); 
287                   if(memcmp(addr_block_pointed1, addr_block_pointed2, mdp1->heapinfo[block_pointed1].busy_block.busy_size) != 0){
288                     distance++;
289                   }else{
290                     fprintf(stderr, "False difference detected\n");
291                   }
292                 }else{
293                   distance++;
294                 }
295               }else{ // Fragmented block
296                 address_pointed1 = (char*)mdp1 + ((char*)address_pointed1 - (char*)s_heap);
297                 address_pointed2 = (char*)mdp2 + ((char*)address_pointed2 - (char*)s_heap);
298                 //addr_block_pointed1 = (void*) (((ADDR2UINT((size_t)block_pointed1)) - 1) * BLOCKSIZE + (char*)heapbase1);
299                 //addr_block_pointed2 = (void*) (((ADDR2UINT((size_t)block_pointed2)) - 1) * BLOCKSIZE + (char*)heapbase2);
300                 addr_block_pointed1 = (char*)heapbase1 + ((block_pointed1 - 1)*BLOCKSIZE);
301                 addr_block_pointed2 = (char*)heapbase2 + ((block_pointed2 - 1)*BLOCKSIZE);
302                 frag_pointed1 = 0;
303                 while(address_pointed1 > (void*)((char*)addr_block_pointed1 + ((frag_pointed1 +1 ) * frag_size))){
304                   frag_pointed1++;
305                 }
306                 frag_pointed2 = 0;
307                 while(address_pointed2 > (void*)((char*)addr_block_pointed2 + ((frag_pointed2 +1) * frag_size))){
308                   frag_pointed2++;
309                 }
310                 if(mdp1->heapinfo[block_pointed1].busy_frag.frag_size[frag_pointed1] == mdp2->heapinfo[block_pointed2].busy_frag.frag_size[frag_pointed2]){
311                   fprintf(stderr, "Memcmp between fragments %d (block %d) and %d (block %d) (size = %d)\n", frag_pointed1, block_pointed1, frag_pointed2, block_pointed2,  mdp1->heapinfo[block_pointed1].busy_frag.frag_size[frag_pointed1]); 
312                   if(memcmp((char*)addr_block_pointed1 + (frag_pointed1 * frag_size), (char*)addr_block_pointed2 + (frag_pointed2 * frag_size), mdp1->heapinfo[block_pointed1].busy_frag.frag_size[frag_pointed1]) != 0){
313                     distance++;
314                   }else{
315                     fprintf(stderr, "False difference detected\n");
316                   }
317                 }else{
318                   distance ++;
319                 }
320                   
321                   
322               }
323             }else{
324               distance++;
325             }
326           }else{
327             distance++;
328           }
329             
330         }
331       }
332
333
334       if(distance>0){
335         fprintf(stderr,"\nDifferent data in large block %zu (size = %zu (in blocks), busy_size = %zu (in bytes))\n", i, mdp1->heapinfo[i].busy_block.size, mdp1->heapinfo[i].busy_block.busy_size);
336         fflush(NULL);
337         fprintf(stderr, "Hamming distance between blocks : %d\n", distance);
338         mmalloc_backtrace_block_display(mdp1, i);
339         mmalloc_backtrace_block_display(mdp2, i);
340         errors++; 
341         total_distance += distance;
342       }
343     
344       
345       i++;
346       
347     }else{
348       
349       if(mdp1->heapinfo[i].type > 0){ /* busy fragmented block */
350
351         if(mdp1->heapinfo[i].type != mdp2->heapinfo[i].type){
352           fprintf(stderr,"Different size of fragments in fragmented block %zu : %d - %d\n", i, mdp1->heapinfo[i].type, mdp2->heapinfo[i].type); fflush(NULL);
353           errors++;
354         }
355
356         if(mdp1->heapinfo[i].busy_frag.nfree != mdp2->heapinfo[i].busy_frag.nfree){
357           fprintf(stderr,"Different free fragments in fragmented block %zu : %zu - %zu\n", i, mdp1->heapinfo[i].busy_frag.nfree, mdp2->heapinfo[i].busy_frag.nfree); fflush(NULL);
358           errors++;
359         } 
360         
361         if(mdp1->heapinfo[i].busy_frag.first != mdp2->heapinfo[i].busy_frag.first){
362           fprintf(stderr,"Different busy_size of a large cluster : %zu - %zu\n", mdp1->heapinfo[i].busy_block.busy_size, mdp2->heapinfo[i].busy_block.busy_size); fflush(NULL);
363           errors++;
364         } 
365
366         //fprintf(stderr,"\n");
367
368         frag_size = pow(2, mdp1->heapinfo[i].type);
369
370         for(j=0; j< (BLOCKSIZE/frag_size); j++){
371
372           if(mdp1->heapinfo[i].busy_frag.frag_size[j] != mdp2->heapinfo[i].busy_frag.frag_size[j]){
373             fprintf(stderr,"Different busy_size for fragment %zu in block %zu : %hu - %hu\n", j, i, mdp1->heapinfo[i].busy_frag.frag_size[j], mdp2->heapinfo[i].busy_frag.frag_size[j]); fflush(NULL);
374             errors++;
375           }
376
377           if(mdp1->heapinfo[i].busy_frag.frag_size[j] > 0){
378             
379             addr_frag1 = (char *)addr_block1 + (j * frag_size);
380             addr_frag2 = (char *)addr_block2 + (j * frag_size);
381
382
383             /* Hamming distance on different blocks */
384             distance = 0;
385             //for(k=0;k<frag_size;k++){
386             for(k=0;k<mdp1->heapinfo[i].busy_frag.frag_size[j];k++){
387               if(memcmp(((char *)addr_frag1) + k, ((char *)addr_frag2) + k, 1) != 0){
388                 //fprintf(stderr, "Different byte (offset=%d) (%p - %p) in fragment %zu in block %zu\n", k, (char *)addr_frag1 + k, (char *)addr_frag2 + k, j, i); fflush(NULL);
389                 pointer_align = (k / sizeof(void*)) * sizeof(void*);
390                 address_pointed1 = *((void **)((char *)addr_frag1 + pointer_align));
391                 address_pointed2 = *((void **)((char *)addr_frag2 + pointer_align));                               
392                 if(((address_pointed1 > (void *)s_heap) && (address_pointed1 < mdp1->breakval)) && ((address_pointed2 > (void *)s_heap) && (address_pointed2 < mdp2->breakval))){
393                   block_pointed1 = ((char*)address_pointed1 - (char*)((struct mdesc*)s_heap)->heapbase) / BLOCKSIZE + 1;
394                   block_pointed2 = ((char*)address_pointed2 - (char*)((struct mdesc*)s_heap)->heapbase) / BLOCKSIZE + 1;
395                   //fprintf(stderr, "Blocks pointed : %d - %d\n", block_pointed1, block_pointed2);
396                   if(mdp1->heapinfo[block_pointed1].type == mdp2->heapinfo[block_pointed2].type){
397                     if(mdp1->heapinfo[block_pointed1].type == 0){ // Large block
398                       while(mdp1->heapinfo[block_pointed1].busy_block.size == 0)
399                         block_pointed1--;
400                       while(mdp2->heapinfo[block_pointed2].busy_block.size == 0)
401                         block_pointed2--;
402                       if(mdp1->heapinfo[block_pointed1].busy_block.busy_size == mdp2->heapinfo[block_pointed2].busy_block.busy_size){
403                         //addr_block_pointed1 = (void*) (((ADDR2UINT((size_t)block_pointed1)) - 1) * BLOCKSIZE + (char*)heapbase1);
404                         //addr_block_pointed2 = (void*) (((ADDR2UINT((size_t)block_pointed2)) - 1) * BLOCKSIZE + (char*)heapbase2);
405                         addr_block_pointed1 = (char*)heapbase1 + ((block_pointed1 - 1)*BLOCKSIZE);
406                         addr_block_pointed2 = (char*)heapbase2 + ((block_pointed2 - 1)*BLOCKSIZE);
407                         fprintf(stderr, "Memcmp between blocks %d and %d (size = %zu)\n", block_pointed1, block_pointed2,  mdp1->heapinfo[block_pointed1].busy_block.busy_size); 
408                         if(memcmp(addr_block_pointed1, addr_block_pointed2, mdp1->heapinfo[block_pointed1].busy_block.busy_size) != 0){
409                           distance++;
410                         }else{
411                           fprintf(stderr, "False difference detected\n");
412                         }
413                       }else{
414                         distance++;
415                       }
416                     }else{ // Fragmented block
417                       address_pointed1 = (char*)mdp1 + ((char*)address_pointed1 - (char*)s_heap);
418                       address_pointed2 = (char*)mdp2 + ((char*)address_pointed2 - (char*)s_heap);
419                       //addr_block_pointed1 = (void*) (((ADDR2UINT((size_t)block_pointed1)) - 1) * BLOCKSIZE + (char*)heapbase1);
420                       //addr_block_pointed2 = (void*) (((ADDR2UINT((size_t)block_pointed2)) - 1) * BLOCKSIZE + (char*)heapbase2);
421                       addr_block_pointed1 = (char*)heapbase1 + ((block_pointed1 - 1)*BLOCKSIZE);
422                       addr_block_pointed2 = (char*)heapbase2 + ((block_pointed2 - 1)*BLOCKSIZE);
423                       frag_pointed1 = 0;
424                       while(address_pointed1 > (void*)((char*)addr_block_pointed1 + ((frag_pointed1 + 1) * frag_size))){
425                         frag_pointed1++;
426                       }
427                       frag_pointed2 = 0;
428                       while(address_pointed2 > (void*)((char*)addr_block_pointed2 + ((frag_pointed2 + 1) * frag_size))){
429                         frag_pointed2++;
430                       }
431                       if(mdp1->heapinfo[block_pointed1].busy_frag.frag_size[frag_pointed1] == mdp2->heapinfo[block_pointed2].busy_frag.frag_size[frag_pointed2]){
432                         fprintf(stderr, "Memcmp between fragments %d (block %d) and %d (block %d) (size = %d)\n", frag_pointed1, block_pointed1, frag_pointed2, block_pointed2,  mdp1->heapinfo[block_pointed1].busy_frag.frag_size[frag_pointed1]); 
433                         if(memcmp((char*)addr_block_pointed1 + (frag_pointed1 * frag_size), (char*)addr_block_pointed2 + (frag_pointed2 * frag_size), mdp1->heapinfo[block_pointed1].busy_frag.frag_size[frag_pointed1]) != 0){
434                           distance++;
435                         }else{
436                           fprintf(stderr, "False difference detected\n");
437                         }
438                       }else{
439                         distance ++;
440                       }
441                     }
442                   }else{
443                     distance++;
444                   }
445                 }else{
446                   distance++;
447                 }
448               }
449
450             }
451             
452             if(distance > 0){
453               fprintf(stderr,"\nDifferent data in fragment %zu (size = %zu, size used = %hu) in block %zu \n", j, frag_size, mdp1->heapinfo[i].busy_frag.frag_size[j], i);
454               fprintf(stderr, "Hamming distance between fragments : %d\n", distance);
455               mmalloc_backtrace_fragment_display(mdp1, i, j);
456               mmalloc_backtrace_fragment_display(mdp2, i, j);
457               errors++;
458               total_distance += distance;
459               
460             }
461
462           }
463         }
464
465         i++;
466
467       }else{ /* free block */
468
469         i++;
470
471         //fprintf(stderr,"\n");
472
473       }
474       
475     }
476
477   }
478
479   //free(pointed_address1);
480   //free(pointed_address2);
481
482   fprintf(stderr, "Hamming distance between heap regions : %d\n", total_distance);
483
484   return (errors);
485 }
486
487
488 /* void *get_end_addr_heap(void *heap){ */
489
490 /*   FILE *fp;                     /\* File pointer to process's proc maps file *\/ */
491 /*   char *line = NULL;            /\* Temporal storage for each line that is readed *\/ */
492 /*   ssize_t read;                 /\* Number of bytes readed *\/ */
493 /*   size_t n = 0;                 /\* Amount of bytes to read by getline *\/ */
494
495 /*   fp = fopen("/proc/self/maps", "r"); */
496   
497 /*   if(fp == NULL) */
498 /*     perror("fopen failed"); */
499
500
501 /*   xbt_dynar_t lfields = NULL; */
502 /*   xbt_dynar_t start_end  = NULL; */
503 /*   void *start_addr; */
504 /*   void *end_addr; */
505
506 /*   while ((read = getline(&line, &n, fp)) != -1) { */
507
508 /*     xbt_str_trim(line, NULL); */
509 /*     xbt_str_strip_spaces(line); */
510 /*     lfields = xbt_str_split(line,NULL); */
511
512 /*     start_end = xbt_str_split(xbt_dynar_get_as(lfields, 0, char*), "-"); */
513 /*     start_addr = (void *) strtoul(xbt_dynar_get_as(start_end, 0, char*), NULL, 16); */
514 /*     end_addr = (void *) strtoul(xbt_dynar_get_as(start_end, 1, char*), NULL, 16); */
515
516 /*     if(start_addr == heap){ */
517 /*       free(line); */
518 /*       fclose(fp); */
519 /*       xbt_dynar_reset(lfields); */
520 /*       xbt_free(lfields); */
521 /*       xbt_dynar_reset(start_end); */
522 /*       xbt_free(start_end); */
523 /*       return end_addr; */
524 /*     } */
525
526 /*   } */
527
528 /*   xbt_dynar_reset(lfields); */
529 /*   xbt_free(lfields); */
530 /*   xbt_dynar_reset(start_end); */
531 /*   xbt_free(start_end); */
532 /*   free(line); */
533 /*   fclose(fp); */
534 /*   return NULL; */
535
536
537 /* } */
538
539
540 void mmalloc_display_info_heap(xbt_mheap_t h){
541
542 }
543
544
545