void* calloc(size_t nm, size_t sz) { cpu_AtomicAdd(&alloc_count, 1); static void *(*libc_calloc)(size_t, size_t); if (libc_calloc == NULL) { if (alloc_has_called_dlsym && !alloc_bootstrapped) { ENSURE(nm*sz <= ARRAY_SIZE(alloc_bootstrap_buffer)); #ifdef ALLOC_DEBUG printf("### calloc-bs(%d, %d) = %p\n", nm, sz, alloc_bootstrap_buffer); #endif alloc_bootstrapped = true; return alloc_bootstrap_buffer; } alloc_has_called_dlsym = true; libc_calloc = (void *(*)(size_t, size_t)) dlsym(RTLD_NEXT, "calloc"); } void* ret = libc_calloc(nm, sz); #ifdef ALLOC_DEBUG printf("### calloc(%d, %d) = %p\n", nm, sz, ret); #endif return ret; }
void *calloc(size_t nmemb, size_t size) { if (inside_init) { if (inside_init == 1) { void *ptr = sbrk(nmemb * size); memset(ptr, 0x00, nmemb * size); return ptr; } else return libc_calloc(nmemb, size); } if (!alloc_handle) contest_alloc_init(); void *addr = alloc_calloc(nmemb, size); contest_tracking(); return addr; }
void *calloc(size_t nmemb, size_t size) { void *p = NULL; if (libc_calloc == NULL) SAVE_LIBC_FUNC(libc_calloc, "calloc"); init_env(); if (mem_allocated + nmemb * size <= mem_threshold) { p = libc_calloc(nmemb, size); } else { log("Restricting calloc of %zu elements per %zu size\n", nmemb, size); errno = ENOMEM; return NULL; } if (!no_hook) account_alloc(p, nmemb * size); return p; }