summaryrefslogtreecommitdiffstats
path: root/rust/kernel/ptr.rs
diff options
context:
space:
mode:
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>2026-03-16 11:50:48 +0100
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2026-03-16 11:50:48 +0100
commitde6c925db978004703944585e9dd57d58aba0fac (patch)
tree64aa124199d1121dd8aa103f28f3a76f34435486 /rust/kernel/ptr.rs
parent322a81d35ecdf9997c3bbf676e3547d75f38935a (diff)
parentf338e77383789c0cae23ca3d48adcc5e9e137e3c (diff)
downloadlinux-de6c925db978004703944585e9dd57d58aba0fac.tar.gz
linux-de6c925db978004703944585e9dd57d58aba0fac.zip
Merge 7.0-rc4 into usb-next
We need the USB fixes in this branch as well to build on top of Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'rust/kernel/ptr.rs')
-rw-r--r--rust/kernel/ptr.rs30
1 files changed, 29 insertions, 1 deletions
diff --git a/rust/kernel/ptr.rs b/rust/kernel/ptr.rs
index 5b6a382637fe..bdc2d79ff669 100644
--- a/rust/kernel/ptr.rs
+++ b/rust/kernel/ptr.rs
@@ -2,7 +2,13 @@
//! Types and functions to work with pointers and addresses.
-use core::mem::align_of;
+pub mod projection;
+pub use crate::project_pointer as project;
+
+use core::mem::{
+ align_of,
+ size_of, //
+};
use core::num::NonZero;
/// Type representing an alignment, which is always a power of two.
@@ -225,3 +231,25 @@ macro_rules! impl_alignable_uint {
}
impl_alignable_uint!(u8, u16, u32, u64, usize);
+
+/// Trait to represent compile-time known size information.
+///
+/// This is a generalization of [`size_of`] that works for dynamically sized types.
+pub trait KnownSize {
+ /// Get the size of an object of this type in bytes, with the metadata of the given pointer.
+ fn size(p: *const Self) -> usize;
+}
+
+impl<T> KnownSize for T {
+ #[inline(always)]
+ fn size(_: *const Self) -> usize {
+ size_of::<T>()
+ }
+}
+
+impl<T> KnownSize for [T] {
+ #[inline(always)]
+ fn size(p: *const Self) -> usize {
+ p.len() * size_of::<T>()
+ }
+}