예제 #1
0
	void* _realloc(void* p, size_t size)
	{
		RegisterFree(p);
		void* newP = real_realloc(p ,size);
		RegisterAllocation(newP, size);
		return newP;
	}
static void * myth_malloc_wrapper_realloc(void *ptr,size_t size)
{
#ifdef MYTH_WRAP_MALLOC_RUNTIME
  /* fall back to the bump allocator before wrapping completed */
  if (!g_wrap_malloc_completed) {
    /* leak old ptr */
    void *new_ptr = sys_alloc_align(16, size);
    memcpy(new_ptr, ptr, size);
    return new_ptr;
  }
  /* no wrap. call the real one */
  if (!g_wrap_malloc) {
    return real_realloc(ptr, size);
  }
#endif
  if (size==0){free(ptr);return NULL;}
  if (!ptr)return malloc(size);
  uint64_t *rptr=(uint64_t*)ptr;rptr-=16/8;
  MAY_BE_UNUSED size_t nrsize;
  size_t orsize;
  int oidx,nidx;
  oidx=*rptr;
  if (size<16)size=16;
  nidx=MYTH_MALLOC_SIZE_TO_INDEX(size);
  if (oidx==nidx)return ptr;
  nrsize=MYTH_MALLOC_INDEX_TO_RSIZE(nidx);
  orsize=MYTH_MALLOC_INDEX_TO_RSIZE(*rptr);
  void *nptr = myth_malloc_wrapper_malloc(size);
  if (!nptr)return NULL;
  size_t btc=(size<orsize)?size:orsize;
  memcpy(nptr,ptr,btc);
  myth_malloc_wrapper_free(ptr);
  return nptr;
}
예제 #3
0
void *
realloc(void *ptr, size_t size)
{
    size_t   usable;
    void    *p;

    while (real_realloc == NULL){
        if (!initializing){
            initializing = 1;
            __init();
            initializing = 0;
        }
        sched_yield();
    }

    if (size == 0){
        /* size=0,ptr is not NULL => free(ptr); */
        free(ptr);
        return NULL;
    }

    ptr = real_realloc(ptr, size + SIZEOF_F_RZ + SIZEOF_SIZE);
    usable = malloc_usable_size(ptr);
    /* corner cases */

    /* ptr is NULL => malloc(size); */
    p = ptr + size; /* end of user region */
    memset(p, MAGIC_BYTE, SIZEOF_RZ(usable, size));
    p += SIZEOF_RZ(usable,size); /* end of redzone */
    *(size_t *)p = size;
    OFC_DUMP(ptr, usable, size);
    return ptr;
}
void * __terminal_hook_realloc(void *ptr, size_t size, const void *caller)
{
	static void *(*real_realloc)(void*, size_t);
	if (!real_realloc) real_realloc = fake_dlsym(RTLD_DEFAULT, "__real_realloc");
	if (!real_realloc) real_realloc = fake_dlsym(RTLD_DEFAULT, "realloc"); // probably infinite regress...
	if (!real_realloc) abort();
	return real_realloc(ptr, size);
}
예제 #5
0
파일: syscalls.c 프로젝트: 4dahalibut/RIOT
void *realloc(void *ptr, size_t size)
{
    void *r;
    _native_syscall_enter();
    r = real_realloc(ptr, size);
    _native_syscall_leave();
    return r;
}
예제 #6
0
파일: allocs.c 프로젝트: ocedo/ocheck
void* realloc(void *ptr, size_t size)
{
	void *out_ptr;
	START_CALL();
	out_ptr = real_realloc(ptr, size);
	if (ptr != out_ptr) {
		remove_message_by_ptr(&alloc_msg_store, (uintptr_t)ptr);
		END_CALL(out_ptr, size);
	}
	return out_ptr;
}
예제 #7
0
void *realloc(void *p, size_t s)
{
  xbt_mheap_t mdp = __mmalloc_current_heap;
  void *ret;

  if (mdp) {
    LOCK(mdp);
    ret = mrealloc(mdp, p, s);
    UNLOCK(mdp);
  } else {
    ret = real_realloc(p,s);
  }

  return ret;
}
예제 #8
0
void *realloc(void *ptr, size_t size)
{
    void *p;
    if(!real_realloc) {
	if(!real_realloc) return NULL;
    }
    p = real_realloc(ptr, size);
    if(memlog) {
      LOCK;
      fprintf(memlog, "realloc 0x%08x %u 0x%08x ", ptr, size, p);
      print_stack();
      fprintf(memlog, "\n");
      UNLOCK;
    }
    return p;
}
예제 #9
0
static void *
track_realloc (malloc_zone_t * zone, void * oldp, size_t size) {
  // Pointer to the allocated object
  char * objp;

  //
  // Perform the allocation.
  //
  objp = (char*) real_realloc (zone, oldp, size);

  //
  // Record the allocation and return to the caller.
  //
  ExternalObjects.insert(objp, objp + size);
  return objp;
}
예제 #10
0
void *
realloc(void *ptr, size_t size)
{
    void *ret;

    if (!inited) {
        init();
    }

    if (size >= min_size && count >= max_count) {
        errno = ENOMEM;
        return NULL;
    }

    ret = real_realloc(ptr, size);
    if (size >= min_size) {
        count++;
    }

    return ret;
}
예제 #11
0
void *realloc(void *ptr, size_t size)
{
	struct log_malloc_s *mem;
	sig_atomic_t memuse = 0;
	sig_atomic_t memruse = 0;
	sig_atomic_t memchange = 0;
#ifdef HAVE_MALLOC_USABLE_SIZE
	size_t       rsize = 0;
	sig_atomic_t memrchange = 0;
#endif

	if(!DL_RESOLVE_CHECK(realloc))
		return NULL;

	mem = (ptr != NULL) ? MEM_HEAD(ptr) : NULL;

	//FIXME: not handling foreign memory here (seems not needed)
	if(mem && (mem->size != ~mem->cb))
	{
		assert(mem->size != ~mem->cb);
		return NULL;
	}

	if((mem = real_realloc(mem, size + MEM_OFF)) != NULL)
	{
		memchange = (ptr) ? size - mem->size : size;
		memuse = __sync_add_and_fetch(&g_ctx.mem_used, memchange);

#ifdef HAVE_MALLOC_USABLE_SIZE
		rsize = malloc_usable_size(mem);

		memrchange = (ptr) ? rsize - mem->rsize : rsize;
		memruse = __sync_add_and_fetch(&g_ctx.mem_rused, memrchange);
#endif
	}
#ifndef DISABLE_CALL_COUNTS
	(void)__sync_fetch_and_add(&g_ctx.stat.realloc, 1);
	g_ctx.stat.unrel_sum++;
#endif

	if(!g_ctx.memlog_disabled)
	{
		int s;
		char buf[LOG_BUFSIZE];

		s = snprintf(buf, sizeof(buf), "+ realloc %d %p %p (%zu %zu) [%u:%u]\n",
			memchange, ptr,
			MEM_PTR(mem), (mem ? mem->size : 0), size,
			memuse, memruse);

		log_trace(buf, s, sizeof(buf), 1);
	}

	/* now we can update */
	if(mem != NULL)
	{
		mem->size = size;
		mem->cb = ~mem->size;
#ifdef HAVE_MALLOC_USABLE_SIZE
		mem->rsize = rsize;
#endif
	}
	return MEM_PTR(mem);
}