Merge 1ef4cf5f98 ("rust: alloc: update module comment of alloc.rs") into android16-6.12

Steps on the way to 6.12.18

Resolves merge conflicts in:
	rust/kernel/types.rs
	scripts/Makefile.build

Change-Id: I1a0d7a30074e2532f53b9c9d4cf0e8346d57ffef
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
[Re-resolved rust/kernel/types.rs <mmaurer@google.com>]
Signed-off-by: Matthew Maurer <mmaurer@google.com>
This commit is contained in:
Greg Kroah-Hartman
2025-04-01 16:33:46 +00:00
parent 2419132b8c
commit dfed1574cd
49 changed files with 2351 additions and 588 deletions
+9 -10
View File
@@ -17,13 +17,12 @@
//! [`Arc`]: https://doc.rust-lang.org/std/sync/struct.Arc.html
use crate::{
alloc::{box_ext::BoxExt, AllocError, Flags},
alloc::{AllocError, Flags, KBox},
bindings,
init::{self, InPlaceInit, Init, PinInit},
try_init,
types::{ForeignOwnable, Opaque},
};
use alloc::boxed::Box;
use core::{
alloc::Layout,
fmt,
@@ -201,11 +200,11 @@ impl<T> Arc<T> {
data: contents,
};
let inner = <Box<_> as BoxExt<_>>::new(value, flags)?;
let inner = KBox::new(value, flags)?;
// SAFETY: We just created `inner` with a reference count of 1, which is owned by the new
// `Arc` object.
Ok(unsafe { Self::from_inner(Box::leak(inner).into()) })
Ok(unsafe { Self::from_inner(KBox::leak(inner).into()) })
}
}
@@ -338,7 +337,7 @@ impl<T: 'static> ForeignOwnable for Arc<T> {
}
unsafe fn borrow<'a>(ptr: *const core::ffi::c_void) -> ArcBorrow<'a, T> {
// SAFETY: By the safety requirement of this function, we know that `ptr` came from
// By the safety requirement of this function, we know that `ptr` came from
// a previous call to `Arc::into_foreign`.
let inner = NonNull::new(ptr as *mut ArcInner<T>).unwrap();
@@ -398,8 +397,8 @@ impl<T: ?Sized> Drop for Arc<T> {
if is_zero {
// The count reached zero, we must free the memory.
//
// SAFETY: The pointer was initialised from the result of `Box::leak`.
unsafe { drop(Box::from_raw(self.ptr.as_ptr())) };
// SAFETY: The pointer was initialised from the result of `KBox::leak`.
unsafe { drop(KBox::from_raw(self.ptr.as_ptr())) };
}
}
}
@@ -641,7 +640,7 @@ impl<T> UniqueArc<T> {
/// Tries to allocate a new [`UniqueArc`] instance whose contents are not initialised yet.
pub fn new_uninit(flags: Flags) -> Result<UniqueArc<MaybeUninit<T>>, AllocError> {
// INVARIANT: The refcount is initialised to a non-zero value.
let inner = Box::try_init::<AllocError>(
let inner = KBox::try_init::<AllocError>(
try_init!(ArcInner {
// SAFETY: There are no safety requirements for this FFI call.
refcount: Opaque::new(unsafe { bindings::REFCOUNT_INIT(1) }),
@@ -651,8 +650,8 @@ impl<T> UniqueArc<T> {
)?;
Ok(UniqueArc {
// INVARIANT: The newly-created object has a refcount of 1.
// SAFETY: The pointer from the `Box` is valid.
inner: unsafe { Arc::from_inner(Box::leak(inner).into()) },
// SAFETY: The pointer from the `KBox` is valid.
inner: unsafe { Arc::from_inner(KBox::leak(inner).into()) },
})
}
}
+2
View File
@@ -1,5 +1,7 @@
// SPDX-License-Identifier: Apache-2.0 OR MIT
//! Rust standard library vendored code.
//!
//! The contents of this file come from the Rust standard library, hosted in
//! the <https://github.com/rust-lang/rust> repository, licensed under
//! "Apache-2.0 OR MIT" and adapted for kernel use. For copyright details,
+2 -3
View File
@@ -72,8 +72,8 @@ pub use new_condvar;
/// }
///
/// /// Allocates a new boxed `Example`.
/// fn new_example() -> Result<Pin<Box<Example>>> {
/// Box::pin_init(pin_init!(Example {
/// fn new_example() -> Result<Pin<KBox<Example>>> {
/// KBox::pin_init(pin_init!(Example {
/// value <- new_mutex!(0),
/// value_changed <- new_condvar!(),
/// }), GFP_KERNEL)
@@ -95,7 +95,6 @@ pub struct CondVar {
}
// SAFETY: `CondVar` only uses a `struct wait_queue_head`, which is safe to use on any thread.
#[allow(clippy::non_send_fields_in_send_ty)]
unsafe impl Send for CondVar {}
// SAFETY: `CondVar` only uses a `struct wait_queue_head`, which is safe to use on multiple threads
+3 -3
View File
@@ -179,9 +179,9 @@ impl<'a, T: ?Sized, B: Backend> Guard<'a, T, B> {
// SAFETY: The caller owns the lock, so it is safe to unlock it.
unsafe { B::unlock(self.lock.state.get(), &self.state) };
// SAFETY: The lock was just unlocked above and is being relocked now.
let _relock =
ScopeGuard::new(|| unsafe { B::relock(self.lock.state.get(), &mut self.state) });
let _relock = ScopeGuard::new(||
// SAFETY: The lock was just unlocked above and is being relocked now.
unsafe { B::relock(self.lock.state.get(), &mut self.state) });
cb()
}
+1 -1
View File
@@ -58,7 +58,7 @@ pub use new_mutex;
/// }
///
/// // Allocate a boxed `Example`.
/// let e = Box::pin_init(Example::new(), GFP_KERNEL)?;
/// let e = KBox::pin_init(Example::new(), GFP_KERNEL)?;
/// assert_eq!(e.c, 10);
/// assert_eq!(e.d.lock().a, 20);
/// assert_eq!(e.d.lock().b, 30);
+1 -1
View File
@@ -56,7 +56,7 @@ pub use new_spinlock;
/// }
///
/// // Allocate a boxed `Example`.
/// let e = Box::pin_init(Example::new(), GFP_KERNEL)?;
/// let e = KBox::pin_init(Example::new(), GFP_KERNEL)?;
/// assert_eq!(e.c, 10);
/// assert_eq!(e.d.lock().a, 20);
/// assert_eq!(e.d.lock().b, 30);
+1 -1
View File
@@ -43,7 +43,7 @@ use core::{cell::UnsafeCell, mem::size_of, ptr};
/// struct InnerDirectory {
/// /// The sum of the bytes used by all files.
/// bytes_used: u64,
/// _files: Vec<File>,
/// _files: KVec<File>,
/// }
///
/// struct Directory {