diff --git a/crate/memory/src/paging/mod.rs b/crate/memory/src/paging/mod.rs index ccb2a0e..322df2c 100644 --- a/crate/memory/src/paging/mod.rs +++ b/crate/memory/src/paging/mod.rs @@ -3,7 +3,6 @@ //! Implemented for every architecture, used by OS. use super::*; -use log::*; #[cfg(test)] pub use self::mock_page_table::MockPageTable; pub use self::ext::*; diff --git a/crate/memory/src/swap/mod.rs b/crate/memory/src/swap/mod.rs index 14a027a..5f47391 100644 --- a/crate/memory/src/swap/mod.rs +++ b/crate/memory/src/swap/mod.rs @@ -296,7 +296,7 @@ impl SwapExt { entry.set_present(true); entry.update(); } - if(swapin){ + if swapin { unsafe { self.set_swappable(pt, addr & 0xfffff000); } diff --git a/crate/process/src/process_manager.rs b/crate/process/src/process_manager.rs index b6e8af6..d052470 100644 --- a/crate/process/src/process_manager.rs +++ b/crate/process/src/process_manager.rs @@ -1,9 +1,7 @@ use alloc::boxed::Box; -use alloc::sync::Arc; use alloc::vec::Vec; use spin::Mutex; use log::*; -use core::cell::UnsafeCell; use crate::scheduler::Scheduler; use crate::event_hub::EventHub; diff --git a/crate/process/src/processor.rs b/crate/process/src/processor.rs index d29d560..e316324 100644 --- a/crate/process/src/processor.rs +++ b/crate/process/src/processor.rs @@ -1,6 +1,5 @@ use alloc::boxed::Box; use alloc::sync::Arc; -use spin::Mutex; use log::*; use core::cell::UnsafeCell; use crate::process_manager::*; @@ -30,14 +29,12 @@ impl Processor { } pub unsafe fn init(&self, id: usize, context: Box, manager: Arc) { - unsafe { - *self.inner.get() = Some(ProcessorInner { - id, - proc: None, - loop_context: context, - manager, - }); - } + *self.inner.get() = Some(ProcessorInner { + id, + proc: None, + loop_context: context, + manager, + }); } fn inner(&self) -> &mut ProcessorInner { diff --git a/crate/process/src/thread.rs b/crate/process/src/thread.rs index d333bc1..65406c4 100644 --- a/crate/process/src/thread.rs +++ b/crate/process/src/thread.rs @@ -7,14 +7,11 @@ //! - `new_kernel_context`: Construct a `Context` of the new kernel thread use alloc::boxed::Box; -use alloc::collections::BTreeMap; use core::marker::PhantomData; -use core::ptr; use core::time::Duration; use log::*; use crate::processor::*; use crate::process_manager::*; -use crate::scheduler::Scheduler; #[linkage = "weak"] #[no_mangle] diff --git a/kernel/src/fs.rs b/kernel/src/fs.rs index 725642d..7c6d4cc 100644 --- a/kernel/src/fs.rs +++ b/kernel/src/fs.rs @@ -1,7 +1,6 @@ use simple_filesystem::*; use alloc::{boxed::Box, sync::Arc, string::String, collections::VecDeque, vec::Vec}; use core::any::Any; -use core::slice; use lazy_static::lazy_static; #[cfg(target_arch = "x86_64")] use crate::arch::driver::ide; diff --git a/kernel/src/main.rs b/kernel/src/main.rs index 3199250..b5190fe 100644 --- a/kernel/src/main.rs +++ b/kernel/src/main.rs @@ -2,4 +2,5 @@ #![cfg_attr(not(test), no_main)] // disable all Rust-level entry points #![cfg_attr(test, allow(dead_code, unused_macros, unused_imports))] +#[allow(unused_imports)] use ucore; \ No newline at end of file diff --git a/kernel/src/memory.rs b/kernel/src/memory.rs index 295e26e..875c9b2 100644 --- a/kernel/src/memory.rs +++ b/kernel/src/memory.rs @@ -2,13 +2,11 @@ pub use crate::arch::paging::*; use bit_allocator::BitAlloc; use crate::consts::MEMORY_OFFSET; use super::HEAP_ALLOCATOR; -use ucore_memory::{*, paging::PageTable}; +use ucore_memory::*; use ucore_memory::cow::CowExt; pub use ucore_memory::memory_set::{MemoryArea, MemoryAttr, handler::*}; -use ucore_memory::swap::*; use crate::process::{process}; use crate::sync::{SpinNoIrqLock, SpinNoIrq, MutexGuard}; -use alloc::collections::VecDeque; use lazy_static::*; use log::*; use linked_list_allocator::LockedHeap; diff --git a/kernel/src/process/context.rs b/kernel/src/process/context.rs index c115bdf..e83e364 100644 --- a/kernel/src/process/context.rs +++ b/kernel/src/process/context.rs @@ -4,10 +4,10 @@ use log::*; use simple_filesystem::file::File; use spin::Mutex; use ucore_process::Context; -use xmas_elf::{ElfFile, header, program::{Flags, ProgramHeader, SegmentData, Type}}; +use xmas_elf::{ElfFile, header, program::{Flags, Type}}; use crate::arch::interrupt::{Context as ArchContext, TrapFrame}; -use crate::memory::{ByFrame, Delay, FrameAllocator, GlobalFrameAlloc, KernelStack, MemoryArea, MemoryAttr, MemorySet}; +use crate::memory::{ByFrame, GlobalFrameAlloc, KernelStack, MemoryAttr, MemorySet}; // TODO: avoid pub pub struct Process { @@ -110,7 +110,7 @@ impl Process { pub fn fork(&self, tf: &TrapFrame) -> Box { info!("COME into fork!"); // Clone memory set, make a new page table - let mut memory_set = self.memory_set.clone(); + let memory_set = self.memory_set.clone(); info!("finish mmset clone in fork!"); // MMU: copy data to the new space @@ -149,7 +149,6 @@ unsafe fn push_slice(mut sp: usize, vs: &[T]) -> usize { unsafe fn push_args_at_stack<'a, Iter>(args: Iter, stack_top: usize) -> usize where Iter: Iterator { - use core::{ptr, slice}; let mut sp = stack_top; let mut argv = Vec::new(); for arg in args { diff --git a/kernel/src/process/mod.rs b/kernel/src/process/mod.rs index 790e4ce..2f2a4e5 100644 --- a/kernel/src/process/mod.rs +++ b/kernel/src/process/mod.rs @@ -1,11 +1,8 @@ -use spin::Mutex; pub use self::context::Process; pub use ucore_process::*; use crate::consts::{MAX_CPU_NUM, MAX_PROCESS_NUM}; use crate::arch::cpu; -use alloc::{boxed::Box, sync::Arc, vec::Vec}; -use crate::sync::Condvar; -use core::sync::atomic::*; +use alloc::{boxed::Box, sync::Arc}; use log::*; pub mod context; diff --git a/kernel/src/shell.rs b/kernel/src/shell.rs index 236bb42..cddd898 100644 --- a/kernel/src/shell.rs +++ b/kernel/src/shell.rs @@ -1,7 +1,6 @@ //! Kernel shell use alloc::string::String; -use alloc::vec::Vec; use crate::fs::{ROOT_INODE, INodeExt}; use crate::process::*; diff --git a/kernel/src/syscall.rs b/kernel/src/syscall.rs index 2a7ffdf..e438ee8 100644 --- a/kernel/src/syscall.rs +++ b/kernel/src/syscall.rs @@ -141,7 +141,7 @@ fn sys_dup(fd1: usize, fd2: usize) -> SysResult { /// Fork the current process. Return the child's PID. fn sys_fork(tf: &TrapFrame) -> SysResult { - let mut context = process().fork(tf); + let context = process().fork(tf); //memory_set_map_swappable(context.get_memory_set_mut()); let pid = processor().manager().add(context, thread::current().id()); //memory_set_map_swappable(processor.get_context_mut(pid).get_memory_set_mut()); @@ -374,6 +374,7 @@ impl From for Stat { mode: match info.type_ { FileType::File => StatMode::FILE, FileType::Dir => StatMode::DIR, + #[allow(unreachable_patterns)] _ => StatMode::NULL, }, nlinks: info.nlinks as u32, diff --git a/kernel/src/util.rs b/kernel/src/util.rs index 1629386..a4ff86a 100644 --- a/kernel/src/util.rs +++ b/kernel/src/util.rs @@ -1,5 +1,3 @@ -use core::fmt::Debug; - /// Convert C string to Rust string pub unsafe fn from_cstr(s: *const u8) -> &'static str { use core::{str, slice};