Fix clippy.sh script and fix a number of clippy warnings
This commit is contained in:
@@ -172,8 +172,8 @@ impl Iterator for DmarIter {
|
||||
type Item = DmarEntry;
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
if self.i + 4 <= self.sdt.data_len() {
|
||||
let entry_type = unsafe { *((self.sdt.data_address() as *const u8).offset(self.i as isize) as *const u16) };
|
||||
let entry_len = unsafe { *((self.sdt.data_address() as *const u8).offset(self.i as isize + 2) as *const u16) } as usize;
|
||||
let entry_type = unsafe { *((self.sdt.data_address() as *const u8).add(self.i) as *const u16) };
|
||||
let entry_len = unsafe { *((self.sdt.data_address() as *const u8).add(self.i + 2) as *const u16) } as usize;
|
||||
|
||||
if self.i + entry_len <= self.sdt.data_len() {
|
||||
let item = match entry_type {
|
||||
|
||||
@@ -226,8 +226,8 @@ impl Iterator for MadtIter {
|
||||
type Item = MadtEntry;
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
if self.i + 1 < self.sdt.data_len() {
|
||||
let entry_type = unsafe { *(self.sdt.data_address() as *const u8).offset(self.i as isize) };
|
||||
let entry_len = unsafe { *(self.sdt.data_address() as *const u8).offset(self.i as isize + 1) } as usize;
|
||||
let entry_type = unsafe { *(self.sdt.data_address() as *const u8).add(self.i) };
|
||||
let entry_len = unsafe { *(self.sdt.data_address() as *const u8).add(self.i + 1) } as usize;
|
||||
|
||||
if self.i + entry_len <= self.sdt.data_len() {
|
||||
let item = match entry_type {
|
||||
|
||||
@@ -35,7 +35,7 @@ impl Iterator for RsdtIter {
|
||||
type Item = usize;
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
if self.i < self.sdt.data_len()/mem::size_of::<u32>() {
|
||||
let item = unsafe { *(self.sdt.data_address() as *const u32).offset(self.i as isize) };
|
||||
let item = unsafe { *(self.sdt.data_address() as *const u32).add(self.i) };
|
||||
self.i += 1;
|
||||
Some(item as usize)
|
||||
} else {
|
||||
|
||||
@@ -35,7 +35,7 @@ impl Iterator for XsdtIter {
|
||||
type Item = usize;
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
if self.i < self.sdt.data_len()/mem::size_of::<u64>() {
|
||||
let item = unsafe { *(self.sdt.data_address() as *const u64).offset(self.i as isize) };
|
||||
let item = unsafe { *(self.sdt.data_address() as *const u64).add(self.i) };
|
||||
self.i += 1;
|
||||
Some(item as usize)
|
||||
} else {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use core::alloc::{AllocErr, GlobalAlloc, Layout};
|
||||
use core::ptr::NonNull;
|
||||
use core::ptr::{self, NonNull};
|
||||
use linked_list_allocator::Heap;
|
||||
use spin::Mutex;
|
||||
|
||||
@@ -40,7 +40,7 @@ unsafe impl GlobalAlloc for Allocator {
|
||||
panic!("__rust_allocate: heap not initialized");
|
||||
}
|
||||
},
|
||||
other => return other.ok().map_or(0 as *mut u8, |allocation| allocation.as_ptr()),
|
||||
other => return other.ok().map_or(ptr::null_mut(), |allocation| allocation.as_ptr()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,19 +8,19 @@ pub fn cpu_info<W: Write>(w: &mut W) -> Result {
|
||||
let cpuid = CpuId::new();
|
||||
|
||||
if let Some(info) = cpuid.get_vendor_info() {
|
||||
write!(w, "Vendor: {}\n", info.as_string())?;
|
||||
writeln!(w, "Vendor: {}", info.as_string())?;
|
||||
}
|
||||
|
||||
if let Some(info) = cpuid.get_extended_function_info() {
|
||||
if let Some(brand) = info.processor_brand_string() {
|
||||
write!(w, "Model: {}\n", brand)?;
|
||||
writeln!(w, "Model: {}", brand)?;
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(info) = cpuid.get_processor_frequency_info() {
|
||||
write!(w, "CPU Base MHz: {}\n", info.processor_base_frequency())?;
|
||||
write!(w, "CPU Max MHz: {}\n", info.processor_max_frequency())?;
|
||||
write!(w, "Bus MHz: {}\n", info.bus_frequency())?;
|
||||
writeln!(w, "CPU Base MHz: {}", info.processor_base_frequency())?;
|
||||
writeln!(w, "CPU Max MHz: {}", info.processor_max_frequency())?;
|
||||
writeln!(w, "Bus MHz: {}", info.bus_frequency())?;
|
||||
}
|
||||
|
||||
write!(w, "Features:")?;
|
||||
@@ -120,7 +120,7 @@ pub fn cpu_info<W: Write>(w: &mut W) -> Result {
|
||||
if info.has_mpx() { write!(w, " mpx")? };
|
||||
}
|
||||
|
||||
write!(w, "\n")?;
|
||||
writeln!(w)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -188,7 +188,7 @@ impl GdtEntry {
|
||||
limitl: limit as u16,
|
||||
offsetl: offset as u16,
|
||||
offsetm: (offset >> 16) as u8,
|
||||
access: access,
|
||||
access,
|
||||
flags_limith: flags & 0xF0 | ((limit >> 16) as u8) & 0x0F,
|
||||
offseth: (offset >> 24) as u8
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ impl Display {
|
||||
let size = self.offscreen.len() - offset;
|
||||
unsafe {
|
||||
let to = self.offscreen.as_mut_ptr();
|
||||
let from = to.offset(offset as isize);
|
||||
let from = to.add(offset);
|
||||
fast_copy(to as *mut u8, from as *const u8, size * 4);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,7 +134,7 @@ impl Mapper {
|
||||
self.map_to(page, frame, flags)
|
||||
}
|
||||
|
||||
fn unmap_inner(&mut self, page: &Page, keep_parents: bool) -> Frame {
|
||||
fn unmap_inner(&mut self, page: Page, keep_parents: bool) -> Frame {
|
||||
let frame;
|
||||
|
||||
let p4 = self.p4_mut();
|
||||
@@ -203,14 +203,14 @@ impl Mapper {
|
||||
|
||||
/// Unmap a page
|
||||
pub fn unmap(&mut self, page: Page) -> MapperFlush {
|
||||
let frame = self.unmap_inner(&page, false);
|
||||
let frame = self.unmap_inner(page, false);
|
||||
deallocate_frames(frame, 1);
|
||||
MapperFlush::new(page)
|
||||
}
|
||||
|
||||
/// Unmap a page, return frame without free
|
||||
pub fn unmap_return(&mut self, page: Page, keep_parents: bool) -> (MapperFlush, Frame) {
|
||||
let frame = self.unmap_inner(&page, keep_parents);
|
||||
let frame = self.unmap_inner(page, keep_parents);
|
||||
(MapperFlush::new(page), frame)
|
||||
}
|
||||
|
||||
|
||||
@@ -393,23 +393,23 @@ pub struct Page {
|
||||
}
|
||||
|
||||
impl Page {
|
||||
pub fn start_address(&self) -> VirtualAddress {
|
||||
pub fn start_address(self) -> VirtualAddress {
|
||||
VirtualAddress::new(self.number * PAGE_SIZE)
|
||||
}
|
||||
|
||||
pub fn p4_index(&self) -> usize {
|
||||
pub fn p4_index(self) -> usize {
|
||||
(self.number >> 27) & 0o777
|
||||
}
|
||||
|
||||
pub fn p3_index(&self) -> usize {
|
||||
pub fn p3_index(self) -> usize {
|
||||
(self.number >> 18) & 0o777
|
||||
}
|
||||
|
||||
pub fn p2_index(&self) -> usize {
|
||||
pub fn p2_index(self) -> usize {
|
||||
(self.number >> 9) & 0o777
|
||||
}
|
||||
|
||||
pub fn p1_index(&self) -> usize {
|
||||
pub fn p1_index(self) -> usize {
|
||||
self.number & 0o777
|
||||
}
|
||||
|
||||
@@ -420,10 +420,7 @@ impl Page {
|
||||
}
|
||||
|
||||
pub fn range_inclusive(start: Page, end: Page) -> PageIter {
|
||||
PageIter {
|
||||
start: start,
|
||||
end: end,
|
||||
}
|
||||
PageIter { start, end }
|
||||
}
|
||||
|
||||
pub fn next(self) -> Page {
|
||||
|
||||
@@ -9,7 +9,7 @@ use crate::memory::allocate_frames;
|
||||
use super::entry::{EntryFlags, Entry};
|
||||
use super::ENTRY_COUNT;
|
||||
|
||||
pub const P4: *mut Table<Level4> = (crate::RECURSIVE_PAGE_OFFSET | 0x7ffffff000) as *mut _;
|
||||
pub const P4: *mut Table<Level4> = (crate::RECURSIVE_PAGE_OFFSET | 0x7f_ffff_f000) as *mut _;
|
||||
|
||||
pub trait TableLevel {}
|
||||
|
||||
|
||||
@@ -13,9 +13,7 @@ pub struct TemporaryPage {
|
||||
|
||||
impl TemporaryPage {
|
||||
pub fn new(page: Page) -> TemporaryPage {
|
||||
TemporaryPage {
|
||||
page: page,
|
||||
}
|
||||
TemporaryPage { page }
|
||||
}
|
||||
|
||||
pub fn start_address (&self) -> VirtualAddress {
|
||||
|
||||
@@ -22,7 +22,7 @@ impl<T> Unique<T> {
|
||||
pub unsafe fn new_unchecked(ptr: *mut T) -> Self {
|
||||
Self(NonNull::new_unchecked(ptr))
|
||||
}
|
||||
pub fn as_ptr(&self) -> *mut T {
|
||||
pub fn as_ptr(self) -> *mut T {
|
||||
self.0.as_ptr()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,18 +76,20 @@ impl Context {
|
||||
if !self.loadable {
|
||||
return false;
|
||||
}
|
||||
let old = unsafe { &*(self.fx as *const FloatRegisters) };
|
||||
new._reserved = old._reserved;
|
||||
let old_st = new.st_space;
|
||||
let mut new_st = new.st_space;
|
||||
for (new_st, old_st) in new_st.iter_mut().zip(&old_st) {
|
||||
*new_st &= !ST_RESERVED;
|
||||
*new_st |= old_st & ST_RESERVED;
|
||||
}
|
||||
new.st_space = new_st;
|
||||
|
||||
// Make sure we don't use `old` from now on
|
||||
drop(old);
|
||||
{
|
||||
let old = unsafe { &*(self.fx as *const FloatRegisters) };
|
||||
new._reserved = old._reserved;
|
||||
let old_st = new.st_space;
|
||||
let mut new_st = new.st_space;
|
||||
for (new_st, old_st) in new_st.iter_mut().zip(&old_st) {
|
||||
*new_st &= !ST_RESERVED;
|
||||
*new_st |= old_st & ST_RESERVED;
|
||||
}
|
||||
new.st_space = new_st;
|
||||
|
||||
// Make sure we don't use `old` from now on
|
||||
}
|
||||
|
||||
unsafe {
|
||||
*(self.fx as *mut FloatRegisters) = new;
|
||||
|
||||
@@ -183,7 +183,7 @@ impl Context {
|
||||
let syscall_tail = unsafe { Box::from_raw(crate::ALLOCATOR.alloc(Layout::from_size_align_unchecked(PAGE_SIZE, PAGE_SIZE)) as *mut [u8; PAGE_SIZE]) };
|
||||
|
||||
Context {
|
||||
id: id,
|
||||
id,
|
||||
pgid: id,
|
||||
ppid: ContextId::from(0),
|
||||
ruid: 0,
|
||||
@@ -198,8 +198,8 @@ impl Context {
|
||||
running: false,
|
||||
cpu_id: None,
|
||||
syscall: None,
|
||||
syscall_head: syscall_head,
|
||||
syscall_tail: syscall_tail,
|
||||
syscall_head,
|
||||
syscall_tail,
|
||||
vfork: false,
|
||||
waitpid: Arc::new(WaitMap::new()),
|
||||
pending: VecDeque::new(),
|
||||
|
||||
@@ -83,7 +83,7 @@ impl ContextList {
|
||||
let offset = stack.len() - mem::size_of::<usize>();
|
||||
unsafe {
|
||||
let offset = stack.len() - mem::size_of::<usize>();
|
||||
let func_ptr = stack.as_mut_ptr().offset(offset as isize);
|
||||
let func_ptr = stack.as_mut_ptr().add(offset);
|
||||
*(func_ptr as *mut usize) = func as usize;
|
||||
}
|
||||
context.arch.set_page_table(unsafe { paging::ActivePageTable::new().address() });
|
||||
|
||||
@@ -312,9 +312,9 @@ pub struct Memory {
|
||||
impl Memory {
|
||||
pub fn new(start: VirtualAddress, size: usize, flags: EntryFlags, clear: bool) -> Self {
|
||||
let mut memory = Memory {
|
||||
start: start,
|
||||
size: size,
|
||||
flags: flags
|
||||
start,
|
||||
size,
|
||||
flags,
|
||||
};
|
||||
|
||||
memory.map(clear);
|
||||
|
||||
@@ -99,7 +99,7 @@ pub unsafe fn switch() -> bool {
|
||||
let mut context = context_lock.write();
|
||||
if runnable(&mut context, cpu_id) {
|
||||
to_ptr = context.deref_mut() as *mut Context;
|
||||
if (&mut *to_ptr).ksig.is_none() {
|
||||
if (*to_ptr).ksig.is_none() {
|
||||
to_sig = context.pending.pop_front();
|
||||
}
|
||||
break;
|
||||
@@ -113,7 +113,7 @@ pub unsafe fn switch() -> bool {
|
||||
let mut context = context_lock.write();
|
||||
if runnable(&mut context, cpu_id) {
|
||||
to_ptr = context.deref_mut() as *mut Context;
|
||||
if (&mut *to_ptr).ksig.is_none() {
|
||||
if (*to_ptr).ksig.is_none() {
|
||||
to_sig = context.pending.pop_front();
|
||||
}
|
||||
break;
|
||||
@@ -125,13 +125,13 @@ pub unsafe fn switch() -> bool {
|
||||
|
||||
// Switch process states, TSS stack pointer, and store new context ID
|
||||
if to_ptr as usize != 0 {
|
||||
(&mut *from_ptr).running = false;
|
||||
(&mut *to_ptr).running = true;
|
||||
(*from_ptr).running = false;
|
||||
(*to_ptr).running = true;
|
||||
if let Some(ref stack) = (*to_ptr).kstack {
|
||||
gdt::set_tss_stack(stack.as_ptr() as usize + stack.len());
|
||||
}
|
||||
gdt::set_tcb((&mut *to_ptr).id.into());
|
||||
CONTEXT_ID.store((&mut *to_ptr).id, Ordering::SeqCst);
|
||||
gdt::set_tcb((*to_ptr).id.into());
|
||||
CONTEXT_ID.store((*to_ptr).id, Ordering::SeqCst);
|
||||
}
|
||||
|
||||
// Unset global lock before switch, as arch is only usable by the current CPU at this time
|
||||
@@ -146,16 +146,16 @@ pub unsafe fn switch() -> bool {
|
||||
// Signal was found, run signal handler
|
||||
|
||||
//TODO: Allow nested signals
|
||||
assert!((&mut *to_ptr).ksig.is_none());
|
||||
assert!((*to_ptr).ksig.is_none());
|
||||
|
||||
let arch = (&mut *to_ptr).arch.clone();
|
||||
let kfx = (&mut *to_ptr).kfx.clone();
|
||||
let kstack = (&mut *to_ptr).kstack.clone();
|
||||
(&mut *to_ptr).ksig = Some((arch, kfx, kstack, sig));
|
||||
(&mut *to_ptr).arch.signal_stack(signal_handler, sig);
|
||||
let arch = (*to_ptr).arch.clone();
|
||||
let kfx = (*to_ptr).kfx.clone();
|
||||
let kstack = (*to_ptr).kstack.clone();
|
||||
(*to_ptr).ksig = Some((arch, kfx, kstack, sig));
|
||||
(*to_ptr).arch.signal_stack(signal_handler, sig);
|
||||
}
|
||||
|
||||
(&mut *from_ptr).arch.switch_to(&mut (&mut *to_ptr).arch);
|
||||
(*from_ptr).arch.switch_to(&mut (*to_ptr).arch);
|
||||
|
||||
true
|
||||
}
|
||||
|
||||
@@ -32,9 +32,9 @@ fn registry() -> MutexGuard<'static, Registry> {
|
||||
pub fn register(scheme_id: SchemeId, event_id: usize, clock: usize, time: TimeSpec) {
|
||||
let mut registry = registry();
|
||||
registry.push_back(Timeout {
|
||||
scheme_id: scheme_id,
|
||||
event_id: event_id,
|
||||
clock: clock,
|
||||
scheme_id,
|
||||
event_id,
|
||||
clock,
|
||||
time: (time.tv_sec as u64, time.tv_nsec as u64)
|
||||
});
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ impl<'a> Elf<'a> {
|
||||
Err(format!("Elf: Invalid architecture: {:?} != {:?}", data.get(header::EI_CLASS), header::ELFCLASS))
|
||||
} else {
|
||||
Ok(Elf {
|
||||
data: data,
|
||||
data,
|
||||
header: unsafe { &*(data.as_ptr() as usize as *const header::Header) }
|
||||
})
|
||||
}
|
||||
@@ -61,7 +61,7 @@ impl<'a> Elf<'a> {
|
||||
if let Some(symtab) = symtab_opt {
|
||||
Some(ElfSymbols {
|
||||
data: self.data,
|
||||
symtab: symtab,
|
||||
symtab,
|
||||
i: 0
|
||||
})
|
||||
} else {
|
||||
|
||||
@@ -20,7 +20,7 @@ pub struct EventQueue {
|
||||
impl EventQueue {
|
||||
pub fn new(id: EventQueueId) -> EventQueue {
|
||||
EventQueue {
|
||||
id: id,
|
||||
id,
|
||||
queue: WaitQueue::new()
|
||||
}
|
||||
}
|
||||
|
||||
32
src/lib.rs
32
src/lib.rs
@@ -3,16 +3,30 @@
|
||||
//! The Redox OS Kernel is a microkernel that supports `x86_64` systems and
|
||||
//! provides Unix-like syscalls for primarily Rust applications
|
||||
|
||||
//#![deny(warnings)]
|
||||
#![cfg_attr(feature = "clippy", allow(if_same_then_else))]
|
||||
#![cfg_attr(feature = "clippy", allow(inline_always))]
|
||||
#![cfg_attr(feature = "clippy", allow(many_single_char_names))]
|
||||
#![cfg_attr(feature = "clippy", allow(module_inception))]
|
||||
#![cfg_attr(feature = "clippy", allow(new_without_default))]
|
||||
#![cfg_attr(feature = "clippy", allow(not_unsafe_ptr_arg_deref))]
|
||||
#![cfg_attr(feature = "clippy", allow(or_fun_call))]
|
||||
#![cfg_attr(feature = "clippy", allow(too_many_arguments))]
|
||||
// Useful for adding comments about different branches
|
||||
#![allow(clippy::if_same_then_else)]
|
||||
// Useful in the syscall function
|
||||
#![allow(clippy::many_single_char_names)]
|
||||
// Used for context::context
|
||||
#![allow(clippy::module_inception)]
|
||||
// Not implementing default is sometimes useful in the case something has significant cost
|
||||
// to allocate. If you implement default, it can be allocated without evidence using the
|
||||
// ..Default::default() syntax. Not fun in kernel space
|
||||
#![allow(clippy::new_without_default)]
|
||||
// Used to make it nicer to return errors, for example, .ok_or(Error::new(ESRCH))
|
||||
#![allow(clippy::or_fun_call)]
|
||||
// This is needed in some cases, like for syscall
|
||||
#![allow(clippy::too_many_arguments)]
|
||||
// There is no harm in this being done
|
||||
#![allow(clippy::useless_format)]
|
||||
// TODO: address ocurrances and then deny
|
||||
#![warn(clippy::not_unsafe_ptr_arg_deref)]
|
||||
// TODO: address ocurrances and then deny
|
||||
#![warn(clippy::cast_ptr_alignment)]
|
||||
// This is usually a serious issue - a missing import of a define where it is interpreted
|
||||
// as a catch-all variable in a match, for example
|
||||
#![deny(unreachable_patterns)]
|
||||
|
||||
#![feature(allocator_api)]
|
||||
#![feature(asm)]
|
||||
#![feature(concat_idents)]
|
||||
|
||||
@@ -16,7 +16,7 @@ impl Log {
|
||||
pub fn new(size: usize) -> Log {
|
||||
Log {
|
||||
data: VecDeque::with_capacity(size),
|
||||
size: size
|
||||
size
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ pub struct MemoryAreaIter {
|
||||
impl MemoryAreaIter {
|
||||
fn new(_type: u32) -> Self {
|
||||
MemoryAreaIter {
|
||||
_type: _type,
|
||||
_type,
|
||||
i: 0
|
||||
}
|
||||
}
|
||||
@@ -73,7 +73,7 @@ static ALLOCATOR: Mutex<Option<RecycleAllocator<BumpAllocator>>> = Mutex::new(No
|
||||
pub unsafe fn init(kernel_start: usize, kernel_end: usize) {
|
||||
// Copy memory map from bootloader location
|
||||
for (i, entry) in MEMORY_MAP.iter_mut().enumerate() {
|
||||
*entry = *(0x500 as *const MemoryArea).offset(i as isize);
|
||||
*entry = *(0x500 as *const MemoryArea).add(i);
|
||||
if entry._type != MEMORY_AREA_NULL {
|
||||
println!("{:?}", entry);
|
||||
}
|
||||
@@ -157,10 +157,7 @@ impl Frame {
|
||||
|
||||
//TODO: Set private
|
||||
pub fn range_inclusive(start: Frame, end: Frame) -> FrameIter {
|
||||
FrameIter {
|
||||
start: start,
|
||||
end: end,
|
||||
}
|
||||
FrameIter { start, end }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ pub struct RecycleAllocator<T: FrameAllocator> {
|
||||
impl<T: FrameAllocator> RecycleAllocator<T> {
|
||||
pub fn new(inner: T) -> Self {
|
||||
Self {
|
||||
inner: inner,
|
||||
inner,
|
||||
noncore: false,
|
||||
free: Vec::new(),
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ use crate::sync::WaitQueue;
|
||||
use crate::syscall::flag::{EventFlags, EVENT_READ, F_GETFL, F_SETFL, O_ACCMODE, O_NONBLOCK};
|
||||
use crate::syscall::scheme::Scheme;
|
||||
|
||||
pub static DEBUG_SCHEME_ID: AtomicSchemeId = ATOMIC_SCHEMEID_INIT;
|
||||
pub static DEBUG_SCHEME_ID: AtomicSchemeId = AtomicSchemeId::default();
|
||||
|
||||
/// Input queue
|
||||
static INPUT: Once<WaitQueue<u8>> = Once::new();
|
||||
|
||||
@@ -4,12 +4,12 @@ use spin::Mutex;
|
||||
|
||||
use crate::event;
|
||||
use crate::interrupt::irq::acknowledge;
|
||||
use crate::scheme::{AtomicSchemeId, ATOMIC_SCHEMEID_INIT, SchemeId};
|
||||
use crate::scheme::{AtomicSchemeId, SchemeId};
|
||||
use crate::syscall::error::*;
|
||||
use crate::syscall::flag::{EventFlags, EVENT_READ};
|
||||
use crate::syscall::scheme::Scheme;
|
||||
|
||||
pub static IRQ_SCHEME_ID: AtomicSchemeId = ATOMIC_SCHEMEID_INIT;
|
||||
pub static IRQ_SCHEME_ID: AtomicSchemeId = AtomicSchemeId::default();
|
||||
|
||||
/// IRQ queues
|
||||
static ACKS: Mutex<[usize; 16]> = Mutex::new([0; 16]);
|
||||
|
||||
@@ -77,8 +77,6 @@ int_like!(SchemeNamespace, AtomicSchemeNamespace, usize, AtomicUsize);
|
||||
// Unique identifier for a scheme.
|
||||
int_like!(SchemeId, AtomicSchemeId, usize, AtomicUsize);
|
||||
|
||||
pub const ATOMIC_SCHEMEID_INIT: AtomicSchemeId = AtomicSchemeId::default();
|
||||
|
||||
// Unique identifier for a file descriptor.
|
||||
int_like!(FileHandle, AtomicFileHandle, usize, AtomicUsize);
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ use core::sync::atomic::{AtomicUsize, Ordering};
|
||||
use spin::{Mutex, Once, RwLock, RwLockReadGuard, RwLockWriteGuard};
|
||||
|
||||
use crate::event;
|
||||
use crate::scheme::{AtomicSchemeId, ATOMIC_SCHEMEID_INIT, SchemeId};
|
||||
use crate::scheme::{AtomicSchemeId, SchemeId};
|
||||
use crate::sync::WaitCondition;
|
||||
use crate::syscall::error::{Error, Result, EAGAIN, EBADF, EINTR, EINVAL, EPIPE, ESPIPE};
|
||||
use crate::syscall::flag::{EventFlags, EVENT_READ, EVENT_WRITE, F_GETFL, F_SETFL, O_ACCMODE, O_NONBLOCK, MODE_FIFO};
|
||||
@@ -12,7 +12,7 @@ use crate::syscall::scheme::Scheme;
|
||||
use crate::syscall::data::Stat;
|
||||
|
||||
/// Pipes list
|
||||
pub static PIPE_SCHEME_ID: AtomicSchemeId = ATOMIC_SCHEMEID_INIT;
|
||||
pub static PIPE_SCHEME_ID: AtomicSchemeId = AtomicSchemeId::default();
|
||||
static PIPE_NEXT_ID: AtomicUsize = AtomicUsize::new(0);
|
||||
static PIPES: Once<RwLock<(BTreeMap<usize, Arc<PipeRead>>, BTreeMap<usize, Arc<PipeWrite>>)>> = Once::new();
|
||||
|
||||
@@ -204,10 +204,8 @@ impl PipeRead {
|
||||
return Ok(0);
|
||||
} else if self.flags.load(Ordering::SeqCst) & O_NONBLOCK == O_NONBLOCK {
|
||||
return Err(Error::new(EAGAIN));
|
||||
} else {
|
||||
if ! self.condition.wait() {
|
||||
return Err(Error::new(EINTR));
|
||||
}
|
||||
} else if ! self.condition.wait() {
|
||||
return Err(Error::new(EINTR));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ use crate::{
|
||||
arch::paging::VirtualAddress,
|
||||
context::{self, Context, ContextId, Status},
|
||||
ptrace,
|
||||
scheme::{ATOMIC_SCHEMEID_INIT, AtomicSchemeId, SchemeId},
|
||||
scheme::{AtomicSchemeId, SchemeId},
|
||||
syscall::{
|
||||
data::{FloatRegisters, IntRegisters, PtraceEvent},
|
||||
error::*,
|
||||
@@ -167,7 +167,7 @@ impl Handle {
|
||||
}
|
||||
}
|
||||
|
||||
pub static PROC_SCHEME_ID: AtomicSchemeId = ATOMIC_SCHEMEID_INIT;
|
||||
pub static PROC_SCHEME_ID: AtomicSchemeId = AtomicSchemeId::default();
|
||||
|
||||
pub struct ProcScheme {
|
||||
next_id: AtomicUsize,
|
||||
@@ -520,8 +520,8 @@ impl Scheme for ProcScheme {
|
||||
|
||||
match cmd {
|
||||
F_SETFL => { handle.info.flags = arg; Ok(0) },
|
||||
F_GETFL => return Ok(handle.info.flags),
|
||||
_ => return Err(Error::new(EINVAL))
|
||||
F_GETFL => Ok(handle.info.flags),
|
||||
_ => Err(Error::new(EINVAL))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -63,8 +63,8 @@ pub struct RootScheme {
|
||||
impl RootScheme {
|
||||
pub fn new(scheme_ns: SchemeNamespace, scheme_id: SchemeId) -> RootScheme {
|
||||
RootScheme {
|
||||
scheme_ns: scheme_ns,
|
||||
scheme_id: scheme_id,
|
||||
scheme_ns,
|
||||
scheme_id,
|
||||
next_id: AtomicUsize::new(0),
|
||||
handles: RwLock::new(BTreeMap::new()),
|
||||
}
|
||||
|
||||
@@ -40,19 +40,19 @@ impl SysScheme {
|
||||
pub fn new() -> SysScheme {
|
||||
let mut files: BTreeMap<&'static [u8], Box<SysFn>> = BTreeMap::new();
|
||||
|
||||
files.insert(b"context", Box::new(move || context::resource()));
|
||||
files.insert(b"cpu", Box::new(move || cpu::resource()));
|
||||
files.insert(b"exe", Box::new(move || exe::resource()));
|
||||
files.insert(b"iostat", Box::new(move || iostat::resource()));
|
||||
files.insert(b"log", Box::new(move || log::resource()));
|
||||
files.insert(b"scheme", Box::new(move || scheme::resource()));
|
||||
files.insert(b"scheme_num", Box::new(move || scheme_num::resource()));
|
||||
files.insert(b"syscall", Box::new(move || syscall::resource()));
|
||||
files.insert(b"uname", Box::new(move || uname::resource()));
|
||||
files.insert(b"context", Box::new(context::resource));
|
||||
files.insert(b"cpu", Box::new(cpu::resource));
|
||||
files.insert(b"exe", Box::new(exe::resource));
|
||||
files.insert(b"iostat", Box::new(iostat::resource));
|
||||
files.insert(b"log", Box::new(log::resource));
|
||||
files.insert(b"scheme", Box::new(scheme::resource));
|
||||
files.insert(b"scheme_num", Box::new(scheme_num::resource));
|
||||
files.insert(b"syscall", Box::new(syscall::resource));
|
||||
files.insert(b"uname", Box::new(uname::resource));
|
||||
|
||||
SysScheme {
|
||||
next_id: AtomicUsize::new(0),
|
||||
files: files,
|
||||
files,
|
||||
handles: RwLock::new(BTreeMap::new())
|
||||
}
|
||||
}
|
||||
@@ -75,7 +75,7 @@ impl Scheme for SysScheme {
|
||||
let id = self.next_id.fetch_add(1, Ordering::SeqCst);
|
||||
self.handles.write().insert(id, Handle {
|
||||
path: b"",
|
||||
data: data,
|
||||
data,
|
||||
mode: MODE_DIR | 0o444,
|
||||
seek: 0
|
||||
});
|
||||
|
||||
@@ -20,7 +20,7 @@ pub struct TimeScheme {
|
||||
impl TimeScheme {
|
||||
pub fn new(scheme_id: SchemeId) -> TimeScheme {
|
||||
TimeScheme {
|
||||
scheme_id: scheme_id,
|
||||
scheme_id,
|
||||
next_id: AtomicUsize::new(0),
|
||||
handles: RwLock::new(BTreeMap::new())
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ use crate::event;
|
||||
use crate::paging::{InactivePageTable, Page, VirtualAddress};
|
||||
use crate::paging::entry::EntryFlags;
|
||||
use crate::paging::temporary_page::TemporaryPage;
|
||||
use crate::scheme::{AtomicSchemeId, ATOMIC_SCHEMEID_INIT, SchemeId};
|
||||
use crate::scheme::{AtomicSchemeId, SchemeId};
|
||||
use crate::sync::{WaitQueue, WaitMap};
|
||||
use crate::syscall::data::{Map, Packet, Stat, StatVfs, TimeSpec};
|
||||
use crate::syscall::error::*;
|
||||
@@ -38,13 +38,13 @@ pub struct UserInner {
|
||||
impl UserInner {
|
||||
pub fn new(root_id: SchemeId, handle_id: usize, name: Box<[u8]>, flags: usize, context: Weak<RwLock<Context>>) -> UserInner {
|
||||
UserInner {
|
||||
root_id: root_id,
|
||||
handle_id: handle_id,
|
||||
name: name,
|
||||
flags: flags,
|
||||
scheme_id: ATOMIC_SCHEMEID_INIT,
|
||||
root_id,
|
||||
handle_id,
|
||||
name,
|
||||
flags,
|
||||
scheme_id: AtomicSchemeId::default(),
|
||||
next_id: AtomicU64::new(1),
|
||||
context: context,
|
||||
context,
|
||||
todo: WaitQueue::new(),
|
||||
fmap: Mutex::new(BTreeMap::new()),
|
||||
funmap: Mutex::new(BTreeMap::new()),
|
||||
@@ -78,12 +78,12 @@ impl UserInner {
|
||||
self.call_inner(Packet {
|
||||
id: self.next_id.fetch_add(1, Ordering::SeqCst),
|
||||
pid: pid.into(),
|
||||
uid: uid,
|
||||
gid: gid,
|
||||
a: a,
|
||||
b: b,
|
||||
c: c,
|
||||
d: d
|
||||
uid,
|
||||
gid,
|
||||
a,
|
||||
b,
|
||||
c,
|
||||
d
|
||||
})
|
||||
}
|
||||
|
||||
@@ -229,7 +229,7 @@ impl UserInner {
|
||||
let len = buf.len()/packet_size;
|
||||
let mut i = 0;
|
||||
while i < len {
|
||||
let mut packet = unsafe { *(buf.as_ptr() as *const Packet).offset(i as isize) };
|
||||
let mut packet = unsafe { *(buf.as_ptr() as *const Packet).add(i) };
|
||||
if packet.id == 0 {
|
||||
match packet.a {
|
||||
SYS_FEVENT => event::trigger(self.scheme_id.load(Ordering::SeqCst), packet.b, EventFlags::from_bits_truncate(packet.c)),
|
||||
@@ -273,9 +273,7 @@ pub struct UserScheme {
|
||||
|
||||
impl UserScheme {
|
||||
pub fn new(inner: Weak<UserInner>) -> UserScheme {
|
||||
UserScheme {
|
||||
inner: inner
|
||||
}
|
||||
UserScheme { inner }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -394,10 +392,10 @@ impl Scheme for UserScheme {
|
||||
inner.fmap.lock().insert(id, (context_lock, desc, *map));
|
||||
|
||||
let result = inner.call_inner(Packet {
|
||||
id: id,
|
||||
id,
|
||||
pid: pid.into(),
|
||||
uid: uid,
|
||||
gid: gid,
|
||||
uid,
|
||||
gid,
|
||||
a: SYS_FMAP,
|
||||
b: file,
|
||||
c: address,
|
||||
|
||||
@@ -29,12 +29,12 @@ pub fn file_op(a: usize, fd: FileHandle, c: usize, d: usize) -> Result<usize> {
|
||||
let mut packet = Packet {
|
||||
id: 0,
|
||||
pid: pid.into(),
|
||||
uid: uid,
|
||||
gid: gid,
|
||||
a: a,
|
||||
uid,
|
||||
gid,
|
||||
a,
|
||||
b: file.description.read().number,
|
||||
c: c,
|
||||
d: d
|
||||
c,
|
||||
d
|
||||
};
|
||||
|
||||
scheme.handle(&mut packet);
|
||||
@@ -406,8 +406,7 @@ pub fn frename(fd: FileHandle, path: &[u8]) -> Result<usize> {
|
||||
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
|
||||
context.get_file(fd).ok_or(Error::new(EBADF))?
|
||||
};
|
||||
|
||||
let (path_canon, uid, gid, scheme_ns) = {
|
||||
|
||||
@@ -149,7 +149,7 @@ pub fn clone(flags: CloneFlags, stack_base: usize) -> Result<ContextId> {
|
||||
// Change the return address of the child
|
||||
// (previously syscall) to the arch-specific
|
||||
// clone_ret callback
|
||||
let func_ptr = new_stack.as_mut_ptr().offset(offset as isize);
|
||||
let func_ptr = new_stack.as_mut_ptr().add(offset);
|
||||
*(func_ptr as *mut usize) = interrupt::syscall::clone_ret as usize;
|
||||
}
|
||||
|
||||
@@ -1044,7 +1044,6 @@ pub fn fexec(fd: FileHandle, arg_ptrs: &[[usize; 2]], var_ptrs: &[[usize; 2]]) -
|
||||
// Argument must be moved into kernel space before exec unmaps all memory
|
||||
args.push(arg.to_vec().into_boxed_slice());
|
||||
}
|
||||
drop(arg_ptrs);
|
||||
|
||||
let mut vars = Vec::new();
|
||||
for var_ptr in var_ptrs {
|
||||
@@ -1052,7 +1051,9 @@ pub fn fexec(fd: FileHandle, arg_ptrs: &[[usize; 2]], var_ptrs: &[[usize; 2]]) -
|
||||
// Argument must be moved into kernel space before exec unmaps all memory
|
||||
vars.push(var.to_vec().into_boxed_slice());
|
||||
}
|
||||
drop(var_ptrs);
|
||||
|
||||
// Neither arg_ptrs nor var_ptrs should be used after this point, the kernel
|
||||
// now has owned copies in args and vars
|
||||
|
||||
fexec_kernel(fd, args.into_boxed_slice(), vars.into_boxed_slice(), None)
|
||||
}
|
||||
@@ -1125,10 +1126,8 @@ pub fn exit(status: usize) -> ! {
|
||||
if let Some(parent_lock) = contexts.get(ppid) {
|
||||
let waitpid = {
|
||||
let mut parent = parent_lock.write();
|
||||
if vfork {
|
||||
if ! parent.unblock() {
|
||||
println!("{}: {} not blocked for exit vfork unblock", pid.into(), ppid.into());
|
||||
}
|
||||
if vfork && ! parent.unblock() {
|
||||
println!("{}: {} not blocked for exit vfork unblock", pid.into(), ppid.into());
|
||||
}
|
||||
Arc::clone(&parent.waitpid)
|
||||
};
|
||||
|
||||
@@ -28,6 +28,7 @@ fn validate(address: usize, size: usize, flags: EntryFlags) -> Result<()> {
|
||||
}
|
||||
|
||||
/// Convert a pointer and length to slice, if valid
|
||||
//TODO: Mark unsafe
|
||||
pub fn validate_slice<T>(ptr: *const T, len: usize) -> Result<&'static [T]> {
|
||||
if len == 0 {
|
||||
Ok(&[])
|
||||
@@ -38,6 +39,7 @@ pub fn validate_slice<T>(ptr: *const T, len: usize) -> Result<&'static [T]> {
|
||||
}
|
||||
|
||||
/// Convert a pointer and length to slice, if valid
|
||||
//TODO: Mark unsafe
|
||||
pub fn validate_slice_mut<T>(ptr: *mut T, len: usize) -> Result<&'static mut [T]> {
|
||||
if len == 0 {
|
||||
Ok(&mut [])
|
||||
|
||||
Reference in New Issue
Block a user