Struct VmaMixedMap

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

A wrapper for the kernel’s struct vm_area_struct with read access and VM_MIXEDMAP set.

It represents an area of virtual memory.

This struct is identical to VmaRef except that it must only be used when the VM_MIXEDMAP flag is set on the vma.

§Invariants

The caller must hold the mmap read lock or the vma read lock. The VM_MIXEDMAP flag must be set.

Implementations§

Source§

impl VmaMixedMap

Source

pub unsafe fn from_raw<'a>(vma: *const vm_area_struct) -> &'a Self

Access a virtual memory area given a raw pointer.

§Safety

Callers must ensure that vma is valid for the duration of ’a, and that the mmap read lock (or stronger) is held for at least the duration of ’a. The VM_MIXEDMAP flag must be set.

Source

pub fn vm_insert_page(&self, address: usize, page: &Page) -> Result

Maps a single page at the given address within the virtual memory area.

This operation does not take ownership of the page.

Methods from Deref<Target = VmaRef>§

Source

pub fn as_ptr(&self) -> *mut vm_area_struct

Returns a raw pointer to this area.

Source

pub fn mm(&self) -> &MmWithUser

Access the underlying mm_struct.

Source

pub fn flags(&self) -> vm_flags_t

Returns the flags associated with the virtual memory area.

The possible flags are a combination of the constants in flags.

Source

pub fn start(&self) -> usize

Returns the (inclusive) start address of the virtual memory area.

Source

pub fn end(&self) -> usize

Returns the (exclusive) end address of the virtual memory area.

Source

pub fn zap_page_range_single(&self, address: usize, size: usize)

Zap pages in the given page range.

This clears page table mappings for the range at the leaf level, leaving all other page tables intact, and freeing any memory referenced by the VMA in this range. That is, anonymous memory is completely freed, file-backed memory has its reference count on page cache folio’s dropped, any dirty data will still be written back to disk as usual.

It may seem odd that we clear at the leaf level, this is however a product of the page table structure used to map physical memory into a virtual address space - each virtual address actually consists of a bitmap of array indices into page tables, which form a hierarchical page table level structure.

As a result, each page table level maps a multiple of page table levels below, and thus span ever increasing ranges of pages. At the leaf or PTE level, we map the actual physical memory.

It is here where a zap operates, as it the only place we can be certain of clearing without impacting any other virtual mappings. It is an implementation detail as to whether the kernel goes further in freeing unused page tables, but for the purposes of this operation we must only assume that the leaf level is cleared.

Source

pub fn as_mixedmap_vma(&self) -> Option<&VmaMixedMap>

If the VM_MIXEDMAP flag is set, returns a VmaMixedMap to this VMA, otherwise returns None.

This can be used to access methods that require VM_MIXEDMAP to be set.

Trait Implementations§

Source§

impl Deref for VmaMixedMap

Source§

type Target = VmaRef

The resulting type after dereferencing.
Source§

fn deref(&self) -> &VmaRef

Dereferences the value.

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, E> Init<T, E> for T

Source§

unsafe fn __init(self, slot: *mut T) -> Result<(), E>

Initializes slot. Read more
Source§

fn chain<F>(self, f: F) -> ChainInit<Self, F, T, E>
where F: FnOnce(&mut T) -> Result<(), E>,

First initializes the value using self then calls the function f with the initialized value. Read more
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, E> PinInit<T, E> for T

Source§

unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), E>

Initializes slot. Read more
Source§

fn pin_chain<F>(self, f: F) -> ChainPinInit<Self, F, T, E>
where F: FnOnce(Pin<&mut T>) -> Result<(), E>,

First initializes the value using self then calls the function f with the initialized value. Read more
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.