From a6cd153fca83ed6f6b535e5ba4e4f7ebef9088dd Mon Sep 17 00:00:00 2001 From: equation314 Date: Sat, 4 Apr 2020 17:48:45 +0800 Subject: [PATCH 1/4] Remove unused import --- kernel/src/arch/mipsel/board/malta/mod.rs | 1 - kernel/src/arch/mipsel/interrupt.rs | 10 ++++----- kernel/src/arch/mipsel/memory.rs | 4 +--- kernel/src/arch/mipsel/mod.rs | 1 - kernel/src/arch/riscv/interrupt.rs | 2 +- kernel/src/arch/riscv/memory.rs | 7 +++--- kernel/src/arch/riscv/mod.rs | 3 +-- kernel/src/arch/riscv/paging.rs | 8 ++----- kernel/src/arch/x86_64/board/mod.rs | 4 +--- kernel/src/arch/x86_64/interrupt/handler.rs | 2 +- kernel/src/backtrace.rs | 2 +- kernel/src/drivers/block/virtio_blk.rs | 2 -- kernel/src/drivers/bus/virtio_mmio.rs | 2 +- kernel/src/drivers/gpu/fb.rs | 1 - kernel/src/drivers/gpu/virtio_gpu.rs | 1 - kernel/src/drivers/net/virtio_net.rs | 2 -- kernel/src/fs/device.rs | 1 + kernel/src/fs/epoll.rs | 7 ++---- kernel/src/fs/file_like.rs | 2 -- kernel/src/fs/mod.rs | 5 ++--- kernel/src/fs/pipe.rs | 2 +- kernel/src/fs/pseudo.rs | 2 +- kernel/src/fs/random.rs | 3 +-- kernel/src/fs/stdio.rs | 3 +-- kernel/src/fs/vga.rs | 2 -- kernel/src/ipc/semary.rs | 3 +-- kernel/src/lkm/api.rs | 4 +--- kernel/src/lkm/kernelvm.rs | 6 +----- kernel/src/lkm/manager.rs | 24 ++++++--------------- kernel/src/sync/condvar.rs | 2 +- kernel/src/syscall/custom.rs | 5 +++-- kernel/src/syscall/fs.rs | 7 +----- kernel/src/syscall/ipc.rs | 5 ----- kernel/src/syscall/lkm.rs | 3 --- 34 files changed, 40 insertions(+), 98 deletions(-) diff --git a/kernel/src/arch/mipsel/board/malta/mod.rs b/kernel/src/arch/mipsel/board/malta/mod.rs index 94ca1bb5..bb929912 100644 --- a/kernel/src/arch/mipsel/board/malta/mod.rs +++ b/kernel/src/arch/mipsel/board/malta/mod.rs @@ -1,6 +1,5 @@ use crate::drivers::bus::pci; use crate::drivers::gpu::fb::{self, FramebufferInfo}; -use alloc::string::String; use mips::registers::cp0; pub mod consts; diff --git a/kernel/src/arch/mipsel/interrupt.rs b/kernel/src/arch/mipsel/interrupt.rs index 578a16dd..52ea2b68 100644 --- a/kernel/src/arch/mipsel/interrupt.rs +++ b/kernel/src/arch/mipsel/interrupt.rs @@ -1,12 +1,10 @@ pub use self::context::*; use crate::arch::paging::get_root_page_table_ptr; -use crate::drivers::{DRIVERS, IRQ_MANAGER}; +use crate::drivers::IRQ_MANAGER; use log::*; use mips::addr::*; use mips::interrupts; -use mips::paging::{ - PageTable as MIPSPageTable, PageTableEntry, PageTableFlags as EF, TwoLevelPageTable, -}; +use mips::paging::PageTable as MIPSPageTable; use mips::registers::cp0; use mips::tlb; @@ -154,7 +152,7 @@ fn syscall(tf: &mut TrapFrame) { ); // temporary solution for ThinPad - if (tf.v0 == 0) { + if tf.v0 == 0 { warn!("Syscall ID = 0"); tf.v0 = unsafe { *((tf.sp + 28) as *const usize) }; } @@ -162,7 +160,7 @@ fn syscall(tf: &mut TrapFrame) { let ret = crate::syscall::syscall(tf.v0, arguments, tf) as isize; // comply with mips n32 abi, always return a positive value // https://git.musl-libc.org/cgit/musl/tree/arch/mipsn32/syscall_arch.h - if (ret < 0) { + if ret < 0 { tf.v0 = (-ret) as usize; tf.a3 = 1; } else { diff --git a/kernel/src/arch/mipsel/memory.rs b/kernel/src/arch/mipsel/memory.rs index 43c99f0d..c859756c 100644 --- a/kernel/src/arch/mipsel/memory.rs +++ b/kernel/src/arch/mipsel/memory.rs @@ -1,8 +1,6 @@ use crate::arch::paging::*; use crate::consts::{KERNEL_OFFSET, MEMORY_END, MEMORY_OFFSET}; -use crate::memory::{init_heap, Linear, MemoryAttr, MemorySet, FRAME_ALLOCATOR}; -use core::mem; -use log::*; +use crate::memory::{init_heap, FRAME_ALLOCATOR}; use rcore_memory::PAGE_SIZE; /// Initialize the memory management module diff --git a/kernel/src/arch/mipsel/mod.rs b/kernel/src/arch/mipsel/mod.rs index 027823c1..3d368434 100644 --- a/kernel/src/arch/mipsel/mod.rs +++ b/kernel/src/arch/mipsel/mod.rs @@ -9,7 +9,6 @@ pub mod rand; pub mod syscall; pub mod timer; -use log::*; use mips::registers::cp0; #[cfg(feature = "board_malta")] diff --git a/kernel/src/arch/riscv/interrupt.rs b/kernel/src/arch/riscv/interrupt.rs index 8a342b91..f16ece3b 100644 --- a/kernel/src/arch/riscv/interrupt.rs +++ b/kernel/src/arch/riscv/interrupt.rs @@ -1,5 +1,5 @@ pub use self::context::*; -use crate::drivers::{DRIVERS, IRQ_MANAGER}; +use crate::drivers::IRQ_MANAGER; use log::*; use riscv::register::*; diff --git a/kernel/src/arch/riscv/memory.rs b/kernel/src/arch/riscv/memory.rs index 6ea6a7e0..31b75f51 100644 --- a/kernel/src/arch/riscv/memory.rs +++ b/kernel/src/arch/riscv/memory.rs @@ -1,10 +1,9 @@ -use crate::consts::{KERNEL_OFFSET, MEMORY_END, MEMORY_OFFSET, PHYSICAL_MEMORY_OFFSET}; -use crate::memory::{init_heap, Linear, MemoryAttr, MemorySet, FRAME_ALLOCATOR}; +use crate::consts::{KERNEL_OFFSET, MEMORY_END, MEMORY_OFFSET}; +use crate::memory::{init_heap, MemorySet, FRAME_ALLOCATOR}; use core::mem; use log::*; use rcore_memory::PAGE_SIZE; -use riscv::register::satp; -use riscv::{addr::*, register::sstatus}; +use riscv::register::sstatus; /// Initialize the memory management module pub fn init(dtb: usize) { diff --git a/kernel/src/arch/riscv/mod.rs b/kernel/src/arch/riscv/mod.rs index 33bf2280..8fc712d0 100644 --- a/kernel/src/arch/riscv/mod.rs +++ b/kernel/src/arch/riscv/mod.rs @@ -22,7 +22,6 @@ pub mod timer; use crate::memory::phys_to_virt; use core::sync::atomic::{AtomicBool, Ordering}; -use log::*; #[no_mangle] pub extern "C" fn rust_main(hartid: usize, device_tree_paddr: usize) -> ! { @@ -88,7 +87,7 @@ const BOOT_HART_ID: usize = 0; #[cfg(feature = "board_u540")] const BOOT_HART_ID: usize = 1; -/// Constant & Macro for `trap.asm` +// Constant & Macro for `trap.asm` #[cfg(target_arch = "riscv32")] global_asm!( r" diff --git a/kernel/src/arch/riscv/paging.rs b/kernel/src/arch/riscv/paging.rs index 57a8cfc1..2591e2dc 100644 --- a/kernel/src/arch/riscv/paging.rs +++ b/kernel/src/arch/riscv/paging.rs @@ -6,11 +6,7 @@ use rcore_memory::paging::*; use riscv::addr::*; use riscv::asm::{sfence_vma, sfence_vma_all}; use riscv::paging::{FrameAllocator, FrameDeallocator}; -use riscv::paging::{ - Mapper, PageTable as RvPageTable, PageTableEntry, PageTableFlags as EF, PageTableType, - RecursivePageTable, -}; -use riscv::register::satp; +use riscv::paging::{Mapper, PageTable as RvPageTable, PageTableEntry, PageTableFlags as EF}; #[cfg(target_arch = "riscv32")] type TopLevelPageTable<'a> = riscv::paging::Rv32PageTable<'a>; @@ -199,7 +195,7 @@ impl PageTableExt for PageTableImpl { } #[cfg(target_arch = "riscv64")] for i in 509..512 { - if (i == 510) { + if i == 510 { // MMIO range 0x60000000 - 0x7FFFFFFF does not work as a large page, dunno why continue; } diff --git a/kernel/src/arch/x86_64/board/mod.rs b/kernel/src/arch/x86_64/board/mod.rs index 8699975c..4b29dbd5 100755 --- a/kernel/src/arch/x86_64/board/mod.rs +++ b/kernel/src/arch/x86_64/board/mod.rs @@ -1,7 +1,5 @@ -use crate::consts::KERNEL_OFFSET; use crate::drivers::gpu::fb::{self, ColorDepth, ColorFormat, FramebufferInfo}; use crate::memory::phys_to_virt; -use core::mem::zeroed; use rboot::BootInfo; pub fn init_driver(boot_info: &BootInfo) { @@ -17,7 +15,7 @@ pub fn init_driver(boot_info: &BootInfo) { xoffset: 0, yoffset: 0, depth: ColorDepth::ColorDepth32, - format: fb::ColorFormat::RGBA8888, + format: ColorFormat::RGBA8888, paddr: info.fb_addr as usize, vaddr: phys_to_virt(info.fb_addr as usize), screen_size: info.fb_size as usize, diff --git a/kernel/src/arch/x86_64/interrupt/handler.rs b/kernel/src/arch/x86_64/interrupt/handler.rs index b71b766d..53539e1e 100644 --- a/kernel/src/arch/x86_64/interrupt/handler.rs +++ b/kernel/src/arch/x86_64/interrupt/handler.rs @@ -66,7 +66,7 @@ use super::consts::*; use super::TrapFrame; -use crate::drivers::{DRIVERS, IRQ_MANAGER}; +use crate::drivers::IRQ_MANAGER; use bitflags::*; use log::*; diff --git a/kernel/src/backtrace.rs b/kernel/src/backtrace.rs index 223e99be..6a41652e 100644 --- a/kernel/src/backtrace.rs +++ b/kernel/src/backtrace.rs @@ -1,5 +1,4 @@ use core::mem::size_of; -use rcore_memory::PAGE_SIZE; extern "C" { fn stext(); @@ -165,6 +164,7 @@ pub fn backtrace() { // Kernel stack at 0x0000_57ac_0000_0000 (defined in bootloader crate) // size = 512 pages current_fp = *(current_fp as *const usize).offset(0); + use rcore_memory::PAGE_SIZE; if current_fp >= 0x0000_57ac_0000_0000 + 512 * PAGE_SIZE - size_of::() && current_fp <= 0xffff_ff00_0000_0000 { diff --git a/kernel/src/drivers/block/virtio_blk.rs b/kernel/src/drivers/block/virtio_blk.rs index e38d49c0..ca99b816 100644 --- a/kernel/src/drivers/block/virtio_blk.rs +++ b/kernel/src/drivers/block/virtio_blk.rs @@ -1,11 +1,9 @@ use alloc::string::String; use alloc::sync::Arc; -use log::*; use virtio_drivers::{VirtIOBlk, VirtIOHeader}; use super::super::{DeviceType, Driver, BLK_DRIVERS, DRIVERS, IRQ_MANAGER}; -use crate::memory::phys_to_virt; use crate::sync::SpinNoIrqLock as Mutex; struct VirtIOBlkDriver(Mutex>); diff --git a/kernel/src/drivers/bus/virtio_mmio.rs b/kernel/src/drivers/bus/virtio_mmio.rs index 4d8331dd..61c8fd3d 100644 --- a/kernel/src/drivers/bus/virtio_mmio.rs +++ b/kernel/src/drivers/bus/virtio_mmio.rs @@ -8,7 +8,7 @@ use super::super::block::virtio_blk; use super::super::gpu::virtio_gpu; use super::super::input::virtio_input; use super::super::net::virtio_net; -use crate::memory::{phys_to_virt, virt_to_phys}; +use crate::memory::phys_to_virt; pub fn virtio_probe(node: &Node) { let reg = match node.prop_raw("reg") { diff --git a/kernel/src/drivers/gpu/fb.rs b/kernel/src/drivers/gpu/fb.rs index a3745f23..e9b43472 100644 --- a/kernel/src/drivers/gpu/fb.rs +++ b/kernel/src/drivers/gpu/fb.rs @@ -2,7 +2,6 @@ use alloc::string::String; use core::fmt; -use lazy_static::lazy_static; use log::*; use spin::Mutex; diff --git a/kernel/src/drivers/gpu/virtio_gpu.rs b/kernel/src/drivers/gpu/virtio_gpu.rs index a17e2b3f..e9d2bbf2 100644 --- a/kernel/src/drivers/gpu/virtio_gpu.rs +++ b/kernel/src/drivers/gpu/virtio_gpu.rs @@ -1,7 +1,6 @@ use alloc::string::String; use alloc::sync::Arc; -use log::*; use virtio_drivers::{VirtIOGpu, VirtIOHeader}; use super::super::{DeviceType, Driver, DRIVERS, IRQ_MANAGER}; diff --git a/kernel/src/drivers/net/virtio_net.rs b/kernel/src/drivers/net/virtio_net.rs index 957f8dd0..a5a4c12b 100644 --- a/kernel/src/drivers/net/virtio_net.rs +++ b/kernel/src/drivers/net/virtio_net.rs @@ -2,7 +2,6 @@ use alloc::format; use alloc::string::String; use alloc::sync::Arc; -use log::*; use smoltcp::phy::{self, DeviceCapabilities}; use smoltcp::time::Instant; use smoltcp::wire::{EthernetAddress, Ipv4Address}; @@ -10,7 +9,6 @@ use smoltcp::Result; use virtio_drivers::{VirtIOHeader, VirtIONet}; use super::super::{DeviceType, Driver, DRIVERS, IRQ_MANAGER, NET_DRIVERS}; -use crate::memory::phys_to_virt; use crate::sync::SpinNoIrqLock as Mutex; #[derive(Clone)] diff --git a/kernel/src/fs/device.rs b/kernel/src/fs/device.rs index 10f36213..b067e63b 100644 --- a/kernel/src/fs/device.rs +++ b/kernel/src/fs/device.rs @@ -8,6 +8,7 @@ use crate::arch::driver::ide; #[cfg(target_arch = "aarch64")] use crate::arch::board::emmc; +#[cfg(target_arch = "aarch64")] use crate::sync::SpinNoIrqLock as Mutex; pub struct MemBuf(RwLock<&'static mut [u8]>); diff --git a/kernel/src/fs/epoll.rs b/kernel/src/fs/epoll.rs index 65380ab2..94389b89 100644 --- a/kernel/src/fs/epoll.rs +++ b/kernel/src/fs/epoll.rs @@ -1,11 +1,8 @@ use crate::fs::FileLike; -use crate::memory::MemorySet; use crate::process::Process; -use crate::sync::{Condvar, SpinNoIrqLock}; +use crate::sync::SpinNoIrqLock; use crate::syscall::{SysError, SysResult}; use alloc::{collections::BTreeMap, collections::BTreeSet}; -use core::mem::size_of; -use core::slice; pub struct EpollInstance { pub events: BTreeMap, @@ -29,7 +26,7 @@ impl EpollInstance { } pub fn control(&mut self, op: usize, fd: usize, event: &EpollEvent) -> SysResult { - match (op as i32) { + match op as i32 { EPollCtlOp::ADD => { self.events.insert(fd, event.clone()); self.newCtlList.lock().insert(fd); diff --git a/kernel/src/fs/file_like.rs b/kernel/src/fs/file_like.rs index e180f4dc..1e83c725 100644 --- a/kernel/src/fs/file_like.rs +++ b/kernel/src/fs/file_like.rs @@ -4,10 +4,8 @@ use super::ioctl::*; use super::FileHandle; use crate::fs::epoll::EpollInstance; use crate::net::Socket; -use crate::sync::Condvar; use crate::syscall::{SysError, SysResult}; use alloc::boxed::Box; -use alloc::vec::Vec; use rcore_fs::vfs::PollStatus; // TODO: merge FileLike to FileHandle ? diff --git a/kernel/src/fs/mod.rs b/kernel/src/fs/mod.rs index 75e812b9..4fed389e 100644 --- a/kernel/src/fs/mod.rs +++ b/kernel/src/fs/mod.rs @@ -1,14 +1,11 @@ use alloc::{sync::Arc, vec::Vec}; -use rcore_fs::dev::block_cache::BlockCache; use rcore_fs::vfs::*; use rcore_fs_devfs::{special::*, DevFS}; use rcore_fs_mountfs::MountFS; use rcore_fs_ramfs::RamFS; use rcore_fs_sfs::SimpleFileSystem; -use crate::drivers::BlockDriver; - pub use self::file::*; pub use self::file_like::*; pub use self::pipe::Pipe; @@ -50,6 +47,8 @@ lazy_static! { let device = { #[cfg(any(target_arch = "riscv32", target_arch = "riscv64", target_arch = "x86_64"))] { + use crate::drivers::BlockDriver; + use rcore_fs::dev::block_cache::BlockCache; let driver = BlockDriver( crate::drivers::BLK_DRIVERS .read().iter() diff --git a/kernel/src/fs/pipe.rs b/kernel/src/fs/pipe.rs index 1019c4c9..c56fd65f 100644 --- a/kernel/src/fs/pipe.rs +++ b/kernel/src/fs/pipe.rs @@ -1,6 +1,6 @@ //! Implement INode for Pipe -use alloc::{collections::vec_deque::VecDeque, string::String, sync::Arc}; +use alloc::{collections::vec_deque::VecDeque, sync::Arc}; use core::any::Any; use rcore_fs::vfs::*; diff --git a/kernel/src/fs/pseudo.rs b/kernel/src/fs/pseudo.rs index 5f01a954..44b8c6d6 100644 --- a/kernel/src/fs/pseudo.rs +++ b/kernel/src/fs/pseudo.rs @@ -1,6 +1,6 @@ //! Pseudo file system INode -use alloc::{string::String, sync::Arc, vec::Vec}; +use alloc::vec::Vec; use core::any::Any; use rcore_fs::vfs::*; diff --git a/kernel/src/fs/random.rs b/kernel/src/fs/random.rs index 065b7931..13c2345c 100644 --- a/kernel/src/fs/random.rs +++ b/kernel/src/fs/random.rs @@ -1,11 +1,10 @@ //! Implement INode for RandomINode -use alloc::{collections::vec_deque::VecDeque, string::String, sync::Arc}; +use alloc::sync::Arc; use core::any::Any; use rcore_fs::vfs::*; -use crate::sync::Condvar; use crate::sync::SpinNoIrqLock as Mutex; pub struct RandomINodeData { diff --git a/kernel/src/fs/stdio.rs b/kernel/src/fs/stdio.rs index 0d40c56f..72f3787f 100644 --- a/kernel/src/fs/stdio.rs +++ b/kernel/src/fs/stdio.rs @@ -1,12 +1,11 @@ //! Implement INode for Stdin & Stdout -use alloc::{collections::vec_deque::VecDeque, string::String, sync::Arc}; +use alloc::{collections::vec_deque::VecDeque, sync::Arc}; use core::any::Any; use rcore_fs::vfs::*; use super::ioctl::*; -use crate::process::Process; use crate::sync::Condvar; use crate::sync::SpinNoIrqLock as Mutex; diff --git a/kernel/src/fs/vga.rs b/kernel/src/fs/vga.rs index e3f7d3b6..454fa520 100755 --- a/kernel/src/fs/vga.rs +++ b/kernel/src/fs/vga.rs @@ -1,8 +1,6 @@ use rcore_fs::vfs::*; use crate::drivers::gpu::fb::{ColorFormat, FramebufferInfo, FRAME_BUFFER}; -use crate::memory::phys_to_virt; -use alloc::{string::String, sync::Arc, vec::Vec}; use core::any::Any; #[derive(Default)] diff --git a/kernel/src/ipc/semary.rs b/kernel/src/ipc/semary.rs index b54511af..a79f9e87 100644 --- a/kernel/src/ipc/semary.rs +++ b/kernel/src/ipc/semary.rs @@ -1,6 +1,5 @@ use crate::sync::Semaphore; -use crate::sync::SpinLock as Mutex; -use alloc::{boxed::Box, collections::BTreeMap, string::String, sync::Arc, sync::Weak, vec::Vec}; +use alloc::{collections::BTreeMap, sync::Arc, sync::Weak, vec::Vec}; use core::ops::Index; use spin::RwLock; diff --git a/kernel/src/lkm/api.rs b/kernel/src/lkm/api.rs index 72e1d1a0..81dcf4a7 100644 --- a/kernel/src/lkm/api.rs +++ b/kernel/src/lkm/api.rs @@ -1,7 +1,5 @@ use super::*; -use crate::lkm::manager::ModuleManager; use crate::lkm::structs::LoadedModule; -use alloc::boxed::Box; use alloc::string::String; use alloc::sync::Arc; use core::alloc::{GlobalAlloc, Layout}; @@ -10,7 +8,7 @@ use core::slice::from_raw_parts; pub fn get_module(this_module: usize) -> &'static mut LoadedModule { unsafe { let ptr = this_module as *mut LoadedModule; - &mut (*ptr) as (&'static mut LoadedModule) + &mut (*ptr) as &'static mut LoadedModule } } diff --git a/kernel/src/lkm/kernelvm.rs b/kernel/src/lkm/kernelvm.rs index 6ef4af60..bf18022e 100644 --- a/kernel/src/lkm/kernelvm.rs +++ b/kernel/src/lkm/kernelvm.rs @@ -1,14 +1,10 @@ // Simple kernel memory set for kernel virtual memory use crate::arch::paging::PageTableImpl; -use crate::consts::*; use crate::memory::GlobalFrameAlloc; use crate::sync::SpinLock as Mutex; use alloc::vec::*; -use buddy_system_allocator::*; -use core::alloc::Layout; use core::mem::ManuallyDrop; use core::ops::DerefMut; -use core::ptr::NonNull; use lazy_static::lazy_static; use rcore_memory::memory_set::handler::{ByFrame, MemoryHandler}; use rcore_memory::memory_set::MemoryAttr; @@ -119,7 +115,7 @@ impl VirtualArea { parent: &mut VirtualSpace, ) -> VirtualArea { let aligned_start_addr = page_addr - page_addr % PAGE_SIZE; - let mut aligned_end = (page_addr + size + PAGE_SIZE - 1); + let mut aligned_end = page_addr + size + PAGE_SIZE - 1; aligned_end = aligned_end - aligned_end % PAGE_SIZE; let lock = parent.allocator.lock(); let mut active_pt = lock.kernel_table(); diff --git a/kernel/src/lkm/manager.rs b/kernel/src/lkm/manager.rs index d81c67e9..84f09c9f 100644 --- a/kernel/src/lkm/manager.rs +++ b/kernel/src/lkm/manager.rs @@ -2,36 +2,26 @@ use super::api::*; use super::const_reloc as loader; use super::kernelvm::*; use super::structs::*; -use crate::consts::*; use crate::lkm::structs::ModuleState::{Ready, Unloading}; -use crate::memory::GlobalFrameAlloc; -use crate::sync::{Condvar, SpinLock as Mutex}; +use crate::sync::SpinLock as Mutex; use crate::syscall::SysError::*; use crate::syscall::SysResult; use alloc::boxed::Box; use alloc::collections::btree_map::BTreeMap; -use alloc::prelude::*; use alloc::string::*; use alloc::sync::Arc; use alloc::vec::*; -use core::borrow::BorrowMut; use core::mem::transmute; -use core::slice; use lazy_static::lazy_static; -use rcore_memory::memory_set::handler::{ByFrame, MemoryHandler}; use rcore_memory::memory_set::MemoryAttr; -use rcore_memory::{Page, PAGE_SIZE}; +use rcore_memory::PAGE_SIZE; use xmas_elf::dynamic::Tag; use xmas_elf::program::Type::Load; use xmas_elf::sections::SectionData; use xmas_elf::sections::SectionData::{DynSymbolTable64, Dynamic64, Undefined}; use xmas_elf::symbol_table::DynEntry64; use xmas_elf::symbol_table::Entry; -use xmas_elf::{ - header, - program::{Flags, Type}, - ElfFile, -}; +use xmas_elf::{header, ElfFile}; // The symbol data table. global_asm!(include_str!("symbol_table.asm")); @@ -96,15 +86,15 @@ impl ModuleManager { return; } use compression::prelude::*; - let zipped_symbols = - unsafe { slice::from_raw_parts(symbol_table_start as *const u8, symbol_table_len) } - .to_vec(); + let zipped_symbols = unsafe { + core::slice::from_raw_parts(symbol_table_start as *const u8, symbol_table_len) + } + .to_vec(); let real_symbols = zipped_symbols .decode(&mut GZipDecoder::new()) .collect::, _>>() .unwrap(); - use core::slice; use core::str::from_utf8; self.init_kernel_symbols(from_utf8(&real_symbols).unwrap()); } diff --git a/kernel/src/sync/condvar.rs b/kernel/src/sync/condvar.rs index 22ca8f63..37b76262 100644 --- a/kernel/src/sync/condvar.rs +++ b/kernel/src/sync/condvar.rs @@ -1,6 +1,6 @@ use super::*; +use crate::process::thread_manager; use crate::process::Process; -use crate::process::{current_thread, thread_manager}; use crate::thread; use alloc::collections::VecDeque; use alloc::sync::Arc; diff --git a/kernel/src/syscall/custom.rs b/kernel/src/syscall/custom.rs index 08253f14..42df0c99 100644 --- a/kernel/src/syscall/custom.rs +++ b/kernel/src/syscall/custom.rs @@ -1,7 +1,5 @@ //! Custom nonstandard syscalls use super::*; -use rcore_memory::memory_set::handler::Linear; -use rcore_memory::memory_set::MemoryAttr; impl Syscall<'_> { /// Allocate this PCI device to user space @@ -9,6 +7,9 @@ impl Syscall<'_> { #[cfg(target_arch = "x86_64")] pub fn sys_map_pci_device(&mut self, vendor: usize, product: usize) -> SysResult { use crate::drivers::bus::pci; + use rcore_memory::memory_set::handler::Linear; + use rcore_memory::memory_set::MemoryAttr; + info!( "map_pci_device: vendor: {:x}, product: {:x}", vendor, product diff --git a/kernel/src/syscall/fs.rs b/kernel/src/syscall/fs.rs index f4e2213c..f04d2cff 100644 --- a/kernel/src/syscall/fs.rs +++ b/kernel/src/syscall/fs.rs @@ -8,18 +8,14 @@ use rcore_fs::vfs::Timespec; use crate::drivers::SOCKET_ACTIVITY; use crate::fs::*; use crate::memory::MemorySet; -use crate::sync::{Condvar, SpinNoIrqLock}; +use crate::sync::Condvar; use crate::trap::TICK_ACTIVITY; -use alloc::{collections::BTreeMap, collections::BTreeSet}; use bitvec::prelude::{BitSlice, BitVec, LittleEndian}; use super::*; use crate::fs::epoll::EpollInstance; -use crate::net::server; use crate::process::Process; -use alloc::collections::VecDeque; -use bitflags::_core::task::Poll; use rcore_fs::vfs::PollStatus; impl Syscall<'_> { @@ -394,7 +390,6 @@ impl Syscall<'_> { let begin_time_ms = crate::trap::uptime_msec(); let condition = move || { - use PollEvents as PE; let mut proc = self.process(); let epollInstance = match proc.get_epoll_instance_mut(epfd) { diff --git a/kernel/src/syscall/ipc.rs b/kernel/src/syscall/ipc.rs index c9956f3b..367bad3f 100644 --- a/kernel/src/syscall/ipc.rs +++ b/kernel/src/syscall/ipc.rs @@ -1,9 +1,4 @@ -use crate::sync::Semaphore; -use crate::sync::SpinLock as Mutex; -use alloc::{boxed::Box, collections::BTreeMap, string::String, sync::Arc, sync::Weak, vec::Vec}; use bitflags::*; -use core::cell::UnsafeCell; -use spin::RwLock; pub use crate::ipc::*; diff --git a/kernel/src/syscall/lkm.rs b/kernel/src/syscall/lkm.rs index 9941feba..2bf4e256 100644 --- a/kernel/src/syscall/lkm.rs +++ b/kernel/src/syscall/lkm.rs @@ -1,8 +1,5 @@ use crate::lkm::manager::ModuleManager; -use crate::sync::Mutex; use crate::syscall::{check_and_clone_cstr, SysResult, Syscall}; -use alloc::collections::btree_map::BTreeMap; -use compression::prelude::Action; impl Syscall<'_> { pub fn sys_init_module( From 110c9676938a398e151f8ca1ddb28b9168de9808 Mon Sep 17 00:00:00 2001 From: equation314 Date: Sat, 4 Apr 2020 19:01:24 +0800 Subject: [PATCH 2/4] Resolve unused variables & unnecessary mut --- kernel/src/arch/mipsel/cpu.rs | 2 +- kernel/src/arch/mipsel/paging.rs | 6 +-- kernel/src/arch/riscv/cpu.rs | 2 +- kernel/src/arch/riscv/memory.rs | 2 +- kernel/src/arch/riscv/paging.rs | 66 ++++++++++++------------ kernel/src/arch/x86_64/acpi.rs | 2 +- kernel/src/arch/x86_64/driver/mod.rs | 2 +- kernel/src/arch/x86_64/ipi.rs | 2 +- kernel/src/arch/x86_64/paging.rs | 11 ++-- kernel/src/drivers/input/virtio_input.rs | 2 +- kernel/src/drivers/net/router.rs | 6 +-- kernel/src/drivers/net/virtio_net.rs | 4 +- kernel/src/fs/epoll.rs | 14 ++--- kernel/src/fs/file.rs | 8 ++- kernel/src/fs/file_like.rs | 14 ++--- kernel/src/fs/stdio.rs | 2 +- kernel/src/fs/vga.rs | 2 +- kernel/src/ipc/semary.rs | 2 +- kernel/src/lkm/api.rs | 2 +- kernel/src/lkm/kernelvm.rs | 6 +-- kernel/src/lkm/manager.rs | 22 ++++---- kernel/src/memory.rs | 2 +- kernel/src/net/structs.rs | 10 ++-- kernel/src/net/test.rs | 2 +- kernel/src/process/structs.rs | 11 ++-- kernel/src/sync/condvar.rs | 12 ++--- kernel/src/sync/semaphore.rs | 2 +- kernel/src/syscall/custom.rs | 2 +- kernel/src/syscall/fs.rs | 62 +++++++++++----------- kernel/src/syscall/lkm.rs | 4 +- kernel/src/syscall/mem.rs | 2 +- kernel/src/syscall/mod.rs | 2 +- kernel/src/syscall/net.rs | 18 +++---- kernel/src/syscall/time.rs | 2 +- 34 files changed, 151 insertions(+), 159 deletions(-) diff --git a/kernel/src/arch/mipsel/cpu.rs b/kernel/src/arch/mipsel/cpu.rs index afce457c..14fe81b5 100644 --- a/kernel/src/arch/mipsel/cpu.rs +++ b/kernel/src/arch/mipsel/cpu.rs @@ -27,7 +27,7 @@ pub fn halt() { } } -pub unsafe fn exit_in_qemu(error_code: u8) -> ! { +pub unsafe fn exit_in_qemu(_error_code: u8) -> ! { /* nothing to do */ loop {} } diff --git a/kernel/src/arch/mipsel/paging.rs b/kernel/src/arch/mipsel/paging.rs index 845c6cff..97a4f563 100644 --- a/kernel/src/arch/mipsel/paging.rs +++ b/kernel/src/arch/mipsel/paging.rs @@ -125,7 +125,7 @@ impl Entry for PageEntry { fn readonly_shared(&self) -> bool { false } - fn set_shared(&mut self, writable: bool) {} + fn set_shared(&mut self, _writable: bool) {} fn clear_shared(&mut self) {} fn swapped(&self) -> bool { self.0.flags().contains(EF::RESERVED1) @@ -136,11 +136,11 @@ impl Entry for PageEntry { fn user(&self) -> bool { true } - fn set_user(&mut self, value: bool) {} + fn set_user(&mut self, _value: bool) {} fn execute(&self) -> bool { true } - fn set_execute(&mut self, value: bool) {} + fn set_execute(&mut self, _value: bool) {} fn mmio(&self) -> u8 { 0 } diff --git a/kernel/src/arch/riscv/cpu.rs b/kernel/src/arch/riscv/cpu.rs index 89e2d95a..ec58597e 100644 --- a/kernel/src/arch/riscv/cpu.rs +++ b/kernel/src/arch/riscv/cpu.rs @@ -18,7 +18,7 @@ pub fn halt() { unsafe { riscv::asm::wfi() } } -pub unsafe fn exit_in_qemu(error_code: u8) -> ! { +pub unsafe fn exit_in_qemu(_error_code: u8) -> ! { super::sbi::shutdown() } diff --git a/kernel/src/arch/riscv/memory.rs b/kernel/src/arch/riscv/memory.rs index 31b75f51..620ec15b 100644 --- a/kernel/src/arch/riscv/memory.rs +++ b/kernel/src/arch/riscv/memory.rs @@ -50,7 +50,7 @@ fn init_frame_allocator() { /// Remap the kernel memory address with 4K page recorded in p1 page table fn remap_the_kernel(_dtb: usize) { - let mut ms = MemorySet::new(); + let ms = MemorySet::new(); unsafe { ms.activate(); } diff --git a/kernel/src/arch/riscv/paging.rs b/kernel/src/arch/riscv/paging.rs index 2591e2dc..c4e4ee9b 100644 --- a/kernel/src/arch/riscv/paging.rs +++ b/kernel/src/arch/riscv/paging.rs @@ -208,40 +208,40 @@ impl PageTableExt for PageTableImpl { } // MMIO range 0x60000000 - 0x7FFFFFFF does not work as a large page, dunno why - let flags = EF::VALID | EF::READABLE | EF::WRITABLE; // map Uartlite for Rocket Chip #[cfg(feature = "board_rocket_chip")] - self.page_table - .map_to( - Page::of_addr(VirtAddr::new(PHYSICAL_MEMORY_OFFSET + 0x6000_0000)), - Frame::of_addr(PhysAddr::new(0x6000_0000)), - flags, - &mut FrameAllocatorForRiscv, - ) - .unwrap() - .flush(); - // map AXI INTC for Rocket Chip - #[cfg(feature = "board_rocket_chip")] - self.page_table - .map_to( - Page::of_addr(VirtAddr::new(PHYSICAL_MEMORY_OFFSET + 0x6120_0000)), - Frame::of_addr(PhysAddr::new(0x6120_0000)), - flags, - &mut FrameAllocatorForRiscv, - ) - .unwrap() - .flush(); - // map AXI4-Stream Data FIFO for Rocket Chip - #[cfg(feature = "board_rocket_chip")] - self.page_table - .map_to( - Page::of_addr(VirtAddr::new(PHYSICAL_MEMORY_OFFSET + 0x64A0_0000)), - Frame::of_addr(PhysAddr::new(0x64A0_0000)), - flags, - &mut FrameAllocatorForRiscv, - ) - .unwrap() - .flush(); + { + let flags = EF::VALID | EF::READABLE | EF::WRITABLE; + self.page_table + .map_to( + Page::of_addr(VirtAddr::new(PHYSICAL_MEMORY_OFFSET + 0x6000_0000)), + Frame::of_addr(PhysAddr::new(0x6000_0000)), + flags, + &mut FrameAllocatorForRiscv, + ) + .unwrap() + .flush(); + // map AXI INTC for Rocket Chip + self.page_table + .map_to( + Page::of_addr(VirtAddr::new(PHYSICAL_MEMORY_OFFSET + 0x6120_0000)), + Frame::of_addr(PhysAddr::new(0x6120_0000)), + flags, + &mut FrameAllocatorForRiscv, + ) + .unwrap() + .flush(); + // map AXI4-Stream Data FIFO for Rocket Chip + self.page_table + .map_to( + Page::of_addr(VirtAddr::new(PHYSICAL_MEMORY_OFFSET + 0x64A0_0000)), + Frame::of_addr(PhysAddr::new(0x64A0_0000)), + flags, + &mut FrameAllocatorForRiscv, + ) + .unwrap() + .flush(); + } } fn token(&self) -> usize { @@ -256,7 +256,7 @@ impl PageTableExt for PageTableImpl { } fn active_token() -> usize { - let mut token: usize = 0; + let mut token; unsafe { asm!("csrr $0, satp" : "=r"(token) ::: "volatile"); } diff --git a/kernel/src/arch/x86_64/acpi.rs b/kernel/src/arch/x86_64/acpi.rs index dd10a3e6..64002bda 100644 --- a/kernel/src/arch/x86_64/acpi.rs +++ b/kernel/src/arch/x86_64/acpi.rs @@ -18,7 +18,7 @@ impl AcpiHandler for Handler { } } - fn unmap_physical_region(&mut self, region: PhysicalMapping) { + fn unmap_physical_region(&mut self, _region: PhysicalMapping) { // do nothing } } diff --git a/kernel/src/arch/x86_64/driver/mod.rs b/kernel/src/arch/x86_64/driver/mod.rs index 3fa0c2f7..f96a5a70 100644 --- a/kernel/src/arch/x86_64/driver/mod.rs +++ b/kernel/src/arch/x86_64/driver/mod.rs @@ -5,7 +5,7 @@ pub mod serial; use super::BootInfo; -pub fn init(boot_info: &BootInfo) { +pub fn init(_boot_info: &BootInfo) { serial::init(); keyboard::init(); diff --git a/kernel/src/arch/x86_64/ipi.rs b/kernel/src/arch/x86_64/ipi.rs index 3d0b28a8..4ad26de5 100644 --- a/kernel/src/arch/x86_64/ipi.rs +++ b/kernel/src/arch/x86_64/ipi.rs @@ -10,7 +10,7 @@ use core::sync::atomic::{spin_loop_hint, AtomicU8, Ordering}; pub type IPIEventItem = Box; unsafe fn get_apic() -> XApic { - let mut lapic = XApic::new(phys_to_virt(LAPIC_ADDR)); + let lapic = XApic::new(phys_to_virt(LAPIC_ADDR)); lapic } diff --git a/kernel/src/arch/x86_64/paging.rs b/kernel/src/arch/x86_64/paging.rs index a90d05a6..9a637577 100644 --- a/kernel/src/arch/x86_64/paging.rs +++ b/kernel/src/arch/x86_64/paging.rs @@ -1,7 +1,6 @@ use super::consts::*; use crate::memory::{alloc_frame, dealloc_frame, phys_to_virt}; use core::mem::ManuallyDrop; -use core::sync::atomic::Ordering; use log::*; use rcore_memory::paging::*; use x86_64::instructions::tlb; @@ -284,11 +283,11 @@ impl FrameDeallocator for FrameAllocatorForX86 { } /// Flush TLB for `vaddr` on all CPU -fn flush_tlb_all(vaddr: usize) { +fn flush_tlb_all(_vaddr: usize) { // FIXME: too slow, disable now. return; - if !super::AP_CAN_INIT.load(Ordering::Relaxed) { - return; - } - super::ipi::invoke_on_allcpu(move || tlb::flush(VirtAddr::new(vaddr as u64)), false); + // if !super::AP_CAN_INIT.load(Ordering::Relaxed) { + // return; + // } + // super::ipi::invoke_on_allcpu(move || tlb::flush(VirtAddr::new(vaddr as u64)), false); } diff --git a/kernel/src/drivers/input/virtio_input.rs b/kernel/src/drivers/input/virtio_input.rs index da06eb55..4d98ff02 100644 --- a/kernel/src/drivers/input/virtio_input.rs +++ b/kernel/src/drivers/input/virtio_input.rs @@ -31,7 +31,7 @@ impl Driver for VirtIOInputDriver { pub fn init(header: &'static mut VirtIOHeader) { let event_buf = Box::leak(Box::new([0u64; 32])); - let mut input = VirtIOInput::new(header, event_buf).expect("failed to create input driver"); + let input = VirtIOInput::new(header, event_buf).expect("failed to create input driver"); let driver = Arc::new(VirtIOInputDriver(Mutex::new(input))); IRQ_MANAGER.write().register_all(driver.clone()); diff --git a/kernel/src/drivers/net/router.rs b/kernel/src/drivers/net/router.rs index abac98e0..0c80035a 100644 --- a/kernel/src/drivers/net/router.rs +++ b/kernel/src/drivers/net/router.rs @@ -159,10 +159,10 @@ impl Driver for RouterInterface { let rdfo = AXI_STREAM_FIFO_RDFO.read_volatile(); if rdfo > 0 { let mut buffer = Vec::new(); - let rlr = AXI_STREAM_FIFO_RLR.read_volatile(); - let rdr = AXI_STREAM_FIFO_RDR.read_volatile(); + let _rlr = AXI_STREAM_FIFO_RLR.read_volatile(); + let _rdr = AXI_STREAM_FIFO_RDR.read_volatile(); let port = AXI_STREAM_FIFO_RDFD.read_volatile(); - for i in 1..rdfo { + for _ in 1..rdfo { buffer.push(AXI_STREAM_FIFO_RDFD.read_volatile() as u8); } debug!( diff --git a/kernel/src/drivers/net/virtio_net.rs b/kernel/src/drivers/net/virtio_net.rs index a5a4c12b..f424df23 100644 --- a/kernel/src/drivers/net/virtio_net.rs +++ b/kernel/src/drivers/net/virtio_net.rs @@ -49,7 +49,7 @@ impl phy::Device<'_> for VirtIONetDriver { type TxToken = VirtIONetDriver; fn receive(&mut self) -> Option<(Self::RxToken, Self::TxToken)> { - let mut net = self.0.lock(); + let net = self.0.lock(); if net.can_recv() { Some((self.clone(), self.clone())) } else { @@ -58,7 +58,7 @@ impl phy::Device<'_> for VirtIONetDriver { } fn transmit(&mut self) -> Option { - let mut net = self.0.lock(); + let net = self.0.lock(); if net.can_send() { Some(self.clone()) } else { diff --git a/kernel/src/fs/epoll.rs b/kernel/src/fs/epoll.rs index 94389b89..8beefe99 100644 --- a/kernel/src/fs/epoll.rs +++ b/kernel/src/fs/epoll.rs @@ -6,8 +6,8 @@ use alloc::{collections::BTreeMap, collections::BTreeSet}; pub struct EpollInstance { pub events: BTreeMap, - pub readyList: SpinNoIrqLock>, - pub newCtlList: SpinNoIrqLock>, + pub ready_list: SpinNoIrqLock>, + pub new_ctl_list: SpinNoIrqLock>, } impl Clone for EpollInstance { @@ -17,11 +17,11 @@ impl Clone for EpollInstance { } impl EpollInstance { - pub fn new(flags: usize) -> Self { + pub fn new(_flags: usize) -> Self { return EpollInstance { events: BTreeMap::new(), - readyList: Default::default(), - newCtlList: Default::default(), + ready_list: Default::default(), + new_ctl_list: Default::default(), }; } @@ -29,14 +29,14 @@ impl EpollInstance { match op as i32 { EPollCtlOp::ADD => { self.events.insert(fd, event.clone()); - self.newCtlList.lock().insert(fd); + self.new_ctl_list.lock().insert(fd); } EPollCtlOp::MOD => { if self.events.get(&fd).is_some() { self.events.remove(&fd); self.events.insert(fd, event.clone()); - self.newCtlList.lock().insert(fd); + self.new_ctl_list.lock().insert(fd); } else { return Err(SysError::EPERM); } diff --git a/kernel/src/fs/file.rs b/kernel/src/fs/file.rs index 705debbb..888f350e 100644 --- a/kernel/src/fs/file.rs +++ b/kernel/src/fs/file.rs @@ -50,14 +50,12 @@ impl FileHandle { if !self.options.read { return Err(FsError::InvalidParam); // FIXME: => EBADF } - let mut len: usize = 0; if !self.options.nonblock { // block loop { match self.inode.read_at(offset, buf) { Ok(read_len) => { - len = read_len; - break; + return Ok(read_len); } Err(FsError::Again) => { thread::yield_now(); @@ -68,9 +66,9 @@ impl FileHandle { } } } else { - len = self.inode.read_at(offset, buf)?; + let len = self.inode.read_at(offset, buf)?; + Ok(len) } - Ok(len) } pub fn write(&mut self, buf: &[u8]) -> Result { diff --git a/kernel/src/fs/file_like.rs b/kernel/src/fs/file_like.rs index 1e83c725..0d91fc38 100644 --- a/kernel/src/fs/file_like.rs +++ b/kernel/src/fs/file_like.rs @@ -22,7 +22,7 @@ impl FileLike { let len = match self { FileLike::File(file) => file.read(buf)?, FileLike::Socket(socket) => socket.read(buf).0?, - FileLike::EpollInstance(instance) => { + FileLike::EpollInstance(_) => { return Err(SysError::ENOSYS); } }; @@ -32,7 +32,7 @@ impl FileLike { let len = match self { FileLike::File(file) => file.write(buf)?, FileLike::Socket(socket) => socket.write(buf, None)?, - FileLike::EpollInstance(instance) => { + FileLike::EpollInstance(_) => { return Err(SysError::ENOSYS); } }; @@ -49,7 +49,7 @@ impl FileLike { FileLike::Socket(socket) => { socket.ioctl(request, arg1, arg2, arg3)?; } - FileLike::EpollInstance(instance) => { + FileLike::EpollInstance(_) => { return Err(SysError::ENOSYS); } } @@ -64,7 +64,7 @@ impl FileLike { let (read, write, error) = socket.poll(); PollStatus { read, write, error } } - FileLike::EpollInstance(instance) => { + FileLike::EpollInstance(_) => { return Err(SysError::ENOSYS); } }; @@ -74,10 +74,10 @@ impl FileLike { pub fn fcntl(&mut self, cmd: usize, arg: usize) -> SysResult { match self { FileLike::File(file) => file.fcntl(cmd, arg)?, - FileLike::Socket(socket) => { + FileLike::Socket(_) => { //TODO } - FileLike::EpollInstance(instance) => {} + FileLike::EpollInstance(_) => {} } Ok(0) } @@ -88,7 +88,7 @@ impl fmt::Debug for FileLike { match self { FileLike::File(file) => write!(f, "File({:?})", file), FileLike::Socket(socket) => write!(f, "Socket({:?})", socket), - FileLike::EpollInstance(instance) => write!(f, "EpollInstance()"), + FileLike::EpollInstance(_) => write!(f, "EpollInstance()"), } } } diff --git a/kernel/src/fs/stdio.rs b/kernel/src/fs/stdio.rs index 72f3787f..0c5d76d3 100644 --- a/kernel/src/fs/stdio.rs +++ b/kernel/src/fs/stdio.rs @@ -54,7 +54,7 @@ lazy_static! { } impl INode for Stdin { - fn read_at(&self, offset: usize, buf: &mut [u8]) -> Result { + fn read_at(&self, _offset: usize, buf: &mut [u8]) -> Result { if self.can_read() { buf[0] = self.pop() as u8; Ok(1) diff --git a/kernel/src/fs/vga.rs b/kernel/src/fs/vga.rs index 454fa520..a70e78c3 100755 --- a/kernel/src/fs/vga.rs +++ b/kernel/src/fs/vga.rs @@ -7,7 +7,7 @@ use core::any::Any; pub struct Vga; impl INode for Vga { - fn read_at(&self, offset: usize, buf: &mut [u8]) -> Result { + fn read_at(&self, _offset: usize, _buf: &mut [u8]) -> Result { Err(FsError::NotSupported) } fn write_at(&self, _offset: usize, _buf: &[u8]) -> Result { diff --git a/kernel/src/ipc/semary.rs b/kernel/src/ipc/semary.rs index a79f9e87..577aa6bc 100644 --- a/kernel/src/ipc/semary.rs +++ b/kernel/src/ipc/semary.rs @@ -34,7 +34,7 @@ impl SemArray { } // not found, create one let mut semaphores = Vec::new(); - for i in 0..nsems { + for _ in 0..nsems { semaphores.push(Semaphore::new(0)); } // insert to global map diff --git a/kernel/src/lkm/api.rs b/kernel/src/lkm/api.rs index 81dcf4a7..eff78e79 100644 --- a/kernel/src/lkm/api.rs +++ b/kernel/src/lkm/api.rs @@ -79,6 +79,6 @@ pub extern "C" fn lkm_api_add_kernel_symbols(start: usize, end: usize) { let symbols = unsafe { from_utf8(from_raw_parts(start as *const u8, length)) }.unwrap(); let global_lkmm = &LKM_MANAGER; let mut locked_lkmm = global_lkmm.lock(); - let mut lkmm = locked_lkmm.as_mut().unwrap(); + let lkmm = locked_lkmm.as_mut().unwrap(); lkmm.init_kernel_symbols(symbols); } diff --git a/kernel/src/lkm/kernelvm.rs b/kernel/src/lkm/kernelvm.rs index bf18022e..ebdfb912 100644 --- a/kernel/src/lkm/kernelvm.rs +++ b/kernel/src/lkm/kernelvm.rs @@ -34,14 +34,14 @@ impl MemorySpaceManager for LinearManager { LinearManager { last_page: 0 } } fn alloc(&mut self, size: usize) -> Option<(usize, usize)> { - let mut required_pages = (size + PAGE_SIZE - 1) / PAGE_SIZE; + let required_pages = (size + PAGE_SIZE - 1) / PAGE_SIZE; let current = self.last_page * PAGE_SIZE + KSEG2_START; self.last_page += required_pages; Some((current, required_pages * PAGE_SIZE)) } - fn free(&mut self, (addr, size): (usize, usize)) { + fn free(&mut self, (_addr, _size): (usize, usize)) { //Do nothing. } } @@ -95,7 +95,7 @@ impl VirtualSpace { impl Drop for VirtualSpace { fn drop(&mut self) { - for mut v in self.areas.iter_mut() { + for v in self.areas.iter_mut() { v.unmap(self.allocator, &mut self.page_allocator); } } diff --git a/kernel/src/lkm/manager.rs b/kernel/src/lkm/manager.rs index 84f09c9f..6c9a924d 100644 --- a/kernel/src/lkm/manager.rs +++ b/kernel/src/lkm/manager.rs @@ -103,7 +103,7 @@ impl ModuleManager { for l in lines.into_iter() { let mut words = l.split_whitespace(); let address = words.next().unwrap(); - let stype = words.next().unwrap(); + let _stype = words.next().unwrap(); let name = words.next().unwrap(); // Simply add the symbol into stub. self.stub_symbols.insert( @@ -160,7 +160,7 @@ impl ModuleManager { Some(base + (selected_symbol.value() as usize)) } } - pub fn init_module(&mut self, module_image: &[u8], param_values: &str) -> SysResult { + pub fn init_module(&mut self, module_image: &[u8], _param_values: &str) -> SysResult { let elf = ElfFile::new(module_image).expect("[LKM] failed to read elf"); let is32 = match elf.header.pt2 { header::HeaderPt2::Header32(_) => true, @@ -289,7 +289,7 @@ impl ModuleManager { if flags.is_execute() { attr = attr.execute(); } - let area_ref = vspace_ref.add_area(prog_start_addr, prog_end_addr, &attr); + let _area_ref = vspace_ref.add_area(prog_start_addr, prog_end_addr, &attr); //self.vallocator.map_pages(prog_start_addr, prog_end_addr, &attr); //No need to flush TLB. let target = unsafe { @@ -487,7 +487,7 @@ impl ModuleManager { fn reloc_symbols( &mut self, elf: &ElfFile, - (start, total_size, single_size): (usize, usize, usize), + (start, total_size, _single_size): (usize, usize, usize), base: usize, dynsym: &[DynEntry64], this_module: usize, @@ -501,8 +501,8 @@ impl ModuleManager { match s.get_data(elf).unwrap() { SectionData::Rela64(rela_items) => { for item in rela_items.iter() { - let mut addend = item.get_addend() as usize; - let mut reloc_addr = item.get_offset() as usize; + let addend = item.get_addend() as usize; + let reloc_addr = item.get_offset() as usize; let sti = item.get_symbol_table_index() as usize; let itype = item.get_type() as usize; self.relocate_single_symbol( @@ -519,8 +519,8 @@ impl ModuleManager { } SectionData::Rel64(rel_items) => { for item in rel_items.iter() { - let mut addend = 0 as usize; - let mut reloc_addr = item.get_offset() as usize; + let addend = 0 as usize; + let reloc_addr = item.get_offset() as usize; let sti = item.get_symbol_table_index() as usize; let itype = item.get_type() as usize; self.relocate_single_symbol( @@ -544,7 +544,7 @@ impl ModuleManager { } } } - pub fn delete_module(&mut self, name: &str, flags: u32) -> SysResult { + pub fn delete_module(&mut self, name: &str, _flags: u32) -> SysResult { //unimplemented!("[LKM] You can't plug out what's INSIDE you, RIGHT?"); info!("[LKM] now you can plug out a kernel module!"); @@ -579,7 +579,7 @@ impl ModuleManager { } drop(mod_lock); - let my_box = self.loaded_modules.remove(i); + let _my_box = self.loaded_modules.remove(i); unsafe { LKM_MANAGER.force_unlock(); } @@ -597,7 +597,7 @@ impl ModuleManager { pub fn with(f: impl FnOnce(&mut ModuleManager) -> T) -> T { let global_lkmm: &Mutex> = &LKM_MANAGER; let mut locked_lkmm = global_lkmm.lock(); - let mut lkmm = locked_lkmm.as_mut().unwrap(); + let lkmm = locked_lkmm.as_mut().unwrap(); f(lkmm) } pub fn init() { diff --git a/kernel/src/memory.rs b/kernel/src/memory.rs index 4868823b..203f94a5 100644 --- a/kernel/src/memory.rs +++ b/kernel/src/memory.rs @@ -155,7 +155,7 @@ pub fn enlarge_heap(heap: &mut Heap) { let mut addrs = [(0, 0); 32]; let mut addr_len = 0; let va_offset = PHYSICAL_MEMORY_OFFSET; - for i in 0..16384 { + for _ in 0..16384 { let page = alloc_frame().unwrap(); let va = va_offset + page; if addr_len > 0 { diff --git a/kernel/src/net/structs.rs b/kernel/src/net/structs.rs index db18357a..2141293e 100644 --- a/kernel/src/net/structs.rs +++ b/kernel/src/net/structs.rs @@ -197,7 +197,7 @@ impl Socket for TcpSocketState { }) } - fn write(&self, data: &[u8], sendto_endpoint: Option) -> SysResult { + fn write(&self, data: &[u8], _sendto_endpoint: Option) -> SysResult { let mut sockets = SOCKETS.lock(); let mut socket = sockets.get::(self.handle.0); @@ -212,7 +212,7 @@ impl Socket for TcpSocketState { poll_ifaces(); Ok(size) } - Err(err) => Err(SysError::ENOBUFS), + Err(_) => Err(SysError::ENOBUFS), } } else { Err(SysError::ENOBUFS) @@ -480,7 +480,7 @@ impl Socket for UdpSocketState { poll_ifaces(); Ok(data.len()) } - Err(err) => Err(SysError::ENOBUFS), + Err(_) => Err(SysError::ENOBUFS), } } else { Err(SysError::ENOBUFS) @@ -523,7 +523,7 @@ impl Socket for UdpSocketState { } } - fn ioctl(&mut self, request: usize, arg1: usize, arg2: usize, arg3: usize) -> SysResult { + fn ioctl(&mut self, request: usize, arg1: usize, _arg2: usize, _arg3: usize) -> SysResult { match request { // SIOCGARP 0x8954 => { @@ -710,7 +710,7 @@ impl PacketSocketState { } impl Socket for PacketSocketState { - fn read(&self, data: &mut [u8]) -> (SysResult, Endpoint) { + fn read(&self, _data: &mut [u8]) -> (SysResult, Endpoint) { unimplemented!() } diff --git a/kernel/src/net/test.rs b/kernel/src/net/test.rs index 9e0633a3..3ee11882 100644 --- a/kernel/src/net/test.rs +++ b/kernel/src/net/test.rs @@ -73,7 +73,7 @@ pub extern "C" fn server(_arg: usize) -> ! { if socket.can_recv() { let mut data = [0u8; 2048]; - let size = socket.recv_slice(&mut data).unwrap(); + let _size = socket.recv_slice(&mut data).unwrap(); } } } diff --git a/kernel/src/process/structs.rs b/kernel/src/process/structs.rs index 17427e62..f65b08d7 100644 --- a/kernel/src/process/structs.rs +++ b/kernel/src/process/structs.rs @@ -143,8 +143,8 @@ impl Thread { /// Return `(MemorySet, entry_point, ustack_top)` pub fn new_user_vm( inode: &Arc, - exec_path: &str, - mut args: Vec, + _exec_path: &str, + args: Vec, envs: Vec, ) -> Result<(MemorySet, usize, usize), &'static str> { // Read ELF header @@ -385,12 +385,7 @@ impl Process { let mut process_table = PROCESSES.write(); // assign pid - let pid = (0..) - .find(|i| match process_table.get(i) { - Some(p) => false, - _ => true, - }) - .unwrap(); + let pid = (0..).find(|i| process_table.get(i).is_none()).unwrap(); self.pid = Pid(pid); // put to process table diff --git a/kernel/src/sync/condvar.rs b/kernel/src/sync/condvar.rs index 37b76262..900abbe6 100644 --- a/kernel/src/sync/condvar.rs +++ b/kernel/src/sync/condvar.rs @@ -44,7 +44,7 @@ impl Condvar { } /// Wait for condvar until condition() returns Some - pub fn wait_event(condvar: &Condvar, mut condition: impl FnMut() -> Option) -> T { + pub fn wait_event(condvar: &Condvar, condition: impl FnMut() -> Option) -> T { Self::wait_events(&[condvar], condition) } @@ -60,7 +60,7 @@ impl Condvar { let mut locks = Vec::with_capacity(condvars.len()); loop { for condvar in condvars { - let mut lock = condvar.wait_queue.lock(); + let lock = condvar.wait_queue.lock(); locks.push(lock); } thread_manager().sleep(tid, 0); @@ -162,13 +162,13 @@ impl Condvar { let epoll_list = self.epoll_queue.lock(); for ist in epoll_list.iter() { if thread.id() == ist.tid { - let mut proc = ist.proc.lock(); + let proc = ist.proc.lock(); match proc.get_epoll_instance(ist.epfd) { Ok(instacne) => { - let mut readylist = instacne.readyList.lock(); - readylist.insert(ist.fd); + let mut ready_list = instacne.ready_list.lock(); + ready_list.insert(ist.fd); } - Err(r) => { + Err(_) => { panic!("epoll instance not exist"); } } diff --git a/kernel/src/sync/semaphore.rs b/kernel/src/sync/semaphore.rs index be7927c4..b4947151 100644 --- a/kernel/src/sync/semaphore.rs +++ b/kernel/src/sync/semaphore.rs @@ -64,7 +64,7 @@ impl Semaphore { /// Get the current count pub fn get(&self) -> isize { - let mut count = self.lock.lock(); + let count = self.lock.lock(); *count } diff --git a/kernel/src/syscall/custom.rs b/kernel/src/syscall/custom.rs index 42df0c99..52259649 100644 --- a/kernel/src/syscall/custom.rs +++ b/kernel/src/syscall/custom.rs @@ -36,7 +36,7 @@ impl Syscall<'_> { } #[cfg(not(target_arch = "x86_64"))] - pub fn sys_map_pci_device(&mut self, vendor: usize, product: usize) -> SysResult { + pub fn sys_map_pci_device(&mut self, _vendor: usize, _product: usize) -> SysResult { Err(SysError::ENOSYS) } diff --git a/kernel/src/syscall/fs.rs b/kernel/src/syscall/fs.rs index f04d2cff..c9b5c9dc 100644 --- a/kernel/src/syscall/fs.rs +++ b/kernel/src/syscall/fs.rs @@ -102,7 +102,7 @@ impl Syscall<'_> { } // check whether the fds is valid and is owned by this process - let mut condvars = alloc::vec![&(*TICK_ACTIVITY), &STDIN.pushed, &(*SOCKET_ACTIVITY)]; + let condvars = alloc::vec![&(*TICK_ACTIVITY), &STDIN.pushed, &(*SOCKET_ACTIVITY)]; let polls = unsafe { self.vm().check_write_array(ufds, nfds)? }; @@ -194,7 +194,7 @@ impl Syscall<'_> { 1 << 31 }; - let mut condvars = alloc::vec![&(*TICK_ACTIVITY), &STDIN.pushed, &(*SOCKET_ACTIVITY)]; + let condvars = alloc::vec![&(*TICK_ACTIVITY), &STDIN.pushed, &(*SOCKET_ACTIVITY)]; // for debugging if cfg!(debug_assertions) { @@ -264,8 +264,8 @@ impl Syscall<'_> { pub fn sys_epoll_create1(&mut self, flags: usize) -> SysResult { info!("epoll_create1: flags: {:?}", flags); let mut proc = self.process(); - let epollInstance = EpollInstance::new(flags); - let fd = proc.add_file(FileLike::EpollInstance(epollInstance)); + let epoll_instance = EpollInstance::new(flags); + let fd = proc.add_file(FileLike::EpollInstance(epoll_instance)); Ok(fd) } @@ -288,14 +288,14 @@ impl Syscall<'_> { return Err(SysError::EPERM); } - let epollInstance = match proc.get_epoll_instance_mut(epfd) { + let epoll_instance = match proc.get_epoll_instance_mut(epfd) { Ok(ins) => ins, Err(err) => { return Err(err); } }; - let ret = epollInstance.control(op, fd, &_event)?; + let ret = epoll_instance.control(op, fd, &_event)?; return Ok(ret); } @@ -315,26 +315,26 @@ impl Syscall<'_> { events: *mut EpollEvent, maxevents: usize, timeout_msecs: usize, - sigset_t: usize, + _sigset_t: usize, ) -> SysResult { info!("epoll_pwait: epfd: {}, timeout: {:?}", epfd, timeout_msecs); - let mut proc = self.process(); + let proc = self.process(); let events = unsafe { self.vm().check_write_array(events, maxevents)? }; - let epollInstance = proc.get_epoll_instance(epfd)?; + let epoll_instance = proc.get_epoll_instance(epfd)?; // add new fds which are registered by epoll_ctl after latest epoll_pwait - epollInstance.readyList.lock().clear(); - epollInstance - .readyList + epoll_instance.ready_list.lock().clear(); + epoll_instance + .ready_list .lock() - .extend(epollInstance.newCtlList.lock().clone()); - epollInstance.newCtlList.lock().clear(); + .extend(epoll_instance.new_ctl_list.lock().clone()); + epoll_instance.new_ctl_list.lock().clear(); // if registered fd has data to handle and its mode isn't epollet, we need // to add it to the list. - let keys: Vec<_> = epollInstance.events.keys().cloned().collect(); - for (k, v) in epollInstance.events.iter() { + let keys: Vec<_> = epoll_instance.events.keys().cloned().collect(); + for (k, v) in epoll_instance.events.iter() { if !v.contains(EpollEvent::EPOLLET) { match &proc.files.get(k) { None => { @@ -343,8 +343,8 @@ impl Syscall<'_> { Some(file_like) => { let status = file_like.poll()?; if status.write || status.read || status.error { - let mut readylist = epollInstance.readyList.lock(); - readylist.insert(*k); + let mut ready_list = epoll_instance.ready_list.lock(); + ready_list.insert(*k); } } } @@ -354,11 +354,11 @@ impl Syscall<'_> { let mut callbacks = alloc::vec![]; for fd in &keys { - let mut proc = self.process(); + let proc = self.process(); match proc.files.get(&fd) { Some(file_like) => { match file_like { - FileLike::File(file) => { + FileLike::File(_file) => { &crate::fs::STDIN.pushed.register_epoll_list( self.thread.proc.clone(), thread::current().id(), @@ -367,7 +367,7 @@ impl Syscall<'_> { ); callbacks.push((0, thread::current().id(), epfd, *fd)); } - FileLike::Socket(socket) => { + FileLike::Socket(_socket) => { &(*crate::drivers::SOCKET_ACTIVITY).register_epoll_list( self.thread.proc.clone(), thread::current().id(), @@ -376,7 +376,7 @@ impl Syscall<'_> { ); callbacks.push((1, thread::current().id(), epfd, *fd)); } - FileLike::EpollInstance(instance) => { + FileLike::EpollInstance(_) => { return Err(SysError::EINVAL); } }; @@ -386,22 +386,22 @@ impl Syscall<'_> { drop(proc); } - let mut condvars = alloc::vec![&(*TICK_ACTIVITY), &STDIN.pushed, &(*SOCKET_ACTIVITY)]; + let condvars = alloc::vec![&(*TICK_ACTIVITY), &STDIN.pushed, &(*SOCKET_ACTIVITY)]; let begin_time_ms = crate::trap::uptime_msec(); let condition = move || { let mut proc = self.process(); - let epollInstance = match proc.get_epoll_instance_mut(epfd) { + let epoll_instance = match proc.get_epoll_instance_mut(epfd) { Ok(ins) => ins, Err(err) => { return Some(Err(err)); } }; - let readylist = epollInstance.readyList.lock().clone(); + let ready_list = epoll_instance.ready_list.lock().clone(); let mut events_num = 0; - for infd in readylist.iter() { + for infd in ready_list.iter() { let mut status: PollStatus = Default::default(); { if let Some(file_like) = proc.files.get(&infd) { @@ -416,13 +416,13 @@ impl Syscall<'_> { } { - let epollInstance = match proc.get_epoll_instance_mut(epfd) { + let epoll_instance = match proc.get_epoll_instance_mut(epfd) { Ok(ins) => ins, Err(err) => { return Some(Err(err)); } }; - let epollevent = epollInstance.events.get_mut(&infd)?; + let epollevent = epoll_instance.events.get_mut(&infd)?; if status.error { events[events_num].events = EpollEvent::EPOLLERR; @@ -445,13 +445,13 @@ impl Syscall<'_> { } { - let epollInstance = match proc.get_epoll_instance_mut(epfd) { + let epoll_instance = match proc.get_epoll_instance_mut(epfd) { Ok(ins) => ins, Err(err) => { return Some(Err(err)); } }; - epollInstance.readyList.lock().clear(); + epoll_instance.ready_list.lock().clear(); } drop(proc); @@ -602,7 +602,7 @@ impl Syscall<'_> { dirfd as isize, path, mode, flags ); } - let inode = + let _inode = proc.lookup_inode_at(dirfd, &path, !flags.contains(AtFlags::SYMLINK_NOFOLLOW))?; Ok(0) } diff --git a/kernel/src/syscall/lkm.rs b/kernel/src/syscall/lkm.rs index 2bf4e256..c3abe4c6 100644 --- a/kernel/src/syscall/lkm.rs +++ b/kernel/src/syscall/lkm.rs @@ -8,7 +8,7 @@ impl Syscall<'_> { len: usize, param_values: *const u8, ) -> SysResult { - let mut proc = self.process(); + let _proc = self.process(); let modimg = unsafe { self.vm().check_read_array(module_image, len)? }; let copied_param_values = check_and_clone_cstr(param_values)?; @@ -16,7 +16,7 @@ impl Syscall<'_> { } pub fn sys_delete_module(&mut self, module_name: *const u8, flags: u32) -> SysResult { - let mut proc = self.process(); + let _proc = self.process(); let copied_modname = check_and_clone_cstr(module_name)?; info!("[LKM] Removing module {:?}", copied_modname); let ret = ModuleManager::with(|kmm| kmm.delete_module(&copied_modname, flags)); diff --git a/kernel/src/syscall/mem.rs b/kernel/src/syscall/mem.rs index 247182b8..415481d5 100644 --- a/kernel/src/syscall/mem.rs +++ b/kernel/src/syscall/mem.rs @@ -101,7 +101,7 @@ impl Syscall<'_> { "mprotect: addr={:#x}, size={:#x}, prot={:?}", addr, len, prot ); - let attr = prot.to_attr(); + let _attr = prot.to_attr(); // FIXME: properly set the attribute of the area // now some mut ptr check is fault diff --git a/kernel/src/syscall/mod.rs b/kernel/src/syscall/mod.rs index 7d801158..84ab37c1 100644 --- a/kernel/src/syscall/mod.rs +++ b/kernel/src/syscall/mod.rs @@ -406,7 +406,7 @@ impl Syscall<'_> { SYS_PIPE => { let fd_ptr = args[0] as *mut u32; match self.sys_pipe(fd_ptr) { - Ok(code) => { + Ok(_code) => { unsafe { self.tf.v0 = *fd_ptr as usize; self.tf.v1 = *(fd_ptr.add(1)) as usize; diff --git a/kernel/src/syscall/net.rs b/kernel/src/syscall/net.rs index 3197ab70..edc7f164 100644 --- a/kernel/src/syscall/net.rs +++ b/kernel/src/syscall/net.rs @@ -519,15 +519,15 @@ enum_with_unknown! { } } -const IPPROTO_IP: usize = 0; -const IPPROTO_ICMP: usize = 1; -const IPPROTO_TCP: usize = 6; +pub const IPPROTO_IP: usize = 0; +pub const IPPROTO_ICMP: usize = 1; +pub const IPPROTO_TCP: usize = 6; -const SOL_SOCKET: usize = 1; -const SO_SNDBUF: usize = 7; -const SO_RCVBUF: usize = 8; -const SO_LINGER: usize = 13; +pub const SOL_SOCKET: usize = 1; +pub const SO_SNDBUF: usize = 7; +pub const SO_RCVBUF: usize = 8; +pub const SO_LINGER: usize = 13; -const TCP_CONGESTION: usize = 13; +pub const TCP_CONGESTION: usize = 13; -const IP_HDRINCL: usize = 3; +pub const IP_HDRINCL: usize = 3; diff --git a/kernel/src/syscall/time.rs b/kernel/src/syscall/time.rs index 5cb4bffe..f996764b 100644 --- a/kernel/src/syscall/time.rs +++ b/kernel/src/syscall/time.rs @@ -64,7 +64,7 @@ impl Syscall<'_> { info!("times: buf: {:?}", buf); let buf = unsafe { self.vm().check_write_ptr(buf)? }; - let tick_base = *TICK_BASE; + let _tick_base = *TICK_BASE; let tick = unsafe { crate::trap::TICK as u64 }; let new_buf = Tms { From 9b488bed0634eb45cf2e5df6836c9aa7e8168a81 Mon Sep 17 00:00:00 2001 From: equation314 Date: Sat, 4 Apr 2020 19:46:58 +0800 Subject: [PATCH 3/4] Resolve never used constants/fileds/methods --- kernel/src/arch/mipsel/memory.rs | 4 ---- kernel/src/arch/mipsel/mod.rs | 2 ++ kernel/src/drivers/gpu/qemu_stdvga.rs | 2 ++ kernel/src/drivers/mod.rs | 1 + kernel/src/fs/device.rs | 2 ++ kernel/src/fs/epoll.rs | 3 +-- kernel/src/fs/ioctl.rs | 1 + kernel/src/fs/vga.rs | 2 ++ kernel/src/ipc/semary.rs | 4 ++-- kernel/src/lkm/kernelvm.rs | 4 ++-- kernel/src/syscall/fs.rs | 3 +++ kernel/src/syscall/ipc.rs | 2 ++ kernel/src/syscall/misc.rs | 2 ++ kernel/src/syscall/proc.rs | 1 + kernel/src/syscall/time.rs | 1 + 15 files changed, 24 insertions(+), 10 deletions(-) diff --git a/kernel/src/arch/mipsel/memory.rs b/kernel/src/arch/mipsel/memory.rs index c859756c..bd066441 100644 --- a/kernel/src/arch/mipsel/memory.rs +++ b/kernel/src/arch/mipsel/memory.rs @@ -44,10 +44,6 @@ fn init_frame_allocator() { } } -// First core stores its SATP here. -// Other cores load it later. -static mut SATP: usize = 0; - pub unsafe fn clear_bss() { let start = sbss as usize; let end = ebss as usize; diff --git a/kernel/src/arch/mipsel/mod.rs b/kernel/src/arch/mipsel/mod.rs index 3d368434..5bbac1c3 100644 --- a/kernel/src/arch/mipsel/mod.rs +++ b/kernel/src/arch/mipsel/mod.rs @@ -61,12 +61,14 @@ pub extern "C" fn rust_main() -> ! { crate::kmain(); } +/* fn others_main() -> ! { interrupt::init(); memory::init_other(); timer::init(); crate::kmain(); } +*/ const BOOT_CPU_ID: u32 = 0; diff --git a/kernel/src/drivers/gpu/qemu_stdvga.rs b/kernel/src/drivers/gpu/qemu_stdvga.rs index 1515f152..f1654405 100644 --- a/kernel/src/drivers/gpu/qemu_stdvga.rs +++ b/kernel/src/drivers/gpu/qemu_stdvga.rs @@ -1,5 +1,7 @@ //! driver for qemu stdvga (Cirrus) +#![allow(dead_code)] + use crate::util::{read, write}; const VGA_MMIO_OFFSET: usize = 0x400 - 0x3C0; diff --git a/kernel/src/drivers/mod.rs b/kernel/src/drivers/mod.rs index 62dfa812..2ed5b0cf 100644 --- a/kernel/src/drivers/mod.rs +++ b/kernel/src/drivers/mod.rs @@ -14,6 +14,7 @@ pub mod block; #[allow(dead_code)] pub mod bus; pub mod console; +#[allow(dead_code)] mod device_tree; #[allow(dead_code)] pub mod gpu; diff --git a/kernel/src/fs/device.rs b/kernel/src/fs/device.rs index b067e63b..f6cb6410 100644 --- a/kernel/src/fs/device.rs +++ b/kernel/src/fs/device.rs @@ -1,5 +1,7 @@ //! Implement Device +#![allow(dead_code)] + use rcore_fs::dev::*; use spin::RwLock; diff --git a/kernel/src/fs/epoll.rs b/kernel/src/fs/epoll.rs index 8beefe99..fbf74476 100644 --- a/kernel/src/fs/epoll.rs +++ b/kernel/src/fs/epoll.rs @@ -59,10 +59,9 @@ impl EpollInstance { #[derive(Clone, Copy)] pub struct EpollData { - ptr: u64, + _ptr: u64, } -#[repr(packed)] #[derive(Clone)] pub struct EpollEvent { pub events: u32, /* Epoll events */ diff --git a/kernel/src/fs/ioctl.rs b/kernel/src/fs/ioctl.rs index 30652a7a..d32825b2 100644 --- a/kernel/src/fs/ioctl.rs +++ b/kernel/src/fs/ioctl.rs @@ -1,6 +1,7 @@ // for IOR and IOW: // 32bits total, command in lower 16bits, size of the parameter structure in the lower 14 bits of the upper 16 bits // higher 2 bits: 01 = write, 10 = read +#![allow(dead_code)] #[cfg(not(target_arch = "mips"))] pub const TCGETS: usize = 0x5401; diff --git a/kernel/src/fs/vga.rs b/kernel/src/fs/vga.rs index a70e78c3..647b6c23 100755 --- a/kernel/src/fs/vga.rs +++ b/kernel/src/fs/vga.rs @@ -84,6 +84,7 @@ impl INode for Vga { } #[repr(u32)] +#[allow(dead_code)] #[derive(Debug, Copy, Clone)] enum FbType { /// Packed Pixels @@ -101,6 +102,7 @@ enum FbType { } #[repr(u32)] +#[allow(dead_code)] #[derive(Debug, Copy, Clone)] enum FbVisual { /// Monochr. 1=Black 0=White diff --git a/kernel/src/ipc/semary.rs b/kernel/src/ipc/semary.rs index 577aa6bc..914ff154 100644 --- a/kernel/src/ipc/semary.rs +++ b/kernel/src/ipc/semary.rs @@ -5,7 +5,7 @@ use spin::RwLock; /// A System V semaphore set pub struct SemArray { - key: usize, + _key: usize, sems: Vec, } @@ -39,7 +39,7 @@ impl SemArray { } // insert to global map let array = Arc::new(SemArray { - key, + _key: key, sems: semaphores, }); key2sem.insert(key, Arc::downgrade(&array)); diff --git a/kernel/src/lkm/kernelvm.rs b/kernel/src/lkm/kernelvm.rs index ebdfb912..ca5d81f6 100644 --- a/kernel/src/lkm/kernelvm.rs +++ b/kernel/src/lkm/kernelvm.rs @@ -104,7 +104,7 @@ impl Drop for VirtualSpace { pub struct VirtualArea { start: usize, end: usize, - attr: MemoryAttr, + _attr: MemoryAttr, } impl VirtualArea { @@ -128,7 +128,7 @@ impl VirtualArea { VirtualArea { start: aligned_start_addr, end: aligned_end, - attr: attr.clone(), + _attr: attr.clone(), } } pub fn unmap(&mut self, allocator: &LockedVMM, parent: &mut ByFrame) { diff --git a/kernel/src/syscall/fs.rs b/kernel/src/syscall/fs.rs index c9b5c9dc..746f38e7 100644 --- a/kernel/src/syscall/fs.rs +++ b/kernel/src/syscall/fs.rs @@ -1,4 +1,7 @@ //! Syscalls for file system + +#![allow(dead_code)] + use core::cell::UnsafeCell; use core::cmp::min; use core::mem::size_of; diff --git a/kernel/src/syscall/ipc.rs b/kernel/src/syscall/ipc.rs index 367bad3f..348ae984 100644 --- a/kernel/src/syscall/ipc.rs +++ b/kernel/src/syscall/ipc.rs @@ -1,3 +1,5 @@ +#![allow(dead_code)] + use bitflags::*; pub use crate::ipc::*; diff --git a/kernel/src/syscall/misc.rs b/kernel/src/syscall/misc.rs index 3d2ea123..99873631 100644 --- a/kernel/src/syscall/misc.rs +++ b/kernel/src/syscall/misc.rs @@ -1,3 +1,5 @@ +#![allow(dead_code)] + use super::*; use crate::arch::cpu; use crate::consts::USER_STACK_SIZE; diff --git a/kernel/src/syscall/proc.rs b/kernel/src/syscall/proc.rs index 6a79aabd..be0c4684 100644 --- a/kernel/src/syscall/proc.rs +++ b/kernel/src/syscall/proc.rs @@ -13,6 +13,7 @@ impl Syscall<'_> { Ok(pid) } + #[cfg(target_arch = "x86_64")] pub fn sys_vfork(&mut self) -> SysResult { self.sys_fork() } diff --git a/kernel/src/syscall/time.rs b/kernel/src/syscall/time.rs index f996764b..4fc16218 100644 --- a/kernel/src/syscall/time.rs +++ b/kernel/src/syscall/time.rs @@ -29,6 +29,7 @@ impl Syscall<'_> { Ok(0) } + #[cfg(target_arch = "x86_64")] pub fn sys_time(&mut self, time: *mut u64) -> SysResult { let sec = get_epoch_usec() / USEC_PER_SEC; if time as usize != 0 { From 5c8fa87c2778e1b6c9d22b3ff727ca3b1d3d86c5 Mon Sep 17 00:00:00 2001 From: equation314 Date: Sat, 4 Apr 2020 23:02:05 +0800 Subject: [PATCH 4/4] Resolve deprecated funtions --- kernel/src/arch/mipsel/context.rs | 4 ++-- kernel/src/arch/mipsel/interrupt.rs | 3 +-- kernel/src/arch/riscv/mod.rs | 6 ++---- kernel/src/process/structs.rs | 3 ++- kernel/src/syscall/fs.rs | 8 ++++---- 5 files changed, 11 insertions(+), 13 deletions(-) diff --git a/kernel/src/arch/mipsel/context.rs b/kernel/src/arch/mipsel/context.rs index ee968e3f..92ae8b6a 100644 --- a/kernel/src/arch/mipsel/context.rs +++ b/kernel/src/arch/mipsel/context.rs @@ -1,5 +1,5 @@ use mips::registers::cp0; -use mips::tlb; +use mips::tlb::TLBEntry; /// Saved registers on a trap. #[derive(Clone)] @@ -238,7 +238,7 @@ impl Context { fn switch_context(src: *mut Context, dst: *mut Context); } - tlb::clear_all_tlb(); + TLBEntry::clear_all(); switch_context(self as *mut Context, target as *mut Context); } diff --git a/kernel/src/arch/mipsel/interrupt.rs b/kernel/src/arch/mipsel/interrupt.rs index 52ea2b68..c15966f1 100644 --- a/kernel/src/arch/mipsel/interrupt.rs +++ b/kernel/src/arch/mipsel/interrupt.rs @@ -6,7 +6,6 @@ use mips::addr::*; use mips::interrupts; use mips::paging::PageTable as MIPSPageTable; use mips::registers::cp0; -use mips::tlb; #[path = "context.rs"] mod context; @@ -280,7 +279,7 @@ fn page_fault(tf: &mut TrapFrame) { } } - tlb::write_tlb_random(tlb_entry) + tlb_entry.write_random() } Err(()) => { if !crate::memory::handle_page_fault(addr) { diff --git a/kernel/src/arch/riscv/mod.rs b/kernel/src/arch/riscv/mod.rs index 8fc712d0..67c4c59b 100644 --- a/kernel/src/arch/riscv/mod.rs +++ b/kernel/src/arch/riscv/mod.rs @@ -25,16 +25,14 @@ use core::sync::atomic::{AtomicBool, Ordering}; #[no_mangle] pub extern "C" fn rust_main(hartid: usize, device_tree_paddr: usize) -> ! { - let mut device_tree_vaddr = phys_to_virt(device_tree_paddr); + let device_tree_vaddr = phys_to_virt(device_tree_paddr); unsafe { cpu::set_cpu_id(hartid); } #[cfg(feature = "board_rocket_chip")] - { - device_tree_vaddr = board::DTB.as_ptr() as usize; - } + let device_tree_vaddr = board::DTB.as_ptr() as usize; if hartid != BOOT_HART_ID { while !AP_CAN_INIT.load(Ordering::Relaxed) {} diff --git a/kernel/src/process/structs.rs b/kernel/src/process/structs.rs index f65b08d7..1c1a455b 100644 --- a/kernel/src/process/structs.rs +++ b/kernel/src/process/structs.rs @@ -102,10 +102,11 @@ impl rcore_thread::Context for Thread { impl Thread { /// Make a struct for the init thread pub unsafe fn new_init() -> Box { + let zero = MaybeUninit::::zeroed(); Box::new(Thread { context: Context::null(), // safety: other fields will never be used - ..core::mem::MaybeUninit::zeroed().assume_init() + ..zero.assume_init() }) } diff --git a/kernel/src/syscall/fs.rs b/kernel/src/syscall/fs.rs index 746f38e7..c5381ec1 100644 --- a/kernel/src/syscall/fs.rs +++ b/kernel/src/syscall/fs.rs @@ -14,7 +14,7 @@ use crate::memory::MemorySet; use crate::sync::Condvar; use crate::trap::TICK_ACTIVITY; -use bitvec::prelude::{BitSlice, BitVec, LittleEndian}; +use bitvec::prelude::{BitSlice, BitVec, Lsb0}; use super::*; use crate::fs::epoll::EpollInstance; @@ -1723,8 +1723,8 @@ const FD_PER_ITEM: usize = 8 * size_of::(); const MAX_FDSET_SIZE: usize = 1024 / FD_PER_ITEM; struct FdSet { - bitset: &'static mut BitSlice, - origin: BitVec, + bitset: &'static mut BitSlice, + origin: BitVec, } impl FdSet { @@ -1742,7 +1742,7 @@ impl FdSet { return Err(SysError::EINVAL); } let slice = unsafe { vm.check_write_array(addr, len)? }; - let bitset: &'static mut BitSlice = slice.into(); + let bitset: &'static mut BitSlice = slice.into(); debug!("bitset {:?}", bitset); // save the fdset, and clear it