[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <5dd90c62-0dc5-1225-c66c-e8f201cb0d59@ryhl.io>
Date: Fri, 31 Mar 2023 00:36:24 +0200
From: Alice Ryhl <alice@...l.io>
To: y86-dev@...tonmail.com
Cc: rust-for-linux@...r.kernel.org, linux-kernel@...r.kernel.org,
patches@...ts.linux.dev, Miguel Ojeda <ojeda@...nel.org>,
Alex Gaynor <alex.gaynor@...il.com>,
Wedson Almeida Filho <wedsonaf@...il.com>,
Boqun Feng <boqun.feng@...il.com>, Gary Guo <gary@...yguo.net>,
Björn Roy Baron <bjorn3_gh@...tonmail.com>
Subject: Re: [PATCH v3 09/13] rust: init: add `Zeroable` trait and
`init::zeroed` function
On 3/30/23 00:33, y86-dev@...tonmail.com wrote:
> From: Benno Lossin <y86-dev@...tonmail.com>
>
> Add the `Zeroable` trait which marks types that can be initialized by
> writing `0x00` to every byte of the type. Also add the `init::zeroed`
> function that creates an initializer for a `Zeroable` type that writes
> `0x00` to every byte.
>
> Signed-off-by: Benno Lossin <y86-dev@...tonmail.com>
Reviewed-by: Alice Ryhl <aliceryhl@...gle.com>
> +impl_zeroable! {
> + // SAFETY: All primitives that are allowed to be zero.
> + bool,
> + char,
> + u8, u16, u32, u64, u128, usize,
> + i8, i16, i32, i64, i128, isize,
> + f32, f64,
> + // SAFETY: There is nothing to zero.
> + core::marker::PhantomPinned, Infallible, (),
> +}
Here are some other types it might make sense to add:
* Option<NonNull<T>>
* Option<Box<T>>
* Option<NonZeroU32>
* PhantomData<T>
* MaybeUninit<T>
> +
> +// SAFETY: We are allowed to zero padding bytes.
> +unsafe impl<const N: usize, T: Zeroable> Zeroable for [T; N] {}
There are no padding bytes in [T; N].
Powered by blists - more mailing lists