Logo AND Algorithmique Numérique Distribuée

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