refactor: fix non-doc warnings

This commit is contained in:
Mark Poliakov 2021-11-22 15:42:43 +02:00
parent 4cfa1f2958
commit fabf4e8d3f
21 changed files with 175 additions and 158 deletions

View File

@ -414,7 +414,7 @@ impl Vnode {
}
}
pub fn check_access(&self, ioctx: &Ioctx, access: AccessMode) -> Result<(), Errno> {
pub fn check_access(&self, _ioctx: &Ioctx, access: AccessMode) -> Result<(), Errno> {
let props = self.props.borrow();
let mode = props.mode;

View File

@ -4,7 +4,7 @@ use crate::arch::machine;
use crate::debug::Level;
use crate::dev::irq::{IntController, IrqContext};
use crate::mem;
use crate::proc::{sched, Thread, Process};
use crate::proc::{sched, Thread};
use crate::syscall;
use cortex_a::registers::{ESR_EL1, FAR_EL1};
use libsys::{abi::SystemCall, signal::Signal};
@ -120,7 +120,6 @@ extern "C" fn __aa64_exc_sync_handler(exc: &mut ExceptionFrame) {
let num = SystemCall::from_repr(exc.x[8]);
if num.is_none() {
todo!();
return;
}
let num = num.unwrap();

View File

@ -3,7 +3,7 @@
use crate::config::{ConfigKey, CONFIG};
use crate::fs::{devfs, MemfsBlockAlloc};
use crate::mem;
use crate::proc::{wait, elf, Process};
use crate::proc::{elf, Process};
use libsys::stat::{FileDescriptor, OpenFlags};
use memfs::Ramfs;
use vfs::{Filesystem, Ioctx};

View File

@ -93,18 +93,18 @@ impl SimpleManager {
self.stats.available -= count;
}
fn update_stats_free(&mut self, pu: PageUsage, count: usize) {
let field = match pu {
PageUsage::Kernel => &mut self.stats.kernel,
PageUsage::KernelHeap => &mut self.stats.kernel_heap,
PageUsage::Paging => &mut self.stats.paging,
PageUsage::UserPrivate => &mut self.stats.user_private,
PageUsage::Filesystem => &mut self.stats.filesystem,
_ => panic!("TODO {:?}", pu),
};
*field -= count;
self.stats.available += count;
}
// fn update_stats_free(&mut self, pu: PageUsage, count: usize) {
// let field = match pu {
// PageUsage::Kernel => &mut self.stats.kernel,
// PageUsage::KernelHeap => &mut self.stats.kernel_heap,
// PageUsage::Paging => &mut self.stats.paging,
// PageUsage::UserPrivate => &mut self.stats.user_private,
// PageUsage::Filesystem => &mut self.stats.filesystem,
// _ => panic!("TODO {:?}", pu),
// };
// *field -= count;
// self.stats.available += count;
// }
}
unsafe impl Manager for SimpleManager {
fn alloc_page(&mut self, pu: PageUsage) -> Result<usize, Errno> {
@ -134,11 +134,9 @@ unsafe impl Manager for SimpleManager {
Err(Errno::OutOfMemory)
}
fn free_page(&mut self, addr: usize) -> Result<(), Errno> {
let usage = {
let index = self.page_index(addr);
let page = &mut self.pages[index];
let usage = page.usage;
assert!(page.usage != PageUsage::Reserved && page.usage != PageUsage::Available);
if page.refcount > 1 {
@ -151,8 +149,6 @@ unsafe impl Manager for SimpleManager {
self.last_index = index;
}
usage
};
// FIXME
// self.update_stats_free(usage, 1);

View File

@ -6,11 +6,10 @@ use crate::mem::{
virt::{MapAttributes, Space},
};
use crate::proc::{
wait::Wait, Context, ProcessIo, Thread, ThreadRef, ThreadState, PROCESSES, SCHED, THREADS,
wait::Wait, Context, ProcessIo, Thread, ThreadRef, ThreadState, PROCESSES, SCHED,
};
use crate::sync::{IrqSafeSpinLock, IrqSafeSpinLockGuard};
use alloc::{rc::Rc, vec::Vec};
use core::cell::UnsafeCell;
use core::sync::atomic::{AtomicU32, Ordering};
use libsys::{
error::Errno,
@ -108,7 +107,7 @@ impl Process {
/// Sets a pending signal for a process
pub fn set_signal(&self, signal: Signal) {
let mut lock = self.inner.lock();
let lock = self.inner.lock();
let main_thread = Thread::get(lock.threads[0]).unwrap();
// TODO check that `signal` is not a fault signal
@ -133,7 +132,11 @@ impl Process {
}
}
fn enter_signal_on(mut inner: IrqSafeSpinLockGuard<ProcessInner>, thread: ThreadRef, signal: Signal) {
fn enter_signal_on(
mut inner: IrqSafeSpinLockGuard<ProcessInner>,
thread: ThreadRef,
signal: Signal,
) {
let ttbr0 =
inner.space.as_mut().unwrap().address_phys() | ((inner.id.asid() as usize) << 48);
drop(inner);

View File

@ -1,5 +1,5 @@
//!
use crate::proc::{Pid, Process, ProcessRef, Thread, ThreadRef, PROCESSES, THREADS};
use crate::proc::{Thread, ThreadRef, THREADS};
use crate::sync::IrqSafeSpinLock;
use crate::util::InitOnce;
use alloc::{collections::VecDeque, rc::Rc};

View File

@ -2,10 +2,14 @@ use crate::arch::aarch64::exception::ExceptionFrame;
use crate::proc::{wait::Wait, Process, ProcessRef, SCHED, THREADS};
use crate::sync::IrqSafeSpinLock;
use crate::util::InitOnce;
use alloc::{rc::Rc, vec::Vec};
use alloc::rc::Rc;
use core::cell::UnsafeCell;
use core::sync::atomic::{AtomicU32, Ordering};
use libsys::{error::Errno, proc::{Pid, ExitCode}, signal::Signal};
use libsys::{
error::Errno,
proc::{ExitCode, Pid},
signal::Signal,
};
pub use crate::arch::platform::context::{self, Context};
@ -297,7 +301,7 @@ impl Thread {
panic!("Already handling a signal (maybe handle this case)");
}
let mut lock = self.inner.lock();
let lock = self.inner.lock();
if lock.signal_entry == 0 || lock.signal_stack == 0 {
drop(lock);
Process::exit_thread(self, ExitCode::from(-1));
@ -317,7 +321,12 @@ impl Thread {
assert_eq!(lock.state, State::Running);
unsafe {
signal_ctx.setup_signal_entry(lock.signal_entry, signal as usize, ttbr0, lock.signal_stack);
signal_ctx.setup_signal_entry(
lock.signal_entry,
signal as usize,
ttbr0,
lock.signal_stack,
);
}
drop(lock);

View File

@ -2,11 +2,11 @@
use crate::arch::machine;
use crate::dev::timer::TimestampSource;
use crate::proc::{self, sched::SCHED, Process, Thread, ThreadRef};
use crate::proc::{sched::SCHED, Thread, ThreadRef};
use crate::sync::IrqSafeSpinLock;
use alloc::collections::LinkedList;
use core::time::Duration;
use libsys::{error::Errno, stat::FdSet, proc::Pid};
use libsys::{error::Errno, stat::FdSet};
/// Wait channel structure. Contains a queue of processes
/// waiting for some event to happen.
@ -61,46 +61,45 @@ pub fn select(
mut wfds: Option<&mut FdSet>,
timeout: Option<Duration>,
) -> Result<usize, Errno> {
if wfds.is_none() && rfds.is_none() {
todo!();
// // TODO support wfds
// if wfds.is_some() || rfds.is_none() {
// todo!();
// }
// let read = rfds.as_deref().map(FdSet::clone);
// let write = wfds.as_deref().map(FdSet::clone);
// rfds.as_deref_mut().map(FdSet::reset);
// wfds.as_deref_mut().map(FdSet::reset);
}
let read = rfds.as_deref().map(FdSet::clone);
let write = wfds.as_deref().map(FdSet::clone);
rfds.as_deref_mut().map(FdSet::reset);
wfds.as_deref_mut().map(FdSet::reset);
// let deadline = timeout.map(|v| v + machine::local_timer().timestamp().unwrap());
// let mut io = proc.io.lock();
let deadline = timeout.map(|v| v + machine::local_timer().timestamp().unwrap());
let proc = thread.owner().unwrap();
let mut io = proc.io.lock();
// loop {
// if let Some(read) = &read {
// for fd in read.iter() {
// let file = io.file(fd)?;
// if file.borrow().is_ready(false)? {
// rfds.as_mut().unwrap().set(fd);
// return Ok(1);
// }
// }
// }
// if let Some(write) = &write {
// for fd in write.iter() {
// let file = io.file(fd)?;
// if file.borrow().is_ready(true)? {
// wfds.as_mut().unwrap().set(fd);
// return Ok(1);
// }
// }
// }
loop {
if let Some(read) = &read {
for fd in read.iter() {
let file = io.file(fd)?;
if file.borrow().is_ready(false)? {
rfds.as_mut().unwrap().set(fd);
return Ok(1);
}
}
}
if let Some(write) = &write {
for fd in write.iter() {
let file = io.file(fd)?;
if file.borrow().is_ready(true)? {
wfds.as_mut().unwrap().set(fd);
return Ok(1);
}
}
}
// // Suspend
// match WAIT_SELECT.wait(deadline) {
// Err(Errno::TimedOut) => return Ok(0),
// Err(e) => return Err(e),
// Ok(_) => {}
// }
// }
// Suspend
match WAIT_SELECT.wait(deadline) {
Err(Errno::TimedOut) => return Ok(0),
Err(e) => return Err(e),
Ok(_) => {}
}
}
}
impl Wait {

View File

@ -2,7 +2,6 @@
use crate::mem;
use core::alloc::Layout;
use core::mem::size_of;
use libsys::error::Errno;
use crate::proc::Process;
@ -100,7 +99,7 @@ fn validate_ptr(base: usize, len: usize, write: bool) -> Result<(), Errno> {
})
} else {
todo!();
Err(Errno::DoesNotExist)
// Err(Errno::DoesNotExist)
};
if res.is_ok() {

View File

@ -191,7 +191,7 @@ pub fn sys_fstatat(
/// System call
#[inline(always)]
pub unsafe fn sys_fork() -> Result<Option<Pid>, Errno> {
Errno::from_syscall(unsafe { syscall!(SystemCall::Fork) }).map(|res| {
Errno::from_syscall(syscall!(SystemCall::Fork)).map(|res| {
if res != 0 {
Some(unsafe { Pid::from_raw(res as u32) })
} else {

View File

@ -1,6 +1,4 @@
use crate::io::{AsRawFd, Error};
use crate::os;
use crate::trace;
use libsys::stat::FileDescriptor;
pub struct File {
@ -8,7 +6,7 @@ pub struct File {
}
impl File {
pub fn open(path: &str) -> Result<File, Error> {
pub fn open(_path: &str) -> Result<File, Error> {
todo!()
}
}

View File

@ -2,6 +2,7 @@ use libsys::error::Errno;
#[derive(Debug)]
pub struct Error {
#[allow(dead_code)]
repr: Repr,
}

View File

@ -27,6 +27,6 @@ pub trait AsRawFd {
pub fn stat(pathname: &str) -> Result<Stat, Error> {
let mut buf = Stat::default();
// TODO error handling
let res = sys_fstatat(None, pathname, &mut buf, 0).unwrap();
sys_fstatat(None, pathname, &mut buf, 0).unwrap();
Ok(buf)
}

View File

@ -1,40 +1,40 @@
use libsys::{
stat::FileDescriptor,
calls::{sys_read, sys_write}
};
use crate::io::{Read, Write, Error};
use crate::sync::{Mutex, MutexGuard};
use crate::io::{Error, Read, Write};
use crate::sync::Mutex;
use core::fmt;
use libsys::{
calls::{sys_read, sys_write},
stat::FileDescriptor,
};
struct InputInner {
fd: FileDescriptor
fd: FileDescriptor,
}
struct OutputInner {
fd: FileDescriptor
fd: FileDescriptor,
}
pub struct StdinLock<'a> {
lock: MutexGuard<'a, InputInner>
}
pub struct StdoutLock<'a> {
lock: MutexGuard<'a, OutputInner>
}
pub struct StderrLock<'a> {
lock: MutexGuard<'a, OutputInner>
}
//pub struct StdinLock<'a> {
// lock: MutexGuard<'a, InputInner>
//}
//
//pub struct StdoutLock<'a> {
// lock: MutexGuard<'a, OutputInner>
//}
//
//pub struct StderrLock<'a> {
// lock: MutexGuard<'a, OutputInner>
//}
pub struct Stdin {
inner: &'static Mutex<InputInner>,
}
pub struct Stdout {
inner: &'static Mutex<OutputInner>
inner: &'static Mutex<OutputInner>,
}
pub struct Stderr {
inner: &'static Mutex<OutputInner>
inner: &'static Mutex<OutputInner>,
}
// STDIN
@ -51,6 +51,14 @@ impl Read for Stdin {
}
}
// impl Stdin {
// pub fn lock(&self) -> StdinLock {
// StdinLock {
// lock: self.inner.lock()
// }
// }
// }
// STDOUT/STDERR
impl fmt::Write for OutputInner {
@ -89,21 +97,21 @@ impl Write for Stderr {
}
}
impl Stdout {
pub fn lock(&self) -> StdoutLock {
StdoutLock {
lock: self.inner.lock()
}
}
}
impl Stderr {
pub fn lock(&self) -> StderrLock {
StderrLock {
lock: self.inner.lock()
}
}
}
// impl Stdout {
// pub fn lock(&self) -> StdoutLock {
// StdoutLock {
// lock: self.inner.lock()
// }
// }
// }
//
// impl Stderr {
// pub fn lock(&self) -> StderrLock {
// StderrLock {
// lock: self.inner.lock()
// }
// }
// }
lazy_static! {
static ref STDIN: Mutex<InputInner> = Mutex::new(InputInner {

View File

@ -1,5 +1,5 @@
use core::fmt;
use crate::io::{self, Write};
use crate::io::Write;
#[macro_export]
macro_rules! print {

View File

@ -1,7 +1,5 @@
use crate::sys;
use core::fmt;
use core::mem::{size_of, MaybeUninit};
use libsys::{ioctl::IoctlCmd, stat::FileDescriptor, termios::Termios};
#[macro_export]
macro_rules! trace {

View File

@ -1,11 +1,15 @@
use libsys::{calls::{sys_exit, sys_ex_sigreturn}, signal::Signal, proc::ExitCode};
use crate::{trace, thread};
use crate::trace;
use libsys::{
calls::{sys_ex_sigreturn, sys_exit},
proc::ExitCode,
signal::Signal,
};
#[derive(Clone, Copy)]
pub enum SignalHandler {
Func(fn(Signal) -> ()),
Ignore,
Terminate
Terminate,
}
// TODO per-thread signal handler table

View File

@ -23,11 +23,6 @@ impl RawMutex {
self.inner.compare_exchange_weak(false, true, Ordering::Acquire, Ordering::Relaxed).is_ok()
}
#[inline]
unsafe fn is_locked(&self) -> bool {
self.inner.load(Ordering::Acquire)
}
#[inline]
pub unsafe fn lock(&self) {
while !self.try_lock() {

View File

@ -1,15 +1,13 @@
use crate::signal;
use alloc::{boxed::Box, sync::Arc, vec};
use core::any::Any;
use core::cell::UnsafeCell;
use core::fmt;
use core::mem::MaybeUninit;
use libsys::{
calls::{sys_ex_clone, sys_ex_signal, sys_ex_thread_exit, sys_ex_thread_wait, sys_ex_gettid},
error::Errno,
calls::{sys_ex_clone, sys_ex_gettid, sys_ex_signal, sys_ex_thread_exit, sys_ex_thread_wait},
proc::ExitCode,
};
use core::sync::atomic::{AtomicU32, Ordering};
use core::any::Any;
use crate::{trace, signal};
use core::fmt;
struct NativeData<F, T>
where
@ -24,7 +22,7 @@ where
#[derive(Clone)]
pub struct Thread {
id: u32
id: u32,
}
pub type ThreadResult<T> = Result<T, Box<dyn Any + Send + Sync>>;
@ -32,7 +30,7 @@ pub type ThreadPacket<T> = Arc<UnsafeCell<MaybeUninit<ThreadResult<T>>>>;
pub struct JoinHandle<T> {
native: u32,
result: ThreadPacket<T>
result: ThreadPacket<T>,
}
impl Thread {
@ -43,26 +41,33 @@ impl Thread {
impl fmt::Debug for Thread {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("Thread").field("id", &self.id).finish_non_exhaustive()
f.debug_struct("Thread")
.field("id", &self.id)
.finish_non_exhaustive()
}
}
impl<T> JoinHandle<T> {
pub fn join(self) -> ThreadResult<T> {
sys_ex_thread_wait(self.native).unwrap();
unsafe { Arc::try_unwrap(self.result).unwrap().into_inner().assume_init() }
unsafe {
Arc::try_unwrap(self.result)
.unwrap()
.into_inner()
.assume_init()
}
}
}
unsafe fn init_common(signal_stack_pointer: *mut u8) {
let tid = sys_ex_gettid();
asm!("msr tpidr_el0, {}", in(reg) tid);
let tid = sys_ex_gettid() as u64;
asm!("msr tpidr_el0, {:x}", in(reg) tid);
// thread::current() should be valid at this point
sys_ex_signal(
signal::signal_handler as usize,
signal_stack_pointer as usize
signal_stack_pointer as usize,
)
.unwrap();
}
@ -70,19 +75,19 @@ unsafe fn init_common(signal_stack_pointer: *mut u8) {
pub(crate) unsafe fn init_main() {
#[repr(align(16))]
struct StackWrapper {
data: [u8; 8192]
data: [u8; 8192],
}
static mut STACK: StackWrapper = StackWrapper { data: [0; 8192] };
init_common(STACK.data.as_mut_ptr().add(8192))
}
pub fn current() -> Thread {
let mut id: u32;
let mut id: u64;
unsafe {
asm!("mrs {}, tpidr_el0", out(reg) id);
asm!("mrs {:x}, tpidr_el0", out(reg) id);
}
Thread { id }
Thread { id: id as u32 }
}
pub fn spawn<F, T>(f: F) -> JoinHandle<T>
@ -101,7 +106,7 @@ where
F: Send + 'static,
T: Send + 'static,
{
let (stack, len) = {
let (_stack, _len) = {
// Setup signal handling
let mut signal_stack = vec![0u8; 8192];
@ -123,7 +128,7 @@ where
sys_ex_thread_exit(ExitCode::from(0));
}
let native = unsafe {
let native = {
let stack = stack.as_mut_ptr() as usize + stack.len();
let data: *mut NativeData<F, T> = Box::into_raw(Box::new(NativeData {
closure: f,

View File

@ -2,11 +2,13 @@
#![no_std]
#![no_main]
#![allow(unused_macros)]
#![allow(dead_code)]
#[macro_use]
extern crate libusr;
use libusr::sys::{abi::SystemCall, stat::Stat, Signal};
use libusr::signal::{self, SignalHandler};
use libusr::sys::{abi::SystemCall, stat::Stat};
static mut STATE: u64 = 0;
@ -115,9 +117,10 @@ fn main() -> i32 {
// Test sys_ex_getcputime()
let mut prev_time = libusr::sys::sys_ex_getcputime().unwrap().as_nanos();
for _ in 0..100000 {
for _ in 0..1000 {
let t = libusr::sys::sys_ex_getcputime().unwrap().as_nanos();
assert!(t >= prev_time);
prev_time = t;
}
// Test non-utf8 input fed into syscalls expecting strings

View File

@ -6,7 +6,7 @@ extern crate libusr;
extern crate alloc;
use alloc::borrow::ToOwned;
use libusr::sys::{sys_faccessat, sys_exit, sys_execve, sys_waitpid, sys_fork, ExitCode, Errno, AccessMode};
use libusr::sys::{sys_exit, sys_execve, sys_waitpid, sys_fork, ExitCode, Errno};
use libusr::io::{self, Read};
fn readline<'a, F: Read>(f: &mut F, bytes: &'a mut [u8]) -> Result<Option<&'a str>, io::Error> {
@ -19,7 +19,7 @@ fn readline<'a, F: Read>(f: &mut F, bytes: &'a mut [u8]) -> Result<Option<&'a st
}
fn execvp(cmd: &str) -> ! {
sys_execve(&("/bin/".to_owned() + cmd));
sys_execve(&("/bin/".to_owned() + cmd)).unwrap();
sys_exit(ExitCode::from(-1));
}
@ -52,7 +52,7 @@ fn main() -> i32 {
continue;
}
execute(line);
execute(line).ok();
}
0
}