diff --git a/src/context/context.rs b/src/context/context.rs index b6db7b5..f5c568e 100644 --- a/src/context/context.rs +++ b/src/context/context.rs @@ -2,10 +2,12 @@ use alloc::sync::Arc; use alloc::boxed::Box; use alloc::vec::Vec; use alloc::collections::VecDeque; +use core::alloc::{GlobalAlloc, Layout}; use core::cmp::Ordering; use core::mem; use spin::Mutex; +use arch::paging::PAGE_SIZE; use context::arch; use context::file::FileDescriptor; use context::memory::{Grant, Memory, SharedMemory, Tls}; @@ -119,6 +121,10 @@ pub struct Context { pub cpu_id: Option, /// Current system call pub syscall: Option<(usize, usize, usize, usize, usize, usize)>, + /// Head buffer to use when system call buffers are not page aligned + pub syscall_head: Box<[u8]>, + /// Tail buffer to use when system call buffers are not page aligned + pub syscall_tail: Box<[u8]>, /// Context is halting parent pub vfork: bool, /// Context is being waited on @@ -161,6 +167,9 @@ pub struct Context { impl Context { pub fn new(id: ContextId) -> Context { + let syscall_head = unsafe { Box::from_raw(::ALLOCATOR.alloc(Layout::from_size_align_unchecked(PAGE_SIZE, PAGE_SIZE)) as *mut [u8; PAGE_SIZE]) }; + let syscall_tail = unsafe { Box::from_raw(::ALLOCATOR.alloc(Layout::from_size_align_unchecked(PAGE_SIZE, PAGE_SIZE)) as *mut [u8; PAGE_SIZE]) }; + Context { id: id, pgid: id, @@ -176,6 +185,8 @@ impl Context { running: false, cpu_id: None, syscall: None, + syscall_head: syscall_head, + syscall_tail: syscall_tail, vfork: false, waitpid: Arc::new(WaitMap::new()), pending: VecDeque::new(), diff --git a/src/context/memory.rs b/src/context/memory.rs index 1fc68b7..f41640b 100644 --- a/src/context/memory.rs +++ b/src/context/memory.rs @@ -68,6 +68,7 @@ impl Grant { pub fn map_inactive(from: VirtualAddress, to: VirtualAddress, size: usize, flags: EntryFlags, new_table: &mut InactivePageTable, temporary_page: &mut TemporaryPage) -> Grant { let mut active_table = unsafe { ActivePageTable::new() }; + //TODO: Do not allocate let mut frames = VecDeque::with_capacity(size/PAGE_SIZE); let start_page = Page::containing_address(from); diff --git a/src/scheme/user.rs b/src/scheme/user.rs index 9b6e6b5..442c765 100644 --- a/src/scheme/user.rs +++ b/src/scheme/user.rs @@ -127,6 +127,7 @@ impl UserInner { i += 1; } + //TODO: Use syscall_head and syscall_tail to avoid leaking data grants.insert(i, Grant::map_inactive( VirtualAddress::new(from_address), VirtualAddress::new(to_address),