mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-10 05:46:48 +00:00
Rename ProcessVmarGuard::get
to unwrap
This commit is contained in:
parent
293f1ff4c9
commit
7e1abc1fbb
@ -122,7 +122,7 @@ impl PosixThreadBuilder {
|
|||||||
Arc::new_cyclic(|weak_task| {
|
Arc::new_cyclic(|weak_task| {
|
||||||
let root_vmar = process
|
let root_vmar = process
|
||||||
.upgrade()
|
.upgrade()
|
||||||
.map(|process| process.lock_root_vmar().get().dup().unwrap());
|
.map(|process| process.lock_root_vmar().unwrap().dup().unwrap());
|
||||||
|
|
||||||
let posix_thread = {
|
let posix_thread = {
|
||||||
let prof_clock = ProfClock::new();
|
let prof_clock = ProfClock::new();
|
||||||
|
@ -385,7 +385,7 @@ impl InitStackReader<'_> {
|
|||||||
let stack_base = self.init_stack_bottom();
|
let stack_base = self.init_stack_bottom();
|
||||||
let page_base_addr = stack_base.align_down(PAGE_SIZE);
|
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 mut cursor = vm_space.cursor(&(page_base_addr..page_base_addr + PAGE_SIZE))?;
|
||||||
let VmItem::Mapped { frame, .. } = cursor.query()? else {
|
let VmItem::Mapped { frame, .. } = cursor.query()? else {
|
||||||
return_errno_with_message!(Errno::EACCES, "Page not accessible");
|
return_errno_with_message!(Errno::EACCES, "Page not accessible");
|
||||||
@ -409,7 +409,7 @@ impl InitStackReader<'_> {
|
|||||||
let mut argv = Vec::with_capacity(argc);
|
let mut argv = Vec::with_capacity(argc);
|
||||||
let page_base_addr = read_offset.align_down(PAGE_SIZE);
|
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 mut cursor = vm_space.cursor(&(page_base_addr..page_base_addr + PAGE_SIZE))?;
|
||||||
let VmItem::Mapped { frame, .. } = cursor.query()? else {
|
let VmItem::Mapped { frame, .. } = cursor.query()? else {
|
||||||
return_errno_with_message!(Errno::EACCES, "Page not accessible");
|
return_errno_with_message!(Errno::EACCES, "Page not accessible");
|
||||||
@ -449,7 +449,7 @@ impl InitStackReader<'_> {
|
|||||||
let mut envp = Vec::new();
|
let mut envp = Vec::new();
|
||||||
let page_base_addr = read_offset.align_down(PAGE_SIZE);
|
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 mut cursor = vm_space.cursor(&(page_base_addr..page_base_addr + PAGE_SIZE))?;
|
||||||
let VmItem::Mapped { frame, .. } = cursor.query()? else {
|
let VmItem::Mapped { frame, .. } = cursor.query()? else {
|
||||||
return_errno_with_message!(Errno::EACCES, "Page not accessible");
|
return_errno_with_message!(Errno::EACCES, "Page not accessible");
|
||||||
|
@ -78,8 +78,12 @@ pub struct ProcessVmarGuard<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ProcessVmarGuard<'_> {
|
impl ProcessVmarGuard<'_> {
|
||||||
/// Gets a reference to the process VMAR.
|
/// Unwraps and returns a reference to the process VMAR.
|
||||||
pub fn get(&self) -> &Vmar<Full> {
|
///
|
||||||
|
/// # 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()
|
self.inner.as_ref().unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,7 +100,7 @@ impl Clone for ProcessVm {
|
|||||||
fn clone(&self) -> Self {
|
fn clone(&self) -> Self {
|
||||||
let root_vmar = self.lock_root_vmar();
|
let root_vmar = self.lock_root_vmar();
|
||||||
Self {
|
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(),
|
init_stack: self.init_stack.clone(),
|
||||||
heap: self.heap.clone(),
|
heap: self.heap.clone(),
|
||||||
}
|
}
|
||||||
@ -122,7 +126,7 @@ impl ProcessVm {
|
|||||||
/// The returned `ProcessVm` will have a forked `Vmar`.
|
/// The returned `ProcessVm` will have a forked `Vmar`.
|
||||||
pub fn fork_from(other: &ProcessVm) -> Result<Self> {
|
pub fn fork_from(other: &ProcessVm) -> Result<Self> {
|
||||||
let process_vmar = other.lock_root_vmar();
|
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 {
|
Ok(Self {
|
||||||
root_vmar,
|
root_vmar,
|
||||||
heap: other.heap.clone(),
|
heap: other.heap.clone(),
|
||||||
@ -156,7 +160,7 @@ impl ProcessVm {
|
|||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let root_vmar: ProcessVmarGuard<'_> = self.lock_root_vmar();
|
let root_vmar: ProcessVmarGuard<'_> = self.lock_root_vmar();
|
||||||
self.init_stack
|
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 {
|
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.
|
/// Clears existing mappings and then maps the heap VMO to the current VMAR.
|
||||||
pub fn clear_and_map(&self) {
|
pub fn clear_and_map(&self) {
|
||||||
let root_vmar = self.lock_root_vmar();
|
let root_vmar = self.lock_root_vmar();
|
||||||
root_vmar.get().clear().unwrap();
|
root_vmar.unwrap().clear().unwrap();
|
||||||
self.heap.alloc_and_map_vm(&root_vmar.get()).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));
|
root_vmar.set_vmar(Some(new_vmar));
|
||||||
drop(guard);
|
drop(guard);
|
||||||
|
|
||||||
process_vm.heap.alloc_and_map_vm(root_vmar.get()).unwrap();
|
process_vm
|
||||||
|
.heap
|
||||||
|
.alloc_and_map_vm(root_vmar.unwrap())
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@ pub fn load_elf_to_vm(
|
|||||||
// the process cannot return to user space again,
|
// the process cannot return to user space again,
|
||||||
// so `Vmar::clear` and `do_exit_group` are called here.
|
// so `Vmar::clear` and `do_exit_group` are called here.
|
||||||
// FIXME: sending a fault signal is an alternative approach.
|
// 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`.
|
// FIXME: `current` macro will be used in `do_exit_group`.
|
||||||
// if the macro is used when creating the init process,
|
// if the macro is used when creating the init process,
|
||||||
@ -116,7 +116,7 @@ fn init_and_map_vmos(
|
|||||||
elf_file: &Dentry,
|
elf_file: &Dentry,
|
||||||
) -> Result<(Vaddr, AuxVec)> {
|
) -> Result<(Vaddr, AuxVec)> {
|
||||||
let process_vmar = process_vm.lock_root_vmar();
|
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.
|
// 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 {
|
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.
|
/// Maps the VDSO VMO to the corresponding virtual memory address.
|
||||||
fn map_vdso_to_vm(process_vm: &ProcessVm) -> Option<Vaddr> {
|
fn map_vdso_to_vm(process_vm: &ProcessVm) -> Option<Vaddr> {
|
||||||
let process_vmar = process_vm.lock_root_vmar();
|
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 vdso_vmo = vdso_vmo()?;
|
||||||
|
|
||||||
let options = root_vmar
|
let options = root_vmar
|
||||||
|
Loading…
x
Reference in New Issue
Block a user