Require mutable context to perform page table modifications

This commit is contained in:
Jeremy Soller
2020-02-10 17:58:44 -07:00
parent 7721a0a4c6
commit b892603501
4 changed files with 12 additions and 12 deletions

View File

@@ -53,7 +53,7 @@ impl Context {
}
}
pub fn get_page_table(&self) -> usize {
pub fn get_page_table(&mut self) -> usize {
self.cr3
}

View File

@@ -421,7 +421,7 @@ pub unsafe fn regs_for_mut(context: &mut Context) -> Option<&mut InterruptStack>
// |_| |_|\___|_| |_| |_|\___/|_| \__, |
// |___/
pub fn with_context_memory<F>(context: &Context, offset: VirtualAddress, len: usize, f: F) -> Result<()>
pub fn with_context_memory<F>(context: &mut Context, offset: VirtualAddress, len: usize, f: F) -> Result<()>
where F: FnOnce(*mut u8) -> Result<()>
{
// As far as I understand, mapping any regions following

View File

@@ -321,9 +321,9 @@ impl Scheme for ProcScheme {
let contexts = context::contexts();
let context = contexts.get(info.pid).ok_or(Error::new(ESRCH))?;
let context = context.read();
let mut context = context.write();
ptrace::with_context_memory(&context, data.offset, buf.len(), |ptr| {
ptrace::with_context_memory(&mut context, data.offset, buf.len(), |ptr| {
buf.copy_from_slice(validate::validate_slice(ptr, buf.len())?);
Ok(())
})?;
@@ -411,9 +411,9 @@ impl Scheme for ProcScheme {
let contexts = context::contexts();
let context = contexts.get(info.pid).ok_or(Error::new(ESRCH))?;
let context = context.read();
let mut context = context.write();
ptrace::with_context_memory(&context, data.offset, buf.len(), |ptr| {
ptrace::with_context_memory(&mut context, data.offset, buf.len(), |ptr| {
validate::validate_slice_mut(ptr, buf.len())?.copy_from_slice(buf);
Ok(())
})?;

View File

@@ -114,13 +114,13 @@ impl UserInner {
Ok(0)
} else {
let context_lock = context_weak.upgrade().ok_or(Error::new(ESRCH))?;
let context = context_lock.read();
let mut grants = context.grants.lock();
let mut context = context_lock.write();
let mut new_table = unsafe { InactivePageTable::from_address(context.arch.get_page_table()) };
let mut temporary_page = TemporaryPage::new(Page::containing_address(VirtualAddress::new(crate::USER_TMP_GRANT_OFFSET)));
let mut grants = context.grants.lock();
let from_address = (address/4096) * 4096;
let offset = address - from_address;
let full_size = ((offset + size + 4095)/4096) * 4096;
@@ -170,13 +170,13 @@ impl UserInner {
Ok(())
} else {
let context_lock = self.context.upgrade().ok_or(Error::new(ESRCH))?;
let context = context_lock.read();
let mut grants = context.grants.lock();
let mut context = context_lock.write();
let mut new_table = unsafe { InactivePageTable::from_address(context.arch.get_page_table()) };
let mut temporary_page = TemporaryPage::new(Page::containing_address(VirtualAddress::new(crate::USER_TMP_GRANT_OFFSET)));
let mut grants = context.grants.lock();
for i in 0 .. grants.len() {
let start = grants[i].start_address().get();
let end = start + grants[i].size();