13
13
//! To initialize a `struct` with an in-place constructor you will need two things:
14
14
//! - an in-place constructor,
15
15
//! - 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`]).
17
17
//!
18
18
//! To get an in-place constructor there are generally three options:
19
19
//! - directly creating an in-place constructor using the [`pin_init!`] macro,
68
68
//! # a <- new_mutex!(42, "Foo::a"),
69
69
//! # b: 24,
70
70
//! # });
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);
72
72
//! ```
73
73
//!
74
74
//! For more information see the [`pin_init!`] macro.
93
93
//! struct DriverData {
94
94
//! #[pin]
95
95
//! status: Mutex<i32>,
96
- //! buffer: Box <[u8; 1_000_000]>,
96
+ //! buffer: KBox <[u8; 1_000_000]>,
97
97
//! }
98
98
//!
99
99
//! impl DriverData {
100
100
//! fn new() -> impl PinInit<Self, Error> {
101
101
//! try_pin_init!(Self {
102
102
//! status <- new_mutex!(0, "DriverData::status"),
103
- //! buffer: Box ::init(kernel::init::zeroed(), GFP_KERNEL)?,
103
+ //! buffer: KBox ::init(kernel::init::zeroed(), GFP_KERNEL)?,
104
104
//! })
105
105
//! }
106
106
//! }
211
211
//! [`pin_init!`]: crate::pin_init!
212
212
213
213
use crate :: {
214
- alloc:: { box_ext:: BoxExt , AllocError , Flags } ,
214
+ alloc:: { box_ext:: BoxExt , AllocError , Flags , KBox } ,
215
215
error:: { self , Error } ,
216
216
sync:: Arc ,
217
217
sync:: UniqueArc ,
@@ -298,7 +298,7 @@ macro_rules! stack_pin_init {
298
298
/// struct Foo {
299
299
/// #[pin]
300
300
/// a: Mutex<usize>,
301
- /// b: Box <Bar>,
301
+ /// b: KBox <Bar>,
302
302
/// }
303
303
///
304
304
/// struct Bar {
@@ -307,7 +307,7 @@ macro_rules! stack_pin_init {
307
307
///
308
308
/// stack_try_pin_init!(let foo: Result<Pin<&mut Foo>, AllocError> = pin_init!(Foo {
309
309
/// a <- new_mutex!(42),
310
- /// b: Box ::new(Bar {
310
+ /// b: KBox ::new(Bar {
311
311
/// x: 64,
312
312
/// }, GFP_KERNEL)?,
313
313
/// }));
@@ -324,7 +324,7 @@ macro_rules! stack_pin_init {
324
324
/// struct Foo {
325
325
/// #[pin]
326
326
/// a: Mutex<usize>,
327
- /// b: Box <Bar>,
327
+ /// b: KBox <Bar>,
328
328
/// }
329
329
///
330
330
/// struct Bar {
@@ -333,7 +333,7 @@ macro_rules! stack_pin_init {
333
333
///
334
334
/// stack_try_pin_init!(let foo: Pin<&mut Foo> =? pin_init!(Foo {
335
335
/// a <- new_mutex!(42),
336
- /// b: Box ::new(Bar {
336
+ /// b: KBox ::new(Bar {
337
337
/// x: 64,
338
338
/// }, GFP_KERNEL)?,
339
339
/// }));
@@ -392,7 +392,7 @@ macro_rules! stack_try_pin_init {
392
392
/// },
393
393
/// });
394
394
/// # initializer }
395
- /// # Box ::pin_init(demo(), GFP_KERNEL).unwrap();
395
+ /// # KBox ::pin_init(demo(), GFP_KERNEL).unwrap();
396
396
/// ```
397
397
///
398
398
/// Arbitrary Rust expressions can be used to set the value of a variable.
@@ -462,7 +462,7 @@ macro_rules! stack_try_pin_init {
462
462
/// # })
463
463
/// # }
464
464
/// # }
465
- /// let foo = Box ::pin_init(Foo::new(), GFP_KERNEL);
465
+ /// let foo = KBox ::pin_init(Foo::new(), GFP_KERNEL);
466
466
/// ```
467
467
///
468
468
/// They can also easily embed it into their own `struct`s:
@@ -594,15 +594,15 @@ macro_rules! pin_init {
594
594
/// use kernel::{init::{self, PinInit}, error::Error};
595
595
/// #[pin_data]
596
596
/// struct BigBuf {
597
- /// big: Box <[u8; 1024 * 1024 * 1024]>,
597
+ /// big: KBox <[u8; 1024 * 1024 * 1024]>,
598
598
/// small: [u8; 1024 * 1024],
599
599
/// ptr: *mut u8,
600
600
/// }
601
601
///
602
602
/// impl BigBuf {
603
603
/// fn new() -> impl PinInit<Self, Error> {
604
604
/// try_pin_init!(Self {
605
- /// big: Box ::init(init::zeroed(), GFP_KERNEL)?,
605
+ /// big: KBox ::init(init::zeroed(), GFP_KERNEL)?,
606
606
/// small: [0; 1024 * 1024],
607
607
/// ptr: core::ptr::null_mut(),
608
608
/// }? Error)
@@ -694,16 +694,16 @@ macro_rules! init {
694
694
/// # Examples
695
695
///
696
696
/// ```rust
697
- /// use kernel::{init::{PinInit, zeroed}, error::Error};
697
+ /// use kernel::{alloc::KBox, init::{PinInit, zeroed}, error::Error};
698
698
/// struct BigBuf {
699
- /// big: Box <[u8; 1024 * 1024 * 1024]>,
699
+ /// big: KBox <[u8; 1024 * 1024 * 1024]>,
700
700
/// small: [u8; 1024 * 1024],
701
701
/// }
702
702
///
703
703
/// impl BigBuf {
704
704
/// fn new() -> impl Init<Self, Error> {
705
705
/// try_init!(Self {
706
- /// big: Box ::init(zeroed(), GFP_KERNEL)?,
706
+ /// big: KBox ::init(zeroed(), GFP_KERNEL)?,
707
707
/// small: [0; 1024 * 1024],
708
708
/// }? Error)
709
709
/// }
@@ -814,8 +814,8 @@ macro_rules! assert_pinned {
814
814
/// A pin-initializer for the type `T`.
815
815
///
816
816
/// 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.
819
819
///
820
820
/// Also see the [module description](self).
821
821
///
@@ -894,7 +894,7 @@ pub unsafe trait PinInit<T: ?Sized, E = Infallible>: Sized {
894
894
}
895
895
896
896
/// 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 > ) > ) ;
898
898
899
899
// SAFETY: The `__pinned_init` function is implemented such that it
900
900
// - returns `Ok(())` on successful initialization,
@@ -920,8 +920,8 @@ where
920
920
/// An initializer for `T`.
921
921
///
922
922
/// 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
925
925
/// [`PinInit<T, E>`] is a super trait, you can use every function that takes it as well.
926
926
///
927
927
/// Also see the [module description](self).
@@ -993,7 +993,7 @@ pub unsafe trait Init<T: ?Sized, E = Infallible>: PinInit<T, E> {
993
993
}
994
994
995
995
/// 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 > ) > ) ;
997
997
998
998
// SAFETY: The `__init` function is implemented such that it
999
999
// - returns `Ok(())` on successful initialization,
@@ -1077,8 +1077,9 @@ pub fn uninit<T, E>() -> impl Init<MaybeUninit<T>, E> {
1077
1077
/// # Examples
1078
1078
///
1079
1079
/// ```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();
1082
1083
/// assert_eq!(array.len(), 1_000);
1083
1084
/// ```
1084
1085
pub fn init_array_from_fn < I , const N : usize , T , E > (
@@ -1451,7 +1452,7 @@ impl_zeroable! {
1451
1452
//
1452
1453
// In this case we are allowed to use `T: ?Sized`, since all zeros is the `None` variant.
1453
1454
{ <T : ?Sized >} Option <NonNull <T >>,
1454
- { <T : ?Sized >} Option <Box <T >>,
1455
+ { <T : ?Sized >} Option <KBox <T >>,
1455
1456
1456
1457
// SAFETY: `null` pointer is valid.
1457
1458
//
0 commit comments