WIP: Kevent
This commit is contained in:
parent
94ef9dd14a
commit
616dfbc055
16 changed files with 131 additions and 13 deletions
|
@ -8,7 +8,7 @@ use super::{contexts, Context, Status, CONTEXT_ID};
|
|||
/// # Safety
|
||||
///
|
||||
/// Do not call this while holding locks!
|
||||
pub unsafe fn switch() {
|
||||
pub unsafe fn switch() -> bool {
|
||||
use core::ops::DerefMut;
|
||||
|
||||
// Set the global lock to avoid the unsafe operations below from causing issues
|
||||
|
@ -48,10 +48,9 @@ pub unsafe fn switch() {
|
|||
}
|
||||
|
||||
if to_ptr as usize == 0 {
|
||||
// TODO: Sleep, wait for interrupt
|
||||
// Unset global lock if no context found
|
||||
arch::context::CONTEXT_SWITCH_LOCK.store(false, Ordering::SeqCst);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
//println!("Switch {} to {}", (&*from_ptr).id, (&*to_ptr).id);
|
||||
|
@ -64,4 +63,6 @@ pub unsafe fn switch() {
|
|||
CONTEXT_ID.store((&mut *to_ptr).id, Ordering::SeqCst);
|
||||
|
||||
(&mut *from_ptr).arch.switch_to(&mut (&mut *to_ptr).arch);
|
||||
|
||||
true
|
||||
}
|
||||
|
|
|
@ -162,8 +162,11 @@ pub extern fn kmain() {
|
|||
loop {
|
||||
unsafe {
|
||||
interrupt::disable();
|
||||
context::switch();
|
||||
interrupt::enable_and_nop();
|
||||
if context::switch() {
|
||||
interrupt::enable_and_nop();
|
||||
} else {
|
||||
interrupt::enable_and_halt();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ impl Scheme for DebugScheme {
|
|||
if i > 0 {
|
||||
return Ok(i);
|
||||
} else {
|
||||
unsafe { context::switch(); }
|
||||
unsafe { context::switch(); } //TODO: Block
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
33
kernel/scheme/event.rs
Normal file
33
kernel/scheme/event.rs
Normal file
|
@ -0,0 +1,33 @@
|
|||
use core::{mem, str};
|
||||
|
||||
use arch::interrupt::irq::{ACKS, COUNTS, acknowledge};
|
||||
use syscall::error::*;
|
||||
use syscall::scheme::Scheme;
|
||||
|
||||
pub struct EventScheme;
|
||||
|
||||
impl Scheme for EventScheme {
|
||||
fn open(&self, _path: &[u8], _flags: usize) -> Result<usize> {
|
||||
Ok(
|
||||
}
|
||||
|
||||
fn dup(&self, file: usize) -> Result<usize> {
|
||||
Ok(file)
|
||||
}
|
||||
|
||||
fn read(&self, file: usize, buffer: &mut [u8]) -> Result<usize> {
|
||||
Ok(0)
|
||||
}
|
||||
|
||||
fn write(&self, file: usize, buffer: &[u8]) -> Result<usize> {
|
||||
Ok(0)
|
||||
}
|
||||
|
||||
fn fsync(&self, _file: usize) -> Result<usize> {
|
||||
Ok(0)
|
||||
}
|
||||
|
||||
fn close(&self, _file: usize) -> Result<usize> {
|
||||
Ok(0)
|
||||
}
|
||||
}
|
|
@ -52,7 +52,7 @@ impl UserInner {
|
|||
}
|
||||
}
|
||||
|
||||
unsafe { context::switch(); }
|
||||
unsafe { context::switch(); } //TODO: Block
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -163,7 +163,7 @@ impl UserInner {
|
|||
if i > 0 {
|
||||
return Ok(i * packet_size);
|
||||
} else {
|
||||
unsafe { context::switch(); }
|
||||
unsafe { context::switch(); } //TODO: Block
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -230,7 +230,12 @@ impl Scheme for UserScheme {
|
|||
|
||||
fn seek(&self, file: usize, position: usize, whence: usize) -> Result<usize> {
|
||||
let inner = self.inner.upgrade().ok_or(Error::new(ENODEV))?;
|
||||
inner.call(SYS_FSYNC, file, position, whence)
|
||||
inner.call(SYS_LSEEK, file, position, whence)
|
||||
}
|
||||
|
||||
fn fevent(&self, file: usize, flags: usize) -> Result<usize> {
|
||||
let inner = self.inner.upgrade().ok_or(Error::new(ENODEV))?;
|
||||
inner.call(SYS_FEVENT, file, flags, 0)
|
||||
}
|
||||
|
||||
fn fstat(&self, file: usize, stat: &mut Stat) -> Result<usize> {
|
||||
|
|
|
@ -98,6 +98,24 @@ pub fn dup(fd: usize) -> Result<usize> {
|
|||
scheme.dup(file.number)
|
||||
}
|
||||
|
||||
/// Register events for file
|
||||
pub fn fevent(fd: usize, flags: usize) -> Result<usize> {
|
||||
let file = {
|
||||
let contexts = context::contexts();
|
||||
let context_lock = contexts.current().ok_or(Error::new(ESRCH))?;
|
||||
let context = context_lock.read();
|
||||
let file = context.get_file(fd).ok_or(Error::new(EBADF))?;
|
||||
file
|
||||
};
|
||||
|
||||
let scheme = {
|
||||
let schemes = scheme::schemes();
|
||||
let scheme = schemes.get(file.scheme).ok_or(Error::new(EBADF))?;
|
||||
scheme.clone()
|
||||
};
|
||||
scheme.fevent(file.number, flags)
|
||||
}
|
||||
|
||||
/// Get the canonical path of the file
|
||||
pub fn fpath(fd: usize, buf: &mut [u8]) -> Result<usize> {
|
||||
let file = {
|
||||
|
|
|
@ -45,6 +45,7 @@ pub extern fn syscall(a: usize, b: usize, c: usize, d: usize, e: usize, f: usize
|
|||
SYS_CLONE => clone(b, stack),
|
||||
SYS_YIELD => sched_yield(),
|
||||
SYS_GETCWD => getcwd(validate_slice_mut(b as *mut u8, c)?),
|
||||
SYS_FEVENT => fevent(b, c),
|
||||
SYS_FPATH => fpath(b, validate_slice_mut(c as *mut u8, d)?),
|
||||
SYS_PHYSMAP => physmap(b, c, d),
|
||||
SYS_PHYSUNMAP => physunmap(b),
|
||||
|
|
|
@ -618,7 +618,6 @@ pub fn sched_yield() -> Result<usize> {
|
|||
}
|
||||
|
||||
pub fn waitpid(pid: usize, status_ptr: usize, flags: usize) -> Result<usize> {
|
||||
//TODO: Implement status_ptr and options
|
||||
loop {
|
||||
{
|
||||
let mut exited = false;
|
||||
|
@ -644,6 +643,6 @@ pub fn waitpid(pid: usize, status_ptr: usize, flags: usize) -> Result<usize> {
|
|||
}
|
||||
}
|
||||
|
||||
unsafe { context::switch(); }
|
||||
unsafe { context::switch(); } //TODO: Block
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue