Expand description
This crate implements a generic page table walker in Rust, which can be used to either introspect or manage virtual address spaces on architectures that implement a Memory Management Unit (MMU) that traverses a hierarchy of page tables to translate virtual address into physical addresses and a set of permissions. Note that paging is not limited to CPUs, and that paging is also common on modern GPUs. The implementations provided here may therefore be useful when implementing drivers for any sort of paging architecture, an operating system, a hypervisor, etc.
The page table hierarchies of different architectures are described in the arch
module. In
particular, the PageFormat
struct is used to describe a page table hierarchy or layout
consisting of one or more PageLevel
structs, where each level describes which virtual
address bits are used to index into the page table. PageFormat::walk
and
PageFormat::walk_mut
implement a software page table walker that essentially starts at the
root address and traverses the page tables one by one using the PageFormat
struct to select
the appropriate bits from the virtual address to index into these page tables.
While traversing the page tables, the PageFormat::walk
and PageFormat::walk_mut
invoke
functions provided by a user supplied type implementing the PageWalker
and
PageWalkerMut
traits respectively to operate on the various page table entries (PTEs). Note
that there is an immutable version that does not allow modification of the page tables, and a
mutable version that does.
While it is possible to implement your own PageWalker
and PageWalkerMut
, this crate
also provides a higher-level abstraction of an virtual address space in AddressSpace
that
only requires you to implement a PageTableMapper
for mapping and unmapping page tables. The
AddressSpace
then simply offers you the functionality to retrieve and modify the PTEs of
existing pages.
In addition, when PageTableMapper::alloc_page
and PageTableMapper::free_page
are
implemented, the full range of functionality can be used. More specifically, the
AddressSpace
provides functions to allocate and free pages for a given virtual address
range, change the protection of a given virtual address range and allows mapping and unmapping
a physical address range to a given virtual address range for memory-mapped I/O.
Re-exports§
pub use address_space::AddressSpace;
pub use address_space::PageTableMapper;
pub use format::PageFormat;
pub use level::PageLevel;
pub use walker::PageWalker;
pub use walker::PageWalkerMut;
pub use walker::PteType;
Modules§
- address_
space - This module provides the
AddressSpace
struct which provides an abstraction over a virtual address space and provides methods to introspect and manage the virtual address space. - arch
- This module provides architecture-specific page formats.
- format
- This module provides the
PageFormat
struct that is used to describe the page table hierarchy. - level
- This module provides the
PageLevel
struct used to describe a single level in a page table hierarchy. The full page table hierarchy is described bycrate::format::PageFormat
. - walker
- This module provides the
PageWalker
andPageWalkerMut
traits that are used bycrate::format::PageFormat::walk
andcrate::format::PageFormat::walk_mut
to invoke user-specified callbacks during a page table walk, allowing the user to interact with the page tables of an address space in a generic way. - walkers
- This module provides various walkers to help with managing the
AddressSpace
.