page_walker/lib.rs
1//! This crate implements a generic page table walker in Rust, which can be used to either
2//! introspect or manage virtual address spaces on architectures that implement a Memory Management
3//! Unit (MMU) that traverses a hierarchy of page tables to translate virtual address into physical
4//! addresses and a set of permissions. Note that paging is not limited to CPUs, and that paging is
5//! also common on modern GPUs. The implementations provided here may therefore be useful when
6//! implementing drivers for any sort of paging architecture, an operating system, a hypervisor,
7//! etc.
8//!
9//! The page table hierarchies of different architectures are described in the [`arch`] module. In
10//! particular, the [`PageFormat`] struct is used to describe a page table hierarchy or layout
11//! consisting of one or more [`PageLevel`] structs, where each level describes which virtual
12//! address bits are used to index into the page table. [`PageFormat::walk`] and
13//! [`PageFormat::walk_mut`] implement a software page table walker that essentially starts at the
14//! root address and traverses the page tables one by one using the [`PageFormat`] struct to select
15//! the appropriate bits from the virtual address to index into these page tables.
16//!
17//! While traversing the page tables, the [`PageFormat::walk`] and [`PageFormat::walk_mut`] invoke
18//! functions provided by a user supplied type implementing the [`PageWalker`] and
19//! [`PageWalkerMut`] traits respectively to operate on the various page table entries (PTEs). Note
20//! that there is an immutable version that does not allow modification of the page tables, and a
21//! mutable version that does.
22//!
23//! While it is possible to implement your own [`PageWalker`] and [`PageWalkerMut`], this crate
24//! also provides a higher-level abstraction of an virtual address space in [`AddressSpace`] that
25//! only requires you to implement a [`PageTableMapper`] for mapping and unmapping page tables. The
26//! [`AddressSpace`] then simply offers you the functionality to retrieve and modify the PTEs of
27//! existing pages.
28//!
29//! In addition, when [`PageTableMapper::alloc_page`] and [`PageTableMapper::free_page`] are
30//! implemented, the full range of functionality can be used. More specifically, the
31//! [`AddressSpace`] provides functions to allocate and free pages for a given virtual address
32//! range, change the protection of a given virtual address range and allows mapping and unmapping
33//! a physical address range to a given virtual address range for memory-mapped I/O.
34
35#![no_std]
36#![deny(missing_docs, rustdoc::broken_intra_doc_links)]
37
38pub mod address_space;
39pub mod arch;
40pub mod format;
41pub mod level;
42pub mod walker;
43pub mod walkers;
44
45pub use address_space::{AddressSpace, PageTableMapper};
46pub use format::PageFormat;
47pub use level::PageLevel;
48pub use walker::{PageWalker, PageWalkerMut, PteType};