Skip to main content

MmapRegion

Struct MmapRegion 

Source
pub struct MmapRegion { /* private fields */ }
Expand description

Mapping mmap partageable et compatible io_uring : ses pages restent valides tant qu’une opération io_uring en vol (madvise/futex_*) y référence de la mémoire. Compté par référence — munmap au dernier drop (la région et toutes les gardes de vivacité d’ops en vol).

Distinct de Mapping à dessein : Mapping reste l’usage synchrone unique/zéro-coût ; MmapRegion est l’opt-in partageable (une allocation Arc, cf. exception ADR-021 c.4 ci-dessus). Cloner incrémente le compteur fort ; aucune copie de pages, seulement du partage de propriété.

Implementations§

Source§

impl MmapRegion

Source

pub fn new_anonymous( len: usize, prot: ProtectionFlags, flags: MapFlags, ) -> Result<Self, Errno>

Mapping anonyme partageable (équivalent mmap_anonymous rendant une MmapRegion).

§Errors

Toute erreur de mmap(2) (cf. mmap_anonymous) : EINVAL, ENOMEM

Source

pub fn from_file( fd: BorrowedFd<'_>, len: usize, prot: ProtectionFlags, flags: MapFlags, offset: u64, ) -> Result<Self, Errno>

Mapping de fichier partageable (équivalent mmap_file rendant une MmapRegion).

§Errors

Toute erreur de mmap(2) (cf. mmap_file) : EINVAL, EACCES

Source

pub fn from_mapping(mapping: Mapping, prot: ProtectionFlags) -> Self

Promeut un Mapping unique en région partageable : transfère la responsabilité du munmap à l’inner partagé. Le Mapping est consommé et neutralisé (son Drop ne munmap plus) → pas de double munmap. Une seule allocation (l’inner).

prot explicite (obligatoire). Un Mapping nu ne mémorise pas ses protections ; l’appelant doit fournir le prot avec lequel le Mapping a été créé, sinon MmapRegion::bytes / MmapRegion::futex_word décideraient de l’accessibilité sur une base fausse (référence qui faute à l’usage). Il n’y a pas de défaut READ|WRITE : le prot passé fait foi.

Source

pub fn len(&self) -> usize

Longueur du mapping en octets.

Source

pub fn is_empty(&self) -> bool

true si la longueur est zéro.

Source

pub fn as_ptr(&self) -> *const u8

Pointeur brut vers le début du mapping (consommateurs avancés ; pas de transfert de propriété — le munmap reste géré par la MmapRegion).

Source

pub fn bytes(&self) -> &[u8]

Tranche d’octets en lecture, bornée par construction. Renvoie une tranche vide si la région n’est pas lisible (prot sans READ) — jamais de référence vers de la mémoire inaccessible.

Source

pub fn futex_word(&self, offset: usize) -> Result<&AtomicU32, Errno>

Référence à un mot futex (AtomicU32) à offset octets.

La référence est mutable par partage (AtomicU32 : store/load via &) ; la rendre sur des pages non inscriptibles serait unsound (une écriture fauterait). La validation amont (Principe 4) exige donc que la région soit inscriptible (prot ⊇ WRITE), offset borné (offset + 4 ≤ len) et aligné sur 4 (un futex est un u32 aligné) — sinon la référence n’est pas rendue.

§Errors

[Errno::EINVAL] si la région n’est pas inscriptible, ou si offset est hors bornes ou non aligné sur 4.

Trait Implementations§

Source§

impl Clone for MmapRegion

Source§

fn clone(&self) -> MmapRegion

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MmapRegion

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.