Logo AND Algorithmique Numérique Distribuée

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