2016-09-24 01:54:39 +02:00
|
|
|
use alloc::arc::{Arc, Weak};
|
Orbital (#16)
* Port previous ethernet scheme
* Add ipd
* Fix initfs rebuilds, use QEMU user networking addresses in ipd
* Add tcp/udp, netutils, dns, and network config
* Add fsync to network driver
* Add dns, router, subnet by default
* Fix e1000 driver. Make ethernet and IP non-blocking to avoid deadlocks
* Add orbital server, WIP
* Add futex
* Add orbutils and orbital
* Update libstd, orbutils, and orbital
Move ANSI key encoding to vesad
* Add orbital assets
* Update orbital
* Update to add login manager
* Add blocking primitives, block for most things except waitpid, update orbital
* Wait in waitpid and IRQ, improvements for other waits
* Fevent in root scheme
* WIP: Switch to using fevent
* Reorganize
* Event based e1000d driver
* Superuser-only access to some network schemes, display, and disk
* Superuser root and irq schemes
* Fix orbital
2016-10-14 01:21:42 +02:00
|
|
|
use collections::BTreeMap;
|
|
|
|
use core::{mem, slice};
|
2016-09-24 01:54:39 +02:00
|
|
|
use core::sync::atomic::{AtomicUsize, Ordering};
|
Orbital (#16)
* Port previous ethernet scheme
* Add ipd
* Fix initfs rebuilds, use QEMU user networking addresses in ipd
* Add tcp/udp, netutils, dns, and network config
* Add fsync to network driver
* Add dns, router, subnet by default
* Fix e1000 driver. Make ethernet and IP non-blocking to avoid deadlocks
* Add orbital server, WIP
* Add futex
* Add orbutils and orbital
* Update libstd, orbutils, and orbital
Move ANSI key encoding to vesad
* Add orbital assets
* Update orbital
* Update to add login manager
* Add blocking primitives, block for most things except waitpid, update orbital
* Wait in waitpid and IRQ, improvements for other waits
* Fevent in root scheme
* WIP: Switch to using fevent
* Reorganize
* Event based e1000d driver
* Superuser-only access to some network schemes, display, and disk
* Superuser root and irq schemes
* Fix orbital
2016-10-14 01:21:42 +02:00
|
|
|
use spin::RwLock;
|
2016-09-23 23:47:53 +02:00
|
|
|
|
2016-09-24 01:54:39 +02:00
|
|
|
use context;
|
Orbital (#16)
* Port previous ethernet scheme
* Add ipd
* Fix initfs rebuilds, use QEMU user networking addresses in ipd
* Add tcp/udp, netutils, dns, and network config
* Add fsync to network driver
* Add dns, router, subnet by default
* Fix e1000 driver. Make ethernet and IP non-blocking to avoid deadlocks
* Add orbital server, WIP
* Add futex
* Add orbutils and orbital
* Update libstd, orbutils, and orbital
Move ANSI key encoding to vesad
* Add orbital assets
* Update orbital
* Update to add login manager
* Add blocking primitives, block for most things except waitpid, update orbital
* Wait in waitpid and IRQ, improvements for other waits
* Fevent in root scheme
* WIP: Switch to using fevent
* Reorganize
* Event based e1000d driver
* Superuser-only access to some network schemes, display, and disk
* Superuser root and irq schemes
* Fix orbital
2016-10-14 01:21:42 +02:00
|
|
|
use sync::WaitQueue;
|
2016-09-24 01:54:39 +02:00
|
|
|
use syscall::data::Event;
|
2016-09-23 23:47:53 +02:00
|
|
|
use syscall::error::*;
|
|
|
|
use syscall::scheme::Scheme;
|
|
|
|
|
2016-09-24 01:54:39 +02:00
|
|
|
pub struct EventScheme {
|
|
|
|
next_id: AtomicUsize,
|
Orbital (#16)
* Port previous ethernet scheme
* Add ipd
* Fix initfs rebuilds, use QEMU user networking addresses in ipd
* Add tcp/udp, netutils, dns, and network config
* Add fsync to network driver
* Add dns, router, subnet by default
* Fix e1000 driver. Make ethernet and IP non-blocking to avoid deadlocks
* Add orbital server, WIP
* Add futex
* Add orbutils and orbital
* Update libstd, orbutils, and orbital
Move ANSI key encoding to vesad
* Add orbital assets
* Update orbital
* Update to add login manager
* Add blocking primitives, block for most things except waitpid, update orbital
* Wait in waitpid and IRQ, improvements for other waits
* Fevent in root scheme
* WIP: Switch to using fevent
* Reorganize
* Event based e1000d driver
* Superuser-only access to some network schemes, display, and disk
* Superuser root and irq schemes
* Fix orbital
2016-10-14 01:21:42 +02:00
|
|
|
handles: RwLock<BTreeMap<usize, Weak<WaitQueue<Event>>>>
|
2016-09-24 01:54:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
impl EventScheme {
|
|
|
|
pub fn new() -> EventScheme {
|
|
|
|
EventScheme {
|
|
|
|
next_id: AtomicUsize::new(0),
|
|
|
|
handles: RwLock::new(BTreeMap::new())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-09-23 23:47:53 +02:00
|
|
|
|
|
|
|
impl Scheme for EventScheme {
|
2016-10-06 02:01:05 +02:00
|
|
|
fn open(&self, _path: &[u8], _flags: usize, _uid: u32, _gid: u32) -> Result<usize> {
|
2016-09-24 01:54:39 +02:00
|
|
|
let handle = {
|
|
|
|
let contexts = context::contexts();
|
|
|
|
let context_lock = contexts.current().ok_or(Error::new(ESRCH))?;
|
|
|
|
let context = context_lock.read();
|
|
|
|
context.events.clone()
|
|
|
|
};
|
2016-09-23 23:47:53 +02:00
|
|
|
|
2016-09-24 01:54:39 +02:00
|
|
|
let id = self.next_id.fetch_add(1, Ordering::SeqCst);
|
|
|
|
self.handles.write().insert(id, Arc::downgrade(&handle));
|
|
|
|
|
|
|
|
Ok(id)
|
2016-09-23 23:47:53 +02:00
|
|
|
}
|
|
|
|
|
2016-10-26 21:19:56 +02:00
|
|
|
fn dup(&self, id: usize, _buf: &[u8]) -> Result<usize> {
|
2016-09-24 01:54:39 +02:00
|
|
|
let handle = {
|
|
|
|
let handles = self.handles.read();
|
|
|
|
let handle_weak = handles.get(&id).ok_or(Error::new(EBADF))?;
|
|
|
|
handle_weak.upgrade().ok_or(Error::new(EBADF))?
|
|
|
|
};
|
|
|
|
|
|
|
|
let new_id = self.next_id.fetch_add(1, Ordering::SeqCst);
|
|
|
|
self.handles.write().insert(new_id, Arc::downgrade(&handle));
|
|
|
|
Ok(new_id)
|
2016-09-23 23:47:53 +02:00
|
|
|
}
|
|
|
|
|
2016-09-24 01:54:39 +02:00
|
|
|
fn read(&self, id: usize, buf: &mut [u8]) -> Result<usize> {
|
|
|
|
let handle = {
|
|
|
|
let handles = self.handles.read();
|
|
|
|
let handle_weak = handles.get(&id).ok_or(Error::new(EBADF))?;
|
|
|
|
handle_weak.upgrade().ok_or(Error::new(EBADF))?
|
|
|
|
};
|
|
|
|
|
Orbital (#16)
* Port previous ethernet scheme
* Add ipd
* Fix initfs rebuilds, use QEMU user networking addresses in ipd
* Add tcp/udp, netutils, dns, and network config
* Add fsync to network driver
* Add dns, router, subnet by default
* Fix e1000 driver. Make ethernet and IP non-blocking to avoid deadlocks
* Add orbital server, WIP
* Add futex
* Add orbutils and orbital
* Update libstd, orbutils, and orbital
Move ANSI key encoding to vesad
* Add orbital assets
* Update orbital
* Update to add login manager
* Add blocking primitives, block for most things except waitpid, update orbital
* Wait in waitpid and IRQ, improvements for other waits
* Fevent in root scheme
* WIP: Switch to using fevent
* Reorganize
* Event based e1000d driver
* Superuser-only access to some network schemes, display, and disk
* Superuser root and irq schemes
* Fix orbital
2016-10-14 01:21:42 +02:00
|
|
|
let event_buf = unsafe { slice::from_raw_parts_mut(buf.as_mut_ptr() as *mut Event, buf.len()/mem::size_of::<Event>()) };
|
2016-10-20 20:31:39 +02:00
|
|
|
Ok(handle.receive_into(event_buf, true) * mem::size_of::<Event>())
|
2016-09-23 23:47:53 +02:00
|
|
|
}
|
|
|
|
|
2016-09-24 01:54:39 +02:00
|
|
|
fn fsync(&self, id: usize) -> Result<usize> {
|
|
|
|
let handles = self.handles.read();
|
|
|
|
let handle_weak = handles.get(&id).ok_or(Error::new(EBADF))?;
|
|
|
|
handle_weak.upgrade().ok_or(Error::new(EBADF)).and(Ok(0))
|
2016-09-23 23:47:53 +02:00
|
|
|
}
|
|
|
|
|
2016-09-24 01:54:39 +02:00
|
|
|
fn close(&self, id: usize) -> Result<usize> {
|
|
|
|
self.handles.write().remove(&id).ok_or(Error::new(EBADF)).and(Ok(0))
|
2016-09-23 23:47:53 +02:00
|
|
|
}
|
|
|
|
}
|