Refactor Grants.

Page alignment is now verified at compile time, for example.
This commit is contained in:
4lDO2
2023-06-20 13:10:31 +02:00
parent d4b5899c53
commit 34b4512dbd
11 changed files with 375 additions and 468 deletions
+12 -10
View File
@@ -1,4 +1,4 @@
use crate::paging::{RmmA, RmmArch, TableKind};
use crate::paging::{RmmA, RmmArch, TableKind, PAGE_SIZE};
//TODO: combine arches into one function (aarch64 one is newest)
@@ -182,12 +182,12 @@ pub unsafe fn debugger(target_id: Option<crate::context::ContextId>) {
let addr_space = addr_space.read();
if ! addr_space.grants.is_empty() {
println!("grants:");
for grant in addr_space.grants.iter() {
let region = grant.region();
for (base, info) in addr_space.grants.iter() {
let size = info.page_count() * PAGE_SIZE;
println!(
" virt 0x{:016x}:0x{:016x} size 0x{:08x} {}",
region.start_address().data(), region.final_address().data(), region.size(),
if grant.is_owned() { "owned" } else { "borrowed" },
base.start_address().data(), base.start_address().data() + size - 1, size,
if info.is_owned() { "owned" } else { "borrowed" },
);
}
}
@@ -228,6 +228,7 @@ pub unsafe fn debugger(target_id: Option<crate::context::ContextId>) {
#[cfg(target_arch = "x86_64")]
pub unsafe fn check_consistency(addr_space: &mut crate::context::memory::AddrSpace) {
use crate::context::memory::PageSpan;
use crate::paging::*;
let p4 = addr_space.table.utable.table();
@@ -261,7 +262,7 @@ pub unsafe fn check_consistency(addr_space: &mut crate::context::memory::AddrSpa
};
let address = VirtualAddress::new((p1i << 12) | (p2i << 21) | (p3i << 30) | (p4i << 39));
let grant = match addr_space.grants.contains(address) {
let (base, grant) = match addr_space.grants.contains(Page::containing_address(address)) {
Some(g) => g,
None => {
log::error!("ADDRESS {:p} LACKING GRANT BUT MAPPED TO {:#0x} FLAGS {:?}!", address.data() as *const u8, physaddr.data(), flags);
@@ -270,19 +271,20 @@ pub unsafe fn check_consistency(addr_space: &mut crate::context::memory::AddrSpa
};
const STICKY: usize = (1 << 5) | (1 << 6); // accessed+dirty
if grant.flags().data() & !STICKY != flags.data() & !STICKY {
log::error!("FLAG MISMATCH: {:?} != {:?}, address {:p} in grant at {:?}", grant.flags(), flags, address.data() as *const u8, grant.region());
log::error!("FLAG MISMATCH: {:?} != {:?}, address {:p} in grant at {:?}", grant.flags(), flags, address.data() as *const u8, PageSpan::new(base, grant.page_count()));
}
}
}
}
}
for grant in addr_space.grants.iter() {
for page in grant.pages() {
for (base, info) in addr_space.grants.iter() {
let span = PageSpan::new(base, info.page_count());
for page in span.pages() {
let _entry = match addr_space.table.utable.translate(page.start_address()) {
Some(e) => e,
None => {
log::error!("GRANT AT {:?} LACKING MAPPING AT PAGE {:p}", grant.region(), page.start_address().data() as *const u8);
log::error!("GRANT AT {:?} LACKING MAPPING AT PAGE {:p}", span, page.start_address().data() as *const u8);
continue;
}
};