Re: [PATCH v2] rust: alloc: satisfy `aligned_alloc` requirements

Danilo Krummrich
2025-02-06T19:46:36Z

On Thu, Feb 06, 2025 at 08:37:07PM +0100, Miguel Ojeda wrote:
> On Thu, Feb 6, 2025 at 7:58 PM Danilo Krummrich <dakr@kernel.org> wrote:
> >
> > What makes you think so?
> >
> > AFAICS, the man page applies for posix_memalign, aligned_alloc, memalign,
> > valloc and pvalloc.
> >
> > In case behavior differs between the functions, this is stated explicitly, e.g.
> > in the "RETURN VALUE" section.
> >
> > The "ERRORS" setion does not differentiate, hence it should apply to all the
> > functions above, including aligned_alloc.
> >
> > Do I miss anything?
>
> The explanation of the requirements (in the Linux man page) mention
> different requirements for each function.

Indeed, it seems a bit ambiguous.

>
> Moreover, in practice, glibc seemed to allow almost any alignment up
> to 2023, and since then they have this:
>
> +/* Similar to memalign, but starting with ISO C17 the standard
> + requires an error for alignments that are not supported by the
> + implementation. Valid alignments for the current implementation
> + are non-negative powers of two. */
> + if (!powerof2 (alignment) || alignment == 0)
> + {
> + __set_errno (EINVAL);
> + return 0;
> + }

Agree, in practice no concern from my side either.

>
> Including a test that does not fail for a degenerate alignment (1).
> Thus I don't think the "multiple of sizeof" part applies today or in
> the past for that implementation (again, in practice).
>
> But I don't know how those sections are formally supposed to work or
> what requirements (and/or behavior) the man pages are supposed to be
> documenting -- Cc'ing Alejandro. It seems clarifying the page would
> help.

+1