Clean all warnings

master
Harry Cheng 5 years ago
parent 2b4a2b1f1f
commit 185fb6e891

@ -1,7 +1,5 @@
#![cfg_attr(not(test), no_std)]
#![feature(alloc)]
#![feature(nll)]
#![feature(maybe_uninit)]
// import macros from log
use log::*;

@ -6,17 +6,17 @@ pub struct ByFrame<T: FrameAllocator> {
}
impl<T: FrameAllocator> MemoryHandler for ByFrame<T> {
fn box_clone(&self) -> Box<MemoryHandler> {
fn box_clone(&self) -> Box<dyn MemoryHandler> {
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<T: FrameAllocator> MemoryHandler for ByFrame<T> {
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<T: FrameAllocator> MemoryHandler for ByFrame<T> {
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
}
}

@ -6,17 +6,17 @@ pub struct Delay<T: FrameAllocator> {
}
impl<T: FrameAllocator> MemoryHandler for Delay<T> {
fn box_clone(&self) -> Box<MemoryHandler> {
fn box_clone(&self) -> Box<dyn MemoryHandler> {
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<T: FrameAllocator> MemoryHandler for Delay<T> {
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<T: FrameAllocator> MemoryHandler for Delay<T> {
}
}
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

@ -15,17 +15,17 @@ pub trait Read: Clone + Send + Sync + 'static {
}
impl<F: Read, T: FrameAllocator> MemoryHandler for File<F, T> {
fn box_clone(&self) -> Box<MemoryHandler> {
fn box_clone(&self) -> Box<dyn MemoryHandler> {
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<F: Read, T: FrameAllocator> MemoryHandler for File<F, T> {
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<F: Read, T: FrameAllocator> MemoryHandler for File<F, T> {
}
}
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<F: Read, T: FrameAllocator> MemoryHandler for File<F, T> {
}
impl<F: Read, T: FrameAllocator> File<F, T> {
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)

@ -6,31 +6,31 @@ pub struct Linear {
}
impl MemoryHandler for Linear {
fn box_clone(&self) -> Box<MemoryHandler> {
fn box_clone(&self) -> Box<dyn MemoryHandler> {
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
}
}

@ -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<MemoryHandler>;
fn box_clone(&self) -> Box<dyn MemoryHandler>;
/// 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<MemoryHandler> {
fn clone(&self) -> Box<MemoryHandler> {
impl Clone for Box<dyn MemoryHandler> {
fn clone(&self) -> Box<dyn MemoryHandler> {
self.box_clone()
}
}

@ -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<MemoryHandler>,
handler: Box<dyn MemoryHandler>,
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);

@ -101,12 +101,12 @@ impl Entry for MockEntry {
}
}
type PageFaultHandler = Box<FnMut(&mut MockPageTable, VirtAddr)>;
type PageFaultHandler = Box<dyn FnMut(&mut MockPageTable, VirtAddr)>;
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] {

@ -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];

@ -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
}

@ -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 {

@ -1,4 +1,4 @@
use super::driver::console::CONSOLE;
use super::driver::serial::*;
use core::fmt::{Arguments, Write};

@ -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<Fn()>;
pub type IPIEventItem = Box<dyn Fn()>;
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
}

@ -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);

@ -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;

@ -237,6 +237,6 @@ pub fn get_bar0_mem(loc: Location) -> Option<(usize, usize)> {
}
lazy_static! {
pub static ref PCI_DRIVERS: Mutex<BTreeMap<Location, Arc<Driver>>> =
pub static ref PCI_DRIVERS: Mutex<BTreeMap<Location, Arc<dyn Driver>>> =
Mutex::new(BTreeMap::new());
}

@ -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};

@ -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>;

@ -93,12 +93,12 @@ pub trait Driver: Send + Sync {
lazy_static! {
// NOTE: RwLock only write when initializing drivers
pub static ref DRIVERS: RwLock<Vec<Arc<Driver>>> = RwLock::new(Vec::new());
pub static ref NET_DRIVERS: RwLock<Vec<Arc<Driver>>> = RwLock::new(Vec::new());
pub static ref BLK_DRIVERS: RwLock<Vec<Arc<Driver>>> = RwLock::new(Vec::new());
pub static ref DRIVERS: RwLock<Vec<Arc<dyn Driver>>> = RwLock::new(Vec::new());
pub static ref NET_DRIVERS: RwLock<Vec<Arc<dyn Driver>>> = RwLock::new(Vec::new());
pub static ref BLK_DRIVERS: RwLock<Vec<Arc<dyn Driver>>> = RwLock::new(Vec::new());
}
pub struct BlockDriver(pub Arc<Driver>);
pub struct BlockDriver(pub Arc<dyn Driver>);
impl BlockDevice for BlockDriver {
const BLOCK_SIZE_LOG2: u8 = 9; // 512

@ -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!(

@ -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);
}

@ -8,7 +8,7 @@ use rcore_fs::vfs::{FsError, INode, Metadata, PollStatus, Result};
#[derive(Clone)]
pub struct FileHandle {
inode: Arc<INode>,
inode: Arc<dyn INode>,
offset: u64,
options: OpenOptions,
pub path: String,
@ -31,7 +31,7 @@ pub enum SeekFrom {
}
impl FileHandle {
pub fn new(inode: Arc<INode>, options: OpenOptions, path: String) -> Self {
pub fn new(inode: Arc<dyn INode>, 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<Arc<INode>> {
pub fn lookup_follow(&self, path: &str, max_follow: usize) -> Result<Arc<dyn INode>> {
self.inode.lookup_follow(path, max_follow)
}
@ -141,7 +141,7 @@ impl FileHandle {
self.inode.io_control(cmd, arg)
}
pub fn inode(&self) -> Arc<INode> {
pub fn inode(&self) -> Arc<dyn INode> {
self.inode.clone()
}

@ -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
}
}

@ -39,7 +39,7 @@ _user_img_end:
lazy_static! {
/// The root of file system
pub static ref ROOT_INODE: Arc<INode> = {
pub static ref ROOT_INODE: Arc<dyn INode> = {
#[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<Vec<u8>>;
}
impl INodeExt for INode {
impl INodeExt for dyn INode {
fn read_as_vec(&self) -> Result<Vec<u8>> {
let size = self.metadata()?.size;
let mut buf = Vec::with_capacity(size);

@ -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<Arc<INode>> { Err(FsError::NotDir) }
fn create(&self, _name: &str, _type_: FileType, _mode: u32) -> Result<Arc<dyn INode>> { Err(FsError::NotDir) }
fn unlink(&self, _name: &str) -> Result<()> { Err(FsError::NotDir) }
fn link(&self, _name: &str, _other: &Arc<INode>) -> Result<()> { Err(FsError::NotDir) }
fn move_(&self, _old_name: &str, _target: &Arc<INode>, _new_name: &str) -> Result<()> { Err(FsError::NotDir) }
fn find(&self, _name: &str) -> Result<Arc<INode>> { Err(FsError::NotDir) }
fn link(&self, _name: &str, _other: &Arc<dyn INode>) -> Result<()> { Err(FsError::NotDir) }
fn move_(&self, _old_name: &str, _target: &Arc<dyn INode>, _new_name: &str) -> Result<()> { Err(FsError::NotDir) }
fn find(&self, _name: &str) -> Result<Arc<dyn INode>> { Err(FsError::NotDir) }
fn get_entry(&self, _id: usize) -> Result<String> { Err(FsError::NotDir) }
fn io_control(&self, _cmd: u32, _data: usize) -> Result<()> { Err(FsError::NotSupported) }
fn fs(&self) -> Arc<FileSystem> { unimplemented!() }
fn as_any_ref(&self) -> &Any { self }
fn fs(&self) -> Arc<dyn FileSystem> { unimplemented!() }
fn as_any_ref(&self) -> &dyn Any { self }
};
}

@ -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<Arc<INode>> { Err(FsError::NotDir) }
fn create(&self, _name: &str, _type_: FileType, _mode: u32) -> Result<Arc<dyn INode>> { Err(FsError::NotDir) }
fn unlink(&self, _name: &str) -> Result<()> { Err(FsError::NotDir) }
fn link(&self, _name: &str, _other: &Arc<INode>) -> Result<()> { Err(FsError::NotDir) }
fn move_(&self, _old_name: &str, _target: &Arc<INode>, _new_name: &str) -> Result<()> { Err(FsError::NotDir) }
fn find(&self, _name: &str) -> Result<Arc<INode>> { Err(FsError::NotDir) }
fn link(&self, _name: &str, _other: &Arc<dyn INode>) -> Result<()> { Err(FsError::NotDir) }
fn move_(&self, _old_name: &str, _target: &Arc<dyn INode>, _new_name: &str) -> Result<()> { Err(FsError::NotDir) }
fn find(&self, _name: &str) -> Result<Arc<dyn INode>> { Err(FsError::NotDir) }
fn get_entry(&self, _id: usize) -> Result<String> { Err(FsError::NotDir) }
fn io_control(&self, cmd: u32, data: usize) -> Result<()> { Err(FsError::NotSupported) }
fn fs(&self) -> Arc<FileSystem> { unimplemented!() }
fn as_any_ref(&self) -> &Any { self }
fn io_control(&self, _cmd: u32, _data: usize) -> Result<()> { Err(FsError::NotSupported) }
fn fs(&self) -> Arc<dyn FileSystem> { unimplemented!() }
fn as_any_ref(&self) -> &dyn Any { self }
};
}

@ -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<Arc<INode>> { Err(FsError::NotDir) }
fn create(&self, _name: &str, _type_: FileType, _mode: u32) -> Result<Arc<dyn INode>> { Err(FsError::NotDir) }
fn unlink(&self, _name: &str) -> Result<()> { Err(FsError::NotDir) }
fn link(&self, _name: &str, _other: &Arc<INode>) -> Result<()> { Err(FsError::NotDir) }
fn move_(&self, _old_name: &str, _target: &Arc<INode>, _new_name: &str) -> Result<()> { Err(FsError::NotDir) }
fn find(&self, _name: &str) -> Result<Arc<INode>> { Err(FsError::NotDir) }
fn link(&self, _name: &str, _other: &Arc<dyn INode>) -> Result<()> { Err(FsError::NotDir) }
fn move_(&self, _old_name: &str, _target: &Arc<dyn INode>, _new_name: &str) -> Result<()> { Err(FsError::NotDir) }
fn find(&self, _name: &str) -> Result<Arc<dyn INode>> { Err(FsError::NotDir) }
fn get_entry(&self, _id: usize) -> Result<String> { 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<FileSystem> { unimplemented!() }
fn as_any_ref(&self) -> &Any { self }
fn fs(&self) -> Arc<dyn FileSystem> { unimplemented!() }
fn as_any_ref(&self) -> &dyn Any { self }
};
}
impl INode for Stdin {
fn read_at(&self, offset: usize, buf: &mut [u8]) -> Result<usize> {
fn read_at(&self, _offset: usize, buf: &mut [u8]) -> Result<usize> {
if self.can_read() {
buf[0] = self.pop() as u8;
Ok(1)

@ -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<Arc<INode>> { Err(FsError::NotDir) }
fn create(&self, _name: &str, _type_: FileType, _mode: u32) -> Result<Arc<dyn INode>> { Err(FsError::NotDir) }
fn unlink(&self, _name: &str) -> Result<()> { Err(FsError::NotDir) }
fn link(&self, _name: &str, _other: &Arc<INode>) -> Result<()> { Err(FsError::NotDir) }
fn move_(&self, _old_name: &str, _target: &Arc<INode>, _new_name: &str) -> Result<()> { Err(FsError::NotDir) }
fn find(&self, _name: &str) -> Result<Arc<INode>> { Err(FsError::NotDir) }
fn link(&self, _name: &str, _other: &Arc<dyn INode>) -> Result<()> { Err(FsError::NotDir) }
fn move_(&self, _old_name: &str, _target: &Arc<dyn INode>, _new_name: &str) -> Result<()> { Err(FsError::NotDir) }
fn find(&self, _name: &str) -> Result<Arc<dyn INode>> { Err(FsError::NotDir) }
fn get_entry(&self, _id: usize) -> Result<String> { Err(FsError::NotDir) }
fn fs(&self) -> Arc<FileSystem> { unimplemented!() }
fn as_any_ref(&self) -> &Any { self }
fn fs(&self) -> Arc<dyn FileSystem> { unimplemented!() }
fn as_any_ref(&self) -> &dyn Any { self }
};
}
impl INode for Vga {
fn read_at(&self, offset: usize, buf: &mut [u8]) -> Result<usize> {
fn read_at(&self, _offset: usize, _buf: &mut [u8]) -> Result<usize> {
Err(FsError::NotSupported)
}
fn write_at(&self, _offset: usize, _buf: &[u8]) -> Result<usize> {

@ -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]

@ -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;

@ -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 {

@ -197,7 +197,7 @@ impl Socket for TcpSocketState {
})
}
fn write(&self, data: &[u8], sendto_endpoint: Option<Endpoint>) -> SysResult {
fn write(&self, data: &[u8], _sendto_endpoint: Option<Endpoint>) -> SysResult {
let mut sockets = SOCKETS.lock();
let mut socket = sockets.get::<TcpSocket>(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!()
}

@ -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();
}
}
}

@ -126,6 +126,6 @@ pub fn processor() -> &'static Processor {
}
#[no_mangle]
pub fn new_kernel_context(entry: extern "C" fn(usize) -> !, arg: usize) -> Box<Context> {
pub fn new_kernel_context(entry: extern "C" fn(usize) -> !, arg: usize) -> Box<dyn Context> {
Thread::new_kernel(entry, arg)
}

@ -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>,
inode: &Arc<dyn INode>,
exec_path: &str,
args: Vec<String>,
envs: Vec<String>,
@ -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<INode>) -> MemorySet;
fn make_memory_set(&self, inode: &Arc<dyn INode>) -> 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<INode>) -> MemorySet {
fn make_memory_set(&self, inode: &Arc<dyn INode>) -> 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<INode>);
pub struct INodeForMap(pub Arc<dyn INode>);
impl Read for INodeForMap {
fn read_at(&self, offset: usize, buf: &mut [u8]) -> usize {

@ -7,7 +7,7 @@ use alloc::vec::Vec;
#[derive(Default)]
pub struct Condvar {
wait_queue: SpinNoIrqLock<VecDeque<Arc<thread::Thread>>>,
pub wait_queue: SpinNoIrqLock<VecDeque<Arc<thread::Thread>>>,
}
impl Condvar {
@ -34,7 +34,7 @@ impl Condvar {
}
/// Wait for condvar until condition() returns Some
pub fn wait_event<T>(condvar: &Condvar, mut condition: impl FnMut() -> Option<T>) -> T {
pub fn wait_event<T>(condvar: &Condvar, condition: impl FnMut() -> Option<T>) -> 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);

@ -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 {}

@ -21,7 +21,7 @@ impl Philosopher {
Philosopher { name, left, right }
}
fn eat(&self, table: &Arc<Table>) {
fn eat(&self, table: &Arc<dyn Table>) {
table.eat(self.name, self.left, self.right);
}
@ -79,7 +79,7 @@ impl Table for MonitorTable {
}
}
fn philosopher(table: Arc<Table>) {
fn philosopher(table: Arc<dyn Table>) {
let philosophers = vec![
Philosopher::new("1", 0, 1),
Philosopher::new("2", 1, 2),

@ -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<Arc<INode>, SysError> {
) -> Result<Arc<dyn INode>, 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<Arc<INode>, SysError> {
pub fn lookup_inode(&self, path: &str) -> Result<Arc<dyn INode>, SysError> {
self.lookup_inode_at(AT_FDCWD, path, true)
}
}

@ -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

@ -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 {

@ -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;
}
// @AZ[\]^_`az{|}~
0x40...0x7E => {
0x40..=0x7E => {
if let Some(param) = self.current_param {
self.params.push(param).unwrap();
}

Loading…
Cancel
Save