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
This commit is contained in:
parent
372d44f88c
commit
224c43f761
92 changed files with 3415 additions and 473 deletions
|
@ -1,21 +1,54 @@
|
|||
use core::{mem, str};
|
||||
use core::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering};
|
||||
use spin::{Mutex, Once};
|
||||
|
||||
use arch::interrupt::irq::{ACKS, COUNTS, acknowledge};
|
||||
use arch::interrupt::irq::acknowledge;
|
||||
use context;
|
||||
use sync::WaitCondition;
|
||||
use syscall::error::*;
|
||||
use syscall::flag::EVENT_READ;
|
||||
use syscall::scheme::Scheme;
|
||||
|
||||
pub static IRQ_SCHEME_ID: AtomicUsize = ATOMIC_USIZE_INIT;
|
||||
|
||||
/// IRQ queues
|
||||
static ACKS: Mutex<[usize; 16]> = Mutex::new([0; 16]);
|
||||
static COUNTS: Mutex<[usize; 16]> = Mutex::new([0; 16]);
|
||||
static WAITS: Once<[WaitCondition; 16]> = Once::new();
|
||||
|
||||
fn init_waits() -> [WaitCondition; 16] {
|
||||
[
|
||||
WaitCondition::new(), WaitCondition::new(), WaitCondition::new(), WaitCondition::new(),
|
||||
WaitCondition::new(), WaitCondition::new(), WaitCondition::new(), WaitCondition::new(),
|
||||
WaitCondition::new(), WaitCondition::new(), WaitCondition::new(), WaitCondition::new(),
|
||||
WaitCondition::new(), WaitCondition::new(), WaitCondition::new(), WaitCondition::new()
|
||||
]
|
||||
}
|
||||
|
||||
/// Add to the input queue
|
||||
#[no_mangle]
|
||||
pub extern fn irq_trigger(irq: u8) {
|
||||
COUNTS.lock()[irq as usize] += 1;
|
||||
WAITS.call_once(init_waits)[irq as usize].notify();
|
||||
context::event::trigger(IRQ_SCHEME_ID.load(Ordering::SeqCst), irq as usize, EVENT_READ, mem::size_of::<usize>());
|
||||
}
|
||||
|
||||
pub struct IrqScheme;
|
||||
|
||||
impl Scheme for IrqScheme {
|
||||
fn open(&self, path: &[u8], _flags: usize, _uid: u32, _gid: u32) -> Result<usize> {
|
||||
let path_str = str::from_utf8(path).or(Err(Error::new(ENOENT)))?;
|
||||
fn open(&self, path: &[u8], _flags: usize, uid: u32, _gid: u32) -> Result<usize> {
|
||||
if uid == 0 {
|
||||
let path_str = str::from_utf8(path).or(Err(Error::new(ENOENT)))?;
|
||||
|
||||
let id = path_str.parse::<usize>().or(Err(Error::new(ENOENT)))?;
|
||||
let id = path_str.parse::<usize>().or(Err(Error::new(ENOENT)))?;
|
||||
|
||||
if id < COUNTS.lock().len() {
|
||||
Ok(id)
|
||||
if id < COUNTS.lock().len() {
|
||||
Ok(id)
|
||||
} else {
|
||||
Err(Error::new(ENOENT))
|
||||
}
|
||||
} else {
|
||||
Err(Error::new(ENOENT))
|
||||
Err(Error::new(EACCES))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -26,15 +59,17 @@ impl Scheme for IrqScheme {
|
|||
fn read(&self, file: usize, buffer: &mut [u8]) -> Result<usize> {
|
||||
// Ensures that the length of the buffer is larger than the size of a usize
|
||||
if buffer.len() >= mem::size_of::<usize>() {
|
||||
let ack = ACKS.lock()[file];
|
||||
let current = COUNTS.lock()[file];
|
||||
if ack != current {
|
||||
// Safe if the length of the buffer is larger than the size of a usize
|
||||
assert!(buffer.len() >= mem::size_of::<usize>());
|
||||
unsafe { *(buffer.as_mut_ptr() as *mut usize) = current; }
|
||||
Ok(mem::size_of::<usize>())
|
||||
} else {
|
||||
Ok(0)
|
||||
loop {
|
||||
let ack = ACKS.lock()[file];
|
||||
let current = COUNTS.lock()[file];
|
||||
if ack != current {
|
||||
// Safe if the length of the buffer is larger than the size of a usize
|
||||
assert!(buffer.len() >= mem::size_of::<usize>());
|
||||
unsafe { *(buffer.as_mut_ptr() as *mut usize) = current; }
|
||||
return Ok(mem::size_of::<usize>());
|
||||
} else {
|
||||
WAITS.call_once(init_waits)[file].wait();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Err(Error::new(EINVAL))
|
||||
|
@ -58,6 +93,10 @@ impl Scheme for IrqScheme {
|
|||
}
|
||||
}
|
||||
|
||||
fn fevent(&self, _file: usize, _flags: usize) -> Result<usize> {
|
||||
Ok(0)
|
||||
}
|
||||
|
||||
fn fsync(&self, _file: usize) -> Result<usize> {
|
||||
Ok(0)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue