Commit 114fc92d authored by Jeremy Soller's avatar Jeremy Soller

Add flags to fmap by using a struct for fmap arguments.

parent f479a668
use super::arch::*;
use super::data::{SigAction, Stat, StatVfs, TimeSpec};
use super::data::{Map, SigAction, Stat, StatVfs, TimeSpec};
use super::error::Result;
use super::number::*;
......@@ -100,8 +100,8 @@ pub fn fexec(fd: usize, args: &[[usize; 2]], vars: &[[usize; 2]]) -> Result<usiz
}
/// Map a file into memory
pub unsafe fn fmap(fd: usize, offset: usize, size: usize) -> Result<usize> {
syscall3(SYS_FMAP, fd, offset, size)
pub unsafe fn fmap(fd: usize, map: &Map) -> Result<usize> {
syscall3(SYS_FMAP, fd, map as *const Map as usize, mem::size_of::<Map>())
}
/// Unmap a memory-mapped file
......
......@@ -26,6 +26,31 @@ impl DerefMut for Event {
}
}
#[derive(Copy, Clone, Debug, Default)]
#[repr(C)]
pub struct Map {
pub offset: usize,
pub size: usize,
pub flags: usize,
}
impl Deref for Map {
type Target = [u8];
fn deref(&self) -> &[u8] {
unsafe {
slice::from_raw_parts(self as *const Map as *const u8, mem::size_of::<Map>()) as &[u8]
}
}
}
impl DerefMut for Map {
fn deref_mut(&mut self) -> &mut [u8] {
unsafe {
slice::from_raw_parts_mut(self as *mut Map as *mut u8, mem::size_of::<Map>()) as &mut [u8]
}
}
}
#[derive(Copy, Clone, Debug, Default)]
#[repr(C)]
pub struct Packet {
......
......@@ -22,8 +22,8 @@ pub const FUTEX_WAIT: usize = 0;
pub const FUTEX_WAKE: usize = 1;
pub const FUTEX_REQUEUE: usize = 2;
pub const MAP_WRITE: usize = 1;
pub const MAP_WRITE_COMBINE: usize = 2;
pub const MAP_SHARED: usize = 0x0001;
pub const MAP_PRIVATE: usize = 0x0002;
pub const MODE_TYPE: u16 = 0xF000;
pub const MODE_DIR: u16 = 0x4000;
......@@ -55,6 +55,14 @@ pub const O_SYMLINK: usize = 0x4000_0000;
pub const O_NOFOLLOW: usize = 0x8000_0000;
pub const O_ACCMODE: usize = O_RDONLY | O_WRONLY | O_RDWR;
pub const PHYSMAP_WRITE: usize = 1;
pub const PHYSMAP_WRITE_COMBINE: usize = 2;
pub const PROT_NONE: usize = 0x0000_0000;
pub const PROT_EXEC: usize = 0x0001_0000;
pub const PROT_WRITE: usize = 0x0002_0000;
pub const PROT_READ: usize = 0x0004_0000;
pub const SEEK_SET: usize = 0;
pub const SEEK_CUR: usize = 1;
pub const SEEK_END: usize = 2;
......
......@@ -32,7 +32,7 @@ pub struct Dma<T> {
impl<T> Dma<T> {
pub fn new(value: T) -> Result<Dma<T>> {
let phys = PhysBox::new(mem::size_of::<T>())?;
let virt = unsafe { ::physmap(phys.address, phys.size, ::MAP_WRITE)? } as *mut T;
let virt = unsafe { ::physmap(phys.address, phys.size, ::PHYSMAP_WRITE)? } as *mut T;
unsafe { ptr::write(virt, value); }
Ok(Dma {
phys: phys,
......@@ -42,7 +42,7 @@ impl<T> Dma<T> {
pub fn zeroed() -> Result<Dma<T>> {
let phys = PhysBox::new(mem::size_of::<T>())?;
let virt = unsafe { ::physmap(phys.address, phys.size, ::MAP_WRITE)? } as *mut T;
let virt = unsafe { ::physmap(phys.address, phys.size, ::PHYSMAP_WRITE)? } as *mut T;
unsafe { ptr::write_bytes(virt as *mut u8, 0, phys.size); }
Ok(Dma {
phys: phys,
......
......@@ -27,7 +27,7 @@ pub const SYS_FCHOWN: usize = SYS_CLASS_FILE | 207;
pub const SYS_FCNTL: usize = SYS_CLASS_FILE | 55;
pub const SYS_FEVENT: usize = SYS_CLASS_FILE | 927;
pub const SYS_FEXEC: usize = SYS_CLASS_FILE | 11;
pub const SYS_FMAP: usize = SYS_CLASS_FILE | 90;
pub const SYS_FMAP: usize = SYS_CLASS_FILE | SYS_ARG_SLICE | 90;
pub const SYS_FUNMAP: usize = SYS_CLASS_FILE | 91;
pub const SYS_FPATH: usize = SYS_CLASS_FILE | SYS_ARG_MSLICE | 928;
pub const SYS_FRENAME: usize = SYS_CLASS_FILE | SYS_ARG_PATH | 38;
......
......@@ -20,7 +20,11 @@ pub trait Scheme {
SYS_FCHOWN => self.fchown(packet.b, packet.c as u32, packet.d as u32),
SYS_FCNTL => self.fcntl(packet.b, packet.c, packet.d),
SYS_FEVENT => self.fevent(packet.b, packet.c),
SYS_FMAP => self.fmap(packet.b, packet.c, packet.d),
SYS_FMAP => if packet.d >= mem::size_of::<Map>() {
self.fmap(packet.b, unsafe { &*(packet.c as *const Map) })
} else {
Err(Error::new(EFAULT))
},
SYS_FPATH => self.fpath(packet.b, unsafe { slice::from_raw_parts_mut(packet.c as *mut u8, packet.d) }),
SYS_FRENAME => self.frename(packet.b, unsafe { slice::from_raw_parts(packet.c as *const u8, packet.d) }, packet.uid, packet.gid),
SYS_FSTAT => if packet.d >= mem::size_of::<Stat>() {
......@@ -111,7 +115,7 @@ pub trait Scheme {
}
#[allow(unused_variables)]
fn fmap(&self, id: usize, offset: usize, size: usize) -> Result<usize> {
fn fmap(&self, id: usize, map: &Map) -> Result<usize> {
Err(Error::new(EBADF))
}
......
......@@ -20,7 +20,11 @@ pub trait SchemeBlock {
SYS_FCHOWN => self.fchown(packet.b, packet.c as u32, packet.d as u32),
SYS_FCNTL => self.fcntl(packet.b, packet.c, packet.d),
SYS_FEVENT => self.fevent(packet.b, packet.c),
SYS_FMAP => self.fmap(packet.b, packet.c, packet.d),
SYS_FMAP => if packet.d >= mem::size_of::<Map>() {
self.fmap(packet.b, unsafe { &*(packet.c as *const Map) })
} else {
Err(Error::new(EFAULT))
},
SYS_FPATH => self.fpath(packet.b, unsafe { slice::from_raw_parts_mut(packet.c as *mut u8, packet.d) }),
SYS_FRENAME => self.frename(packet.b, unsafe { slice::from_raw_parts(packet.c as *const u8, packet.d) }, packet.uid, packet.gid),
SYS_FSTAT => if packet.d >= mem::size_of::<Stat>() {
......@@ -111,7 +115,7 @@ pub trait SchemeBlock {
}
#[allow(unused_variables)]
fn fmap(&self, id: usize, offset: usize, size: usize) -> Result<Option<usize>> {
fn fmap(&self, id: usize, map: &Map) -> Result<Option<usize>> {
Err(Error::new(EBADF))
}
......
......@@ -20,7 +20,11 @@ pub trait SchemeBlockMut {
SYS_FCHOWN => self.fchown(packet.b, packet.c as u32, packet.d as u32),
SYS_FCNTL => self.fcntl(packet.b, packet.c, packet.d),
SYS_FEVENT => self.fevent(packet.b, packet.c),
SYS_FMAP => self.fmap(packet.b, packet.c, packet.d),
SYS_FMAP => if packet.d >= mem::size_of::<Map>() {
self.fmap(packet.b, unsafe { &*(packet.c as *const Map) })
} else {
Err(Error::new(EFAULT))
},
SYS_FPATH => self.fpath(packet.b, unsafe { slice::from_raw_parts_mut(packet.c as *mut u8, packet.d) }),
SYS_FRENAME => self.frename(packet.b, unsafe { slice::from_raw_parts(packet.c as *const u8, packet.d) }, packet.uid, packet.gid),
SYS_FSTAT => if packet.d >= mem::size_of::<Stat>() {
......@@ -111,7 +115,7 @@ pub trait SchemeBlockMut {
}
#[allow(unused_variables)]
fn fmap(&mut self, id: usize, offset: usize, size: usize) -> Result<Option<usize>> {
fn fmap(&mut self, id: usize, map: &Map) -> Result<Option<usize>> {
Err(Error::new(EBADF))
}
......
......@@ -20,7 +20,11 @@ pub trait SchemeMut {
SYS_FCHOWN => self.fchown(packet.b, packet.c as u32, packet.d as u32),
SYS_FCNTL => self.fcntl(packet.b, packet.c, packet.d),
SYS_FEVENT => self.fevent(packet.b, packet.c),
SYS_FMAP => self.fmap(packet.b, packet.c, packet.d),
SYS_FMAP => if packet.d >= mem::size_of::<Map>() {
self.fmap(packet.b, unsafe { &*(packet.c as *const Map) })
} else {
Err(Error::new(EFAULT))
},
SYS_FPATH => self.fpath(packet.b, unsafe { slice::from_raw_parts_mut(packet.c as *mut u8, packet.d) }),
SYS_FRENAME => self.frename(packet.b, unsafe { slice::from_raw_parts(packet.c as *const u8, packet.d) }, packet.uid, packet.gid),
SYS_FSTAT => if packet.d >= mem::size_of::<Stat>() {
......@@ -111,7 +115,7 @@ pub trait SchemeMut {
}
#[allow(unused_variables)]
fn fmap(&mut self, id: usize, offset: usize, size: usize) -> Result<usize> {
fn fmap(&mut self, id: usize, map: &Map) -> Result<usize> {
Err(Error::new(EBADF))
}
......
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