diff --git a/crate/memory/src/lib.rs b/crate/memory/src/lib.rs index 2b68ad0..14a5155 100644 --- a/crate/memory/src/lib.rs +++ b/crate/memory/src/lib.rs @@ -1,7 +1,5 @@ #![cfg_attr(not(test), no_std)] -#![feature(alloc)] #![feature(nll)] -#![feature(maybe_uninit)] // import macros from log use log::*; diff --git a/crate/memory/src/memory_set/handler/byframe.rs b/crate/memory/src/memory_set/handler/byframe.rs index 8c81117..202287a 100644 --- a/crate/memory/src/memory_set/handler/byframe.rs +++ b/crate/memory/src/memory_set/handler/byframe.rs @@ -6,17 +6,17 @@ pub struct ByFrame { } impl MemoryHandler for ByFrame { - fn box_clone(&self) -> Box { + fn box_clone(&self) -> Box { Box::new(self.clone()) } - fn map(&self, pt: &mut PageTable, addr: VirtAddr, attr: &MemoryAttr) { + fn map(&self, pt: &mut dyn PageTable, addr: VirtAddr, attr: &MemoryAttr) { let target = self.allocator.alloc().expect("failed to allocate frame"); let entry = pt.map(addr, target); attr.apply(entry); } - fn unmap(&self, pt: &mut PageTable, addr: VirtAddr) { + fn unmap(&self, pt: &mut dyn PageTable, addr: VirtAddr) { let target = pt.get_entry(addr).expect("fail to get entry").target(); self.allocator.dealloc(target); pt.unmap(addr); @@ -24,8 +24,8 @@ impl MemoryHandler for ByFrame { fn clone_map( &self, - pt: &mut PageTable, - src_pt: &mut PageTable, + pt: &mut dyn PageTable, + src_pt: &mut dyn PageTable, addr: VirtAddr, attr: &MemoryAttr, ) { @@ -34,7 +34,7 @@ impl MemoryHandler for ByFrame { pt.get_page_slice_mut(addr).copy_from_slice(data); } - fn handle_page_fault(&self, _pt: &mut PageTable, _addr: VirtAddr) -> bool { + fn handle_page_fault(&self, _pt: &mut dyn PageTable, _addr: VirtAddr) -> bool { false } } diff --git a/crate/memory/src/memory_set/handler/delay.rs b/crate/memory/src/memory_set/handler/delay.rs index 60b8cfe..e809629 100644 --- a/crate/memory/src/memory_set/handler/delay.rs +++ b/crate/memory/src/memory_set/handler/delay.rs @@ -6,17 +6,17 @@ pub struct Delay { } impl MemoryHandler for Delay { - fn box_clone(&self) -> Box { + fn box_clone(&self) -> Box { Box::new(self.clone()) } - fn map(&self, pt: &mut PageTable, addr: VirtAddr, attr: &MemoryAttr) { + fn map(&self, pt: &mut dyn PageTable, addr: VirtAddr, attr: &MemoryAttr) { let entry = pt.map(addr, 0); entry.set_present(false); attr.apply(entry); } - fn unmap(&self, pt: &mut PageTable, addr: VirtAddr) { + fn unmap(&self, pt: &mut dyn PageTable, addr: VirtAddr) { let entry = pt.get_entry(addr).expect("failed to get entry"); if entry.present() { self.allocator.dealloc(entry.target()); @@ -29,8 +29,8 @@ impl MemoryHandler for Delay { fn clone_map( &self, - pt: &mut PageTable, - src_pt: &mut PageTable, + pt: &mut dyn PageTable, + src_pt: &mut dyn PageTable, addr: VirtAddr, attr: &MemoryAttr, ) { @@ -48,7 +48,7 @@ impl MemoryHandler for Delay { } } - fn handle_page_fault(&self, pt: &mut PageTable, addr: VirtAddr) -> bool { + fn handle_page_fault(&self, pt: &mut dyn PageTable, addr: VirtAddr) -> bool { let entry = pt.get_entry(addr).expect("failed to get entry"); if entry.present() { // not a delay case diff --git a/crate/memory/src/memory_set/handler/file.rs b/crate/memory/src/memory_set/handler/file.rs index bef7f40..cfd505e 100644 --- a/crate/memory/src/memory_set/handler/file.rs +++ b/crate/memory/src/memory_set/handler/file.rs @@ -15,17 +15,17 @@ pub trait Read: Clone + Send + Sync + 'static { } impl MemoryHandler for File { - fn box_clone(&self) -> Box { + fn box_clone(&self) -> Box { Box::new(self.clone()) } - fn map(&self, pt: &mut PageTable, addr: usize, attr: &MemoryAttr) { + fn map(&self, pt: &mut dyn PageTable, addr: usize, attr: &MemoryAttr) { let entry = pt.map(addr, 0); entry.set_present(false); attr.apply(entry); } - fn unmap(&self, pt: &mut PageTable, addr: usize) { + fn unmap(&self, pt: &mut dyn PageTable, addr: usize) { let entry = pt.get_entry(addr).expect("failed to get entry"); if entry.present() { self.allocator.dealloc(entry.target()); @@ -38,8 +38,8 @@ impl MemoryHandler for File { fn clone_map( &self, - pt: &mut PageTable, - src_pt: &mut PageTable, + pt: &mut dyn PageTable, + src_pt: &mut dyn PageTable, addr: usize, attr: &MemoryAttr, ) { @@ -57,7 +57,7 @@ impl MemoryHandler for File { } } - fn handle_page_fault(&self, pt: &mut PageTable, addr: usize) -> bool { + fn handle_page_fault(&self, pt: &mut dyn PageTable, addr: usize) -> bool { let addr = addr & !(PAGE_SIZE - 1); let entry = pt.get_entry(addr).expect("failed to get entry"); if entry.present() { @@ -74,7 +74,7 @@ impl MemoryHandler for File { } impl File { - fn fill_data(&self, pt: &mut PageTable, addr: VirtAddr) { + fn fill_data(&self, pt: &mut dyn PageTable, addr: VirtAddr) { let data = pt.get_page_slice_mut(addr); let file_offset = addr + self.file_start - self.mem_start; let read_size = (self.file_end as isize - file_offset as isize) diff --git a/crate/memory/src/memory_set/handler/linear.rs b/crate/memory/src/memory_set/handler/linear.rs index 81b987f..a32ea79 100644 --- a/crate/memory/src/memory_set/handler/linear.rs +++ b/crate/memory/src/memory_set/handler/linear.rs @@ -6,31 +6,31 @@ pub struct Linear { } impl MemoryHandler for Linear { - fn box_clone(&self) -> Box { + fn box_clone(&self) -> Box { Box::new(self.clone()) } - fn map(&self, pt: &mut PageTable, addr: VirtAddr, attr: &MemoryAttr) { + fn map(&self, pt: &mut dyn PageTable, addr: VirtAddr, attr: &MemoryAttr) { let target = (addr as isize + self.offset) as PhysAddr; let entry = pt.map(addr, target); attr.apply(entry); } - fn unmap(&self, pt: &mut PageTable, addr: VirtAddr) { + fn unmap(&self, pt: &mut dyn PageTable, addr: VirtAddr) { pt.unmap(addr); } fn clone_map( &self, - pt: &mut PageTable, - _src_pt: &mut PageTable, + pt: &mut dyn PageTable, + _src_pt: &mut dyn PageTable, addr: VirtAddr, attr: &MemoryAttr, ) { self.map(pt, addr, attr); } - fn handle_page_fault(&self, _pt: &mut PageTable, _addr: VirtAddr) -> bool { + fn handle_page_fault(&self, _pt: &mut dyn PageTable, _addr: VirtAddr) -> bool { false } } diff --git a/crate/memory/src/memory_set/handler/mod.rs b/crate/memory/src/memory_set/handler/mod.rs index d2a6bc3..e2bd3a2 100644 --- a/crate/memory/src/memory_set/handler/mod.rs +++ b/crate/memory/src/memory_set/handler/mod.rs @@ -2,31 +2,31 @@ use super::*; // here may be a interesting part for lab pub trait MemoryHandler: Debug + Send + Sync + 'static { - fn box_clone(&self) -> Box; + fn box_clone(&self) -> Box; /// Map `addr` in the page table /// Should set page flags here instead of in `page_fault_handler` - fn map(&self, pt: &mut PageTable, addr: VirtAddr, attr: &MemoryAttr); + fn map(&self, pt: &mut dyn PageTable, addr: VirtAddr, attr: &MemoryAttr); /// Unmap `addr` in the page table - fn unmap(&self, pt: &mut PageTable, addr: VirtAddr); + fn unmap(&self, pt: &mut dyn PageTable, addr: VirtAddr); /// Clone map `addr` from page table `src_pt` to `pt`. fn clone_map( &self, - pt: &mut PageTable, - src_pt: &mut PageTable, + pt: &mut dyn PageTable, + src_pt: &mut dyn PageTable, addr: VirtAddr, attr: &MemoryAttr, ); /// Handle page fault on `addr` /// Return true if success, false if error - fn handle_page_fault(&self, pt: &mut PageTable, addr: VirtAddr) -> bool; + fn handle_page_fault(&self, pt: &mut dyn PageTable, addr: VirtAddr) -> bool; } -impl Clone for Box { - fn clone(&self) -> Box { +impl Clone for Box { + fn clone(&self) -> Box { self.box_clone() } } diff --git a/crate/memory/src/memory_set/mod.rs b/crate/memory/src/memory_set/mod.rs index 9e572e3..35ceaed 100644 --- a/crate/memory/src/memory_set/mod.rs +++ b/crate/memory/src/memory_set/mod.rs @@ -1,6 +1,6 @@ //! Memory management structures -use alloc::{boxed::Box, string::String, vec::Vec}; +use alloc::{boxed::Box, vec::Vec}; use core::fmt::{Debug, Error, Formatter}; use core::mem::size_of; @@ -18,7 +18,7 @@ pub struct MemoryArea { start_addr: VirtAddr, end_addr: VirtAddr, attr: MemoryAttr, - handler: Box, + handler: Box, name: &'static str, } @@ -58,13 +58,13 @@ impl MemoryArea { !(p1 <= p2 || p0 >= p3) } /// Map all pages in the area to page table `pt` - fn map(&self, pt: &mut PageTable) { + fn map(&self, pt: &mut dyn PageTable) { for page in Page::range_of(self.start_addr, self.end_addr) { self.handler.map(pt, page.start_address(), &self.attr); } } /// Unmap all pages in the area from page table `pt` - fn unmap(&self, pt: &mut PageTable) { + fn unmap(&self, pt: &mut dyn PageTable) { for page in Page::range_of(self.start_addr, self.end_addr) { self.handler.unmap(pt, page.start_address()); } @@ -103,7 +103,7 @@ impl MemoryAttr { } /// Apply the attributes to page table entry, then update it. /// NOTE: You may need to set present manually. - pub fn apply(&self, entry: &mut Entry) { + pub fn apply(&self, entry: &mut dyn Entry) { entry.set_user(self.user); entry.set_writable(!self.readonly); entry.set_execute(self.execute); diff --git a/crate/memory/src/paging/mock_page_table.rs b/crate/memory/src/paging/mock_page_table.rs index 35a8b0d..4f791d3 100644 --- a/crate/memory/src/paging/mock_page_table.rs +++ b/crate/memory/src/paging/mock_page_table.rs @@ -101,12 +101,12 @@ impl Entry for MockEntry { } } -type PageFaultHandler = Box; +type PageFaultHandler = Box; impl PageTable for MockPageTable { // type Entry = MockEntry; - fn map(&mut self, addr: VirtAddr, target: PhysAddr) -> &mut Entry { + fn map(&mut self, addr: VirtAddr, target: PhysAddr) -> &mut dyn Entry { let entry = &mut self.entries[addr / PAGE_SIZE]; assert!(!entry.present); entry.present = true; @@ -119,7 +119,7 @@ impl PageTable for MockPageTable { assert!(entry.present); entry.present = false; } - fn get_entry(&mut self, addr: VirtAddr) -> Option<&mut Entry> { + fn get_entry(&mut self, addr: VirtAddr) -> Option<&mut dyn Entry> { Some(&mut self.entries[addr / PAGE_SIZE]) } fn get_page_slice_mut<'a, 'b>(&'a mut self, addr: VirtAddr) -> &'b mut [u8] { diff --git a/crate/memory/src/paging/mod.rs b/crate/memory/src/paging/mod.rs index 2c54948..6dfe551 100644 --- a/crate/memory/src/paging/mod.rs +++ b/crate/memory/src/paging/mod.rs @@ -14,14 +14,14 @@ pub trait PageTable { /// Map a page of virual address `addr` to the frame of physics address `target` /// Return the page table entry of the mapped virual address - fn map(&mut self, addr: VirtAddr, target: PhysAddr) -> &mut Entry; + fn map(&mut self, addr: VirtAddr, target: PhysAddr) -> &mut dyn Entry; /// Unmap a page of virual address `addr` fn unmap(&mut self, addr: VirtAddr); /// Get the page table entry of a page of virual address `addr` /// If its page do not exist, return `None` - fn get_entry(&mut self, addr: VirtAddr) -> Option<&mut Entry>; + fn get_entry(&mut self, addr: VirtAddr) -> Option<&mut dyn Entry>; /// Get a mutable reference of the content of a page of virtual address `addr` fn get_page_slice_mut<'a>(&mut self, addr: VirtAddr) -> &'a mut [u8]; diff --git a/kernel/src/arch/aarch64/paging.rs b/kernel/src/arch/aarch64/paging.rs index 014d3f5..981c3bb 100644 --- a/kernel/src/arch/aarch64/paging.rs +++ b/kernel/src/arch/aarch64/paging.rs @@ -24,7 +24,7 @@ pub struct PageTableImpl { pub struct PageEntry(&'static mut PageTableEntry, Page); impl PageTable for PageTableImpl { - fn map(&mut self, addr: usize, target: usize) -> &mut Entry { + fn map(&mut self, addr: usize, target: usize) -> &mut dyn Entry { let flags = EF::default(); let attr = MairNormal::attr_value(); unsafe { @@ -50,12 +50,12 @@ impl PageTable for PageTableImpl { .flush(); } - fn get_entry(&mut self, vaddr: usize) -> Option<&mut Entry> { + fn get_entry(&mut self, vaddr: usize) -> Option<&mut dyn Entry> { let page = Page::of_addr(vaddr as u64); if let Ok(e) = self.page_table.get_entry_mut(page) { let e = unsafe { &mut *(e as *mut PageTableEntry) }; self.entry = PageEntry(e, page); - Some(&mut self.entry as &mut Entry) + Some(&mut self.entry as &mut dyn Entry) } else { None } diff --git a/kernel/src/arch/x86_64/board/mod.rs b/kernel/src/arch/x86_64/board/mod.rs index d99c32c..db9cfb2 100755 --- a/kernel/src/arch/x86_64/board/mod.rs +++ b/kernel/src/arch/x86_64/board/mod.rs @@ -1,10 +1,10 @@ #[path = "../../../drivers/gpu/fb.rs"] pub mod fb; -use crate::consts::KERNEL_OFFSET; + use crate::memory::phys_to_virt; use bootloader::bootinfo::{BootInfo, VbeModeInfo}; -use core::mem::zeroed; + use fb::{ColorConfig, FramebufferInfo, FramebufferResult, FRAME_BUFFER}; static mut VBE_MODE: VbeModeInfo = VbeModeInfo { diff --git a/kernel/src/arch/x86_64/io.rs b/kernel/src/arch/x86_64/io.rs index 08893bc..e7f287d 100644 --- a/kernel/src/arch/x86_64/io.rs +++ b/kernel/src/arch/x86_64/io.rs @@ -1,4 +1,4 @@ -use super::driver::console::CONSOLE; + use super::driver::serial::*; use core::fmt::{Arguments, Write}; diff --git a/kernel/src/arch/x86_64/ipi.rs b/kernel/src/arch/x86_64/ipi.rs index abe6c08..b862a9e 100644 --- a/kernel/src/arch/x86_64/ipi.rs +++ b/kernel/src/arch/x86_64/ipi.rs @@ -6,10 +6,10 @@ use alloc::sync::Arc; use apic::{LocalApic, XApic, LAPIC_ADDR}; use core::sync::atomic::{spin_loop_hint, AtomicU8, Ordering}; -pub type IPIEventItem = Box; +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/memory.rs b/kernel/src/arch/x86_64/memory.rs index ca57515..3a4ddad 100644 --- a/kernel/src/arch/x86_64/memory.rs +++ b/kernel/src/arch/x86_64/memory.rs @@ -1,7 +1,7 @@ use super::{BootInfo, MemoryRegionType}; use crate::memory::{init_heap, FRAME_ALLOCATOR}; use bitmap_allocator::BitAlloc; -use rcore_memory::paging::*; + pub fn init(boot_info: &BootInfo) { init_frame_allocator(boot_info); diff --git a/kernel/src/arch/x86_64/paging.rs b/kernel/src/arch/x86_64/paging.rs index 8ce5507..92a5baf 100644 --- a/kernel/src/arch/x86_64/paging.rs +++ b/kernel/src/arch/x86_64/paging.rs @@ -1,5 +1,5 @@ use crate::memory::{alloc_frame, dealloc_frame, phys_to_virt}; -use core::sync::atomic::Ordering; + use log::*; use rcore_memory::paging::*; use x86_64::instructions::tlb; @@ -20,7 +20,7 @@ pub trait PageExt { impl PageExt for Page { fn of_addr(address: usize) -> Self { - use x86_64; + Page::containing_address(VirtAddr::new(address as u64)) } fn range_of(begin: usize, end: usize) -> PageRange { @@ -47,7 +47,7 @@ pub struct PageTableImpl( pub struct PageEntry(&'static mut PageTableEntry, Page, Frame); impl PageTable for PageTableImpl { - fn map(&mut self, addr: usize, target: usize) -> &mut Entry { + fn map(&mut self, addr: usize, target: usize) -> &mut dyn Entry { let flags = EF::PRESENT | EF::WRITABLE | EF::NO_EXECUTE; unsafe { self.0 @@ -69,7 +69,7 @@ impl PageTable for PageTableImpl { flush_tlb_all(addr); } - fn get_entry(&mut self, addr: usize) -> Option<&mut Entry> { + fn get_entry(&mut self, addr: usize) -> Option<&mut dyn Entry> { let mut page_table = frame_to_page_table(self.2); for level in 0..4 { let index = (addr >> (12 + (3 - level) * 9)) & 0o777; @@ -77,7 +77,7 @@ impl PageTable for PageTableImpl { if level == 3 { let page = Page::of_addr(addr); self.1 = PageEntry(entry, page, self.2); - return Some(&mut self.1 as &mut Entry); + return Some(&mut self.1 as &mut dyn Entry); } if !entry.flags().contains(EF::PRESENT) { return None; diff --git a/kernel/src/drivers/bus/pci.rs b/kernel/src/drivers/bus/pci.rs index c122646..ffc7d52 100644 --- a/kernel/src/drivers/bus/pci.rs +++ b/kernel/src/drivers/bus/pci.rs @@ -237,6 +237,6 @@ pub fn get_bar0_mem(loc: Location) -> Option<(usize, usize)> { } lazy_static! { - pub static ref PCI_DRIVERS: Mutex>> = + pub static ref PCI_DRIVERS: Mutex>> = Mutex::new(BTreeMap::new()); } diff --git a/kernel/src/drivers/console/mod.rs b/kernel/src/drivers/console/mod.rs index f7737ee..ee8b635 100644 --- a/kernel/src/drivers/console/mod.rs +++ b/kernel/src/drivers/console/mod.rs @@ -10,7 +10,7 @@ use spin::Mutex; use crate::util::escape_parser::{CharacterAttribute, EscapeParser}; -use super::fb::{ColorConfig, ColorDepth::*, FramebufferInfo, FRAME_BUFFER}; +use super::fb::{ColorConfig, FramebufferInfo, FRAME_BUFFER}; use self::color::FramebufferColor; use self::fonts::{Font, Font8x16}; diff --git a/kernel/src/drivers/gpu/fb.rs b/kernel/src/drivers/gpu/fb.rs index de278af..2ee7073 100644 --- a/kernel/src/drivers/gpu/fb.rs +++ b/kernel/src/drivers/gpu/fb.rs @@ -1,6 +1,6 @@ //! Framebuffer -use crate::fs::vga::{fb_bitfield, fb_var_screeninfo}; +use crate::fs::vga::{fb_var_screeninfo}; use alloc::string::String; use core::fmt; use lazy_static::lazy_static; @@ -54,7 +54,7 @@ pub enum ColorConfig { BGRA8888, VgaPalette, } -use self::ColorConfig::*; + pub type FramebufferResult = Result<(FramebufferInfo, ColorConfig, usize), String>; diff --git a/kernel/src/drivers/mod.rs b/kernel/src/drivers/mod.rs index bc9bba8..dadeb03 100644 --- a/kernel/src/drivers/mod.rs +++ b/kernel/src/drivers/mod.rs @@ -93,12 +93,12 @@ pub trait Driver: Send + Sync { lazy_static! { // NOTE: RwLock only write when initializing drivers - pub static ref DRIVERS: RwLock>> = RwLock::new(Vec::new()); - pub static ref NET_DRIVERS: RwLock>> = RwLock::new(Vec::new()); - pub static ref BLK_DRIVERS: RwLock>> = RwLock::new(Vec::new()); + pub static ref DRIVERS: RwLock>> = RwLock::new(Vec::new()); + pub static ref NET_DRIVERS: RwLock>> = RwLock::new(Vec::new()); + pub static ref BLK_DRIVERS: RwLock>> = RwLock::new(Vec::new()); } -pub struct BlockDriver(pub Arc); +pub struct BlockDriver(pub Arc); impl BlockDevice for BlockDriver { const BLOCK_SIZE_LOG2: u8 = 9; // 512 diff --git a/kernel/src/drivers/net/router.rs b/kernel/src/drivers/net/router.rs index 6577d5b..7892b86 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 _i in 1..rdfo { buffer.push(AXI_STREAM_FIFO_RDFD.read_volatile() as u8); } debug!( diff --git a/kernel/src/drivers/provider.rs b/kernel/src/drivers/provider.rs index 909a121..b12180a 100644 --- a/kernel/src/drivers/provider.rs +++ b/kernel/src/drivers/provider.rs @@ -11,7 +11,7 @@ impl provider::Provider for Provider { fn alloc_dma(size: usize) -> (usize, usize) { // TODO: allocate continuous pages let mut paddr = alloc_frame().unwrap(); - for i in 1..(size / PAGE_SIZE) { + for _i in 1..(size / PAGE_SIZE) { let paddr_new = alloc_frame().unwrap(); assert_eq!(paddr - PAGE_SIZE, paddr_new); paddr = paddr_new; @@ -20,7 +20,7 @@ impl provider::Provider for Provider { (vaddr, paddr) } - fn dealloc_dma(vaddr: usize, size: usize) { + fn dealloc_dma(vaddr: usize, _size: usize) { let paddr = virt_to_phys(vaddr); dealloc_frame(paddr); } diff --git a/kernel/src/fs/file.rs b/kernel/src/fs/file.rs index db4f84e..2eb9a64 100644 --- a/kernel/src/fs/file.rs +++ b/kernel/src/fs/file.rs @@ -8,7 +8,7 @@ use rcore_fs::vfs::{FsError, INode, Metadata, PollStatus, Result}; #[derive(Clone)] pub struct FileHandle { - inode: Arc, + inode: Arc, offset: u64, options: OpenOptions, pub path: String, @@ -31,7 +31,7 @@ pub enum SeekFrom { } impl FileHandle { - pub fn new(inode: Arc, options: OpenOptions, path: String) -> Self { + pub fn new(inode: Arc, options: OpenOptions, path: String) -> Self { return FileHandle { inode, offset: 0, @@ -120,7 +120,7 @@ impl FileHandle { self.inode.metadata() } - pub fn lookup_follow(&self, path: &str, max_follow: usize) -> Result> { + pub fn lookup_follow(&self, path: &str, max_follow: usize) -> Result> { self.inode.lookup_follow(path, max_follow) } @@ -141,7 +141,7 @@ impl FileHandle { self.inode.io_control(cmd, arg) } - pub fn inode(&self) -> Arc { + pub fn inode(&self) -> Arc { self.inode.clone() } diff --git a/kernel/src/fs/file_like.rs b/kernel/src/fs/file_like.rs index bd45dc8..938e9c3 100644 --- a/kernel/src/fs/file_like.rs +++ b/kernel/src/fs/file_like.rs @@ -60,7 +60,7 @@ 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(_socket) => { //TODO } } diff --git a/kernel/src/fs/mod.rs b/kernel/src/fs/mod.rs index 99fe306..f7bc6b7 100644 --- a/kernel/src/fs/mod.rs +++ b/kernel/src/fs/mod.rs @@ -39,7 +39,7 @@ _user_img_end: lazy_static! { /// The root of file system - pub static ref ROOT_INODE: Arc = { + pub static ref ROOT_INODE: Arc = { #[cfg(not(feature = "link_user"))] let device = { #[cfg(any(target_arch = "riscv32", target_arch = "riscv64", target_arch = "x86_64"))] @@ -80,7 +80,7 @@ pub trait INodeExt { fn read_as_vec(&self) -> Result>; } -impl INodeExt for INode { +impl INodeExt for dyn INode { fn read_as_vec(&self) -> Result> { let size = self.metadata()?.size; let mut buf = Vec::with_capacity(size); diff --git a/kernel/src/fs/pipe.rs b/kernel/src/fs/pipe.rs index 59fa2fa..e1e6164 100644 --- a/kernel/src/fs/pipe.rs +++ b/kernel/src/fs/pipe.rs @@ -74,15 +74,15 @@ macro_rules! impl_inode { fn sync_all(&self) -> Result<()> { Ok(()) } fn sync_data(&self) -> Result<()> { Ok(()) } fn resize(&self, _len: usize) -> Result<()> { Err(FsError::NotSupported) } - fn create(&self, _name: &str, _type_: FileType, _mode: u32) -> Result> { Err(FsError::NotDir) } + fn create(&self, _name: &str, _type_: FileType, _mode: u32) -> Result> { Err(FsError::NotDir) } fn unlink(&self, _name: &str) -> Result<()> { Err(FsError::NotDir) } - fn link(&self, _name: &str, _other: &Arc) -> Result<()> { Err(FsError::NotDir) } - fn move_(&self, _old_name: &str, _target: &Arc, _new_name: &str) -> Result<()> { Err(FsError::NotDir) } - fn find(&self, _name: &str) -> Result> { Err(FsError::NotDir) } + fn link(&self, _name: &str, _other: &Arc) -> Result<()> { Err(FsError::NotDir) } + fn move_(&self, _old_name: &str, _target: &Arc, _new_name: &str) -> Result<()> { Err(FsError::NotDir) } + fn find(&self, _name: &str) -> Result> { Err(FsError::NotDir) } fn get_entry(&self, _id: usize) -> Result { Err(FsError::NotDir) } fn io_control(&self, _cmd: u32, _data: usize) -> Result<()> { Err(FsError::NotSupported) } - fn fs(&self) -> Arc { unimplemented!() } - fn as_any_ref(&self) -> &Any { self } + fn fs(&self) -> Arc { unimplemented!() } + fn as_any_ref(&self) -> &dyn Any { self } }; } diff --git a/kernel/src/fs/pseudo.rs b/kernel/src/fs/pseudo.rs index 273a200..7f10ec1 100644 --- a/kernel/src/fs/pseudo.rs +++ b/kernel/src/fs/pseudo.rs @@ -26,15 +26,15 @@ macro_rules! impl_inode { fn sync_all(&self) -> Result<()> { Ok(()) } fn sync_data(&self) -> Result<()> { Ok(()) } fn resize(&self, _len: usize) -> Result<()> { Err(FsError::NotSupported) } - fn create(&self, _name: &str, _type_: FileType, _mode: u32) -> Result> { Err(FsError::NotDir) } + fn create(&self, _name: &str, _type_: FileType, _mode: u32) -> Result> { Err(FsError::NotDir) } fn unlink(&self, _name: &str) -> Result<()> { Err(FsError::NotDir) } - fn link(&self, _name: &str, _other: &Arc) -> Result<()> { Err(FsError::NotDir) } - fn move_(&self, _old_name: &str, _target: &Arc, _new_name: &str) -> Result<()> { Err(FsError::NotDir) } - fn find(&self, _name: &str) -> Result> { Err(FsError::NotDir) } + fn link(&self, _name: &str, _other: &Arc) -> Result<()> { Err(FsError::NotDir) } + fn move_(&self, _old_name: &str, _target: &Arc, _new_name: &str) -> Result<()> { Err(FsError::NotDir) } + fn find(&self, _name: &str) -> Result> { Err(FsError::NotDir) } fn get_entry(&self, _id: usize) -> Result { Err(FsError::NotDir) } - fn io_control(&self, cmd: u32, data: usize) -> Result<()> { Err(FsError::NotSupported) } - fn fs(&self) -> Arc { unimplemented!() } - fn as_any_ref(&self) -> &Any { self } + fn io_control(&self, _cmd: u32, _data: usize) -> Result<()> { Err(FsError::NotSupported) } + fn fs(&self) -> Arc { unimplemented!() } + fn as_any_ref(&self) -> &dyn Any { self } }; } diff --git a/kernel/src/fs/stdio.rs b/kernel/src/fs/stdio.rs index a3f84a1..1eacbc7 100644 --- a/kernel/src/fs/stdio.rs +++ b/kernel/src/fs/stdio.rs @@ -61,11 +61,11 @@ macro_rules! impl_inode { fn sync_all(&self) -> Result<()> { Ok(()) } fn sync_data(&self) -> Result<()> { Ok(()) } fn resize(&self, _len: usize) -> Result<()> { Err(FsError::NotSupported) } - fn create(&self, _name: &str, _type_: FileType, _mode: u32) -> Result> { Err(FsError::NotDir) } + fn create(&self, _name: &str, _type_: FileType, _mode: u32) -> Result> { Err(FsError::NotDir) } fn unlink(&self, _name: &str) -> Result<()> { Err(FsError::NotDir) } - fn link(&self, _name: &str, _other: &Arc) -> Result<()> { Err(FsError::NotDir) } - fn move_(&self, _old_name: &str, _target: &Arc, _new_name: &str) -> Result<()> { Err(FsError::NotDir) } - fn find(&self, _name: &str) -> Result> { Err(FsError::NotDir) } + fn link(&self, _name: &str, _other: &Arc) -> Result<()> { Err(FsError::NotDir) } + fn move_(&self, _old_name: &str, _target: &Arc, _new_name: &str) -> Result<()> { Err(FsError::NotDir) } + fn find(&self, _name: &str) -> Result> { Err(FsError::NotDir) } fn get_entry(&self, _id: usize) -> Result { Err(FsError::NotDir) } fn io_control(&self, cmd: u32, data: usize) -> Result<()> { match cmd as usize { @@ -84,13 +84,13 @@ macro_rules! impl_inode { _ => Err(FsError::NotSupported) } } - fn fs(&self) -> Arc { unimplemented!() } - fn as_any_ref(&self) -> &Any { self } + fn fs(&self) -> Arc { unimplemented!() } + fn as_any_ref(&self) -> &dyn Any { self } }; } 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 95b0385..d077011 100755 --- a/kernel/src/fs/vga.rs +++ b/kernel/src/fs/vga.rs @@ -1,8 +1,8 @@ use rcore_fs::vfs::*; use crate::arch::board::fb::FRAME_BUFFER; -use crate::memory::phys_to_virt; -use alloc::{string::String, sync::Arc, vec::Vec}; + +use alloc::{string::String, sync::Arc}; use core::any::Any; #[derive(Default)] @@ -14,19 +14,19 @@ macro_rules! impl_inode { fn sync_all(&self) -> Result<()> { Ok(()) } fn sync_data(&self) -> Result<()> { Ok(()) } fn resize(&self, _len: usize) -> Result<()> { Err(FsError::NotSupported) } - fn create(&self, _name: &str, _type_: FileType, _mode: u32) -> Result> { Err(FsError::NotDir) } + fn create(&self, _name: &str, _type_: FileType, _mode: u32) -> Result> { Err(FsError::NotDir) } fn unlink(&self, _name: &str) -> Result<()> { Err(FsError::NotDir) } - fn link(&self, _name: &str, _other: &Arc) -> Result<()> { Err(FsError::NotDir) } - fn move_(&self, _old_name: &str, _target: &Arc, _new_name: &str) -> Result<()> { Err(FsError::NotDir) } - fn find(&self, _name: &str) -> Result> { Err(FsError::NotDir) } + fn link(&self, _name: &str, _other: &Arc) -> Result<()> { Err(FsError::NotDir) } + fn move_(&self, _old_name: &str, _target: &Arc, _new_name: &str) -> Result<()> { Err(FsError::NotDir) } + fn find(&self, _name: &str) -> Result> { Err(FsError::NotDir) } fn get_entry(&self, _id: usize) -> Result { Err(FsError::NotDir) } - fn fs(&self) -> Arc { unimplemented!() } - fn as_any_ref(&self) -> &Any { self } + fn fs(&self) -> Arc { unimplemented!() } + fn as_any_ref(&self) -> &dyn Any { self } }; } 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/lib.rs b/kernel/src/lib.rs index 54cc330..0417ad4 100644 --- a/kernel/src/lib.rs +++ b/kernel/src/lib.rs @@ -1,14 +1,13 @@ #![feature(lang_items)] -#![feature(alloc)] #![feature(naked_functions)] #![feature(untagged_unions)] #![feature(asm)] #![feature(optin_builtin_traits)] #![feature(panic_info_message)] #![feature(global_asm)] -#![feature(maybe_uninit)] #![deny(unused_must_use)] #![no_std] +#![allow(non_snake_case, unused_imports, unused_variables, unused_assignments, dead_code)] // just keep it ... #[macro_use] diff --git a/kernel/src/main.rs b/kernel/src/main.rs index b3a360e..0ce3725 100644 --- a/kernel/src/main.rs +++ b/kernel/src/main.rs @@ -1,7 +1,6 @@ #![no_std] // don't link the Rust standard library #![cfg_attr(not(test), no_main)] // disable all Rust-level entry points #![cfg_attr(test, allow(dead_code, unused_macros, unused_imports))] -#![allow(non_snake_case, unused_imports, unused_variables, unused_assignments)] #[allow(unused_imports)] use rcore; diff --git a/kernel/src/memory.rs b/kernel/src/memory.rs index 99c41f0..286b364 100644 --- a/kernel/src/memory.rs +++ b/kernel/src/memory.rs @@ -148,7 +148,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 _i 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 544b87c..cbc3a0d 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) => 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) => 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 => { @@ -691,13 +691,12 @@ impl Socket for RawSocketState { fn setsockopt(&mut self, level: usize, opt: usize, data: &[u8]) -> SysResult { match (level, opt) { - (IPPROTO_IP, IP_HDRINCL) => { + (_IPPROTO_IP, _IP_HDRINCL) => { if let Some(arg) = data.first() { self.header_included = *arg > 0; debug!("hdrincl set to {}", self.header_included); } } - _ => {} } Ok(0) } @@ -710,7 +709,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 9e0633a..3ee1188 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/mod.rs b/kernel/src/process/mod.rs index e08f628..2f00b1d 100644 --- a/kernel/src/process/mod.rs +++ b/kernel/src/process/mod.rs @@ -126,6 +126,6 @@ pub fn processor() -> &'static Processor { } #[no_mangle] -pub fn new_kernel_context(entry: extern "C" fn(usize) -> !, arg: usize) -> Box { +pub fn new_kernel_context(entry: extern "C" fn(usize) -> !, arg: usize) -> Box { Thread::new_kernel(entry, arg) } diff --git a/kernel/src/process/structs.rs b/kernel/src/process/structs.rs index d3bf3c1..28827de 100644 --- a/kernel/src/process/structs.rs +++ b/kernel/src/process/structs.rs @@ -84,7 +84,7 @@ lazy_static! { /// Let `rcore_thread` can switch between our `Thread` impl rcore_thread::Context for Thread { - unsafe fn switch_to(&mut self, target: &mut rcore_thread::Context) { + unsafe fn switch_to(&mut self, target: &mut dyn rcore_thread::Context) { use core::mem::transmute; let (target, _): (&mut Thread, *const ()) = transmute(target); self.context.switch(&mut target.context); @@ -241,7 +241,7 @@ impl Thread { /// Make a new user process from ELF `data` pub fn new_user( - inode: &Arc, + inode: &Arc, exec_path: &str, args: Vec, envs: Vec, @@ -443,7 +443,7 @@ impl ToMemoryAttr for Flags { /// Helper functions to process ELF file trait ElfExt { /// Generate a MemorySet according to the ELF file. - fn make_memory_set(&self, inode: &Arc) -> MemorySet; + fn make_memory_set(&self, inode: &Arc) -> MemorySet; /// Get interpreter string if it has. fn get_interpreter(&self) -> Result<&str, &str>; @@ -453,7 +453,7 @@ trait ElfExt { } impl ElfExt for ElfFile<'_> { - fn make_memory_set(&self, inode: &Arc) -> MemorySet { + fn make_memory_set(&self, inode: &Arc) -> MemorySet { debug!("creating MemorySet from ELF"); let mut ms = MemorySet::new(); @@ -517,7 +517,7 @@ impl ElfExt for ElfFile<'_> { } #[derive(Clone)] -pub struct INodeForMap(pub Arc); +pub struct INodeForMap(pub Arc); impl Read for INodeForMap { fn read_at(&self, offset: usize, buf: &mut [u8]) -> usize { diff --git a/kernel/src/sync/condvar.rs b/kernel/src/sync/condvar.rs index e9e4ae0..2013e86 100644 --- a/kernel/src/sync/condvar.rs +++ b/kernel/src/sync/condvar.rs @@ -7,7 +7,7 @@ use alloc::vec::Vec; #[derive(Default)] pub struct Condvar { - wait_queue: SpinNoIrqLock>>, + pub wait_queue: SpinNoIrqLock>>, } impl Condvar { @@ -34,7 +34,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) } @@ -50,7 +50,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); } processor().manager().sleep(tid, 0); diff --git a/kernel/src/sync/mutex.rs b/kernel/src/sync/mutex.rs index 623bac5..5496e9d 100644 --- a/kernel/src/sync/mutex.rs +++ b/kernel/src/sync/mutex.rs @@ -287,6 +287,7 @@ impl MutexSupport for Condvar { Condvar::new() } fn cpu_relax(&self) { + #[allow(deprecated)] //Not really possible to work around. self._wait(); } fn before_lock() -> Self::GuardData {} diff --git a/kernel/src/sync/test.rs b/kernel/src/sync/test.rs index 76196e8..148da0b 100644 --- a/kernel/src/sync/test.rs +++ b/kernel/src/sync/test.rs @@ -21,7 +21,7 @@ impl Philosopher { Philosopher { name, left, right } } - fn eat(&self, table: &Arc) { + fn eat(&self, table: &Arc) { table.eat(self.name, self.left, self.right); } @@ -79,7 +79,7 @@ impl Table for MonitorTable { } } -fn philosopher(table: Arc
) { +fn philosopher(table: Arc) { let philosophers = vec![ Philosopher::new("1", 0, 1), Philosopher::new("2", 1, 2), diff --git a/kernel/src/syscall/fs.rs b/kernel/src/syscall/fs.rs index 20bdd30..640e2c6 100644 --- a/kernel/src/syscall/fs.rs +++ b/kernel/src/syscall/fs.rs @@ -274,7 +274,7 @@ impl Syscall<'_> { mode: usize, ) -> SysResult { let mut proc = self.process(); - let path = unsafe { check_and_clone_cstr(path)? }; + let path = check_and_clone_cstr(path)?; let flags = OpenFlags::from_bits_truncate(flags); info!( "openat: dir_fd: {}, path: {:?}, flags: {:?}, mode: {:#o}", @@ -338,7 +338,7 @@ impl Syscall<'_> { ) -> SysResult { // TODO: check permissions based on uid/gid let proc = self.process(); - let path = unsafe { check_and_clone_cstr(path)? }; + let path = check_and_clone_cstr(path)?; let flags = AtFlags::from_bits_truncate(flags); if !proc.pid.is_init() { // we trust pid 0 process @@ -347,7 +347,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) } @@ -419,7 +419,7 @@ impl Syscall<'_> { len: usize, ) -> SysResult { let proc = self.process(); - let path = unsafe { check_and_clone_cstr(path)? }; + let path = check_and_clone_cstr(path)?; let slice = unsafe { self.vm().check_write_array(base, len)? }; info!( "readlinkat: dirfd: {}, path: {:?}, base: {:?}, len: {}", @@ -465,7 +465,7 @@ impl Syscall<'_> { pub fn sys_truncate(&mut self, path: *const u8, len: usize) -> SysResult { let proc = self.process(); - let path = unsafe { check_and_clone_cstr(path)? }; + let path = check_and_clone_cstr(path)?; info!("truncate: path: {:?}, len: {}", path, len); proc.lookup_inode(&path)?.resize(len)?; Ok(0) @@ -678,7 +678,7 @@ impl Syscall<'_> { pub fn sys_unlinkat(&mut self, dirfd: usize, path: *const u8, flags: usize) -> SysResult { let proc = self.process(); - let path = unsafe { check_and_clone_cstr(path)? }; + let path = check_and_clone_cstr(path)?; let flags = AtFlags::from_bits_truncate(flags); info!( "unlinkat: dirfd: {}, path: {:?}, flags: {:?}", @@ -876,7 +876,7 @@ impl Process { dirfd: usize, path: &str, follow: bool, - ) -> Result, SysError> { + ) -> Result, SysError> { debug!( "lookup_inode_at: dirfd: {:?}, cwd: {:?}, path: {:?}, follow: {:?}", dirfd as isize, self.cwd, path, follow @@ -916,7 +916,7 @@ impl Process { } } - pub fn lookup_inode(&self, path: &str) -> Result, SysError> { + pub fn lookup_inode(&self, path: &str) -> Result, SysError> { self.lookup_inode_at(AT_FDCWD, path, true) } } diff --git a/kernel/src/syscall/mem.rs b/kernel/src/syscall/mem.rs index 5727802..16e2d6f 100644 --- a/kernel/src/syscall/mem.rs +++ b/kernel/src/syscall/mem.rs @@ -97,7 +97,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/time.rs b/kernel/src/syscall/time.rs index 5cb4bff..f996764 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 { diff --git a/kernel/src/util/escape_parser.rs b/kernel/src/util/escape_parser.rs index 0fc0442..70e2b92 100644 --- a/kernel/src/util/escape_parser.rs +++ b/kernel/src/util/escape_parser.rs @@ -45,8 +45,8 @@ impl CharacterAttribute { 24 => self.underline = false, 27 => self.reverse = false, 29 => self.strikethrough = false, - 30...37 | 90...97 => self.foreground = ConsoleColor::from_console_code(code).unwrap(), - 40...47 | 100...107 => { + 30..=37 | 90..=97 => self.foreground = ConsoleColor::from_console_code(code).unwrap(), + 40..=47 | 100..=107 => { self.background = ConsoleColor::from_console_code(code - 10).unwrap() } _ => { /* unimplemented!() */ } @@ -136,7 +136,7 @@ impl EscapeParser { _ => { /* unimplemented!() */ } }, ParseStatus::ParsingCSI => match byte { - b'0'...b'9' => { + b'0'..=b'9' => { let digit = (byte - b'0') as u32; let param = self.current_param.unwrap_or(0) as u32; let res = param * 10 + digit; @@ -150,7 +150,7 @@ impl EscapeParser { return None; } // @A–Z[\]^_`a–z{|}~ - 0x40...0x7E => { + 0x40..=0x7E => { if let Some(param) = self.current_param { self.params.push(param).unwrap(); }