#page-table #mmu

nightly no-std page-table-generic

A library for general page table operations

15 releases (5 breaking)

0.5.2 Jan 23, 2025
0.5.1 Jan 23, 2025
0.4.0 Jan 23, 2025
0.3.0 Dec 12, 2024
0.0.1 Oct 30, 2024

#113 in No standard library

Download history 142/week @ 2024-10-30 206/week @ 2024-11-06 450/week @ 2024-11-13 26/week @ 2024-11-20 31/week @ 2024-11-27 162/week @ 2024-12-04 248/week @ 2024-12-11 18/week @ 2024-12-18 22/week @ 2024-12-25 1/week @ 2025-01-01 64/week @ 2025-01-08 71/week @ 2025-01-15 466/week @ 2025-01-22

602 downloads per month
Used in 5 crates (2 directly)

MIT license

27KB
685 lines

通用页表操作库

使用示例

实现接口

use page_table_generic::*;

//  实现页表操作接口
#[derive(Clone, Copy)]
struct PteImpl;

impl PTEArch for PteImpl {
    fn page_size() -> usize {
        // 4k
        4096
    }

    fn new_pte(config: PTEGeneric) -> usize {
        todo!()
    }

    fn read_pte(pte: usize) -> PTEGeneric {
        todo!()
    }

    fn level() -> usize {
        // 4级页表
        4
    }
}

// 实现内存操作接口
struct AccessImpl;

impl Access for AccessImpl {
    fn va_offset(&self) -> usize {
        0
    }

    unsafe fn alloc(&mut self, layout: Layout) -> Option<NonNull<u8>> {
        todo!()
    }

    unsafe fn dealloc(&mut self, mut ptr: NonNull<u8>, layout: Layout) {
        todo!()
    }
}

// 使用
let mut access = AccessImpl;

let mut pg = PageTableRef::<PteImpl>::create_empty(&mut access).unwrap();
unsafe {
    pg.map_region(
        MapConfig::new(
            0xffffff0000000000usize as _,
            0x0000,
            AccessSetting::Read | AccessSetting::Write,
            CacheSetting::Device,
        )
        .set_user_access(AccessSetting::Read),
        0x2000,
        false,
        &mut access,
    )
    .unwrap();
}
for i in pg.iter_all(&access) {
    println!("l: {:x}, va: {:#p} c: {:?}", i.level, i.vaddr, i.pte);
}
pg.release(&mut access);

Dependencies

~0.4–0.9MB
~21K SLoC