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 props = self.props.borrow();
let mode = props.mode; let mode = props.mode;

View File

@ -4,7 +4,7 @@ use crate::arch::machine;
use crate::debug::Level; use crate::debug::Level;
use crate::dev::irq::{IntController, IrqContext}; use crate::dev::irq::{IntController, IrqContext};
use crate::mem; use crate::mem;
use crate::proc::{sched, Thread, Process}; use crate::proc::{sched, Thread};
use crate::syscall; use crate::syscall;
use cortex_a::registers::{ESR_EL1, FAR_EL1}; use cortex_a::registers::{ESR_EL1, FAR_EL1};
use libsys::{abi::SystemCall, signal::Signal}; 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]); let num = SystemCall::from_repr(exc.x[8]);
if num.is_none() { if num.is_none() {
todo!(); todo!();
return;
} }
let num = num.unwrap(); let num = num.unwrap();

View File

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

View File

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

View File

@ -6,11 +6,10 @@ use crate::mem::{
virt::{MapAttributes, Space}, virt::{MapAttributes, Space},
}; };
use crate::proc::{ 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 crate::sync::{IrqSafeSpinLock, IrqSafeSpinLockGuard};
use alloc::{rc::Rc, vec::Vec}; use alloc::{rc::Rc, vec::Vec};
use core::cell::UnsafeCell;
use core::sync::atomic::{AtomicU32, Ordering}; use core::sync::atomic::{AtomicU32, Ordering};
use libsys::{ use libsys::{
error::Errno, error::Errno,
@ -108,7 +107,7 @@ impl Process {
/// Sets a pending signal for a process /// Sets a pending signal for a process
pub fn set_signal(&self, signal: Signal) { 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(); let main_thread = Thread::get(lock.threads[0]).unwrap();
// TODO check that `signal` is not a fault signal // 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 = let ttbr0 =
inner.space.as_mut().unwrap().address_phys() | ((inner.id.asid() as usize) << 48); inner.space.as_mut().unwrap().address_phys() | ((inner.id.asid() as usize) << 48);
drop(inner); 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::sync::IrqSafeSpinLock;
use crate::util::InitOnce; use crate::util::InitOnce;
use alloc::{collections::VecDeque, rc::Rc}; 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::proc::{wait::Wait, Process, ProcessRef, SCHED, THREADS};
use crate::sync::IrqSafeSpinLock; use crate::sync::IrqSafeSpinLock;
use crate::util::InitOnce; use crate::util::InitOnce;
use alloc::{rc::Rc, vec::Vec}; use alloc::rc::Rc;
use core::cell::UnsafeCell; use core::cell::UnsafeCell;
use core::sync::atomic::{AtomicU32, Ordering}; 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}; pub use crate::arch::platform::context::{self, Context};
@ -297,7 +301,7 @@ impl Thread {
panic!("Already handling a signal (maybe handle this case)"); 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 { if lock.signal_entry == 0 || lock.signal_stack == 0 {
drop(lock); drop(lock);
Process::exit_thread(self, ExitCode::from(-1)); Process::exit_thread(self, ExitCode::from(-1));
@ -317,7 +321,12 @@ impl Thread {
assert_eq!(lock.state, State::Running); assert_eq!(lock.state, State::Running);
unsafe { 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); drop(lock);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,11 +1,15 @@
use libsys::{calls::{sys_exit, sys_ex_sigreturn}, signal::Signal, proc::ExitCode}; use crate::trace;
use crate::{trace, thread}; use libsys::{
calls::{sys_ex_sigreturn, sys_exit},
proc::ExitCode,
signal::Signal,
};
#[derive(Clone, Copy)] #[derive(Clone, Copy)]
pub enum SignalHandler { pub enum SignalHandler {
Func(fn(Signal) -> ()), Func(fn(Signal) -> ()),
Ignore, Ignore,
Terminate Terminate,
} }
// TODO per-thread signal handler table // 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() 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] #[inline]
pub unsafe fn lock(&self) { pub unsafe fn lock(&self) {
while !self.try_lock() { while !self.try_lock() {

View File

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

View File

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

View File

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