[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAJ-ks9mwB+9F8Bz89TB0ZecijOftM49yfPzn5GgcyPDEput+xg@mail.gmail.com>
Date: Thu, 6 Feb 2025 14:04:54 -0500
From: Tamir Duberstein <tamird@...il.com>
To: Danilo Krummrich <dakr@...nel.org>
Cc: Miguel Ojeda <miguel.ojeda.sandonis@...il.com>, Miguel Ojeda <ojeda@...nel.org>,
Alex Gaynor <alex.gaynor@...il.com>, Boqun Feng <boqun.feng@...il.com>,
Gary Guo <gary@...yguo.net>, Björn Roy Baron <bjorn3_gh@...tonmail.com>,
Benno Lossin <benno.lossin@...ton.me>, Andreas Hindborg <a.hindborg@...nel.org>,
Alice Ryhl <aliceryhl@...gle.com>, Trevor Gross <tmgross@...ch.edu>, rust-for-linux@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH v2] rust: alloc: satisfy `aligned_alloc` requirements
On Thu, Feb 6, 2025 at 1:58 PM Danilo Krummrich <dakr@...nel.org> wrote:
>
> On Thu, Feb 06, 2025 at 07:20:20PM +0100, Miguel Ojeda wrote:
> > On Thu, Feb 6, 2025 at 7:04 PM Danilo Krummrich <dakr@...nel.org> wrote:
> > >
> > > I previously checked man posix_memalign(3) and it says:
> > >
> > > ERRORS
> > > EINVAL The alignment argument was not a power of two, or was not a
> > > multiple of sizeof(void *).
> >
> > Yeah, but that may not apply to `alligned_alloc` as far as I can see.
>
> 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 writing is definitely obtuse.
> Return Value
>. aligned_alloc(), memalign(), valloc(), and pvalloc() return a pointer to the allocated memory, or NULL if the request fails.
>
> posix_memalign() returns zero on success, or one of the error values listed in the next section on failure. Note that errno is not set.
>
> Errors
> EINVAL
> The alignment argument was not a power of two, or was not a multiple of sizeof(void *).
> ENOMEM
>. There was insufficient memory to fulfill the allocation request.
It seems that the errors section applies to posix_memalign only. The
description section also contains:
> The obsolete function memalign() allocates size bytes and returns a pointer to the allocated memory. The memory address will be a multiple of alignment, which must be a power of two.
>
> The function aligned_alloc() is the same as memalign(), except for the added restriction that size should be a multiple of alignment.
So aligned_alloc has the same alignment requirement as memalign, which
is only that it's a power of two.
Powered by blists - more mailing lists