Add more getter methods for VmSpace

This commit is contained in:
Chen Chengjun
2024-04-08 13:30:09 +08:00
committed by Tate, Hongliang Tian
parent acf956fa03
commit 233e1fac98
3 changed files with 107 additions and 54 deletions

View File

@ -31,6 +31,7 @@ impl VmSpace {
memory_set: Arc::new(Mutex::new(MemorySet::new())),
}
}
/// Activate the page table, load root physical address to cr3
#[allow(clippy::missing_safety_doc)]
pub unsafe fn activate(&self) {
@ -80,12 +81,26 @@ impl VmSpace {
Ok(base_addr)
}
/// determine whether a vaddr is already mapped
/// Determine whether a `vaddr` is already mapped.
pub fn is_mapped(&self, vaddr: Vaddr) -> bool {
let memory_set = self.memory_set.lock();
memory_set.is_mapped(vaddr)
}
/// Determine whether the target `vaddr` is writable based on the page table.
pub fn is_writable(&self, vaddr: Vaddr) -> bool {
let memory_set = self.memory_set.lock();
let flags = memory_set.flags(vaddr);
flags.is_some_and(|flags| flags.contains(PageTableFlags::WRITABLE))
}
/// Determine whether the target `vaddr` is executable based on the page table.
pub fn is_executable(&self, vaddr: Vaddr) -> bool {
let memory_set = self.memory_set.lock();
let flags = memory_set.flags(vaddr);
flags.is_some_and(|flags| !flags.contains(PageTableFlags::NO_EXECUTE))
}
/// Unmaps the physical memory pages within the VM address range.
///
/// The range is allowed to contain gaps, where no physical memory pages
@ -128,6 +143,16 @@ impl VmSpace {
}
Ok(())
}
/// Deep-copy the current `VmSpace`.
///
/// The generated new `VmSpace` possesses a `MemorySet` independent from the
/// original `VmSpace`, with initial contents identical to the original.
pub fn deep_copy(&self) -> Self {
Self {
memory_set: Arc::new(Mutex::new(self.memory_set.lock().clone())),
}
}
}
impl Default for VmSpace {