lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <226e4772-0e10-6593-7cfe-e1e290a0216c@protonmail.com>
Date:   Thu, 30 Mar 2023 15:38:54 +0000
From:   Benno Lossin <y86-dev@...tonmail.com>
To:     Alice Ryhl <alice@...l.io>
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 05/13] rust: init: add initialization macros

On 30.03.23 16:21, Alice Ryhl wrote:
> On 3/30/23 00:33, y86-dev@...tonmail.com wrote:
>> From: Benno Lossin <y86-dev@...tonmail.com>
>>
>> Add the following initializer macros:
>> - `#[pin_data]` to annotate structurally pinned fields of structs,
>>     needed for `pin_init!` and `try_pin_init!` to select the correct
>>     initializer of fields.
>> - `pin_init!` create a pin-initializer for a struct with the
>>     `Infallible` error type.
>> - `try_pin_init!` create a pin-initializer for a struct with a custom
>>     error type (`kernel::error::Error` is the default).
>> - `init!` create an in-place-initializer for a struct with the
>>     `Infallible` error type.
>> - `try_init!` create an in-place-initializer for a struct with a custom
>>     error type (`kernel::error::Error` is the default).
>>
>> Also add their needed internal helper traits and structs.
>>
>> Co-developed-by: Gary Guo <gary@...yguo.net>
>> Signed-off-by: Gary Guo <gary@...yguo.net>
>> Signed-off-by: Benno Lossin <y86-dev@...tonmail.com>
>
> Reviewed-by: Alice Ryhl <aliceryhl@...gle.com>
>
>> +/// ```rust
>> +/// # #![allow(clippy::disallowed_names, clippy::new_ret_no_self)]
>> +/// # use kernel::{init, pin_init, prelude::*, init::*};
>> +/// # use core::pin::Pin;
>> +/// # #[pin_data]
>> +/// # struct Foo {
>> +/// #     a: usize,
>> +/// #     b: Bar,
>> +/// # }
>> +/// # #[pin_data]
>> +/// # struct Bar {
>> +/// #     x: u32,
>> +/// # }
>> +///
>> +/// impl Foo {
>> +///     fn new() -> impl PinInit<Self> {
>
> I would remove the empty line above `impl Foo` so that the example
> doesn't start with an empty line when rendered.

Sure.

>
>> +/// # Syntax
>> +///
>> +/// As already mentioned in the examples above, inside of `pin_init!` a `struct` initializer with
>> +/// the following modifications is expected:
>> +/// - Fields that you want to initialize in-place have to use `<-` instead of `:`.
>> +/// - In front of the initializer you can write `&this in` to have access to a [`NonNull<Self>`]
>> +///   pointer named `this` inside of the initializer.
>> +///
>> +/// For instance:
>> +///
>> +/// ```rust
>> +/// # use kernel::pin_init;
>> +/// # use macros::pin_data;
>> +/// # use core::{ptr::addr_of_mut, marker::PhantomPinned};
>> +/// #[pin_data]
>> +/// struct Buf {
>> +///     ptr: *mut u8,
>
> I'd add a comment on the `ptr` field saying "points at `buf`".

Sure.

>
>> +/// impl BigBuf {
>> +///     fn new() -> impl PinInit<Self, Error> {
>> +///         try_pin_init!(Self {
>> +///             big: {
>> +///                 let zero = Box::try_new_zeroed()?;
>> +///                 unsafe { zero.assume_init() }
>> +///             },
>
> Is there a reason for not using `Box::init(kernel::init::zeroed())?` here?

No, this was probably designed prior to `zeroed`, will change it.

--
Cheers,
Benno

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ