mirror of
https://github.com/rdmsr/zag.git
synced 2026-10-27 13:58:20 +00:00
feat(mm): add query
This commit is contained in:
@@ -112,4 +112,9 @@ pub const PMap = struct {
|
||||
pub fn activate(self: *Self) void {
|
||||
self.impl.activate();
|
||||
}
|
||||
|
||||
/// Given a virtual page, return its physical page, if present.
|
||||
pub fn query(self: *Self, va: r.VAddr) ?r.PAddr {
|
||||
return self.impl.query(va);
|
||||
}
|
||||
};
|
||||
|
||||
+20
-1
@@ -90,6 +90,25 @@ pub fn RadixPmap(comptime Impl: type) type {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn query(self: *Self, va: r.VAddr) ?r.PAddr {
|
||||
var c = self.cursor(va);
|
||||
|
||||
var level: usize = num_levels - 1;
|
||||
while (true) {
|
||||
const idx = index_for_level(va, level);
|
||||
const pte = c.tables[level][idx];
|
||||
|
||||
if (!pte.present) return null;
|
||||
|
||||
if (level == 0 or leaf_level_enabled(level)) {
|
||||
return pte.address() + (va & (page_size(level) - 1));
|
||||
}
|
||||
|
||||
if (!c.walk_down_resolve(level - 1)) return null;
|
||||
level -= 1;
|
||||
}
|
||||
}
|
||||
|
||||
/// Ensure all intermediate page tables down to `target_level` exist for
|
||||
/// the given virtual address range, allocating them as needed. Useful for
|
||||
/// pre-populating a shared region (e.g. the kernel half of a user pmap)
|
||||
@@ -148,7 +167,7 @@ pub fn RadixPmap(comptime Impl: type) type {
|
||||
}
|
||||
}
|
||||
|
||||
fn walk_down_resolve(self: *Cursor, target_level: usize) bool {
|
||||
pub fn walk_down_resolve(self: *Cursor, target_level: usize) bool {
|
||||
self.walk_down(target_level, false) catch return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@ pub var kernel_heap_base: usize = 0;
|
||||
pub var pfndb_base: usize = 0;
|
||||
pub const hhdm_minimum_max_address: usize = 0;
|
||||
|
||||
var page_table: std.AutoHashMap(usize, usize) = .init(std.heap.page_allocator);
|
||||
|
||||
pub fn init_kernel() void {
|
||||
kernel_heap_base = linux.mmap(
|
||||
null,
|
||||
@@ -62,9 +64,17 @@ pub const PMap = struct {
|
||||
@bitCast(item.pa),
|
||||
);
|
||||
|
||||
page_table.put(va & ~@as(usize, 0xFFF), item.pa) catch unreachable;
|
||||
|
||||
remain -|= item.len;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn query(_: *Self, va: r.VAddr) ?r.PAddr {
|
||||
const page = va & ~@as(usize, 0xFFF);
|
||||
const pa = page_table.get(page) orelse return null;
|
||||
return pa;
|
||||
}
|
||||
|
||||
pub fn activate(_: *Self) void {}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user