diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1be6baa5..fbffddff 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -7,11 +7,10 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - run: rm rust-toolchain - uses: actions-rs/toolchain@v1 with: profile: minimal - toolchain: nightly + toolchain: nightly-2020-04-06 override: true components: rustfmt, clippy - name: Check code format @@ -30,7 +29,7 @@ jobs: - uses: actions-rs/toolchain@v1 with: profile: minimal - toolchain: nightly-2020-01-17 + toolchain: nightly-2020-04-06 components: rust-src, llvm-tools-preview - name: Cache QEMU diff --git a/kernel/Cargo.lock b/kernel/Cargo.lock index 41889fb4..535f2e45 100644 --- a/kernel/Cargo.lock +++ b/kernel/Cargo.lock @@ -107,9 +107,10 @@ dependencies = [ [[package]] name = "buddy_system_allocator" -version = "0.3.5" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ + "rustversion 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "spin 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -330,7 +331,7 @@ name = "rboot" version = "0.1.2" dependencies = [ "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "uefi 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", + "uefi 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", "x86_64 0.9.6 (registry+https://github.com/rust-lang/crates.io-index)", "xmas-elf 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -348,7 +349,7 @@ dependencies = [ "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "bitmap-allocator 0.1.0 (git+https://github.com/rcore-os/bitmap-allocator)", "bitvec 0.17.2 (registry+https://github.com/rust-lang/crates.io-index)", - "buddy_system_allocator 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "buddy_system_allocator 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", "cc 1.0.50 (registry+https://github.com/rust-lang/crates.io-index)", "compression 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "device_tree 1.0.3 (git+https://github.com/rcore-os/device_tree-rs)", @@ -362,11 +363,11 @@ dependencies = [ "raw-cpuid 7.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "rboot 0.1.2", "rcore-console 0.1.0 (git+https://github.com/rcore-os/rcore-console?rev=b7bacf9)", - "rcore-fs 0.1.0 (git+https://github.com/rcore-os/rcore-fs?rev=e17b27b)", - "rcore-fs-devfs 0.1.0 (git+https://github.com/rcore-os/rcore-fs?rev=e17b27b)", - "rcore-fs-mountfs 0.1.0 (git+https://github.com/rcore-os/rcore-fs?rev=e17b27b)", - "rcore-fs-ramfs 0.1.0 (git+https://github.com/rcore-os/rcore-fs?rev=e17b27b)", - "rcore-fs-sfs 0.1.0 (git+https://github.com/rcore-os/rcore-fs?rev=e17b27b)", + "rcore-fs 0.1.0 (git+https://github.com/rcore-os/rcore-fs?rev=7f5eeac)", + "rcore-fs-devfs 0.1.0 (git+https://github.com/rcore-os/rcore-fs?rev=7f5eeac)", + "rcore-fs-mountfs 0.1.0 (git+https://github.com/rcore-os/rcore-fs?rev=7f5eeac)", + "rcore-fs-ramfs 0.1.0 (git+https://github.com/rcore-os/rcore-fs?rev=7f5eeac)", + "rcore-fs-sfs 0.1.0 (git+https://github.com/rcore-os/rcore-fs?rev=7f5eeac)", "rcore-memory 0.1.0", "rcore-thread 0.1.0 (git+https://github.com/rcore-os/rcore-thread?rev=d727949b)", "riscv 0.5.0 (git+https://github.com/rcore-os/riscv)", @@ -392,7 +393,7 @@ dependencies = [ [[package]] name = "rcore-fs" version = "0.1.0" -source = "git+https://github.com/rcore-os/rcore-fs?rev=e17b27b#e17b27b3d257f23ed8ba43d902c909d23245a008" +source = "git+https://github.com/rcore-os/rcore-fs?rev=7f5eeac#7f5eeac8b77f6bab11f6f2ce631a194bee658555" dependencies = [ "filetime 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", "spin 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -402,42 +403,42 @@ dependencies = [ [[package]] name = "rcore-fs-devfs" version = "0.1.0" -source = "git+https://github.com/rcore-os/rcore-fs?rev=e17b27b#e17b27b3d257f23ed8ba43d902c909d23245a008" +source = "git+https://github.com/rcore-os/rcore-fs?rev=7f5eeac#7f5eeac8b77f6bab11f6f2ce631a194bee658555" dependencies = [ "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "rcore-fs 0.1.0 (git+https://github.com/rcore-os/rcore-fs?rev=e17b27b)", + "rcore-fs 0.1.0 (git+https://github.com/rcore-os/rcore-fs?rev=7f5eeac)", "spin 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "rcore-fs-mountfs" version = "0.1.0" -source = "git+https://github.com/rcore-os/rcore-fs?rev=e17b27b#e17b27b3d257f23ed8ba43d902c909d23245a008" +source = "git+https://github.com/rcore-os/rcore-fs?rev=7f5eeac#7f5eeac8b77f6bab11f6f2ce631a194bee658555" dependencies = [ "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "rcore-fs 0.1.0 (git+https://github.com/rcore-os/rcore-fs?rev=e17b27b)", + "rcore-fs 0.1.0 (git+https://github.com/rcore-os/rcore-fs?rev=7f5eeac)", "spin 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "rcore-fs-ramfs" version = "0.1.0" -source = "git+https://github.com/rcore-os/rcore-fs?rev=e17b27b#e17b27b3d257f23ed8ba43d902c909d23245a008" +source = "git+https://github.com/rcore-os/rcore-fs?rev=7f5eeac#7f5eeac8b77f6bab11f6f2ce631a194bee658555" dependencies = [ "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "rcore-fs 0.1.0 (git+https://github.com/rcore-os/rcore-fs?rev=e17b27b)", + "rcore-fs 0.1.0 (git+https://github.com/rcore-os/rcore-fs?rev=7f5eeac)", "spin 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "rcore-fs-sfs" version = "0.1.0" -source = "git+https://github.com/rcore-os/rcore-fs?rev=e17b27b#e17b27b3d257f23ed8ba43d902c909d23245a008" +source = "git+https://github.com/rcore-os/rcore-fs?rev=7f5eeac#7f5eeac8b77f6bab11f6f2ce631a194bee658555" dependencies = [ "bitvec 0.17.2 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "rcore-fs 0.1.0 (git+https://github.com/rcore-os/rcore-fs?rev=e17b27b)", + "rcore-fs 0.1.0 (git+https://github.com/rcore-os/rcore-fs?rev=7f5eeac)", "spin 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", "static_assertions 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -496,6 +497,16 @@ dependencies = [ "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "rustversion" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "semver" version = "0.9.0" @@ -569,7 +580,7 @@ dependencies = [ [[package]] name = "uefi" -version = "0.4.3" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -717,7 +728,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" "checksum bitmap-allocator 0.1.0 (git+https://github.com/rcore-os/bitmap-allocator)" = "" "checksum bitvec 0.17.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1fe4300c1d7a9ea6f3e3f39c10b39862bb79e1175c0572b6b49539a30e5562f5" -"checksum buddy_system_allocator 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "59da15ef556589ee78370281d75b67f2d69ed26465ec0e0f3961e2021502426f" +"checksum buddy_system_allocator 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "9e953b958d83e13a44b1ead5b6aaa2a5f854bd5170239a66b606e030a14d018f" "checksum byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a7c3dd8985a7111efc5c80b44e23ecdd8c007de8ade3b96595387e812b957cf5" "checksum cast 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "4b9434b9a5aa1450faa3f9cb14ea0e8c53bb5d2b3c1bfd1ab4fc03e9f33fbfb0" "checksum cc 1.0.50 (registry+https://github.com/rust-lang/crates.io-index)" = "95e28fa049fda1c330bcf9d723be7663a899c4679724b34c81e9f5a326aab8cd" @@ -747,17 +758,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum raw-cpuid 6.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "30a9d219c32c9132f7be513c18be77c9881c7107d2ab5569d205a6a0f0e6dc7d" "checksum raw-cpuid 7.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "b4a349ca83373cfa5d6dbb66fd76e58b2cca08da71a5f6400de0a0a6a9bceeaf" "checksum rcore-console 0.1.0 (git+https://github.com/rcore-os/rcore-console?rev=b7bacf9)" = "" -"checksum rcore-fs 0.1.0 (git+https://github.com/rcore-os/rcore-fs?rev=e17b27b)" = "" -"checksum rcore-fs-devfs 0.1.0 (git+https://github.com/rcore-os/rcore-fs?rev=e17b27b)" = "" -"checksum rcore-fs-mountfs 0.1.0 (git+https://github.com/rcore-os/rcore-fs?rev=e17b27b)" = "" -"checksum rcore-fs-ramfs 0.1.0 (git+https://github.com/rcore-os/rcore-fs?rev=e17b27b)" = "" -"checksum rcore-fs-sfs 0.1.0 (git+https://github.com/rcore-os/rcore-fs?rev=e17b27b)" = "" +"checksum rcore-fs 0.1.0 (git+https://github.com/rcore-os/rcore-fs?rev=7f5eeac)" = "" +"checksum rcore-fs-devfs 0.1.0 (git+https://github.com/rcore-os/rcore-fs?rev=7f5eeac)" = "" +"checksum rcore-fs-mountfs 0.1.0 (git+https://github.com/rcore-os/rcore-fs?rev=7f5eeac)" = "" +"checksum rcore-fs-ramfs 0.1.0 (git+https://github.com/rcore-os/rcore-fs?rev=7f5eeac)" = "" +"checksum rcore-fs-sfs 0.1.0 (git+https://github.com/rcore-os/rcore-fs?rev=7f5eeac)" = "" "checksum rcore-thread 0.1.0 (git+https://github.com/rcore-os/rcore-thread?rev=d727949b)" = "" "checksum redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)" = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84" "checksum register 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e10f31b6d2299e5620986ad9fcdd66463e125ad72af4f403f9aedf7592d5ccdb" "checksum riscv 0.5.0 (git+https://github.com/rcore-os/riscv)" = "" "checksum rlibc 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc874b127765f014d792f16763a81245ab80500e2ad921ed4ee9e82481ee08fe" "checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" +"checksum rustversion 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b3bba175698996010c4f6dce5e7f173b6eb781fce25d2cfc45e27091ce0b79f6" "checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" "checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" "checksum smoltcp 0.5.0 (git+https://github.com/rcore-os/smoltcp?rev=5bd87c7c)" = "" @@ -768,7 +780,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum typenum 1.11.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6d2783fe2d6b8c1101136184eb41be8b1ad379e4657050b8aaff0c79ee7575f9" "checksum uart_16550 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "58fc0bc8ff1beb1436e8c4ce9c4b47f6f6c1376b56fb91505fabeef13743eb33" "checksum ucs2 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "85061f4e43545a613c0da6b87725bf23f8da8613cf2473719c4f71a270c4ce8a" -"checksum uefi 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "36c63ddfef80d9e7f1318917f6c05135b3b98027e973a9e9f0a6aebe87b95934" +"checksum uefi 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "5cec6a2850639f588cc8042140b5deaa2f2170c23db5adb08f4316fa04cdb4a0" "checksum uefi-macros 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c7d4a1b0215dc72e83d8d501b3275eb59477d3b595be8861abfb8ab110180955" "checksum unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" "checksum usize_conversions 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f70329e2cbe45d6c97a5112daad40c34cd9a4e18edb5a2a18fefeb584d8d25e5" diff --git a/kernel/Cargo.toml b/kernel/Cargo.toml index 1f220f82..5111467c 100644 --- a/kernel/Cargo.toml +++ b/kernel/Cargo.toml @@ -55,7 +55,7 @@ bitflags = "1.2" bit_field = "0.10" volatile = "0.2" bitvec = { version = "0.17", default-features = false, features = ["alloc"] } -buddy_system_allocator = "0.3" +buddy_system_allocator = "0.3.9" pci = { git = "https://github.com/rcore-os/pci-rs" } device_tree = { git = "https://github.com/rcore-os/device_tree-rs" } isomorphic_drivers = { git = "https://github.com/rcore-os/isomorphic_drivers", features = ["log"] } @@ -66,11 +66,11 @@ bitmap-allocator = { git = "https://github.com/rcore-os/bitmap-allocator" } rcore-console = { git = "https://github.com/rcore-os/rcore-console", rev = "b7bacf9", default-features = false } rcore-memory = { path = "../crate/memory" } rcore-thread = { git = "https://github.com/rcore-os/rcore-thread", rev = "d727949b" } -rcore-fs = { git = "https://github.com/rcore-os/rcore-fs", rev = "e17b27b" } -rcore-fs-sfs = { git = "https://github.com/rcore-os/rcore-fs", rev = "e17b27b" } -rcore-fs-ramfs = { git = "https://github.com/rcore-os/rcore-fs", rev = "e17b27b" } -rcore-fs-mountfs = { git = "https://github.com/rcore-os/rcore-fs", rev = "e17b27b" } -rcore-fs-devfs = { git = "https://github.com/rcore-os/rcore-fs", rev = "e17b27b" } +rcore-fs = { git = "https://github.com/rcore-os/rcore-fs", rev = "7f5eeac" } +rcore-fs-sfs = { git = "https://github.com/rcore-os/rcore-fs", rev = "7f5eeac" } +rcore-fs-ramfs = { git = "https://github.com/rcore-os/rcore-fs", rev = "7f5eeac" } +rcore-fs-mountfs = { git = "https://github.com/rcore-os/rcore-fs", rev = "7f5eeac" } +rcore-fs-devfs = { git = "https://github.com/rcore-os/rcore-fs", rev = "7f5eeac" } compression = { version = "0.1.4", default-features = false, features = ["gzip"] } diff --git a/kernel/src/arch/mipsel/board/malta/mod.rs b/kernel/src/arch/mipsel/board/malta/mod.rs index 94ca1bb5..bb929912 100644 --- a/kernel/src/arch/mipsel/board/malta/mod.rs +++ b/kernel/src/arch/mipsel/board/malta/mod.rs @@ -1,6 +1,5 @@ use crate::drivers::bus::pci; use crate::drivers::gpu::fb::{self, FramebufferInfo}; -use alloc::string::String; use mips::registers::cp0; pub mod consts; diff --git a/kernel/src/arch/mipsel/context.rs b/kernel/src/arch/mipsel/context.rs index ee968e3f..92ae8b6a 100644 --- a/kernel/src/arch/mipsel/context.rs +++ b/kernel/src/arch/mipsel/context.rs @@ -1,5 +1,5 @@ use mips::registers::cp0; -use mips::tlb; +use mips::tlb::TLBEntry; /// Saved registers on a trap. #[derive(Clone)] @@ -238,7 +238,7 @@ impl Context { fn switch_context(src: *mut Context, dst: *mut Context); } - tlb::clear_all_tlb(); + TLBEntry::clear_all(); switch_context(self as *mut Context, target as *mut Context); } diff --git a/kernel/src/arch/mipsel/cpu.rs b/kernel/src/arch/mipsel/cpu.rs index afce457c..14fe81b5 100644 --- a/kernel/src/arch/mipsel/cpu.rs +++ b/kernel/src/arch/mipsel/cpu.rs @@ -27,7 +27,7 @@ pub fn halt() { } } -pub unsafe fn exit_in_qemu(error_code: u8) -> ! { +pub unsafe fn exit_in_qemu(_error_code: u8) -> ! { /* nothing to do */ loop {} } diff --git a/kernel/src/arch/mipsel/interrupt.rs b/kernel/src/arch/mipsel/interrupt.rs index 578a16dd..c15966f1 100644 --- a/kernel/src/arch/mipsel/interrupt.rs +++ b/kernel/src/arch/mipsel/interrupt.rs @@ -1,14 +1,11 @@ pub use self::context::*; use crate::arch::paging::get_root_page_table_ptr; -use crate::drivers::{DRIVERS, IRQ_MANAGER}; +use crate::drivers::IRQ_MANAGER; use log::*; use mips::addr::*; use mips::interrupts; -use mips::paging::{ - PageTable as MIPSPageTable, PageTableEntry, PageTableFlags as EF, TwoLevelPageTable, -}; +use mips::paging::PageTable as MIPSPageTable; use mips::registers::cp0; -use mips::tlb; #[path = "context.rs"] mod context; @@ -154,7 +151,7 @@ fn syscall(tf: &mut TrapFrame) { ); // temporary solution for ThinPad - if (tf.v0 == 0) { + if tf.v0 == 0 { warn!("Syscall ID = 0"); tf.v0 = unsafe { *((tf.sp + 28) as *const usize) }; } @@ -162,7 +159,7 @@ fn syscall(tf: &mut TrapFrame) { let ret = crate::syscall::syscall(tf.v0, arguments, tf) as isize; // comply with mips n32 abi, always return a positive value // https://git.musl-libc.org/cgit/musl/tree/arch/mipsn32/syscall_arch.h - if (ret < 0) { + if ret < 0 { tf.v0 = (-ret) as usize; tf.a3 = 1; } else { @@ -282,7 +279,7 @@ fn page_fault(tf: &mut TrapFrame) { } } - tlb::write_tlb_random(tlb_entry) + tlb_entry.write_random() } Err(()) => { if !crate::memory::handle_page_fault(addr) { diff --git a/kernel/src/arch/mipsel/memory.rs b/kernel/src/arch/mipsel/memory.rs index 43c99f0d..bd066441 100644 --- a/kernel/src/arch/mipsel/memory.rs +++ b/kernel/src/arch/mipsel/memory.rs @@ -1,8 +1,6 @@ use crate::arch::paging::*; use crate::consts::{KERNEL_OFFSET, MEMORY_END, MEMORY_OFFSET}; -use crate::memory::{init_heap, Linear, MemoryAttr, MemorySet, FRAME_ALLOCATOR}; -use core::mem; -use log::*; +use crate::memory::{init_heap, FRAME_ALLOCATOR}; use rcore_memory::PAGE_SIZE; /// Initialize the memory management module @@ -46,10 +44,6 @@ fn init_frame_allocator() { } } -// First core stores its SATP here. -// Other cores load it later. -static mut SATP: usize = 0; - pub unsafe fn clear_bss() { let start = sbss as usize; let end = ebss as usize; diff --git a/kernel/src/arch/mipsel/mod.rs b/kernel/src/arch/mipsel/mod.rs index 027823c1..5bbac1c3 100644 --- a/kernel/src/arch/mipsel/mod.rs +++ b/kernel/src/arch/mipsel/mod.rs @@ -9,7 +9,6 @@ pub mod rand; pub mod syscall; pub mod timer; -use log::*; use mips::registers::cp0; #[cfg(feature = "board_malta")] @@ -62,12 +61,14 @@ pub extern "C" fn rust_main() -> ! { crate::kmain(); } +/* fn others_main() -> ! { interrupt::init(); memory::init_other(); timer::init(); crate::kmain(); } +*/ const BOOT_CPU_ID: u32 = 0; diff --git a/kernel/src/arch/mipsel/paging.rs b/kernel/src/arch/mipsel/paging.rs index 845c6cff..97a4f563 100644 --- a/kernel/src/arch/mipsel/paging.rs +++ b/kernel/src/arch/mipsel/paging.rs @@ -125,7 +125,7 @@ impl Entry for PageEntry { fn readonly_shared(&self) -> bool { false } - fn set_shared(&mut self, writable: bool) {} + fn set_shared(&mut self, _writable: bool) {} fn clear_shared(&mut self) {} fn swapped(&self) -> bool { self.0.flags().contains(EF::RESERVED1) @@ -136,11 +136,11 @@ impl Entry for PageEntry { fn user(&self) -> bool { true } - fn set_user(&mut self, value: bool) {} + fn set_user(&mut self, _value: bool) {} fn execute(&self) -> bool { true } - fn set_execute(&mut self, value: bool) {} + fn set_execute(&mut self, _value: bool) {} fn mmio(&self) -> u8 { 0 } diff --git a/kernel/src/arch/riscv/cpu.rs b/kernel/src/arch/riscv/cpu.rs index 89e2d95a..ec58597e 100644 --- a/kernel/src/arch/riscv/cpu.rs +++ b/kernel/src/arch/riscv/cpu.rs @@ -18,7 +18,7 @@ pub fn halt() { unsafe { riscv::asm::wfi() } } -pub unsafe fn exit_in_qemu(error_code: u8) -> ! { +pub unsafe fn exit_in_qemu(_error_code: u8) -> ! { super::sbi::shutdown() } diff --git a/kernel/src/arch/riscv/interrupt.rs b/kernel/src/arch/riscv/interrupt.rs index 8a342b91..f16ece3b 100644 --- a/kernel/src/arch/riscv/interrupt.rs +++ b/kernel/src/arch/riscv/interrupt.rs @@ -1,5 +1,5 @@ pub use self::context::*; -use crate::drivers::{DRIVERS, IRQ_MANAGER}; +use crate::drivers::IRQ_MANAGER; use log::*; use riscv::register::*; diff --git a/kernel/src/arch/riscv/memory.rs b/kernel/src/arch/riscv/memory.rs index 6ea6a7e0..620ec15b 100644 --- a/kernel/src/arch/riscv/memory.rs +++ b/kernel/src/arch/riscv/memory.rs @@ -1,10 +1,9 @@ -use crate::consts::{KERNEL_OFFSET, MEMORY_END, MEMORY_OFFSET, PHYSICAL_MEMORY_OFFSET}; -use crate::memory::{init_heap, Linear, MemoryAttr, MemorySet, FRAME_ALLOCATOR}; +use crate::consts::{KERNEL_OFFSET, MEMORY_END, MEMORY_OFFSET}; +use crate::memory::{init_heap, MemorySet, FRAME_ALLOCATOR}; use core::mem; use log::*; use rcore_memory::PAGE_SIZE; -use riscv::register::satp; -use riscv::{addr::*, register::sstatus}; +use riscv::register::sstatus; /// Initialize the memory management module pub fn init(dtb: usize) { @@ -51,7 +50,7 @@ fn init_frame_allocator() { /// Remap the kernel memory address with 4K page recorded in p1 page table fn remap_the_kernel(_dtb: usize) { - let mut ms = MemorySet::new(); + let ms = MemorySet::new(); unsafe { ms.activate(); } diff --git a/kernel/src/arch/riscv/mod.rs b/kernel/src/arch/riscv/mod.rs index 33bf2280..67c4c59b 100644 --- a/kernel/src/arch/riscv/mod.rs +++ b/kernel/src/arch/riscv/mod.rs @@ -22,20 +22,17 @@ pub mod timer; use crate::memory::phys_to_virt; use core::sync::atomic::{AtomicBool, Ordering}; -use log::*; #[no_mangle] pub extern "C" fn rust_main(hartid: usize, device_tree_paddr: usize) -> ! { - let mut device_tree_vaddr = phys_to_virt(device_tree_paddr); + let device_tree_vaddr = phys_to_virt(device_tree_paddr); unsafe { cpu::set_cpu_id(hartid); } #[cfg(feature = "board_rocket_chip")] - { - device_tree_vaddr = board::DTB.as_ptr() as usize; - } + let device_tree_vaddr = board::DTB.as_ptr() as usize; if hartid != BOOT_HART_ID { while !AP_CAN_INIT.load(Ordering::Relaxed) {} @@ -88,7 +85,7 @@ const BOOT_HART_ID: usize = 0; #[cfg(feature = "board_u540")] const BOOT_HART_ID: usize = 1; -/// Constant & Macro for `trap.asm` +// Constant & Macro for `trap.asm` #[cfg(target_arch = "riscv32")] global_asm!( r" diff --git a/kernel/src/arch/riscv/paging.rs b/kernel/src/arch/riscv/paging.rs index 57a8cfc1..c4e4ee9b 100644 --- a/kernel/src/arch/riscv/paging.rs +++ b/kernel/src/arch/riscv/paging.rs @@ -6,11 +6,7 @@ use rcore_memory::paging::*; use riscv::addr::*; use riscv::asm::{sfence_vma, sfence_vma_all}; use riscv::paging::{FrameAllocator, FrameDeallocator}; -use riscv::paging::{ - Mapper, PageTable as RvPageTable, PageTableEntry, PageTableFlags as EF, PageTableType, - RecursivePageTable, -}; -use riscv::register::satp; +use riscv::paging::{Mapper, PageTable as RvPageTable, PageTableEntry, PageTableFlags as EF}; #[cfg(target_arch = "riscv32")] type TopLevelPageTable<'a> = riscv::paging::Rv32PageTable<'a>; @@ -199,7 +195,7 @@ impl PageTableExt for PageTableImpl { } #[cfg(target_arch = "riscv64")] for i in 509..512 { - if (i == 510) { + if i == 510 { // MMIO range 0x60000000 - 0x7FFFFFFF does not work as a large page, dunno why continue; } @@ -212,40 +208,40 @@ impl PageTableExt for PageTableImpl { } // MMIO range 0x60000000 - 0x7FFFFFFF does not work as a large page, dunno why - let flags = EF::VALID | EF::READABLE | EF::WRITABLE; // map Uartlite for Rocket Chip #[cfg(feature = "board_rocket_chip")] - self.page_table - .map_to( - Page::of_addr(VirtAddr::new(PHYSICAL_MEMORY_OFFSET + 0x6000_0000)), - Frame::of_addr(PhysAddr::new(0x6000_0000)), - flags, - &mut FrameAllocatorForRiscv, - ) - .unwrap() - .flush(); - // map AXI INTC for Rocket Chip - #[cfg(feature = "board_rocket_chip")] - self.page_table - .map_to( - Page::of_addr(VirtAddr::new(PHYSICAL_MEMORY_OFFSET + 0x6120_0000)), - Frame::of_addr(PhysAddr::new(0x6120_0000)), - flags, - &mut FrameAllocatorForRiscv, - ) - .unwrap() - .flush(); - // map AXI4-Stream Data FIFO for Rocket Chip - #[cfg(feature = "board_rocket_chip")] - self.page_table - .map_to( - Page::of_addr(VirtAddr::new(PHYSICAL_MEMORY_OFFSET + 0x64A0_0000)), - Frame::of_addr(PhysAddr::new(0x64A0_0000)), - flags, - &mut FrameAllocatorForRiscv, - ) - .unwrap() - .flush(); + { + let flags = EF::VALID | EF::READABLE | EF::WRITABLE; + self.page_table + .map_to( + Page::of_addr(VirtAddr::new(PHYSICAL_MEMORY_OFFSET + 0x6000_0000)), + Frame::of_addr(PhysAddr::new(0x6000_0000)), + flags, + &mut FrameAllocatorForRiscv, + ) + .unwrap() + .flush(); + // map AXI INTC for Rocket Chip + self.page_table + .map_to( + Page::of_addr(VirtAddr::new(PHYSICAL_MEMORY_OFFSET + 0x6120_0000)), + Frame::of_addr(PhysAddr::new(0x6120_0000)), + flags, + &mut FrameAllocatorForRiscv, + ) + .unwrap() + .flush(); + // map AXI4-Stream Data FIFO for Rocket Chip + self.page_table + .map_to( + Page::of_addr(VirtAddr::new(PHYSICAL_MEMORY_OFFSET + 0x64A0_0000)), + Frame::of_addr(PhysAddr::new(0x64A0_0000)), + flags, + &mut FrameAllocatorForRiscv, + ) + .unwrap() + .flush(); + } } fn token(&self) -> usize { @@ -260,7 +256,7 @@ impl PageTableExt for PageTableImpl { } fn active_token() -> usize { - let mut token: usize = 0; + let mut token; unsafe { asm!("csrr $0, satp" : "=r"(token) ::: "volatile"); } diff --git a/kernel/src/arch/x86_64/acpi.rs b/kernel/src/arch/x86_64/acpi.rs index dd10a3e6..64002bda 100644 --- a/kernel/src/arch/x86_64/acpi.rs +++ b/kernel/src/arch/x86_64/acpi.rs @@ -18,7 +18,7 @@ impl AcpiHandler for Handler { } } - fn unmap_physical_region(&mut self, region: PhysicalMapping) { + fn unmap_physical_region(&mut self, _region: PhysicalMapping) { // do nothing } } diff --git a/kernel/src/arch/x86_64/board/mod.rs b/kernel/src/arch/x86_64/board/mod.rs index 8699975c..4b29dbd5 100755 --- a/kernel/src/arch/x86_64/board/mod.rs +++ b/kernel/src/arch/x86_64/board/mod.rs @@ -1,7 +1,5 @@ -use crate::consts::KERNEL_OFFSET; use crate::drivers::gpu::fb::{self, ColorDepth, ColorFormat, FramebufferInfo}; use crate::memory::phys_to_virt; -use core::mem::zeroed; use rboot::BootInfo; pub fn init_driver(boot_info: &BootInfo) { @@ -17,7 +15,7 @@ pub fn init_driver(boot_info: &BootInfo) { xoffset: 0, yoffset: 0, depth: ColorDepth::ColorDepth32, - format: fb::ColorFormat::RGBA8888, + format: ColorFormat::RGBA8888, paddr: info.fb_addr as usize, vaddr: phys_to_virt(info.fb_addr as usize), screen_size: info.fb_size as usize, diff --git a/kernel/src/arch/x86_64/driver/mod.rs b/kernel/src/arch/x86_64/driver/mod.rs index 3fa0c2f7..f96a5a70 100644 --- a/kernel/src/arch/x86_64/driver/mod.rs +++ b/kernel/src/arch/x86_64/driver/mod.rs @@ -5,7 +5,7 @@ pub mod serial; use super::BootInfo; -pub fn init(boot_info: &BootInfo) { +pub fn init(_boot_info: &BootInfo) { serial::init(); keyboard::init(); diff --git a/kernel/src/arch/x86_64/interrupt/handler.rs b/kernel/src/arch/x86_64/interrupt/handler.rs index b71b766d..53539e1e 100644 --- a/kernel/src/arch/x86_64/interrupt/handler.rs +++ b/kernel/src/arch/x86_64/interrupt/handler.rs @@ -66,7 +66,7 @@ use super::consts::*; use super::TrapFrame; -use crate::drivers::{DRIVERS, IRQ_MANAGER}; +use crate::drivers::IRQ_MANAGER; use bitflags::*; use log::*; diff --git a/kernel/src/arch/x86_64/ipi.rs b/kernel/src/arch/x86_64/ipi.rs index 3d0b28a8..4ad26de5 100644 --- a/kernel/src/arch/x86_64/ipi.rs +++ b/kernel/src/arch/x86_64/ipi.rs @@ -10,7 +10,7 @@ use core::sync::atomic::{spin_loop_hint, AtomicU8, Ordering}; pub type IPIEventItem = Box; unsafe fn get_apic() -> XApic { - let mut lapic = XApic::new(phys_to_virt(LAPIC_ADDR)); + let lapic = XApic::new(phys_to_virt(LAPIC_ADDR)); lapic } diff --git a/kernel/src/arch/x86_64/paging.rs b/kernel/src/arch/x86_64/paging.rs index a90d05a6..9a637577 100644 --- a/kernel/src/arch/x86_64/paging.rs +++ b/kernel/src/arch/x86_64/paging.rs @@ -1,7 +1,6 @@ use super::consts::*; use crate::memory::{alloc_frame, dealloc_frame, phys_to_virt}; use core::mem::ManuallyDrop; -use core::sync::atomic::Ordering; use log::*; use rcore_memory::paging::*; use x86_64::instructions::tlb; @@ -284,11 +283,11 @@ impl FrameDeallocator for FrameAllocatorForX86 { } /// Flush TLB for `vaddr` on all CPU -fn flush_tlb_all(vaddr: usize) { +fn flush_tlb_all(_vaddr: usize) { // FIXME: too slow, disable now. return; - if !super::AP_CAN_INIT.load(Ordering::Relaxed) { - return; - } - super::ipi::invoke_on_allcpu(move || tlb::flush(VirtAddr::new(vaddr as u64)), false); + // if !super::AP_CAN_INIT.load(Ordering::Relaxed) { + // return; + // } + // super::ipi::invoke_on_allcpu(move || tlb::flush(VirtAddr::new(vaddr as u64)), false); } diff --git a/kernel/src/backtrace.rs b/kernel/src/backtrace.rs index 223e99be..6a41652e 100644 --- a/kernel/src/backtrace.rs +++ b/kernel/src/backtrace.rs @@ -1,5 +1,4 @@ use core::mem::size_of; -use rcore_memory::PAGE_SIZE; extern "C" { fn stext(); @@ -165,6 +164,7 @@ pub fn backtrace() { // Kernel stack at 0x0000_57ac_0000_0000 (defined in bootloader crate) // size = 512 pages current_fp = *(current_fp as *const usize).offset(0); + use rcore_memory::PAGE_SIZE; if current_fp >= 0x0000_57ac_0000_0000 + 512 * PAGE_SIZE - size_of::() && current_fp <= 0xffff_ff00_0000_0000 { diff --git a/kernel/src/drivers/block/virtio_blk.rs b/kernel/src/drivers/block/virtio_blk.rs index e38d49c0..ca99b816 100644 --- a/kernel/src/drivers/block/virtio_blk.rs +++ b/kernel/src/drivers/block/virtio_blk.rs @@ -1,11 +1,9 @@ use alloc::string::String; use alloc::sync::Arc; -use log::*; use virtio_drivers::{VirtIOBlk, VirtIOHeader}; use super::super::{DeviceType, Driver, BLK_DRIVERS, DRIVERS, IRQ_MANAGER}; -use crate::memory::phys_to_virt; use crate::sync::SpinNoIrqLock as Mutex; struct VirtIOBlkDriver(Mutex>); diff --git a/kernel/src/drivers/bus/virtio_mmio.rs b/kernel/src/drivers/bus/virtio_mmio.rs index 4d8331dd..61c8fd3d 100644 --- a/kernel/src/drivers/bus/virtio_mmio.rs +++ b/kernel/src/drivers/bus/virtio_mmio.rs @@ -8,7 +8,7 @@ use super::super::block::virtio_blk; use super::super::gpu::virtio_gpu; use super::super::input::virtio_input; use super::super::net::virtio_net; -use crate::memory::{phys_to_virt, virt_to_phys}; +use crate::memory::phys_to_virt; pub fn virtio_probe(node: &Node) { let reg = match node.prop_raw("reg") { diff --git a/kernel/src/drivers/console/mod.rs b/kernel/src/drivers/console/mod.rs index f2ccb5df..eb371e44 100644 --- a/kernel/src/drivers/console/mod.rs +++ b/kernel/src/drivers/console/mod.rs @@ -12,7 +12,7 @@ pub static CONSOLE: Mutex> = Mutex::new(None); /// Initialize console driver pub fn init() { if cfg!(feature = "consolegraphic") { - if let Some(fb) = FRAME_BUFFER.lock().take() { + if let Some(fb) = FRAME_BUFFER.write().take() { // FIXME: now take FrameBuffer out of global variable, then move into Console let console = Console::on_frame_buffer(fb.fb_info.xres, fb.fb_info.yres, fb); *CONSOLE.lock() = Some(console); diff --git a/kernel/src/drivers/gpu/fb.rs b/kernel/src/drivers/gpu/fb.rs index a3745f23..de3a300d 100644 --- a/kernel/src/drivers/gpu/fb.rs +++ b/kernel/src/drivers/gpu/fb.rs @@ -2,9 +2,8 @@ use alloc::string::String; use core::fmt; -use lazy_static::lazy_static; use log::*; -use spin::Mutex; +use spin::RwLock; /// Framebuffer information #[repr(C)] @@ -195,23 +194,48 @@ impl Framebuffer { } } - /// Copy buffer `[src_off .. src_off + size]` to `[dst_off .. dst_off + size]`. - /// `dst_off`, `src_off` and `size` must be aligned with `usize`. - pub fn copy(&mut self, dst_off: usize, src_off: usize, size: usize) { - const USIZE: usize = core::mem::size_of::(); - let mut dst = self.base_addr() + dst_off; - let mut src = self.base_addr() + src_off; - let src_end = src + size; - while src < src_end { - unsafe { *(dst as *mut usize) = *(src as *mut usize) } - dst += USIZE; - src += USIZE; + /// Read buffer data starts at `offset` to `buf`. + pub fn read_at(&self, offset: usize, buf: &mut [u8]) -> usize { + if offset >= self.fb_info.screen_size { + return 0; } + let count = buf.len().min(self.fb_info.screen_size - offset); + let data = unsafe { + core::slice::from_raw_parts((self.buf.base_addr + offset) as *const u8, count) + }; + buf[..count].copy_from_slice(&data); + count } - /// Fill buffer `[offset .. offset + size]` with `pixel`. - /// `offset` and `size` must be aligned with `usize`. - pub fn fill(&mut self, offset: usize, size: usize, pixel: u32) { + /// Write buffer data starts at `offset` to `buf`. + pub fn write_at(&mut self, offset: usize, buf: &[u8]) -> usize { + if offset > self.fb_info.screen_size { + return 0; + } + let count = buf.len().min(self.fb_info.screen_size - offset); + let data = unsafe { + core::slice::from_raw_parts_mut((self.buf.base_addr + offset) as *mut u8, count) + }; + data.copy_from_slice(&buf[..count]); + count + } + + /// Copy buffer `[src_off .. src_off + count]` to `[dst_off .. dst_off + count]`. + pub fn copy(&mut self, dst_off: usize, src_off: usize, count: usize) { + let size = self.fb_info.screen_size; + if src_off >= size || dst_off >= size { + return; + } + let count = count.min(size - src_off).min(size - dst_off); + unsafe { + let buf = core::slice::from_raw_parts_mut(self.buf.base_addr as *mut u8, size); + buf.copy_within(src_off..src_off + count, dst_off) + }; + } + + /// Fill buffer `[offset .. offset + count]` with `pixel`. + /// `offset` and `count` must be aligned with `usize`. + pub fn fill(&mut self, offset: usize, count: usize, pixel: u32) { const USIZE: usize = core::mem::size_of::(); let mut value: usize = 0; let depth = self.fb_info.depth as usize; @@ -222,8 +246,13 @@ impl Framebuffer { value += pixel as usize & mask; } + let offset = offset & !(USIZE - 1); + if offset >= self.fb_info.screen_size { + return; + } + let count = (count & !(USIZE - 1)).min(self.fb_info.screen_size - offset); let mut start = self.base_addr() + offset; - let end = start + size; + let end = start + count; while start < end { unsafe { *(start as *mut usize) = value } start += USIZE; @@ -280,7 +309,7 @@ impl ColorEncode for Rgb888 { } } -pub static FRAME_BUFFER: Mutex> = Mutex::new(None); +pub static FRAME_BUFFER: RwLock> = RwLock::new(None); /// Initialize framebuffer /// @@ -288,5 +317,5 @@ pub static FRAME_BUFFER: Mutex> = Mutex::new(None); pub fn init(info: FramebufferInfo) { let fb = Framebuffer::new(info); info!("framebuffer: init end\n{:#x?}", fb); - *FRAME_BUFFER.lock() = Some(fb); + *FRAME_BUFFER.write() = Some(fb); } diff --git a/kernel/src/drivers/gpu/qemu_stdvga.rs b/kernel/src/drivers/gpu/qemu_stdvga.rs index 1515f152..f1654405 100644 --- a/kernel/src/drivers/gpu/qemu_stdvga.rs +++ b/kernel/src/drivers/gpu/qemu_stdvga.rs @@ -1,5 +1,7 @@ //! driver for qemu stdvga (Cirrus) +#![allow(dead_code)] + use crate::util::{read, write}; const VGA_MMIO_OFFSET: usize = 0x400 - 0x3C0; diff --git a/kernel/src/drivers/gpu/virtio_gpu.rs b/kernel/src/drivers/gpu/virtio_gpu.rs index a17e2b3f..e9d2bbf2 100644 --- a/kernel/src/drivers/gpu/virtio_gpu.rs +++ b/kernel/src/drivers/gpu/virtio_gpu.rs @@ -1,7 +1,6 @@ use alloc::string::String; use alloc::sync::Arc; -use log::*; use virtio_drivers::{VirtIOGpu, VirtIOHeader}; use super::super::{DeviceType, Driver, DRIVERS, IRQ_MANAGER}; diff --git a/kernel/src/drivers/input/virtio_input.rs b/kernel/src/drivers/input/virtio_input.rs index da06eb55..4d98ff02 100644 --- a/kernel/src/drivers/input/virtio_input.rs +++ b/kernel/src/drivers/input/virtio_input.rs @@ -31,7 +31,7 @@ impl Driver for VirtIOInputDriver { pub fn init(header: &'static mut VirtIOHeader) { let event_buf = Box::leak(Box::new([0u64; 32])); - let mut input = VirtIOInput::new(header, event_buf).expect("failed to create input driver"); + let input = VirtIOInput::new(header, event_buf).expect("failed to create input driver"); let driver = Arc::new(VirtIOInputDriver(Mutex::new(input))); IRQ_MANAGER.write().register_all(driver.clone()); diff --git a/kernel/src/drivers/mod.rs b/kernel/src/drivers/mod.rs index 62dfa812..2ed5b0cf 100644 --- a/kernel/src/drivers/mod.rs +++ b/kernel/src/drivers/mod.rs @@ -14,6 +14,7 @@ pub mod block; #[allow(dead_code)] pub mod bus; pub mod console; +#[allow(dead_code)] mod device_tree; #[allow(dead_code)] pub mod gpu; diff --git a/kernel/src/drivers/net/router.rs b/kernel/src/drivers/net/router.rs index abac98e0..0c80035a 100644 --- a/kernel/src/drivers/net/router.rs +++ b/kernel/src/drivers/net/router.rs @@ -159,10 +159,10 @@ impl Driver for RouterInterface { let rdfo = AXI_STREAM_FIFO_RDFO.read_volatile(); if rdfo > 0 { let mut buffer = Vec::new(); - let rlr = AXI_STREAM_FIFO_RLR.read_volatile(); - let rdr = AXI_STREAM_FIFO_RDR.read_volatile(); + let _rlr = AXI_STREAM_FIFO_RLR.read_volatile(); + let _rdr = AXI_STREAM_FIFO_RDR.read_volatile(); let port = AXI_STREAM_FIFO_RDFD.read_volatile(); - for i in 1..rdfo { + for _ in 1..rdfo { buffer.push(AXI_STREAM_FIFO_RDFD.read_volatile() as u8); } debug!( diff --git a/kernel/src/drivers/net/virtio_net.rs b/kernel/src/drivers/net/virtio_net.rs index 957f8dd0..f424df23 100644 --- a/kernel/src/drivers/net/virtio_net.rs +++ b/kernel/src/drivers/net/virtio_net.rs @@ -2,7 +2,6 @@ use alloc::format; use alloc::string::String; use alloc::sync::Arc; -use log::*; use smoltcp::phy::{self, DeviceCapabilities}; use smoltcp::time::Instant; use smoltcp::wire::{EthernetAddress, Ipv4Address}; @@ -10,7 +9,6 @@ use smoltcp::Result; use virtio_drivers::{VirtIOHeader, VirtIONet}; use super::super::{DeviceType, Driver, DRIVERS, IRQ_MANAGER, NET_DRIVERS}; -use crate::memory::phys_to_virt; use crate::sync::SpinNoIrqLock as Mutex; #[derive(Clone)] @@ -51,7 +49,7 @@ impl phy::Device<'_> for VirtIONetDriver { type TxToken = VirtIONetDriver; fn receive(&mut self) -> Option<(Self::RxToken, Self::TxToken)> { - let mut net = self.0.lock(); + let net = self.0.lock(); if net.can_recv() { Some((self.clone(), self.clone())) } else { @@ -60,7 +58,7 @@ impl phy::Device<'_> for VirtIONetDriver { } fn transmit(&mut self) -> Option { - let mut net = self.0.lock(); + let net = self.0.lock(); if net.can_send() { Some(self.clone()) } else { diff --git a/kernel/src/fs/vga.rs b/kernel/src/fs/devfs/fbdev.rs similarity index 76% rename from kernel/src/fs/vga.rs rename to kernel/src/fs/devfs/fbdev.rs index e3f7d3b6..d761ccef 100755 --- a/kernel/src/fs/vga.rs +++ b/kernel/src/fs/devfs/fbdev.rs @@ -1,32 +1,43 @@ -use rcore_fs::vfs::*; +//! Implement INode for framebuffer use crate::drivers::gpu::fb::{ColorFormat, FramebufferInfo, FRAME_BUFFER}; -use crate::memory::phys_to_virt; -use alloc::{string::String, sync::Arc, vec::Vec}; +use crate::syscall::MmapProt; use core::any::Any; -#[derive(Default)] -pub struct Vga; +use rcore_fs::vfs::*; +use rcore_memory::memory_set::handler::Linear; -impl INode for Vga { +#[derive(Default)] +pub struct Fbdev; + +impl INode for Fbdev { fn read_at(&self, offset: usize, buf: &mut [u8]) -> Result { - Err(FsError::NotSupported) - } - fn write_at(&self, _offset: usize, _buf: &[u8]) -> Result { - info!("the _offset is {} {}", _offset, _buf[0]); - let lock = FRAME_BUFFER.lock(); - if let Some(ref frame_buffer) = *lock { - use core::slice; - let frame_buffer_data = unsafe { - slice::from_raw_parts_mut( - frame_buffer.base_addr() as *mut u8, - frame_buffer.framebuffer_size(), - ) - }; - frame_buffer_data.copy_from_slice(&_buf); - Ok(frame_buffer.framebuffer_size()) + info!( + "fbdev read_at: offset={:#x} buf_len={:#x}", + offset, + buf.len() + ); + if let Some(fb) = FRAME_BUFFER.read().as_ref() { + Ok(fb.read_at(offset, buf)) } else { - Err(FsError::EntryNotFound) + Err(FsError::NoDevice) + } + } + fn write_at(&self, offset: usize, buf: &[u8]) -> Result { + info!( + "fbdev write_at: offset={:#x} buf_len={:#x}", + offset, + buf.len() + ); + if let Some(fb) = FRAME_BUFFER.write().as_mut() { + let count = fb.write_at(offset, buf); + if count == buf.len() { + Ok(count) + } else { + Err(FsError::NoDeviceSpace) + } + } else { + Err(FsError::NoDevice) } } fn poll(&self) -> Result { @@ -41,18 +52,18 @@ impl INode for Vga { Ok(Metadata { dev: 0, inode: 0, - size: 0x24000, + size: 0, blk_size: 0, blocks: 0, atime: Timespec { sec: 0, nsec: 0 }, mtime: Timespec { sec: 0, nsec: 0 }, ctime: Timespec { sec: 0, nsec: 0 }, - type_: FileType::SymLink, - mode: 0, - nlinks: 0, + type_: FileType::CharDevice, + mode: 0o660, + nlinks: 1, uid: 0, gid: 0, - rdev: 0, + rdev: make_rdev(29, 0), }) } fn io_control(&self, cmd: u32, data: usize) -> Result<()> { @@ -62,14 +73,14 @@ impl INode for Vga { match cmd { FBIOGET_FSCREENINFO => { let fb_fix_info = unsafe { &mut *(data as *mut FbFixScreeninfo) }; - if let Some(fb) = FRAME_BUFFER.lock().as_ref() { + if let Some(fb) = FRAME_BUFFER.read().as_ref() { fb_fix_info.fill_from(&fb.fb_info); } Ok(()) } FBIOGET_VSCREENINFO => { let fb_var_info = unsafe { &mut *(data as *mut FbVarScreeninfo) }; - if let Some(fb) = FRAME_BUFFER.lock().as_ref() { + if let Some(fb) = FRAME_BUFFER.read().as_ref() { fb_var_info.fill_from(&fb.fb_info); } Ok(()) @@ -80,12 +91,35 @@ impl INode for Vga { } } } + fn mmap(&self, area: MMapArea) -> Result<()> { + let attr = MmapProt::from_bits_truncate(area.prot).to_attr(); + #[cfg(target_arch = "aarch64")] + let attr = attr.mmio(crate::arch::paging::MMIOType::NormalNonCacheable as u8); + + if let Some(fb) = FRAME_BUFFER.read().as_ref() { + if area.offset + area.end_vaddr - area.start_vaddr > fb.framebuffer_size() { + return Err(FsError::NoDeviceSpace); + } + let thread = unsafe { crate::process::current_thread() }; + thread.vm.lock().push( + area.start_vaddr, + area.end_vaddr, + attr, + Linear::new((fb.paddr() + area.offset - area.start_vaddr) as isize), + "mmap_file", + ); + Ok(()) + } else { + Err(FsError::NoDevice) + } + } fn as_any_ref(&self) -> &dyn Any { self } } #[repr(u32)] +#[allow(dead_code)] #[derive(Debug, Copy, Clone)] enum FbType { /// Packed Pixels @@ -103,6 +137,7 @@ enum FbType { } #[repr(u32)] +#[allow(dead_code)] #[derive(Debug, Copy, Clone)] enum FbVisual { /// Monochr. 1=Black 0=White diff --git a/kernel/src/fs/devfs/mod.rs b/kernel/src/fs/devfs/mod.rs new file mode 100644 index 00000000..38729d42 --- /dev/null +++ b/kernel/src/fs/devfs/mod.rs @@ -0,0 +1,9 @@ +//! Device file system mounted at /dev + +mod fbdev; +mod random; +mod stdio; + +pub use fbdev::*; +pub use random::*; +pub use stdio::*; diff --git a/kernel/src/fs/random.rs b/kernel/src/fs/devfs/random.rs similarity index 93% rename from kernel/src/fs/random.rs rename to kernel/src/fs/devfs/random.rs index 065b7931..425774e0 100644 --- a/kernel/src/fs/random.rs +++ b/kernel/src/fs/devfs/random.rs @@ -1,14 +1,13 @@ //! Implement INode for RandomINode -use alloc::{collections::vec_deque::VecDeque, string::String, sync::Arc}; +use alloc::sync::Arc; use core::any::Any; use rcore_fs::vfs::*; -use crate::sync::Condvar; use crate::sync::SpinNoIrqLock as Mutex; -pub struct RandomINodeData { +struct RandomINodeData { seed: u32, } diff --git a/kernel/src/fs/stdio.rs b/kernel/src/fs/devfs/stdio.rs similarity index 94% rename from kernel/src/fs/stdio.rs rename to kernel/src/fs/devfs/stdio.rs index c914c44a..368c3e0b 100644 --- a/kernel/src/fs/stdio.rs +++ b/kernel/src/fs/devfs/stdio.rs @@ -1,12 +1,11 @@ //! Implement INode for Stdin & Stdout -use alloc::{collections::vec_deque::VecDeque, string::String, sync::Arc}; +use alloc::{collections::vec_deque::VecDeque, sync::Arc}; use core::any::Any; use rcore_fs::vfs::*; -use super::ioctl::*; -use crate::process::Process; +use crate::fs::ioctl::*; use crate::sync::Condvar; use crate::sync::SpinNoIrqLock as Mutex; @@ -55,7 +54,7 @@ lazy_static! { } impl INode for Stdin { - fn read_at(&self, offset: usize, buf: &mut [u8]) -> Result { + fn read_at(&self, _offset: usize, buf: &mut [u8]) -> Result { if self.can_read() { buf[0] = self.pop() as u8; Ok(1) diff --git a/kernel/src/fs/device.rs b/kernel/src/fs/device.rs index 10f36213..f6cb6410 100644 --- a/kernel/src/fs/device.rs +++ b/kernel/src/fs/device.rs @@ -1,5 +1,7 @@ //! Implement Device +#![allow(dead_code)] + use rcore_fs::dev::*; use spin::RwLock; @@ -8,6 +10,7 @@ use crate::arch::driver::ide; #[cfg(target_arch = "aarch64")] use crate::arch::board::emmc; +#[cfg(target_arch = "aarch64")] use crate::sync::SpinNoIrqLock as Mutex; pub struct MemBuf(RwLock<&'static mut [u8]>); diff --git a/kernel/src/fs/epoll.rs b/kernel/src/fs/epoll.rs index 65380ab2..fbf74476 100644 --- a/kernel/src/fs/epoll.rs +++ b/kernel/src/fs/epoll.rs @@ -1,16 +1,13 @@ use crate::fs::FileLike; -use crate::memory::MemorySet; use crate::process::Process; -use crate::sync::{Condvar, SpinNoIrqLock}; +use crate::sync::SpinNoIrqLock; use crate::syscall::{SysError, SysResult}; use alloc::{collections::BTreeMap, collections::BTreeSet}; -use core::mem::size_of; -use core::slice; pub struct EpollInstance { pub events: BTreeMap, - pub readyList: SpinNoIrqLock>, - pub newCtlList: SpinNoIrqLock>, + pub ready_list: SpinNoIrqLock>, + pub new_ctl_list: SpinNoIrqLock>, } impl Clone for EpollInstance { @@ -20,26 +17,26 @@ impl Clone for EpollInstance { } impl EpollInstance { - pub fn new(flags: usize) -> Self { + pub fn new(_flags: usize) -> Self { return EpollInstance { events: BTreeMap::new(), - readyList: Default::default(), - newCtlList: Default::default(), + ready_list: Default::default(), + new_ctl_list: Default::default(), }; } pub fn control(&mut self, op: usize, fd: usize, event: &EpollEvent) -> SysResult { - match (op as i32) { + match op as i32 { EPollCtlOp::ADD => { self.events.insert(fd, event.clone()); - self.newCtlList.lock().insert(fd); + self.new_ctl_list.lock().insert(fd); } EPollCtlOp::MOD => { if self.events.get(&fd).is_some() { self.events.remove(&fd); self.events.insert(fd, event.clone()); - self.newCtlList.lock().insert(fd); + self.new_ctl_list.lock().insert(fd); } else { return Err(SysError::EPERM); } @@ -62,10 +59,9 @@ impl EpollInstance { #[derive(Clone, Copy)] pub struct EpollData { - ptr: u64, + _ptr: u64, } -#[repr(packed)] #[derive(Clone)] pub struct EpollEvent { pub events: u32, /* Epoll events */ diff --git a/kernel/src/fs/file.rs b/kernel/src/fs/file.rs index 705debbb..7c68f4a7 100644 --- a/kernel/src/fs/file.rs +++ b/kernel/src/fs/file.rs @@ -1,10 +1,14 @@ //! File handle for process +use crate::memory::GlobalFrameAlloc; +use crate::process::{current_thread, INodeForMap}; +use crate::syscall::MmapProt; use crate::thread; use alloc::{string::String, sync::Arc}; use core::fmt; -use rcore_fs::vfs::{FsError, INode, Metadata, PollStatus, Result}; +use rcore_fs::vfs::{FileType, FsError, INode, MMapArea, Metadata, PollStatus, Result}; +use rcore_memory::memory_set::handler::File; #[derive(Clone)] pub struct FileHandle { @@ -50,14 +54,12 @@ impl FileHandle { if !self.options.read { return Err(FsError::InvalidParam); // FIXME: => EBADF } - let mut len: usize = 0; if !self.options.nonblock { // block loop { match self.inode.read_at(offset, buf) { Ok(read_len) => { - len = read_len; - break; + return Ok(read_len); } Err(FsError::Again) => { thread::yield_now(); @@ -68,9 +70,9 @@ impl FileHandle { } } } else { - len = self.inode.read_at(offset, buf)?; + let len = self.inode.read_at(offset, buf)?; + Ok(len) } - Ok(len) } pub fn write(&mut self, buf: &[u8]) -> Result { @@ -141,6 +143,32 @@ impl FileHandle { self.inode.io_control(cmd, arg) } + pub fn mmap(&mut self, area: MMapArea) -> Result<()> { + info!("mmap file path is {}", self.path); + match self.inode.metadata()?.type_ { + FileType::File => { + let prot = MmapProt::from_bits_truncate(area.prot); + let thread = unsafe { current_thread() }; + thread.vm.lock().push( + area.start_vaddr, + area.end_vaddr, + prot.to_attr(), + File { + file: INodeForMap(self.inode.clone()), + mem_start: area.start_vaddr, + file_start: area.offset, + file_end: area.offset + area.end_vaddr - area.start_vaddr, + allocator: GlobalFrameAlloc, + }, + "mmap_file", + ); + Ok(()) + } + FileType::CharDevice => self.inode.mmap(area), + _ => Err(FsError::NotSupported), + } + } + pub fn inode(&self) -> Arc { self.inode.clone() } diff --git a/kernel/src/fs/file_like.rs b/kernel/src/fs/file_like.rs index e180f4dc..24844b24 100644 --- a/kernel/src/fs/file_like.rs +++ b/kernel/src/fs/file_like.rs @@ -4,11 +4,9 @@ use super::ioctl::*; use super::FileHandle; use crate::fs::epoll::EpollInstance; use crate::net::Socket; -use crate::sync::Condvar; use crate::syscall::{SysError, SysResult}; use alloc::boxed::Box; -use alloc::vec::Vec; -use rcore_fs::vfs::PollStatus; +use rcore_fs::vfs::{MMapArea, PollStatus}; // TODO: merge FileLike to FileHandle ? // TODO: fix dup and remove Clone @@ -24,7 +22,7 @@ impl FileLike { let len = match self { FileLike::File(file) => file.read(buf)?, FileLike::Socket(socket) => socket.read(buf).0?, - FileLike::EpollInstance(instance) => { + FileLike::EpollInstance(_) => { return Err(SysError::ENOSYS); } }; @@ -34,7 +32,7 @@ impl FileLike { let len = match self { FileLike::File(file) => file.write(buf)?, FileLike::Socket(socket) => socket.write(buf, None)?, - FileLike::EpollInstance(instance) => { + FileLike::EpollInstance(_) => { return Err(SysError::ENOSYS); } }; @@ -51,7 +49,7 @@ impl FileLike { FileLike::Socket(socket) => { socket.ioctl(request, arg1, arg2, arg3)?; } - FileLike::EpollInstance(instance) => { + FileLike::EpollInstance(_) => { return Err(SysError::ENOSYS); } } @@ -59,6 +57,13 @@ impl FileLike { } } } + pub fn mmap(&mut self, area: MMapArea) -> SysResult { + match self { + FileLike::File(file) => file.mmap(area)?, + _ => return Err(SysError::ENOSYS), + }; + Ok(0) + } pub fn poll(&self) -> Result { let status = match self { FileLike::File(file) => file.poll()?, @@ -66,20 +71,19 @@ impl FileLike { let (read, write, error) = socket.poll(); PollStatus { read, write, error } } - FileLike::EpollInstance(instance) => { + FileLike::EpollInstance(_) => { return Err(SysError::ENOSYS); } }; Ok(status) } - pub fn fcntl(&mut self, cmd: usize, arg: usize) -> SysResult { match self { FileLike::File(file) => file.fcntl(cmd, arg)?, - FileLike::Socket(socket) => { + FileLike::Socket(_) => { //TODO } - FileLike::EpollInstance(instance) => {} + FileLike::EpollInstance(_) => {} } Ok(0) } @@ -90,7 +94,7 @@ impl fmt::Debug for FileLike { match self { FileLike::File(file) => write!(f, "File({:?})", file), FileLike::Socket(socket) => write!(f, "Socket({:?})", socket), - FileLike::EpollInstance(instance) => write!(f, "EpollInstance()"), + FileLike::EpollInstance(_) => write!(f, "EpollInstance()"), } } } diff --git a/kernel/src/fs/ioctl.rs b/kernel/src/fs/ioctl.rs index 7456435f..8708db14 100644 --- a/kernel/src/fs/ioctl.rs +++ b/kernel/src/fs/ioctl.rs @@ -1,6 +1,7 @@ // for IOR and IOW: // 32bits total, command in lower 16bits, size of the parameter structure in the lower 14 bits of the upper 16 bits // higher 2 bits: 01 = write, 10 = read +#![allow(dead_code)] #[cfg(not(target_arch = "mips"))] pub const TCGETS: usize = 0x5401; diff --git a/kernel/src/fs/mod.rs b/kernel/src/fs/mod.rs index ef323014..179e4df4 100644 --- a/kernel/src/fs/mod.rs +++ b/kernel/src/fs/mod.rs @@ -1,14 +1,17 @@ use alloc::{sync::Arc, vec::Vec}; -use rcore_fs::dev::block_cache::BlockCache; use rcore_fs::vfs::*; -use rcore_fs_devfs::{special::*, DevFS}; +use rcore_fs_devfs::{ + special::{NullINode, ZeroINode}, + DevFS, +}; use rcore_fs_mountfs::MountFS; use rcore_fs_ramfs::RamFS; use rcore_fs_sfs::SimpleFileSystem; -use crate::drivers::BlockDriver; +use self::devfs::{Fbdev, RandomINode}; +pub use self::devfs::{STDIN, STDOUT}; pub use self::file::*; pub use self::file_like::*; pub use self::pipe::Pipe; @@ -18,6 +21,7 @@ pub use self::stdio::{STDIN, STDOUT}; pub use self::vga::*; pub use self::tty::TtyINode; +mod devfs; mod device; pub mod epoll; mod file; @@ -52,6 +56,8 @@ lazy_static! { let device = { #[cfg(any(target_arch = "riscv32", target_arch = "riscv64", target_arch = "x86_64"))] { + use crate::drivers::BlockDriver; + use rcore_fs::dev::block_cache::BlockCache; let driver = BlockDriver( crate::drivers::BLK_DRIVERS .read().iter() @@ -89,6 +95,7 @@ lazy_static! { devfs.add("random", Arc::new(RandomINode::new(false))).expect("failed to mknod /dev/random"); devfs.add("urandom", Arc::new(RandomINode::new(true))).expect("failed to mknod /dev/urandom"); devfs.add("tty", Arc::new(TtyINode::default())).expect("failed to mknod /dev/tty"); + devfs.add("fb0", Arc::new(Fbdev::default())).expect("failed to mknod /dev/fb0"); // mount DevFS at /dev let dev = root.find(true, "dev").unwrap_or_else(|_| { diff --git a/kernel/src/fs/pipe.rs b/kernel/src/fs/pipe.rs index 1019c4c9..c56fd65f 100644 --- a/kernel/src/fs/pipe.rs +++ b/kernel/src/fs/pipe.rs @@ -1,6 +1,6 @@ //! Implement INode for Pipe -use alloc::{collections::vec_deque::VecDeque, string::String, sync::Arc}; +use alloc::{collections::vec_deque::VecDeque, sync::Arc}; use core::any::Any; use rcore_fs::vfs::*; diff --git a/kernel/src/fs/pseudo.rs b/kernel/src/fs/pseudo.rs index 5f01a954..8ae3b4ac 100644 --- a/kernel/src/fs/pseudo.rs +++ b/kernel/src/fs/pseudo.rs @@ -1,6 +1,6 @@ //! Pseudo file system INode -use alloc::{string::String, sync::Arc, vec::Vec}; +use alloc::vec::Vec; use core::any::Any; use rcore_fs::vfs::*; @@ -50,7 +50,7 @@ impl INode for Pseudo { ctime: Timespec { sec: 0, nsec: 0 }, type_: self.type_, mode: 0, - nlinks: 0, + nlinks: 1, uid: 0, gid: 0, rdev: 0, diff --git a/kernel/src/fs/tty.rs b/kernel/src/fs/tty.rs index 0f8f2adc..d2150025 100644 --- a/kernel/src/fs/tty.rs +++ b/kernel/src/fs/tty.rs @@ -26,7 +26,6 @@ impl INode for TtyINode { error: false, }) } - fn as_any_ref(&self) -> &dyn Any { self } /// Get metadata of the INode fn metadata(&self) -> Result { @@ -47,4 +46,6 @@ impl INode for TtyINode { rdev: make_rdev(5, 0), }) } -} \ No newline at end of file + + fn as_any_ref(&self) -> &dyn Any { self } +} diff --git a/kernel/src/ipc/semary.rs b/kernel/src/ipc/semary.rs index b54511af..914ff154 100644 --- a/kernel/src/ipc/semary.rs +++ b/kernel/src/ipc/semary.rs @@ -1,12 +1,11 @@ use crate::sync::Semaphore; -use crate::sync::SpinLock as Mutex; -use alloc::{boxed::Box, collections::BTreeMap, string::String, sync::Arc, sync::Weak, vec::Vec}; +use alloc::{collections::BTreeMap, sync::Arc, sync::Weak, vec::Vec}; use core::ops::Index; use spin::RwLock; /// A System V semaphore set pub struct SemArray { - key: usize, + _key: usize, sems: Vec, } @@ -35,12 +34,12 @@ impl SemArray { } // not found, create one let mut semaphores = Vec::new(); - for i in 0..nsems { + for _ in 0..nsems { semaphores.push(Semaphore::new(0)); } // insert to global map let array = Arc::new(SemArray { - key, + _key: key, sems: semaphores, }); key2sem.insert(key, Arc::downgrade(&array)); diff --git a/kernel/src/lkm/api.rs b/kernel/src/lkm/api.rs index 72e1d1a0..eff78e79 100644 --- a/kernel/src/lkm/api.rs +++ b/kernel/src/lkm/api.rs @@ -1,7 +1,5 @@ use super::*; -use crate::lkm::manager::ModuleManager; use crate::lkm::structs::LoadedModule; -use alloc::boxed::Box; use alloc::string::String; use alloc::sync::Arc; use core::alloc::{GlobalAlloc, Layout}; @@ -10,7 +8,7 @@ use core::slice::from_raw_parts; pub fn get_module(this_module: usize) -> &'static mut LoadedModule { unsafe { let ptr = this_module as *mut LoadedModule; - &mut (*ptr) as (&'static mut LoadedModule) + &mut (*ptr) as &'static mut LoadedModule } } @@ -81,6 +79,6 @@ pub extern "C" fn lkm_api_add_kernel_symbols(start: usize, end: usize) { let symbols = unsafe { from_utf8(from_raw_parts(start as *const u8, length)) }.unwrap(); let global_lkmm = &LKM_MANAGER; let mut locked_lkmm = global_lkmm.lock(); - let mut lkmm = locked_lkmm.as_mut().unwrap(); + let lkmm = locked_lkmm.as_mut().unwrap(); lkmm.init_kernel_symbols(symbols); } diff --git a/kernel/src/lkm/kernelvm.rs b/kernel/src/lkm/kernelvm.rs index 6ef4af60..ca5d81f6 100644 --- a/kernel/src/lkm/kernelvm.rs +++ b/kernel/src/lkm/kernelvm.rs @@ -1,14 +1,10 @@ // Simple kernel memory set for kernel virtual memory use crate::arch::paging::PageTableImpl; -use crate::consts::*; use crate::memory::GlobalFrameAlloc; use crate::sync::SpinLock as Mutex; use alloc::vec::*; -use buddy_system_allocator::*; -use core::alloc::Layout; use core::mem::ManuallyDrop; use core::ops::DerefMut; -use core::ptr::NonNull; use lazy_static::lazy_static; use rcore_memory::memory_set::handler::{ByFrame, MemoryHandler}; use rcore_memory::memory_set::MemoryAttr; @@ -38,14 +34,14 @@ impl MemorySpaceManager for LinearManager { LinearManager { last_page: 0 } } fn alloc(&mut self, size: usize) -> Option<(usize, usize)> { - let mut required_pages = (size + PAGE_SIZE - 1) / PAGE_SIZE; + let required_pages = (size + PAGE_SIZE - 1) / PAGE_SIZE; let current = self.last_page * PAGE_SIZE + KSEG2_START; self.last_page += required_pages; Some((current, required_pages * PAGE_SIZE)) } - fn free(&mut self, (addr, size): (usize, usize)) { + fn free(&mut self, (_addr, _size): (usize, usize)) { //Do nothing. } } @@ -99,7 +95,7 @@ impl VirtualSpace { impl Drop for VirtualSpace { fn drop(&mut self) { - for mut v in self.areas.iter_mut() { + for v in self.areas.iter_mut() { v.unmap(self.allocator, &mut self.page_allocator); } } @@ -108,7 +104,7 @@ impl Drop for VirtualSpace { pub struct VirtualArea { start: usize, end: usize, - attr: MemoryAttr, + _attr: MemoryAttr, } impl VirtualArea { @@ -119,7 +115,7 @@ impl VirtualArea { parent: &mut VirtualSpace, ) -> VirtualArea { let aligned_start_addr = page_addr - page_addr % PAGE_SIZE; - let mut aligned_end = (page_addr + size + PAGE_SIZE - 1); + let mut aligned_end = page_addr + size + PAGE_SIZE - 1; aligned_end = aligned_end - aligned_end % PAGE_SIZE; let lock = parent.allocator.lock(); let mut active_pt = lock.kernel_table(); @@ -132,7 +128,7 @@ impl VirtualArea { VirtualArea { start: aligned_start_addr, end: aligned_end, - attr: attr.clone(), + _attr: attr.clone(), } } pub fn unmap(&mut self, allocator: &LockedVMM, parent: &mut ByFrame) { diff --git a/kernel/src/lkm/manager.rs b/kernel/src/lkm/manager.rs index d81c67e9..6c9a924d 100644 --- a/kernel/src/lkm/manager.rs +++ b/kernel/src/lkm/manager.rs @@ -2,36 +2,26 @@ use super::api::*; use super::const_reloc as loader; use super::kernelvm::*; use super::structs::*; -use crate::consts::*; use crate::lkm::structs::ModuleState::{Ready, Unloading}; -use crate::memory::GlobalFrameAlloc; -use crate::sync::{Condvar, SpinLock as Mutex}; +use crate::sync::SpinLock as Mutex; use crate::syscall::SysError::*; use crate::syscall::SysResult; use alloc::boxed::Box; use alloc::collections::btree_map::BTreeMap; -use alloc::prelude::*; use alloc::string::*; use alloc::sync::Arc; use alloc::vec::*; -use core::borrow::BorrowMut; use core::mem::transmute; -use core::slice; use lazy_static::lazy_static; -use rcore_memory::memory_set::handler::{ByFrame, MemoryHandler}; use rcore_memory::memory_set::MemoryAttr; -use rcore_memory::{Page, PAGE_SIZE}; +use rcore_memory::PAGE_SIZE; use xmas_elf::dynamic::Tag; use xmas_elf::program::Type::Load; use xmas_elf::sections::SectionData; use xmas_elf::sections::SectionData::{DynSymbolTable64, Dynamic64, Undefined}; use xmas_elf::symbol_table::DynEntry64; use xmas_elf::symbol_table::Entry; -use xmas_elf::{ - header, - program::{Flags, Type}, - ElfFile, -}; +use xmas_elf::{header, ElfFile}; // The symbol data table. global_asm!(include_str!("symbol_table.asm")); @@ -96,15 +86,15 @@ impl ModuleManager { return; } use compression::prelude::*; - let zipped_symbols = - unsafe { slice::from_raw_parts(symbol_table_start as *const u8, symbol_table_len) } - .to_vec(); + let zipped_symbols = unsafe { + core::slice::from_raw_parts(symbol_table_start as *const u8, symbol_table_len) + } + .to_vec(); let real_symbols = zipped_symbols .decode(&mut GZipDecoder::new()) .collect::, _>>() .unwrap(); - use core::slice; use core::str::from_utf8; self.init_kernel_symbols(from_utf8(&real_symbols).unwrap()); } @@ -113,7 +103,7 @@ impl ModuleManager { for l in lines.into_iter() { let mut words = l.split_whitespace(); let address = words.next().unwrap(); - let stype = words.next().unwrap(); + let _stype = words.next().unwrap(); let name = words.next().unwrap(); // Simply add the symbol into stub. self.stub_symbols.insert( @@ -170,7 +160,7 @@ impl ModuleManager { Some(base + (selected_symbol.value() as usize)) } } - pub fn init_module(&mut self, module_image: &[u8], param_values: &str) -> SysResult { + pub fn init_module(&mut self, module_image: &[u8], _param_values: &str) -> SysResult { let elf = ElfFile::new(module_image).expect("[LKM] failed to read elf"); let is32 = match elf.header.pt2 { header::HeaderPt2::Header32(_) => true, @@ -299,7 +289,7 @@ impl ModuleManager { if flags.is_execute() { attr = attr.execute(); } - let area_ref = vspace_ref.add_area(prog_start_addr, prog_end_addr, &attr); + let _area_ref = vspace_ref.add_area(prog_start_addr, prog_end_addr, &attr); //self.vallocator.map_pages(prog_start_addr, prog_end_addr, &attr); //No need to flush TLB. let target = unsafe { @@ -497,7 +487,7 @@ impl ModuleManager { fn reloc_symbols( &mut self, elf: &ElfFile, - (start, total_size, single_size): (usize, usize, usize), + (start, total_size, _single_size): (usize, usize, usize), base: usize, dynsym: &[DynEntry64], this_module: usize, @@ -511,8 +501,8 @@ impl ModuleManager { match s.get_data(elf).unwrap() { SectionData::Rela64(rela_items) => { for item in rela_items.iter() { - let mut addend = item.get_addend() as usize; - let mut reloc_addr = item.get_offset() as usize; + let addend = item.get_addend() as usize; + let reloc_addr = item.get_offset() as usize; let sti = item.get_symbol_table_index() as usize; let itype = item.get_type() as usize; self.relocate_single_symbol( @@ -529,8 +519,8 @@ impl ModuleManager { } SectionData::Rel64(rel_items) => { for item in rel_items.iter() { - let mut addend = 0 as usize; - let mut reloc_addr = item.get_offset() as usize; + let addend = 0 as usize; + let reloc_addr = item.get_offset() as usize; let sti = item.get_symbol_table_index() as usize; let itype = item.get_type() as usize; self.relocate_single_symbol( @@ -554,7 +544,7 @@ impl ModuleManager { } } } - pub fn delete_module(&mut self, name: &str, flags: u32) -> SysResult { + pub fn delete_module(&mut self, name: &str, _flags: u32) -> SysResult { //unimplemented!("[LKM] You can't plug out what's INSIDE you, RIGHT?"); info!("[LKM] now you can plug out a kernel module!"); @@ -589,7 +579,7 @@ impl ModuleManager { } drop(mod_lock); - let my_box = self.loaded_modules.remove(i); + let _my_box = self.loaded_modules.remove(i); unsafe { LKM_MANAGER.force_unlock(); } @@ -607,7 +597,7 @@ impl ModuleManager { pub fn with(f: impl FnOnce(&mut ModuleManager) -> T) -> T { let global_lkmm: &Mutex> = &LKM_MANAGER; let mut locked_lkmm = global_lkmm.lock(); - let mut lkmm = locked_lkmm.as_mut().unwrap(); + let lkmm = locked_lkmm.as_mut().unwrap(); f(lkmm) } pub fn init() { diff --git a/kernel/src/memory.rs b/kernel/src/memory.rs index 4868823b..203f94a5 100644 --- a/kernel/src/memory.rs +++ b/kernel/src/memory.rs @@ -155,7 +155,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 _ in 0..16384 { let page = alloc_frame().unwrap(); let va = va_offset + page; if addr_len > 0 { diff --git a/kernel/src/net/structs.rs b/kernel/src/net/structs.rs index db18357a..2141293e 100644 --- a/kernel/src/net/structs.rs +++ b/kernel/src/net/structs.rs @@ -197,7 +197,7 @@ impl Socket for TcpSocketState { }) } - fn write(&self, data: &[u8], sendto_endpoint: Option) -> SysResult { + fn write(&self, data: &[u8], _sendto_endpoint: Option) -> SysResult { let mut sockets = SOCKETS.lock(); let mut socket = sockets.get::(self.handle.0); @@ -212,7 +212,7 @@ impl Socket for TcpSocketState { poll_ifaces(); Ok(size) } - Err(err) => Err(SysError::ENOBUFS), + Err(_) => Err(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(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 => { @@ -710,7 +710,7 @@ impl PacketSocketState { } impl Socket for PacketSocketState { - fn read(&self, data: &mut [u8]) -> (SysResult, Endpoint) { + fn read(&self, _data: &mut [u8]) -> (SysResult, Endpoint) { unimplemented!() } diff --git a/kernel/src/net/test.rs b/kernel/src/net/test.rs index 9e0633a3..3ee11882 100644 --- a/kernel/src/net/test.rs +++ b/kernel/src/net/test.rs @@ -73,7 +73,7 @@ pub extern "C" fn server(_arg: usize) -> ! { if socket.can_recv() { let mut data = [0u8; 2048]; - let size = socket.recv_slice(&mut data).unwrap(); + let _size = socket.recv_slice(&mut data).unwrap(); } } } diff --git a/kernel/src/process/structs.rs b/kernel/src/process/structs.rs index 17427e62..f416feda 100644 --- a/kernel/src/process/structs.rs +++ b/kernel/src/process/structs.rs @@ -25,6 +25,7 @@ use crate::process::thread_manager; use core::mem::MaybeUninit; use rcore_fs::vfs::INode; +#[allow(dead_code)] pub struct Thread { context: Context, kstack: KernelStack, @@ -102,10 +103,11 @@ impl rcore_thread::Context for Thread { impl Thread { /// Make a struct for the init thread pub unsafe fn new_init() -> Box { + let zero = MaybeUninit::::zeroed(); Box::new(Thread { context: Context::null(), // safety: other fields will never be used - ..core::mem::MaybeUninit::zeroed().assume_init() + ..zero.assume_init() }) } @@ -143,8 +145,8 @@ impl Thread { /// Return `(MemorySet, entry_point, ustack_top)` pub fn new_user_vm( inode: &Arc, - exec_path: &str, - mut args: Vec, + _exec_path: &str, + args: Vec, envs: Vec, ) -> Result<(MemorySet, usize, usize), &'static str> { // Read ELF header @@ -385,12 +387,7 @@ impl Process { let mut process_table = PROCESSES.write(); // assign pid - let pid = (0..) - .find(|i| match process_table.get(i) { - Some(p) => false, - _ => true, - }) - .unwrap(); + let pid = (0..).find(|i| process_table.get(i).is_none()).unwrap(); self.pid = Pid(pid); // put to process table diff --git a/kernel/src/sync/condvar.rs b/kernel/src/sync/condvar.rs index 22ca8f63..900abbe6 100644 --- a/kernel/src/sync/condvar.rs +++ b/kernel/src/sync/condvar.rs @@ -1,6 +1,6 @@ use super::*; +use crate::process::thread_manager; use crate::process::Process; -use crate::process::{current_thread, thread_manager}; use crate::thread; use alloc::collections::VecDeque; use alloc::sync::Arc; @@ -44,7 +44,7 @@ impl Condvar { } /// Wait for condvar until condition() returns Some - pub fn wait_event(condvar: &Condvar, mut condition: impl FnMut() -> Option) -> T { + pub fn wait_event(condvar: &Condvar, condition: impl FnMut() -> Option) -> T { Self::wait_events(&[condvar], condition) } @@ -60,7 +60,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); } thread_manager().sleep(tid, 0); @@ -162,13 +162,13 @@ impl Condvar { let epoll_list = self.epoll_queue.lock(); for ist in epoll_list.iter() { if thread.id() == ist.tid { - let mut proc = ist.proc.lock(); + let proc = ist.proc.lock(); match proc.get_epoll_instance(ist.epfd) { Ok(instacne) => { - let mut readylist = instacne.readyList.lock(); - readylist.insert(ist.fd); + let mut ready_list = instacne.ready_list.lock(); + ready_list.insert(ist.fd); } - Err(r) => { + Err(_) => { panic!("epoll instance not exist"); } } diff --git a/kernel/src/sync/mod.rs b/kernel/src/sync/mod.rs index 7e16fe06..8f52efe5 100644 --- a/kernel/src/sync/mod.rs +++ b/kernel/src/sync/mod.rs @@ -17,9 +17,6 @@ //! 完全照搬`std::sync::Semaphore`,std中已经废弃。 //! 貌似在Rust中并不常用,一般都用`Mutex`。 //! -//! * `mpsc`: 消息传递通道。 -//! 多生产者-单消费者的FIFO队列。用于在线程间传递数据。 -//! //! * `test`: 测试。 //! 目前分别用`Mutex`和`Condvar`(Monitor)实现了哲学家就餐问题。 //! @@ -55,7 +52,6 @@ pub use self::mutex::*; pub use self::semaphore::*; mod condvar; -pub mod mpsc; mod mutex; mod semaphore; pub mod test; diff --git a/kernel/src/sync/mpsc.rs b/kernel/src/sync/mpsc.rs deleted file mode 100644 index 0a9159e7..00000000 --- a/kernel/src/sync/mpsc.rs +++ /dev/null @@ -1,145 +0,0 @@ -use super::Condvar; -use super::SpinLock as Mutex; -use alloc::{collections::VecDeque, sync::Arc, sync::Weak}; - -struct Channel { - deque: Mutex>, - pushed: Condvar, -} - -impl Default for Channel { - fn default() -> Self { - Channel { - deque: Mutex::<_>::default(), - pushed: Condvar::default(), - } - } -} - -/// The receiving half of Rust's channel (or sync_channel) type. -/// This half can only be owned by one thread. -/// -/// Messages sent to the channel can be retrieved using recv. -pub struct Receiver { - inner: Arc>, -} - -unsafe impl Send for Receiver {} - -impl !Sync for Receiver {} - -#[derive(Debug)] -pub struct RecvError; - -impl Receiver { - /// Attempts to wait for a value on this receiver, - /// returning an error if the corresponding channel has hung up. - pub fn recv(&self) -> Result { - let mut deque = self.inner.deque.lock(); - while deque.is_empty() { - deque = self.inner.pushed.wait(deque); - } - Ok(deque.pop_front().unwrap()) - } -} - -/// The sending-half of Rust's asynchronous channel type. -/// This half can only be owned by one thread, but it can be cloned to send to other threads. -/// -/// Messages can be sent through this channel with send. -#[derive(Clone)] -pub struct Sender { - inner: Weak>, -} - -unsafe impl Send for Sender {} - -impl !Sync for Sender {} - -#[derive(Debug)] -pub struct SendError(pub T); - -impl Sender { - /// Attempts to send a value on this channel, - /// returning it back if it could not be sent. - pub fn send(&self, t: T) -> Result<(), SendError> { - match self.inner.upgrade() { - None => Err(SendError(t)), - Some(inner) => { - let mut deque = inner.deque.lock(); - deque.push_back(t); - inner.pushed.notify_one(); - Ok(()) - } - } - } -} - -/// Creates a new asynchronous channel, returning the sender/receiver halves. -pub fn channel() -> (Sender, Receiver) { - let channel = Arc::new(Channel::::default()); - let sender = Sender { - inner: Arc::downgrade(&channel), - }; - let receiver = Receiver { inner: channel }; - (sender, receiver) -} - -pub mod test { - //! Copied from std::mpsc::test - - use super::*; - use crate::thread; - use alloc::boxed::Box; - - fn smoke() { - let (tx, rx) = channel::(); - tx.send(1).unwrap(); - assert_eq!(rx.recv().unwrap(), 1); - } - - fn drop_full() { - let (tx, _rx) = channel::>(); - tx.send(Box::new(1)).unwrap(); - } - - fn drop_full_shared() { - let (tx, _rx) = channel::>(); - drop(tx.clone()); - drop(tx.clone()); - tx.send(Box::new(1)).unwrap(); - } - - fn smoke_shared() { - let (tx, rx) = channel::(); - tx.send(1).unwrap(); - assert_eq!(rx.recv().unwrap(), 1); - let tx = tx.clone(); - tx.send(1).unwrap(); - assert_eq!(rx.recv().unwrap(), 1); - } - - fn smoke_threads() { - let (tx, rx) = channel::(); - let _t = thread::spawn(move || { - tx.send(1).unwrap(); - }); - assert_eq!(rx.recv().unwrap(), 1); - } - - fn smoke_port_gone() { - let (tx, rx) = channel::(); - drop(rx); - assert!(tx.send(1).is_err()); - } - - pub fn test_all() { - smoke(); - drop_full(); - drop_full_shared(); - smoke_shared(); - smoke_threads(); - smoke_port_gone(); - println!("mpsc test end"); - } -} diff --git a/kernel/src/sync/semaphore.rs b/kernel/src/sync/semaphore.rs index be7927c4..b4947151 100644 --- a/kernel/src/sync/semaphore.rs +++ b/kernel/src/sync/semaphore.rs @@ -64,7 +64,7 @@ impl Semaphore { /// Get the current count pub fn get(&self) -> isize { - let mut count = self.lock.lock(); + let count = self.lock.lock(); *count } diff --git a/kernel/src/syscall/custom.rs b/kernel/src/syscall/custom.rs index 08253f14..52259649 100644 --- a/kernel/src/syscall/custom.rs +++ b/kernel/src/syscall/custom.rs @@ -1,7 +1,5 @@ //! Custom nonstandard syscalls use super::*; -use rcore_memory::memory_set::handler::Linear; -use rcore_memory::memory_set::MemoryAttr; impl Syscall<'_> { /// Allocate this PCI device to user space @@ -9,6 +7,9 @@ impl Syscall<'_> { #[cfg(target_arch = "x86_64")] pub fn sys_map_pci_device(&mut self, vendor: usize, product: usize) -> SysResult { use crate::drivers::bus::pci; + use rcore_memory::memory_set::handler::Linear; + use rcore_memory::memory_set::MemoryAttr; + info!( "map_pci_device: vendor: {:x}, product: {:x}", vendor, product @@ -35,7 +36,7 @@ impl Syscall<'_> { } #[cfg(not(target_arch = "x86_64"))] - pub fn sys_map_pci_device(&mut self, vendor: usize, product: usize) -> SysResult { + pub fn sys_map_pci_device(&mut self, _vendor: usize, _product: usize) -> SysResult { Err(SysError::ENOSYS) } diff --git a/kernel/src/syscall/fs.rs b/kernel/src/syscall/fs.rs index c722127d..73e59770 100644 --- a/kernel/src/syscall/fs.rs +++ b/kernel/src/syscall/fs.rs @@ -1,4 +1,7 @@ //! Syscalls for file system + +#![allow(dead_code)] + use core::cell::UnsafeCell; use core::cmp::min; use core::mem::size_of; @@ -8,18 +11,14 @@ use rcore_fs::vfs::Timespec; use crate::drivers::SOCKET_ACTIVITY; use crate::fs::*; use crate::memory::MemorySet; -use crate::sync::{Condvar, SpinNoIrqLock}; +use crate::sync::Condvar; use crate::trap::TICK_ACTIVITY; -use alloc::{collections::BTreeMap, collections::BTreeSet}; -use bitvec::prelude::{BitSlice, BitVec, LittleEndian}; +use bitvec::prelude::{BitSlice, BitVec, Lsb0}; use super::*; use crate::fs::epoll::EpollInstance; -use crate::net::server; use crate::process::Process; -use alloc::collections::VecDeque; -use bitflags::_core::task::Poll; use rcore_fs::vfs::PollStatus; impl Syscall<'_> { @@ -110,7 +109,7 @@ impl Syscall<'_> { } // check whether the fds is valid and is owned by this process - let mut condvars = alloc::vec![&(*TICK_ACTIVITY), &STDIN.pushed, &(*SOCKET_ACTIVITY)]; + let condvars = alloc::vec![&(*TICK_ACTIVITY), &STDIN.pushed, &(*SOCKET_ACTIVITY)]; let polls = unsafe { self.vm().check_write_array(ufds, nfds)? }; @@ -202,7 +201,7 @@ impl Syscall<'_> { 1 << 31 }; - let mut condvars = alloc::vec![&(*TICK_ACTIVITY), &STDIN.pushed, &(*SOCKET_ACTIVITY)]; + let condvars = alloc::vec![&(*TICK_ACTIVITY), &STDIN.pushed, &(*SOCKET_ACTIVITY)]; // for debugging if cfg!(debug_assertions) { @@ -272,8 +271,8 @@ impl Syscall<'_> { pub fn sys_epoll_create1(&mut self, flags: usize) -> SysResult { info!("epoll_create1: flags: {:?}", flags); let mut proc = self.process(); - let epollInstance = EpollInstance::new(flags); - let fd = proc.add_file(FileLike::EpollInstance(epollInstance)); + let epoll_instance = EpollInstance::new(flags); + let fd = proc.add_file(FileLike::EpollInstance(epoll_instance)); Ok(fd) } @@ -296,14 +295,14 @@ impl Syscall<'_> { return Err(SysError::EPERM); } - let epollInstance = match proc.get_epoll_instance_mut(epfd) { + let epoll_instance = match proc.get_epoll_instance_mut(epfd) { Ok(ins) => ins, Err(err) => { return Err(err); } }; - let ret = epollInstance.control(op, fd, &_event)?; + let ret = epoll_instance.control(op, fd, &_event)?; return Ok(ret); } @@ -323,26 +322,26 @@ impl Syscall<'_> { events: *mut EpollEvent, maxevents: usize, timeout_msecs: usize, - sigset_t: usize, + _sigset_t: usize, ) -> SysResult { info!("epoll_pwait: epfd: {}, timeout: {:?}", epfd, timeout_msecs); - let mut proc = self.process(); + let proc = self.process(); let events = unsafe { self.vm().check_write_array(events, maxevents)? }; - let epollInstance = proc.get_epoll_instance(epfd)?; + let epoll_instance = proc.get_epoll_instance(epfd)?; // add new fds which are registered by epoll_ctl after latest epoll_pwait - epollInstance.readyList.lock().clear(); - epollInstance - .readyList + epoll_instance.ready_list.lock().clear(); + epoll_instance + .ready_list .lock() - .extend(epollInstance.newCtlList.lock().clone()); - epollInstance.newCtlList.lock().clear(); + .extend(epoll_instance.new_ctl_list.lock().clone()); + epoll_instance.new_ctl_list.lock().clear(); // if registered fd has data to handle and its mode isn't epollet, we need // to add it to the list. - let keys: Vec<_> = epollInstance.events.keys().cloned().collect(); - for (k, v) in epollInstance.events.iter() { + let keys: Vec<_> = epoll_instance.events.keys().cloned().collect(); + for (k, v) in epoll_instance.events.iter() { if !v.contains(EpollEvent::EPOLLET) { match &proc.files.get(k) { None => { @@ -351,8 +350,8 @@ impl Syscall<'_> { Some(file_like) => { let status = file_like.poll()?; if status.write || status.read || status.error { - let mut readylist = epollInstance.readyList.lock(); - readylist.insert(*k); + let mut ready_list = epoll_instance.ready_list.lock(); + ready_list.insert(*k); } } } @@ -362,11 +361,11 @@ impl Syscall<'_> { let mut callbacks = alloc::vec![]; for fd in &keys { - let mut proc = self.process(); + let proc = self.process(); match proc.files.get(&fd) { Some(file_like) => { match file_like { - FileLike::File(file) => { + FileLike::File(_file) => { &crate::fs::STDIN.pushed.register_epoll_list( self.thread.proc.clone(), thread::current().id(), @@ -375,7 +374,7 @@ impl Syscall<'_> { ); callbacks.push((0, thread::current().id(), epfd, *fd)); } - FileLike::Socket(socket) => { + FileLike::Socket(_socket) => { &(*crate::drivers::SOCKET_ACTIVITY).register_epoll_list( self.thread.proc.clone(), thread::current().id(), @@ -384,7 +383,7 @@ impl Syscall<'_> { ); callbacks.push((1, thread::current().id(), epfd, *fd)); } - FileLike::EpollInstance(instance) => { + FileLike::EpollInstance(_) => { return Err(SysError::EINVAL); } }; @@ -394,23 +393,22 @@ impl Syscall<'_> { drop(proc); } - let mut condvars = alloc::vec![&(*TICK_ACTIVITY), &STDIN.pushed, &(*SOCKET_ACTIVITY)]; + let condvars = alloc::vec![&(*TICK_ACTIVITY), &STDIN.pushed, &(*SOCKET_ACTIVITY)]; let begin_time_ms = crate::trap::uptime_msec(); let condition = move || { - use PollEvents as PE; let mut proc = self.process(); - let epollInstance = match proc.get_epoll_instance_mut(epfd) { + let epoll_instance = match proc.get_epoll_instance_mut(epfd) { Ok(ins) => ins, Err(err) => { return Some(Err(err)); } }; - let readylist = epollInstance.readyList.lock().clone(); + let ready_list = epoll_instance.ready_list.lock().clone(); let mut events_num = 0; - for infd in readylist.iter() { + for infd in ready_list.iter() { let mut status: PollStatus = Default::default(); { if let Some(file_like) = proc.files.get(&infd) { @@ -425,13 +423,13 @@ impl Syscall<'_> { } { - let epollInstance = match proc.get_epoll_instance_mut(epfd) { + let epoll_instance = match proc.get_epoll_instance_mut(epfd) { Ok(ins) => ins, Err(err) => { return Some(Err(err)); } }; - let epollevent = epollInstance.events.get_mut(&infd)?; + let epollevent = epoll_instance.events.get_mut(&infd)?; if status.error { events[events_num].events = EpollEvent::EPOLLERR; @@ -454,13 +452,13 @@ impl Syscall<'_> { } { - let epollInstance = match proc.get_epoll_instance_mut(epfd) { + let epoll_instance = match proc.get_epoll_instance_mut(epfd) { Ok(ins) => ins, Err(err) => { return Some(Err(err)); } }; - epollInstance.readyList.lock().clear(); + epoll_instance.ready_list.lock().clear(); } drop(proc); @@ -611,7 +609,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) } @@ -1150,10 +1148,6 @@ impl Process { "/proc/self/exe" => { return Ok(Arc::new(Pseudo::new(&self.exec_path, FileType::SymLink))); } - "/dev/fb0" => { - info!("/dev/fb0 will be opened"); - return Ok(Arc::new(Vga::default())); - } _ => {} } let (fd_dir_path, fd_name) = split_path(&path); @@ -1579,7 +1573,7 @@ impl From for Stat { nlink: info.nlinks as u32, uid: info.uid as u32, gid: info.gid as u32, - rdev: 0, + rdev: info.rdev as u64, size: info.size as u64, blksize: info.blk_size as u32, blocks: info.blocks as u64, @@ -1610,7 +1604,7 @@ impl From for Stat { nlink: info.nlinks as u32, uid: info.uid as u32, gid: info.gid as u32, - rdev: 0, + rdev: info.rdev as u64, size: info.size as u64, blksize: info.blk_size as u32, blocks: info.blocks as u64, @@ -1729,8 +1723,8 @@ const FD_PER_ITEM: usize = 8 * size_of::(); const MAX_FDSET_SIZE: usize = 1024 / FD_PER_ITEM; struct FdSet { - bitset: &'static mut BitSlice, - origin: BitVec, + bitset: &'static mut BitSlice, + origin: BitVec, } impl FdSet { @@ -1748,7 +1742,7 @@ impl FdSet { return Err(SysError::EINVAL); } let slice = unsafe { vm.check_write_array(addr, len)? }; - let bitset: &'static mut BitSlice = slice.into(); + let bitset: &'static mut BitSlice = slice.into(); debug!("bitset {:?}", bitset); // save the fdset, and clear it diff --git a/kernel/src/syscall/ipc.rs b/kernel/src/syscall/ipc.rs index c9956f3b..348ae984 100644 --- a/kernel/src/syscall/ipc.rs +++ b/kernel/src/syscall/ipc.rs @@ -1,9 +1,6 @@ -use crate::sync::Semaphore; -use crate::sync::SpinLock as Mutex; -use alloc::{boxed::Box, collections::BTreeMap, string::String, sync::Arc, sync::Weak, vec::Vec}; +#![allow(dead_code)] + use bitflags::*; -use core::cell::UnsafeCell; -use spin::RwLock; pub use crate::ipc::*; diff --git a/kernel/src/syscall/lkm.rs b/kernel/src/syscall/lkm.rs index 9941feba..c3abe4c6 100644 --- a/kernel/src/syscall/lkm.rs +++ b/kernel/src/syscall/lkm.rs @@ -1,8 +1,5 @@ use crate::lkm::manager::ModuleManager; -use crate::sync::Mutex; use crate::syscall::{check_and_clone_cstr, SysResult, Syscall}; -use alloc::collections::btree_map::BTreeMap; -use compression::prelude::Action; impl Syscall<'_> { pub fn sys_init_module( @@ -11,7 +8,7 @@ impl Syscall<'_> { len: usize, param_values: *const u8, ) -> SysResult { - let mut proc = self.process(); + let _proc = self.process(); let modimg = unsafe { self.vm().check_read_array(module_image, len)? }; let copied_param_values = check_and_clone_cstr(param_values)?; @@ -19,7 +16,7 @@ impl Syscall<'_> { } pub fn sys_delete_module(&mut self, module_name: *const u8, flags: u32) -> SysResult { - let mut proc = self.process(); + let _proc = self.process(); let copied_modname = check_and_clone_cstr(module_name)?; info!("[LKM] Removing module {:?}", copied_modname); let ret = ModuleManager::with(|kmm| kmm.delete_module(&copied_modname, flags)); diff --git a/kernel/src/syscall/mem.rs b/kernel/src/syscall/mem.rs index 247182b8..48115a53 100644 --- a/kernel/src/syscall/mem.rs +++ b/kernel/src/syscall/mem.rs @@ -1,15 +1,15 @@ -use rcore_memory::memory_set::handler::{Delay, File, Linear}; +use rcore_fs::vfs::MMapArea; +use rcore_memory::memory_set::handler::Delay; use rcore_memory::memory_set::MemoryAttr; use rcore_memory::PAGE_SIZE; -use crate::memory::GlobalFrameAlloc; - use super::*; +use crate::memory::GlobalFrameAlloc; impl Syscall<'_> { pub fn sys_mmap( &mut self, - mut addr: usize, + addr: usize, len: usize, prot: usize, flags: usize, @@ -24,6 +24,7 @@ impl Syscall<'_> { ); let mut proc = self.process(); + let mut addr = addr; if addr == 0 { // although NULL can be a valid address // but in C, NULL is regarded as allocation failure @@ -49,49 +50,18 @@ impl Syscall<'_> { Delay::new(GlobalFrameAlloc), "mmap_anon", ); - return Ok(addr); + Ok(addr) } else { - let file = proc.get_file(fd)?; - info!("mmap path is {} ", &*file.path); - match &*file.path { - "/dev/fb0" => { - use crate::drivers::gpu::fb::FRAME_BUFFER; - let attr = prot.to_attr(); - #[cfg(feature = "board_raspi3")] - let attr = attr.mmio(crate::arch::paging::MMIOType::NormalNonCacheable as u8); - - if let Some(fb) = FRAME_BUFFER.lock().as_ref() { - self.vm().push( - addr, - addr + len, - attr, - Linear::new((fb.paddr() - addr) as isize), - "mmap_file", - ); - info!("mmap for /dev/fb0"); - return Ok(addr); - } else { - return Err(SysError::ENOENT); - } - } - _ => { - let inode = file.inode(); - self.vm().push( - addr, - addr + len, - prot.to_attr(), - File { - file: INodeForMap(inode), - mem_start: addr, - file_start: offset, - file_end: offset + len, - allocator: GlobalFrameAlloc, - }, - "mmap_file", - ); - return Ok(addr); - } + let file_like = proc.get_file_like(fd)?; + let area = MMapArea { + start_vaddr: addr, + end_vaddr: addr + len, + prot: prot.bits(), + flags: flags.bits(), + offset, }; + file_like.mmap(area)?; + Ok(addr) } } @@ -101,7 +71,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 @@ -121,6 +91,7 @@ impl Syscall<'_> { Ok(0) } } + bitflags! { pub struct MmapProt: usize { /// Data cannot be accessed @@ -163,7 +134,7 @@ bitflags! { } impl MmapProt { - fn to_attr(self) -> MemoryAttr { + pub fn to_attr(self) -> MemoryAttr { let mut attr = MemoryAttr::default().user(); if self.contains(MmapProt::EXEC) { attr = attr.execute(); diff --git a/kernel/src/syscall/misc.rs b/kernel/src/syscall/misc.rs index 3d2ea123..99873631 100644 --- a/kernel/src/syscall/misc.rs +++ b/kernel/src/syscall/misc.rs @@ -1,3 +1,5 @@ +#![allow(dead_code)] + use super::*; use crate::arch::cpu; use crate::consts::USER_STACK_SIZE; diff --git a/kernel/src/syscall/mod.rs b/kernel/src/syscall/mod.rs index a158fddc..b6022749 100644 --- a/kernel/src/syscall/mod.rs +++ b/kernel/src/syscall/mod.rs @@ -406,7 +406,7 @@ impl Syscall<'_> { SYS_PIPE => { let fd_ptr = args[0] as *mut u32; match self.sys_pipe(fd_ptr) { - Ok(code) => { + Ok(_code) => { unsafe { self.tf.v0 = *fd_ptr as usize; self.tf.v1 = *(fd_ptr.add(1)) as usize; diff --git a/kernel/src/syscall/net.rs b/kernel/src/syscall/net.rs index 3197ab70..edc7f164 100644 --- a/kernel/src/syscall/net.rs +++ b/kernel/src/syscall/net.rs @@ -519,15 +519,15 @@ enum_with_unknown! { } } -const IPPROTO_IP: usize = 0; -const IPPROTO_ICMP: usize = 1; -const IPPROTO_TCP: usize = 6; +pub const IPPROTO_IP: usize = 0; +pub const IPPROTO_ICMP: usize = 1; +pub const IPPROTO_TCP: usize = 6; -const SOL_SOCKET: usize = 1; -const SO_SNDBUF: usize = 7; -const SO_RCVBUF: usize = 8; -const SO_LINGER: usize = 13; +pub const SOL_SOCKET: usize = 1; +pub const SO_SNDBUF: usize = 7; +pub const SO_RCVBUF: usize = 8; +pub const SO_LINGER: usize = 13; -const TCP_CONGESTION: usize = 13; +pub const TCP_CONGESTION: usize = 13; -const IP_HDRINCL: usize = 3; +pub const IP_HDRINCL: usize = 3; diff --git a/kernel/src/syscall/proc.rs b/kernel/src/syscall/proc.rs index 6a79aabd..be0c4684 100644 --- a/kernel/src/syscall/proc.rs +++ b/kernel/src/syscall/proc.rs @@ -13,6 +13,7 @@ impl Syscall<'_> { Ok(pid) } + #[cfg(target_arch = "x86_64")] pub fn sys_vfork(&mut self) -> SysResult { self.sys_fork() } diff --git a/kernel/src/syscall/time.rs b/kernel/src/syscall/time.rs index 5cb4bffe..4fc16218 100644 --- a/kernel/src/syscall/time.rs +++ b/kernel/src/syscall/time.rs @@ -29,6 +29,7 @@ impl Syscall<'_> { Ok(0) } + #[cfg(target_arch = "x86_64")] pub fn sys_time(&mut self, time: *mut u64) -> SysResult { let sec = get_epoch_usec() / USEC_PER_SEC; if time as usize != 0 { @@ -64,7 +65,7 @@ impl Syscall<'_> { info!("times: buf: {:?}", buf); let buf = unsafe { self.vm().check_write_ptr(buf)? }; - let tick_base = *TICK_BASE; + let _tick_base = *TICK_BASE; let tick = unsafe { crate::trap::TICK as u64 }; let new_buf = Tms { diff --git a/rust-toolchain b/rust-toolchain index 17841400..8bd4ff0a 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -nightly-2020-01-17 +nightly-2020-04-06 diff --git a/user b/user index 0aeea8f9..bb156ac8 160000 --- a/user +++ b/user @@ -1 +1 @@ -Subproject commit 0aeea8f956884e8cfecb73a02fdaa5c287ae1b9d +Subproject commit bb156ac8b60a4223da9871f7bfbd883f68f5b284