Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
cosmetics
[simgrid.git] / src / xbt / mmalloc / mm_diff.c
index a6da007..f32cb5d 100644 (file)
@@ -204,11 +204,11 @@ int mmalloc_compare_heap(xbt_mheap_t heap1, xbt_mheap_t heap2, xbt_dynar_t *stac
         continue;
       }
 
-      if(heapinfo1[i1].busy_block.equal_to != NULL){         
+      if(heapinfo1[i1].busy_block.equal_to != NULL){
         i1++;
         continue;
       }
-      
+    
       i2 = 1;
       equal = 0;
   
@@ -220,7 +220,6 @@ int mmalloc_compare_heap(xbt_mheap_t heap1, xbt_mheap_t heap2, xbt_dynar_t *stac
           if(heapinfo1[current_block].busy_block.busy_size == heapinfo2[current_block].busy_block.busy_size){
 
             addr_block2 = ((void*) (((ADDR2UINT(current_block)) - 1) * BLOCKSIZE + (char*)heapbase2));
-
             real_addr_block2 = (char*)((xbt_mheap_t)s_heap)->heapbase + (((char *)addr_block2) - (char *)heapbase2);
           
             if((stack_name = is_stack(real_addr_block2)) != NULL){
@@ -262,8 +261,7 @@ int mmalloc_compare_heap(xbt_mheap_t heap1, xbt_mheap_t heap2, xbt_dynar_t *stac
 
       while(i2 <= heaplimit && !equal){
 
-        addr_block2 = ((void*) (((ADDR2UINT(i2)) - 1) * BLOCKSIZE + (char*)heapbase2));
-        
+        addr_block2 = ((void*) (((ADDR2UINT(i2)) - 1) * BLOCKSIZE + (char*)heapbase2));        
         real_addr_block2 = (char*)((xbt_mheap_t)s_heap)->heapbase + (((char *)addr_block2) - (char *)heapbase2);
         
         if((stack_name = is_stack(real_addr_block2)) != NULL){
@@ -338,8 +336,8 @@ int mmalloc_compare_heap(xbt_mheap_t heap1, xbt_mheap_t heap2, xbt_dynar_t *stac
 
         if(heapinfo1[i1].busy_frag.frag_size[j1] == 0) /* Free fragment */
           continue;
-        
-        if(heapinfo1[i1].busy_frag.equal_to[j1] != NULL)                
+
+        if(heapinfo1[i1].busy_frag.equal_to[j1] != NULL)
           continue;
 
         addr_frag1 = (void*) ((char *)addr_block1 + (j1 << heapinfo1[i1].type));
@@ -1061,4 +1059,36 @@ static void remove_heap_equality(xbt_dynar_t *equals, int address, void *a){
   }
 
   
+}
+
+int is_free_area(void *area, xbt_mheap_t heap){
+
+  void *sheap = (char *)mmalloc_get_current_heap() - STD_HEAP_SIZE - getpagesize();
+  malloc_info *heapinfo = (malloc_info *)((char *)heap + ((uintptr_t)((char *)heap->heapinfo - (char *)sheap)));
+  size_t heapsize = heap->heapsize;
+
+  /* Get block number */ 
+  size_t block = ((char*)area - (char*)((xbt_mheap_t)sheap)->heapbase) / BLOCKSIZE + 1;
+  size_t fragment;
+
+  /* Check if valid block number */
+  if((char *)area < (char*)((xbt_mheap_t)sheap)->heapbase || block > heapsize || block < 1)
+    return 0;
+
+  if(heapinfo[block].type < 0)
+    return 1;
+
+  if(heapinfo[block].type == 0)
+    return 0;
+
+  if(heapinfo[block].type > 0){
+    fragment = ((uintptr_t) (ADDR2UINT(area) % (BLOCKSIZE))) >> heapinfo[block].type;
+    if(heapinfo[block].busy_frag.frag_size[fragment] == 0)
+      return 1;  
+  }
+
+  return 0;
+  
+
+
 }