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.
92
92
//! struct DriverData {
93
93
//! #[pin]
94
94
//! status: Mutex<i32>,
95
- //! buffer: Box <[u8; 1_000_000]>,
95
+ //! buffer: KBox <[u8; 1_000_000]>,
96
96
//! }
97
97
//!
98
98
//! impl DriverData {
99
99
//! fn new() -> impl PinInit<Self, Error> {
100
100
//! try_pin_init!(Self {
101
101
//! status <- new_mutex!(0, "DriverData::status"),
102
- //! buffer: Box ::init(kernel::init::zeroed(), GFP_KERNEL)?,
102
+ //! buffer: KBox ::init(kernel::init::zeroed(), GFP_KERNEL)?,
103
103
//! })
104
104
//! }
105
105
//! }
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
/// }));
@@ -391,7 +391,7 @@ macro_rules! stack_try_pin_init {
391
391
/// },
392
392
/// });
393
393
/// # initializer }
394
- /// # Box ::pin_init(demo(), GFP_KERNEL).unwrap();
394
+ /// # KBox ::pin_init(demo(), GFP_KERNEL).unwrap();
395
395
/// ```
396
396
///
397
397
/// Arbitrary Rust expressions can be used to set the value of a variable.
@@ -460,7 +460,7 @@ macro_rules! stack_try_pin_init {
460
460
/// # })
461
461
/// # }
462
462
/// # }
463
- /// let foo = Box ::pin_init(Foo::new(), GFP_KERNEL);
463
+ /// let foo = KBox ::pin_init(Foo::new(), GFP_KERNEL);
464
464
/// ```
465
465
///
466
466
/// They can also easily embed it into their own `struct`s:
@@ -592,15 +592,15 @@ macro_rules! pin_init {
592
592
/// use kernel::{init::{self, PinInit}, error::Error};
593
593
/// #[pin_data]
594
594
/// struct BigBuf {
595
- /// big: Box <[u8; 1024 * 1024 * 1024]>,
595
+ /// big: KBox <[u8; 1024 * 1024 * 1024]>,
596
596
/// small: [u8; 1024 * 1024],
597
597
/// ptr: *mut u8,
598
598
/// }
599
599
///
600
600
/// impl BigBuf {
601
601
/// fn new() -> impl PinInit<Self, Error> {
602
602
/// try_pin_init!(Self {
603
- /// big: Box ::init(init::zeroed(), GFP_KERNEL)?,
603
+ /// big: KBox ::init(init::zeroed(), GFP_KERNEL)?,
604
604
/// small: [0; 1024 * 1024],
605
605
/// ptr: core::ptr::null_mut(),
606
606
/// }? Error)
@@ -692,16 +692,16 @@ macro_rules! init {
692
692
/// # Examples
693
693
///
694
694
/// ```rust
695
- /// use kernel::{init::{PinInit, zeroed}, error::Error};
695
+ /// use kernel::{alloc::KBox, init::{PinInit, zeroed}, error::Error};
696
696
/// struct BigBuf {
697
- /// big: Box <[u8; 1024 * 1024 * 1024]>,
697
+ /// big: KBox <[u8; 1024 * 1024 * 1024]>,
698
698
/// small: [u8; 1024 * 1024],
699
699
/// }
700
700
///
701
701
/// impl BigBuf {
702
702
/// fn new() -> impl Init<Self, Error> {
703
703
/// try_init!(Self {
704
- /// big: Box ::init(zeroed(), GFP_KERNEL)?,
704
+ /// big: KBox ::init(zeroed(), GFP_KERNEL)?,
705
705
/// small: [0; 1024 * 1024],
706
706
/// }? Error)
707
707
/// }
@@ -812,8 +812,8 @@ macro_rules! assert_pinned {
812
812
/// A pin-initializer for the type `T`.
813
813
///
814
814
/// 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.
817
817
///
818
818
/// Also see the [module description](self).
819
819
///
@@ -893,7 +893,7 @@ pub unsafe trait PinInit<T: ?Sized, E = Infallible>: Sized {
893
893
}
894
894
895
895
/// 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 > ) > ) ;
897
897
898
898
// SAFETY: The `__pinned_init` function is implemented such that it
899
899
// - returns `Ok(())` on successful initialization,
@@ -919,8 +919,8 @@ where
919
919
/// An initializer for `T`.
920
920
///
921
921
/// 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
924
924
/// [`PinInit<T, E>`] is a super trait, you can use every function that takes it as well.
925
925
///
926
926
/// Also see the [module description](self).
@@ -992,7 +992,7 @@ pub unsafe trait Init<T: ?Sized, E = Infallible>: PinInit<T, E> {
992
992
}
993
993
994
994
/// 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 > ) > ) ;
996
996
997
997
// SAFETY: The `__init` function is implemented such that it
998
998
// - returns `Ok(())` on successful initialization,
@@ -1076,8 +1076,9 @@ pub fn uninit<T, E>() -> impl Init<MaybeUninit<T>, E> {
1076
1076
/// # Examples
1077
1077
///
1078
1078
/// ```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();
1081
1082
/// assert_eq!(array.len(), 1_000);
1082
1083
/// ```
1083
1084
pub fn init_array_from_fn < I , const N : usize , T , E > (
@@ -1453,7 +1454,7 @@ impl_zeroable! {
1453
1454
//
1454
1455
// In this case we are allowed to use `T: ?Sized`, since all zeros is the `None` variant.
1455
1456
{ <T : ?Sized >} Option <NonNull <T >>,
1456
- { <T : ?Sized >} Option <Box <T >>,
1457
+ { <T : ?Sized >} Option <KBox <T >>,
1457
1458
1458
1459
// SAFETY: `null` pointer is valid.
1459
1460
//
0 commit comments