File tree 2 files changed +28
-0
lines changed 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change
1
+ Added ` MapFlags::map_hugetlb_with_size_log2 ` method for Linux targets
Original file line number Diff line number Diff line change @@ -188,6 +188,33 @@ libc_bitflags! {
188
188
}
189
189
}
190
190
191
+ impl MapFlags {
192
+ /// Create `MAP_HUGETLB` with provided size of huge page.
193
+ ///
194
+ /// Under the hood it computes `MAP_HUGETLB | (huge_page_size_log2 << libc::MAP_HUGE_SHIFT`).
195
+ /// `huge_page_size_log2` denotes logarithm of huge page size to use and should be
196
+ /// between 16 and 63 (inclusively).
197
+ ///
198
+ /// ```
199
+ /// # use nix::sys::mman::MapFlags;
200
+ /// let f = MapFlags::map_hugetlb_with_size_log2(30).unwrap();
201
+ /// assert_eq!(f, MapFlags::MAP_HUGETLB | MapFlags::MAP_HUGE_1GB);
202
+ /// ```
203
+ // TODO: support Andorid and Fuchsia when https://github.com/rust-lang/libc/pull/3444
204
+ // will be released
205
+ #[ cfg( target_os = "linux" ) ]
206
+ #[ cfg_attr( docsrs, doc( cfg( all( ) ) ) ) ]
207
+ pub fn map_hugetlb_with_size_log2 ( huge_page_size_log2 : u32 ) -> Option < Self > {
208
+ if ( 16 ..=63 ) . contains ( & huge_page_size_log2) {
209
+ let flag = libc:: MAP_HUGETLB
210
+ | ( huge_page_size_log2 << libc:: MAP_HUGE_SHIFT ) as i32 ;
211
+ Some ( Self ( flag. into ( ) ) )
212
+ } else {
213
+ None
214
+ }
215
+ }
216
+ }
217
+
191
218
#[ cfg( any( target_os = "linux" , target_os = "netbsd" ) ) ]
192
219
libc_bitflags ! {
193
220
/// Options for [`mremap`].
You can’t perform that action at this time.
0 commit comments