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: <ae53994a-aaa5-8a57-4284-85000229249d@ryhl.io>
Date:   Thu, 30 Mar 2023 22:28:25 +0200
From:   Alice Ryhl <alice@...l.io>
To:     Benno Lossin <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>,
        Björn Roy Baron <bjorn3_gh@...tonmail.com>,
        Gary Guo <gary@...yguo.net>
Subject: Re: [PATCH v3 08/13] rust: init: add `stack_pin_init!` macro

On 3/30/23 17:19, Benno Lossin wrote:
> On 30.03.23 17:00, Alice Ryhl wrote:
>> On 3/30/23 00:33, y86-dev@...tonmail.com wrote:
>>> From: Benno Lossin <y86-dev@...tonmail.com>
>>>
>>> The `stack_pin_init!` macro allows pin-initializing a value on the
>>> stack. It accepts a `impl PinInit<T, E>` to initialize a `T`. It allows
>>> propagating any errors via `?` or handling it normally via `match`.
>>>
>>> Signed-off-by: Benno Lossin <y86-dev@...tonmail.com>
>>
>> Reviewed-by: Alice Ryhl <aliceryhl@...gle.com>
>>
>>> ---
>>> +#[macro_export]
>>> +macro_rules! stack_pin_init {
>>> +    (let $var:ident $(: $t:ty)? = $val:expr) => {
>>> +        let mut $var = $crate::init::__internal::StackInit$(::<$t>)?::uninit();
>>> +        let mut $var = {
>>> +            let val = $val;
>>> +            unsafe { $crate::init::__internal::StackInit::init(&mut $var, val) }
>>> +        };
>>> +    };
>>> +    (let $var:ident $(: $t:ty)? =? $val:expr) => {
>>> +        let mut $var = $crate::init::__internal::StackInit$(::<$t>)?::uninit();
>>> +        let mut $var = {
>>> +            let val = $val;
>>> +            unsafe { $crate::init::__internal::StackInit::init(&mut $var, val)? }
>>> +        };
>>> +    };
>>> +}
>>
>> This will be inconvenient to use if the initializer is infallible and is
>> used inside an infallible function. However, I'm not sure what a better
>> alternative would be. Perhaps we should have three variants?
> 
> That could be an option, any ideas for the syntax though? Or should it
> be a different macro like `stack_pin_init!` and `try_stack_pin_init!`?

You've also split up the other macros into a fallible and infallible 
version, so I think the same would be fine here. Perhaps use 
`stack_pin_try_init!` as the name?

>> Also, maybe a `<-` rather than `=` would be more consistent?
> 
> That is sadly not possible, since `<-` is not allowed after `ty` fragments.
> 
>> Anyway, I don't think this should block the PR. We can revisit it later
>> if it becomes a problem.
> 
> Sure.
> 
> --
> Cheers,
> Benno
> 
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ