Revert "Merge branch 'clone_grant_using_fmap' into 'master'"
This reverts merge request !190
This commit is contained in:
@@ -7,7 +7,7 @@ use crate::scheme::{self, SchemeNamespace, SchemeId};
|
||||
use crate::syscall::error::{Result, Error, EBADF};
|
||||
|
||||
/// A file description
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
#[derive(Debug)]
|
||||
pub struct FileDescription {
|
||||
/// The namespace the file was opened from (used for debugging)
|
||||
pub namespace: SchemeNamespace,
|
||||
|
||||
@@ -290,15 +290,7 @@ pub struct Grant {
|
||||
mapped: bool,
|
||||
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>,
|
||||
}
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct GrantFileRef {
|
||||
pub desc: FileDescriptor,
|
||||
pub offset: usize,
|
||||
// TODO: Can the flags maybe be stored together with the page flags. Should some flags be kept,
|
||||
// and others discarded when re-fmapping on clone?
|
||||
pub flags: MapFlags,
|
||||
pub desc_opt: Option<FileDescriptor>,
|
||||
}
|
||||
|
||||
impl Grant {
|
||||
@@ -371,7 +363,7 @@ impl Grant {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn map_inactive(src: VirtualAddress, dst: VirtualAddress, size: usize, flags: PageFlags<RmmA>, desc_opt: Option<GrantFileRef>, inactive_table: &mut InactivePageTable) -> Grant {
|
||||
pub fn map_inactive(src: VirtualAddress, dst: VirtualAddress, size: usize, flags: PageFlags<RmmA>, desc_opt: Option<FileDescriptor>, inactive_table: &mut InactivePageTable) -> Grant {
|
||||
let active_table = unsafe { ActivePageTable::new(src.kind()) };
|
||||
let mut inactive_mapper = inactive_table.mapper();
|
||||
|
||||
@@ -515,9 +507,10 @@ impl Grant {
|
||||
|
||||
flush_all.flush();
|
||||
|
||||
if let Some(file_ref) = self.desc_opt.take() {
|
||||
if let Some(desc) = self.desc_opt.take() {
|
||||
println!("Grant::unmap: close desc {:?}", desc);
|
||||
//TODO: This imposes a large cost on unmapping, but that cost cannot be avoided without modifying fmap and funmap
|
||||
let _ = file_ref.desc.close();
|
||||
let _ = desc.close();
|
||||
}
|
||||
|
||||
self.mapped = false;
|
||||
@@ -540,9 +533,10 @@ impl Grant {
|
||||
|
||||
ipi(IpiKind::Tlb, IpiTarget::Other);
|
||||
|
||||
if let Some(file_ref) = self.desc_opt.take() {
|
||||
if let Some(desc) = self.desc_opt.take() {
|
||||
println!("Grant::unmap_inactive: close desc {:?}", desc);
|
||||
//TODO: This imposes a large cost on unmapping, but that cost cannot be avoided without modifying fmap and funmap
|
||||
let _ = file_ref.desc.close();
|
||||
let _ = desc.close();
|
||||
}
|
||||
|
||||
self.mapped = false;
|
||||
|
||||
@@ -8,7 +8,7 @@ use spin::{Mutex, RwLock};
|
||||
|
||||
use crate::context::{self, Context};
|
||||
use crate::context::file::FileDescriptor;
|
||||
use crate::context::memory::{DANGLING, page_flags, round_down_pages, Grant, Region, GrantFileRef};
|
||||
use crate::context::memory::{DANGLING, page_flags, round_down_pages, Grant, Region};
|
||||
use crate::event;
|
||||
use crate::paging::{PAGE_SIZE, InactivePageTable, VirtualAddress};
|
||||
use crate::scheme::{AtomicSchemeId, SchemeId};
|
||||
@@ -123,7 +123,7 @@ impl UserInner {
|
||||
).map(|addr| addr.data())
|
||||
}
|
||||
|
||||
fn capture_inner(context_weak: &Weak<RwLock<Context>>, dst_address: usize, address: usize, size: usize, flags: MapFlags, desc_opt: Option<GrantFileRef>)
|
||||
fn capture_inner(context_weak: &Weak<RwLock<Context>>, dst_address: usize, address: usize, size: usize, flags: MapFlags, desc_opt: Option<FileDescriptor>)
|
||||
-> Result<VirtualAddress> {
|
||||
// TODO: More abstractions over grant creation!
|
||||
|
||||
@@ -233,8 +233,7 @@ impl UserInner {
|
||||
if address % PAGE_SIZE > 0 {
|
||||
println!("scheme returned unaligned address, causing extra frame to be allocated");
|
||||
}
|
||||
let file_ref = GrantFileRef { desc, offset: map.offset, flags: map.flags };
|
||||
let res = UserInner::capture_inner(&context_weak, map.address, address, map.size, map.flags, Some(file_ref));
|
||||
let res = UserInner::capture_inner(&context_weak, map.address, address, map.size, map.flags, Some(desc));
|
||||
if let Ok(grant_address) = res {
|
||||
if let Some(context_lock) = context_weak.upgrade() {
|
||||
let context = context_lock.read();
|
||||
|
||||
@@ -489,8 +489,11 @@ pub fn funmap_old(virtual_address: usize) -> Result<usize> {
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(file_ref) = desc_opt {
|
||||
let scheme_id = { file_ref.desc.description.read().scheme };
|
||||
if let Some(desc) = desc_opt {
|
||||
let scheme_id = {
|
||||
let description = desc.description.read();
|
||||
description.scheme
|
||||
};
|
||||
|
||||
let scheme = {
|
||||
let schemes = scheme::schemes();
|
||||
@@ -499,7 +502,7 @@ pub fn funmap_old(virtual_address: usize) -> Result<usize> {
|
||||
};
|
||||
let res = scheme.funmap_old(virtual_address);
|
||||
|
||||
let _ = file_ref.desc.close();
|
||||
let _ = desc.close();
|
||||
|
||||
res
|
||||
} else {
|
||||
@@ -552,8 +555,11 @@ pub fn funmap(virtual_address: usize, length: usize) -> Result<usize> {
|
||||
}
|
||||
}
|
||||
|
||||
for (file_ref, intersection) in notify_files {
|
||||
let scheme_id = { file_ref.desc.description.read().scheme };
|
||||
for (desc, intersection) in notify_files {
|
||||
let scheme_id = {
|
||||
let description = desc.description.read();
|
||||
description.scheme
|
||||
};
|
||||
|
||||
let scheme = {
|
||||
let schemes = scheme::schemes();
|
||||
@@ -562,7 +568,7 @@ pub fn funmap(virtual_address: usize, length: usize) -> Result<usize> {
|
||||
};
|
||||
let res = scheme.funmap(intersection.start_address().data(), intersection.size());
|
||||
|
||||
let _ = file_ref.desc.close();
|
||||
let _ = desc.close();
|
||||
|
||||
res?;
|
||||
}
|
||||
|
||||
@@ -10,9 +10,9 @@ use core::ops::DerefMut;
|
||||
use core::{intrinsics, mem, str};
|
||||
use spin::RwLock;
|
||||
|
||||
use crate::context::file::{FileDescription, FileDescriptor};
|
||||
use crate::context::file::FileDescriptor;
|
||||
use crate::context::{ContextId, WaitpidKey};
|
||||
use crate::context::memory::{Grant, UserGrants, Region};
|
||||
use crate::context::memory::{UserGrants, Region};
|
||||
use crate::context;
|
||||
#[cfg(not(feature="doc"))]
|
||||
use crate::elf::{self, program_header};
|
||||
@@ -267,38 +267,23 @@ pub fn clone(flags: CloneFlags, stack_base: usize) -> Result<ContextId> {
|
||||
// If not cloning virtual memory, use fmap to re-obtain every grant where possible
|
||||
if !flags.contains(CLONE_VM) {
|
||||
let mut grants = grants.write();
|
||||
let old_grants = mem::take(&mut grants.inner);
|
||||
|
||||
// TODO: Find some way to do this without having to allocate.
|
||||
let mut to_remove = BTreeSet::new();
|
||||
|
||||
// TODO: Check that the current process is not allowed to serve any scheme this logic
|
||||
// could interfere with. Deadlocks would otherwise seem inevitable.
|
||||
// TODO: Use drain_filter if possible
|
||||
|
||||
for mut grant in old_grants.into_iter() {
|
||||
let address = grant.start_address().data();
|
||||
let size = grant.size();
|
||||
|
||||
if let Some(ref mut file_ref) = grant.desc_opt {
|
||||
|
||||
let FileDescription { scheme, number, .. } = { *file_ref.desc.description.read() };
|
||||
let scheme_arc = match crate::scheme::schemes().get(scheme) {
|
||||
Some(s) => Arc::clone(s),
|
||||
None => continue,
|
||||
};
|
||||
let map = crate::syscall::data::Map {
|
||||
address,
|
||||
size,
|
||||
offset: file_ref.offset,
|
||||
flags: file_ref.flags,
|
||||
};
|
||||
grant.unmap();
|
||||
match scheme_arc.fmap(number, &map) {
|
||||
Ok(_) => (),
|
||||
Err(_) => continue,
|
||||
};
|
||||
} else {
|
||||
grants.insert(grant);
|
||||
for grant in grants.iter() {
|
||||
let remove = false;
|
||||
if let Some(ref _desc) = grant.desc_opt {
|
||||
println!("todo: clone grant using fmap: {:?}", grant);
|
||||
}
|
||||
if remove {
|
||||
to_remove.insert(Region::from(grant));
|
||||
}
|
||||
}
|
||||
|
||||
for region in to_remove {
|
||||
grants.remove(®ion);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user