# Mapper in riscv::paging - Rust
API documentation for the Rust `Mapper` trait in crate `riscv`.
Keywords: rust, rustlang, rust-lang, Mapper

# Trait riscv::paging::Mapper

source · [−]

    pub trait Mapper {
        type P: PhysicalAddress;
        type V: VirtualAddress;
        type MapperFlush: MapperFlushable;
        type Entry: PTE;
        fn map_to(
            &mut self,
            page: PageWith<Self::V>,
            frame: FrameWith<Self::P>,
            flags: PageTableFlags,
            allocator: &mut impl FrameAllocatorFor<<Self as Mapper>::P>
        ) -> Result<Self::MapperFlush, MapToError>;
        fn unmap(
            &mut self,
            page: PageWith<Self::V>
        ) -> Result<(FrameWith<Self::P>, Self::MapperFlush), UnmapError<<Self as Mapper>::P>>;
        fn ref_entry(
            &mut self,
            page: PageWith<Self::V>
        ) -> Result<&mut Self::Entry, FlagUpdateError>;

        fn update_flags(
            &mut self,
            page: PageWith<Self::V>,
            flags: PageTableFlags
        ) -> Result<Self::MapperFlush, FlagUpdateError> { ... }
        fn translate_page(
            &mut self,
            page: PageWith<Self::V>
        ) -> Option<FrameWith<Self::P>> { ... }
        fn identity_map(
            &mut self,
            frame: FrameWith<Self::P>,
            flags: PageTableFlags,
            allocator: &mut impl FrameAllocatorFor<<Self as Mapper>::P>
        ) -> Result<Self::MapperFlush, MapToError> { ... }
    }

## Associated Types

source

#### type P: PhysicalAddress

source

#### type V: VirtualAddress

source

#### type MapperFlush: MapperFlushable

source

#### type Entry: PTE

## Required methods

source

#### fn map_to(
&mut self,
page: PageWith<Self::V>,
frame: FrameWith<Self::P>,
flags: PageTableFlags,
allocator: &mut impl FrameAllocatorFor<<Self as Mapper>::P>
) -> Result<Self::MapperFlush, MapToError>

Creates a new mapping in the page table.

This function might need additional physical frames to create new page tables. These frames are allocated from the `allocator` argument. At most three frames are required.

source

#### fn unmap(
&mut self,
page: PageWith<Self::V>
) -> Result<( FrameWith<Self::P>, Self::MapperFlush ), UnmapError<<Self as Mapper>::P>>

Removes a mapping from the page table and returns the frame that used to be mapped.

Note that no page tables or pages are deallocated.

source

#### fn ref_entry(
&mut self,
page: PageWith<Self::V>
) -> Result<&mut Self::Entry, FlagUpdateError>

Get the reference of the specified `page` entry

## Provided methods

source

#### fn update_flags(
&mut self,
page: PageWith<Self::V>,
flags: PageTableFlags
) -> Result<Self::MapperFlush, FlagUpdateError>

Updates the flags of an existing mapping.

source

#### fn translate_page(
&mut self,
page: PageWith<Self::V>
) -> Option<FrameWith<Self::P>>

Return the frame that the specified page is mapped to.

source

#### fn identity_map(
&mut self,
frame: FrameWith<Self::P>,
flags: PageTableFlags,
allocator: &mut impl FrameAllocatorFor<<Self as Mapper>::P>
) -> Result<Self::MapperFlush, MapToError>

Maps the given frame to the virtual page with the same address.

## Implementors

source

### impl<'a, V: VirtualAddress + AddressL2, FL: MapperFlushable> Mapper for Rv32PageTableWith<'a, V, FL>

#### type P = PhysAddrSv32

#### type V = V

#### type MapperFlush = FL

#### type Entry = PageTableEntryX32

source

### impl<'a, V: VirtualAddress + AddressL3, FL: MapperFlushable> Mapper for Rv39PageTableWith<'a, V, FL>

#### type P = PhysAddrSv39

#### type V = V

#### type MapperFlush = FL

#### type Entry = PageTableEntryX64

source

### impl<'a, V: VirtualAddress + AddressL4, FL: MapperFlushable> Mapper for Rv48PageTableWith<'a, V, FL>

#### type P = PhysAddrSv48

#### type V = V

#### type MapperFlush = FL

#### type Entry = PageTableEntryX64