22 releases

Uses new Rust 2024

0.8.1 Apr 2, 2026
0.6.1 Feb 12, 2026
0.6.0 Jan 27, 2026
0.5.7 Nov 25, 2025
0.3.1 Jul 31, 2024

#36 in Operating systems

Download history 1797/week @ 2026-02-20 1639/week @ 2026-02-27 1780/week @ 2026-03-06 1595/week @ 2026-03-13 1305/week @ 2026-03-20 1102/week @ 2026-03-27 2153/week @ 2026-04-03 2328/week @ 2026-04-10 2814/week @ 2026-04-17 2136/week @ 2026-04-24 905/week @ 2026-05-01 2191/week @ 2026-05-08 727/week @ 2026-05-15 1153/week @ 2026-05-22 845/week @ 2026-05-29 1391/week @ 2026-06-05

4,218 downloads per month
Used in 68 crates (3 directly)

GPL-3.0-or-later OR Apache-2…

110KB
2K SLoC

page_table_multiarch

Crates.io Docs.rs CI

This crate provides generic, unified, architecture-independent, and OS-free page table structures for various hardware architectures.

The core structs are PageTable64<M, PTE, H> (for 64-bit) and PageTable32<M, PTE, H> (for 32-bit). OS-functions and architecture-dependent types are provided by generic parameters:

  • M: The architecture-dependent metadata, requires to implement the PagingMetaData trait.
  • PTE: The architecture-dependent page table entry, requires to implement the GenericPTE trait.
  • H: OS-functions such as physical memory allocation, requires to implement the PagingHandler trait.

Currently supported architectures and page table structures:

Examples (x86_64)

use memory_addr::{MemoryAddr, PhysAddr, VirtAddr};
use page_table_multiarch::x86_64::{X64PageTable};
use page_table_multiarch::{MappingFlags, PagingHandler, PageSize};

use core::alloc::Layout;

extern crate alloc;

struct PagingHandlerImpl;

impl PagingHandler for PagingHandlerImpl {
    fn alloc_frame() -> Option<PhysAddr> {
        let layout = Layout::from_size_align(0x1000, 0x1000).unwrap();
        let ptr = unsafe { alloc::alloc::alloc(layout) };
        Some(PhysAddr::from(ptr as usize))
    }

    fn alloc_frames(num_pages: usize, align: usize) -> Option<PhysAddr> {
        let layout = Layout::from_size_align(num_pages * 0x1000, align).unwrap();
        let ptr = unsafe { alloc::alloc::alloc(layout) };
        Some(PhysAddr::from(ptr as usize))
    }

    fn dealloc_frame(paddr: PhysAddr) {
        let layout = Layout::from_size_align(0x1000, 0x1000).unwrap();
        let ptr = paddr.as_usize() as *mut u8;
        unsafe { alloc::alloc::dealloc(ptr, layout) };
    }
    
    fn dealloc_frames(paddr: PhysAddr, num_pages: usize) {
        let layout = Layout::from_size_align(num_pages * 0x1000, 0x1000).unwrap();
        let ptr = paddr.as_usize() as *mut u8;
        unsafe { alloc::alloc::dealloc(ptr, layout) };
    }

    fn phys_to_virt(paddr: PhysAddr) -> VirtAddr {
        VirtAddr::from(paddr.as_usize())
    }
}

let vaddr = VirtAddr::from(0xdead_beef_000);
let paddr = PhysAddr::from(0x2000);
let flags = MappingFlags::READ | MappingFlags::WRITE;
let mut pt = X64PageTable::<PagingHandlerImpl>::try_new().unwrap();

assert!(pt.root_paddr().is_aligned_4k());
assert!(pt.cursor().map(vaddr, paddr, PageSize::Size4K, flags).is_ok());
assert_eq!(pt.query(vaddr), Ok((paddr, flags, PageSize::Size4K)));

Dependencies

~3.5MB
~37K SLoC