pub struct MmapOptions { /* private fields */ }Expand description
Configuration for creating a memory mapping.
Implementations§
Source§impl MmapOptions
impl MmapOptions
Sourcepub const fn new() -> Self
pub const fn new() -> Self
Creates a new MmapOptions with default settings (length 0).
You must set a length before mapping.
Sourcepub const fn with_hint(self, addr: usize) -> Self
pub const fn with_hint(self, addr: usize) -> Self
Sets a hint address for the mapping.
This is a request to the OS to place the mapping at this specific virtual address. The OS is not required to honor this request (on some platforms), or the call may fail if the address is already in use or invalid.
For the best chance of success:
- The address should be aligned to
allocation_granularity(). - The address range
[hint_addr, hint_addr + len)should be free.
Sourcepub const fn populate(self, populate: bool) -> Self
pub const fn populate(self, populate: bool) -> Self
Sets whether to pre-populate (prefault) the page tables.
On Linux, this adds MAP_POPULATE.
Sourcepub const fn no_reserve(self, no_reserve: bool) -> Self
pub const fn no_reserve(self, no_reserve: bool) -> Self
Sets whether to reserve swap space (on supported platforms).
On Linux, this adds MAP_NORESERVE.
Sourcepub const fn strict(self, strict: bool) -> Self
pub const fn strict(self, strict: bool) -> Self
Sets whether the hint address is strict.
If true, map_anon will return an error if the OS cannot map the memory
at the exact requested hint_addr.
Sourcepub unsafe fn map_anon(&self) -> Result<Mmap>
pub unsafe fn map_anon(&self) -> Result<Mmap>
Creates an anonymous memory map.
§Safety
This function is unsafe because it creates a raw memory mapping which has
implications for memory safety (e.g. use-after-free if the Mmap is dropped
while valid pointers into it still exist - though Mmap itself is safe,
using the raw pointer it yields requires care).
Actually, Mmap owns the memory, so as long as Mmap is alive, the pointer is valid.
However, sys_alloc is a low-level crate, so we mark creation as unsafe
mostly because of the OS interactions and potential for UB if hint_addr
is misused in some extensive contexts (though simply asking for an addr is usually safe).
§Errors
Returns an error if the length is 0, or if the system call fails (e.g. out of memory), or if strict hint compliance is requested but cannot be satisfied.
Trait Implementations§
Source§impl Clone for MmapOptions
impl Clone for MmapOptions
Source§fn clone(&self) -> MmapOptions
fn clone(&self) -> MmapOptions
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more