Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
function check_fraghead to detect mmalloc metadata corruption
authorMarion Guthmuller <marion.guthmuller@loria.fr>
Wed, 10 Oct 2012 13:05:56 +0000 (15:05 +0200)
committerMarion Guthmuller <marion.guthmuller@loria.fr>
Wed, 10 Oct 2012 13:06:25 +0000 (15:06 +0200)
src/xbt/mmalloc/mfree.c
src/xbt/mmalloc/mm_module.c
src/xbt/mmalloc/mmalloc.c
src/xbt/mmalloc/mmprivate.h

index f10f48b..01cf670 100644 (file)
@@ -35,6 +35,7 @@ void mfree(struct mdesc *mdp, void *ptr)
     abort();
   }
 
     abort();
   }
 
+  check_fraghead(mdp);
 
   type = mdp->heapinfo[block].type;
 
 
   type = mdp->heapinfo[block].type;
 
@@ -214,4 +215,6 @@ void mfree(struct mdesc *mdp, void *ptr)
     }
     break;
   }
     }
     break;
   }
+
+  check_fraghead(mdp);
 }
 }
index 1272d4d..87bbb8a 100644 (file)
@@ -339,3 +339,22 @@ void mmalloc_postexit(void)
   //  mmalloc_detach(__mmalloc_default_mdp);
   xbt_mheap_destroy_no_free(__mmalloc_default_mdp);
 }
   //  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");
+
+}
index c54fb4c..aaa9e24 100644 (file)
@@ -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
 
 
   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.
   /* 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;
         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 */
         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);
 
   }
   //printf("(%s) Done mallocing. Result is %p\n",xbt_thread_self_name(),result);fflush(stdout);
+  check_fraghead(mdp);
   return (result);
 }
   return (result);
 }
index 061a4e7..63ee257 100644 (file)
@@ -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)
 
 #define LOCK(mdp) sem_wait(&mdp->sem)
 #define UNLOCK(mdp) sem_post(&mdp->sem)
 
+void check_fraghead(struct mdesc *mdp);
+
 #endif                          /* __MMPRIVATE_H */
 #endif                          /* __MMPRIVATE_H */