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);
71
+ //! let foo: Result<Pin<Box<Foo>>> = Box::pin_init(foo, GFP_KERNEL );
72
72
//! ```
73
73
//!
74
74
//! For more information see the [`pin_init!`] macro.
80
80
//!
81
81
//! ```rust
82
82
//! # use kernel::sync::{new_mutex, Arc, Mutex};
83
- //! let mtx: Result<Arc<Mutex<usize>>> = Arc::pin_init(new_mutex!(42, "example::mtx"));
83
+ //! let mtx: Result<Arc<Mutex<usize>>> =
84
+ //! Arc::pin_init(new_mutex!(42, "example::mtx"), GFP_KERNEL);
84
85
//! ```
85
86
//!
86
87
//! To declare an init macro/function you just return an [`impl PinInit<T, E>`]:
99
100
//! fn new() -> impl PinInit<Self, Error> {
100
101
//! try_pin_init!(Self {
101
102
//! status <- new_mutex!(0, "DriverData::status"),
102
- //! buffer: Box::init(kernel::init::zeroed())?,
103
+ //! buffer: Box::init(kernel::init::zeroed(), GFP_KERNEL )?,
103
104
//! })
104
105
//! }
105
106
//! }
210
211
//! [`pin_init!`]: crate::pin_init!
211
212
212
213
use crate :: {
213
- alloc:: { box_ext:: BoxExt , flags :: * } ,
214
+ alloc:: { box_ext:: BoxExt , Flags } ,
214
215
error:: { self , Error } ,
215
216
sync:: UniqueArc ,
216
217
types:: { Opaque , ScopeGuard } ,
@@ -391,7 +392,7 @@ macro_rules! stack_try_pin_init {
391
392
/// },
392
393
/// });
393
394
/// # initializer }
394
- /// # Box::pin_init(demo()).unwrap();
395
+ /// # Box::pin_init(demo(), GFP_KERNEL ).unwrap();
395
396
/// ```
396
397
///
397
398
/// Arbitrary Rust expressions can be used to set the value of a variable.
@@ -461,7 +462,7 @@ macro_rules! stack_try_pin_init {
461
462
/// # })
462
463
/// # }
463
464
/// # }
464
- /// let foo = Box::pin_init(Foo::new());
465
+ /// let foo = Box::pin_init(Foo::new(), GFP_KERNEL );
465
466
/// ```
466
467
///
467
468
/// They can also easily embed it into their own `struct`s:
@@ -601,7 +602,7 @@ macro_rules! pin_init {
601
602
/// impl BigBuf {
602
603
/// fn new() -> impl PinInit<Self, Error> {
603
604
/// try_pin_init!(Self {
604
- /// big: Box::init(init::zeroed())?,
605
+ /// big: Box::init(init::zeroed(), GFP_KERNEL )?,
605
606
/// small: [0; 1024 * 1024],
606
607
/// ptr: core::ptr::null_mut(),
607
608
/// }? Error)
@@ -702,7 +703,7 @@ macro_rules! init {
702
703
/// impl BigBuf {
703
704
/// fn new() -> impl Init<Self, Error> {
704
705
/// try_init!(Self {
705
- /// big: Box::init(zeroed())?,
706
+ /// big: Box::init(zeroed(), GFP_KERNEL )?,
706
707
/// small: [0; 1024 * 1024],
707
708
/// }? Error)
708
709
/// }
@@ -1014,7 +1015,7 @@ pub fn uninit<T, E>() -> impl Init<MaybeUninit<T>, E> {
1014
1015
///
1015
1016
/// ```rust
1016
1017
/// use kernel::{error::Error, init::init_array_from_fn};
1017
- /// let array: Box<[usize; 1_000]> = Box::init::<Error>(init_array_from_fn(|i| i)).unwrap();
1018
+ /// let array: Box<[usize; 1_000]> = Box::init::<Error>(init_array_from_fn(|i| i), GFP_KERNEL ).unwrap();
1018
1019
/// assert_eq!(array.len(), 1_000);
1019
1020
/// ```
1020
1021
pub fn init_array_from_fn < I , const N : usize , T , E > (
@@ -1058,7 +1059,7 @@ where
1058
1059
/// ```rust
1059
1060
/// use kernel::{sync::{Arc, Mutex}, init::pin_init_array_from_fn, new_mutex};
1060
1061
/// let array: Arc<[Mutex<usize>; 1_000]> =
1061
- /// Arc::pin_init(pin_init_array_from_fn(|i| new_mutex!(i))).unwrap();
1062
+ /// Arc::pin_init(pin_init_array_from_fn(|i| new_mutex!(i)), GFP_KERNEL ).unwrap();
1062
1063
/// assert_eq!(array.len(), 1_000);
1063
1064
/// ```
1064
1065
pub fn pin_init_array_from_fn < I , const N : usize , T , E > (
@@ -1116,50 +1117,50 @@ pub trait InPlaceInit<T>: Sized {
1116
1117
/// type.
1117
1118
///
1118
1119
/// If `T: !Unpin` it will not be able to move afterwards.
1119
- fn try_pin_init < E > ( init : impl PinInit < T , E > ) -> Result < Pin < Self > , E >
1120
+ fn try_pin_init < E > ( init : impl PinInit < T , E > , flags : Flags ) -> Result < Pin < Self > , E >
1120
1121
where
1121
1122
E : From < AllocError > ;
1122
1123
1123
1124
/// Use the given pin-initializer to pin-initialize a `T` inside of a new smart pointer of this
1124
1125
/// type.
1125
1126
///
1126
1127
/// If `T: !Unpin` it will not be able to move afterwards.
1127
- fn pin_init < E > ( init : impl PinInit < T , E > ) -> error:: Result < Pin < Self > >
1128
+ fn pin_init < E > ( init : impl PinInit < T , E > , flags : Flags ) -> error:: Result < Pin < Self > >
1128
1129
where
1129
1130
Error : From < E > ,
1130
1131
{
1131
1132
// SAFETY: We delegate to `init` and only change the error type.
1132
1133
let init = unsafe {
1133
1134
pin_init_from_closure ( |slot| init. __pinned_init ( slot) . map_err ( |e| Error :: from ( e) ) )
1134
1135
} ;
1135
- Self :: try_pin_init ( init)
1136
+ Self :: try_pin_init ( init, flags )
1136
1137
}
1137
1138
1138
1139
/// Use the given initializer to in-place initialize a `T`.
1139
- fn try_init < E > ( init : impl Init < T , E > ) -> Result < Self , E >
1140
+ fn try_init < E > ( init : impl Init < T , E > , flags : Flags ) -> Result < Self , E >
1140
1141
where
1141
1142
E : From < AllocError > ;
1142
1143
1143
1144
/// Use the given initializer to in-place initialize a `T`.
1144
- fn init < E > ( init : impl Init < T , E > ) -> error:: Result < Self >
1145
+ fn init < E > ( init : impl Init < T , E > , flags : Flags ) -> error:: Result < Self >
1145
1146
where
1146
1147
Error : From < E > ,
1147
1148
{
1148
1149
// SAFETY: We delegate to `init` and only change the error type.
1149
1150
let init = unsafe {
1150
1151
init_from_closure ( |slot| init. __pinned_init ( slot) . map_err ( |e| Error :: from ( e) ) )
1151
1152
} ;
1152
- Self :: try_init ( init)
1153
+ Self :: try_init ( init, flags )
1153
1154
}
1154
1155
}
1155
1156
1156
1157
impl < T > InPlaceInit < T > for Box < T > {
1157
1158
#[ inline]
1158
- fn try_pin_init < E > ( init : impl PinInit < T , E > ) -> Result < Pin < Self > , E >
1159
+ fn try_pin_init < E > ( init : impl PinInit < T , E > , flags : Flags ) -> Result < Pin < Self > , E >
1159
1160
where
1160
1161
E : From < AllocError > ,
1161
1162
{
1162
- let mut this = <Box < _ > as BoxExt < _ > >:: new_uninit ( GFP_KERNEL ) ?;
1163
+ let mut this = <Box < _ > as BoxExt < _ > >:: new_uninit ( flags ) ?;
1163
1164
let slot = this. as_mut_ptr ( ) ;
1164
1165
// SAFETY: When init errors/panics, slot will get deallocated but not dropped,
1165
1166
// slot is valid and will not be moved, because we pin it later.
@@ -1169,11 +1170,11 @@ impl<T> InPlaceInit<T> for Box<T> {
1169
1170
}
1170
1171
1171
1172
#[ inline]
1172
- fn try_init < E > ( init : impl Init < T , E > ) -> Result < Self , E >
1173
+ fn try_init < E > ( init : impl Init < T , E > , flags : Flags ) -> Result < Self , E >
1173
1174
where
1174
1175
E : From < AllocError > ,
1175
1176
{
1176
- let mut this = <Box < _ > as BoxExt < _ > >:: new_uninit ( GFP_KERNEL ) ?;
1177
+ let mut this = <Box < _ > as BoxExt < _ > >:: new_uninit ( flags ) ?;
1177
1178
let slot = this. as_mut_ptr ( ) ;
1178
1179
// SAFETY: When init errors/panics, slot will get deallocated but not dropped,
1179
1180
// slot is valid.
@@ -1185,11 +1186,11 @@ impl<T> InPlaceInit<T> for Box<T> {
1185
1186
1186
1187
impl < T > InPlaceInit < T > for UniqueArc < T > {
1187
1188
#[ inline]
1188
- fn try_pin_init < E > ( init : impl PinInit < T , E > ) -> Result < Pin < Self > , E >
1189
+ fn try_pin_init < E > ( init : impl PinInit < T , E > , flags : Flags ) -> Result < Pin < Self > , E >
1189
1190
where
1190
1191
E : From < AllocError > ,
1191
1192
{
1192
- let mut this = UniqueArc :: new_uninit ( GFP_KERNEL ) ?;
1193
+ let mut this = UniqueArc :: new_uninit ( flags ) ?;
1193
1194
let slot = this. as_mut_ptr ( ) ;
1194
1195
// SAFETY: When init errors/panics, slot will get deallocated but not dropped,
1195
1196
// slot is valid and will not be moved, because we pin it later.
@@ -1199,11 +1200,11 @@ impl<T> InPlaceInit<T> for UniqueArc<T> {
1199
1200
}
1200
1201
1201
1202
#[ inline]
1202
- fn try_init < E > ( init : impl Init < T , E > ) -> Result < Self , E >
1203
+ fn try_init < E > ( init : impl Init < T , E > , flags : Flags ) -> Result < Self , E >
1203
1204
where
1204
1205
E : From < AllocError > ,
1205
1206
{
1206
- let mut this = UniqueArc :: new_uninit ( GFP_KERNEL ) ?;
1207
+ let mut this = UniqueArc :: new_uninit ( flags ) ?;
1207
1208
let slot = this. as_mut_ptr ( ) ;
1208
1209
// SAFETY: When init errors/panics, slot will get deallocated but not dropped,
1209
1210
// slot is valid.
0 commit comments