continue;
}
- if(heapinfo1[i1].busy_block.equal_to != NULL){
+ if(heapinfo1[i1].busy_block.equal_to != NULL){
i1++;
continue;
}
-
+
i2 = 1;
equal = 0;
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){
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){
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));
}
+}
+
+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;
+
+
+
}