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;
277 end = memchr(s, 0, len);
296 memcpy(ptr, p, size);
303 void **
tab = *(
void ***)tab_ptr;
307 *(
void ***)tab_ptr = tab;
316 void **
tab = *(
void ***)tab_ptr;
320 *(
void ***)tab_ptr = tab;
333 tab_elem_data = (
uint8_t *)*tab_ptr + (*nb_ptr) * elem_size;
335 memcpy(tab_elem_data, elem_data, elem_size);
336 else if (CONFIG_MEMORY_POISONING)
342 return tab_elem_data;
367 uint32_t
a = v << 8 | v >> 16;
368 uint32_t
b = v << 16 | v >> 8;
369 uint32_t
c = v << 24 |
v;
372 uint32_t a = v | v << 24;
373 uint32_t b = v >> 8 | v << 16;
374 uint32_t c = v >> 16 | v << 8;
426 memset(dst, *src, cnt);
427 }
else if (back == 2) {
429 }
else if (back == 3) {
431 }
else if (back == 4) {
436 while (cnt > blocklen) {
437 memcpy(dst, src, blocklen);
442 memcpy(dst, src, cnt);
471 if (min_size < *size)
474 min_size =
FFMAX(17 * min_size / 16 + 32, min_size);
491 if (min_size < *size)
493 min_size =
FFMAX(17 * min_size / 16 + 32, min_size);