diff --git a/src/context/memory.rs b/src/context/memory.rs index 6a07d3784e1c917c00aa358c5b3c99c2ca7eb3d0..f21d37e1106495e23b179d2b72db43ace541d1e2 100644 --- a/src/context/memory.rs +++ b/src/context/memory.rs @@ -598,7 +598,6 @@ pub struct Grant { flags: PageFlags<RmmA>, mapped: bool, pub(crate) owned: bool, - pub(crate) allocator_owned: bool, //TODO: This is probably a very heavy way to keep track of fmap'd files, perhaps move to the context? pub desc_opt: Option<GrantFileRef>, } @@ -644,7 +643,6 @@ impl Grant { flags, mapped: true, owned: false, - allocator_owned: false, desc_opt: None, }) } @@ -654,10 +652,10 @@ impl Grant { let flush = unsafe { mapper.map(page.start_address(), flags) }.ok_or(Enomem)?; flusher.consume(flush); } - Ok(Grant { region: Region { start: dst.start_address(), size: page_count * PAGE_SIZE }, flags, mapped: true, owned: true, allocator_owned: true, desc_opt: None }) + Ok(Grant { region: Region { start: dst.start_address(), size: page_count * PAGE_SIZE }, flags, mapped: true, owned: true, desc_opt: None }) } pub fn borrow(src_base: Page, dst_base: Page, page_count: usize, flags: PageFlags<RmmA>, desc_opt: Option<GrantFileRef>, src_mapper: &mut PageMapper, dst_mapper: &mut PageMapper, dst_flusher: impl Flusher<RmmA>) -> Result<Grant, Enomem> { - Self::copy_inner(src_base, dst_base, page_count, flags, desc_opt, src_mapper, dst_mapper, (), dst_flusher, false, false, false) + Self::copy_inner(src_base, dst_base, page_count, flags, desc_opt, src_mapper, dst_mapper, (), dst_flusher, false, false) } pub fn reborrow(src_grant: &Grant, dst_base: Page, src_mapper: &mut PageMapper, dst_mapper: &mut PageMapper, dst_flusher: impl Flusher<RmmA>) -> Result<Grant> { Self::borrow(Page::containing_address(src_grant.start_address()), dst_base, src_grant.size() / PAGE_SIZE, src_grant.flags(), src_grant.desc_opt.clone(), src_mapper, dst_mapper, dst_flusher).map_err(Into::into) @@ -666,7 +664,7 @@ impl Grant { assert!(core::mem::replace(&mut src_grant.mapped, false)); let desc_opt = src_grant.desc_opt.take(); - Self::copy_inner(Page::containing_address(src_grant.start_address()), dst_base, src_grant.size() / PAGE_SIZE, src_grant.flags(), desc_opt, src_mapper, dst_mapper, src_flusher, dst_flusher, src_grant.owned, src_grant.allocator_owned, true).map_err(Into::into) + Self::copy_inner(Page::containing_address(src_grant.start_address()), dst_base, src_grant.size() / PAGE_SIZE, src_grant.flags(), desc_opt, src_mapper, dst_mapper, src_flusher, dst_flusher, src_grant.owned, true).map_err(Into::into) } fn copy_inner( @@ -680,7 +678,6 @@ impl Grant { mut src_flusher: impl Flusher<RmmA>, mut dst_flusher: impl Flusher<RmmA>, owned: bool, - allocator_owned: bool, unmap: bool, ) -> Result<Grant, Enomem> { let mut successful_count = 0; @@ -716,7 +713,7 @@ impl Grant { }; dst_flusher.consume(flush); - if owned && allocator_owned { + if owned { crate::memory::deallocate_frames(Frame::containing_address(frame), 1); } } @@ -731,7 +728,6 @@ impl Grant { flags, mapped: true, owned, - allocator_owned, desc_opt, }) } @@ -763,7 +759,7 @@ impl Grant { let (entry, _, flush) = unsafe { mapper.unmap_phys(page.start_address(), true) } .unwrap_or_else(|| panic!("missing page at {:#0x} for grant {:?}", page.start_address().data(), self)); - if self.owned && self.allocator_owned { + if self.owned { // TODO: make sure this frame can be safely freed, physical use counter. // // Namely, we can either have MAP_PRIVATE or MAP_SHARED-style mappings. The former @@ -811,7 +807,6 @@ impl Grant { flags: self.flags, mapped: self.mapped, owned: self.owned, - allocator_owned: self.allocator_owned, desc_opt: self.desc_opt.clone(), }); let after_grant = self.after(region).map(|region| Grant { @@ -819,7 +814,6 @@ impl Grant { flags: self.flags, mapped: self.mapped, owned: self.owned, - allocator_owned: self.allocator_owned, desc_opt: self.desc_opt.clone(), }); diff --git a/src/syscall/process.rs b/src/syscall/process.rs index 9b5242aa7628fb384110b920e9d06ac2932a92bf..1625b9e1735b9c51ce66896d75b4c74db090c2ae 100644 --- a/src/syscall/process.rs +++ b/src/syscall/process.rs @@ -590,18 +590,16 @@ pub unsafe fn usermode_bootstrap(bootstrap: &Bootstrap) -> ! { let mut addr_space = addr_space.write(); let addr_space = &mut *addr_space; - let mut grant = context::memory::Grant::physmap( + // TODO: Mark as owned and then support reclaiming the memory to the allocator if + // deallocated? + addr_space.grants.insert(context::memory::Grant::physmap( bootstrap.base.clone(), Page::containing_address(VirtualAddress::new(0)), bootstrap.page_count, PageFlags::new().user(true).write(true).execute(true), &mut addr_space.table.utable, PageFlushAll::new(), - ).expect("failed to physmap bootstrap memory"); - grant.allocator_owned = false; - grant.owned = true; - - addr_space.grants.insert(grant); + ).expect("failed to physmap bootstrap memory")); } // Start in a minimal environment without any stack.