Eliminate some warnings

master
Jiajie Chen 6 years ago
parent d1d7fe44a7
commit 51868e1616

@ -1,5 +1,4 @@
use super::ipi::IPIEventItem; use super::ipi::IPIEventItem;
use alloc::boxed::Box;
use alloc::vec::*; use alloc::vec::*;
use core::sync::atomic::{AtomicBool, Ordering}; use core::sync::atomic::{AtomicBool, Ordering};
use x86_64::registers::model_specific::Msr; use x86_64::registers::model_specific::Msr;
@ -8,7 +7,7 @@ use x86_64::structures::tss::TaskStateSegment;
use x86_64::{PrivilegeLevel, VirtAddr}; use x86_64::{PrivilegeLevel, VirtAddr};
use crate::consts::MAX_CPU_NUM; use crate::consts::MAX_CPU_NUM;
use crate::sync::{Semaphore, SpinLock as Mutex}; use crate::sync::SpinLock as Mutex;
/// Init TSS & GDT. /// Init TSS & GDT.
pub fn init() { pub fn init() {
@ -79,7 +78,7 @@ impl Cpu {
self.preemption_disabled.load(Ordering::Relaxed) self.preemption_disabled.load(Ordering::Relaxed)
} }
unsafe fn init(&'static mut self) { unsafe fn init(&'static mut self) {
use x86_64::instructions::segmentation::{load_fs, set_cs}; use x86_64::instructions::segmentation::set_cs;
use x86_64::instructions::tables::load_tss; use x86_64::instructions::tables::load_tss;
// Set the stack when DoubleFault occurs // Set the stack when DoubleFault occurs

@ -1,5 +1,4 @@
use super::super::gdt; use super::super::gdt;
use super::TrapFrame;
use core::mem::transmute; use core::mem::transmute;
/// `syscall` instruction /// `syscall` instruction
use x86_64::registers::model_specific::*; use x86_64::registers::model_specific::*;

@ -1,5 +1,4 @@
use super::driver::serial::*; use super::driver::serial::*;
use super::driver::vga::VGA_WRITER;
use core::fmt::{Arguments, Write}; use core::fmt::{Arguments, Write};
pub fn getchar() -> char { pub fn getchar() -> char {
@ -19,6 +18,7 @@ pub fn putfmt(fmt: Arguments) {
} }
#[cfg(not(feature = "nographic"))] #[cfg(not(feature = "nographic"))]
{ {
use super::driver::vga::VGA_WRITER;
unsafe { unsafe {
VGA_WRITER.force_unlock(); VGA_WRITER.force_unlock();
} }

@ -9,7 +9,7 @@ use core::sync::atomic::{spin_loop_hint, AtomicU8, Ordering};
pub type IPIEventItem = Box<FnBox()>; pub type IPIEventItem = Box<FnBox()>;
unsafe fn get_apic() -> XApic { unsafe fn get_apic() -> XApic {
let mut lapic = unsafe { XApic::new(phys_to_virt(LAPIC_ADDR)) }; let mut lapic = XApic::new(phys_to_virt(LAPIC_ADDR));
lapic lapic
} }

@ -16,7 +16,7 @@ pub mod rand;
pub mod syscall; pub mod syscall;
pub mod timer; pub mod timer;
static AP_CAN_INIT: AtomicBool = ATOMIC_BOOL_INIT; static AP_CAN_INIT: AtomicBool = AtomicBool::new(false);
/// The entry point of kernel /// The entry point of kernel
#[no_mangle] // don't mangle the name of this function #[no_mangle] // don't mangle the name of this function

@ -21,7 +21,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; use x86_64;
Page::containing_address(x86_64::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 {
Page::range(Page::of_addr(begin), Page::of_addr(end - 1) + 1) Page::range(Page::of_addr(begin), Page::of_addr(end - 1) + 1)
@ -101,7 +101,7 @@ fn frame_to_page_table(frame: Frame) -> *mut x86PageTable {
impl Entry for PageEntry { impl Entry for PageEntry {
fn update(&mut self) { fn update(&mut self) {
use x86_64::{instructions::tlb::flush, VirtAddr}; use x86_64::instructions::tlb::flush;
let addr = self.1.start_address(); let addr = self.1.start_address();
flush(addr); flush(addr);
flush_tlb_all(addr.as_u64() as usize); flush_tlb_all(addr.as_u64() as usize);
@ -199,7 +199,7 @@ impl PageTableImpl {
/// WARN: You MUST call `core::mem::forget` for it after use! /// WARN: You MUST call `core::mem::forget` for it after use!
pub unsafe fn active() -> Self { pub unsafe fn active() -> Self {
let frame = Cr3::read().0; let frame = Cr3::read().0;
let table = unsafe { &mut *frame_to_page_table(frame) }; let table = &mut *frame_to_page_table(frame);
PageTableImpl( PageTableImpl(
MappedPageTable::new(table, frame_to_page_table), MappedPageTable::new(table, frame_to_page_table),
core::mem::MaybeUninit::uninitialized().into_initialized(), core::mem::MaybeUninit::uninitialized().into_initialized(),

@ -11,7 +11,6 @@ use bitflags::*;
use device_tree::util::SliceRead; use device_tree::util::SliceRead;
use device_tree::Node; use device_tree::Node;
use log::*; use log::*;
use rcore_memory::paging::PageTable;
use rcore_memory::PAGE_SIZE; use rcore_memory::PAGE_SIZE;
use volatile::Volatile; use volatile::Volatile;

@ -5,12 +5,12 @@ use alloc::string::String;
use alloc::sync::Arc; use alloc::sync::Arc;
use alloc::vec::Vec; use alloc::vec::Vec;
use bitflags::*;
use smoltcp::iface::*; use smoltcp::iface::*;
use smoltcp::phy::{self, DeviceCapabilities}; use smoltcp::phy::{self, DeviceCapabilities};
use smoltcp::time::Instant; use smoltcp::time::Instant;
use smoltcp::wire::*; use smoltcp::wire::*;
use smoltcp::Result; use smoltcp::Result;
use bitflags::*;
use crate::net::SOCKETS; use crate::net::SOCKETS;
use crate::sync::SpinNoIrqLock as Mutex; use crate::sync::SpinNoIrqLock as Mutex;
@ -119,7 +119,12 @@ impl phy::TxToken for RouterTxToken {
{ {
let mut buffer = vec![0; len]; let mut buffer = vec![0; len];
let res = f(&mut buffer); let res = f(&mut buffer);
debug!("out buf {} data {:x?} port {}", len, &buffer[..20], (self.0).1); debug!(
"out buf {} data {:x?} port {}",
len,
&buffer[..20],
(self.0).1
);
unsafe { unsafe {
AXI_STREAM_FIFO_TDR.write_volatile(2); AXI_STREAM_FIFO_TDR.write_volatile(2);
@ -145,7 +150,10 @@ impl Driver for RouterInterface {
let isr = unsafe { AXI_STREAM_FIFO_ISR.read_volatile() }; let isr = unsafe { AXI_STREAM_FIFO_ISR.read_volatile() };
if isr > 0 { if isr > 0 {
debug!("handle router interrupt {:?}", AXIStreamFifoInterrupt::from_bits_truncate(isr)); debug!(
"handle router interrupt {:?}",
AXIStreamFifoInterrupt::from_bits_truncate(isr)
);
unsafe { unsafe {
AXI_STREAM_FIFO_ISR.write(isr); AXI_STREAM_FIFO_ISR.write(isr);
let rdfo = AXI_STREAM_FIFO_RDFO.read_volatile(); let rdfo = AXI_STREAM_FIFO_RDFO.read_volatile();
@ -157,7 +165,12 @@ impl Driver for RouterInterface {
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!("got packet of length {} port {} data {:x?}", rdfo, port, &buffer[..20]); debug!(
"got packet of length {} port {} data {:x?}",
rdfo,
port,
&buffer[..20]
);
driver.buffer[port as usize].push(buffer); driver.buffer[port as usize].push(buffer);
} }
drop(driver); drop(driver);
@ -214,11 +227,14 @@ pub fn router_init() {
for i in 0..ENABLED_PORTS { for i in 0..ENABLED_PORTS {
let ethernet_addr = EthernetAddress::from_bytes(&[2, 2, 3, 3, 0, i]); let ethernet_addr = EthernetAddress::from_bytes(&[2, 2, 3, 3, 0, i]);
let net_driver = RouterDriver(Arc::new(Mutex::new(Router { buffer: [Vec::new(), Vec::new()] })), i); let net_driver = RouterDriver(
Arc::new(Mutex::new(Router {
buffer: [Vec::new(), Vec::new()],
})),
i,
);
let ip_addrs = [ let ip_addrs = [IpCidr::new(IpAddress::v4(10, 0, i, 1), 24)];
IpCidr::new(IpAddress::v4(10, 0, i, 1), 24),
];
let neighbor_cache = NeighborCache::new(BTreeMap::new()); let neighbor_cache = NeighborCache::new(BTreeMap::new());
let routes = Routes::new(BTreeMap::new()); let routes = Routes::new(BTreeMap::new());
let iface = EthernetInterfaceBuilder::new(net_driver.clone()) let iface = EthernetInterfaceBuilder::new(net_driver.clone())

@ -14,10 +14,9 @@
use super::HEAP_ALLOCATOR; use super::HEAP_ALLOCATOR;
pub use crate::arch::paging::*; pub use crate::arch::paging::*;
use crate::consts::{KERNEL_OFFSET, MEMORY_OFFSET, PHYSICAL_MEMORY_OFFSET}; use crate::consts::{MEMORY_OFFSET, PHYSICAL_MEMORY_OFFSET};
use crate::process::current_thread; use crate::process::current_thread;
use crate::sync::{MutexGuard, SpinNoIrq, SpinNoIrqLock}; use crate::sync::SpinNoIrqLock;
use alloc::boxed::Box;
use bitmap_allocator::BitAlloc; use bitmap_allocator::BitAlloc;
use buddy_system_allocator::Heap; use buddy_system_allocator::Heap;
use core::mem; use core::mem;
@ -132,13 +131,13 @@ pub fn handle_page_fault(addr: usize) -> bool {
pub fn init_heap() { pub fn init_heap() {
use crate::consts::KERNEL_HEAP_SIZE; use crate::consts::KERNEL_HEAP_SIZE;
const machine_align: usize = mem::size_of::<usize>(); const MACHINE_ALIGN: usize = mem::size_of::<usize>();
const heap_block: usize = KERNEL_HEAP_SIZE / machine_align; const HEAP_BLOCK: usize = KERNEL_HEAP_SIZE / MACHINE_ALIGN;
static mut HEAP: [usize; heap_block] = [0; heap_block]; static mut HEAP: [usize; HEAP_BLOCK] = [0; HEAP_BLOCK];
unsafe { unsafe {
HEAP_ALLOCATOR HEAP_ALLOCATOR
.lock() .lock()
.init(HEAP.as_ptr() as usize, heap_block * machine_align); .init(HEAP.as_ptr() as usize, HEAP_BLOCK * MACHINE_ALIGN);
} }
info!("heap init end"); info!("heap init end");
} }

@ -1,7 +1,6 @@
pub use self::structs::*; pub use self::structs::*;
use crate::arch::cpu; use crate::arch::cpu;
use crate::consts::{MAX_CPU_NUM, MAX_PROCESS_NUM}; use crate::consts::{MAX_CPU_NUM, MAX_PROCESS_NUM};
use crate::sync::{MutexGuard, SpinNoIrq};
use alloc::{boxed::Box, sync::Arc}; use alloc::{boxed::Box, sync::Arc};
use log::*; use log::*;
pub use rcore_thread::*; pub use rcore_thread::*;

@ -1,6 +1,5 @@
//! Kernel shell //! Kernel shell
use crate::arch::io;
use crate::fs::ROOT_INODE; use crate::fs::ROOT_INODE;
use crate::process::*; use crate::process::*;
use alloc::string::String; use alloc::string::String;

@ -1,5 +1,4 @@
use super::*; use super::*;
use crate::arch::cpu;
use crate::process::processor; use crate::process::processor;
use crate::thread; use crate::thread;
use alloc::collections::VecDeque; use alloc::collections::VecDeque;
@ -105,7 +104,7 @@ impl Condvar {
let mut count = 0; let mut count = 0;
let queue = self.wait_queue.lock(); let queue = self.wait_queue.lock();
for t in queue.iter() { for t in queue.iter() {
if (count >= n) { if count >= n {
break; break;
} }
t.unpark(); t.unpark();

@ -388,7 +388,7 @@ impl Syscall<'_> {
flags: usize, flags: 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 stat_ref = unsafe { self.vm().check_write_ptr(stat_ptr)? }; let stat_ref = unsafe { self.vm().check_write_ptr(stat_ptr)? };
let flags = AtFlags::from_bits_truncate(flags); let flags = AtFlags::from_bits_truncate(flags);
info!( info!(
@ -539,7 +539,7 @@ impl Syscall<'_> {
pub fn sys_chdir(&mut self, path: *const u8) -> SysResult { pub fn sys_chdir(&mut self, path: *const u8) -> 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)?;
if !proc.pid.is_init() { if !proc.pid.is_init() {
// we trust pid 0 process // we trust pid 0 process
info!("chdir: path: {:?}", path); info!("chdir: path: {:?}", path);
@ -592,8 +592,8 @@ impl Syscall<'_> {
newpath: *const u8, newpath: *const u8,
) -> SysResult { ) -> SysResult {
let proc = self.process(); let proc = self.process();
let oldpath = unsafe { check_and_clone_cstr(oldpath)? }; let oldpath = check_and_clone_cstr(oldpath)?;
let newpath = unsafe { check_and_clone_cstr(newpath)? }; let newpath = check_and_clone_cstr(newpath)?;
info!( info!(
"renameat: olddirfd: {}, oldpath: {:?}, newdirfd: {}, newpath: {:?}", "renameat: olddirfd: {}, oldpath: {:?}, newdirfd: {}, newpath: {:?}",
olddirfd as isize, oldpath, newdirfd as isize, newpath olddirfd as isize, oldpath, newdirfd as isize, newpath
@ -613,7 +613,7 @@ impl Syscall<'_> {
pub fn sys_mkdirat(&mut self, dirfd: usize, path: *const u8, mode: usize) -> SysResult { pub fn sys_mkdirat(&mut self, dirfd: usize, path: *const u8, mode: 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)?;
// TODO: check pathname // TODO: check pathname
info!( info!(
"mkdirat: dirfd: {}, path: {:?}, mode: {:#o}", "mkdirat: dirfd: {}, path: {:?}, mode: {:#o}",
@ -631,7 +631,7 @@ impl Syscall<'_> {
pub fn sys_rmdir(&mut self, path: *const u8) -> SysResult { pub fn sys_rmdir(&mut self, path: *const u8) -> 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!("rmdir: path: {:?}", path); info!("rmdir: path: {:?}", path);
let (dir_path, file_name) = split_path(&path); let (dir_path, file_name) = split_path(&path);
@ -657,8 +657,8 @@ impl Syscall<'_> {
flags: usize, flags: usize,
) -> SysResult { ) -> SysResult {
let proc = self.process(); let proc = self.process();
let oldpath = unsafe { check_and_clone_cstr(oldpath)? }; let oldpath = check_and_clone_cstr(oldpath)?;
let newpath = unsafe { check_and_clone_cstr(newpath)? }; let newpath = check_and_clone_cstr(newpath)?;
let flags = AtFlags::from_bits_truncate(flags); let flags = AtFlags::from_bits_truncate(flags);
info!( info!(
"linkat: olddirfd: {}, oldpath: {:?}, newdirfd: {}, newpath: {:?}, flags: {:?}", "linkat: olddirfd: {}, oldpath: {:?}, newdirfd: {}, newpath: {:?}, flags: {:?}",

@ -1,7 +1,5 @@
use rcore_memory::memory_set::handler::{Delay, File}; use rcore_memory::memory_set::handler::{Delay, File};
use rcore_memory::memory_set::MemoryAttr; use rcore_memory::memory_set::MemoryAttr;
use rcore_memory::paging::PageTable;
use rcore_memory::Page;
use rcore_memory::PAGE_SIZE; use rcore_memory::PAGE_SIZE;
use crate::memory::GlobalFrameAlloc; use crate::memory::GlobalFrameAlloc;

@ -16,13 +16,13 @@ use crate::sync::{Condvar, MutexGuard, SpinNoIrq};
use crate::thread; use crate::thread;
use crate::util; use crate::util;
use self::custom::*; pub use self::custom::*;
use self::fs::*; pub use self::fs::*;
use self::mem::*; pub use self::mem::*;
use self::misc::*; pub use self::misc::*;
pub use self::net::*; pub use self::net::*;
use self::proc::*; pub use self::proc::*;
use self::time::*; pub use self::time::*;
mod custom; mod custom;
mod fs; mod fs;
@ -32,7 +32,9 @@ mod net;
mod proc; mod proc;
mod time; mod time;
#[cfg(feature = "profile")]
use alloc::collections::BTreeMap; use alloc::collections::BTreeMap;
#[cfg(feature = "profile")]
use spin::Mutex; use spin::Mutex;
#[cfg(feature = "profile")] #[cfg(feature = "profile")]

@ -6,7 +6,7 @@ use crate::fs::FileLike;
use crate::memory::MemorySet; use crate::memory::MemorySet;
use crate::net::{ use crate::net::{
Endpoint, LinkLevelEndpoint, NetlinkEndpoint, NetlinkSocketState, PacketSocketState, Endpoint, LinkLevelEndpoint, NetlinkEndpoint, NetlinkSocketState, PacketSocketState,
RawSocketState, Socket, TcpSocketState, UdpSocketState, SOCKETS, RawSocketState, Socket, TcpSocketState, UdpSocketState,
}; };
use alloc::boxed::Box; use alloc::boxed::Box;
use core::cmp::min; use core::cmp::min;
@ -462,13 +462,13 @@ impl SockAddr {
return Ok(0); return Ok(0);
} }
let addr_len = unsafe { vm.check_write_ptr(addr_len)? }; let addr_len = vm.check_write_ptr(addr_len)?;
let max_addr_len = *addr_len as usize; let max_addr_len = *addr_len as usize;
let full_len = self.len()?; let full_len = self.len()?;
let written_len = min(max_addr_len, full_len); let written_len = min(max_addr_len, full_len);
if written_len > 0 { if written_len > 0 {
let target = unsafe { vm.check_write_array(addr as *mut u8, written_len)? }; let target = vm.check_write_array(addr as *mut u8, written_len)?;
let source = slice::from_raw_parts(&self as *const SockAddr as *const u8, written_len); let source = slice::from_raw_parts(&self as *const SockAddr as *const u8, written_len);
target.copy_from_slice(source); target.copy_from_slice(source);
} }

@ -1,7 +1,6 @@
//! Syscalls for process //! Syscalls for process
use super::*; use super::*;
use crate::fs::INodeExt;
impl Syscall<'_> { impl Syscall<'_> {
/// Fork the current process. Return the child's PID. /// Fork the current process. Return the child's PID.
@ -153,9 +152,9 @@ impl Syscall<'_> {
path, argv, envp path, argv, envp
); );
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 args = unsafe { check_and_clone_cstr_array(argv)? }; let args = check_and_clone_cstr_array(argv)?;
let envs = unsafe { check_and_clone_cstr_array(envp)? }; let envs = check_and_clone_cstr_array(envp)?;
if args.is_empty() { if args.is_empty() {
error!("exec: args is null"); error!("exec: args is null");

Loading…
Cancel
Save