コード例 #1
0
ファイル: pos-malloc.c プロジェクト: kunulee/f-stm
void
pos_public_fREe(char *name, Void_t *mem)
{
	struct malloc_state * ar_ptr;
	mchunkptr p;


	/*if (pos_is_mapped(name) == 0) {
		//printf("Not mapped\n");
		return ;
	}*/

	if (mem == (Void_t *)0)
		return;

	p = mem2chunk(mem);

	ar_ptr = (struct malloc_state *)pos_lookup_mstate(name);
	if (ar_ptr == NULL) {
		return;
	}

	(void)mutex_lock(&ar_ptr->mutex);
	pos_int_free(name, ar_ptr, p, 1);
	(void)mutex_unlock(&ar_ptr->mutex);
}
コード例 #2
0
ファイル: pos-malloc.c プロジェクト: kunulee/f-stm
// Call unsafe Pointer Check
void pos_check_unsafe_pointer(char *name)
{
    struct malloc_state * av;
    struct pos_name_entry *name_entry;
    mchunkptr chunk_ptr;
    struct seg_info *head;
    int i = 1;

    av = (struct malloc_state *)pos_lookup_mstate(name);	
    if(av == NULL)   
        printf("Not Allocate Memory\n");

    name_entry = pos_lookup_name_entry(name);
    name_entry -> seg_head = (struct seg_info *)malloc(sizeof(struct seg_info) * 1024);
    memset(name_entry -> seg_head, 0, sizeof(struct seg_info) * 1024);

    //Search Seg_info System call
    syscall(306 , name , name_entry -> seg_head);
    head = name_entry -> seg_head;	

    // First Segment
    chunk_ptr = chunk_at_offset(av, sizeof(struct malloc_state));
    pos_check_unsafe_segment(name, av, head, chunk_ptr);

    // Other Segment
    while(head[i].addr != 0)
    {
        pos_check_unsafe_segment(name, av, head, (Void_t *)head[i].addr);
	i++;
    }
}
コード例 #3
0
ファイル: pos-malloc.c プロジェクト: kunulee/f-stm
Void_t*
pos_public_mALLOc(char *name, unsigned long _bytes)
{
	struct malloc_state *ar_ptr;
	Void_t *victim = NULL;
	size_t bytes = _bytes;
	

	/*if (pos_is_mapped(name) == 0) {
		//printf("Not mapped\n");
		return NULL;
	}*/
	ar_ptr = (struct malloc_state *)pos_lookup_mstate(name);

	if (ar_ptr == NULL) {
		return NULL;
	}
	
	//if(*((size_t *)ar_ptr) == POS_MAGIC)
	if (!have_init_key(ar_ptr)) {
		pos_malloc_init_state(name, ar_ptr);
	}

	(void)mutex_lock(&ar_ptr->mutex);
	victim = pos_int_malloc(name, ar_ptr, bytes);
	(void)mutex_unlock(&ar_ptr->mutex);
	return victim;
}
コード例 #4
0
ファイル: pos-malloc.c プロジェクト: kunulee/f-stm
void *
pos_get_prime_object(char *name)
{
	struct malloc_state *ar_ptr;
	ar_ptr = (struct malloc_state *)pos_lookup_mstate(name);
	if (ar_ptr == NULL) {
		return NULL;
	}

	return ar_ptr->prime_obj;
}
コード例 #5
0
ファイル: pos-malloc.c プロジェクト: kunulee/f-stm
void
pos_set_prime_object(char *name, void *obj)
{
	struct malloc_state *ar_ptr;

	ar_ptr = (struct malloc_state *)pos_lookup_mstate(name);
	if (ar_ptr == NULL) {
		return;
	}

	ar_ptr->prime_obj = obj;
/*#if CONSISTENCY == 1
	POS_WRITE_VAUE(name, (unsigned long *)&ar_ptr->prime_obj, (unsigned long)obj);
#else
	ar_ptr->prime_obj = obj;
#endif*/ 
}
コード例 #6
0
ファイル: pos-malloc.c プロジェクト: kunulee/f-stm
/*
  ------------------------------ pos_test_function ------------------------------
*/
void
pos_print_free_chunks(char *name)
{
	struct malloc_state * av;
	mbinptr	bin;
	mchunkptr p;
	int i;


	av = (struct malloc_state *)pos_lookup_mstate(name);
	if (av == NULL || !have_init_key(av)) {
		printf("\n     Can't print free chunks.\n");
		return;
	}

	printf("\n      ******************** Free chunks of `%s` ************************\n", name);

	printf("      *  1. Fast bins(0~7)\n");
	for (i=0; i< NFASTBINS ; i++) {
		p = (mchunkptr)fastbin(av, i);
		while (p!=0) {
			printf("      *    [%3d] addr=0x%lX, size=%lu", i, (unsigned long int)p, (unsigned long int)chunksize(p));
			if (chunk_is_first(p)) printf("(F)\n");
			else if (chunk_is_last(p)) printf("(L)\n");
			else printf("(M)\n");
			p = p->fd;
		}
	}

	printf("      *  2. Unsorted(1) / Small(2~63) / Large(64~128) bins\n");
	for (i=1; i < NBINS; i++) {
		bin = bin_at(av,i);
		p = bin->fd;
		while (p != bin) {
			printf("      *    [%3d] addr=0x%lX, size=%lu", i, (unsigned long int)p, (unsigned long int)chunksize(p));
			if (chunk_is_first(p)) printf("(F)\n");
			else if (chunk_is_last(p)) printf("(L)\n");
			else printf("(M)\n");
			p = p->fd;
		}
	}

	printf("      ***********************************************************************\n");
}
コード例 #7
0
ファイル: pos-lib.c プロジェクト: chl4651/HEAPO
int register_node_info(char *name, void *node, void *ptr, unsigned long size)
{
	struct malloc_state *av;
	int i;

	av = (struct malloc_state *)pos_lookup_mstate(name);
	if(av == NULL)
		printf("Not Allocate Memory\n");

	av -> node_obj.size = size;
	for(i = 0 ; i < 50 ; i++)
	{
		if(av -> node_obj.ptr_offset[i] == 0)
		{
			av -> node_obj.ptr_offset[i] = (unsigned long)(ptr - node);
			break;
		}		
	}
}
コード例 #8
0
ファイル: pos-malloc.c プロジェクト: kunulee/f-stm
Void_t*
pos_public_rEALLOc(char *name, Void_t *oldmem, unsigned long _bytes)
{
	mstate ar_ptr;
	INTERNAL_SIZE_T nb;      /* padded request size */

	Void_t* newp;             /* chunk to return */

	size_t bytes = _bytes;

	/*if (bytes == 0 && oldmem != NULL) {
		pos_public_fREe(name, oldmem);
		return NULL;
	}*/

	/* realloc of null is supposed to be same as malloc */
	if (oldmem == 0)
		return pos_public_mALLOc(name, bytes);


	/* chunk corresponding to oldmem */
	const mchunkptr oldp = mem2chunk(oldmem);
	/* its size */
	const INTERNAL_SIZE_T oldsize = chunksize(oldp);

	/* Little security check which won't hurt performance: the
	    allocator never wrapps around at the end of the address space.
	    Therefore we can exclude some size values which might appear
	    here by accident or by "design" from some intruder. */
	/*if (__builtin_expect ((uintptr_t) oldp > (uintptr_t) -oldsize, 0)
		|| __builtin_expect (misaligned_chunk (oldp), 0))
	{
		malloc_printerr (check_action, "realloc(): invalid pointer", oldmem);
		return NULL;
	}*/

	checked_request2size(bytes, nb);

	ar_ptr = (struct malloc_state *)pos_lookup_mstate(name);
	if (ar_ptr == NULL) {
		return NULL;
	}

	(void)mutex_lock(&ar_ptr->mutex);
	newp = pos_int_realloc(name, ar_ptr, oldp, oldsize, nb);
	(void)mutex_unlock(&ar_ptr->mutex);

	if (newp == NULL) {
		/* Try harder to allocate memory in other arenas.  */
		newp = pos_public_mALLOc(name, bytes);
		if (newp != NULL) {
			memcpy (newp, oldmem, oldsize - SIZE_SZ);
			
			(void)mutex_lock(&ar_ptr->mutex);
			pos_int_free(name, ar_ptr, oldp, 1);
			(void)mutex_unlock(&ar_ptr->mutex);
		}
	}

	return newp;
}