diff options
| author | Miguel Ojeda <ojeda@kernel.org> | 2025-03-25 22:33:11 +0100 |
|---|---|---|
| committer | Miguel Ojeda <ojeda@kernel.org> | 2025-03-25 23:41:14 +0100 |
| commit | e6ea10d5dbe082c54add289b44f08c9fcfe658af (patch) | |
| tree | fbd2cf911102c177511d97d35c1238f53c97cd33 /rust/kernel/sync/arc.rs | |
| parent | rust: dma: add `Send` implementation for `CoherentAllocation` (diff) | |
| parent | rust: hrtimer: add maintainer entry (diff) | |
| download | linux-e6ea10d5dbe082c54add289b44f08c9fcfe658af.tar.gz linux-e6ea10d5dbe082c54add289b44f08c9fcfe658af.zip | |
Merge tag 'rust-hrtimer-for-v6.15-v3' of https://github.com/Rust-for-Linux/linux into rust-next
Pull rust-hrtimer updates from Andreas Hindborg:
"Introduce Rust support for the 'hrtimer' subsystem:
- Add a way to use the 'hrtimer' subsystem from Rust. Rust code can
now set up intrusive timers without allocating when starting the
timer.
- Add support for 'Pin<Box<_>>', 'Arc<_>', 'Pin<&_>' and
'Pin<&mut _>' as pointer types for use with timer callbacks.
- Add support for setting clock source and timer mode.
'kernel' crate:
- Add 'Arc::as_ptr' for converting an 'Arc' to a raw pointer. This is
a dependency for the 'hrtimer' API.
- Add 'Box::into_pin' for converting a 'Box<_>' into a 'Pin<Box<_>>'
to align with Rust 'alloc'. This is a dependency for the 'hrtimer'
API."
* tag 'rust-hrtimer-for-v6.15-v3' of https://github.com/Rust-for-Linux/linux:
rust: hrtimer: add maintainer entry
rust: hrtimer: add clocksource selection through `ClockId`
rust: hrtimer: add `HrTimerMode`
rust: hrtimer: implement `HrTimerPointer` for `Pin<Box<T>>`
rust: alloc: add `Box::into_pin`
rust: hrtimer: implement `UnsafeHrTimerPointer` for `Pin<&mut T>`
rust: hrtimer: implement `UnsafeHrTimerPointer` for `Pin<&T>`
rust: hrtimer: add `hrtimer::ScopedHrTimerPointer`
rust: hrtimer: add `UnsafeHrTimerPointer`
rust: hrtimer: allow timer restart from timer handler
rust: hrtimer: implement `HrTimerPointer` for `Arc`
rust: sync: add `Arc::as_ptr`
rust: hrtimer: introduce hrtimer support
Diffstat (limited to 'rust/kernel/sync/arc.rs')
| -rw-r--r-- | rust/kernel/sync/arc.rs | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/rust/kernel/sync/arc.rs b/rust/kernel/sync/arc.rs index c64eac8b4235..8484c814609a 100644 --- a/rust/kernel/sync/arc.rs +++ b/rust/kernel/sync/arc.rs @@ -266,6 +266,15 @@ impl<T: ?Sized> Arc<T> { unsafe { core::ptr::addr_of!((*ptr).data) } } + /// Return a raw pointer to the data in this arc. + pub fn as_ptr(this: &Self) -> *const T { + let ptr = this.ptr.as_ptr(); + + // SAFETY: As `ptr` points to a valid allocation of type `ArcInner`, + // field projection to `data`is within bounds of the allocation. + unsafe { core::ptr::addr_of!((*ptr).data) } + } + /// Recreates an [`Arc`] instance previously deconstructed via [`Arc::into_raw`]. /// /// # Safety @@ -559,11 +568,11 @@ impl<T: ?Sized> ArcBorrow<'_, T> { } /// Creates an [`ArcBorrow`] to an [`Arc`] that has previously been deconstructed with - /// [`Arc::into_raw`]. + /// [`Arc::into_raw`] or [`Arc::as_ptr`]. /// /// # Safety /// - /// * The provided pointer must originate from a call to [`Arc::into_raw`]. + /// * The provided pointer must originate from a call to [`Arc::into_raw`] or [`Arc::as_ptr`]. /// * For the duration of the lifetime annotated on this `ArcBorrow`, the reference count must /// not hit zero. /// * For the duration of the lifetime annotated on this `ArcBorrow`, there must not be a |
