Skip to main content

Module mapping

Module mapping 

Source
Expand description

Memory mappings.

Each memory mapping is made of a virtual allocation and a physical allocation, where the size of the virtual allocation is equal to or larger than the size of the physical allocation.

The physical memory is then mapped to a space within the virtual allocation, and the rest of the virtual allocation is left reserved but inaccessible. The size of the physical allocation (and thus usable memory) is the value requested by users of the mapping API.

The size of and offset within the virtual allocation is controlled by implementations of Mappable, as shown below.

---+------------------------------+---
   |      virtual allocation      |
---+------------------------------+---
    <----------------------------> `virtual_size()`
    <---> `base_virtual_offset()`
         +---------------------+
         | physical allocation |
         +---------------------+

A Mapping can be created with Config::map:

use kernel_api::mapping::{Config, Ty, Mmap};
use core::num::NonZero;

let mapping = Config::new(NonZero::new(1).unwrap(), Ty::KERNEL_OTHER)
                  .map::<Mmap>()?;

Data can then be read from and written to the mapping:

use kernel_api::mapping::{Config, Ty, Mmap};
use core::num::NonZero;

let mut mapping = Config::new(NonZero::new(1).unwrap(), Ty::KERNEL_OTHER)
                      .protection(/* writable: */ true, false, false)
                      .map::<Mmap>()?;

for ptr in mapping.as_mut_ptr_range() {
    unsafe { *ptr = 1 };
}

for ptr in mapping.as_ptr_range() {
    assert_eq!(unsafe { *ptr }, 1);
}

Structs§

Configfull
A Mapping builder, providing control over the way the underlying buffer is mapped.
Mappingfull
An owned memory mapping.
MappingMetafull
The returned type when creating a userspace mapping.
Mmapfull
A basic map of virtual to physical memory.
Protectionfull
The protection that should be applied to the mapping.
Ty
The type of memory being mapped.
UncheckedMmapfull
A basic map of virtual to physical memory, with no out-of-bounds checking.

Enums§

Cachingfull
The caching strategy to use for the mapping.
Locationfull
The strategy used to place the allocation within the address space.
MapPageErrorfull

Traits§

Mappablefull
Basic operations to decide how to map memory together.

Type Aliases§

Stackfull
An implementation of Mappable for a stack, providing guard pages at the start and end of each allocation.
UnsafeMmapDeprecatedfull
A basic map of virtual to physical memory, with no out-of-bounds checking.