memfile::hp: Added `Mask`: Converts bytes into a suitable `MAP_HUGE_` constant via its `.raw()` method, and a suitable flag for `memfd_create()` via its `.mask()` method.
The above is all either `const fn` or checked, and can be bitwise OR"d together, producing a higher `Mask`, or bitwise OR"d with an arbitrary `c_uint` to produce a valid mask for `memfd_create()` (in the latter case, the OR with MFD_HUGETLB is unneeded, as `Mask` applies this itself.)
Fortune for collect's current commit: Blessing − 吉
.checked_shl(Self::SHIFTasu32).ok_or(eyre!("Left shift would overflow"))?))
}
/// Create a new mask from a number of bytes.
///
/// This is unchecked and may overflow if the number of bytes is so large (in which case, there is likely a bug), for a checked version, use `new_checked()`.
#[inline]
pubconstfnnew(bytes: usize)-> Self
{
Self((log2_usize(bytes)asc_uint)<<Self::SHIFT)
}
/// Create from a raw `MAP_HUGE_` mask.
///
/// # Safety
/// The caller **must** guarantee that `mask` is a valid `MAP_HUGE_` mask.
#[inline]
pubconstunsafefnfrom_raw(mask: c_uint)-> Self
{
Self(mask)
}
/// Get the raw `MAP_HUGE_` mask.
#[inline]
pubconstfnraw(self)-> c_uint
{
self.0
}
/// Get a HUGETLB mask suitable for `memfd_create()` from this value.
#[inline]
pubconstfnmask(self)-> c_uint
{
self.raw()|Self::HUGETLB_MASK
}
/// Create a function that acts as `memfd_create()` with *only* this mask applied to it.
///
/// The `flags` argument is erased. To pass arbitrary flags to `memfd_create()`, use `memfd_create_wrapper_flags()`
//TODO: add test for `Mask::new{,_checked}()` above, and `.memfd_create_wrapper{,_flags}()` usage, too with some `MAP_HUGE_` constants as sizes
/// Take a directory path and try to parse the hugepage size from it.
/// Take a directory path and try to parse the hugepage size from it.
///
///
/// All subdirectories from `HUGEPAGE_SIZES_LOCATION` should be passed to this, and the correct system-valid hugepage size will be returned for that specific hugepage.
/// All subdirectories from `HUGEPAGE_SIZES_LOCATION` should be passed to this, and the correct system-valid hugepage size will be returned for that specific hugepage.