Logo AND Algorithmique Numérique Distribuée

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