pub struct UnsafeMmapFlags(/* private fields */);
Expand description
The available flags to configure the allocated mapping, but that are considered unsafe to use.
Implementations§
Source§impl UnsafeMmapFlags
impl UnsafeMmapFlags
Sourcepub const MAP_FIXED: Self
pub const MAP_FIXED: Self
Maps the memory mapping at the address specified, replacing any pages that have been mapped at that address range.
This is not supported on Microsoft Windows.
Sourcepub const JIT: Self
pub const JIT: Self
Allows mapping the page as RWX. While this may seem useful for self-modifying code and
JIT engines, it is instead recommended to convert between mutable and executable
mappings using Mmap::make_mut()
and MmapMut::make_exec()
instead.
As it may be tempting to use this flag, this flag has been (indirectly) marked as unsafe. Make sure to read the text below to understand the complications of this flag before using it.
RWX pages are an interesting targets to attackers, e.g. for buffer overflow attacks, as RWX mappings can potentially simplify such attacks. Without RWX mappings, attackers instead have to resort to return-oriented programming (ROP) gadgets. To prevent buffer overflow attacks, contemporary CPUs allow pages to be marked as non-executable which is then used by the operating system to ensure that pages are either marked as writeable or as executable, but not both. This is also known as W^X.
While the x86 and x86-64 architectures guarantee cache coherency between the L1 instruction and the L1 data cache, other architectures such as Arm and AArch64 do not. If the user modified the pages, then executing the code may result in undefined behavior. To ensure correct behavior a user has to flush the instruction cache after modifying and before executing the page.
Source§impl UnsafeMmapFlags
impl UnsafeMmapFlags
Sourcepub const fn bits(&self) -> u32
pub const fn bits(&self) -> u32
Get the underlying bits value.
The returned value is exactly the bits set in this flags value.
Sourcepub const fn from_bits(bits: u32) -> Option<Self>
pub const fn from_bits(bits: u32) -> Option<Self>
Convert from a bits value.
This method will return None
if any unknown bits are set.
Sourcepub const fn from_bits_truncate(bits: u32) -> Self
pub const fn from_bits_truncate(bits: u32) -> Self
Convert from a bits value, unsetting any unknown bits.
Sourcepub const fn from_bits_retain(bits: u32) -> Self
pub const fn from_bits_retain(bits: u32) -> Self
Convert from a bits value exactly.
Sourcepub fn from_name(name: &str) -> Option<Self>
pub fn from_name(name: &str) -> Option<Self>
Get a flags value with the bits of a flag with the given name set.
This method will return None
if name
is empty or doesn’t
correspond to any named flag.
Sourcepub const fn intersects(&self, other: Self) -> bool
pub const fn intersects(&self, other: Self) -> bool
Whether any set bits in a source flags value are also set in a target flags value.
Sourcepub const fn contains(&self, other: Self) -> bool
pub const fn contains(&self, other: Self) -> bool
Whether all set bits in a source flags value are also set in a target flags value.
Sourcepub fn remove(&mut self, other: Self)
pub fn remove(&mut self, other: Self)
The intersection of a source flags value with the complement of a target flags
value (&!
).
This method is not equivalent to self & !other
when other
has unknown bits set.
remove
won’t truncate other
, but the !
operator will.
Sourcepub fn toggle(&mut self, other: Self)
pub fn toggle(&mut self, other: Self)
The bitwise exclusive-or (^
) of the bits in two flags values.
Sourcepub fn set(&mut self, other: Self, value: bool)
pub fn set(&mut self, other: Self, value: bool)
Call insert
when value
is true
or remove
when value
is false
.
Sourcepub const fn intersection(self, other: Self) -> Self
pub const fn intersection(self, other: Self) -> Self
The bitwise and (&
) of the bits in two flags values.
Sourcepub const fn union(self, other: Self) -> Self
pub const fn union(self, other: Self) -> Self
The bitwise or (|
) of the bits in two flags values.
Sourcepub const fn difference(self, other: Self) -> Self
pub const fn difference(self, other: Self) -> Self
The intersection of a source flags value with the complement of a target flags
value (&!
).
This method is not equivalent to self & !other
when other
has unknown bits set.
difference
won’t truncate other
, but the !
operator will.
Sourcepub const fn symmetric_difference(self, other: Self) -> Self
pub const fn symmetric_difference(self, other: Self) -> Self
The bitwise exclusive-or (^
) of the bits in two flags values.
Sourcepub const fn complement(self) -> Self
pub const fn complement(self) -> Self
The bitwise negation (!
) of the bits in a flags value, truncating the result.
Source§impl UnsafeMmapFlags
impl UnsafeMmapFlags
Sourcepub const fn iter(&self) -> Iter<UnsafeMmapFlags>
pub const fn iter(&self) -> Iter<UnsafeMmapFlags>
Yield a set of contained flags values.
Each yielded flags value will correspond to a defined named flag. Any unknown bits will be yielded together as a final flags value.
Sourcepub const fn iter_names(&self) -> IterNames<UnsafeMmapFlags>
pub const fn iter_names(&self) -> IterNames<UnsafeMmapFlags>
Yield a set of contained named flags values.
This method is like iter
, except only yields bits in contained named flags.
Any unknown bits, or bits not corresponding to a contained flag will not be yielded.
Trait Implementations§
Source§impl Binary for UnsafeMmapFlags
impl Binary for UnsafeMmapFlags
Source§impl BitAnd for UnsafeMmapFlags
impl BitAnd for UnsafeMmapFlags
Source§impl BitAndAssign for UnsafeMmapFlags
impl BitAndAssign for UnsafeMmapFlags
Source§fn bitand_assign(&mut self, other: Self)
fn bitand_assign(&mut self, other: Self)
The bitwise and (&
) of the bits in two flags values.
Source§impl BitOr for UnsafeMmapFlags
impl BitOr for UnsafeMmapFlags
Source§fn bitor(self, other: UnsafeMmapFlags) -> Self
fn bitor(self, other: UnsafeMmapFlags) -> Self
The bitwise or (|
) of the bits in two flags values.
Source§type Output = UnsafeMmapFlags
type Output = UnsafeMmapFlags
|
operator.Source§impl BitOrAssign for UnsafeMmapFlags
impl BitOrAssign for UnsafeMmapFlags
Source§fn bitor_assign(&mut self, other: Self)
fn bitor_assign(&mut self, other: Self)
The bitwise or (|
) of the bits in two flags values.
Source§impl BitXor for UnsafeMmapFlags
impl BitXor for UnsafeMmapFlags
Source§impl BitXorAssign for UnsafeMmapFlags
impl BitXorAssign for UnsafeMmapFlags
Source§fn bitxor_assign(&mut self, other: Self)
fn bitxor_assign(&mut self, other: Self)
The bitwise exclusive-or (^
) of the bits in two flags values.
Source§impl Clone for UnsafeMmapFlags
impl Clone for UnsafeMmapFlags
Source§fn clone(&self) -> UnsafeMmapFlags
fn clone(&self) -> UnsafeMmapFlags
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for UnsafeMmapFlags
impl Debug for UnsafeMmapFlags
Source§impl Extend<UnsafeMmapFlags> for UnsafeMmapFlags
impl Extend<UnsafeMmapFlags> for UnsafeMmapFlags
Source§fn extend<T: IntoIterator<Item = Self>>(&mut self, iterator: T)
fn extend<T: IntoIterator<Item = Self>>(&mut self, iterator: T)
The bitwise or (|
) of the bits in each flags value.
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Source§impl Flags for UnsafeMmapFlags
impl Flags for UnsafeMmapFlags
Source§const FLAGS: &'static [Flag<UnsafeMmapFlags>]
const FLAGS: &'static [Flag<UnsafeMmapFlags>]
Source§fn from_bits_retain(bits: u32) -> UnsafeMmapFlags
fn from_bits_retain(bits: u32) -> UnsafeMmapFlags
Source§fn contains_unknown_bits(&self) -> bool
fn contains_unknown_bits(&self) -> bool
true
if any unknown bits are set.Source§fn from_bits_truncate(bits: Self::Bits) -> Self
fn from_bits_truncate(bits: Self::Bits) -> Self
Source§fn from_name(name: &str) -> Option<Self>
fn from_name(name: &str) -> Option<Self>
Source§fn iter_names(&self) -> IterNames<Self>
fn iter_names(&self) -> IterNames<Self>
Source§fn intersects(&self, other: Self) -> boolwhere
Self: Sized,
fn intersects(&self, other: Self) -> boolwhere
Self: Sized,
Source§fn contains(&self, other: Self) -> boolwhere
Self: Sized,
fn contains(&self, other: Self) -> boolwhere
Self: Sized,
Source§fn insert(&mut self, other: Self)where
Self: Sized,
fn insert(&mut self, other: Self)where
Self: Sized,
|
) of the bits in two flags values.Source§fn remove(&mut self, other: Self)where
Self: Sized,
fn remove(&mut self, other: Self)where
Self: Sized,
&!
). Read moreSource§fn toggle(&mut self, other: Self)where
Self: Sized,
fn toggle(&mut self, other: Self)where
Self: Sized,
^
) of the bits in two flags values.Source§fn intersection(self, other: Self) -> Self
fn intersection(self, other: Self) -> Self
&
) of the bits in two flags values.Source§fn difference(self, other: Self) -> Self
fn difference(self, other: Self) -> Self
&!
). Read moreSource§fn symmetric_difference(self, other: Self) -> Self
fn symmetric_difference(self, other: Self) -> Self
^
) of the bits in two flags values.Source§fn complement(self) -> Self
fn complement(self) -> Self
!
) of the bits in a flags value, truncating the result.Source§impl FromIterator<UnsafeMmapFlags> for UnsafeMmapFlags
impl FromIterator<UnsafeMmapFlags> for UnsafeMmapFlags
Source§fn from_iter<T: IntoIterator<Item = Self>>(iterator: T) -> Self
fn from_iter<T: IntoIterator<Item = Self>>(iterator: T) -> Self
The bitwise or (|
) of the bits in each flags value.
Source§impl Hash for UnsafeMmapFlags
impl Hash for UnsafeMmapFlags
Source§impl IntoIterator for UnsafeMmapFlags
impl IntoIterator for UnsafeMmapFlags
Source§impl LowerHex for UnsafeMmapFlags
impl LowerHex for UnsafeMmapFlags
Source§impl Not for UnsafeMmapFlags
impl Not for UnsafeMmapFlags
Source§impl Octal for UnsafeMmapFlags
impl Octal for UnsafeMmapFlags
Source§impl PartialEq for UnsafeMmapFlags
impl PartialEq for UnsafeMmapFlags
Source§impl PublicFlags for UnsafeMmapFlags
impl PublicFlags for UnsafeMmapFlags
Source§impl Sub for UnsafeMmapFlags
impl Sub for UnsafeMmapFlags
Source§fn sub(self, other: Self) -> Self
fn sub(self, other: Self) -> Self
The intersection of a source flags value with the complement of a target flags value (&!
).
This method is not equivalent to self & !other
when other
has unknown bits set.
difference
won’t truncate other
, but the !
operator will.
Source§type Output = UnsafeMmapFlags
type Output = UnsafeMmapFlags
-
operator.Source§impl SubAssign for UnsafeMmapFlags
impl SubAssign for UnsafeMmapFlags
Source§fn sub_assign(&mut self, other: Self)
fn sub_assign(&mut self, other: Self)
The intersection of a source flags value with the complement of a target flags value (&!
).
This method is not equivalent to self & !other
when other
has unknown bits set.
difference
won’t truncate other
, but the !
operator will.