From 8d279fc189349f75156771216621eec1cde29307 Mon Sep 17 00:00:00 2001 From: Marion Guthmuller Date: Tue, 10 Jul 2012 18:39:52 +0200 Subject: [PATCH] model-checker : new recursive function for comparison of block/fragment with pointers --- src/xbt/mmalloc/mm_diff.c | 141 ++++++++++++++++++++++++++++++++++-- src/xbt/mmalloc/mmprivate.h | 2 + 2 files changed, 136 insertions(+), 7 deletions(-) diff --git a/src/xbt/mmalloc/mm_diff.c b/src/xbt/mmalloc/mm_diff.c index e6c78abf36..e61c97f78c 100644 --- a/src/xbt/mmalloc/mm_diff.c +++ b/src/xbt/mmalloc/mm_diff.c @@ -78,6 +78,11 @@ int mmalloc_compare_heap(xbt_mheap_t mdp1, xbt_mheap_t mdp2){ } +void *s_heap; +malloc_info *heapinfo1, *heapinfo2; +void *heapbase1, *heapbase2; +size_t heapsize1, heapsize2; + int mmalloc_compare_mdesc(struct mdesc *mdp1, struct mdesc *mdp2){ int errors = 0; @@ -87,21 +92,24 @@ int mmalloc_compare_mdesc(struct mdesc *mdp1, struct mdesc *mdp2){ return 1; } - void* s_heap = (char *)mmalloc_get_current_heap() - STD_HEAP_SIZE - getpagesize(); + s_heap = (char *)mmalloc_get_current_heap() - STD_HEAP_SIZE - getpagesize(); fprintf(stderr, "s_heap->heapbase : %p\n", ((struct mdesc*)s_heap)->heapbase); - void *heapbase1 = (char *)mdp1 + BLOCKSIZE; - void *heapbase2 = (char *)mdp2 + BLOCKSIZE; + heapbase1 = (char *)mdp1 + BLOCKSIZE; + heapbase2 = (char *)mdp2 + BLOCKSIZE; fprintf(stderr, "Heapbase1 : %p, Heapbase2 : %p\n", heapbase1, heapbase2); fprintf(stderr, "Heapinfo : %p\n", mdp1->heapinfo); - malloc_info* heapinfo1 = (malloc_info *)((char *)mdp1 + ((char *)mdp1->heapinfo - (char *)s_heap)); - malloc_info* heapinfo2 = (malloc_info *)((char *)mdp2 + ((char *)mdp2->heapinfo - (char *)s_heap)); + heapinfo1 = (malloc_info *)((char *)mdp1 + ((char *)mdp1->heapinfo - (char *)s_heap)); + heapinfo2 = (malloc_info *)((char *)mdp2 + ((char *)mdp2->heapinfo - (char *)s_heap)); fprintf(stderr, "Heapinfo1 : %p, Heapinfo2 : %p\n", heapinfo1, heapinfo2); + heapsize1 = mdp1->heapsize; + heapsize2 = mdp2->heapsize; + size_t i, j; void *addr_block1 = NULL, *addr_block2 = NULL, *addr_frag1 = NULL, *addr_frag2 = NULL; size_t frag_size; @@ -168,7 +176,7 @@ int mmalloc_compare_mdesc(struct mdesc *mdp1, struct mdesc *mdp2){ fprintf(stderr, "Blocks pointed : %d - %d\n", block_pointed1, block_pointed2); - 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) { + 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) { fprintf(stderr, "Unknown pointer(s) ! \n"); fflush(NULL); distance++; @@ -328,7 +336,7 @@ int mmalloc_compare_mdesc(struct mdesc *mdp1, struct mdesc *mdp2){ fprintf(stderr, "Blocks pointed : %d - %d\n", block_pointed1, block_pointed2); - 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) { + 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) { fprintf(stderr, "Unknown pointer(s) ! \n"); fflush(NULL); distance++; @@ -453,6 +461,125 @@ int mmalloc_compare_mdesc(struct mdesc *mdp1, struct mdesc *mdp2){ } +int compare_area(void *area1, void* area2, size_t size){ + + int distance = 0; + int i, pointer_align; + void *address_pointed1 = NULL, *address_pointed2 = NULL; + int block_pointed1, block_pointed2, frag_pointed1, frag_pointed2; + void *addr_block_pointed1 = NULL, *addr_block_pointed2 = NULL, *addr_frag_pointed1 = NULL, *addr_frag_pointed2 = NULL; + + for(i=0; iheapbase) / BLOCKSIZE + 1; + block_pointed2 = ((char*)address_pointed2 - (char*)((struct mdesc*)s_heap)->heapbase) / BLOCKSIZE + 1; + + /* Check if valid blocks number */ + 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) { + fprintf(stderr, "Unknown pointer(s) ! \n"); + fflush(NULL); + distance++; + continue; + } + + /* Get address of pointed block in saved heaps */ + addr_block_pointed1 = ((void*) (((ADDR2UINT((size_t)block_pointed1)) - 1) * BLOCKSIZE + (char*)heapbase1)); + addr_block_pointed2 = ((void*) (((ADDR2UINT((size_t)block_pointed2)) - 1) * BLOCKSIZE + (char*)heapbase2)); + + if(heapinfo1[block_pointed1].type == heapinfo2[block_pointed2].type){ /* Same type of block (large or fragmented) */ + + if(heapinfo1[block_pointed1].type == 0){ /* Large block */ + + if(heapinfo1[block_pointed1].busy_block.busy_size == heapinfo2[block_pointed2].busy_block.busy_size){ + + if(compare_area(addr_block_pointed1, addr_block_pointed2, heapinfo1[block_pointed1].busy_block.busy_size) != 0){ + /* FIXME : Check temp list of differences */ + distance++; + }else{ + fprintf(stderr, "False difference detected\n"); + } + + }else{ + /* FIXME : Add blocks in temp list of differences */ + distance++; + } + + }else{ /* Fragmented block */ + + /* Get pointed fragments number */ + frag_pointed1 = ((uintptr_t) (ADDR2UINT (address_pointed1) % (BLOCKSIZE))) >> ((struct mdesc*)s_heap)->heapinfo[block_pointed1].type; + frag_pointed2 = ((uintptr_t) (ADDR2UINT (address_pointed2) % (BLOCKSIZE))) >> ((struct mdesc*)s_heap)->heapinfo[block_pointed2].type; + + /* Get address of pointed fragments in saved heaps */ + addr_frag_pointed1 = (char*)addr_block_pointed1 + (frag_pointed1 * (int)pow(2, heapinfo1[block_pointed1].type)); + addr_frag_pointed2 = (char*)addr_block_pointed2 + (frag_pointed2 * (int)pow(2, heapinfo2[block_pointed2].type)); + + if(heapinfo1[block_pointed1].busy_frag.frag_size[frag_pointed1] == heapinfo2[block_pointed2].busy_frag.frag_size[frag_pointed2]){ + + if(compare_area(addr_frag_pointed1, addr_frag_pointed2, heapinfo1[block_pointed1].busy_frag.frag_size[frag_pointed1]) != 0){ + /* FIXME : Check in temp list of differences */ + distance++; + }else{ + fprintf(stderr, "False difference detected\n"); + } + + }else{ + /* FIXME : Check in temp list of differences */ + distance ++; + } + + } + + }else{ /* Can be fragmented block with different fragments size but same size_used */ + + if(((heapinfo1[block_pointed1].type == 0) && (heapinfo2[block_pointed2].type != 0)) || ((heapinfo1[block_pointed1].type != 0) && (heapinfo2[block_pointed2].type == 0))){ + + fprintf(stderr, "Pointers on blocks with different types \n"); + distance++; + + }else{ + + /* Get pointed fragments number */ + frag_pointed1 = ((uintptr_t) (ADDR2UINT (address_pointed1) % (BLOCKSIZE))) >> ((struct mdesc*)s_heap)->heapinfo[block_pointed1].type; + frag_pointed2 = ((uintptr_t) (ADDR2UINT (address_pointed2) % (BLOCKSIZE))) >> ((struct mdesc*)s_heap)->heapinfo[block_pointed2].type; + + /* Get address of pointed fragments in saved heaps */ + addr_frag_pointed1 = (char*)addr_block_pointed1 + (frag_pointed1 * (int)pow(2, heapinfo1[block_pointed1].type)); + addr_frag_pointed2 = (char*)addr_block_pointed2 + (frag_pointed2 * (int)pow(2, heapinfo2[block_pointed2].type)); + + if(heapinfo1[block_pointed1].busy_frag.frag_size[frag_pointed1] == heapinfo2[block_pointed2].busy_frag.frag_size[frag_pointed2]){ + + if(compare_area(addr_frag_pointed1, addr_frag_pointed2, heapinfo1[block_pointed1].busy_frag.frag_size[frag_pointed1]) != 0){ + /* FIXME : Check temp list of differences */ + distance++; + }else{ + fprintf(stderr, "False difference detected\n"); + } + + }else{ + /* FIXME : Check list of differences */ + distance ++; + } + + } + + } + } + } + + return distance; + +} + + /* void *get_end_addr_heap(void *heap){ */ /* FILE *fp; /\* File pointer to process's proc maps file *\/ */ diff --git a/src/xbt/mmalloc/mmprivate.h b/src/xbt/mmalloc/mmprivate.h index da1b01e07e..34ce8ec1b5 100644 --- a/src/xbt/mmalloc/mmprivate.h +++ b/src/xbt/mmalloc/mmprivate.h @@ -240,6 +240,8 @@ struct mdesc { int mmalloc_compare_mdesc(struct mdesc *mdp1, struct mdesc *mdp2); +int compare_area(void *area1, void *area2, size_t size); + //void *get_end_addr_heap(void *s_heap); /* Bits to look at in the malloc descriptor flags word */ -- 2.20.1