Clean all warnings

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

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

@ -6,17 +6,17 @@ pub struct ByFrame<T: FrameAllocator> {
} }
impl<T: FrameAllocator> MemoryHandler for ByFrame<T> { impl<T: FrameAllocator> MemoryHandler for ByFrame<T> {
fn box_clone(&self) -> Box<MemoryHandler> { fn box_clone(&self) -> Box<dyn MemoryHandler> {
Box::new(self.clone()) 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 target = self.allocator.alloc().expect("failed to allocate frame");
let entry = pt.map(addr, target); let entry = pt.map(addr, target);
attr.apply(entry); 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(); let target = pt.get_entry(addr).expect("fail to get entry").target();
self.allocator.dealloc(target); self.allocator.dealloc(target);
pt.unmap(addr); pt.unmap(addr);
@ -24,8 +24,8 @@ impl<T: FrameAllocator> MemoryHandler for ByFrame<T> {
fn clone_map( fn clone_map(
&self, &self,
pt: &mut PageTable, pt: &mut dyn PageTable,
src_pt: &mut PageTable, src_pt: &mut dyn PageTable,
addr: VirtAddr, addr: VirtAddr,
attr: &MemoryAttr, attr: &MemoryAttr,
) { ) {
@ -34,7 +34,7 @@ impl<T: FrameAllocator> MemoryHandler for ByFrame<T> {
pt.get_page_slice_mut(addr).copy_from_slice(data); 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 false
} }
} }

@ -6,17 +6,17 @@ pub struct Delay<T: FrameAllocator> {
} }
impl<T: FrameAllocator> MemoryHandler for Delay<T> { impl<T: FrameAllocator> MemoryHandler for Delay<T> {
fn box_clone(&self) -> Box<MemoryHandler> { fn box_clone(&self) -> Box<dyn MemoryHandler> {
Box::new(self.clone()) 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); let entry = pt.map(addr, 0);
entry.set_present(false); entry.set_present(false);
attr.apply(entry); 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"); let entry = pt.get_entry(addr).expect("failed to get entry");
if entry.present() { if entry.present() {
self.allocator.dealloc(entry.target()); self.allocator.dealloc(entry.target());
@ -29,8 +29,8 @@ impl<T: FrameAllocator> MemoryHandler for Delay<T> {
fn clone_map( fn clone_map(
&self, &self,
pt: &mut PageTable, pt: &mut dyn PageTable,
src_pt: &mut PageTable, src_pt: &mut dyn PageTable,
addr: VirtAddr, addr: VirtAddr,
attr: &MemoryAttr, 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"); let entry = pt.get_entry(addr).expect("failed to get entry");
if entry.present() { if entry.present() {
// not a delay case // 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> { 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()) 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); let entry = pt.map(addr, 0);
entry.set_present(false); entry.set_present(false);
attr.apply(entry); 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"); let entry = pt.get_entry(addr).expect("failed to get entry");
if entry.present() { if entry.present() {
self.allocator.dealloc(entry.target()); self.allocator.dealloc(entry.target());
@ -38,8 +38,8 @@ impl<F: Read, T: FrameAllocator> MemoryHandler for File<F, T> {
fn clone_map( fn clone_map(
&self, &self,
pt: &mut PageTable, pt: &mut dyn PageTable,
src_pt: &mut PageTable, src_pt: &mut dyn PageTable,
addr: usize, addr: usize,
attr: &MemoryAttr, 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 addr = addr & !(PAGE_SIZE - 1);
let entry = pt.get_entry(addr).expect("failed to get entry"); let entry = pt.get_entry(addr).expect("failed to get entry");
if entry.present() { 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> { 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 data = pt.get_page_slice_mut(addr);
let file_offset = addr + self.file_start - self.mem_start; let file_offset = addr + self.file_start - self.mem_start;
let read_size = (self.file_end as isize - file_offset as isize) let read_size = (self.file_end as isize - file_offset as isize)

@ -6,31 +6,31 @@ pub struct Linear {
} }
impl MemoryHandler for Linear { impl MemoryHandler for Linear {
fn box_clone(&self) -> Box<MemoryHandler> { fn box_clone(&self) -> Box<dyn MemoryHandler> {
Box::new(self.clone()) 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 target = (addr as isize + self.offset) as PhysAddr;
let entry = pt.map(addr, target); let entry = pt.map(addr, target);
attr.apply(entry); attr.apply(entry);
} }
fn unmap(&self, pt: &mut PageTable, addr: VirtAddr) { fn unmap(&self, pt: &mut dyn PageTable, addr: VirtAddr) {
pt.unmap(addr); pt.unmap(addr);
} }
fn clone_map( fn clone_map(
&self, &self,
pt: &mut PageTable, pt: &mut dyn PageTable,
_src_pt: &mut PageTable, _src_pt: &mut dyn PageTable,
addr: VirtAddr, addr: VirtAddr,
attr: &MemoryAttr, attr: &MemoryAttr,
) { ) {
self.map(pt, addr, attr); 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 false
} }
} }

@ -2,31 +2,31 @@ use super::*;
// here may be a interesting part for lab // here may be a interesting part for lab
pub trait MemoryHandler: Debug + Send + Sync + 'static { 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 /// Map `addr` in the page table
/// Should set page flags here instead of in `page_fault_handler` /// 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 /// 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`. /// Clone map `addr` from page table `src_pt` to `pt`.
fn clone_map( fn clone_map(
&self, &self,
pt: &mut PageTable, pt: &mut dyn PageTable,
src_pt: &mut PageTable, src_pt: &mut dyn PageTable,
addr: VirtAddr, addr: VirtAddr,
attr: &MemoryAttr, attr: &MemoryAttr,
); );
/// Handle page fault on `addr` /// Handle page fault on `addr`
/// Return true if success, false if error /// 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> { impl Clone for Box<dyn MemoryHandler> {
fn clone(&self) -> Box<MemoryHandler> { fn clone(&self) -> Box<dyn MemoryHandler> {
self.box_clone() self.box_clone()
} }
} }

@ -1,6 +1,6 @@
//! Memory management structures //! 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::fmt::{Debug, Error, Formatter};
use core::mem::size_of; use core::mem::size_of;
@ -18,7 +18,7 @@ pub struct MemoryArea {
start_addr: VirtAddr, start_addr: VirtAddr,
end_addr: VirtAddr, end_addr: VirtAddr,
attr: MemoryAttr, attr: MemoryAttr,
handler: Box<MemoryHandler>, handler: Box<dyn MemoryHandler>,
name: &'static str, name: &'static str,
} }
@ -58,13 +58,13 @@ impl MemoryArea {
!(p1 <= p2 || p0 >= p3) !(p1 <= p2 || p0 >= p3)
} }
/// Map all pages in the area to page table `pt` /// 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) { for page in Page::range_of(self.start_addr, self.end_addr) {
self.handler.map(pt, page.start_address(), &self.attr); self.handler.map(pt, page.start_address(), &self.attr);
} }
} }
/// Unmap all pages in the area from page table `pt` /// 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) { for page in Page::range_of(self.start_addr, self.end_addr) {
self.handler.unmap(pt, page.start_address()); self.handler.unmap(pt, page.start_address());
} }
@ -103,7 +103,7 @@ impl MemoryAttr {
} }
/// Apply the attributes to page table entry, then update it. /// Apply the attributes to page table entry, then update it.
/// NOTE: You may need to set present manually. /// 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_user(self.user);
entry.set_writable(!self.readonly); entry.set_writable(!self.readonly);
entry.set_execute(self.execute); 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 { impl PageTable for MockPageTable {
// type Entry = MockEntry; // 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]; let entry = &mut self.entries[addr / PAGE_SIZE];
assert!(!entry.present); assert!(!entry.present);
entry.present = true; entry.present = true;
@ -119,7 +119,7 @@ impl PageTable for MockPageTable {
assert!(entry.present); assert!(entry.present);
entry.present = false; 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]) Some(&mut self.entries[addr / PAGE_SIZE])
} }
fn get_page_slice_mut<'a, 'b>(&'a mut self, addr: VirtAddr) -> &'b mut [u8] { 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` /// Map a page of virual address `addr` to the frame of physics address `target`
/// Return the page table entry of the mapped virual address /// 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` /// Unmap a page of virual address `addr`
fn unmap(&mut self, addr: VirtAddr); fn unmap(&mut self, addr: VirtAddr);
/// Get the page table entry of a page of virual address `addr` /// Get the page table entry of a page of virual address `addr`
/// If its page do not exist, return `None` /// 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` /// 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]; 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); pub struct PageEntry(&'static mut PageTableEntry, Page);
impl PageTable for PageTableImpl { 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 flags = EF::default();
let attr = MairNormal::attr_value(); let attr = MairNormal::attr_value();
unsafe { unsafe {
@ -50,12 +50,12 @@ impl PageTable for PageTableImpl {
.flush(); .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); let page = Page::of_addr(vaddr as u64);
if let Ok(e) = self.page_table.get_entry_mut(page) { if let Ok(e) = self.page_table.get_entry_mut(page) {
let e = unsafe { &mut *(e as *mut PageTableEntry) }; let e = unsafe { &mut *(e as *mut PageTableEntry) };
self.entry = PageEntry(e, page); self.entry = PageEntry(e, page);
Some(&mut self.entry as &mut Entry) Some(&mut self.entry as &mut dyn Entry)
} else { } else {
None None
} }

@ -1,10 +1,10 @@
#[path = "../../../drivers/gpu/fb.rs"] #[path = "../../../drivers/gpu/fb.rs"]
pub mod fb; pub mod fb;
use crate::consts::KERNEL_OFFSET;
use crate::memory::phys_to_virt; use crate::memory::phys_to_virt;
use bootloader::bootinfo::{BootInfo, VbeModeInfo}; use bootloader::bootinfo::{BootInfo, VbeModeInfo};
use core::mem::zeroed;
use fb::{ColorConfig, FramebufferInfo, FramebufferResult, FRAME_BUFFER}; use fb::{ColorConfig, FramebufferInfo, FramebufferResult, FRAME_BUFFER};
static mut VBE_MODE: VbeModeInfo = VbeModeInfo { static mut VBE_MODE: VbeModeInfo = VbeModeInfo {

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

@ -6,10 +6,10 @@ use alloc::sync::Arc;
use apic::{LocalApic, XApic, LAPIC_ADDR}; use apic::{LocalApic, XApic, LAPIC_ADDR};
use core::sync::atomic::{spin_loop_hint, AtomicU8, Ordering}; 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 { 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 lapic
} }

@ -1,7 +1,7 @@
use super::{BootInfo, MemoryRegionType}; use super::{BootInfo, MemoryRegionType};
use crate::memory::{init_heap, FRAME_ALLOCATOR}; use crate::memory::{init_heap, FRAME_ALLOCATOR};
use bitmap_allocator::BitAlloc; use bitmap_allocator::BitAlloc;
use rcore_memory::paging::*;
pub fn init(boot_info: &BootInfo) { pub fn init(boot_info: &BootInfo) {
init_frame_allocator(boot_info); init_frame_allocator(boot_info);

@ -1,5 +1,5 @@
use crate::memory::{alloc_frame, dealloc_frame, phys_to_virt}; use crate::memory::{alloc_frame, dealloc_frame, phys_to_virt};
use core::sync::atomic::Ordering;
use log::*; use log::*;
use rcore_memory::paging::*; use rcore_memory::paging::*;
use x86_64::instructions::tlb; use x86_64::instructions::tlb;
@ -20,7 +20,7 @@ pub trait PageExt {
impl PageExt for Page { impl PageExt for Page {
fn of_addr(address: usize) -> Self { fn of_addr(address: usize) -> Self {
use x86_64;
Page::containing_address(VirtAddr::new(address as u64)) Page::containing_address(VirtAddr::new(address as u64))
} }
fn range_of(begin: usize, end: usize) -> PageRange { fn range_of(begin: usize, end: usize) -> PageRange {
@ -47,7 +47,7 @@ pub struct PageTableImpl(
pub struct PageEntry(&'static mut PageTableEntry, Page, Frame); pub struct PageEntry(&'static mut PageTableEntry, Page, Frame);
impl PageTable for PageTableImpl { 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; let flags = EF::PRESENT | EF::WRITABLE | EF::NO_EXECUTE;
unsafe { unsafe {
self.0 self.0
@ -69,7 +69,7 @@ impl PageTable for PageTableImpl {
flush_tlb_all(addr); 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); let mut page_table = frame_to_page_table(self.2);
for level in 0..4 { for level in 0..4 {
let index = (addr >> (12 + (3 - level) * 9)) & 0o777; let index = (addr >> (12 + (3 - level) * 9)) & 0o777;
@ -77,7 +77,7 @@ impl PageTable for PageTableImpl {
if level == 3 { if level == 3 {
let page = Page::of_addr(addr); let page = Page::of_addr(addr);
self.1 = PageEntry(entry, page, self.2); 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) { if !entry.flags().contains(EF::PRESENT) {
return None; return None;

@ -237,6 +237,6 @@ pub fn get_bar0_mem(loc: Location) -> Option<(usize, usize)> {
} }
lazy_static! { 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()); Mutex::new(BTreeMap::new());
} }

@ -10,7 +10,7 @@ use spin::Mutex;
use crate::util::escape_parser::{CharacterAttribute, EscapeParser}; 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::color::FramebufferColor;
use self::fonts::{Font, Font8x16}; use self::fonts::{Font, Font8x16};

@ -1,6 +1,6 @@
//! Framebuffer //! Framebuffer
use crate::fs::vga::{fb_bitfield, fb_var_screeninfo}; use crate::fs::vga::{fb_var_screeninfo};
use alloc::string::String; use alloc::string::String;
use core::fmt; use core::fmt;
use lazy_static::lazy_static; use lazy_static::lazy_static;
@ -54,7 +54,7 @@ pub enum ColorConfig {
BGRA8888, BGRA8888,
VgaPalette, VgaPalette,
} }
use self::ColorConfig::*;
pub type FramebufferResult = Result<(FramebufferInfo, ColorConfig, usize), String>; pub type FramebufferResult = Result<(FramebufferInfo, ColorConfig, usize), String>;

@ -93,12 +93,12 @@ pub trait Driver: Send + Sync {
lazy_static! { lazy_static! {
// NOTE: RwLock only write when initializing drivers // NOTE: RwLock only write when initializing drivers
pub static ref 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<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<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 { impl BlockDevice for BlockDriver {
const BLOCK_SIZE_LOG2: u8 = 9; // 512 const BLOCK_SIZE_LOG2: u8 = 9; // 512

@ -159,10 +159,10 @@ impl Driver for RouterInterface {
let rdfo = AXI_STREAM_FIFO_RDFO.read_volatile(); let rdfo = AXI_STREAM_FIFO_RDFO.read_volatile();
if rdfo > 0 { if rdfo > 0 {
let mut buffer = Vec::new(); let mut buffer = Vec::new();
let rlr = AXI_STREAM_FIFO_RLR.read_volatile(); let _rlr = AXI_STREAM_FIFO_RLR.read_volatile();
let rdr = AXI_STREAM_FIFO_RDR.read_volatile(); let _rdr = AXI_STREAM_FIFO_RDR.read_volatile();
let port = AXI_STREAM_FIFO_RDFD.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); buffer.push(AXI_STREAM_FIFO_RDFD.read_volatile() as u8);
} }
debug!( debug!(

@ -11,7 +11,7 @@ impl provider::Provider for Provider {
fn alloc_dma(size: usize) -> (usize, usize) { fn alloc_dma(size: usize) -> (usize, usize) {
// TODO: allocate continuous pages // TODO: allocate continuous pages
let mut paddr = alloc_frame().unwrap(); 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(); let paddr_new = alloc_frame().unwrap();
assert_eq!(paddr - PAGE_SIZE, paddr_new); assert_eq!(paddr - PAGE_SIZE, paddr_new);
paddr = paddr_new; paddr = paddr_new;
@ -20,7 +20,7 @@ impl provider::Provider for Provider {
(vaddr, paddr) (vaddr, paddr)
} }
fn dealloc_dma(vaddr: usize, size: usize) { fn dealloc_dma(vaddr: usize, _size: usize) {
let paddr = virt_to_phys(vaddr); let paddr = virt_to_phys(vaddr);
dealloc_frame(paddr); dealloc_frame(paddr);
} }

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

@ -60,7 +60,7 @@ impl FileLike {
pub fn fcntl(&mut self, cmd: usize, arg: usize) -> SysResult { pub fn fcntl(&mut self, cmd: usize, arg: usize) -> SysResult {
match self { match self {
FileLike::File(file) => file.fcntl(cmd, arg)?, FileLike::File(file) => file.fcntl(cmd, arg)?,
FileLike::Socket(socket) => { FileLike::Socket(_socket) => {
//TODO //TODO
} }
} }

@ -39,7 +39,7 @@ _user_img_end:
lazy_static! { lazy_static! {
/// The root of file system /// 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"))] #[cfg(not(feature = "link_user"))]
let device = { let device = {
#[cfg(any(target_arch = "riscv32", target_arch = "riscv64", target_arch = "x86_64"))] #[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>>; 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>> { fn read_as_vec(&self) -> Result<Vec<u8>> {
let size = self.metadata()?.size; let size = self.metadata()?.size;
let mut buf = Vec::with_capacity(size); let mut buf = Vec::with_capacity(size);

@ -74,15 +74,15 @@ macro_rules! impl_inode {
fn sync_all(&self) -> Result<()> { Ok(()) } fn sync_all(&self) -> Result<()> { Ok(()) }
fn sync_data(&self) -> Result<()> { Ok(()) } fn sync_data(&self) -> Result<()> { Ok(()) }
fn resize(&self, _len: usize) -> Result<()> { Err(FsError::NotSupported) } 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 unlink(&self, _name: &str) -> Result<()> { Err(FsError::NotDir) }
fn link(&self, _name: &str, _other: &Arc<INode>) -> Result<()> { Err(FsError::NotDir) } fn link(&self, _name: &str, _other: &Arc<dyn INode>) -> Result<()> { Err(FsError::NotDir) }
fn move_(&self, _old_name: &str, _target: &Arc<INode>, _new_name: &str) -> 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<INode>> { 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 get_entry(&self, _id: usize) -> Result<String> { Err(FsError::NotDir) }
fn io_control(&self, _cmd: u32, _data: usize) -> Result<()> { Err(FsError::NotSupported) } fn io_control(&self, _cmd: u32, _data: usize) -> Result<()> { Err(FsError::NotSupported) }
fn fs(&self) -> Arc<FileSystem> { unimplemented!() } fn fs(&self) -> Arc<dyn FileSystem> { unimplemented!() }
fn as_any_ref(&self) -> &Any { self } fn as_any_ref(&self) -> &dyn Any { self }
}; };
} }

@ -26,15 +26,15 @@ macro_rules! impl_inode {
fn sync_all(&self) -> Result<()> { Ok(()) } fn sync_all(&self) -> Result<()> { Ok(()) }
fn sync_data(&self) -> Result<()> { Ok(()) } fn sync_data(&self) -> Result<()> { Ok(()) }
fn resize(&self, _len: usize) -> Result<()> { Err(FsError::NotSupported) } 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 unlink(&self, _name: &str) -> Result<()> { Err(FsError::NotDir) }
fn link(&self, _name: &str, _other: &Arc<INode>) -> Result<()> { Err(FsError::NotDir) } fn link(&self, _name: &str, _other: &Arc<dyn INode>) -> Result<()> { Err(FsError::NotDir) }
fn move_(&self, _old_name: &str, _target: &Arc<INode>, _new_name: &str) -> 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<INode>> { 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 get_entry(&self, _id: usize) -> Result<String> { Err(FsError::NotDir) }
fn io_control(&self, cmd: u32, data: usize) -> Result<()> { Err(FsError::NotSupported) } fn io_control(&self, _cmd: u32, _data: usize) -> Result<()> { Err(FsError::NotSupported) }
fn fs(&self) -> Arc<FileSystem> { unimplemented!() } fn fs(&self) -> Arc<dyn FileSystem> { unimplemented!() }
fn as_any_ref(&self) -> &Any { self } fn as_any_ref(&self) -> &dyn Any { self }
}; };
} }

@ -61,11 +61,11 @@ macro_rules! impl_inode {
fn sync_all(&self) -> Result<()> { Ok(()) } fn sync_all(&self) -> Result<()> { Ok(()) }
fn sync_data(&self) -> Result<()> { Ok(()) } fn sync_data(&self) -> Result<()> { Ok(()) }
fn resize(&self, _len: usize) -> Result<()> { Err(FsError::NotSupported) } 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 unlink(&self, _name: &str) -> Result<()> { Err(FsError::NotDir) }
fn link(&self, _name: &str, _other: &Arc<INode>) -> Result<()> { Err(FsError::NotDir) } fn link(&self, _name: &str, _other: &Arc<dyn INode>) -> Result<()> { Err(FsError::NotDir) }
fn move_(&self, _old_name: &str, _target: &Arc<INode>, _new_name: &str) -> 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<INode>> { 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 get_entry(&self, _id: usize) -> Result<String> { Err(FsError::NotDir) }
fn io_control(&self, cmd: u32, data: usize) -> Result<()> { fn io_control(&self, cmd: u32, data: usize) -> Result<()> {
match cmd as usize { match cmd as usize {
@ -84,13 +84,13 @@ macro_rules! impl_inode {
_ => Err(FsError::NotSupported) _ => Err(FsError::NotSupported)
} }
} }
fn fs(&self) -> Arc<FileSystem> { unimplemented!() } fn fs(&self) -> Arc<dyn FileSystem> { unimplemented!() }
fn as_any_ref(&self) -> &Any { self } fn as_any_ref(&self) -> &dyn Any { self }
}; };
} }
impl INode for Stdin { 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() { if self.can_read() {
buf[0] = self.pop() as u8; buf[0] = self.pop() as u8;
Ok(1) Ok(1)

@ -1,8 +1,8 @@
use rcore_fs::vfs::*; use rcore_fs::vfs::*;
use crate::arch::board::fb::FRAME_BUFFER; 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; use core::any::Any;
#[derive(Default)] #[derive(Default)]
@ -14,19 +14,19 @@ macro_rules! impl_inode {
fn sync_all(&self) -> Result<()> { Ok(()) } fn sync_all(&self) -> Result<()> { Ok(()) }
fn sync_data(&self) -> Result<()> { Ok(()) } fn sync_data(&self) -> Result<()> { Ok(()) }
fn resize(&self, _len: usize) -> Result<()> { Err(FsError::NotSupported) } 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 unlink(&self, _name: &str) -> Result<()> { Err(FsError::NotDir) }
fn link(&self, _name: &str, _other: &Arc<INode>) -> Result<()> { Err(FsError::NotDir) } fn link(&self, _name: &str, _other: &Arc<dyn INode>) -> Result<()> { Err(FsError::NotDir) }
fn move_(&self, _old_name: &str, _target: &Arc<INode>, _new_name: &str) -> 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<INode>> { 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 get_entry(&self, _id: usize) -> Result<String> { Err(FsError::NotDir) }
fn fs(&self) -> Arc<FileSystem> { unimplemented!() } fn fs(&self) -> Arc<dyn FileSystem> { unimplemented!() }
fn as_any_ref(&self) -> &Any { self } fn as_any_ref(&self) -> &dyn Any { self }
}; };
} }
impl INode for Vga { 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) Err(FsError::NotSupported)
} }
fn write_at(&self, _offset: usize, _buf: &[u8]) -> Result<usize> { fn write_at(&self, _offset: usize, _buf: &[u8]) -> Result<usize> {

@ -1,14 +1,13 @@
#![feature(lang_items)] #![feature(lang_items)]
#![feature(alloc)]
#![feature(naked_functions)] #![feature(naked_functions)]
#![feature(untagged_unions)] #![feature(untagged_unions)]
#![feature(asm)] #![feature(asm)]
#![feature(optin_builtin_traits)] #![feature(optin_builtin_traits)]
#![feature(panic_info_message)] #![feature(panic_info_message)]
#![feature(global_asm)] #![feature(global_asm)]
#![feature(maybe_uninit)]
#![deny(unused_must_use)] #![deny(unused_must_use)]
#![no_std] #![no_std]
#![allow(non_snake_case, unused_imports, unused_variables, unused_assignments, dead_code)]
// just keep it ... // just keep it ...
#[macro_use] #[macro_use]

@ -1,7 +1,6 @@
#![no_std] // don't link the Rust standard library #![no_std] // don't link the Rust standard library
#![cfg_attr(not(test), no_main)] // disable all Rust-level entry points #![cfg_attr(not(test), no_main)] // disable all Rust-level entry points
#![cfg_attr(test, allow(dead_code, unused_macros, unused_imports))] #![cfg_attr(test, allow(dead_code, unused_macros, unused_imports))]
#![allow(non_snake_case, unused_imports, unused_variables, unused_assignments)]
#[allow(unused_imports)] #[allow(unused_imports)]
use rcore; use rcore;

@ -148,7 +148,7 @@ pub fn enlarge_heap(heap: &mut Heap) {
let mut addrs = [(0, 0); 32]; let mut addrs = [(0, 0); 32];
let mut addr_len = 0; let mut addr_len = 0;
let va_offset = PHYSICAL_MEMORY_OFFSET; let va_offset = PHYSICAL_MEMORY_OFFSET;
for i in 0..16384 { for _i in 0..16384 {
let page = alloc_frame().unwrap(); let page = alloc_frame().unwrap();
let va = va_offset + page; let va = va_offset + page;
if addr_len > 0 { 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 sockets = SOCKETS.lock();
let mut socket = sockets.get::<TcpSocket>(self.handle.0); let mut socket = sockets.get::<TcpSocket>(self.handle.0);
@ -212,7 +212,7 @@ impl Socket for TcpSocketState {
poll_ifaces(); poll_ifaces();
Ok(size) Ok(size)
} }
Err(err) => Err(SysError::ENOBUFS), Err(_err) => Err(SysError::ENOBUFS),
} }
} else { } else {
Err(SysError::ENOBUFS) Err(SysError::ENOBUFS)
@ -480,7 +480,7 @@ impl Socket for UdpSocketState {
poll_ifaces(); poll_ifaces();
Ok(data.len()) Ok(data.len())
} }
Err(err) => Err(SysError::ENOBUFS), Err(_err) => Err(SysError::ENOBUFS),
} }
} else { } else {
Err(SysError::ENOBUFS) 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 { match request {
// SIOCGARP // SIOCGARP
0x8954 => { 0x8954 => {
@ -691,13 +691,12 @@ impl Socket for RawSocketState {
fn setsockopt(&mut self, level: usize, opt: usize, data: &[u8]) -> SysResult { fn setsockopt(&mut self, level: usize, opt: usize, data: &[u8]) -> SysResult {
match (level, opt) { match (level, opt) {
(IPPROTO_IP, IP_HDRINCL) => { (_IPPROTO_IP, _IP_HDRINCL) => {
if let Some(arg) = data.first() { if let Some(arg) = data.first() {
self.header_included = *arg > 0; self.header_included = *arg > 0;
debug!("hdrincl set to {}", self.header_included); debug!("hdrincl set to {}", self.header_included);
} }
} }
_ => {}
} }
Ok(0) Ok(0)
} }
@ -710,7 +709,7 @@ impl PacketSocketState {
} }
impl Socket for PacketSocketState { impl Socket for PacketSocketState {
fn read(&self, data: &mut [u8]) -> (SysResult, Endpoint) { fn read(&self, _data: &mut [u8]) -> (SysResult, Endpoint) {
unimplemented!() unimplemented!()
} }

@ -73,7 +73,7 @@ pub extern "C" fn server(_arg: usize) -> ! {
if socket.can_recv() { if socket.can_recv() {
let mut data = [0u8; 2048]; 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] #[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) Thread::new_kernel(entry, arg)
} }

@ -84,7 +84,7 @@ lazy_static! {
/// Let `rcore_thread` can switch between our `Thread` /// Let `rcore_thread` can switch between our `Thread`
impl rcore_thread::Context for 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; use core::mem::transmute;
let (target, _): (&mut Thread, *const ()) = transmute(target); let (target, _): (&mut Thread, *const ()) = transmute(target);
self.context.switch(&mut target.context); self.context.switch(&mut target.context);
@ -241,7 +241,7 @@ impl Thread {
/// Make a new user process from ELF `data` /// Make a new user process from ELF `data`
pub fn new_user( pub fn new_user(
inode: &Arc<INode>, inode: &Arc<dyn INode>,
exec_path: &str, exec_path: &str,
args: Vec<String>, args: Vec<String>,
envs: Vec<String>, envs: Vec<String>,
@ -443,7 +443,7 @@ impl ToMemoryAttr for Flags {
/// Helper functions to process ELF file /// Helper functions to process ELF file
trait ElfExt { trait ElfExt {
/// Generate a MemorySet according to the ELF file. /// 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. /// Get interpreter string if it has.
fn get_interpreter(&self) -> Result<&str, &str>; fn get_interpreter(&self) -> Result<&str, &str>;
@ -453,7 +453,7 @@ trait ElfExt {
} }
impl ElfExt for ElfFile<'_> { 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"); debug!("creating MemorySet from ELF");
let mut ms = MemorySet::new(); let mut ms = MemorySet::new();
@ -517,7 +517,7 @@ impl ElfExt for ElfFile<'_> {
} }
#[derive(Clone)] #[derive(Clone)]
pub struct INodeForMap(pub Arc<INode>); pub struct INodeForMap(pub Arc<dyn INode>);
impl Read for INodeForMap { impl Read for INodeForMap {
fn read_at(&self, offset: usize, buf: &mut [u8]) -> usize { fn read_at(&self, offset: usize, buf: &mut [u8]) -> usize {

@ -7,7 +7,7 @@ use alloc::vec::Vec;
#[derive(Default)] #[derive(Default)]
pub struct Condvar { pub struct Condvar {
wait_queue: SpinNoIrqLock<VecDeque<Arc<thread::Thread>>>, pub wait_queue: SpinNoIrqLock<VecDeque<Arc<thread::Thread>>>,
} }
impl Condvar { impl Condvar {
@ -34,7 +34,7 @@ impl Condvar {
} }
/// Wait for condvar until condition() returns Some /// 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) Self::wait_events(&[condvar], condition)
} }
@ -50,7 +50,7 @@ impl Condvar {
let mut locks = Vec::with_capacity(condvars.len()); let mut locks = Vec::with_capacity(condvars.len());
loop { loop {
for condvar in condvars { for condvar in condvars {
let mut lock = condvar.wait_queue.lock(); let lock = condvar.wait_queue.lock();
locks.push(lock); locks.push(lock);
} }
processor().manager().sleep(tid, 0); processor().manager().sleep(tid, 0);

@ -287,6 +287,7 @@ impl MutexSupport for Condvar {
Condvar::new() Condvar::new()
} }
fn cpu_relax(&self) { fn cpu_relax(&self) {
#[allow(deprecated)] //Not really possible to work around.
self._wait(); self._wait();
} }
fn before_lock() -> Self::GuardData {} fn before_lock() -> Self::GuardData {}

@ -21,7 +21,7 @@ impl Philosopher {
Philosopher { name, left, right } 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); 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![ let philosophers = vec![
Philosopher::new("1", 0, 1), Philosopher::new("1", 0, 1),
Philosopher::new("2", 1, 2), Philosopher::new("2", 1, 2),

@ -274,7 +274,7 @@ impl Syscall<'_> {
mode: usize, mode: usize,
) -> SysResult { ) -> SysResult {
let mut proc = self.process(); 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); let flags = OpenFlags::from_bits_truncate(flags);
info!( info!(
"openat: dir_fd: {}, path: {:?}, flags: {:?}, mode: {:#o}", "openat: dir_fd: {}, path: {:?}, flags: {:?}, mode: {:#o}",
@ -338,7 +338,7 @@ impl Syscall<'_> {
) -> SysResult { ) -> SysResult {
// TODO: check permissions based on uid/gid // TODO: check permissions based on uid/gid
let proc = self.process(); 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); let flags = AtFlags::from_bits_truncate(flags);
if !proc.pid.is_init() { if !proc.pid.is_init() {
// we trust pid 0 process // we trust pid 0 process
@ -347,7 +347,7 @@ impl Syscall<'_> {
dirfd as isize, path, mode, flags dirfd as isize, path, mode, flags
); );
} }
let inode = let _inode =
proc.lookup_inode_at(dirfd, &path, !flags.contains(AtFlags::SYMLINK_NOFOLLOW))?; proc.lookup_inode_at(dirfd, &path, !flags.contains(AtFlags::SYMLINK_NOFOLLOW))?;
Ok(0) Ok(0)
} }
@ -419,7 +419,7 @@ impl Syscall<'_> {
len: usize, len: usize,
) -> SysResult { ) -> SysResult {
let proc = self.process(); 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)? }; let slice = unsafe { self.vm().check_write_array(base, len)? };
info!( info!(
"readlinkat: dirfd: {}, path: {:?}, base: {:?}, len: {}", "readlinkat: dirfd: {}, path: {:?}, base: {:?}, len: {}",
@ -465,7 +465,7 @@ impl Syscall<'_> {
pub fn sys_truncate(&mut self, path: *const u8, len: usize) -> SysResult { pub fn sys_truncate(&mut self, path: *const u8, len: usize) -> SysResult {
let proc = self.process(); 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); info!("truncate: path: {:?}, len: {}", path, len);
proc.lookup_inode(&path)?.resize(len)?; proc.lookup_inode(&path)?.resize(len)?;
Ok(0) Ok(0)
@ -678,7 +678,7 @@ impl Syscall<'_> {
pub fn sys_unlinkat(&mut self, dirfd: usize, path: *const u8, flags: usize) -> SysResult { pub fn sys_unlinkat(&mut self, dirfd: usize, path: *const u8, flags: usize) -> SysResult {
let proc = self.process(); 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); let flags = AtFlags::from_bits_truncate(flags);
info!( info!(
"unlinkat: dirfd: {}, path: {:?}, flags: {:?}", "unlinkat: dirfd: {}, path: {:?}, flags: {:?}",
@ -876,7 +876,7 @@ impl Process {
dirfd: usize, dirfd: usize,
path: &str, path: &str,
follow: bool, follow: bool,
) -> Result<Arc<INode>, SysError> { ) -> Result<Arc<dyn INode>, SysError> {
debug!( debug!(
"lookup_inode_at: dirfd: {:?}, cwd: {:?}, path: {:?}, follow: {:?}", "lookup_inode_at: dirfd: {:?}, cwd: {:?}, path: {:?}, follow: {:?}",
dirfd as isize, self.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) self.lookup_inode_at(AT_FDCWD, path, true)
} }
} }

@ -97,7 +97,7 @@ impl Syscall<'_> {
"mprotect: addr={:#x}, size={:#x}, prot={:?}", "mprotect: addr={:#x}, size={:#x}, prot={:?}",
addr, len, prot addr, len, prot
); );
let attr = prot.to_attr(); let _attr = prot.to_attr();
// FIXME: properly set the attribute of the area // FIXME: properly set the attribute of the area
// now some mut ptr check is fault // now some mut ptr check is fault

@ -64,7 +64,7 @@ impl Syscall<'_> {
info!("times: buf: {:?}", buf); info!("times: buf: {:?}", buf);
let buf = unsafe { self.vm().check_write_ptr(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 tick = unsafe { crate::trap::TICK as u64 };
let new_buf = Tms { let new_buf = Tms {

@ -45,8 +45,8 @@ impl CharacterAttribute {
24 => self.underline = false, 24 => self.underline = false,
27 => self.reverse = false, 27 => self.reverse = false,
29 => self.strikethrough = false, 29 => self.strikethrough = false,
30...37 | 90...97 => self.foreground = ConsoleColor::from_console_code(code).unwrap(), 30..=37 | 90..=97 => self.foreground = ConsoleColor::from_console_code(code).unwrap(),
40...47 | 100...107 => { 40..=47 | 100..=107 => {
self.background = ConsoleColor::from_console_code(code - 10).unwrap() self.background = ConsoleColor::from_console_code(code - 10).unwrap()
} }
_ => { /* unimplemented!() */ } _ => { /* unimplemented!() */ }
@ -136,7 +136,7 @@ impl EscapeParser {
_ => { /* unimplemented!() */ } _ => { /* unimplemented!() */ }
}, },
ParseStatus::ParsingCSI => match byte { ParseStatus::ParsingCSI => match byte {
b'0'...b'9' => { b'0'..=b'9' => {
let digit = (byte - b'0') as u32; let digit = (byte - b'0') as u32;
let param = self.current_param.unwrap_or(0) as u32; let param = self.current_param.unwrap_or(0) as u32;
let res = param * 10 + digit; let res = param * 10 + digit;
@ -150,7 +150,7 @@ impl EscapeParser {
return None; return None;
} }
// @AZ[\]^_`az{|}~ // @AZ[\]^_`az{|}~
0x40...0x7E => { 0x40..=0x7E => {
if let Some(param) = self.current_param { if let Some(param) = self.current_param {
self.params.push(param).unwrap(); self.params.push(param).unwrap();
} }

Loading…
Cancel
Save