Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
model-checker : extend pointer detection in heap comparison algorithm
[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->heaplimit != mdp2->heaplimit){
134     fprintf(stderr,"Different limit of valid info table indices\n");
135     return 1;
136   }
137
138   void* s_heap = (char *)mmalloc_get_current_heap() - STD_HEAP_SIZE - getpagesize();
139
140   void *heapbase1 = (char *)mdp1 + BLOCKSIZE;
141   void *heapbase2 = (char *)mdp2 + BLOCKSIZE;
142
143   size_t i, j;
144   void *addr_block1, *addr_block2, *addr_frag1, *addr_frag2;
145   size_t frag_size;
146
147   i = 1;
148
149   int k;
150   int distance = 0;
151   int total_distance = 0;
152
153   int pointer_align;
154   void *address_pointed1, *address_pointed2;
155
156   int block_pointed1, block_pointed2, frag_pointed1, frag_pointed2;
157   void *addr_block_pointed1, *addr_block_pointed2;
158
159   int pointer1 = 0, pointer2 = 0;
160
161   /* Check busy blocks*/
162
163   while(i < mdp1->heaplimit){
164
165     if(mdp1->heapinfo[i].type != mdp2->heapinfo[i].type){
166       fprintf(stderr,"Different type of block : %d - %d\n", mdp1->heapinfo[i].type, mdp2->heapinfo[i].type);
167       errors++;
168     }
169
170     /* Get address of block i in each heap */
171     addr_block1 = ((void*) (((ADDR2UINT(i)) - 1) * BLOCKSIZE + (char*)heapbase1));
172     addr_block2 = ((void*) (((ADDR2UINT(i)) - 1) * BLOCKSIZE + (char*)heapbase2));
173
174     if(mdp1->heapinfo[i].type == 0){ /* busy large block */
175
176       if(mdp1->heapinfo[i].busy_block.size != mdp2->heapinfo[i].busy_block.size){
177         fprintf(stderr,"Different size of a large cluster : %zu - %zu\n", mdp1->heapinfo[i].busy_block.size, mdp2->heapinfo[i].busy_block.size); 
178         fflush(NULL);
179         errors++;
180       }
181
182       if(mdp1->heapinfo[i].busy_block.busy_size != mdp2->heapinfo[i].busy_block.busy_size){
183         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); 
184         fflush(NULL);
185         errors++;
186       }
187
188       /* Hamming distance on different blocks */
189       distance = 0;
190
191
192       for(k=0;k<mdp1->heapinfo[i].busy_block.busy_size;k++){
193
194         if(memcmp(((char *)addr_block1) + k, ((char *)addr_block2) + k, 1) != 0){
195
196           fprintf(stderr, "Different byte (offset=%d) (%p - %p) in block %zu\n", k, (char *)addr_block1 + k, (char *)addr_block2 + k, i); fflush(NULL);
197           
198           /* Check if pointer difference */
199           pointer_align = (k >> sizeof(void*)) * sizeof(void*);
200           address_pointed1 = *((void **)((char *)addr_block1 + pointer_align));
201           address_pointed2 = *((void **)((char *)addr_block2 + pointer_align));
202
203           fprintf(stderr, "Addresses pointed : %p - %p\n", address_pointed1, address_pointed2);
204           
205           block_pointed1 = ((char*)address_pointed1 - (char*)((struct mdesc*)s_heap)->heapbase) / BLOCKSIZE + 1;
206           block_pointed2 = ((char*)address_pointed2 - (char*)((struct mdesc*)s_heap)->heapbase) / BLOCKSIZE + 1;
207           
208           fprintf(stderr, "Blocks pointed : %d - %d\n", block_pointed1, block_pointed2);
209           
210           /*if((char *) address_pointed1 < (char*)((struct mdesc*)s_heap)->heapbase || block_pointed1 > mdp1->heapsize || block_pointed1 < 1 || (char *) address_pointed2 < (char*)((struct mdesc*)s_heap)->heapbase || block_pointed2 > mdp2->heapsize || block_pointed2 < 1) {
211             fprintf(stderr, "Unknown pointer ! \n");
212             fflush(NULL);
213             distance++;
214             continue;
215             }*/
216
217           if(((char *) address_pointed1 > (char*)((struct mdesc*)s_heap)->heapbase) && (block_pointed1 < mdp1->heapsize) && (block_pointed1 >= 1)){
218             addr_block_pointed1 = ((void*) (((ADDR2UINT((size_t)block_pointed1)) - 1) * BLOCKSIZE + (char*)heapbase1));
219             if(((char *) address_pointed2 > (char*)((struct mdesc*)s_heap)->heapbase) && (block_pointed2 < mdp2->heapsize) && (block_pointed2 >= 1)){
220               addr_block_pointed2 = ((void*) (((ADDR2UINT((size_t)block_pointed2)) - 1) * BLOCKSIZE + (char*)heapbase2));
221             }else{
222               addr_block_pointed2 = addr_block2;
223               block_pointed2 = i;
224             }
225           }else{
226             addr_block_pointed1 = addr_block1;
227             block_pointed1 = i;
228             if(((char *) address_pointed2 > (char*)((struct mdesc*)s_heap)->heapbase) && (block_pointed2 < mdp2->heapsize) && (block_pointed2 >= 1)){
229               addr_block_pointed2 = ((void*) (((ADDR2UINT((size_t)block_pointed2)) - 1) * BLOCKSIZE + (char*)heapbase2));
230             }else{
231               fprintf(stderr, "Unknown pointers ! \n");
232               fflush(NULL);
233               distance++;
234               continue;
235             }
236           }
237           
238           //addr_block_pointed1 = ((void*) (((ADDR2UINT((size_t)block_pointed1)) - 1) * BLOCKSIZE + (char*)heapbase1));
239           //addr_block_pointed2 = ((void*) (((ADDR2UINT((size_t)block_pointed2)) - 1) * BLOCKSIZE + (char*)heapbase2));
240           
241           if(mdp1->heapinfo[block_pointed1].type == mdp2->heapinfo[block_pointed2].type){
242             
243             if(mdp1->heapinfo[block_pointed1].type == 0){ // Large block
244               
245               if(mdp1->heapinfo[block_pointed1].busy_block.busy_size == mdp2->heapinfo[block_pointed2].busy_block.busy_size){
246                 
247                 if(memcmp(addr_block_pointed1, addr_block_pointed2, mdp1->heapinfo[block_pointed1].busy_block.busy_size) != 0){
248                   distance++;
249                 }else{
250                   fprintf(stderr, "False difference detected\n");
251                 }
252                 
253               }else{
254                 distance++;
255               }
256               
257             }else{ // Fragmented block
258               
259               if(pointer1)
260                 frag_pointed1 = ((uintptr_t) (ADDR2UINT (address_pointed1) % (BLOCKSIZE))) >> mdp1->heapinfo[block_pointed1].type;
261               else
262                 frag_pointed1 = -1;
263               if(pointer2)
264                 frag_pointed2 = ((uintptr_t) (ADDR2UINT (address_pointed2) % (BLOCKSIZE))) >> mdp2->heapinfo[block_pointed2].type;
265               else
266                 frag_pointed2 = -1;
267                             
268               fprintf(stderr, "Fragments pointed : %d - %d\n", frag_pointed1, frag_pointed2);
269               
270               if((frag_pointed1 < 0) || (frag_pointed1 > (BLOCKSIZE / pow( 2, mdp1->heapinfo[block_pointed1].type))) || (frag_pointed2 < 0) || (frag_pointed2 > (BLOCKSIZE / pow( 2, mdp2->heapinfo[block_pointed2].type)))){
271                 fprintf(stderr, "Unknown pointer ! \n");
272                 fflush(NULL);
273                 distance++;
274                 continue;
275               } 
276
277               fprintf(stderr, "Size used in fragments pointed : %d - %d\n", mdp1->heapinfo[block_pointed1].busy_frag.frag_size[frag_pointed1], mdp2->heapinfo[block_pointed2].busy_frag.frag_size[frag_pointed2]);  
278               
279               if(mdp1->heapinfo[block_pointed1].busy_frag.frag_size[frag_pointed1] == mdp2->heapinfo[block_pointed2].busy_frag.frag_size[frag_pointed2]){
280                 
281                 if(memcmp(addr_block_pointed1, addr_block_pointed2, mdp1->heapinfo[block_pointed1].busy_frag.frag_size[frag_pointed1]) != 0){
282                   distance++;
283                 }else{
284                   fprintf(stderr, "False difference detected\n");
285                 }
286                 
287               }else{
288                 distance ++;
289               }
290             }
291             
292           }else{
293
294             if(((mdp1->heapinfo[block_pointed1].type == 0) && (mdp2->heapinfo[block_pointed2].type != 0)) || ((mdp1->heapinfo[block_pointed1].type != 0) && (mdp2->heapinfo[block_pointed2].type == 0))){  
295               fprintf(stderr, "Pointers on blocks with different types \n");
296               distance++;
297             }else{
298               if(pointer1)
299                 frag_pointed1 = ((uintptr_t) (ADDR2UINT (address_pointed1) % (BLOCKSIZE))) >> mdp1->heapinfo[block_pointed1].type;
300               else
301                 frag_pointed1 = -1;
302               if(pointer2)
303                 frag_pointed2 = ((uintptr_t) (ADDR2UINT (address_pointed2) % (BLOCKSIZE))) >> mdp2->heapinfo[block_pointed2].type;
304               else
305                 frag_pointed2 = -1;
306               
307               fprintf(stderr, "Fragments pointed : %d - %d\n", frag_pointed1, frag_pointed2);
308               
309               if((frag_pointed1 < 0) || (frag_pointed1 > (BLOCKSIZE / pow( 2, mdp1->heapinfo[block_pointed1].type))) || (frag_pointed2 < 0) || (frag_pointed2 > (BLOCKSIZE / pow( 2, mdp2->heapinfo[block_pointed2].type)))){
310                 fprintf(stderr, "Unknown pointer ! \n");
311                 fflush(NULL);
312                 distance++;
313                 continue;
314               } 
315               
316               fprintf(stderr, "Size used in fragments pointed : %d - %d\n", mdp1->heapinfo[block_pointed1].busy_frag.frag_size[frag_pointed1], mdp2->heapinfo[block_pointed2].busy_frag.frag_size[frag_pointed2]); 
317               
318               if(mdp1->heapinfo[block_pointed1].busy_frag.frag_size[frag_pointed1] == mdp2->heapinfo[block_pointed2].busy_frag.frag_size[frag_pointed2]){
319                 
320                 if(memcmp(addr_block_pointed1, addr_block_pointed2, mdp1->heapinfo[block_pointed1].busy_frag.frag_size[frag_pointed1]) != 0){
321                   distance++;
322                 }else{
323                   fprintf(stderr, "False difference detected\n");
324                 }
325                 
326               }else{
327                 distance ++;
328               }
329             }
330           }
331         }
332      
333       }
334
335
336       if(distance>0){
337         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);
338         fflush(NULL);
339         fprintf(stderr, "Hamming distance between blocks : %d\n", distance);
340         mmalloc_backtrace_block_display(mdp1, i);
341         mmalloc_backtrace_block_display(mdp2, i);
342         fprintf(stderr, "\n");
343         errors++;
344         total_distance += distance;
345       }
346
347       i++;
348
349     }else{
350
351       if(mdp1->heapinfo[i].type > 0){ /* busy fragmented block */
352
353         if(mdp1->heapinfo[i].type != mdp2->heapinfo[i].type){
354           fprintf(stderr,"Different size of fragments in fragmented block %zu : %d - %d\n", i, mdp1->heapinfo[i].type, mdp2->heapinfo[i].type); fflush(NULL);
355           errors++;
356         }
357
358         if(mdp1->heapinfo[i].busy_frag.nfree != mdp2->heapinfo[i].busy_frag.nfree){
359           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);
360           errors++;
361         }
362
363         if(mdp1->heapinfo[i].busy_frag.first != mdp2->heapinfo[i].busy_frag.first){
364           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);
365           errors++;
366         }
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             /* Hamming distance on different blocks */
383             distance = 0;
384
385             for(k=0;k<mdp1->heapinfo[i].busy_frag.frag_size[j];k++){
386
387               if(memcmp(((char *)addr_frag1) + k, ((char *)addr_frag2) + k, 1) != 0){
388
389                 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);
390
391                 pointer_align = (k / sizeof(void*)) * sizeof(void*);
392                 address_pointed1 = *((void **)((char *)addr_frag1 + pointer_align));
393                 address_pointed2 = *((void **)((char *)addr_frag2 + pointer_align));
394
395                 fprintf(stderr, "Addresses pointed : %p - %p\n", address_pointed1, address_pointed2);
396
397                 block_pointed1 = ((char*)address_pointed1 - (char*)((struct mdesc*)s_heap)->heapbase) / BLOCKSIZE + 1;
398                 block_pointed2 = ((char*)address_pointed2 - (char*)((struct mdesc*)s_heap)->heapbase) / BLOCKSIZE + 1;
399
400                 fprintf(stderr, "Blocks pointed : %d - %d\n", block_pointed1, block_pointed2);
401                 
402                 /*if((char *) address_pointed1 < (char*)((struct mdesc*)s_heap)->heapbase || block_pointed1 > mdp1->heapsize || block_pointed1 < 1 || (char *) address_pointed2 < (char*)((struct mdesc*)s_heap)->heapbase || block_pointed2 > mdp2->heapsize || block_pointed2 < 1) {
403                   fprintf(stderr, "Unknown pointer ! \n");
404                   fflush(NULL);
405                   distance++;
406                   continue;
407                   }*/
408
409                 if(((char *) address_pointed1 > (char*)((struct mdesc*)s_heap)->heapbase) && (block_pointed1 < mdp1->heapsize) && (block_pointed1 >= 1)){
410                   addr_block_pointed1 = ((void*) (((ADDR2UINT((size_t)block_pointed1)) - 1) * BLOCKSIZE + (char*)heapbase1));
411                   pointer1 = 1;
412                   if(((char *) address_pointed2 > (char*)((struct mdesc*)s_heap)->heapbase) && (block_pointed2 < mdp2->heapsize) && (block_pointed2 >= 1)){
413                     addr_block_pointed2 = ((void*) (((ADDR2UINT((size_t)block_pointed2)) - 1) * BLOCKSIZE + (char*)heapbase2));
414                     pointer2 = 1;
415                   }else{
416                     pointer2 = 0;
417                     addr_block_pointed2 = addr_block2;
418                     block_pointed2 = i;
419                   }
420                 }else{
421                   addr_block_pointed1 = addr_block1;
422                   block_pointed1 = i;
423                   pointer1 = 0;
424                   if(((char *) address_pointed2 > (char*)((struct mdesc*)s_heap)->heapbase) && (block_pointed2 < mdp2->heapsize) && (block_pointed2 >= 1)){
425                     addr_block_pointed2 = ((void*) (((ADDR2UINT((size_t)block_pointed2)) - 1) * BLOCKSIZE + (char*)heapbase2));
426                     pointer2 = 1;
427                   }else{
428                     fprintf(stderr, "Unknown pointers ! \n");
429                     fflush(NULL);
430                     distance++;
431                     continue;
432                   }
433                 }
434
435                 //addr_block_pointed1 = ((void*) (((ADDR2UINT((size_t)block_pointed1)) - 1) * BLOCKSIZE + (char*)heapbase1));
436                 //addr_block_pointed2 = ((void*) (((ADDR2UINT((size_t)block_pointed2)) - 1) * BLOCKSIZE + (char*)heapbase2));
437                 
438                 if(mdp1->heapinfo[block_pointed1].type == mdp2->heapinfo[block_pointed2].type){
439                   
440                   if(mdp1->heapinfo[block_pointed1].type == 0){ // Large block
441                     
442                     if(mdp1->heapinfo[block_pointed1].busy_block.busy_size == mdp2->heapinfo[block_pointed2].busy_block.busy_size){
443                       
444                       if(memcmp(addr_block_pointed1, addr_block_pointed2, mdp1->heapinfo[block_pointed1].busy_block.busy_size) != 0){
445                         distance++;
446                       }else{
447                         fprintf(stderr, "False difference detected\n");
448                       }
449                       
450                     }else{
451                       distance++;
452                     }
453                     
454                   }else{ // Fragmented block
455
456                     if(pointer1)
457                       frag_pointed1 = ((uintptr_t) (ADDR2UINT (address_pointed1) % (BLOCKSIZE))) >> mdp1->heapinfo[block_pointed1].type;
458                     else
459                       frag_pointed1 = j;
460                     if(pointer2)
461                       frag_pointed2 = ((uintptr_t) (ADDR2UINT (address_pointed2) % (BLOCKSIZE))) >> mdp2->heapinfo[block_pointed2].type;
462                     else
463                       frag_pointed2 = j;
464
465                     fprintf(stderr, "Fragments pointed : %d - %d\n", frag_pointed1, frag_pointed2);
466                     
467                     if((frag_pointed1 < 0) || (frag_pointed1 > (BLOCKSIZE / pow( 2, mdp1->heapinfo[block_pointed1].type))) || (frag_pointed2 < 0) || (frag_pointed2 > (BLOCKSIZE / pow( 2, mdp2->heapinfo[block_pointed2].type)))){
468                        fprintf(stderr, "Unknown pointer ! \n");
469                        fflush(NULL);
470                        distance++;
471                        continue;
472                     } 
473
474                     fprintf(stderr, "Size used in fragments pointed : %d - %d\n", mdp1->heapinfo[block_pointed1].busy_frag.frag_size[frag_pointed1], mdp2->heapinfo[block_pointed2].busy_frag.frag_size[frag_pointed2]); 
475                                         
476                     if(mdp1->heapinfo[block_pointed1].busy_frag.frag_size[frag_pointed1] == mdp2->heapinfo[block_pointed2].busy_frag.frag_size[frag_pointed2]){
477                       
478                       if(memcmp(addr_block_pointed1, addr_block_pointed2, mdp1->heapinfo[block_pointed1].busy_frag.frag_size[frag_pointed1]) != 0){
479                         distance++;
480                       }else{
481                         fprintf(stderr, "False difference detected\n");
482                       }
483                       
484                     }else{
485                       distance ++;
486                     }
487                   }
488
489                 }else{
490
491                   if(((mdp1->heapinfo[block_pointed1].type == 0) && (mdp2->heapinfo[block_pointed2].type != 0)) || ((mdp1->heapinfo[block_pointed1].type != 0) && (mdp2->heapinfo[block_pointed2].type == 0))){  
492                     fprintf(stderr, "Pointers on blocks with different types \n");
493                     distance++;
494                   }else{
495
496                     if(pointer1)
497                       frag_pointed1 = ((uintptr_t) (ADDR2UINT (address_pointed1) % (BLOCKSIZE))) >> mdp1->heapinfo[block_pointed1].type;
498                     else
499                       frag_pointed1 = j;
500                     if(pointer2)
501                       frag_pointed2 = ((uintptr_t) (ADDR2UINT (address_pointed2) % (BLOCKSIZE))) >> mdp2->heapinfo[block_pointed2].type;
502                     else
503                       frag_pointed2 = j;
504
505                     fprintf(stderr, "Fragments pointed : %d - %d\n", frag_pointed1, frag_pointed2);
506                     
507                     if((frag_pointed1 < 0) || (frag_pointed1 > (BLOCKSIZE / pow( 2, mdp1->heapinfo[block_pointed1].type))) || (frag_pointed2 < 0) || (frag_pointed2 > (BLOCKSIZE / pow( 2, mdp2->heapinfo[block_pointed2].type)))){
508                        fprintf(stderr, "Unknown pointers ! \n");
509                        fflush(NULL);
510                        distance++;
511                        continue;
512                     } 
513
514                     fprintf(stderr, "Size used in fragments pointed : %d - %d\n", mdp1->heapinfo[block_pointed1].busy_frag.frag_size[frag_pointed1], mdp2->heapinfo[block_pointed2].busy_frag.frag_size[frag_pointed2]); 
515                                         
516                     if(mdp1->heapinfo[block_pointed1].busy_frag.frag_size[frag_pointed1] == mdp2->heapinfo[block_pointed2].busy_frag.frag_size[frag_pointed2]){
517                       
518                       if(memcmp(addr_block_pointed1, addr_block_pointed2, mdp1->heapinfo[block_pointed1].busy_frag.frag_size[frag_pointed1]) != 0){
519                         distance++;
520                       }else{
521                         fprintf(stderr, "False difference detected\n");
522                       }
523                       
524                     }else{
525                       distance ++;
526                     }
527                   }
528                   
529                 }
530               }
531
532             }
533
534             if(distance > 0){
535               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);
536               fprintf(stderr, "Hamming distance between fragments : %d\n", distance);
537               mmalloc_backtrace_fragment_display(mdp1, i, j);
538               mmalloc_backtrace_fragment_display(mdp2, i, j);
539               fprintf(stderr, "\n");
540               errors++;
541               total_distance += distance;
542
543             }
544
545           }
546         }
547
548         i++;
549
550       }else{ /* free block */
551
552         i++;
553
554       }
555
556     }
557
558   }
559
560
561   fprintf(stderr, "Hamming distance between heap regions : %d\n", total_distance);
562
563   return (errors);
564 }
565
566
567 /* void *get_end_addr_heap(void *heap){ */
568
569 /*   FILE *fp;                     /\* File pointer to process's proc maps file *\/ */
570 /*   char *line = NULL;            /\* Temporal storage for each line that is readed *\/ */
571 /*   ssize_t read;                 /\* Number of bytes readed *\/ */
572 /*   size_t n = 0;                 /\* Amount of bytes to read by getline *\/ */
573
574 /*   fp = fopen("/proc/self/maps", "r"); */
575
576 /*   if(fp == NULL) */
577 /*     perror("fopen failed"); */
578
579
580 /*   xbt_dynar_t lfields = NULL; */
581 /*   xbt_dynar_t start_end  = NULL; */
582 /*   void *start_addr; */
583 /*   void *end_addr; */
584
585 /*   while ((read = getline(&line, &n, fp)) != -1) { */
586
587 /*     xbt_str_trim(line, NULL); */
588 /*     xbt_str_strip_spaces(line); */
589 /*     lfields = xbt_str_split(line,NULL); */
590
591 /*     start_end = xbt_str_split(xbt_dynar_get_as(lfields, 0, char*), "-"); */
592 /*     start_addr = (void *) strtoul(xbt_dynar_get_as(start_end, 0, char*), NULL, 16); */
593 /*     end_addr = (void *) strtoul(xbt_dynar_get_as(start_end, 1, char*), NULL, 16); */
594
595 /*     if(start_addr == heap){ */
596 /*       free(line); */
597 /*       fclose(fp); */
598 /*       xbt_dynar_reset(lfields); */
599 /*       xbt_free(lfields); */
600 /*       xbt_dynar_reset(start_end); */
601 /*       xbt_free(start_end); */
602 /*       return end_addr; */
603 /*     } */
604
605 /*   } */
606
607 /*   xbt_dynar_reset(lfields); */
608 /*   xbt_free(lfields); */
609 /*   xbt_dynar_reset(start_end); */
610 /*   xbt_free(start_end); */
611 /*   free(line); */
612 /*   fclose(fp); */
613 /*   return NULL; */
614
615
616 /* } */
617
618
619 void mmalloc_display_info_heap(xbt_mheap_t h){
620
621 }
622
623
624