@@ -67,6 +67,9 @@ libc {
GLIBC_2.33 {
mallinfo2;
}
+ GLIBC_2.38 {
+ __libc_aligned_alloc;
+ }
GLIBC_PRIVATE {
# Internal startup hook for libpthread.
__libc_malloc_pthread_startup;
@@ -268,7 +268,8 @@ __debug_realloc (void *oldmem, size_t bytes)
strong_alias (__debug_realloc, realloc)
static void *
-_debug_mid_memalign (size_t alignment, size_t bytes, const void *address)
+_debug_mid_memalign (size_t alignment, size_t bytes, const void *address,
+ int check_alignment)
{
void *(*hook) (size_t, size_t, const void *) =
atomic_forced_read (__memalign_hook);
@@ -281,9 +282,15 @@ _debug_mid_memalign (size_t alignment, size_t bytes, const void *address)
if ((!__is_malloc_debug_enabled (MALLOC_MCHECK_HOOK)
|| !memalign_mcheck_before (alignment, &bytes, &victim)))
{
- victim = (__is_malloc_debug_enabled (MALLOC_CHECK_HOOK)
- ? memalign_check (alignment, bytes)
- : __libc_memalign (alignment, bytes));
+ if (check_alignment && !powerof2 (alignment))
+ {
+ __set_errno (EINVAL);
+ victim = NULL;
+ }
+ else
+ victim = (__is_malloc_debug_enabled (MALLOC_CHECK_HOOK)
+ ? memalign_check (alignment, bytes)
+ : __libc_memalign (alignment, bytes));
}
if (__is_malloc_debug_enabled (MALLOC_MCHECK_HOOK) && victim != NULL)
victim = memalign_mcheck_after (victim, alignment, orig_bytes);
@@ -296,10 +303,15 @@ _debug_mid_memalign (size_t alignment, size_t bytes, const void *address)
static void *
__debug_memalign (size_t alignment, size_t bytes)
{
- return _debug_mid_memalign (alignment, bytes, RETURN_ADDRESS (0));
+ return _debug_mid_memalign (alignment, bytes, RETURN_ADDRESS (0), 0);
}
strong_alias (__debug_memalign, memalign)
-strong_alias (__debug_memalign, aligned_alloc)
+static void *
+__debug_aligned_alloc (size_t alignment, size_t bytes)
+{
+ return _debug_mid_memalign (alignment, bytes, RETURN_ADDRESS (0), 1);
+}
+strong_alias (__debug_aligned_alloc, aligned_alloc)
static void *
__debug_pvalloc (size_t bytes)
@@ -319,7 +331,7 @@ __debug_pvalloc (size_t bytes)
}
rounded_bytes = rounded_bytes & -(pagesize - 1);
- return _debug_mid_memalign (pagesize, rounded_bytes, RETURN_ADDRESS (0));
+ return _debug_mid_memalign (pagesize, rounded_bytes, RETURN_ADDRESS (0), 0);
}
strong_alias (__debug_pvalloc, pvalloc)
@@ -329,7 +341,7 @@ __debug_valloc (size_t bytes)
if (!pagesize)
pagesize = sysconf (_SC_PAGESIZE);
- return _debug_mid_memalign (pagesize, bytes, RETURN_ADDRESS (0));
+ return _debug_mid_memalign (pagesize, bytes, RETURN_ADDRESS (0), 0);
}
strong_alias (__debug_valloc, valloc)
@@ -343,7 +355,7 @@ __debug_posix_memalign (void **memptr, size_t alignment, size_t bytes)
|| alignment == 0)
return EINVAL;
- *memptr = _debug_mid_memalign (alignment, bytes, RETURN_ADDRESS (0));
+ *memptr = _debug_mid_memalign (alignment, bytes, RETURN_ADDRESS (0), 0);
if (*memptr == NULL)
return ENOMEM;
@@ -656,6 +656,9 @@ libc_hidden_proto (__libc_realloc)
void* __libc_memalign(size_t, size_t);
libc_hidden_proto (__libc_memalign)
+void * __libc_aligned_alloc (size_t alignment, size_t bytes);
+libc_hidden_proto (__libc_aligned_alloc)
+
/*
valloc(size_t n);
Equivalent to memalign(pagesize, n), where pagesize is the page
@@ -3509,6 +3512,27 @@ __libc_memalign (size_t alignment, size_t bytes)
void *address = RETURN_ADDRESS (0);
return _mid_memalign (alignment, bytes, address);
}
+libc_hidden_def (__libc_memalign)
+
+/* For ISO C11. */
+void *
+__libc_aligned_alloc (size_t alignment, size_t bytes)
+{
+ if (!__malloc_initialized)
+ ptmalloc_init ();
+
+ /* Similar to memalign, but ISO C17 requires an error for invalid
+ alignments. Valid alignments are non-negative powers of two. */
+ if (!powerof2 (alignment) || alignment == 0)
+ {
+ __set_errno (EINVAL);
+ return 0;
+ }
+
+ void *address = RETURN_ADDRESS (0);
+ return _mid_memalign (alignment, bytes, address);
+}
+libc_hidden_def (__libc_aligned_alloc)
static void *
_mid_memalign (size_t alignment, size_t bytes, void *address)
@@ -3567,9 +3591,6 @@ _mid_memalign (size_t alignment, size_t bytes, void *address)
ar_ptr == arena_for_chunk (mem2chunk (p)));
return tag_new_usable (p);
}
-/* For ISO C11. */
-weak_alias (__libc_memalign, aligned_alloc)
-libc_hidden_def (__libc_memalign)
void *
__libc_valloc (size_t bytes)
@@ -5903,6 +5924,7 @@ weak_alias (__libc_mallinfo, mallinfo)
strong_alias (__libc_mallinfo2, __mallinfo2)
weak_alias (__libc_mallinfo2, mallinfo2)
strong_alias (__libc_mallopt, __mallopt) weak_alias (__libc_mallopt, mallopt)
+weak_alias (__libc_aligned_alloc, aligned_alloc)
weak_alias (__malloc_stats, malloc_stats)
weak_alias (__malloc_usable_size, malloc_usable_size)
@@ -995,7 +995,7 @@ power of two than that, use @code{aligned_alloc} or @code{posix_memalign}.
@c Alias to memalign.
The @code{aligned_alloc} function allocates a block of @var{size} bytes whose
address is a multiple of @var{alignment}. The @var{alignment} must be a
-power of two and @var{size} must be a multiple of @var{alignment}.
+power of two.
The @code{aligned_alloc} function returns a null pointer on error and sets
@code{errno} to one of the following values:
@@ -1 +1,2 @@
GLIBC_2.36 pidfd_getfd F
+GLIBC_2.38 __libc_aligned_alloc F
@@ -2326,6 +2326,7 @@ GLIBC_2.38 __isoc23_wcstoull F
GLIBC_2.38 __isoc23_wcstoull_l F
GLIBC_2.38 __isoc23_wcstoumax F
GLIBC_2.38 __isoc23_wscanf F
+GLIBC_2.38 __libc_aligned_alloc F
GLIBC_2.4 __confstr_chk F
GLIBC_2.4 __fgets_chk F
GLIBC_2.4 __fgets_unlocked_chk F
@@ -2665,3 +2665,4 @@ GLIBC_2.38 __isoc23_wcstoull F
GLIBC_2.38 __isoc23_wcstoull_l F
GLIBC_2.38 __isoc23_wcstoumax F
GLIBC_2.38 __isoc23_wscanf F
+GLIBC_2.38 __libc_aligned_alloc F
@@ -2762,6 +2762,7 @@ GLIBC_2.38 __isoc23_wcstoull F
GLIBC_2.38 __isoc23_wcstoull_l F
GLIBC_2.38 __isoc23_wcstoumax F
GLIBC_2.38 __isoc23_wscanf F
+GLIBC_2.38 __libc_aligned_alloc F
GLIBC_2.38 __nldbl___isoc23_fscanf F
GLIBC_2.38 __nldbl___isoc23_fwscanf F
GLIBC_2.38 __nldbl___isoc23_scanf F
@@ -2426,3 +2426,4 @@ GLIBC_2.38 __isoc23_wcstoull F
GLIBC_2.38 __isoc23_wcstoull_l F
GLIBC_2.38 __isoc23_wcstoumax F
GLIBC_2.38 __isoc23_wscanf F
+GLIBC_2.38 __libc_aligned_alloc F
@@ -546,6 +546,7 @@ GLIBC_2.38 __isoc23_wcstoull F
GLIBC_2.38 __isoc23_wcstoull_l F
GLIBC_2.38 __isoc23_wcstoumax F
GLIBC_2.38 __isoc23_wscanf F
+GLIBC_2.38 __libc_aligned_alloc F
GLIBC_2.4 _Exit F
GLIBC_2.4 _IO_2_1_stderr_ D 0xa0
GLIBC_2.4 _IO_2_1_stdin_ D 0xa0
@@ -543,6 +543,7 @@ GLIBC_2.38 __isoc23_wcstoull F
GLIBC_2.38 __isoc23_wcstoull_l F
GLIBC_2.38 __isoc23_wcstoumax F
GLIBC_2.38 __isoc23_wscanf F
+GLIBC_2.38 __libc_aligned_alloc F
GLIBC_2.4 _Exit F
GLIBC_2.4 _IO_2_1_stderr_ D 0xa0
GLIBC_2.4 _IO_2_1_stdin_ D 0xa0
@@ -2702,3 +2702,4 @@ GLIBC_2.38 __isoc23_wcstoull F
GLIBC_2.38 __isoc23_wcstoull_l F
GLIBC_2.38 __isoc23_wcstoumax F
GLIBC_2.38 __isoc23_wscanf F
+GLIBC_2.38 __libc_aligned_alloc F
@@ -2651,6 +2651,7 @@ GLIBC_2.38 __isoc23_wcstoull F
GLIBC_2.38 __isoc23_wcstoull_l F
GLIBC_2.38 __isoc23_wcstoumax F
GLIBC_2.38 __isoc23_wscanf F
+GLIBC_2.38 __libc_aligned_alloc F
GLIBC_2.4 __confstr_chk F
GLIBC_2.4 __fgets_chk F
GLIBC_2.4 __fgets_unlocked_chk F
@@ -2835,6 +2835,7 @@ GLIBC_2.38 __isoc23_wcstoull F
GLIBC_2.38 __isoc23_wcstoull_l F
GLIBC_2.38 __isoc23_wcstoumax F
GLIBC_2.38 __isoc23_wscanf F
+GLIBC_2.38 __libc_aligned_alloc F
GLIBC_2.4 __confstr_chk F
GLIBC_2.4 __fgets_chk F
GLIBC_2.4 __fgets_unlocked_chk F
@@ -2600,6 +2600,7 @@ GLIBC_2.38 __isoc23_wcstoull F
GLIBC_2.38 __isoc23_wcstoull_l F
GLIBC_2.38 __isoc23_wcstoumax F
GLIBC_2.38 __isoc23_wscanf F
+GLIBC_2.38 __libc_aligned_alloc F
GLIBC_2.4 __confstr_chk F
GLIBC_2.4 __fgets_chk F
GLIBC_2.4 __fgets_unlocked_chk F
@@ -2186,3 +2186,4 @@ GLIBC_2.38 __isoc23_wcstoull F
GLIBC_2.38 __isoc23_wcstoull_l F
GLIBC_2.38 __isoc23_wcstoumax F
GLIBC_2.38 __isoc23_wscanf F
+GLIBC_2.38 __libc_aligned_alloc F
@@ -547,6 +547,7 @@ GLIBC_2.38 __isoc23_wcstoull F
GLIBC_2.38 __isoc23_wcstoull_l F
GLIBC_2.38 __isoc23_wcstoumax F
GLIBC_2.38 __isoc23_wscanf F
+GLIBC_2.38 __libc_aligned_alloc F
GLIBC_2.4 _Exit F
GLIBC_2.4 _IO_2_1_stderr_ D 0x98
GLIBC_2.4 _IO_2_1_stdin_ D 0x98
@@ -2778,6 +2778,7 @@ GLIBC_2.38 __isoc23_wcstoull F
GLIBC_2.38 __isoc23_wcstoull_l F
GLIBC_2.38 __isoc23_wcstoumax F
GLIBC_2.38 __isoc23_wscanf F
+GLIBC_2.38 __libc_aligned_alloc F
GLIBC_2.4 __confstr_chk F
GLIBC_2.4 __fgets_chk F
GLIBC_2.4 __fgets_unlocked_chk F
@@ -2751,3 +2751,4 @@ GLIBC_2.38 __isoc23_wcstoull F
GLIBC_2.38 __isoc23_wcstoull_l F
GLIBC_2.38 __isoc23_wcstoumax F
GLIBC_2.38 __isoc23_wscanf F
+GLIBC_2.38 __libc_aligned_alloc F
@@ -2748,3 +2748,4 @@ GLIBC_2.38 __isoc23_wcstoull F
GLIBC_2.38 __isoc23_wcstoull_l F
GLIBC_2.38 __isoc23_wcstoumax F
GLIBC_2.38 __isoc23_wscanf F
+GLIBC_2.38 __libc_aligned_alloc F
@@ -2743,6 +2743,7 @@ GLIBC_2.38 __isoc23_wcstoull F
GLIBC_2.38 __isoc23_wcstoull_l F
GLIBC_2.38 __isoc23_wcstoumax F
GLIBC_2.38 __isoc23_wscanf F
+GLIBC_2.38 __libc_aligned_alloc F
GLIBC_2.4 __confstr_chk F
GLIBC_2.4 __fgets_chk F
GLIBC_2.4 __fgets_unlocked_chk F
@@ -2741,6 +2741,7 @@ GLIBC_2.38 __isoc23_wcstoull F
GLIBC_2.38 __isoc23_wcstoull_l F
GLIBC_2.38 __isoc23_wcstoumax F
GLIBC_2.38 __isoc23_wscanf F
+GLIBC_2.38 __libc_aligned_alloc F
GLIBC_2.4 __confstr_chk F
GLIBC_2.4 __fgets_chk F
GLIBC_2.4 __fgets_unlocked_chk F
@@ -2749,6 +2749,7 @@ GLIBC_2.38 __isoc23_wcstoull F
GLIBC_2.38 __isoc23_wcstoull_l F
GLIBC_2.38 __isoc23_wcstoumax F
GLIBC_2.38 __isoc23_wscanf F
+GLIBC_2.38 __libc_aligned_alloc F
GLIBC_2.4 __confstr_chk F
GLIBC_2.4 __fgets_chk F
GLIBC_2.4 __fgets_unlocked_chk F
@@ -2651,6 +2651,7 @@ GLIBC_2.38 __isoc23_wcstoull F
GLIBC_2.38 __isoc23_wcstoull_l F
GLIBC_2.38 __isoc23_wcstoumax F
GLIBC_2.38 __isoc23_wscanf F
+GLIBC_2.38 __libc_aligned_alloc F
GLIBC_2.4 __confstr_chk F
GLIBC_2.4 __fgets_chk F
GLIBC_2.4 __fgets_unlocked_chk F
@@ -2790,3 +2790,4 @@ GLIBC_2.38 __isoc23_wcstoull F
GLIBC_2.38 __isoc23_wcstoull_l F
GLIBC_2.38 __isoc23_wcstoumax F
GLIBC_2.38 __isoc23_wscanf F
+GLIBC_2.38 __libc_aligned_alloc F
@@ -2172,3 +2172,4 @@ GLIBC_2.38 __isoc23_wcstoull F
GLIBC_2.38 __isoc23_wcstoull_l F
GLIBC_2.38 __isoc23_wcstoumax F
GLIBC_2.38 __isoc23_wscanf F
+GLIBC_2.38 __libc_aligned_alloc F
@@ -2805,6 +2805,7 @@ GLIBC_2.38 __isoc23_wcstoull F
GLIBC_2.38 __isoc23_wcstoull_l F
GLIBC_2.38 __isoc23_wcstoumax F
GLIBC_2.38 __isoc23_wscanf F
+GLIBC_2.38 __libc_aligned_alloc F
GLIBC_2.38 __nldbl___isoc23_fscanf F
GLIBC_2.38 __nldbl___isoc23_fwscanf F
GLIBC_2.38 __nldbl___isoc23_scanf F
@@ -2838,6 +2838,7 @@ GLIBC_2.38 __isoc23_wcstoull F
GLIBC_2.38 __isoc23_wcstoull_l F
GLIBC_2.38 __isoc23_wcstoumax F
GLIBC_2.38 __isoc23_wscanf F
+GLIBC_2.38 __libc_aligned_alloc F
GLIBC_2.38 __nldbl___isoc23_fscanf F
GLIBC_2.38 __nldbl___isoc23_fwscanf F
GLIBC_2.38 __nldbl___isoc23_scanf F
@@ -2559,6 +2559,7 @@ GLIBC_2.38 __isoc23_wcstoull F
GLIBC_2.38 __isoc23_wcstoull_l F
GLIBC_2.38 __isoc23_wcstoumax F
GLIBC_2.38 __isoc23_wscanf F
+GLIBC_2.38 __libc_aligned_alloc F
GLIBC_2.38 __nldbl___isoc23_fscanf F
GLIBC_2.38 __nldbl___isoc23_fwscanf F
GLIBC_2.38 __nldbl___isoc23_scanf F
@@ -2873,6 +2873,7 @@ GLIBC_2.38 __isoc23_wcstoull_l F
GLIBC_2.38 __isoc23_wcstoumax F
GLIBC_2.38 __isoc23_wscanf F
GLIBC_2.38 __isoc23_wscanfieee128 F
+GLIBC_2.38 __libc_aligned_alloc F
GLIBC_2.38 __nldbl___isoc23_fscanf F
GLIBC_2.38 __nldbl___isoc23_fwscanf F
GLIBC_2.38 __nldbl___isoc23_scanf F
@@ -2428,3 +2428,4 @@ GLIBC_2.38 __isoc23_wcstoull F
GLIBC_2.38 __isoc23_wcstoull_l F
GLIBC_2.38 __isoc23_wcstoumax F
GLIBC_2.38 __isoc23_wscanf F
+GLIBC_2.38 __libc_aligned_alloc F
@@ -2628,3 +2628,4 @@ GLIBC_2.38 __isoc23_wcstoull F
GLIBC_2.38 __isoc23_wcstoull_l F
GLIBC_2.38 __isoc23_wcstoumax F
GLIBC_2.38 __isoc23_wscanf F
+GLIBC_2.38 __libc_aligned_alloc F
@@ -2803,6 +2803,7 @@ GLIBC_2.38 __isoc23_wcstoull F
GLIBC_2.38 __isoc23_wcstoull_l F
GLIBC_2.38 __isoc23_wcstoumax F
GLIBC_2.38 __isoc23_wscanf F
+GLIBC_2.38 __libc_aligned_alloc F
GLIBC_2.38 __nldbl___isoc23_fscanf F
GLIBC_2.38 __nldbl___isoc23_fwscanf F
GLIBC_2.38 __nldbl___isoc23_scanf F
@@ -2596,6 +2596,7 @@ GLIBC_2.38 __isoc23_wcstoull F
GLIBC_2.38 __isoc23_wcstoull_l F
GLIBC_2.38 __isoc23_wcstoumax F
GLIBC_2.38 __isoc23_wscanf F
+GLIBC_2.38 __libc_aligned_alloc F
GLIBC_2.38 __nldbl___isoc23_fscanf F
GLIBC_2.38 __nldbl___isoc23_fwscanf F
GLIBC_2.38 __nldbl___isoc23_scanf F
@@ -2658,6 +2658,7 @@ GLIBC_2.38 __isoc23_wcstoull F
GLIBC_2.38 __isoc23_wcstoull_l F
GLIBC_2.38 __isoc23_wcstoumax F
GLIBC_2.38 __isoc23_wscanf F
+GLIBC_2.38 __libc_aligned_alloc F
GLIBC_2.4 __confstr_chk F
GLIBC_2.4 __fgets_chk F
GLIBC_2.4 __fgets_unlocked_chk F
@@ -2655,6 +2655,7 @@ GLIBC_2.38 __isoc23_wcstoull F
GLIBC_2.38 __isoc23_wcstoull_l F
GLIBC_2.38 __isoc23_wcstoumax F
GLIBC_2.38 __isoc23_wscanf F
+GLIBC_2.38 __libc_aligned_alloc F
GLIBC_2.4 __confstr_chk F
GLIBC_2.4 __fgets_chk F
GLIBC_2.4 __fgets_unlocked_chk F
@@ -2798,6 +2798,7 @@ GLIBC_2.38 __isoc23_wcstoull F
GLIBC_2.38 __isoc23_wcstoull_l F
GLIBC_2.38 __isoc23_wcstoumax F
GLIBC_2.38 __isoc23_wscanf F
+GLIBC_2.38 __libc_aligned_alloc F
GLIBC_2.38 __nldbl___isoc23_fscanf F
GLIBC_2.38 __nldbl___isoc23_fwscanf F
GLIBC_2.38 __nldbl___isoc23_scanf F
@@ -2623,6 +2623,7 @@ GLIBC_2.38 __isoc23_wcstoull F
GLIBC_2.38 __isoc23_wcstoull_l F
GLIBC_2.38 __isoc23_wcstoumax F
GLIBC_2.38 __isoc23_wscanf F
+GLIBC_2.38 __libc_aligned_alloc F
GLIBC_2.4 __confstr_chk F
GLIBC_2.4 __fgets_chk F
GLIBC_2.4 __fgets_unlocked_chk F
@@ -2574,6 +2574,7 @@ GLIBC_2.38 __isoc23_wcstoull F
GLIBC_2.38 __isoc23_wcstoull_l F
GLIBC_2.38 __isoc23_wcstoumax F
GLIBC_2.38 __isoc23_wscanf F
+GLIBC_2.38 __libc_aligned_alloc F
GLIBC_2.4 __confstr_chk F
GLIBC_2.4 __fgets_chk F
GLIBC_2.4 __fgets_unlocked_chk F
@@ -2680,3 +2680,4 @@ GLIBC_2.38 __isoc23_wcstoull F
GLIBC_2.38 __isoc23_wcstoull_l F
GLIBC_2.38 __isoc23_wcstoumax F
GLIBC_2.38 __isoc23_wscanf F
+GLIBC_2.38 __libc_aligned_alloc F