From: Marion Guthmuller Date: Wed, 10 Oct 2012 13:05:56 +0000 (+0200) Subject: function check_fraghead to detect mmalloc metadata corruption X-Git-Tag: v3_8~88 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/4958902994c0093f688d9aea855c43eae2dd6dd2?ds=sidebyside function check_fraghead to detect mmalloc metadata corruption --- diff --git a/src/xbt/mmalloc/mfree.c b/src/xbt/mmalloc/mfree.c index f10f48ba8b..01cf670188 100644 --- a/src/xbt/mmalloc/mfree.c +++ b/src/xbt/mmalloc/mfree.c @@ -35,6 +35,7 @@ void mfree(struct mdesc *mdp, void *ptr) abort(); } + check_fraghead(mdp); type = mdp->heapinfo[block].type; @@ -214,4 +215,6 @@ void mfree(struct mdesc *mdp, void *ptr) } break; } + + check_fraghead(mdp); } diff --git a/src/xbt/mmalloc/mm_module.c b/src/xbt/mmalloc/mm_module.c index 1272d4ddb5..87bbb8a79b 100644 --- a/src/xbt/mmalloc/mm_module.c +++ b/src/xbt/mmalloc/mm_module.c @@ -339,3 +339,22 @@ void mmalloc_postexit(void) // mmalloc_detach(__mmalloc_default_mdp); xbt_mheap_destroy_no_free(__mmalloc_default_mdp); } + +void check_fraghead(struct mdesc *mdp){ + + struct list* next; + int j; + + for (j=8; j<12; j++){ + next = mdp->fraghead[j].next; + if(next != NULL){ + while(next->next != NULL){ + if(next->next->prev == NULL); + next = next->next; + } + } + } + + fprintf(stderr, "check fraghead ok\n"); + +} diff --git a/src/xbt/mmalloc/mmalloc.c b/src/xbt/mmalloc/mmalloc.c index c54fb4c52e..aaa9e242c9 100644 --- a/src/xbt/mmalloc/mmalloc.c +++ b/src/xbt/mmalloc/mmalloc.c @@ -125,6 +125,8 @@ void *mmalloc_no_memset(xbt_mheap_t mdp, size_t size) size_t requested_size = size; // The amount of memory requested by user, for real + check_fraghead(mdp); + /* Work even if the user was stupid enough to ask a ridicullously small block (even 0-length), * ie return a valid block that can be realloced and freed. * glibc malloc does not use this trick but return a constant pointer, but we need to enlist the free fragments later on. @@ -251,6 +253,9 @@ void *mmalloc_no_memset(xbt_mheap_t mdp, size_t size) mdp->heapinfo[block].busy_block.bt_size=xbt_backtrace_no_malloc(mdp->heapinfo[block].busy_block.bt,XBT_BACKTRACE_SIZE); mdp -> heapstats.chunks_used++; mdp -> heapstats.bytes_used += blocks * BLOCKSIZE; + + check_fraghead(mdp); + return result; } /* Need large block(s), but found some in the existing heap */ @@ -294,5 +299,6 @@ void *mmalloc_no_memset(xbt_mheap_t mdp, size_t size) } //printf("(%s) Done mallocing. Result is %p\n",xbt_thread_self_name(),result);fflush(stdout); + check_fraghead(mdp); return (result); } diff --git a/src/xbt/mmalloc/mmprivate.h b/src/xbt/mmalloc/mmprivate.h index 061a4e7bdd..63ee257685 100644 --- a/src/xbt/mmalloc/mmprivate.h +++ b/src/xbt/mmalloc/mmprivate.h @@ -280,4 +280,6 @@ extern void *mmorecore(struct mdesc *mdp, int size); #define LOCK(mdp) sem_wait(&mdp->sem) #define UNLOCK(mdp) sem_post(&mdp->sem) +void check_fraghead(struct mdesc *mdp); + #endif /* __MMPRIVATE_H */