Rename ProcessVmarGuard::get to unwrap

This commit is contained in:
Ruihan Li 2025-04-06 15:10:00 +08:00 committed by Tate, Hongliang Tian
parent 293f1ff4c9
commit 7e1abc1fbb
4 changed files with 22 additions and 15 deletions

View File

@ -122,7 +122,7 @@ impl PosixThreadBuilder {
Arc::new_cyclic(|weak_task| {
let root_vmar = process
.upgrade()
.map(|process| process.lock_root_vmar().get().dup().unwrap());
.map(|process| process.lock_root_vmar().unwrap().dup().unwrap());
let posix_thread = {
let prof_clock = ProfClock::new();

View File

@ -385,7 +385,7 @@ impl InitStackReader<'_> {
let stack_base = self.init_stack_bottom();
let page_base_addr = stack_base.align_down(PAGE_SIZE);
let vm_space = self.vmar.get().vm_space();
let vm_space = self.vmar.unwrap().vm_space();
let mut cursor = vm_space.cursor(&(page_base_addr..page_base_addr + PAGE_SIZE))?;
let VmItem::Mapped { frame, .. } = cursor.query()? else {
return_errno_with_message!(Errno::EACCES, "Page not accessible");
@ -409,7 +409,7 @@ impl InitStackReader<'_> {
let mut argv = Vec::with_capacity(argc);
let page_base_addr = read_offset.align_down(PAGE_SIZE);
let vm_space = self.vmar.get().vm_space();
let vm_space = self.vmar.unwrap().vm_space();
let mut cursor = vm_space.cursor(&(page_base_addr..page_base_addr + PAGE_SIZE))?;
let VmItem::Mapped { frame, .. } = cursor.query()? else {
return_errno_with_message!(Errno::EACCES, "Page not accessible");
@ -449,7 +449,7 @@ impl InitStackReader<'_> {
let mut envp = Vec::new();
let page_base_addr = read_offset.align_down(PAGE_SIZE);
let vm_space = self.vmar.get().vm_space();
let vm_space = self.vmar.unwrap().vm_space();
let mut cursor = vm_space.cursor(&(page_base_addr..page_base_addr + PAGE_SIZE))?;
let VmItem::Mapped { frame, .. } = cursor.query()? else {
return_errno_with_message!(Errno::EACCES, "Page not accessible");

View File

@ -78,8 +78,12 @@ pub struct ProcessVmarGuard<'a> {
}
impl ProcessVmarGuard<'_> {
/// Gets a reference to the process VMAR.
pub fn get(&self) -> &Vmar<Full> {
/// Unwraps and returns a reference to the process VMAR.
///
/// # Panics
///
/// This method will panic if the process has exited and its VMAR has been dropped.
pub fn unwrap(&self) -> &Vmar<Full> {
self.inner.as_ref().unwrap()
}
@ -96,7 +100,7 @@ impl Clone for ProcessVm {
fn clone(&self) -> Self {
let root_vmar = self.lock_root_vmar();
Self {
root_vmar: Mutex::new(Some(root_vmar.get().dup().unwrap())),
root_vmar: Mutex::new(Some(root_vmar.unwrap().dup().unwrap())),
init_stack: self.init_stack.clone(),
heap: self.heap.clone(),
}
@ -122,7 +126,7 @@ impl ProcessVm {
/// The returned `ProcessVm` will have a forked `Vmar`.
pub fn fork_from(other: &ProcessVm) -> Result<Self> {
let process_vmar = other.lock_root_vmar();
let root_vmar = Mutex::new(Some(Vmar::<Full>::fork_from(process_vmar.get())?));
let root_vmar = Mutex::new(Some(Vmar::<Full>::fork_from(process_vmar.unwrap())?));
Ok(Self {
root_vmar,
heap: other.heap.clone(),
@ -156,7 +160,7 @@ impl ProcessVm {
) -> Result<()> {
let root_vmar: ProcessVmarGuard<'_> = self.lock_root_vmar();
self.init_stack
.map_and_write(root_vmar.get(), argv, envp, aux_vec)
.map_and_write(root_vmar.unwrap(), argv, envp, aux_vec)
}
pub(super) fn heap(&self) -> &Heap {
@ -166,8 +170,8 @@ impl ProcessVm {
/// Clears existing mappings and then maps the heap VMO to the current VMAR.
pub fn clear_and_map(&self) {
let root_vmar = self.lock_root_vmar();
root_vmar.get().clear().unwrap();
self.heap.alloc_and_map_vm(&root_vmar.get()).unwrap();
root_vmar.unwrap().clear().unwrap();
self.heap.alloc_and_map_vm(&root_vmar.unwrap()).unwrap();
}
}
@ -183,5 +187,8 @@ pub fn renew_vm_and_map(ctx: &Context) {
root_vmar.set_vmar(Some(new_vmar));
drop(guard);
process_vm.heap.alloc_and_map_vm(root_vmar.get()).unwrap();
process_vm
.heap
.alloc_and_map_vm(root_vmar.unwrap())
.unwrap();
}

View File

@ -66,7 +66,7 @@ pub fn load_elf_to_vm(
// the process cannot return to user space again,
// so `Vmar::clear` and `do_exit_group` are called here.
// FIXME: sending a fault signal is an alternative approach.
process_vm.lock_root_vmar().get().clear().unwrap();
process_vm.lock_root_vmar().unwrap().clear().unwrap();
// FIXME: `current` macro will be used in `do_exit_group`.
// if the macro is used when creating the init process,
@ -116,7 +116,7 @@ fn init_and_map_vmos(
elf_file: &Dentry,
) -> Result<(Vaddr, AuxVec)> {
let process_vmar = process_vm.lock_root_vmar();
let root_vmar = process_vmar.get();
let root_vmar = process_vmar.unwrap();
// After we clear process vm, if any error happens, we must call exit_group instead of return to user space.
let ldso_load_info = if let Some((ldso_file, ldso_elf)) = ldso {
@ -409,7 +409,7 @@ pub fn init_aux_vec(elf: &Elf, elf_map_addr: Vaddr, ldso_base: Option<Vaddr>) ->
/// Maps the VDSO VMO to the corresponding virtual memory address.
fn map_vdso_to_vm(process_vm: &ProcessVm) -> Option<Vaddr> {
let process_vmar = process_vm.lock_root_vmar();
let root_vmar = process_vmar.get();
let root_vmar = process_vmar.unwrap();
let vdso_vmo = vdso_vmo()?;
let options = root_vmar