1313//! To initialize a `struct` with an in-place constructor you will need two things:
1414//! - an in-place constructor,
1515//! - a memory location that can hold your `struct` (this can be the [stack], an [`Arc<T>`],
16- //! [`UniqueArc<T>`], [`Box <T>`] or any other smart pointer that implements [`InPlaceInit`]).
16+ //! [`UniqueArc<T>`], [`KBox <T>`] or any other smart pointer that implements [`InPlaceInit`]).
1717//!
1818//! To get an in-place constructor there are generally three options:
1919//! - directly creating an in-place constructor using the [`pin_init!`] macro,
6868//! # a <- new_mutex!(42, "Foo::a"),
6969//! # b: 24,
7070//! # });
71- //! let foo: Result<Pin<Box <Foo>>> = Box ::pin_init(foo, GFP_KERNEL);
71+ //! let foo: Result<Pin<KBox <Foo>>> = KBox ::pin_init(foo, GFP_KERNEL);
7272//! ```
7373//!
7474//! For more information see the [`pin_init!`] macro.
9393//! struct DriverData {
9494//! #[pin]
9595//! status: Mutex<i32>,
96- //! buffer: Box <[u8; 1_000_000]>,
96+ //! buffer: KBox <[u8; 1_000_000]>,
9797//! }
9898//!
9999//! impl DriverData {
100100//! fn new() -> impl PinInit<Self, Error> {
101101//! try_pin_init!(Self {
102102//! status <- new_mutex!(0, "DriverData::status"),
103- //! buffer: Box ::init(kernel::init::zeroed(), GFP_KERNEL)?,
103+ //! buffer: KBox ::init(kernel::init::zeroed(), GFP_KERNEL)?,
104104//! })
105105//! }
106106//! }
211211//! [`pin_init!`]: crate::pin_init!
212212
213213use crate :: {
214- alloc:: { box_ext:: BoxExt , AllocError , Flags } ,
214+ alloc:: { box_ext:: BoxExt , AllocError , Flags , KBox } ,
215215 error:: { self , Error } ,
216216 sync:: Arc ,
217217 sync:: UniqueArc ,
@@ -298,7 +298,7 @@ macro_rules! stack_pin_init {
298298/// struct Foo {
299299/// #[pin]
300300/// a: Mutex<usize>,
301- /// b: Box <Bar>,
301+ /// b: KBox <Bar>,
302302/// }
303303///
304304/// struct Bar {
@@ -307,7 +307,7 @@ macro_rules! stack_pin_init {
307307///
308308/// stack_try_pin_init!(let foo: Result<Pin<&mut Foo>, AllocError> = pin_init!(Foo {
309309/// a <- new_mutex!(42),
310- /// b: Box ::new(Bar {
310+ /// b: KBox ::new(Bar {
311311/// x: 64,
312312/// }, GFP_KERNEL)?,
313313/// }));
@@ -324,7 +324,7 @@ macro_rules! stack_pin_init {
324324/// struct Foo {
325325/// #[pin]
326326/// a: Mutex<usize>,
327- /// b: Box <Bar>,
327+ /// b: KBox <Bar>,
328328/// }
329329///
330330/// struct Bar {
@@ -333,7 +333,7 @@ macro_rules! stack_pin_init {
333333///
334334/// stack_try_pin_init!(let foo: Pin<&mut Foo> =? pin_init!(Foo {
335335/// a <- new_mutex!(42),
336- /// b: Box ::new(Bar {
336+ /// b: KBox ::new(Bar {
337337/// x: 64,
338338/// }, GFP_KERNEL)?,
339339/// }));
@@ -392,7 +392,7 @@ macro_rules! stack_try_pin_init {
392392/// },
393393/// });
394394/// # initializer }
395- /// # Box ::pin_init(demo(), GFP_KERNEL).unwrap();
395+ /// # KBox ::pin_init(demo(), GFP_KERNEL).unwrap();
396396/// ```
397397///
398398/// Arbitrary Rust expressions can be used to set the value of a variable.
@@ -462,7 +462,7 @@ macro_rules! stack_try_pin_init {
462462/// # })
463463/// # }
464464/// # }
465- /// let foo = Box ::pin_init(Foo::new(), GFP_KERNEL);
465+ /// let foo = KBox ::pin_init(Foo::new(), GFP_KERNEL);
466466/// ```
467467///
468468/// They can also easily embed it into their own `struct`s:
@@ -594,15 +594,15 @@ macro_rules! pin_init {
594594/// use kernel::{init::{self, PinInit}, error::Error};
595595/// #[pin_data]
596596/// struct BigBuf {
597- /// big: Box <[u8; 1024 * 1024 * 1024]>,
597+ /// big: KBox <[u8; 1024 * 1024 * 1024]>,
598598/// small: [u8; 1024 * 1024],
599599/// ptr: *mut u8,
600600/// }
601601///
602602/// impl BigBuf {
603603/// fn new() -> impl PinInit<Self, Error> {
604604/// try_pin_init!(Self {
605- /// big: Box ::init(init::zeroed(), GFP_KERNEL)?,
605+ /// big: KBox ::init(init::zeroed(), GFP_KERNEL)?,
606606/// small: [0; 1024 * 1024],
607607/// ptr: core::ptr::null_mut(),
608608/// }? Error)
@@ -694,16 +694,16 @@ macro_rules! init {
694694/// # Examples
695695///
696696/// ```rust
697- /// use kernel::{init::{PinInit, zeroed}, error::Error};
697+ /// use kernel::{alloc::KBox, init::{PinInit, zeroed}, error::Error};
698698/// struct BigBuf {
699- /// big: Box <[u8; 1024 * 1024 * 1024]>,
699+ /// big: KBox <[u8; 1024 * 1024 * 1024]>,
700700/// small: [u8; 1024 * 1024],
701701/// }
702702///
703703/// impl BigBuf {
704704/// fn new() -> impl Init<Self, Error> {
705705/// try_init!(Self {
706- /// big: Box ::init(zeroed(), GFP_KERNEL)?,
706+ /// big: KBox ::init(zeroed(), GFP_KERNEL)?,
707707/// small: [0; 1024 * 1024],
708708/// }? Error)
709709/// }
@@ -814,8 +814,8 @@ macro_rules! assert_pinned {
814814/// A pin-initializer for the type `T`.
815815///
816816/// To use this initializer, you will need a suitable memory location that can hold a `T`. This can
817- /// be [`Box <T>`], [`Arc<T>`], [`UniqueArc<T>`] or even the stack (see [`stack_pin_init!`]). Use the
818- /// [`InPlaceInit::pin_init`] function of a smart pointer like [`Arc<T>`] on this.
817+ /// be [`KBox <T>`], [`Arc<T>`], [`UniqueArc<T>`] or even the stack (see [`stack_pin_init!`]). Use
818+ /// the [`InPlaceInit::pin_init`] function of a smart pointer like [`Arc<T>`] on this.
819819///
820820/// Also see the [module description](self).
821821///
@@ -894,7 +894,7 @@ pub unsafe trait PinInit<T: ?Sized, E = Infallible>: Sized {
894894}
895895
896896/// An initializer returned by [`PinInit::pin_chain`].
897- pub struct ChainPinInit < I , F , T : ?Sized , E > ( I , F , __internal:: Invariant < ( E , Box < T > ) > ) ;
897+ pub struct ChainPinInit < I , F , T : ?Sized , E > ( I , F , __internal:: Invariant < ( E , KBox < T > ) > ) ;
898898
899899// SAFETY: The `__pinned_init` function is implemented such that it
900900// - returns `Ok(())` on successful initialization,
@@ -920,8 +920,8 @@ where
920920/// An initializer for `T`.
921921///
922922/// To use this initializer, you will need a suitable memory location that can hold a `T`. This can
923- /// be [`Box <T>`], [`Arc<T>`], [`UniqueArc<T>`] or even the stack (see [`stack_pin_init!`]). Use the
924- /// [`InPlaceInit::init`] function of a smart pointer like [`Arc<T>`] on this. Because
923+ /// be [`KBox <T>`], [`Arc<T>`], [`UniqueArc<T>`] or even the stack (see [`stack_pin_init!`]). Use
924+ /// the [`InPlaceInit::init`] function of a smart pointer like [`Arc<T>`] on this. Because
925925/// [`PinInit<T, E>`] is a super trait, you can use every function that takes it as well.
926926///
927927/// Also see the [module description](self).
@@ -993,7 +993,7 @@ pub unsafe trait Init<T: ?Sized, E = Infallible>: PinInit<T, E> {
993993}
994994
995995/// An initializer returned by [`Init::chain`].
996- pub struct ChainInit < I , F , T : ?Sized , E > ( I , F , __internal:: Invariant < ( E , Box < T > ) > ) ;
996+ pub struct ChainInit < I , F , T : ?Sized , E > ( I , F , __internal:: Invariant < ( E , KBox < T > ) > ) ;
997997
998998// SAFETY: The `__init` function is implemented such that it
999999// - returns `Ok(())` on successful initialization,
@@ -1077,8 +1077,9 @@ pub fn uninit<T, E>() -> impl Init<MaybeUninit<T>, E> {
10771077/// # Examples
10781078///
10791079/// ```rust
1080- /// use kernel::{error::Error, init::init_array_from_fn};
1081- /// let array: Box<[usize; 1_000]> = Box::init::<Error>(init_array_from_fn(|i| i), GFP_KERNEL).unwrap();
1080+ /// use kernel::{alloc::KBox, error::Error, init::init_array_from_fn};
1081+ /// let array: KBox<[usize; 1_000]> =
1082+ /// KBox::init::<Error>(init_array_from_fn(|i| i), GFP_KERNEL).unwrap();
10821083/// assert_eq!(array.len(), 1_000);
10831084/// ```
10841085pub fn init_array_from_fn < I , const N : usize , T , E > (
@@ -1451,7 +1452,7 @@ impl_zeroable! {
14511452 //
14521453 // In this case we are allowed to use `T: ?Sized`, since all zeros is the `None` variant.
14531454 { <T : ?Sized >} Option <NonNull <T >>,
1454- { <T : ?Sized >} Option <Box <T >>,
1455+ { <T : ?Sized >} Option <KBox <T >>,
14551456
14561457 // SAFETY: `null` pointer is valid.
14571458 //
0 commit comments