pub trait Map<S, A>{
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§
sourceunsafe fn map_page(
&mut self,
virt: Page<VAddr, S>,
phys: Page<PAddr, S>,
frame_alloc: &A
) -> Handle<'_, S, Self::Entry>
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!
fn flags_mut(&mut self, virt: Page<VAddr, S>) -> Handle<'_, S, Self::Entry>
Provided Methods§
sourcefn identity_map(
&mut self,
phys: Page<PAddr, S>,
frame_alloc: &A
) -> Handle<'_, S, Self::Entry>
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.
sourceunsafe fn map_range<F>(
&mut self,
virt: PageRange<VAddr, S>,
phys: PageRange<PAddr, S>,
set_flags: F,
frame_alloc: &A
) -> PageRange<VAddr, S> ⓘ
unsafe fn map_range<F>( &mut self, virt: PageRange<VAddr, S>, phys: PageRange<PAddr, S>, set_flags: F, frame_alloc: &A ) -> PageRange<VAddr, S> ⓘ
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 mapvirt
to. -
set_flags
: a closure invoked with aHandle
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!
sourceunsafe fn unmap_range(&mut self, virt: PageRange<VAddr, S>)
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.
sourcefn identity_map_range<F>(
&mut self,
phys: PageRange<PAddr, S>,
set_flags: F,
frame_alloc: &A
) -> PageRange<VAddr, S> ⓘ
fn identity_map_range<F>( &mut self, phys: PageRange<PAddr, S>, set_flags: F, frame_alloc: &A ) -> PageRange<VAddr, S> ⓘ
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 aHandle
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.