27 #define _XOPEN_SOURCE 600
48 #define malloc AV_JOIN(MALLOC_PREFIX, malloc)
49 #define memalign AV_JOIN(MALLOC_PREFIX, memalign)
50 #define posix_memalign AV_JOIN(MALLOC_PREFIX, posix_memalign)
51 #define realloc AV_JOIN(MALLOC_PREFIX, realloc)
52 #define free AV_JOIN(MALLOC_PREFIX, free)
54 void *malloc(
size_t size);
55 void *memalign(
size_t align,
size_t size);
56 int posix_memalign(
void **ptr,
size_t align,
size_t size);
57 void *realloc(
void *ptr,
size_t size);
62 #define ALIGN (HAVE_AVX ? 32 : 16)
78 #if CONFIG_MEMALIGN_HACK
86 #if CONFIG_MEMALIGN_HACK
87 ptr = malloc(size +
ALIGN);
90 diff = ((~(long)ptr)&(
ALIGN - 1)) + 1;
91 ptr = (
char *)ptr + diff;
92 ((
char *)ptr)[-1] = diff;
93 #elif HAVE_POSIX_MEMALIGN
95 if (posix_memalign(&ptr,
ALIGN, size))
97 #elif HAVE_ALIGNED_MALLOC
98 ptr = _aligned_malloc(size,
ALIGN);
101 ptr = memalign(
ALIGN, size);
103 ptr = memalign(size,
ALIGN);
136 #if CONFIG_MEMORY_POISONING
145 #if CONFIG_MEMALIGN_HACK
153 #if CONFIG_MEMALIGN_HACK
157 diff = ((
char *)ptr)[-1];
159 ptr = realloc((
char *)ptr - diff, size + diff);
161 ptr = (
char *)ptr + diff;
163 #elif HAVE_ALIGNED_MALLOC
164 return _aligned_realloc(ptr, size + !size,
ALIGN);
166 return realloc(ptr, size + !size);
207 if (!size || nmemb >= INT_MAX / size)
216 if (!*ptrptr && nmemb && size)
223 #if CONFIG_MEMALIGN_HACK
225 int v= ((
char *)ptr)[-1];
227 free((
char *)ptr - v);
229 #elif HAVE_ALIGNED_MALLOC
238 void **ptr = (
void **)arg;
247 memset(ptr, 0, size);
262 int len = strlen(s) + 1;
276 memcpy(ptr, p, size);
283 void **
tab = *(
void ***)tab_ptr;
287 *(
void ***)tab_ptr = tab;
296 void **
tab = *(
void ***)tab_ptr;
300 *(
void ***)tab_ptr = tab;
313 tab_elem_data = (
uint8_t *)*tab_ptr + (*nb_ptr) * elem_size;
315 memcpy(tab_elem_data, elem_data, elem_size);
316 else if (CONFIG_MEMORY_POISONING)
322 return tab_elem_data;
347 uint32_t
a = v << 8 | v >> 16;
348 uint32_t
b = v << 16 | v >> 8;
349 uint32_t
c = v << 24 |
v;
352 uint32_t a = v | v << 24;
353 uint32_t b = v >> 8 | v << 16;
354 uint32_t c = v >> 16 | v << 8;
406 memset(dst, *src, cnt);
407 }
else if (back == 2) {
409 }
else if (back == 3) {
411 }
else if (back == 4) {
416 while (cnt > blocklen) {
417 memcpy(dst, src, blocklen);
422 memcpy(dst, src, cnt);
451 if (min_size < *size)
454 min_size =
FFMAX(17 * min_size / 16 + 32, min_size);
471 if (min_size < *size)
473 min_size =
FFMAX(17 * min_size / 16 + 32, min_size);