rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: DJ Delorie <dj@redhat.com>
To: Alejandro Colomar <alx@kernel.org>
Cc: miguel.ojeda.sandonis@gmail.com, eblake@redhat.com,
	will.newton@linaro.org, eggert@cs.ucla.edu,
	linux-man@vger.kernel.org, dakr@kernel.org, tamird@gmail.com,
	ojeda@kernel.org, alex.gaynor@gmail.com, boqun.feng@gmail.com,
	gary@garyguo.net, bjorn3_gh@protonmail.com,
	benno.lossin@proton.me, a.hindborg@kernel.org,
	aliceryhl@google.com, tmgross@umich.edu,
	rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] rust: alloc: satisfy `aligned_alloc` requirements
Date: Sat, 08 Feb 2025 15:21:24 -0500	[thread overview]
Message-ID: <xn4j14nq63.fsf@greed.delorie.com> (raw)
In-Reply-To: <kfkku4rjsktgkufkuehliojv3izxdutc55inmv3yvenu33zr7e@lluedzjnqnki> (message from Alejandro Colomar on Sat, 8 Feb 2025 20:19:22 +0100)

Alejandro Colomar <alx@kernel.org> writes:
> -  aligned_alloc()
>	It makes sure that the input is a power of two, or it fails.
>
> -  posix_memalign()
>
> 	. . . It requires that the input is power of
> 	two,
>
> I wonder why glibc silently overaligns aligned_alloc() without reporting
> an error for an alignment of 2, while it reports an error for an
> alignment of 3.  It doesn't make much sense at first glance.  No
> standard seems to require that, so it looks like an arbitrary choice.

Because 2 is a power of two, but 3 isn't.  No power of two is a multiple
of 3.

GNU malloc only supports alignments that are powers of two.  The
resulting addresses might *happen* to be multiples of other numbers, but
you cannot request that.

As for why, ask Posix:

"If the value of alignment is not a valid alignment supported by the
 implementation, a null pointer shall be returned."
 [EINVAL]
    The value of alignment is not a valid alignment supported by the
    implementation."


  parent reply	other threads:[~2025-02-08 20:21 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-02 11:27 [PATCH v2] rust: alloc: satisfy `aligned_alloc` requirements Tamir Duberstein
2025-02-05 19:13 ` Danilo Krummrich
2025-02-06 17:56 ` Miguel Ojeda
2025-02-06 18:04   ` Danilo Krummrich
2025-02-06 18:10     ` Tamir Duberstein
2025-02-06 18:23       ` Miguel Ojeda
2025-02-06 18:51         ` Tamir Duberstein
2025-02-06 18:20     ` Miguel Ojeda
2025-02-06 18:57       ` Danilo Krummrich
2025-02-06 19:04         ` Tamir Duberstein
2025-02-06 19:37         ` Miguel Ojeda
2025-02-06 19:46           ` Danilo Krummrich
2025-02-08 19:19           ` Alejandro Colomar
2025-02-08 20:09             ` Paul Eggert
2025-02-08 20:31               ` Alejandro Colomar
2025-02-08 20:21             ` DJ Delorie [this message]
2025-02-08 23:11             ` Miguel Ojeda
2025-02-08 23:35               ` Alejandro Colomar
2025-02-08 23:50                 ` Miguel Ojeda
2025-02-10  3:01                 ` DJ Delorie

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xn4j14nq63.fsf@greed.delorie.com \
    --to=dj@redhat.com \
    --cc=a.hindborg@kernel.org \
    --cc=alex.gaynor@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=alx@kernel.org \
    --cc=benno.lossin@proton.me \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=dakr@kernel.org \
    --cc=eblake@redhat.com \
    --cc=eggert@cs.ucla.edu \
    --cc=gary@garyguo.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-man@vger.kernel.org \
    --cc=miguel.ojeda.sandonis@gmail.com \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=tamird@gmail.com \
    --cc=tmgross@umich.edu \
    --cc=will.newton@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).