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: <20241018.171026.271950414623402396.fujita.tomonori@gmail.com>
Date: Fri, 18 Oct 2024 17:10:26 +0900 (JST)
From: FUJITA Tomonori <fujita.tomonori@...il.com>
To: aliceryhl@...gle.com
Cc: fujita.tomonori@...il.com, netdev@...r.kernel.org,
 rust-for-linux@...r.kernel.org, andrew@...n.ch, hkallweit1@...il.com,
 tmgross@...ch.edu, ojeda@...nel.org, alex.gaynor@...il.com,
 gary@...yguo.net, bjorn3_gh@...tonmail.com, benno.lossin@...ton.me,
 a.hindborg@...sung.com, anna-maria@...utronix.de, frederic@...nel.org,
 tglx@...utronix.de, arnd@...db.de, jstultz@...gle.com, sboyd@...nel.org,
 linux-kernel@...r.kernel.org
Subject: Re: [PATCH net-next v3 7/8] rust: Add read_poll_timeout functions

On Wed, 16 Oct 2024 10:52:17 +0200
Alice Ryhl <aliceryhl@...gle.com> wrote:

> On Wed, Oct 16, 2024 at 10:45 AM Alice Ryhl <aliceryhl@...gle.com> wrote:
>>
>> On Wed, Oct 16, 2024 at 5:54 AM FUJITA Tomonori
>> <fujita.tomonori@...il.com> wrote:
>> > +/// Polls periodically until a condition is met or a timeout is reached.
>> > +///
>> > +/// `op` is called repeatedly until `cond` returns `true` or the timeout is
>> > +///  reached. The return value of `op` is passed to `cond`.
>> > +///
>> > +/// `sleep_delta` is the duration to sleep between calls to `op`.
>> > +/// If `sleep_delta` is less than one microsecond, the function will busy-wait.
>> > +///
>> > +/// `timeout_delta` is the maximum time to wait for `cond` to return `true`.
>> > +///
>> > +/// This macro can only be used in a nonatomic context.
>> > +#[macro_export]
>> > +macro_rules! readx_poll_timeout {
>> > +    ($op:expr, $cond:expr, $sleep_delta:expr, $timeout_delta:expr) => {{
>> > +        #[cfg(CONFIG_DEBUG_ATOMIC_SLEEP)]
>> > +        if !$sleep_delta.is_zero() {
>> > +            // SAFETY: FFI call.
>> > +            unsafe {
>> > +                $crate::bindings::__might_sleep(
>> > +                    ::core::file!().as_ptr() as *const i8,
>> > +                    ::core::line!() as i32,
>> > +                )
>> > +            }
>> > +        }
>>
>> I wonder if we can use #[track_caller] and
>> core::panic::Location::caller [1] to do this without having to use a
>> macro? I don't know whether it would work, but if it does, that would
>> be super cool.

Seems it works, no need to use macro. Thanks a lot!

>> #[track_caller]
>> fn might_sleep() {
>>     let location = core::panic::Location::caller();
>>     // SAFETY: FFI call.
>>     unsafe {
>>         $crate::bindings::__might_sleep(
>>             location.file().as_char_ptr(),
>>             location.line() as i32,
>>         )
>>     }
>> }
> 
> Actually, this raises a problem ... core::panic::Location doesn't give
> us a nul-terminated string, so we probably can't pass it to
> `__might_sleep`. The thing is, `::core::file!()` doesn't give us a
> nul-terminated string either, so this code is probably incorrect
> as-is.

Ah, what's the recommended way to get a null-terminated string from
&str?

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ