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.
9292//! struct DriverData {
9393//! #[pin]
9494//! status: Mutex<i32>,
95- //! buffer: Box <[u8; 1_000_000]>,
95+ //! buffer: KBox <[u8; 1_000_000]>,
9696//! }
9797//!
9898//! impl DriverData {
9999//! fn new() -> impl PinInit<Self, Error> {
100100//! try_pin_init!(Self {
101101//! status <- new_mutex!(0, "DriverData::status"),
102- //! buffer: Box ::init(kernel::init::zeroed(), GFP_KERNEL)?,
102+ //! buffer: KBox ::init(kernel::init::zeroed(), GFP_KERNEL)?,
103103//! })
104104//! }
105105//! }
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/// }));
@@ -391,7 +391,7 @@ macro_rules! stack_try_pin_init {
391391/// },
392392/// });
393393/// # initializer }
394- /// # Box ::pin_init(demo(), GFP_KERNEL).unwrap();
394+ /// # KBox ::pin_init(demo(), GFP_KERNEL).unwrap();
395395/// ```
396396///
397397/// Arbitrary Rust expressions can be used to set the value of a variable.
@@ -460,7 +460,7 @@ macro_rules! stack_try_pin_init {
460460/// # })
461461/// # }
462462/// # }
463- /// let foo = Box ::pin_init(Foo::new(), GFP_KERNEL);
463+ /// let foo = KBox ::pin_init(Foo::new(), GFP_KERNEL);
464464/// ```
465465///
466466/// They can also easily embed it into their own `struct`s:
@@ -592,15 +592,15 @@ macro_rules! pin_init {
592592/// use kernel::{init::{self, PinInit}, error::Error};
593593/// #[pin_data]
594594/// struct BigBuf {
595- /// big: Box <[u8; 1024 * 1024 * 1024]>,
595+ /// big: KBox <[u8; 1024 * 1024 * 1024]>,
596596/// small: [u8; 1024 * 1024],
597597/// ptr: *mut u8,
598598/// }
599599///
600600/// impl BigBuf {
601601/// fn new() -> impl PinInit<Self, Error> {
602602/// try_pin_init!(Self {
603- /// big: Box ::init(init::zeroed(), GFP_KERNEL)?,
603+ /// big: KBox ::init(init::zeroed(), GFP_KERNEL)?,
604604/// small: [0; 1024 * 1024],
605605/// ptr: core::ptr::null_mut(),
606606/// }? Error)
@@ -692,16 +692,16 @@ macro_rules! init {
692692/// # Examples
693693///
694694/// ```rust
695- /// use kernel::{init::{PinInit, zeroed}, error::Error};
695+ /// use kernel::{alloc::KBox, init::{PinInit, zeroed}, error::Error};
696696/// struct BigBuf {
697- /// big: Box <[u8; 1024 * 1024 * 1024]>,
697+ /// big: KBox <[u8; 1024 * 1024 * 1024]>,
698698/// small: [u8; 1024 * 1024],
699699/// }
700700///
701701/// impl BigBuf {
702702/// fn new() -> impl Init<Self, Error> {
703703/// try_init!(Self {
704- /// big: Box ::init(zeroed(), GFP_KERNEL)?,
704+ /// big: KBox ::init(zeroed(), GFP_KERNEL)?,
705705/// small: [0; 1024 * 1024],
706706/// }? Error)
707707/// }
@@ -812,8 +812,8 @@ macro_rules! assert_pinned {
812812/// A pin-initializer for the type `T`.
813813///
814814/// To use this initializer, you will need a suitable memory location that can hold a `T`. This can
815- /// be [`Box <T>`], [`Arc<T>`], [`UniqueArc<T>`] or even the stack (see [`stack_pin_init!`]). Use the
816- /// [`InPlaceInit::pin_init`] function of a smart pointer like [`Arc<T>`] on this.
815+ /// be [`KBox <T>`], [`Arc<T>`], [`UniqueArc<T>`] or even the stack (see [`stack_pin_init!`]). Use
816+ /// the [`InPlaceInit::pin_init`] function of a smart pointer like [`Arc<T>`] on this.
817817///
818818/// Also see the [module description](self).
819819///
@@ -893,7 +893,7 @@ pub unsafe trait PinInit<T: ?Sized, E = Infallible>: Sized {
893893}
894894
895895/// An initializer returned by [`PinInit::pin_chain`].
896- pub struct ChainPinInit < I , F , T : ?Sized , E > ( I , F , __internal:: Invariant < ( E , Box < T > ) > ) ;
896+ pub struct ChainPinInit < I , F , T : ?Sized , E > ( I , F , __internal:: Invariant < ( E , KBox < T > ) > ) ;
897897
898898// SAFETY: The `__pinned_init` function is implemented such that it
899899// - returns `Ok(())` on successful initialization,
@@ -919,8 +919,8 @@ where
919919/// An initializer for `T`.
920920///
921921/// To use this initializer, you will need a suitable memory location that can hold a `T`. This can
922- /// be [`Box <T>`], [`Arc<T>`], [`UniqueArc<T>`] or even the stack (see [`stack_pin_init!`]). Use the
923- /// [`InPlaceInit::init`] function of a smart pointer like [`Arc<T>`] on this. Because
922+ /// be [`KBox <T>`], [`Arc<T>`], [`UniqueArc<T>`] or even the stack (see [`stack_pin_init!`]). Use
923+ /// the [`InPlaceInit::init`] function of a smart pointer like [`Arc<T>`] on this. Because
924924/// [`PinInit<T, E>`] is a super trait, you can use every function that takes it as well.
925925///
926926/// Also see the [module description](self).
@@ -992,7 +992,7 @@ pub unsafe trait Init<T: ?Sized, E = Infallible>: PinInit<T, E> {
992992}
993993
994994/// An initializer returned by [`Init::chain`].
995- pub struct ChainInit < I , F , T : ?Sized , E > ( I , F , __internal:: Invariant < ( E , Box < T > ) > ) ;
995+ pub struct ChainInit < I , F , T : ?Sized , E > ( I , F , __internal:: Invariant < ( E , KBox < T > ) > ) ;
996996
997997// SAFETY: The `__init` function is implemented such that it
998998// - returns `Ok(())` on successful initialization,
@@ -1076,8 +1076,9 @@ pub fn uninit<T, E>() -> impl Init<MaybeUninit<T>, E> {
10761076/// # Examples
10771077///
10781078/// ```rust
1079- /// use kernel::{error::Error, init::init_array_from_fn};
1080- /// let array: Box<[usize; 1_000]> = Box::init::<Error>(init_array_from_fn(|i| i), GFP_KERNEL).unwrap();
1079+ /// use kernel::{alloc::KBox, error::Error, init::init_array_from_fn};
1080+ /// let array: KBox<[usize; 1_000]> =
1081+ /// KBox::init::<Error>(init_array_from_fn(|i| i), GFP_KERNEL).unwrap();
10811082/// assert_eq!(array.len(), 1_000);
10821083/// ```
10831084pub fn init_array_from_fn < I , const N : usize , T , E > (
@@ -1453,7 +1454,7 @@ impl_zeroable! {
14531454 //
14541455 // In this case we are allowed to use `T: ?Sized`, since all zeros is the `None` variant.
14551456 { <T : ?Sized >} Option <NonNull <T >>,
1456- { <T : ?Sized >} Option <Box <T >>,
1457+ { <T : ?Sized >} Option <KBox <T >>,
14571458
14581459 // SAFETY: `null` pointer is valid.
14591460 //
0 commit comments