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: <20250402214109.653341-5-lyude@redhat.com>
Date: Wed,  2 Apr 2025 17:40:32 -0400
From: Lyude Paul <lyude@...hat.com>
To: rust-for-linux@...r.kernel.org,
	Andreas Hindborg <a.hindborg@...nel.org>,
	linux-kernel@...r.kernel.org
Cc: Boqun Feng <boqun.feng@...il.com>,
	Frederic Weisbecker <frederic@...nel.org>,
	Thomas Gleixner <tglx@...utronix.de>,
	Anna-Maria Behnsen <anna-maria@...utronix.de>,
	Miguel Ojeda <ojeda@...nel.org>,
	Alex Gaynor <alex.gaynor@...il.com>,
	Gary Guo <gary@...yguo.net>,
	Björn Roy Baron <bjorn3_gh@...tonmail.com>,
	Benno Lossin <benno.lossin@...ton.me>,
	Alice Ryhl <aliceryhl@...gle.com>,
	Trevor Gross <tmgross@...ch.edu>
Subject: [PATCH 4/6] rust: hrtimer: Add HrTimerClockBase::time()

This adds a wrapper for the get_time() callback contained within a
hrtimer_clock_base struct. We'll use this in the next commit in order to
implement HrTimerCallbackContext::forward_now().

Signed-off-by: Lyude Paul <lyude@...hat.com>
---
 rust/kernel/time/hrtimer.rs | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/rust/kernel/time/hrtimer.rs b/rust/kernel/time/hrtimer.rs
index f633550882247..521ff1a8a5aa8 100644
--- a/rust/kernel/time/hrtimer.rs
+++ b/rust/kernel/time/hrtimer.rs
@@ -186,6 +186,16 @@ unsafe fn from_raw<'a>(ptr: *mut bindings::hrtimer_clock_base) -> &'a Self {
         // - Our data layout is equivalent to said struct via our type invariants.
         unsafe { &*ptr.cast() }
     }
+
+    /// Retrieve the current time from this [`HrTimerClockBase`].
+    fn time(&self) -> Ktime {
+        // SAFETY: This callback is initialized to a valid NonNull function for as long as this type
+        // is exposed to users.
+        let get_time_fn = unsafe { (*self.0.get()).get_time.unwrap_unchecked() };
+
+        // SAFETY: This FFI function has no special requirements
+        Ktime::from_raw(unsafe { get_time_fn() })
+    }
 }
 
 /// Implemented by pointer types that point to structs that contain a [`HrTimer`].
-- 
2.48.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ