refactor: fix non-doc warnings

This commit is contained in:
2021-11-22 15:42:43 +02:00
parent 4cfa1f2958
commit fabf4e8d3f
21 changed files with 175 additions and 158 deletions
+1 -3
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!()
}
}
+1
View File
@@ -2,6 +2,7 @@ use libsys::error::Errno;
#[derive(Debug)]
pub struct Error {
#[allow(dead_code)]
repr: Repr,
}
+1 -1
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)
}
+44 -36
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 {
+1 -1
View File
@@ -1,5 +1,5 @@
use core::fmt;
use crate::io::{self, Write};
use crate::io::Write;
#[macro_export]
macro_rules! print {
-2
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 {
+7 -3
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
-5
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() {
+24 -19
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,