Eliminate some warnings

master
Jiajie Chen 6 years ago
parent d1d7fe44a7
commit 51868e1616

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

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

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

@ -9,7 +9,7 @@ use core::sync::atomic::{spin_loop_hint, AtomicU8, Ordering};
pub type IPIEventItem = Box<FnBox()>;
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
}

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

@ -21,7 +21,7 @@ pub trait PageExt {
impl PageExt for Page {
fn of_addr(address: usize) -> Self {
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 {
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 {
fn update(&mut self) {
use x86_64::{instructions::tlb::flush, VirtAddr};
use x86_64::instructions::tlb::flush;
let addr = self.1.start_address();
flush(addr);
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!
pub unsafe fn active() -> Self {
let frame = Cr3::read().0;
let table = unsafe { &mut *frame_to_page_table(frame) };
let table = &mut *frame_to_page_table(frame);
PageTableImpl(
MappedPageTable::new(table, frame_to_page_table),
core::mem::MaybeUninit::uninitialized().into_initialized(),

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

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

@ -14,10 +14,9 @@
use super::HEAP_ALLOCATOR;
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::sync::{MutexGuard, SpinNoIrq, SpinNoIrqLock};
use alloc::boxed::Box;
use crate::sync::SpinNoIrqLock;
use bitmap_allocator::BitAlloc;
use buddy_system_allocator::Heap;
use core::mem;
@ -132,13 +131,13 @@ pub fn handle_page_fault(addr: usize) -> bool {
pub fn init_heap() {
use crate::consts::KERNEL_HEAP_SIZE;
const machine_align: usize = mem::size_of::<usize>();
const heap_block: usize = KERNEL_HEAP_SIZE / machine_align;
static mut HEAP: [usize; heap_block] = [0; heap_block];
const MACHINE_ALIGN: usize = mem::size_of::<usize>();
const HEAP_BLOCK: usize = KERNEL_HEAP_SIZE / MACHINE_ALIGN;
static mut HEAP: [usize; HEAP_BLOCK] = [0; HEAP_BLOCK];
unsafe {
HEAP_ALLOCATOR
.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");
}

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

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

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

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

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

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

@ -6,7 +6,7 @@ use crate::fs::FileLike;
use crate::memory::MemorySet;
use crate::net::{
Endpoint, LinkLevelEndpoint, NetlinkEndpoint, NetlinkSocketState, PacketSocketState,
RawSocketState, Socket, TcpSocketState, UdpSocketState, SOCKETS,
RawSocketState, Socket, TcpSocketState, UdpSocketState,
};
use alloc::boxed::Box;
use core::cmp::min;
@ -462,13 +462,13 @@ impl SockAddr {
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 full_len = self.len()?;
let written_len = min(max_addr_len, full_len);
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);
target.copy_from_slice(source);
}

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

Loading…
Cancel
Save