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
488 downloads per month
Used in 5 crates
(2 directly)
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