char * strdup_MSVC(const char * str) { char * s; s = (char *) mem_alloc_func(strlen(str) + 1); if (s != NULL) strcpy(s, str); return s; }
INLINE void* hash64_mem_alloc(HASH64_TABLE* hash, UINT32 size) { HASH64_INTERNAL_MEM_ALLOCATION_FUNC mem_alloc_func = hash64_get_mem_alloc_func(hash); if (mem_alloc_func == NULL) { return vmm_memory_alloc(size); } else { return mem_alloc_func(size); } }
void* mem_alloc_func_noninline( /*=====================*/ /* out, own: free storage, NULL if did not succeed */ ulint n, /* in: desired number of bytes */ const char* file_name, /* in: file name where created */ ulint line /* in: line where created */ ) { return(mem_alloc_func(n, file_name, line)); }
static inline void * npw_do_mem_alloc (NPW_MemAllocProcPtr mem_alloc_func, uint32_t size, const char *file, int lineno) { uint32_t real_size; NPW_MemBlock *mem; real_size = sizeof (*mem) + size + 2 * MALLOC_CHECK_GUARD_SIZE; if ((mem = mem_alloc_func (real_size)) == NULL) return NULL; mem->magic = NPW_MALLOC_MAGIC; mem->real_size = real_size; mem->alloc_size = size; mem->alloc_file = file; mem->alloc_lineno = lineno; uint8_t *ptr = (uint8_t *)mem + sizeof (*mem) + MALLOC_CHECK_GUARD_SIZE; malloc_check_guards_init (ptr, size); return ptr; }
void * mem_alloc_tiny_func(size_t size, size_t align #if defined(MEMDBG_ON) , char * file, int line #endif ) { static char * buffer = NULL; static size_t bufree = 0; size_t mask; char * p; #if defined(DEBUG) || defined(MEMDBG) size += align; #endif #ifdef DEBUG /* * We may be called with size zero, for example from ldr_load_pw_line() * that calls mem_alloc_copy() with format->params.salt_size as size. * This causes problems with -DDEBUG without this fix because we never * get out of the while loop when MEM_ALLOC_SIZE is zero too. The * previous fix for this was returning NULL but that lead to other * problems that I did not bother digging into. This fix should be * 100% safe. */ if (size == 0) size = 1; #endif #if ARCH_ALLOWS_UNALIGNED if (mem_saving_level > 2 && align < MEM_ALIGN_SIMD) align = MEM_ALIGN_NONE; #endif mask = align - 1; do { if (buffer) { size_t need = size + mask - (((size_t) buffer + mask) & mask); if (bufree >= need) { p = buffer; p += mask; p -= (size_t) p & mask; bufree -= need; buffer = p + size; #if defined(DEBUG) || defined(MEMDBG) /* Ensure alignment is no better than requested */ if (((size_t) p & ((mask << 1) + 1)) == 0) p += align; #endif return p; } } if (size + mask > MEM_ALLOC_SIZE || bufree > MEM_ALLOC_MAX_WASTE) break; #if defined(MEMDBG_ON) buffer = (char *) mem_alloc_func(MEM_ALLOC_SIZE, file, line); #else buffer = (char *) mem_alloc(MEM_ALLOC_SIZE); #endif add_memory_link((void *) buffer); bufree = MEM_ALLOC_SIZE; } while (1); #if defined(MEMDBG_ON) p = (char *) mem_alloc_func(size + mask, file, line); #else p = (char *) mem_alloc(size + mask); #endif add_memory_link((void *) p); p += mask; p -= (size_t) p & mask; #if defined(DEBUG) || defined(MEMDBG) /* Ensure alignment is no better than requested */ if (((size_t) p & ((mask << 1) + 1)) == 0) p += align; #endif return p; }