#page-table #mmu

nightly no-std page-table-generic

A library for general page table operations

15 releases (5 breaking)

new 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

#114 in No standard library

Download history 118/week @ 2024-10-26 33/week @ 2024-11-02 587/week @ 2024-11-09 74/week @ 2024-11-16 21/week @ 2024-11-23 39/week @ 2024-11-30 338/week @ 2024-12-07 68/week @ 2024-12-14 22/week @ 2024-12-21 6/week @ 2024-12-28 27/week @ 2025-01-04 63/week @ 2025-01-11 383/week @ 2025-01-18

488 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
~20K SLoC