static char* umocktypes_stringify_TLSIO_CONFIG_ptr(const TLSIO_CONFIG** value) { char* result; if (*value == NULL) { result = (char*)real_malloc(5); if (result != NULL) { (void)memcpy(result, "NULL", 5); } } else { int length = snprintf(NULL, 0, "{ %p, %p, %s, %d }", (*value)->underlying_io_interface, (*value)->underlying_io_parameters, (*value)->hostname, (*value)->port); if (length < 0) { result = NULL; } else { result = (char*)real_malloc(length + 1); (void)snprintf(result, length + 1, "{ %p, %p, %s, %d }", (*value)->underlying_io_interface, (*value)->underlying_io_parameters, (*value)->hostname, (*value)->port); } } return result; }
void *X(malloc_debug)(size_t n, enum malloc_tag what, const char *file, int line) { char *p; size_t i; struct minfo *info; struct mstat *stat = mstat + what; struct mstat *estat = mstat + EVERYTHING; if (n == 0) n = 1; if (!IN_THREAD) { stat->siz += n; if (stat->siz > stat->maxsiz) stat->maxsiz = stat->siz; estat->siz += n; if (estat->siz > estat->maxsiz) estat->maxsiz = estat->siz; } p = (char *) real_malloc(PAD_FACTOR * n + SZ_HEADER); A(p); /* store the sz in a known position */ ((size_t *) p)[0] = n; ((size_t *) p)[1] = MAGIC; ((size_t *) p)[2] = what; /* fill with junk */ for (i = 0; i < PAD_FACTOR * n; i++) p[i + SZ_HEADER] = (char) (i ^ 0xEF); if (!IN_THREAD) { ++stat->cnt; ++estat->cnt; if (stat->cnt > stat->maxcnt) stat->maxcnt = stat->cnt; if (estat->cnt > estat->maxcnt) estat->maxcnt = estat->cnt; } /* skip the info we stored previously */ p = p + SZ_HEADER; if (!IN_THREAD) { unsigned int h = hashaddr(p); /* record allocation in allocation list */ info = (struct minfo *) malloc(sizeof(struct minfo)); info->n = n; info->file = file; info->line = line; info->p = p; info->next = minfo[h]; minfo[h] = info; } return (void *) p; }
void * malloc(size_t size) { size_t usable; void *ptr, *p; while(real_malloc == NULL){ if(!initializing){ initializing = 1; __init(); initializing = 0; } sched_yield(); } ptr = real_malloc(size + SIZEOF_F_RZ + SIZEOF_SIZE); usable = malloc_usable_size(ptr); 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; }
static int copy_string(char** destination, const char* source) { int result; if (source == NULL) { *destination = NULL; result = 0; } else { size_t length = strlen(source); *destination = (char*)real_malloc(length + 1); if (*destination == NULL) { result = __LINE__; } else { (void)memcpy(*destination, source, length + 1); result = 0; } } return result; }
/* * There is a chicken and egg problem with calloc. dlsym * is calling calloc. So the constructor (init_malloc) will call calloc * to resolve the malloc/realloc/free/... funtions. * Our calloc in turn will call real_malloc and we will end up here when * the constructor is not yet done. * Therefore we need to write a very crude malloc that will return a bit * of space when dlsym needs it. * In other cases it will force the call of the constructor. */ static void *default_malloc(size_t size) { /* * TBD: We should protect extra_space_count access/modification * Now at the time it is used there should not be that many * threads. So is it really needed? */ char *ptr = &extra_space[extra_space_count]; if ((extra_space_count + size) > EXTRA_STATIC_SPACE) { /* * If too much data is requested, this is not dlsym. * So we can force the call to init_malloc. */ init_malloc(); if (real_malloc == default_malloc) { debug("Failed to resolve 'malloc', returning NULL\n"); return NULL; } return real_malloc(size); } else { /* it is assumed this space will never be released */ extra_space_count += size; } return ptr; }
static myth_freelist_t make_chunks(size_t chunk_sz, size_t min_alloc_sz) { #if FIX_FALSE_SHARING4 chunk_sz = (chunk_sz + 63) & ~63; #endif size_t alloc_sz = (chunk_sz <= min_alloc_sz ? min_alloc_sz : chunk_sz); #if 0 fprintf(stderr, "malloc make_chunks(chunk_sz = %ld, min_alloc_sz = %ld, alloc_sz = %ld)\n", chunk_sz, min_alloc_sz, alloc_sz); #endif #if FIX_FALSE_SHARING4 void * region; real_posix_memalign(®ion, 64, alloc_sz); #else void * region = real_malloc(alloc_sz); #endif void * fl = NULL; void * tl = NULL; void * p; for (p = region; p + chunk_sz <= region + alloc_sz; p += chunk_sz) { *((void **)p) = NULL; /* p->next = NULL */ /* append p at the tail of the list */ if (tl) { *((void **)tl) = p; /* fl->next = NULL */ } else { fl = p; } tl = p; } return fl; }
void * __terminal_hook_malloc(size_t size, const void *caller) { static void *(*real_malloc)(size_t); if (!real_malloc) real_malloc = fake_dlsym(RTLD_DEFAULT, "__real_malloc"); if (!real_malloc) real_malloc = fake_dlsym(RTLD_DEFAULT, "malloc"); // probably infinite regress... if (!real_malloc) abort(); return real_malloc(size); }
void *malloc(size_t size) { void *r; _native_syscall_enter(); r = real_malloc(size); _native_syscall_leave(); return r; }
static char* my_IoTHubClient_Auth_Get_SasToken(IOTHUB_AUTHORIZATION_HANDLE handle, const char* scope, size_t expiry_time_relative_seconds, const char* key_name) { (void)handle; (void)expiry_time_relative_seconds; (void)key_name; (void)scope; return (char*)real_malloc(1); }
void* malloc(size_t size) { void *ptr; START_CALL(); ptr = real_malloc(size); END_CALL(ptr, size); return ptr; }
static int my_mallocAndStrcpy_s(char** destination, const char* source) { (void)source; size_t src_len = strlen(source); *destination = (char*)real_malloc(src_len + 1); strcpy(*destination, source); return 0; }
static int umocktypes_copy_WSIO_CONFIG_ptr(WSIO_CONFIG** destination, const WSIO_CONFIG** source) { int result; if (*source == NULL) { *destination = NULL; result = 0; } else { *destination = (WSIO_CONFIG*)real_malloc(sizeof(WSIO_CONFIG)); if (*destination == NULL) { result = __LINE__; } else { if (copy_string((char**)&((*destination)->hostname), (*source)->hostname) != 0) { real_free(*destination); result = __LINE__; } else if (copy_string((char**)&((*destination)->resource_name), (*source)->resource_name) != 0) { real_free((char*)(*destination)->hostname); real_free(*destination); result = __LINE__; } else if (copy_string((char**)&((*destination)->protocol), (*source)->protocol) != 0) { real_free((char*)(*destination)->resource_name); real_free((char*)(*destination)->hostname); real_free(*destination); result = __LINE__; } else { (*destination)->port = (*source)->port; (*destination)->underlying_io_interface = (*source)->underlying_io_interface; if (umocktypes_copy("TLSIO_CONFIG*", &((*destination)->underlying_io_parameters), &((*source)->underlying_io_parameters)) != 0) { real_free((char*)(*destination)->resource_name); real_free((char*)(*destination)->hostname); real_free((char*)(*destination)->protocol); real_free(*destination); result = __LINE__; } else { result = 0; } } } } return result; }
static Evas* create_canvas(int width, int height) { Evas *canvas; Evas_Engine_Info_Buffer *einfo; int method; void *pixels; method = evas_render_method_lookup("buffer"); if (unlikely(method <= 0)) { //fputs("ERROR: evas was not compiled with 'buffer' engine!\n", stderr); return NULL; } canvas = evas_new(); if (unlikely(canvas == NULL)) { //fputs("ERROR: could not instantiate new evas canvas.\n", stderr); return NULL; } evas_output_method_set(canvas, method); evas_output_size_set(canvas, width, height); evas_output_viewport_set(canvas, 0, 0, width, height); einfo = (Evas_Engine_Info_Buffer *)evas_engine_info_get(canvas); if (unlikely(einfo == NULL)) { //fputs("ERROR: could not get evas engine info!\n", stderr); evas_free(canvas); return NULL; } // ARGB32 is sizeof(int), that is 4 bytes, per pixel pixels = real_malloc(width * height * sizeof(int)); if (unlikely(pixels == NULL)) { //fputs("ERROR: could not allocate canvas pixels!\n", stderr); evas_free(canvas); return NULL; } einfo->info.depth_type = EVAS_ENGINE_BUFFER_DEPTH_ARGB32; einfo->info.dest_buffer = pixels; einfo->info.dest_buffer_row_bytes = width * sizeof(int); einfo->info.use_color_key = 0; einfo->info.alpha_threshold = 0; einfo->info.func.new_update_region = NULL; einfo->info.func.free_update_region = NULL; if (unlikely(evas_engine_info_set(canvas,(Evas_Engine_Info*)einfo) == EINA_FALSE)) { PRINTMSG("ERROR: could not set evas engine info!\n"); evas_free(canvas); return NULL; } return canvas; }
void myth_malloc_wrapper_init(int nthreads) { #ifdef MYTH_WRAP_MALLOC_RUNTIME /* check if the user wants to wrap malloc. if not return without doing anything */ if (!g_wrap_malloc) return; #endif assert(real_malloc); #if FIX_FALSE_SHARING1 if (sizeof(myth_freelist_t*)*nthreads < MALLOC_WRAPPER_FL_MIN_SIZE) { g_myth_malloc_wrapper_fl=real_malloc(MALLOC_WRAPPER_FL_MIN_SIZE); } else { g_myth_malloc_wrapper_fl=real_malloc(sizeof(myth_freelist_t*)*nthreads); } #else g_myth_malloc_wrapper_fl=real_malloc(sizeof(myth_freelist_t*)*nthreads); #endif }
void* malloc(size_t size) { if (counter == current_counter++) { return NULL; } static void* (*real_malloc)(size_t size); if (!real_malloc) real_malloc = (void* (*)(size_t)) dlsym(RTLD_NEXT, "malloc"); return real_malloc(size); }
void *malloc(size_t s) { if(!marker) trace_init(); if(s>0x7fffffff) return 0; size_t *p = real_malloc(s+sizeof(s)); if(!p) return p; *p++ = s; void *result = p; VALGRIND_MEMPOOL_ALLOC(&marker, result, s); return result; }
static int umocktypes_copy_HTTP_PROXY_IO_CONFIG_ptr(HTTP_PROXY_IO_CONFIG** destination, const HTTP_PROXY_IO_CONFIG** source) { int result; if (*source == NULL) { *destination = NULL; result = 0; } else { *destination = (HTTP_PROXY_IO_CONFIG*)real_malloc(sizeof(HTTP_PROXY_IO_CONFIG)); if (*destination == NULL) { result = __LINE__; } else { if (copy_string((char**)&((*destination)->hostname), (*source)->hostname) != 0) { real_free(*destination); result = __LINE__; } else if (copy_string((char**)&((*destination)->proxy_hostname), (*source)->proxy_hostname) != 0) { real_free((char*)((*destination)->hostname)); real_free(*destination); result = __LINE__; } else if (copy_string((char**)&((*destination)->username), (*source)->username) != 0) { real_free((char*)((*destination)->proxy_hostname)); real_free((char*)((*destination)->hostname)); real_free(*destination); result = __LINE__; } else if (copy_string((char**)&((*destination)->password), (*source)->password) != 0) { real_free((char*)((*destination)->username)); real_free((char*)((*destination)->proxy_hostname)); real_free((char*)((*destination)->hostname)); real_free(*destination); result = __LINE__; } else { (*destination)->port = (*source)->port; (*destination)->proxy_port = (*source)->proxy_port; result = 0; } } } return result; }
void *malloc(size_t size) { if(real_malloc==NULL) __mtrace_init(); void *p = NULL; fprintf(stderr, "malloc(%d) = ", size); p = real_malloc(size); fprintf(stderr, "%p\n", p); return p; }
void Buffer::Resize(unsigned int newSize) { if (Data == NULL) { Data = (char*)real_malloc(newSize); assert(Data); } else { // Allocate the new size, copy the data, and free the old memory char* newData = (char*)real_malloc(newSize); assert(newData); unsigned int numBytesToCopy = MIN(newSize, CurrentSize); memcpy(newData, Data, numBytesToCopy); real_free(Data); Data = newData; } CurrentSize = newSize; }
ATTRIBUTE_NO_SANITIZE void * bypass_aligned_alloc(size_t alignment, size_t size) noexcept { #if defined(_MSC_VER) void* ptr = _aligned_malloc(size, alignment); #else void* ptr; if (real_aligned_alloc) { ptr = real_aligned_alloc(alignment, size); } else { // emulate alignment by wasting memory void* mem = real_malloc((alignment - 1) + sizeof(void*) + size); uintptr_t uptr = reinterpret_cast<uintptr_t>(mem) + sizeof(void*); uptr += alignment - (uptr & (alignment - 1)); ptr = reinterpret_cast<void*>(uptr); // store original pointer for deallocation (reinterpret_cast<void**>(ptr))[-1] = mem; } #endif if (!ptr) { fprintf(stderr, PPREFIX "bypass_aligned_alloc(%zu align %zu size) = %p (current %zu / %zu)\n", alignment, size, ptr, get(float_curr), get(base_curr)); return ptr; } #if !defined(NDEBUG) && BYPASS_CHECKER { std::unique_lock<std::mutex> lock(s_bypass_mutex); size_t i; for (i = 0; i < kBypassCheckerSize; ++i) { if (s_bypass_checker[i].first != nullptr) continue; s_bypass_checker[i].first = ptr; s_bypass_checker[i].second = size; break; } if (i == kBypassCheckerSize) abort(); } #endif ssize_t mycurr = sync_add_and_fetch(base_curr, size); total_bytes += size; update_peak(float_curr, mycurr); sync_add_and_fetch(total_allocs, 1); sync_add_and_fetch(current_allocs, 1); update_memprofile(get(float_curr), mycurr); return ptr; }
void * malloc(size_t size) { static void * (*real_malloc)(size_t) = NULL; void * ret; if (!real_malloc) real_malloc = dlsym(RTLD_NEXT, "malloc"); //printf ("%p=", malloc); //printf ("%p\n", real_malloc); ret = real_malloc(size); //printf("size = %d address=%p\n", (unsigned int) size, ret); printf("%p = malloc(size = %d)\n", ret, (unsigned int) size); return(ret); }
static char* umocktypes_stringify_HTTP_PROXY_IO_CONFIG_ptr(const HTTP_PROXY_IO_CONFIG** value) { char* result; if (*value == NULL) { result = (char*)real_malloc(5); if (result != NULL) { (void)memcpy(result, "NULL", 5); } } else { int length = snprintf(NULL, 0, "{ %s, %d, %s, %d, %s, %s }", (*value)->hostname, (*value)->port, (*value)->proxy_hostname, (*value)->proxy_port, (*value)->username, (*value)->password); if (length < 0) { result = NULL; } else { result = (char*)real_malloc(length + 1); (void)snprintf(result, length + 1, "{ %s, %d, %s, %d, %s, %s }", (*value)->hostname, (*value)->port, (*value)->proxy_hostname, (*value)->proxy_port, (*value)->username, (*value)->password); } } return result; }
void *malloc(size_t size) { if (real_malloc == NULL) { init(); } if (nghttp2_failmalloc && nghttp2_nmalloc >= nghttp2_failstart) { return NULL; } else { if (nghttp2_countmalloc) { ++nghttp2_nmalloc; } return real_malloc(size); } }
// This version is for linker malloc replacements static void track_system_allocated( void* ptr, size_t len, void * (*real_malloc) (size_t) ) { struct system_allocated_ptr* cur; cur = (struct system_allocated_ptr*) real_malloc(sizeof(struct system_allocated_ptr)); cur->next = system_allocated_head; cur->ptr = ptr; cur->len = len; system_allocated_head = cur; }
static int my_deserialize_and_get_struct_array(void*** dest_arr, size_t* dest_len, JSON_Object* root_object, const char* json_key, FROM_JSON_FUNCTION element_fromJson) { AZURE_UNREFERENCED_PARAMETER(root_object); AZURE_UNREFERENCED_PARAMETER(json_key); AZURE_UNREFERENCED_PARAMETER(element_fromJson); if (error_arr_is_empty) { *dest_len = 0; *dest_arr = NULL; } else { *dest_len = TEST_ARRAY_SIZE; *dest_arr = (void**)real_malloc(*dest_len * sizeof(PROVISIONING_BULK_OPERATION_ERROR*)); for (size_t i = 0; i < *dest_len; i++) { (*dest_arr)[i] = real_malloc(sizeof(PROVISIONING_BULK_OPERATION)); memset((*dest_arr)[i], 0, sizeof(PROVISIONING_BULK_OPERATION)); } } return 0; }
void *X(malloc_plain)(size_t n) { void *p; if (n == 0) n = 1; p = real_malloc(n); CK(p); #ifdef MIN_ALIGMENT A((((uintptr_t)p) % MIN_ALIGNMENT) == 0); #endif return p; }
/* This version use mmalloc if there is a current heap, or the legacy implem if not */ static void *malloc_or_calloc(size_t n, int setzero) { xbt_mheap_t mdp = __mmalloc_current_heap; void *ret; #ifdef MM_LEGACY_VERBOSE static int warned_raw = 0; static int warned_mmalloc = 0; #endif if (mdp) { LOCK(mdp); ret = mmalloc(mdp, n); UNLOCK(mdp); // This was already done by mmalloc: if (mdp->options & XBT_MHEAP_OPTION_MEMSET) { setzero = 0; } #ifdef MM_LEGACY_VERBOSE if (!warned_mmalloc) { fprintf(stderr,"Using mmalloc; enabling the model-checker in cmake may have a bad impact on your simulation performance\n"); warned_mmalloc = 1; } #endif } else if (!real_malloc) { size_t needed_areas = n / JUNK_SIZE; if(needed_areas * JUNK_SIZE != n) needed_areas++; if (allocated_junk+needed_areas>=MAX_JUNK_AREAS) { fprintf(stderr, "Panic: real malloc symbol not resolved yet, and I already gave my little private memory chunk away.\n"); exit(1); } else { size_t i = allocated_junk; allocated_junk += needed_areas; ret = junkareas[i]; } } else { #ifdef MM_LEGACY_VERBOSE if (!warned_raw) { fprintf(stderr,"Using system malloc after interception; you seem to be currently model-checking\n"); warned_raw = 1; } #endif ret = real_malloc(n); } if (ret && setzero) { memset(ret, 0, n); } return ret; }
ATTRIBUTE_NO_SANITIZE void * bypass_malloc(size_t size) noexcept { #if defined(_MSC_VER) void* ptr = malloc(size); #else void* ptr = real_malloc(size); #endif if (!ptr) { fprintf(stderr, PPREFIX "bypass_malloc(%zu size) = %p (current %zu / %zu)\n", size, ptr, get(float_curr), get(base_curr)); return ptr; } if (log_bypass_operations && size >= log_bypass_operations_threshold) { fprintf(stderr, PPREFIX "bypass_malloc(%zu size) = %p (current %zu / %zu)\n", size, ptr, get(float_curr), get(base_curr)); } if (profile_bypass_operations) { tlx::print_raw_backtrace( stdout, 16, PPREFIX "bypass profile %zu", size); } #if !defined(NDEBUG) && BYPASS_CHECKER { std::unique_lock<std::mutex> lock(s_bypass_mutex); size_t i; for (i = 0; i < kBypassCheckerSize; ++i) { if (s_bypass_checker[i].first != nullptr) continue; s_bypass_checker[i].first = ptr; s_bypass_checker[i].second = size; break; } if (i == kBypassCheckerSize) abort(); } #endif ssize_t mycurr = sync_add_and_fetch(base_curr, size); total_bytes += size; update_peak(float_curr, mycurr); sync_add_and_fetch(total_allocs, 1); sync_add_and_fetch(current_allocs, 1); update_memprofile(get(float_curr), mycurr); return ptr; }
static int myth_malloc_wrapper_posix_memalign(void **memptr,size_t alignment,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(alignment, size); if (ptr) { *memptr = ptr; return 0; } else { return ENOMEM; } } /* no wrap. call the real one */ if (!g_wrap_malloc) { return real_posix_memalign(memptr, alignment, size); } #endif if (size == 0) { *memptr = NULL; return 0; } malloc_wrapper_header_t ptr; if (size<16)size=16; if (!real_malloc){ static int load_malloc_protect=0; if (load_malloc_protect==0){ load_malloc_protect=1; real_malloc=dlsym(RTLD_NEXT,"malloc"); } else {*memptr=NULL;return 0;} assert(real_malloc); } uintptr_t n0,n; n0=(uintptr_t)real_malloc(size+alignment+sizeof(malloc_wrapper_header)); if (!n0){ fprintf(stderr,"size=%llu\n",(unsigned long long)size); return ENOMEM; } //align n = n0 + sizeof(malloc_wrapper_header) + alignment - 1; n = n - n % alignment; ptr=(malloc_wrapper_header_t)n;ptr--; assert(n0 <= (uintptr_t)ptr); assert(n + size <= n0 + size+alignment+sizeof(malloc_wrapper_header)); ptr->s.fl_index=FREE_LIST_NUM; ptr->s.org_ptr=(void*)n0; //fprintf(stderr,"memalign A,%p,%p,%p,%d\n",(void*)n0,ptr,(void*)n,FREE_LIST_NUM); *memptr=(void*)n; return 0; }
static void * track_malloc (malloc_zone_t * zone, size_t size) { // Pointer to the allocated object char * objp; // // Perform the allocation. // objp = (char*) real_malloc (zone, size); // // Record the allocation and return to the caller. // ExternalObjects.insert(objp, objp + size); return objp; }