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);
194 memcpy(&val, ptr,
sizeof(val));
202 memcpy(ptr, &val,
sizeof(val));
208 if (!size || nmemb >= INT_MAX / size)
217 memcpy(&val, ptr,
sizeof(val));
219 memcpy(ptr, &val,
sizeof(val));
220 if (!val && nmemb && size)
228 #if CONFIG_MEMALIGN_HACK
230 int v= ((
char *)ptr)[-1];
232 free((
char *)ptr - v);
234 #elif HAVE_ALIGNED_MALLOC
245 memcpy(&val, arg,
sizeof(val));
246 memcpy(arg, &(
void *){
NULL },
sizeof(
val));
254 memset(ptr, 0, size);
269 int len = strlen(s) + 1;
284 end = memchr(s, 0, len);
303 memcpy(ptr, p, size);
311 memcpy(&tab, tab_ptr,
sizeof(tab));
315 memcpy(tab_ptr, &tab,
sizeof(tab));
325 memcpy(&tab, tab_ptr,
sizeof(tab));
329 memcpy(tab_ptr, &tab,
sizeof(tab));
342 tab_elem_data = (
uint8_t *)*tab_ptr + (*nb_ptr) * elem_size;
344 memcpy(tab_elem_data, elem_data, elem_size);
345 else if (CONFIG_MEMORY_POISONING)
351 return tab_elem_data;
376 uint32_t
a = v << 8 | v >> 16;
377 uint32_t
b = v << 16 | v >> 8;
378 uint32_t
c = v << 24 |
v;
381 uint32_t a = v | v << 24;
382 uint32_t b = v >> 8 | v << 16;
383 uint32_t c = v >> 16 | v << 8;
435 memset(dst, *src, cnt);
436 }
else if (back == 2) {
438 }
else if (back == 3) {
440 }
else if (back == 4) {
445 while (cnt > blocklen) {
446 memcpy(dst, src, blocklen);
451 memcpy(dst, src, cnt);
480 if (min_size < *size)
483 min_size =
FFMAX(17 * min_size / 16 + 32, min_size);
501 if (min_size < *size)
503 min_size =
FFMAX(17 * min_size / 16 + 32, min_size);
506 memcpy(ptr, &val,
sizeof(val));