Remove resource_sceme, Fix syscall crate name, add fmap
This commit is contained in:
parent
db4acfbe8c
commit
e3317f05f7
|
@ -10,7 +10,7 @@ crate-type = ["staticlib"]
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bitflags = "*"
|
bitflags = "*"
|
||||||
spin = "*"
|
spin = "*"
|
||||||
syscall = { path = "syscall/" }
|
redox_syscall = { path = "syscall/" }
|
||||||
|
|
||||||
[dependencies.goblin]
|
[dependencies.goblin]
|
||||||
git = "https://github.com/m4b/goblin.git"
|
git = "https://github.com/m4b/goblin.git"
|
||||||
|
|
|
@ -7,7 +7,7 @@ bitflags = "*"
|
||||||
hole_list_allocator = { path = "../../crates/hole_list_allocator/" }
|
hole_list_allocator = { path = "../../crates/hole_list_allocator/" }
|
||||||
io = { path = "../../crates/io/" }
|
io = { path = "../../crates/io/" }
|
||||||
spin = "*"
|
spin = "*"
|
||||||
syscall = { path = "../../syscall/" }
|
redox_syscall = { path = "../../syscall/" }
|
||||||
|
|
||||||
[dependencies.x86]
|
[dependencies.x86]
|
||||||
version = "0.7"
|
version = "0.7"
|
||||||
|
|
|
@ -3,4 +3,4 @@ name = "dma"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
syscall = { path = "../../syscall/" }
|
redox_syscall = { path = "../../syscall/" }
|
||||||
|
|
|
@ -2,5 +2,5 @@
|
||||||
name = "event"
|
name = "event"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
|
||||||
[dependencies.syscall]
|
[dependencies]
|
||||||
path = "../../syscall/"
|
redox_syscall = { path = "../../syscall/" }
|
||||||
|
|
|
@ -1,6 +0,0 @@
|
||||||
[package]
|
|
||||||
name = "resource_scheme"
|
|
||||||
version = "0.1.0"
|
|
||||||
|
|
||||||
[dependencies.syscall]
|
|
||||||
path = "../../syscall/"
|
|
|
@ -1,7 +0,0 @@
|
||||||
extern crate syscall;
|
|
||||||
|
|
||||||
pub use resource::Resource;
|
|
||||||
pub use scheme::ResourceScheme;
|
|
||||||
|
|
||||||
mod resource;
|
|
||||||
mod scheme;
|
|
|
@ -1,52 +0,0 @@
|
||||||
use syscall::data::Stat;
|
|
||||||
use syscall::error::*;
|
|
||||||
|
|
||||||
pub trait Resource {
|
|
||||||
/// Duplicate the resource
|
|
||||||
/// Returns `EPERM` if the operation is not supported.
|
|
||||||
fn dup(&self, _buf: &[u8]) -> Result<Box<Self>> {
|
|
||||||
Err(Error::new(EPERM))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Return the path of this resource
|
|
||||||
/// Returns `EPERM` if the operation is not supported.
|
|
||||||
fn path(&self, _buf: &mut [u8]) -> Result<usize> {
|
|
||||||
Err(Error::new(EPERM))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Read data to buffer
|
|
||||||
/// Returns `EPERM` if the operation is not supported.
|
|
||||||
fn read(&mut self, _buf: &mut [u8]) -> Result<usize> {
|
|
||||||
Err(Error::new(EPERM))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Write to resource
|
|
||||||
/// Returns `EPERM` if the operation is not supported.
|
|
||||||
fn write(&mut self, _buf: &[u8]) -> Result<usize> {
|
|
||||||
Err(Error::new(EPERM))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Seek to the given offset
|
|
||||||
/// Returns `ESPIPE` if the operation is not supported.
|
|
||||||
fn seek(&mut self, _pos: usize, _whence: usize) -> Result<usize> {
|
|
||||||
Err(Error::new(ESPIPE))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get informations about the resource, such as mode and size
|
|
||||||
/// Returns `EPERM` if the operation is not supported.
|
|
||||||
fn stat(&self, _stat: &mut Stat) -> Result<usize> {
|
|
||||||
Err(Error::new(EPERM))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sync all buffers
|
|
||||||
/// Returns `EPERM` if the operation is not supported.
|
|
||||||
fn sync(&mut self) -> Result<usize> {
|
|
||||||
Err(Error::new(EPERM))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Truncate to the given length
|
|
||||||
/// Returns `EPERM` if the operation is not supported.
|
|
||||||
fn truncate(&mut self, _len: usize) -> Result<usize> {
|
|
||||||
Err(Error::new(EPERM))
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,109 +0,0 @@
|
||||||
use std::slice;
|
|
||||||
|
|
||||||
use syscall::data::{Packet, Stat};
|
|
||||||
use syscall::error::*;
|
|
||||||
use syscall::number::*;
|
|
||||||
|
|
||||||
use super::Resource;
|
|
||||||
|
|
||||||
pub trait ResourceScheme<T: Resource> {
|
|
||||||
fn open_resource(&self, path: &[u8], flags: usize, uid: u32, gid: u32) -> Result<Box<T>>;
|
|
||||||
|
|
||||||
fn handle(&self, packet: &mut Packet) {
|
|
||||||
packet.a = Error::mux(match packet.a {
|
|
||||||
SYS_OPEN => self.open(unsafe { slice::from_raw_parts(packet.b as *const u8, packet.c) }, packet.d, packet.uid, packet.gid),
|
|
||||||
SYS_MKDIR => self.mkdir(unsafe { slice::from_raw_parts(packet.b as *const u8, packet.c) }, packet.d as u16, packet.uid, packet.gid),
|
|
||||||
SYS_RMDIR => self.rmdir(unsafe { slice::from_raw_parts(packet.b as *const u8, packet.c) }, packet.uid, packet.gid),
|
|
||||||
SYS_UNLINK => self.unlink(unsafe { slice::from_raw_parts(packet.b as *const u8, packet.c) }, packet.uid, packet.gid),
|
|
||||||
|
|
||||||
SYS_DUP => self.dup(packet.b, unsafe { slice::from_raw_parts(packet.c as *const u8, packet.d) }),
|
|
||||||
SYS_READ => self.read(packet.b, unsafe { slice::from_raw_parts_mut(packet.c as *mut u8, packet.d) }),
|
|
||||||
SYS_WRITE => self.write(packet.b, unsafe { slice::from_raw_parts(packet.c as *const u8, packet.d) }),
|
|
||||||
SYS_LSEEK => self.seek(packet.b, packet.c, packet.d),
|
|
||||||
SYS_FEVENT => self.fevent(packet.b, packet.c),
|
|
||||||
SYS_FPATH => self.fpath(packet.b, unsafe { slice::from_raw_parts_mut(packet.c as *mut u8, packet.d) }),
|
|
||||||
SYS_FSTAT => self.fstat(packet.b, unsafe { &mut *(packet.c as *mut Stat) }),
|
|
||||||
SYS_FSYNC => self.fsync(packet.b),
|
|
||||||
SYS_FTRUNCATE => self.ftruncate(packet.b, packet.c),
|
|
||||||
SYS_CLOSE => self.close(packet.b),
|
|
||||||
|
|
||||||
_ => Err(Error::new(ENOSYS))
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Scheme operations */
|
|
||||||
fn open(&self, path: &[u8], flags: usize, uid: u32, gid: u32) -> Result<usize> {
|
|
||||||
let resource = self.open_resource(path, flags, uid, gid)?;
|
|
||||||
let resource_ptr = Box::into_raw(resource);
|
|
||||||
Ok(resource_ptr as usize)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(unused_variables)]
|
|
||||||
fn mkdir(&self, path: &[u8], mode: u16, uid: u32, gid: u32) -> Result<usize> {
|
|
||||||
Err(Error::new(ENOENT))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(unused_variables)]
|
|
||||||
fn rmdir(&self, path: &[u8], uid: u32, gid: u32) -> Result<usize> {
|
|
||||||
Err(Error::new(ENOENT))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(unused_variables)]
|
|
||||||
fn unlink(&self, path: &[u8], uid: u32, gid: u32) -> Result<usize> {
|
|
||||||
Err(Error::new(ENOENT))
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Resource operations */
|
|
||||||
fn dup(&self, old_id: usize, buf: &[u8]) -> Result<usize> {
|
|
||||||
let old = unsafe { &*(old_id as *const T) };
|
|
||||||
let resource = old.dup(buf)?;
|
|
||||||
let resource_ptr = Box::into_raw(resource);
|
|
||||||
Ok(resource_ptr as usize)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn read(&self, id: usize, buf: &mut [u8]) -> Result<usize> {
|
|
||||||
let mut resource = unsafe { &mut *(id as *mut T) };
|
|
||||||
resource.read(buf)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn write(&self, id: usize, buf: &[u8]) -> Result<usize> {
|
|
||||||
let mut resource = unsafe { &mut *(id as *mut T) };
|
|
||||||
resource.write(buf)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn seek(&self, id: usize, pos: usize, whence: usize) -> Result<usize> {
|
|
||||||
let mut resource = unsafe { &mut *(id as *mut T) };
|
|
||||||
resource.seek(pos, whence)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(unused_variables)]
|
|
||||||
fn fevent(&self, id: usize, flags: usize) -> Result<usize> {
|
|
||||||
Err(Error::new(EBADF))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn fpath(&self, id: usize, buf: &mut [u8]) -> Result<usize> {
|
|
||||||
let resource = unsafe { &*(id as *const T) };
|
|
||||||
resource.path(buf)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn fstat(&self, id: usize, stat: &mut Stat) -> Result<usize> {
|
|
||||||
let resource = unsafe { &*(id as *const T) };
|
|
||||||
resource.stat(stat)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn fsync(&self, id: usize) -> Result<usize> {
|
|
||||||
let mut resource = unsafe { &mut *(id as *mut T) };
|
|
||||||
resource.sync()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn ftruncate(&self, id: usize, len: usize) -> Result<usize> {
|
|
||||||
let mut resource = unsafe { &mut *(id as *mut T) };
|
|
||||||
resource.truncate(len)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn close(&self, id: usize) -> Result<usize> {
|
|
||||||
let resource = unsafe { Box::from_raw(id as *mut T) };
|
|
||||||
drop(resource);
|
|
||||||
Ok(0)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -7,4 +7,4 @@ bitflags = "*"
|
||||||
dma = { path = "../../crates/dma/" }
|
dma = { path = "../../crates/dma/" }
|
||||||
io = { path = "../../crates/io/" }
|
io = { path = "../../crates/io/" }
|
||||||
spin = "*"
|
spin = "*"
|
||||||
syscall = { path = "../../syscall/" }
|
redox_syscall = { path = "../../syscall/" }
|
||||||
|
|
|
@ -8,4 +8,4 @@ dma = { path = "../../crates/dma/" }
|
||||||
event = { path = "../../crates/event/" }
|
event = { path = "../../crates/event/" }
|
||||||
io = { path = "../../crates/io/" }
|
io = { path = "../../crates/io/" }
|
||||||
netutils = { path = "../../programs/netutils/" }
|
netutils = { path = "../../programs/netutils/" }
|
||||||
syscall = { path = "../../syscall/" }
|
redox_syscall = { path = "../../syscall/" }
|
||||||
|
|
|
@ -3,11 +3,9 @@ name = "pcid"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
redox_syscall = { path = "../../syscall/" }
|
||||||
rustc-serialize = { git = "https://github.com/redox-os/rustc-serialize.git" }
|
rustc-serialize = { git = "https://github.com/redox-os/rustc-serialize.git" }
|
||||||
toml = "*"
|
toml = "*"
|
||||||
|
|
||||||
[dependencies.syscall]
|
|
||||||
path = "../../syscall/"
|
|
||||||
|
|
||||||
[replace]
|
[replace]
|
||||||
"rustc-serialize:0.3.19" = { git = "https://github.com/redox-os/rustc-serialize.git" }
|
"rustc-serialize:0.3.19" = { git = "https://github.com/redox-os/rustc-serialize.git" }
|
||||||
|
|
|
@ -7,4 +7,4 @@ bitflags = "*"
|
||||||
event = { path = "../../crates/event/" }
|
event = { path = "../../crates/event/" }
|
||||||
io = { path = "../../crates/io/" }
|
io = { path = "../../crates/io/" }
|
||||||
orbclient = "0.1"
|
orbclient = "0.1"
|
||||||
syscall = { path = "../../syscall/" }
|
redox_syscall = { path = "../../syscall/" }
|
||||||
|
|
|
@ -8,4 +8,4 @@ dma = { path = "../../crates/dma/" }
|
||||||
event = { path = "../../crates/event/" }
|
event = { path = "../../crates/event/" }
|
||||||
io = { path = "../../crates/io/" }
|
io = { path = "../../crates/io/" }
|
||||||
netutils = { path = "../../programs/netutils/" }
|
netutils = { path = "../../programs/netutils/" }
|
||||||
syscall = { path = "../../syscall/" }
|
redox_syscall = { path = "../../syscall/" }
|
||||||
|
|
|
@ -4,9 +4,9 @@ version = "0.1.0"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
orbclient = "0.1"
|
orbclient = "0.1"
|
||||||
ransid = { git = "https://github.com/redox-os/ransid.git" }
|
ransid = "0.2"
|
||||||
rusttype = { git = "https://github.com/dylanede/rusttype.git", optional = true }
|
rusttype = { git = "https://github.com/dylanede/rusttype.git", optional = true }
|
||||||
syscall = { path = "../../syscall/" }
|
redox_syscall = "0.1"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = []
|
default = []
|
||||||
|
|
|
@ -72,6 +72,14 @@ impl SchemeMut for DisplayScheme {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn fmap(&mut self, id: usize, offset: usize, size: usize) -> Result<usize> {
|
||||||
|
if let Some(screen) = self.screens.get(&id) {
|
||||||
|
screen.map(offset, size)
|
||||||
|
} else {
|
||||||
|
Err(Error::new(EBADF))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn fpath(&mut self, id: usize, buf: &mut [u8]) -> Result<usize> {
|
fn fpath(&mut self, id: usize, buf: &mut [u8]) -> Result<usize> {
|
||||||
let path_str = if id == 0 {
|
let path_str = if id == 0 {
|
||||||
format!("display:input")
|
format!("display:input")
|
||||||
|
|
|
@ -45,6 +45,14 @@ impl Screen for GraphicScreen {
|
||||||
Ok(0)
|
Ok(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn map(&self, offset: usize, size: usize) -> Result<usize> {
|
||||||
|
if offset + size <= self.display.offscreen.len() * 4 {
|
||||||
|
Ok(self.display.offscreen.as_ptr() as usize + offset)
|
||||||
|
} else {
|
||||||
|
Err(Error::new(EINVAL))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn input(&mut self, event: &Event) {
|
fn input(&mut self, event: &Event) {
|
||||||
if let EventOption::Mouse(mut mouse_event) = event.to_option() {
|
if let EventOption::Mouse(mut mouse_event) = event.to_option() {
|
||||||
let x = cmp::max(0, cmp::min(self.display.width as i32, self.mouse_x + mouse_event.x));
|
let x = cmp::max(0, cmp::min(self.display.width as i32, self.mouse_x + mouse_event.x));
|
||||||
|
|
|
@ -14,6 +14,8 @@ pub trait Screen {
|
||||||
|
|
||||||
fn event(&mut self, flags: usize) -> Result<usize>;
|
fn event(&mut self, flags: usize) -> Result<usize>;
|
||||||
|
|
||||||
|
fn map(&self, offset: usize, size: usize) -> Result<usize>;
|
||||||
|
|
||||||
fn input(&mut self, event: &Event);
|
fn input(&mut self, event: &Event);
|
||||||
|
|
||||||
fn read(&mut self, buf: &mut [u8]) -> Result<usize>;
|
fn read(&mut self, buf: &mut [u8]) -> Result<usize>;
|
||||||
|
|
|
@ -3,7 +3,7 @@ extern crate ransid;
|
||||||
use std::collections::{BTreeSet, VecDeque};
|
use std::collections::{BTreeSet, VecDeque};
|
||||||
|
|
||||||
use orbclient::{Event, EventOption};
|
use orbclient::{Event, EventOption};
|
||||||
use syscall::Result;
|
use syscall::error::*;
|
||||||
|
|
||||||
use display::Display;
|
use display::Display;
|
||||||
use screen::Screen;
|
use screen::Screen;
|
||||||
|
@ -48,6 +48,10 @@ impl Screen for TextScreen {
|
||||||
Ok(0)
|
Ok(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn map(&self, offset: usize, size: usize) -> Result<usize> {
|
||||||
|
Err(Error::new(EBADF))
|
||||||
|
}
|
||||||
|
|
||||||
fn input(&mut self, event: &Event) {
|
fn input(&mut self, event: &Event) {
|
||||||
let mut buf = vec![];
|
let mut buf = vec![];
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
use alloc::arc::Weak;
|
use alloc::arc::{Arc, Weak};
|
||||||
|
use collections::BTreeMap;
|
||||||
use core::sync::atomic::{AtomicUsize, AtomicU64, Ordering};
|
use core::sync::atomic::{AtomicUsize, AtomicU64, Ordering};
|
||||||
use core::{mem, slice, usize};
|
use core::{mem, slice, usize};
|
||||||
use spin::RwLock;
|
use spin::{Mutex, RwLock};
|
||||||
|
|
||||||
use arch;
|
use arch;
|
||||||
use arch::paging::{InactivePageTable, Page, VirtualAddress, entry};
|
use arch::paging::{InactivePageTable, Page, VirtualAddress, entry};
|
||||||
|
@ -23,6 +24,7 @@ pub struct UserInner {
|
||||||
next_id: AtomicU64,
|
next_id: AtomicU64,
|
||||||
context: Weak<RwLock<Context>>,
|
context: Weak<RwLock<Context>>,
|
||||||
todo: WaitQueue<Packet>,
|
todo: WaitQueue<Packet>,
|
||||||
|
fmap: Mutex<BTreeMap<u64, (Weak<RwLock<Context>>, usize)>>,
|
||||||
done: WaitMap<u64, usize>
|
done: WaitMap<u64, usize>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,6 +37,7 @@ impl UserInner {
|
||||||
next_id: AtomicU64::new(1),
|
next_id: AtomicU64::new(1),
|
||||||
context: context,
|
context: context,
|
||||||
todo: WaitQueue::new(),
|
todo: WaitQueue::new(),
|
||||||
|
fmap: Mutex::new(BTreeMap::new()),
|
||||||
done: WaitMap::new()
|
done: WaitMap::new()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -47,10 +50,8 @@ impl UserInner {
|
||||||
(context.id, context.euid, context.egid)
|
(context.id, context.euid, context.egid)
|
||||||
};
|
};
|
||||||
|
|
||||||
let id = self.next_id.fetch_add(1, Ordering::SeqCst);
|
self.call_inner(Packet {
|
||||||
|
id: self.next_id.fetch_add(1, Ordering::SeqCst),
|
||||||
let packet = Packet {
|
|
||||||
id: id,
|
|
||||||
pid: pid,
|
pid: pid,
|
||||||
uid: uid,
|
uid: uid,
|
||||||
gid: gid,
|
gid: gid,
|
||||||
|
@ -58,7 +59,11 @@ impl UserInner {
|
||||||
b: b,
|
b: b,
|
||||||
c: c,
|
c: c,
|
||||||
d: d
|
d: d
|
||||||
};
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn call_inner(&self, packet: Packet) -> Result<usize> {
|
||||||
|
let id = packet.id;
|
||||||
|
|
||||||
let len = self.todo.send(packet);
|
let len = self.todo.send(packet);
|
||||||
context::event::trigger(ROOT_SCHEME_ID.load(Ordering::SeqCst), self.handle_id, EVENT_READ, mem::size_of::<Packet>() * len);
|
context::event::trigger(ROOT_SCHEME_ID.load(Ordering::SeqCst), self.handle_id, EVENT_READ, mem::size_of::<Packet>() * len);
|
||||||
|
@ -67,18 +72,18 @@ impl UserInner {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn capture(&self, buf: &[u8]) -> Result<usize> {
|
pub fn capture(&self, buf: &[u8]) -> Result<usize> {
|
||||||
self.capture_inner(buf.as_ptr() as usize, buf.len(), false)
|
UserInner::capture_inner(&self.context, buf.as_ptr() as usize, buf.len(), false)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn capture_mut(&self, buf: &mut [u8]) -> Result<usize> {
|
pub fn capture_mut(&self, buf: &mut [u8]) -> Result<usize> {
|
||||||
self.capture_inner(buf.as_mut_ptr() as usize, buf.len(), true)
|
UserInner::capture_inner(&self.context, buf.as_mut_ptr() as usize, buf.len(), true)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn capture_inner(&self, address: usize, size: usize, writable: bool) -> Result<usize> {
|
fn capture_inner(context_weak: &Weak<RwLock<Context>>, address: usize, size: usize, writable: bool) -> Result<usize> {
|
||||||
if size == 0 {
|
if size == 0 {
|
||||||
Ok(0)
|
Ok(0)
|
||||||
} else {
|
} else {
|
||||||
let context_lock = self.context.upgrade().ok_or(Error::new(ESRCH))?;
|
let context_lock = context_weak.upgrade().ok_or(Error::new(ESRCH))?;
|
||||||
let context = context_lock.read();
|
let context = context_lock.read();
|
||||||
|
|
||||||
let mut grants = context.grants.lock();
|
let mut grants = context.grants.lock();
|
||||||
|
@ -165,13 +170,19 @@ impl UserInner {
|
||||||
let len = buf.len()/packet_size;
|
let len = buf.len()/packet_size;
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
while i < len {
|
while i < len {
|
||||||
let packet = unsafe { *(buf.as_ptr() as *const Packet).offset(i as isize) };
|
let mut packet = unsafe { *(buf.as_ptr() as *const Packet).offset(i as isize) };
|
||||||
if packet.id == 0 {
|
if packet.id == 0 {
|
||||||
match packet.a {
|
match packet.a {
|
||||||
SYS_FEVENT => context::event::trigger(self.scheme_id.load(Ordering::SeqCst), packet.b, packet.c, packet.d),
|
SYS_FEVENT => context::event::trigger(self.scheme_id.load(Ordering::SeqCst), packet.b, packet.c, packet.d),
|
||||||
_ => println!("Unknown scheme -> kernel message {}", packet.a)
|
_ => println!("Unknown scheme -> kernel message {}", packet.a)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
if let Some((context_weak, size)) = self.fmap.lock().remove(&packet.id) {
|
||||||
|
if let Ok(address) = Error::demux(packet.a) {
|
||||||
|
packet.a = Error::mux(UserInner::capture_inner(&context_weak, address, size, true));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
self.done.send(packet.id, packet.a);
|
self.done.send(packet.id, packet.a);
|
||||||
}
|
}
|
||||||
i += 1;
|
i += 1;
|
||||||
|
@ -269,6 +280,32 @@ impl Scheme for UserScheme {
|
||||||
inner.call(SYS_FEVENT, file, flags, 0)
|
inner.call(SYS_FEVENT, file, flags, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn fmap(&self, file: usize, offset: usize, size: usize) -> Result<usize> {
|
||||||
|
let inner = self.inner.upgrade().ok_or(Error::new(ENODEV))?;
|
||||||
|
|
||||||
|
let (pid, uid, gid, context_lock) = {
|
||||||
|
let contexts = context::contexts();
|
||||||
|
let context_lock = contexts.current().ok_or(Error::new(ESRCH))?;
|
||||||
|
let context = context_lock.read();
|
||||||
|
(context.id, context.euid, context.egid, Arc::downgrade(&context_lock))
|
||||||
|
};
|
||||||
|
|
||||||
|
let id = inner.next_id.fetch_add(1, Ordering::SeqCst);
|
||||||
|
|
||||||
|
inner.fmap.lock().insert(id, (context_lock, size));
|
||||||
|
|
||||||
|
inner.call_inner(Packet {
|
||||||
|
id: id,
|
||||||
|
pid: pid,
|
||||||
|
uid: uid,
|
||||||
|
gid: gid,
|
||||||
|
a: SYS_FMAP,
|
||||||
|
b: file,
|
||||||
|
c: offset,
|
||||||
|
d: size
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
fn fpath(&self, file: usize, buf: &mut [u8]) -> Result<usize> {
|
fn fpath(&self, file: usize, buf: &mut [u8]) -> Result<usize> {
|
||||||
let inner = self.inner.upgrade().ok_or(Error::new(ENODEV))?;
|
let inner = self.inner.upgrade().ok_or(Error::new(ENODEV))?;
|
||||||
let address = inner.capture_mut(buf)?;
|
let address = inner.capture_mut(buf)?;
|
||||||
|
|
|
@ -293,3 +293,27 @@ pub fn fevent(fd: usize, flags: usize) -> Result<usize> {
|
||||||
context::event::register(fd, file.scheme, event_id);
|
context::event::register(fd, file.scheme, event_id);
|
||||||
Ok(0)
|
Ok(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn funmap(virtual_address: usize) -> Result<usize> {
|
||||||
|
if virtual_address == 0 {
|
||||||
|
Ok(0)
|
||||||
|
} else {
|
||||||
|
let contexts = context::contexts();
|
||||||
|
let context_lock = contexts.current().ok_or(Error::new(ESRCH))?;
|
||||||
|
let context = context_lock.read();
|
||||||
|
|
||||||
|
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();
|
||||||
|
if virtual_address >= start && virtual_address < end {
|
||||||
|
grants.remove(i).unmap();
|
||||||
|
|
||||||
|
return Ok(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Err(Error::new(EFAULT))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -41,6 +41,7 @@ pub extern fn syscall(a: usize, b: usize, c: usize, d: usize, e: usize, f: usize
|
||||||
SYS_CLOSE => close(b),
|
SYS_CLOSE => close(b),
|
||||||
SYS_DUP => dup(b, validate_slice(c as *const u8, d)?),
|
SYS_DUP => dup(b, validate_slice(c as *const u8, d)?),
|
||||||
SYS_FEVENT => fevent(b, c),
|
SYS_FEVENT => fevent(b, c),
|
||||||
|
SYS_FUNMAP => funmap(b),
|
||||||
_ => file_op(a, b, c, d)
|
_ => file_op(a, b, c, d)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -367,11 +367,12 @@ pub fn clone(flags: usize, stack_base: usize) -> Result<usize> {
|
||||||
context.heap = Some(heap_shared);
|
context.heap = Some(heap_shared);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Copy grant mapping
|
||||||
if ! grants.lock().is_empty() {
|
if ! grants.lock().is_empty() {
|
||||||
let frame = active_table.p4()[2].pointed_frame().expect("user heap not mapped");
|
let frame = active_table.p4()[2].pointed_frame().expect("user grants not mapped");
|
||||||
let flags = active_table.p4()[2].flags();
|
let flags = active_table.p4()[2].flags();
|
||||||
active_table.with(&mut new_table, &mut temporary_page, |mapper| {
|
active_table.with(&mut new_table, &mut temporary_page, |mapper| {
|
||||||
mapper.p4_mut()[1].set(frame, flags);
|
mapper.p4_mut()[2].set(frame, flags);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
context.grants = grants;
|
context.grants = grants;
|
||||||
|
|
2
libstd
2
libstd
|
@ -1 +1 @@
|
||||||
Subproject commit c20c669c0eed7bd89fdce3f1f74ae82bb327bafa
|
Subproject commit 2f7ee270c63151c6f3242ad4f1b669a76ed48a5c
|
|
@ -4,4 +4,4 @@ version = "0.1.0"
|
||||||
authors = ["Jeremy Soller <jackpot51@gmail.com>"]
|
authors = ["Jeremy Soller <jackpot51@gmail.com>"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
syscall = { path = "../../syscall/" }
|
redox_syscall = { path = "../../syscall/" }
|
||||||
|
|
|
@ -4,4 +4,4 @@ version = "0.0.0"
|
||||||
authors = ["Jeremy Soller <jackpot51@gmail.com>"]
|
authors = ["Jeremy Soller <jackpot51@gmail.com>"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
syscall = { path = "../../syscall/" }
|
redox_syscall = { path = "../../syscall/" }
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 5c578a59b32e298ec68218270fba0f48d9d37979
|
Subproject commit 43f027a164fd550831f6e9fa9a5db393541bcbe9
|
|
@ -3,4 +3,4 @@ name = "init"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
syscall = { path = "../../syscall" }
|
redox_syscall = { path = "../../syscall" }
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 4fe44e0a610203d78f2e5d8fdac80d77f03bbb88
|
Subproject commit 81d2d47a702cf6ac2993f4c978aaa674f86c0657
|
|
@ -1 +1 @@
|
||||||
Subproject commit 8561cb40bdcdf9d32dea667d50d87cd9fe4c9dc6
|
Subproject commit 18e7916946b6dbe75236023e24c40793fd99705d
|
|
@ -1 +1 @@
|
||||||
Subproject commit 5ae17129d3124b990b38391c60b1b4ad150b3112
|
Subproject commit f27ed41bcb2fde923824e80f2a94eae28e6c211e
|
|
@ -5,4 +5,4 @@ version = "0.1.0"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
event = { path = "../../crates/event/" }
|
event = { path = "../../crates/event/" }
|
||||||
netutils = { path = "../../programs/netutils/" }
|
netutils = { path = "../../programs/netutils/" }
|
||||||
syscall = { path = "../../syscall/" }
|
redox_syscall = { path = "../../syscall/" }
|
||||||
|
|
|
@ -2,5 +2,5 @@
|
||||||
name = "example"
|
name = "example"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
|
||||||
[dependencies.syscall]
|
[dependencies]
|
||||||
path = "../../syscall/"
|
redox_syscall = { path = "../../syscall/" }
|
||||||
|
|
|
@ -5,4 +5,4 @@ version = "0.1.0"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
event = { path = "../../crates/event/" }
|
event = { path = "../../crates/event/" }
|
||||||
netutils = { path = "../../programs/netutils/" }
|
netutils = { path = "../../programs/netutils/" }
|
||||||
syscall = { path = "../../syscall/" }
|
redox_syscall = { path = "../../syscall/" }
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 2c366e9bca7ca97096a77c7c3e355eeacb6db963
|
Subproject commit 9613fa4df8999179cd27ae9cdcb3c65928a0dbac
|
|
@ -3,4 +3,4 @@ name = "ptyd"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
syscall = { path = "../../syscall/" }
|
redox_syscall = { path = "../../syscall/" }
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit a0b381765b66fe798e8b618ad5f6568cebacf0c7
|
Subproject commit b25b2687567dca4b44d1d9fafcd05e4e1f5df885
|
|
@ -6,4 +6,4 @@ version = "0.1.0"
|
||||||
event = { path = "../../crates/event/" }
|
event = { path = "../../crates/event/" }
|
||||||
netutils = { path = "../../programs/netutils/" }
|
netutils = { path = "../../programs/netutils/" }
|
||||||
rand = { git = "https://github.com/redox-os/rand.git" }
|
rand = { git = "https://github.com/redox-os/rand.git" }
|
||||||
syscall = { path = "../../syscall/" }
|
redox_syscall = { path = "../../syscall/" }
|
||||||
|
|
|
@ -6,4 +6,4 @@ version = "0.1.0"
|
||||||
event = { path = "../../crates/event/" }
|
event = { path = "../../crates/event/" }
|
||||||
netutils = { path = "../../programs/netutils/" }
|
netutils = { path = "../../programs/netutils/" }
|
||||||
rand = { git = "https://github.com/redox-os/rand.git" }
|
rand = { git = "https://github.com/redox-os/rand.git" }
|
||||||
syscall = { path = "../../syscall/" }
|
redox_syscall = { path = "../../syscall/" }
|
||||||
|
|
2
syscall
2
syscall
|
@ -1 +1 @@
|
||||||
Subproject commit 5a687dfeb578343431992f3a4d854f303a904486
|
Subproject commit 416fd2217466519eefbbfeecce5f94db915e784c
|
Loading…
Reference in a new issue