Trait hal_core::mem::page::Map

source ·
pub trait Map<S, A>
where S: Size, A: Alloc<S>,
{ type Entry: PageFlags<S>; // Required methods unsafe fn map_page( &mut self, virt: Page<VAddr, S>, phys: Page<PAddr, S>, frame_alloc: &A ) -> Handle<'_, S, Self::Entry>; fn flags_mut(&mut self, virt: Page<VAddr, S>) -> Handle<'_, S, Self::Entry>; unsafe fn unmap(&mut self, virt: Page<VAddr, S>) -> Page<PAddr, S>; // Provided methods fn identity_map( &mut self, phys: Page<PAddr, S>, frame_alloc: &A ) -> Handle<'_, S, Self::Entry> { ... } unsafe fn map_range<F>( &mut self, virt: PageRange<VAddr, S>, phys: PageRange<PAddr, S>, set_flags: F, frame_alloc: &A ) -> PageRange<VAddr, S> where F: FnMut(&mut Handle<'_, S, Self::Entry>) { ... } unsafe fn unmap_range(&mut self, virt: PageRange<VAddr, S>) { ... } fn identity_map_range<F>( &mut self, phys: PageRange<PAddr, S>, set_flags: F, frame_alloc: &A ) -> PageRange<VAddr, S> where F: FnMut(&mut Handle<'_, S, Self::Entry>) { ... } }

Required Associated Types§

Required Methods§

source

unsafe fn map_page( &mut self, virt: Page<VAddr, S>, phys: Page<PAddr, S>, frame_alloc: &A ) -> Handle<'_, S, Self::Entry>

Map the virtual memory page represented by virt to the physical page represented bt phys.

Panics
  • If the physical address is invalid.
  • If the page is already mapped.
Safety

Manual control of page mappings may be used to violate Rust invariants in a variety of exciting ways. For example, aliasing a physical page by mapping multiple virtual pages to it and setting one or more of those virtual pages as writable may result in undefined behavior.

Some rules of thumb:

  • Ensure that the writable XOR executable rule is not violated (by making a page both writable and executable).
  • Don’t alias stack pages onto the heap or vice versa.
  • If loading arbitrary code into executable pages, ensure that this code is trusted and will not violate the kernel’s invariants.

Good luck and have fun!

source

fn flags_mut(&mut self, virt: Page<VAddr, S>) -> Handle<'_, S, Self::Entry>

source

unsafe fn unmap(&mut self, virt: Page<VAddr, S>) -> Page<PAddr, S>

Unmap the provided virtual page, returning the physical page it was previously mapped to.

This does not deallocate any page frames.

Panics
  • If the virtual page was not mapped.
Safety

Manual control of page mappings may be used to violate Rust invariants in a variety of exciting ways.

Provided Methods§

source

fn identity_map( &mut self, phys: Page<PAddr, S>, frame_alloc: &A ) -> Handle<'_, S, Self::Entry>

Identity map the provided physical page to the virtual page with the same address.

source

unsafe fn map_range<F>( &mut self, virt: PageRange<VAddr, S>, phys: PageRange<PAddr, S>, set_flags: F, frame_alloc: &A ) -> PageRange<VAddr, S>
where F: FnMut(&mut Handle<'_, S, Self::Entry>),

Map the range of virtual memory pages represented by virt to the range of physical pages represented by phys.

Arguments
  • virt: the range of virtual pages to map.

  • phys: the range of physical pages to map virt to.

  • set_flags: a closure invoked with a Handle to each page in the range as it is mapped. This closure may modify the flags for that page before the changes to the page mapping are committed.

    Note: The Handle::virt_page method may be used to determine which page’s flags would be modified by each invocation of the cosure.

  • frame_alloc: a page-frame allocator.

Panics
  • If the two ranges have different lengths.
  • If the size is dynamic and the two ranges are of different sized pages.
  • If the physical address is invalid.
  • If any page is already mapped.
Safety

Manual control of page mappings may be used to violate Rust invariants in a variety of exciting ways. For example, aliasing a physical page by mapping multiple virtual pages to it and setting one or more of those virtual pages as writable may result in undefined behavior.

Some rules of thumb:

  • Ensure that the writable XOR executable rule is not violated (by making a page both writable and executable).
  • Don’t alias stack pages onto the heap or vice versa.
  • If loading arbitrary code into executable pages, ensure that this code is trusted and will not violate the kernel’s invariants.

Good luck and have fun!

source

unsafe fn unmap_range(&mut self, virt: PageRange<VAddr, S>)

Unmap the provided range of virtual pages.

This does not deallocate any page frames.

Notes

The default implementation of this method does not assume that the virtual pages are mapped to a contiguous range of physical page frames. Overridden implementations may perform different behavior when the pages are mapped contiguously in the physical address space, but they must not assume this. If an implementation performs additional behavior for contiguously-mapped virtual page ranges, it must check that the page range is, in fact, contiguously mapped.

Additionally, and unlike unmap, this method does not return a physical PageRange, since it is not guaranteed that the unmapped pages are mapped to a contiguous physical page range.

Panics
  • If any virtual page in the range was not mapped.
Safety

Manual control of page mappings may be used to violate Rust invariants in a variety of exciting ways.

source

fn identity_map_range<F>( &mut self, phys: PageRange<PAddr, S>, set_flags: F, frame_alloc: &A ) -> PageRange<VAddr, S>
where F: FnMut(&mut Handle<'_, S, Self::Entry>),

Identity map the provided physical page range to a range of virtual pages with the same address

Arguments
  • phys: the range of physical pages to identity map

  • set_flags: a closure invoked with a Handle to each page in the range as it is mapped. This closure may modify the flags for that page before the changes to the page mapping are committed.

    Note: The Handle::virt_page method may be used to determine which page’s flags would be modified by each invocation of the cosure.

  • frame_alloc: a page-frame allocator.

Panics
  • If any page’s physical address is invalid.
  • If any page is already mapped.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl<M, A, S> Map<S, A> for &mut M
where M: Map<S, A>, S: Size, A: Alloc<S>,

§

type Entry = <M as Map<S, A>>::Entry

source§

unsafe fn map_page( &mut self, virt: Page<VAddr, S>, phys: Page<PAddr, S>, frame_alloc: &A ) -> Handle<'_, S, Self::Entry>

source§

fn flags_mut(&mut self, virt: Page<VAddr, S>) -> Handle<'_, S, Self::Entry>

source§

unsafe fn unmap(&mut self, virt: Page<VAddr, S>) -> Page<PAddr, S>

source§

fn identity_map( &mut self, phys: Page<PAddr, S>, frame_alloc: &A ) -> Handle<'_, S, Self::Entry>

Implementors§