Beispiel #1
0
void *
calloc(size_t nmemb, size_t size)
{
    size_t   newNmemb,newSize,usable;
    void    *ptr, *p;

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

    if ((size * nmemb) == 0){
        /* corner cases */
        /* When size=0 or nmemb=0, */
        /* malloc() maybe return minimum block, */
        newSize = SIZEOF_F_RZ + SIZEOF_SIZE;
        newNmemb = 1;
    }else{
        newSize = size;
        newNmemb = nmemb + ((SIZEOF_F_RZ + SIZEOF_SIZE - 1) / size + 1);
    }
    ptr = real_calloc(newNmemb ,newSize);
    usable = malloc_usable_size(ptr);
    p = ((char*)ptr + (size * nmemb)); /* end of user region */
    memset(p, MAGIC_BYTE, SIZEOF_RZ(usable, size * nmemb));
    p += SIZEOF_RZ(usable,size * nmemb); /* end of redzone */
    *(size_t *)p = size * nmemb;
    OFC_DUMP(ptr, usable, size * nmemb);
    return ptr;
}
Beispiel #2
0
void* calloc(size_t nmemb, size_t size)
{
	void *ptr;
	START_CALL();
	ptr = real_calloc(nmemb, size);
	END_CALL(ptr, (nmemb * size));
	return ptr;
}
Beispiel #3
0
void* calloc(size_t count, size_t size)
{
	if (counter == current_counter++) {
		return NULL;
	}
	static void* (*real_calloc)(size_t count, size_t size);
	if (!real_calloc)
		real_calloc = (void* (*)(size_t, size_t)) dlsym(RTLD_NEXT, "calloc");
	return real_calloc(count, size);
}
Beispiel #4
0
void *calloc(size_t nmemb, size_t size)
{
    /* XXX: This is a dirty hack to enable old dlsym versions to run.
     * Throw it out when Ubuntu 12.04 support runs out (in 2017-04)! */
    if (!real_calloc) {
        return NULL;
    }

    void *r;
    _native_syscall_enter();
    r = real_calloc(nmemb, size);
    _native_syscall_leave();
    return r;
}
static void *
track_calloc (malloc_zone_t * zone, size_t num, size_t size) {
  // Pointer to the allocated object
  char * objp;

  //
  // Perform the allocation.
  //
  objp = (char*) real_calloc (zone, num, size);

  //
  // Record the allocation and return to the caller.
  //
  ExternalObjects.insert(objp, objp + num * size);
  return objp;
}
Beispiel #6
0
void *calloc(size_t nmemb, size_t size)
{
    void *p;
    if(!real_calloc) {
	if(!real_calloc) return NULL;
    	real_calloc = dlsym(RTLD_NEXT, "calloc");
	return NULL;
    }
    p = real_calloc(nmemb, size);
    if(memlog) {
      LOCK;
      fprintf(memlog, "calloc %u %u 0x%08x ", nmemb, size, p);
      print_stack();
      fprintf(memlog, "\n");
      UNLOCK;
    }
    return p;
}
Beispiel #7
0
void *calloc(size_t nmemb, size_t size)
{
	struct log_malloc_s *mem;
	sig_atomic_t memuse;
	sig_atomic_t memruse = 0;
	size_t calloc_size = 0;

	if(!DL_RESOLVE_CHECK(calloc))
		return NULL;

	calloc_size = (nmemb * size);	//FIXME: what about check for overflow here ?
	if((mem = real_calloc(1, calloc_size + MEM_OFF)) != NULL)
	{
		mem->size = calloc_size;
		mem->cb = ~mem->size;
		memuse = __sync_add_and_fetch(&g_ctx.mem_used, mem->size);

#ifdef HAVE_MALLOC_USABLE_SIZE
		mem->rsize = malloc_usable_size(mem);
		memruse = __sync_add_and_fetch(&g_ctx.mem_rused, mem->rsize);
#endif
	}
#ifndef DISABLE_CALL_COUNTS
	(void)__sync_fetch_and_add(&g_ctx.stat.calloc, 1);
	g_ctx.stat.unrel_sum++;
#endif

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

		//getrusage(RUSAGE_SELF, &ruse);
		s = snprintf(buf, sizeof(buf), "+ calloc %zu %p [%u:%u] (%zu %zu)\n",
			nmemb * size, MEM_PTR(mem),
			memuse, memruse,
			nmemb, size);

		log_trace(buf, s, sizeof(buf), 1);
	}
	return MEM_PTR(mem);
}
static void * myth_malloc_wrapper_calloc(size_t nmemb,size_t size)
{
#ifdef MYTH_WRAP_MALLOC_RUNTIME
  /* fall back to the bump allocator before wrapping completed */
  if (!g_wrap_malloc_completed) {
    void *ptr = sys_alloc_align(16, nmemb * size);
    memset(ptr, 0, nmemb * size);
    return ptr;
  }
  /* no wrap. call the real one */
  if (!g_wrap_malloc) {
    return real_calloc(nmemb, size);
  }
#endif
  void *ptr;
  ptr = myth_malloc_wrapper_malloc(nmemb*size);
  if (!ptr)return NULL;
  memset(ptr,0,nmemb*size);
  return ptr;
}
Beispiel #9
0
void *
calloc(size_t number, size_t size)
{
    void *ret;

    if (!inited) {
        init();
    }

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

    ret = real_calloc(number, size);
    if (size >= min_size) {
        count++;
    }

    return ret;
}
Beispiel #10
0
void *calloc(size_t nmemb, size_t size)
{
    /* dynamically load calloc when it's needed - this is necessary to
     * support profiling as it uses calloc before startup runs */
    if (!real_calloc) {
        if (_native_in_calloc) {
            /* XXX: This is a dirty hack to enable old dlsym versions to run.
             * Throw it out when Ubuntu 12.04 support runs out (in 2017-04)! */
            return NULL;
        }
        else {
            _native_in_calloc = 1;
            *(void **)(&real_calloc) = dlsym(RTLD_NEXT, "calloc");
            _native_in_calloc = 0;
        }
    }

    void *r;
    _native_syscall_enter();
    r = real_calloc(nmemb, size);
    _native_syscall_leave();
    return r;
}
Beispiel #11
0
// Replace calloc
void* calloc(size_t nmb,size_t sz)
{
    static __thread int no_hook=0;
    void *ret=NULL;

    if(initializing == -1)
        init();

    if(initializing!=0){ // Avoid circular dependency between calloc and dlsym
        ret=initMalloc(nmb*sz);
        memset(ret,0,nmb*sz);
        return ret;
    }

    ret = real_calloc(nmb,sz);
    if(no_hook==0)
    {
        no_hook=1;
        handle_alloc(nmb*sz,ret, "calloc");
        no_hook=0;
    }
    return ret;
}