6868//! # a <- new_mutex!(42, "Foo::a"),
6969//! # b: 24,
7070//! # });
71- //! let foo: Result<Pin<Box<Foo>>> = Box::pin_init(foo);
71+ //! let foo: Result<Pin<Box<Foo>>> = Box::pin_init(foo, GFP_KERNEL );
7272//! ```
7373//!
7474//! For more information see the [`pin_init!`] macro.
8080//!
8181//! ```rust
8282//! # 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);
8485//! ```
8586//!
8687//! To declare an init macro/function you just return an [`impl PinInit<T, E>`]:
99100//! fn new() -> impl PinInit<Self, Error> {
100101//! try_pin_init!(Self {
101102//! status <- new_mutex!(0, "DriverData::status"),
102- //! buffer: Box::init(kernel::init::zeroed())?,
103+ //! buffer: Box::init(kernel::init::zeroed(), GFP_KERNEL )?,
103104//! })
104105//! }
105106//! }
210211//! [`pin_init!`]: crate::pin_init!
211212
212213use crate :: {
213- alloc:: { box_ext:: BoxExt , flags :: * } ,
214+ alloc:: { box_ext:: BoxExt , Flags } ,
214215 error:: { self , Error } ,
215216 sync:: UniqueArc ,
216217 types:: { Opaque , ScopeGuard } ,
@@ -391,7 +392,7 @@ macro_rules! stack_try_pin_init {
391392/// },
392393/// });
393394/// # initializer }
394- /// # Box::pin_init(demo()).unwrap();
395+ /// # Box::pin_init(demo(), GFP_KERNEL ).unwrap();
395396/// ```
396397///
397398/// Arbitrary Rust expressions can be used to set the value of a variable.
@@ -461,7 +462,7 @@ macro_rules! stack_try_pin_init {
461462/// # })
462463/// # }
463464/// # }
464- /// let foo = Box::pin_init(Foo::new());
465+ /// let foo = Box::pin_init(Foo::new(), GFP_KERNEL );
465466/// ```
466467///
467468/// They can also easily embed it into their own `struct`s:
@@ -601,7 +602,7 @@ macro_rules! pin_init {
601602/// impl BigBuf {
602603/// fn new() -> impl PinInit<Self, Error> {
603604/// try_pin_init!(Self {
604- /// big: Box::init(init::zeroed())?,
605+ /// big: Box::init(init::zeroed(), GFP_KERNEL )?,
605606/// small: [0; 1024 * 1024],
606607/// ptr: core::ptr::null_mut(),
607608/// }? Error)
@@ -702,7 +703,7 @@ macro_rules! init {
702703/// impl BigBuf {
703704/// fn new() -> impl Init<Self, Error> {
704705/// try_init!(Self {
705- /// big: Box::init(zeroed())?,
706+ /// big: Box::init(zeroed(), GFP_KERNEL )?,
706707/// small: [0; 1024 * 1024],
707708/// }? Error)
708709/// }
@@ -1014,7 +1015,7 @@ pub fn uninit<T, E>() -> impl Init<MaybeUninit<T>, E> {
10141015///
10151016/// ```rust
10161017/// 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();
10181019/// assert_eq!(array.len(), 1_000);
10191020/// ```
10201021pub fn init_array_from_fn < I , const N : usize , T , E > (
@@ -1058,7 +1059,7 @@ where
10581059/// ```rust
10591060/// use kernel::{sync::{Arc, Mutex}, init::pin_init_array_from_fn, new_mutex};
10601061/// 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();
10621063/// assert_eq!(array.len(), 1_000);
10631064/// ```
10641065pub fn pin_init_array_from_fn < I , const N : usize , T , E > (
@@ -1116,50 +1117,50 @@ pub trait InPlaceInit<T>: Sized {
11161117 /// type.
11171118 ///
11181119 /// 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 >
11201121 where
11211122 E : From < AllocError > ;
11221123
11231124 /// Use the given pin-initializer to pin-initialize a `T` inside of a new smart pointer of this
11241125 /// type.
11251126 ///
11261127 /// 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 > >
11281129 where
11291130 Error : From < E > ,
11301131 {
11311132 // SAFETY: We delegate to `init` and only change the error type.
11321133 let init = unsafe {
11331134 pin_init_from_closure ( |slot| init. __pinned_init ( slot) . map_err ( |e| Error :: from ( e) ) )
11341135 } ;
1135- Self :: try_pin_init ( init)
1136+ Self :: try_pin_init ( init, flags )
11361137 }
11371138
11381139 /// 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 >
11401141 where
11411142 E : From < AllocError > ;
11421143
11431144 /// 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 >
11451146 where
11461147 Error : From < E > ,
11471148 {
11481149 // SAFETY: We delegate to `init` and only change the error type.
11491150 let init = unsafe {
11501151 init_from_closure ( |slot| init. __pinned_init ( slot) . map_err ( |e| Error :: from ( e) ) )
11511152 } ;
1152- Self :: try_init ( init)
1153+ Self :: try_init ( init, flags )
11531154 }
11541155}
11551156
11561157impl < T > InPlaceInit < T > for Box < T > {
11571158 #[ 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 >
11591160 where
11601161 E : From < AllocError > ,
11611162 {
1162- let mut this = <Box < _ > as BoxExt < _ > >:: new_uninit ( GFP_KERNEL ) ?;
1163+ let mut this = <Box < _ > as BoxExt < _ > >:: new_uninit ( flags ) ?;
11631164 let slot = this. as_mut_ptr ( ) ;
11641165 // SAFETY: When init errors/panics, slot will get deallocated but not dropped,
11651166 // slot is valid and will not be moved, because we pin it later.
@@ -1169,11 +1170,11 @@ impl<T> InPlaceInit<T> for Box<T> {
11691170 }
11701171
11711172 #[ 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 >
11731174 where
11741175 E : From < AllocError > ,
11751176 {
1176- let mut this = <Box < _ > as BoxExt < _ > >:: new_uninit ( GFP_KERNEL ) ?;
1177+ let mut this = <Box < _ > as BoxExt < _ > >:: new_uninit ( flags ) ?;
11771178 let slot = this. as_mut_ptr ( ) ;
11781179 // SAFETY: When init errors/panics, slot will get deallocated but not dropped,
11791180 // slot is valid.
@@ -1185,11 +1186,11 @@ impl<T> InPlaceInit<T> for Box<T> {
11851186
11861187impl < T > InPlaceInit < T > for UniqueArc < T > {
11871188 #[ 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 >
11891190 where
11901191 E : From < AllocError > ,
11911192 {
1192- let mut this = UniqueArc :: new_uninit ( GFP_KERNEL ) ?;
1193+ let mut this = UniqueArc :: new_uninit ( flags ) ?;
11931194 let slot = this. as_mut_ptr ( ) ;
11941195 // SAFETY: When init errors/panics, slot will get deallocated but not dropped,
11951196 // slot is valid and will not be moved, because we pin it later.
@@ -1199,11 +1200,11 @@ impl<T> InPlaceInit<T> for UniqueArc<T> {
11991200 }
12001201
12011202 #[ 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 >
12031204 where
12041205 E : From < AllocError > ,
12051206 {
1206- let mut this = UniqueArc :: new_uninit ( GFP_KERNEL ) ?;
1207+ let mut this = UniqueArc :: new_uninit ( flags ) ?;
12071208 let slot = this. as_mut_ptr ( ) ;
12081209 // SAFETY: When init errors/panics, slot will get deallocated but not dropped,
12091210 // slot is valid.
0 commit comments