mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-26 19:03:27 +00:00
Remove destroy_all methods
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
16690bc61b
commit
b11628b9ce
@ -78,7 +78,6 @@ pub fn wait_child_exit(
|
|||||||
fn reap_zombie_child(process: &Process, pid: Pid) -> ExitCode {
|
fn reap_zombie_child(process: &Process, pid: Pid) -> ExitCode {
|
||||||
let child_process = process.children().lock().remove(&pid).unwrap();
|
let child_process = process.children().lock().remove(&pid).unwrap();
|
||||||
assert!(child_process.is_zombie());
|
assert!(child_process.is_zombie());
|
||||||
child_process.root_vmar().destroy_all().unwrap();
|
|
||||||
for thread in &*child_process.threads().lock() {
|
for thread in &*child_process.threads().lock() {
|
||||||
thread_table::remove_thread(thread.tid());
|
thread_table::remove_thread(thread.tid());
|
||||||
}
|
}
|
||||||
|
@ -113,14 +113,6 @@ impl Vmar<Rights> {
|
|||||||
self.0.clear_root_vmar()
|
self.0.clear_root_vmar()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Destroy a VMAR, including all its mappings and children VMARs.
|
|
||||||
///
|
|
||||||
/// After being destroyed, the VMAR becomes useless and returns errors
|
|
||||||
/// for most of its methods.
|
|
||||||
pub fn destroy_all(&self) -> Result<()> {
|
|
||||||
self.0.destroy_all()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Destroy all mappings and children VMARs that fall within the specified
|
/// Destroy all mappings and children VMARs that fall within the specified
|
||||||
/// range in bytes.
|
/// range in bytes.
|
||||||
///
|
///
|
||||||
|
@ -101,6 +101,23 @@ pub(super) struct Vmar_ {
|
|||||||
parent: Weak<Vmar_>,
|
parent: Weak<Vmar_>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Drop for Vmar_ {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
if self.is_root_vmar() {
|
||||||
|
self.vm_space.clear();
|
||||||
|
}
|
||||||
|
// Drop the child VMAR.
|
||||||
|
// FIXME: This branch can be removed once removing child VMAR usage from the code base.
|
||||||
|
else {
|
||||||
|
let mut cursor = self
|
||||||
|
.vm_space
|
||||||
|
.cursor_mut(&(self.base..self.base + self.size))
|
||||||
|
.unwrap();
|
||||||
|
cursor.unmap(self.size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
struct VmarInner {
|
struct VmarInner {
|
||||||
/// Whether the vmar is destroyed
|
/// Whether the vmar is destroyed
|
||||||
is_destroyed: bool,
|
is_destroyed: bool,
|
||||||
@ -290,32 +307,6 @@ impl Vmar_ {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn destroy_all(&self) -> Result<()> {
|
|
||||||
let mut inner = self.inner.lock();
|
|
||||||
inner.is_destroyed = true;
|
|
||||||
let mut free_regions = BTreeMap::new();
|
|
||||||
for (child_vmar_base, child_vmar) in &inner.child_vmar_s {
|
|
||||||
child_vmar.destroy_all()?;
|
|
||||||
let free_region = FreeRegion::new(child_vmar.range());
|
|
||||||
free_regions.insert(free_region.start(), free_region);
|
|
||||||
}
|
|
||||||
inner.child_vmar_s.clear();
|
|
||||||
inner.free_regions.append(&mut free_regions);
|
|
||||||
|
|
||||||
for vm_mapping in inner.vm_mappings.values() {
|
|
||||||
vm_mapping.unmap(&vm_mapping.range(), true)?;
|
|
||||||
let free_region = FreeRegion::new(vm_mapping.range());
|
|
||||||
free_regions.insert(free_region.start(), free_region);
|
|
||||||
}
|
|
||||||
inner.vm_mappings.clear();
|
|
||||||
inner.free_regions.append(&mut free_regions);
|
|
||||||
|
|
||||||
drop(inner);
|
|
||||||
self.merge_continuous_regions();
|
|
||||||
self.vm_space.clear();
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn destroy(&self, range: Range<usize>) -> Result<()> {
|
pub fn destroy(&self, range: Range<usize>) -> Result<()> {
|
||||||
self.check_destroy_range(&range)?;
|
self.check_destroy_range(&range)?;
|
||||||
let mut inner = self.inner.lock();
|
let mut inner = self.inner.lock();
|
||||||
@ -324,7 +315,6 @@ impl Vmar_ {
|
|||||||
for child_vmar_ in inner.child_vmar_s.find(&range) {
|
for child_vmar_ in inner.child_vmar_s.find(&range) {
|
||||||
let child_vmar_range = child_vmar_.range();
|
let child_vmar_range = child_vmar_.range();
|
||||||
debug_assert!(is_intersected(&child_vmar_range, &range));
|
debug_assert!(is_intersected(&child_vmar_range, &range));
|
||||||
child_vmar_.destroy_all()?;
|
|
||||||
let free_region = FreeRegion::new(child_vmar_range);
|
let free_region = FreeRegion::new(child_vmar_range);
|
||||||
free_regions.insert(free_region.start(), free_region);
|
free_regions.insert(free_region.start(), free_region);
|
||||||
}
|
}
|
||||||
|
@ -120,14 +120,6 @@ impl<R: TRights> Vmar<TRightSet<R>> {
|
|||||||
self.0.clear_root_vmar()
|
self.0.clear_root_vmar()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Destroy a VMAR, including all its mappings and children VMARs.
|
|
||||||
///
|
|
||||||
/// After being destroyed, the VMAR becomes useless and returns errors
|
|
||||||
/// for most of its methods.
|
|
||||||
pub fn destroy_all(&self) -> Result<()> {
|
|
||||||
self.0.destroy_all()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Destroy all mappings and children VMARs that fall within the specified
|
/// Destroy all mappings and children VMARs that fall within the specified
|
||||||
/// range in bytes.
|
/// range in bytes.
|
||||||
///
|
///
|
||||||
|
Reference in New Issue
Block a user