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§
- Config
full - A
Mappingbuilder, providing control over the way the underlying buffer is mapped. - Mapping
full - An owned memory mapping.
- Mapping
Meta full - The returned type when creating a userspace mapping.
- Mmap
full - A basic map of virtual to physical memory.
- Protection
full - The protection that should be applied to the mapping.
- Ty
- The type of memory being mapped.
- Unchecked
Mmap full - A basic map of virtual to physical memory, with no out-of-bounds checking.
Enums§
- Caching
full - The caching strategy to use for the mapping.
- Location
full - The strategy used to place the allocation within the address space.
- MapPage
Error full
Traits§
- Mappable
full - Basic operations to decide how to map memory together.
Type Aliases§
- Stack
full - An implementation of
Mappablefor a stack, providing guard pages at the start and end of each allocation. - Unsafe
Mmap Deprecated full - A basic map of virtual to physical memory, with no out-of-bounds checking.