Commit 30f1265c authored by Jeremy Soller's avatar Jeremy Soller

Add pages to use for head and tail of buffers in userscheme

parent 257e4a6e
...@@ -2,10 +2,12 @@ use alloc::sync::Arc; ...@@ -2,10 +2,12 @@ use alloc::sync::Arc;
use alloc::boxed::Box; use alloc::boxed::Box;
use alloc::vec::Vec; use alloc::vec::Vec;
use alloc::collections::VecDeque; use alloc::collections::VecDeque;
use core::alloc::{GlobalAlloc, Layout};
use core::cmp::Ordering; use core::cmp::Ordering;
use core::mem; use core::mem;
use spin::Mutex; use spin::Mutex;
use arch::paging::PAGE_SIZE;
use context::arch; use context::arch;
use context::file::FileDescriptor; use context::file::FileDescriptor;
use context::memory::{Grant, Memory, SharedMemory, Tls}; use context::memory::{Grant, Memory, SharedMemory, Tls};
...@@ -119,6 +121,10 @@ pub struct Context { ...@@ -119,6 +121,10 @@ pub struct Context {
pub cpu_id: Option<usize>, pub cpu_id: Option<usize>,
/// Current system call /// Current system call
pub syscall: Option<(usize, usize, usize, usize, usize, usize)>, 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 /// Context is halting parent
pub vfork: bool, pub vfork: bool,
/// Context is being waited on /// Context is being waited on
...@@ -161,6 +167,9 @@ pub struct Context { ...@@ -161,6 +167,9 @@ pub struct Context {
impl Context { impl Context {
pub fn new(id: ContextId) -> 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 { Context {
id: id, id: id,
pgid: id, pgid: id,
...@@ -176,6 +185,8 @@ impl Context { ...@@ -176,6 +185,8 @@ impl Context {
running: false, running: false,
cpu_id: None, cpu_id: None,
syscall: None, syscall: None,
syscall_head: syscall_head,
syscall_tail: syscall_tail,
vfork: false, vfork: false,
waitpid: Arc::new(WaitMap::new()), waitpid: Arc::new(WaitMap::new()),
pending: VecDeque::new(), pending: VecDeque::new(),
......
...@@ -68,6 +68,7 @@ impl Grant { ...@@ -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 { 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() }; let mut active_table = unsafe { ActivePageTable::new() };
//TODO: Do not allocate
let mut frames = VecDeque::with_capacity(size/PAGE_SIZE); let mut frames = VecDeque::with_capacity(size/PAGE_SIZE);
let start_page = Page::containing_address(from); let start_page = Page::containing_address(from);
......
...@@ -127,6 +127,7 @@ impl UserInner { ...@@ -127,6 +127,7 @@ impl UserInner {
i += 1; i += 1;
} }
//TODO: Use syscall_head and syscall_tail to avoid leaking data
grants.insert(i, Grant::map_inactive( grants.insert(i, Grant::map_inactive(
VirtualAddress::new(from_address), VirtualAddress::new(from_address),
VirtualAddress::new(to_address), VirtualAddress::new(to_address),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment