From 63e2a835e069f581a2fe399b47479bd161ee2ee5 Mon Sep 17 00:00:00 2001 From: Jeremy Soller <jeremy@system76.com> Date: Sun, 6 Oct 2019 11:04:06 -0600 Subject: [PATCH] Fix clippy.sh script and fix a number of clippy warnings --- Cargo.lock | 416 ++------------------- Cargo.toml | 1 - clippy.sh | 20 +- src/acpi/dmar/mod.rs | 4 +- src/acpi/madt.rs | 4 +- src/acpi/rsdt.rs | 2 +- src/acpi/xsdt.rs | 2 +- src/allocator/linked_list.rs | 4 +- src/arch/x86_64/device/cpu.rs | 12 +- src/arch/x86_64/gdt.rs | 2 +- src/arch/x86_64/graphical_debug/display.rs | 2 +- src/arch/x86_64/paging/mapper.rs | 6 +- src/arch/x86_64/paging/mod.rs | 15 +- src/arch/x86_64/paging/table.rs | 2 +- src/arch/x86_64/paging/temporary_page.rs | 4 +- src/common/unique.rs | 2 +- src/context/arch/x86_64.rs | 24 +- src/context/context.rs | 6 +- src/context/list.rs | 2 +- src/context/memory.rs | 6 +- src/context/switch.rs | 26 +- src/context/timeout.rs | 6 +- src/elf.rs | 4 +- src/event.rs | 2 +- src/lib.rs | 32 +- src/log.rs | 2 +- src/memory/mod.rs | 9 +- src/memory/recycle.rs | 2 +- src/scheme/debug.rs | 2 +- src/scheme/irq.rs | 4 +- src/scheme/mod.rs | 2 - src/scheme/pipe.rs | 10 +- src/scheme/proc.rs | 8 +- src/scheme/root.rs | 4 +- src/scheme/sys/mod.rs | 22 +- src/scheme/time.rs | 2 +- src/scheme/user.rs | 38 +- src/syscall/fs.rs | 13 +- src/syscall/process.rs | 13 +- src/syscall/validate.rs | 2 + 40 files changed, 196 insertions(+), 543 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a9cc12c2..dce7ae51 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,48 +1,5 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -[[package]] -name = "aho-corasick" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "ansi_term" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "autocfg" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "backtrace" -version = "0.3.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "backtrace-sys 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)", - "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-demangle 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "backtrace-sys" -version = "0.1.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "cc 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "bitflags" version = "0.7.0" @@ -50,90 +7,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "bitflags" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "bitflags" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "cargo_metadata" -version = "0.5.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "error-chain 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", - "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "cc" -version = "1.0.35" +version = "1.0.45" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "cfg-if" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "clippy" -version = "0.0.209" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", - "clippy_lints 0.0.209 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 1.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "clippy_lints" -version = "0.0.209" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "cargo_metadata 0.5.8 (registry+https://github.com/rust-lang/crates.io-index)", - "if_chain 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", - "itertools 0.7.11 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", - "pulldown-cmark 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "quine-mc_cluskey 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", - "regex-syntax 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", - "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", - "toml 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-normalization 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", - "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "either" -version = "1.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "error-chain" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "backtrace 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "getopts" -version = "0.2.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "goblin" version = "0.0.21" @@ -143,83 +24,29 @@ dependencies = [ "scroll 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "idna" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-normalization 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "if_chain" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "itertools" -version = "0.7.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "either 1.5.2 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "itoa" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "kernel" version = "0.1.54" dependencies = [ - "bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "clippy 0.0.209 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "goblin 0.0.21 (registry+https://github.com/rust-lang/crates.io-index)", "linked_list_allocator 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", "raw-cpuid 4.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "redox_syscall 0.1.56", - "rustc-demangle 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-demangle 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", "slab_allocator 0.3.1", "spin 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", "x86 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "lazy_static" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "libc" -version = "0.2.51" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "linked_list_allocator" version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "spin 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "spin 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "matches" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "memchr" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "percent-encoding" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "plain" version = "0.2.3" @@ -227,32 +54,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "proc-macro2" -version = "0.4.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "pulldown-cmark" -version = "0.1.2" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", - "getopts 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "quine-mc_cluskey" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "quote" -version = "0.6.11" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -268,43 +81,23 @@ name = "raw-cpuid" version = "4.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "cc 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.45 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "redox_syscall" version = "0.1.56" dependencies = [ - "bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "regex" -version = "1.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "aho-corasick 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)", - "memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "regex-syntax 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", - "thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", - "utf8-ranges 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "regex-syntax" -version = "0.6.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "ucd-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "rustc-demangle" -version = "0.1.13" +version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -315,11 +108,6 @@ dependencies = [ "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "ryu" -version = "0.2.7" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "scroll" version = "0.9.2" @@ -334,7 +122,6 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -344,27 +131,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "serde" -version = "1.0.90" +version = "1.0.101" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "serde_derive" -version = "1.0.90" +version = "1.0.101" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.30 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "serde_json" -version = "1.0.39" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", - "ryu 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 1.0.5 (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.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -375,11 +152,6 @@ dependencies = [ "spin 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "smallvec" -version = "0.6.9" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "spin" version = "0.4.10" @@ -387,98 +159,22 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "spin" -version = "0.5.0" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "syn" -version = "0.15.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "thread_local" -version = "0.3.6" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "toml" -version = "0.4.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "ucd-util" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "unicode-bidi" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "unicode-normalization" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "unicode-width" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "unicode-xid" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "url" -version = "1.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "idna 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", - "percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "utf8-ranges" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "winapi" -version = "0.3.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -491,65 +187,25 @@ dependencies = [ ] [metadata] -"checksum aho-corasick 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e6f484ae0c99fec2e858eb6134949117399f222608d84cadb3f58c1f97c2364c" -"checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" -"checksum autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a6d640bee2da49f60a4068a7fae53acde8982514ab7bae8b8cea9e88cbcfd799" -"checksum backtrace 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "f106c02a3604afcdc0df5d36cc47b44b55917dbaf3d808f71c163a0ddba64637" -"checksum backtrace-sys 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)" = "797c830ac25ccc92a7f8a7b9862bde440715531514594a6154e3d4a54dd769b6" "checksum bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "aad18937a628ec6abcd26d1489012cc0e18c21798210f491af69ded9b881106d" -"checksum bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4efd02e230a02e18f92fc2735f44597385ed02ad8f831e7c1c1156ee5e1ab3a5" -"checksum bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3d155346769a6855b86399e9bc3814ab343cd3d62c7e985113d46a0ec3c281fd" -"checksum cargo_metadata 0.5.8 (registry+https://github.com/rust-lang/crates.io-index)" = "1efca0b863ca03ed4c109fb1c55e0bc4bbeb221d3e103d86251046b06a526bd0" -"checksum cc 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)" = "5e5f3fee5eeb60324c2781f1e41286bdee933850fff9b3c672587fed5ec58c83" -"checksum cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "11d43355396e872eefb45ce6342e4374ed7bc2b3a502d1b28e36d6e23c05d1f4" -"checksum clippy 0.0.209 (registry+https://github.com/rust-lang/crates.io-index)" = "fe56cba96f8d67cd3af996bd2c61fbfea263cc555db9180dc1f7413418454c7d" -"checksum clippy_lints 0.0.209 (registry+https://github.com/rust-lang/crates.io-index)" = "891679ac4d0890425ce9aa4db6ab7c05a60506048fb5e0fc2ae2eeaeb02626e8" -"checksum either 1.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "5527cfe0d098f36e3f8839852688e63c8fff1c90b2b405aef730615f9a7bcf7b" -"checksum error-chain 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ff511d5dc435d703f4971bc399647c9bc38e20cb41452e3b9feb4765419ed3f3" -"checksum getopts 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)" = "0a7292d30132fb5424b354f5dc02512a86e4c516fe544bb7a25e7f266951b797" +"checksum bitflags 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8a606a02debe2813760609f57a64a2ffd27d9fdf5b2f133eaca0b248dd92cdd2" +"checksum cc 1.0.45 (registry+https://github.com/rust-lang/crates.io-index)" = "4fc9a35e1f4290eb9e5fc54ba6cf40671ed2a2514c3eeb2b2a908dda2ea5a1be" "checksum goblin 0.0.21 (registry+https://github.com/rust-lang/crates.io-index)" = "6a4013e9182f2345c6b7829b9ef6e670bce0dfca12c6f974457ed2160c2c7fe9" -"checksum idna 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "38f09e0f0b1fb55fdee1f17470ad800da77af5186a1a76c026b679358b7e844e" -"checksum if_chain 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "4bac95d9aa0624e7b78187d6fb8ab012b41d9f6f54b1bcb61e61c4845f8357ec" -"checksum itertools 0.7.11 (registry+https://github.com/rust-lang/crates.io-index)" = "0d47946d458e94a1b7bcabbf6521ea7c037062c81f534615abcad76e84d4970d" -"checksum itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1306f3464951f30e30d12373d31c79fbd52d236e5e896fd92f96ec7babbbe60b" -"checksum lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bc5729f27f159ddd61f4df6228e827e86643d4d3e7c32183cb30a1c08f604a14" -"checksum libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)" = "bedcc7a809076656486ffe045abeeac163da1b558e963a31e29fbfbeba916917" "checksum linked_list_allocator 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)" = "47314ec1d29aa869ee7cb5a5be57be9b1055c56567d59c3fb6689926743e0bea" -"checksum matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" -"checksum memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2efc7bc57c883d4a4d6e3246905283d8dae951bb3bd32f49d6ef297f546e1c39" -"checksum percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "31010dd2e1ac33d5b46a5b413495239882813e0369f8ed8a5e266f173602f831" "checksum plain 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6" -"checksum proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)" = "4d317f9caece796be1980837fd5cb3dfec5613ebdb04ad0956deea83ce168915" -"checksum pulldown-cmark 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d6fdf85cda6cadfae5428a54661d431330b312bc767ddbc57adbedc24da66e32" -"checksum quine-mc_cluskey 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "07589615d719a60c8dd8a4622e7946465dfef20d1a428f969e3443e7386d5f45" -"checksum quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)" = "cdd8e04bd9c52e0342b406469d494fcb033be4bdbe5c606016defbb1681411e1" +"checksum proc-macro2 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "90cf5f418035b98e655e9cdb225047638296b862b42411c4e45bb88d700f7fc0" +"checksum quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "053a8c8bcc71fcce321828dc897a98ab9760bef03a4fc36693c231e5b3216cfe" "checksum raw-cpuid 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "13b844e4049605ff38fed943f5c7b2c691fad68d9d5bf074d2720554c4e48246" "checksum raw-cpuid 4.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "90e0d3209fac374e168cef2d8806dde7b31ef0ee82a965bcc0bec562c078a6f5" -"checksum regex 1.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "559008764a17de49a3146b234641644ed37d118d1ef641a0bb573d146edc6ce0" -"checksum regex-syntax 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)" = "dcfd8681eebe297b81d98498869d4aae052137651ad7b96822f09ceb690d0a96" -"checksum rustc-demangle 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "adacaae16d02b6ec37fdc7acfcddf365978de76d1983d3ee22afc260e1ca9619" +"checksum rustc-demangle 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783" "checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" -"checksum ryu 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "eb9e9b8cde282a9fe6a42dd4681319bfb63f121b8a8ee9439c6f4107e58a46f7" "checksum scroll 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2f84d114ef17fd144153d608fba7c446b0145d038985e7a8cc5d08bb0ce20383" "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 serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)" = "aa5f7c20820475babd2c077c3ab5f8c77a31c15e16ea38687b4c02d3e48680f4" -"checksum serde_derive 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)" = "58fc82bec244f168b23d1963b45c8bf5726e9a15a9d146a067f9081aeed2de79" -"checksum serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)" = "5a23aa71d4a4d43fdbfaac00eff68ba8a06a51759a89ac3304323e800c4dd40d" -"checksum smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)" = "c4488ae950c49d403731982257768f48fada354a5203fe81f9bb6f43ca9002be" +"checksum serde 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)" = "9796c9b7ba2ffe7a9ce53c2287dfc48080f4b2b362fcc245a259b3a7201119dd" +"checksum serde_derive 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)" = "4b133a43a1ecd55d4086bd5b4dc6c1751c68b1bfbeba7a5040442022c7e7c02e" "checksum spin 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "ceac490aa12c567115b40b7b7fceca03a6c9d53d5defea066123debc83c5dc1f" -"checksum spin 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "44363f6f51401c34e7be73db0db371c04705d35efbe9f7d6082e03a921a32c55" -"checksum syn 0.15.30 (registry+https://github.com/rust-lang/crates.io-index)" = "66c8865bf5a7cbb662d8b011950060b3c8743dca141b054bf7195b20d314d8e2" -"checksum thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b" -"checksum toml 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "758664fc71a3a69038656bee8b6be6477d2a6c315a6b81f7081f591bffa4111f" -"checksum ucd-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "535c204ee4d8434478593480b8f86ab45ec9aae0e83c568ca81abf0fd0e88f86" -"checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5" -"checksum unicode-normalization 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "141339a08b982d942be2ca06ff8b076563cbe223d1befd5450716790d44e2426" -"checksum unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "882386231c45df4700b275c7ff55b6f3698780a650026380e72dabe76fa46526" -"checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" -"checksum url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dd4e7c0d531266369519a4aa4f399d748bd37043b00bde1e4ff1f60a120b355a" -"checksum utf8-ranges 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "796f7e48bef87609f7ade7e06495a87d5cd06c7866e6a5cbfceffc558a243737" -"checksum winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "f10e386af2b13e47c89e7236a7a14a086791a2b88ebad6df9bf42040195cf770" -"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" -"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +"checksum spin 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" +"checksum syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "66850e97125af79138385e9b88339cbcd037e3f28ceab8c5ad98e64f0f1f80bf" +"checksum unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" "checksum x86 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "178718d3f2c7dd98d44f8e353b0ccc8c89b2e81e31e5eed93e7fdf5f36db7a13" diff --git a/Cargo.toml b/Cargo.toml index 80ea505f..f10dbe64 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,6 @@ crate-type = ["staticlib"] [dependencies] bitflags = "1.0.3" -clippy = { version = "0.0.209", optional = true } linked_list_allocator = "0.6.2" raw-cpuid = "4.0.0" redox_syscall = { path = "syscall" } diff --git a/clippy.sh b/clippy.sh index f128f482..a858da52 100755 --- a/clippy.sh +++ b/clippy.sh @@ -2,16 +2,12 @@ set -e +# https://github.com/rust-lang/rust-clippy/issues/4579 +export RUSTUP_TOOLCHAIN="nightly-2019-07-19" +rustup update "${RUSTUP_TOOLCHAIN}" +rustup component add clippy --toolchain "${RUSTUP_TOOLCHAIN}" +rustup component add rust-src --toolchain "${RUSTUP_TOOLCHAIN}" + export RUST_TARGET_PATH="${PWD}/targets" -xargo rustc --lib --release \ - --target x86_64-unknown-none \ - --features clippy \ - -- \ - -C soft-float -C debuginfo=2 \ - -W anonymous-parameters \ - -W trivial-numeric-casts \ - -W unused-extern-crates \ - -W unused-import-braces \ - -W unused-qualifications \ - -W variant-size-differences \ - -Z no-trans -Z extra-plugins=clippy +export RUSTFLAGS="-C soft-float -C debuginfo=2" +xargo clippy --lib --release --target x86_64-unknown-none diff --git a/src/acpi/dmar/mod.rs b/src/acpi/dmar/mod.rs index ad2899fd..1e18a522 100644 --- a/src/acpi/dmar/mod.rs +++ b/src/acpi/dmar/mod.rs @@ -172,8 +172,8 @@ impl Iterator for DmarIter { type Item = DmarEntry; fn next(&mut self) -> Option<Self::Item> { if self.i + 4 <= self.sdt.data_len() { - let entry_type = unsafe { *((self.sdt.data_address() as *const u8).offset(self.i as isize) as *const u16) }; - let entry_len = unsafe { *((self.sdt.data_address() as *const u8).offset(self.i as isize + 2) as *const u16) } as usize; + let entry_type = unsafe { *((self.sdt.data_address() as *const u8).add(self.i) as *const u16) }; + let entry_len = unsafe { *((self.sdt.data_address() as *const u8).add(self.i + 2) as *const u16) } as usize; if self.i + entry_len <= self.sdt.data_len() { let item = match entry_type { diff --git a/src/acpi/madt.rs b/src/acpi/madt.rs index b6716007..d8904899 100644 --- a/src/acpi/madt.rs +++ b/src/acpi/madt.rs @@ -226,8 +226,8 @@ impl Iterator for MadtIter { type Item = MadtEntry; fn next(&mut self) -> Option<Self::Item> { if self.i + 1 < self.sdt.data_len() { - let entry_type = unsafe { *(self.sdt.data_address() as *const u8).offset(self.i as isize) }; - let entry_len = unsafe { *(self.sdt.data_address() as *const u8).offset(self.i as isize + 1) } as usize; + let entry_type = unsafe { *(self.sdt.data_address() as *const u8).add(self.i) }; + let entry_len = unsafe { *(self.sdt.data_address() as *const u8).add(self.i + 1) } as usize; if self.i + entry_len <= self.sdt.data_len() { let item = match entry_type { diff --git a/src/acpi/rsdt.rs b/src/acpi/rsdt.rs index 7877a061..5cf94603 100644 --- a/src/acpi/rsdt.rs +++ b/src/acpi/rsdt.rs @@ -35,7 +35,7 @@ impl Iterator for RsdtIter { type Item = usize; fn next(&mut self) -> Option<Self::Item> { if self.i < self.sdt.data_len()/mem::size_of::<u32>() { - let item = unsafe { *(self.sdt.data_address() as *const u32).offset(self.i as isize) }; + let item = unsafe { *(self.sdt.data_address() as *const u32).add(self.i) }; self.i += 1; Some(item as usize) } else { diff --git a/src/acpi/xsdt.rs b/src/acpi/xsdt.rs index 7339ce01..aea267d4 100644 --- a/src/acpi/xsdt.rs +++ b/src/acpi/xsdt.rs @@ -35,7 +35,7 @@ impl Iterator for XsdtIter { type Item = usize; fn next(&mut self) -> Option<Self::Item> { if self.i < self.sdt.data_len()/mem::size_of::<u64>() { - let item = unsafe { *(self.sdt.data_address() as *const u64).offset(self.i as isize) }; + let item = unsafe { *(self.sdt.data_address() as *const u64).add(self.i) }; self.i += 1; Some(item as usize) } else { diff --git a/src/allocator/linked_list.rs b/src/allocator/linked_list.rs index ddeadf51..a4c42551 100644 --- a/src/allocator/linked_list.rs +++ b/src/allocator/linked_list.rs @@ -1,5 +1,5 @@ use core::alloc::{AllocErr, GlobalAlloc, Layout}; -use core::ptr::NonNull; +use core::ptr::{self, NonNull}; use linked_list_allocator::Heap; use spin::Mutex; @@ -40,7 +40,7 @@ unsafe impl GlobalAlloc for Allocator { panic!("__rust_allocate: heap not initialized"); } }, - other => return other.ok().map_or(0 as *mut u8, |allocation| allocation.as_ptr()), + other => return other.ok().map_or(ptr::null_mut(), |allocation| allocation.as_ptr()), } } } diff --git a/src/arch/x86_64/device/cpu.rs b/src/arch/x86_64/device/cpu.rs index 516ebfe2..f28aa2a1 100644 --- a/src/arch/x86_64/device/cpu.rs +++ b/src/arch/x86_64/device/cpu.rs @@ -8,19 +8,19 @@ pub fn cpu_info<W: Write>(w: &mut W) -> Result { let cpuid = CpuId::new(); if let Some(info) = cpuid.get_vendor_info() { - write!(w, "Vendor: {}\n", info.as_string())?; + writeln!(w, "Vendor: {}", info.as_string())?; } if let Some(info) = cpuid.get_extended_function_info() { if let Some(brand) = info.processor_brand_string() { - write!(w, "Model: {}\n", brand)?; + writeln!(w, "Model: {}", brand)?; } } if let Some(info) = cpuid.get_processor_frequency_info() { - write!(w, "CPU Base MHz: {}\n", info.processor_base_frequency())?; - write!(w, "CPU Max MHz: {}\n", info.processor_max_frequency())?; - write!(w, "Bus MHz: {}\n", info.bus_frequency())?; + writeln!(w, "CPU Base MHz: {}", info.processor_base_frequency())?; + writeln!(w, "CPU Max MHz: {}", info.processor_max_frequency())?; + writeln!(w, "Bus MHz: {}", info.bus_frequency())?; } write!(w, "Features:")?; @@ -120,7 +120,7 @@ pub fn cpu_info<W: Write>(w: &mut W) -> Result { if info.has_mpx() { write!(w, " mpx")? }; } - write!(w, "\n")?; + writeln!(w)?; Ok(()) } diff --git a/src/arch/x86_64/gdt.rs b/src/arch/x86_64/gdt.rs index 652f8103..cc56c3e1 100644 --- a/src/arch/x86_64/gdt.rs +++ b/src/arch/x86_64/gdt.rs @@ -188,7 +188,7 @@ impl GdtEntry { limitl: limit as u16, offsetl: offset as u16, offsetm: (offset >> 16) as u8, - access: access, + access, flags_limith: flags & 0xF0 | ((limit >> 16) as u8) & 0x0F, offseth: (offset >> 24) as u8 } diff --git a/src/arch/x86_64/graphical_debug/display.rs b/src/arch/x86_64/graphical_debug/display.rs index 682c56e1..a88248be 100644 --- a/src/arch/x86_64/graphical_debug/display.rs +++ b/src/arch/x86_64/graphical_debug/display.rs @@ -108,7 +108,7 @@ impl Display { let size = self.offscreen.len() - offset; unsafe { let to = self.offscreen.as_mut_ptr(); - let from = to.offset(offset as isize); + let from = to.add(offset); fast_copy(to as *mut u8, from as *const u8, size * 4); } } diff --git a/src/arch/x86_64/paging/mapper.rs b/src/arch/x86_64/paging/mapper.rs index f8020678..2f69bd2a 100644 --- a/src/arch/x86_64/paging/mapper.rs +++ b/src/arch/x86_64/paging/mapper.rs @@ -134,7 +134,7 @@ impl Mapper { self.map_to(page, frame, flags) } - fn unmap_inner(&mut self, page: &Page, keep_parents: bool) -> Frame { + fn unmap_inner(&mut self, page: Page, keep_parents: bool) -> Frame { let frame; let p4 = self.p4_mut(); @@ -203,14 +203,14 @@ impl Mapper { /// Unmap a page pub fn unmap(&mut self, page: Page) -> MapperFlush { - let frame = self.unmap_inner(&page, false); + let frame = self.unmap_inner(page, false); deallocate_frames(frame, 1); MapperFlush::new(page) } /// Unmap a page, return frame without free pub fn unmap_return(&mut self, page: Page, keep_parents: bool) -> (MapperFlush, Frame) { - let frame = self.unmap_inner(&page, keep_parents); + let frame = self.unmap_inner(page, keep_parents); (MapperFlush::new(page), frame) } diff --git a/src/arch/x86_64/paging/mod.rs b/src/arch/x86_64/paging/mod.rs index 84880b12..f5642fc2 100644 --- a/src/arch/x86_64/paging/mod.rs +++ b/src/arch/x86_64/paging/mod.rs @@ -393,23 +393,23 @@ pub struct Page { } impl Page { - pub fn start_address(&self) -> VirtualAddress { + pub fn start_address(self) -> VirtualAddress { VirtualAddress::new(self.number * PAGE_SIZE) } - pub fn p4_index(&self) -> usize { + pub fn p4_index(self) -> usize { (self.number >> 27) & 0o777 } - pub fn p3_index(&self) -> usize { + pub fn p3_index(self) -> usize { (self.number >> 18) & 0o777 } - pub fn p2_index(&self) -> usize { + pub fn p2_index(self) -> usize { (self.number >> 9) & 0o777 } - pub fn p1_index(&self) -> usize { + pub fn p1_index(self) -> usize { self.number & 0o777 } @@ -420,10 +420,7 @@ impl Page { } pub fn range_inclusive(start: Page, end: Page) -> PageIter { - PageIter { - start: start, - end: end, - } + PageIter { start, end } } pub fn next(self) -> Page { diff --git a/src/arch/x86_64/paging/table.rs b/src/arch/x86_64/paging/table.rs index aac93234..28f59825 100644 --- a/src/arch/x86_64/paging/table.rs +++ b/src/arch/x86_64/paging/table.rs @@ -9,7 +9,7 @@ use crate::memory::allocate_frames; use super::entry::{EntryFlags, Entry}; use super::ENTRY_COUNT; -pub const P4: *mut Table<Level4> = (crate::RECURSIVE_PAGE_OFFSET | 0x7ffffff000) as *mut _; +pub const P4: *mut Table<Level4> = (crate::RECURSIVE_PAGE_OFFSET | 0x7f_ffff_f000) as *mut _; pub trait TableLevel {} diff --git a/src/arch/x86_64/paging/temporary_page.rs b/src/arch/x86_64/paging/temporary_page.rs index c50bbf23..72a18cf3 100644 --- a/src/arch/x86_64/paging/temporary_page.rs +++ b/src/arch/x86_64/paging/temporary_page.rs @@ -13,9 +13,7 @@ pub struct TemporaryPage { impl TemporaryPage { pub fn new(page: Page) -> TemporaryPage { - TemporaryPage { - page: page, - } + TemporaryPage { page } } pub fn start_address (&self) -> VirtualAddress { diff --git a/src/common/unique.rs b/src/common/unique.rs index f426c525..5d22f93a 100644 --- a/src/common/unique.rs +++ b/src/common/unique.rs @@ -22,7 +22,7 @@ impl<T> Unique<T> { pub unsafe fn new_unchecked(ptr: *mut T) -> Self { Self(NonNull::new_unchecked(ptr)) } - pub fn as_ptr(&self) -> *mut T { + pub fn as_ptr(self) -> *mut T { self.0.as_ptr() } } diff --git a/src/context/arch/x86_64.rs b/src/context/arch/x86_64.rs index 25b1925a..85d172aa 100644 --- a/src/context/arch/x86_64.rs +++ b/src/context/arch/x86_64.rs @@ -76,18 +76,20 @@ impl Context { if !self.loadable { return false; } - let old = unsafe { &*(self.fx as *const FloatRegisters) }; - new._reserved = old._reserved; - let old_st = new.st_space; - let mut new_st = new.st_space; - for (new_st, old_st) in new_st.iter_mut().zip(&old_st) { - *new_st &= !ST_RESERVED; - *new_st |= old_st & ST_RESERVED; - } - new.st_space = new_st; - // Make sure we don't use `old` from now on - drop(old); + { + let old = unsafe { &*(self.fx as *const FloatRegisters) }; + new._reserved = old._reserved; + let old_st = new.st_space; + let mut new_st = new.st_space; + for (new_st, old_st) in new_st.iter_mut().zip(&old_st) { + *new_st &= !ST_RESERVED; + *new_st |= old_st & ST_RESERVED; + } + new.st_space = new_st; + + // Make sure we don't use `old` from now on + } unsafe { *(self.fx as *mut FloatRegisters) = new; diff --git a/src/context/context.rs b/src/context/context.rs index 216726e5..f144f600 100644 --- a/src/context/context.rs +++ b/src/context/context.rs @@ -183,7 +183,7 @@ impl Context { let syscall_tail = unsafe { Box::from_raw(crate::ALLOCATOR.alloc(Layout::from_size_align_unchecked(PAGE_SIZE, PAGE_SIZE)) as *mut [u8; PAGE_SIZE]) }; Context { - id: id, + id, pgid: id, ppid: ContextId::from(0), ruid: 0, @@ -198,8 +198,8 @@ impl Context { running: false, cpu_id: None, syscall: None, - syscall_head: syscall_head, - syscall_tail: syscall_tail, + syscall_head, + syscall_tail, vfork: false, waitpid: Arc::new(WaitMap::new()), pending: VecDeque::new(), diff --git a/src/context/list.rs b/src/context/list.rs index ef92c9ce..d56b0e2a 100644 --- a/src/context/list.rs +++ b/src/context/list.rs @@ -83,7 +83,7 @@ impl ContextList { let offset = stack.len() - mem::size_of::<usize>(); unsafe { let offset = stack.len() - mem::size_of::<usize>(); - let func_ptr = stack.as_mut_ptr().offset(offset as isize); + let func_ptr = stack.as_mut_ptr().add(offset); *(func_ptr as *mut usize) = func as usize; } context.arch.set_page_table(unsafe { paging::ActivePageTable::new().address() }); diff --git a/src/context/memory.rs b/src/context/memory.rs index 22426c92..39303dae 100644 --- a/src/context/memory.rs +++ b/src/context/memory.rs @@ -312,9 +312,9 @@ pub struct Memory { impl Memory { pub fn new(start: VirtualAddress, size: usize, flags: EntryFlags, clear: bool) -> Self { let mut memory = Memory { - start: start, - size: size, - flags: flags + start, + size, + flags, }; memory.map(clear); diff --git a/src/context/switch.rs b/src/context/switch.rs index 2a5f6c51..0280a842 100644 --- a/src/context/switch.rs +++ b/src/context/switch.rs @@ -99,7 +99,7 @@ pub unsafe fn switch() -> bool { let mut context = context_lock.write(); if runnable(&mut context, cpu_id) { to_ptr = context.deref_mut() as *mut Context; - if (&mut *to_ptr).ksig.is_none() { + if (*to_ptr).ksig.is_none() { to_sig = context.pending.pop_front(); } break; @@ -113,7 +113,7 @@ pub unsafe fn switch() -> bool { let mut context = context_lock.write(); if runnable(&mut context, cpu_id) { to_ptr = context.deref_mut() as *mut Context; - if (&mut *to_ptr).ksig.is_none() { + if (*to_ptr).ksig.is_none() { to_sig = context.pending.pop_front(); } break; @@ -125,13 +125,13 @@ pub unsafe fn switch() -> bool { // Switch process states, TSS stack pointer, and store new context ID if to_ptr as usize != 0 { - (&mut *from_ptr).running = false; - (&mut *to_ptr).running = true; + (*from_ptr).running = false; + (*to_ptr).running = true; if let Some(ref stack) = (*to_ptr).kstack { gdt::set_tss_stack(stack.as_ptr() as usize + stack.len()); } - gdt::set_tcb((&mut *to_ptr).id.into()); - CONTEXT_ID.store((&mut *to_ptr).id, Ordering::SeqCst); + gdt::set_tcb((*to_ptr).id.into()); + CONTEXT_ID.store((*to_ptr).id, Ordering::SeqCst); } // Unset global lock before switch, as arch is only usable by the current CPU at this time @@ -146,16 +146,16 @@ pub unsafe fn switch() -> bool { // Signal was found, run signal handler //TODO: Allow nested signals - assert!((&mut *to_ptr).ksig.is_none()); + assert!((*to_ptr).ksig.is_none()); - let arch = (&mut *to_ptr).arch.clone(); - let kfx = (&mut *to_ptr).kfx.clone(); - let kstack = (&mut *to_ptr).kstack.clone(); - (&mut *to_ptr).ksig = Some((arch, kfx, kstack, sig)); - (&mut *to_ptr).arch.signal_stack(signal_handler, sig); + let arch = (*to_ptr).arch.clone(); + let kfx = (*to_ptr).kfx.clone(); + let kstack = (*to_ptr).kstack.clone(); + (*to_ptr).ksig = Some((arch, kfx, kstack, sig)); + (*to_ptr).arch.signal_stack(signal_handler, sig); } - (&mut *from_ptr).arch.switch_to(&mut (&mut *to_ptr).arch); + (*from_ptr).arch.switch_to(&mut (*to_ptr).arch); true } diff --git a/src/context/timeout.rs b/src/context/timeout.rs index c26eb63a..5e0fdb38 100644 --- a/src/context/timeout.rs +++ b/src/context/timeout.rs @@ -32,9 +32,9 @@ fn registry() -> MutexGuard<'static, Registry> { pub fn register(scheme_id: SchemeId, event_id: usize, clock: usize, time: TimeSpec) { let mut registry = registry(); registry.push_back(Timeout { - scheme_id: scheme_id, - event_id: event_id, - clock: clock, + scheme_id, + event_id, + clock, time: (time.tv_sec as u64, time.tv_nsec as u64) }); } diff --git a/src/elf.rs b/src/elf.rs index debc08d8..123d44d9 100644 --- a/src/elf.rs +++ b/src/elf.rs @@ -27,7 +27,7 @@ impl<'a> Elf<'a> { Err(format!("Elf: Invalid architecture: {:?} != {:?}", data.get(header::EI_CLASS), header::ELFCLASS)) } else { Ok(Elf { - data: data, + data, header: unsafe { &*(data.as_ptr() as usize as *const header::Header) } }) } @@ -61,7 +61,7 @@ impl<'a> Elf<'a> { if let Some(symtab) = symtab_opt { Some(ElfSymbols { data: self.data, - symtab: symtab, + symtab, i: 0 }) } else { diff --git a/src/event.rs b/src/event.rs index 4eba3be2..51f2b9d3 100644 --- a/src/event.rs +++ b/src/event.rs @@ -20,7 +20,7 @@ pub struct EventQueue { impl EventQueue { pub fn new(id: EventQueueId) -> EventQueue { EventQueue { - id: id, + id, queue: WaitQueue::new() } } diff --git a/src/lib.rs b/src/lib.rs index b7acc714..e874b233 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,16 +3,30 @@ //! The Redox OS Kernel is a microkernel that supports `x86_64` systems and //! provides Unix-like syscalls for primarily Rust applications -//#![deny(warnings)] -#![cfg_attr(feature = "clippy", allow(if_same_then_else))] -#![cfg_attr(feature = "clippy", allow(inline_always))] -#![cfg_attr(feature = "clippy", allow(many_single_char_names))] -#![cfg_attr(feature = "clippy", allow(module_inception))] -#![cfg_attr(feature = "clippy", allow(new_without_default))] -#![cfg_attr(feature = "clippy", allow(not_unsafe_ptr_arg_deref))] -#![cfg_attr(feature = "clippy", allow(or_fun_call))] -#![cfg_attr(feature = "clippy", allow(too_many_arguments))] +// Useful for adding comments about different branches +#![allow(clippy::if_same_then_else)] +// Useful in the syscall function +#![allow(clippy::many_single_char_names)] +// Used for context::context +#![allow(clippy::module_inception)] +// Not implementing default is sometimes useful in the case something has significant cost +// to allocate. If you implement default, it can be allocated without evidence using the +// ..Default::default() syntax. Not fun in kernel space +#![allow(clippy::new_without_default)] +// Used to make it nicer to return errors, for example, .ok_or(Error::new(ESRCH)) +#![allow(clippy::or_fun_call)] +// This is needed in some cases, like for syscall +#![allow(clippy::too_many_arguments)] +// There is no harm in this being done +#![allow(clippy::useless_format)] +// TODO: address ocurrances and then deny +#![warn(clippy::not_unsafe_ptr_arg_deref)] +// TODO: address ocurrances and then deny +#![warn(clippy::cast_ptr_alignment)] +// This is usually a serious issue - a missing import of a define where it is interpreted +// as a catch-all variable in a match, for example #![deny(unreachable_patterns)] + #![feature(allocator_api)] #![feature(asm)] #![feature(concat_idents)] diff --git a/src/log.rs b/src/log.rs index b0866cf3..d11dbfa2 100644 --- a/src/log.rs +++ b/src/log.rs @@ -16,7 +16,7 @@ impl Log { pub fn new(size: usize) -> Log { Log { data: VecDeque::with_capacity(size), - size: size + size } } diff --git a/src/memory/mod.rs b/src/memory/mod.rs index 46920b6e..146ff420 100644 --- a/src/memory/mod.rs +++ b/src/memory/mod.rs @@ -46,7 +46,7 @@ pub struct MemoryAreaIter { impl MemoryAreaIter { fn new(_type: u32) -> Self { MemoryAreaIter { - _type: _type, + _type, i: 0 } } @@ -73,7 +73,7 @@ static ALLOCATOR: Mutex<Option<RecycleAllocator<BumpAllocator>>> = Mutex::new(No pub unsafe fn init(kernel_start: usize, kernel_end: usize) { // Copy memory map from bootloader location for (i, entry) in MEMORY_MAP.iter_mut().enumerate() { - *entry = *(0x500 as *const MemoryArea).offset(i as isize); + *entry = *(0x500 as *const MemoryArea).add(i); if entry._type != MEMORY_AREA_NULL { println!("{:?}", entry); } @@ -157,10 +157,7 @@ impl Frame { //TODO: Set private pub fn range_inclusive(start: Frame, end: Frame) -> FrameIter { - FrameIter { - start: start, - end: end, - } + FrameIter { start, end } } } diff --git a/src/memory/recycle.rs b/src/memory/recycle.rs index 31f4cc98..55a4c81f 100644 --- a/src/memory/recycle.rs +++ b/src/memory/recycle.rs @@ -16,7 +16,7 @@ pub struct RecycleAllocator<T: FrameAllocator> { impl<T: FrameAllocator> RecycleAllocator<T> { pub fn new(inner: T) -> Self { Self { - inner: inner, + inner, noncore: false, free: Vec::new(), } diff --git a/src/scheme/debug.rs b/src/scheme/debug.rs index abcb60c0..f16860f0 100644 --- a/src/scheme/debug.rs +++ b/src/scheme/debug.rs @@ -8,7 +8,7 @@ use crate::sync::WaitQueue; use crate::syscall::flag::{EventFlags, EVENT_READ, F_GETFL, F_SETFL, O_ACCMODE, O_NONBLOCK}; use crate::syscall::scheme::Scheme; -pub static DEBUG_SCHEME_ID: AtomicSchemeId = ATOMIC_SCHEMEID_INIT; +pub static DEBUG_SCHEME_ID: AtomicSchemeId = AtomicSchemeId::default(); /// Input queue static INPUT: Once<WaitQueue<u8>> = Once::new(); diff --git a/src/scheme/irq.rs b/src/scheme/irq.rs index f7a4e373..60bcdd2c 100644 --- a/src/scheme/irq.rs +++ b/src/scheme/irq.rs @@ -4,12 +4,12 @@ use spin::Mutex; use crate::event; use crate::interrupt::irq::acknowledge; -use crate::scheme::{AtomicSchemeId, ATOMIC_SCHEMEID_INIT, SchemeId}; +use crate::scheme::{AtomicSchemeId, SchemeId}; use crate::syscall::error::*; use crate::syscall::flag::{EventFlags, EVENT_READ}; use crate::syscall::scheme::Scheme; -pub static IRQ_SCHEME_ID: AtomicSchemeId = ATOMIC_SCHEMEID_INIT; +pub static IRQ_SCHEME_ID: AtomicSchemeId = AtomicSchemeId::default(); /// IRQ queues static ACKS: Mutex<[usize; 16]> = Mutex::new([0; 16]); diff --git a/src/scheme/mod.rs b/src/scheme/mod.rs index fbdaba62..6a0571a5 100644 --- a/src/scheme/mod.rs +++ b/src/scheme/mod.rs @@ -77,8 +77,6 @@ int_like!(SchemeNamespace, AtomicSchemeNamespace, usize, AtomicUsize); // Unique identifier for a scheme. int_like!(SchemeId, AtomicSchemeId, usize, AtomicUsize); -pub const ATOMIC_SCHEMEID_INIT: AtomicSchemeId = AtomicSchemeId::default(); - // Unique identifier for a file descriptor. int_like!(FileHandle, AtomicFileHandle, usize, AtomicUsize); diff --git a/src/scheme/pipe.rs b/src/scheme/pipe.rs index bfc52321..3d6a0b3b 100644 --- a/src/scheme/pipe.rs +++ b/src/scheme/pipe.rs @@ -4,7 +4,7 @@ use core::sync::atomic::{AtomicUsize, Ordering}; use spin::{Mutex, Once, RwLock, RwLockReadGuard, RwLockWriteGuard}; use crate::event; -use crate::scheme::{AtomicSchemeId, ATOMIC_SCHEMEID_INIT, SchemeId}; +use crate::scheme::{AtomicSchemeId, SchemeId}; use crate::sync::WaitCondition; use crate::syscall::error::{Error, Result, EAGAIN, EBADF, EINTR, EINVAL, EPIPE, ESPIPE}; use crate::syscall::flag::{EventFlags, EVENT_READ, EVENT_WRITE, F_GETFL, F_SETFL, O_ACCMODE, O_NONBLOCK, MODE_FIFO}; @@ -12,7 +12,7 @@ use crate::syscall::scheme::Scheme; use crate::syscall::data::Stat; /// Pipes list -pub static PIPE_SCHEME_ID: AtomicSchemeId = ATOMIC_SCHEMEID_INIT; +pub static PIPE_SCHEME_ID: AtomicSchemeId = AtomicSchemeId::default(); static PIPE_NEXT_ID: AtomicUsize = AtomicUsize::new(0); static PIPES: Once<RwLock<(BTreeMap<usize, Arc<PipeRead>>, BTreeMap<usize, Arc<PipeWrite>>)>> = Once::new(); @@ -204,10 +204,8 @@ impl PipeRead { return Ok(0); } else if self.flags.load(Ordering::SeqCst) & O_NONBLOCK == O_NONBLOCK { return Err(Error::new(EAGAIN)); - } else { - if ! self.condition.wait() { - return Err(Error::new(EINTR)); - } + } else if ! self.condition.wait() { + return Err(Error::new(EINTR)); } } } diff --git a/src/scheme/proc.rs b/src/scheme/proc.rs index 3b666359..9eaf0d4a 100644 --- a/src/scheme/proc.rs +++ b/src/scheme/proc.rs @@ -2,7 +2,7 @@ use crate::{ arch::paging::VirtualAddress, context::{self, Context, ContextId, Status}, ptrace, - scheme::{ATOMIC_SCHEMEID_INIT, AtomicSchemeId, SchemeId}, + scheme::{AtomicSchemeId, SchemeId}, syscall::{ data::{FloatRegisters, IntRegisters, PtraceEvent}, error::*, @@ -167,7 +167,7 @@ impl Handle { } } -pub static PROC_SCHEME_ID: AtomicSchemeId = ATOMIC_SCHEMEID_INIT; +pub static PROC_SCHEME_ID: AtomicSchemeId = AtomicSchemeId::default(); pub struct ProcScheme { next_id: AtomicUsize, @@ -520,8 +520,8 @@ impl Scheme for ProcScheme { match cmd { F_SETFL => { handle.info.flags = arg; Ok(0) }, - F_GETFL => return Ok(handle.info.flags), - _ => return Err(Error::new(EINVAL)) + F_GETFL => Ok(handle.info.flags), + _ => Err(Error::new(EINVAL)) } } diff --git a/src/scheme/root.rs b/src/scheme/root.rs index c4315cd4..447430ad 100644 --- a/src/scheme/root.rs +++ b/src/scheme/root.rs @@ -63,8 +63,8 @@ pub struct RootScheme { impl RootScheme { pub fn new(scheme_ns: SchemeNamespace, scheme_id: SchemeId) -> RootScheme { RootScheme { - scheme_ns: scheme_ns, - scheme_id: scheme_id, + scheme_ns, + scheme_id, next_id: AtomicUsize::new(0), handles: RwLock::new(BTreeMap::new()), } diff --git a/src/scheme/sys/mod.rs b/src/scheme/sys/mod.rs index d12729d7..3af05889 100644 --- a/src/scheme/sys/mod.rs +++ b/src/scheme/sys/mod.rs @@ -40,19 +40,19 @@ impl SysScheme { pub fn new() -> SysScheme { let mut files: BTreeMap<&'static [u8], Box<SysFn>> = BTreeMap::new(); - files.insert(b"context", Box::new(move || context::resource())); - files.insert(b"cpu", Box::new(move || cpu::resource())); - files.insert(b"exe", Box::new(move || exe::resource())); - files.insert(b"iostat", Box::new(move || iostat::resource())); - files.insert(b"log", Box::new(move || log::resource())); - files.insert(b"scheme", Box::new(move || scheme::resource())); - files.insert(b"scheme_num", Box::new(move || scheme_num::resource())); - files.insert(b"syscall", Box::new(move || syscall::resource())); - files.insert(b"uname", Box::new(move || uname::resource())); + files.insert(b"context", Box::new(context::resource)); + files.insert(b"cpu", Box::new(cpu::resource)); + files.insert(b"exe", Box::new(exe::resource)); + files.insert(b"iostat", Box::new(iostat::resource)); + files.insert(b"log", Box::new(log::resource)); + files.insert(b"scheme", Box::new(scheme::resource)); + files.insert(b"scheme_num", Box::new(scheme_num::resource)); + files.insert(b"syscall", Box::new(syscall::resource)); + files.insert(b"uname", Box::new(uname::resource)); SysScheme { next_id: AtomicUsize::new(0), - files: files, + files, handles: RwLock::new(BTreeMap::new()) } } @@ -75,7 +75,7 @@ impl Scheme for SysScheme { let id = self.next_id.fetch_add(1, Ordering::SeqCst); self.handles.write().insert(id, Handle { path: b"", - data: data, + data, mode: MODE_DIR | 0o444, seek: 0 }); diff --git a/src/scheme/time.rs b/src/scheme/time.rs index 718d14dc..2ff548df 100644 --- a/src/scheme/time.rs +++ b/src/scheme/time.rs @@ -20,7 +20,7 @@ pub struct TimeScheme { impl TimeScheme { pub fn new(scheme_id: SchemeId) -> TimeScheme { TimeScheme { - scheme_id: scheme_id, + scheme_id, next_id: AtomicUsize::new(0), handles: RwLock::new(BTreeMap::new()) } diff --git a/src/scheme/user.rs b/src/scheme/user.rs index 91f2d6fc..afcb48b3 100644 --- a/src/scheme/user.rs +++ b/src/scheme/user.rs @@ -12,7 +12,7 @@ use crate::event; use crate::paging::{InactivePageTable, Page, VirtualAddress}; use crate::paging::entry::EntryFlags; use crate::paging::temporary_page::TemporaryPage; -use crate::scheme::{AtomicSchemeId, ATOMIC_SCHEMEID_INIT, SchemeId}; +use crate::scheme::{AtomicSchemeId, SchemeId}; use crate::sync::{WaitQueue, WaitMap}; use crate::syscall::data::{Map, Packet, Stat, StatVfs, TimeSpec}; use crate::syscall::error::*; @@ -38,13 +38,13 @@ pub struct UserInner { impl UserInner { pub fn new(root_id: SchemeId, handle_id: usize, name: Box<[u8]>, flags: usize, context: Weak<RwLock<Context>>) -> UserInner { UserInner { - root_id: root_id, - handle_id: handle_id, - name: name, - flags: flags, - scheme_id: ATOMIC_SCHEMEID_INIT, + root_id, + handle_id, + name, + flags, + scheme_id: AtomicSchemeId::default(), next_id: AtomicU64::new(1), - context: context, + context, todo: WaitQueue::new(), fmap: Mutex::new(BTreeMap::new()), funmap: Mutex::new(BTreeMap::new()), @@ -78,12 +78,12 @@ impl UserInner { self.call_inner(Packet { id: self.next_id.fetch_add(1, Ordering::SeqCst), pid: pid.into(), - uid: uid, - gid: gid, - a: a, - b: b, - c: c, - d: d + uid, + gid, + a, + b, + c, + d }) } @@ -229,7 +229,7 @@ impl UserInner { let len = buf.len()/packet_size; let mut i = 0; while i < len { - let mut packet = unsafe { *(buf.as_ptr() as *const Packet).offset(i as isize) }; + let mut packet = unsafe { *(buf.as_ptr() as *const Packet).add(i) }; if packet.id == 0 { match packet.a { SYS_FEVENT => event::trigger(self.scheme_id.load(Ordering::SeqCst), packet.b, EventFlags::from_bits_truncate(packet.c)), @@ -273,9 +273,7 @@ pub struct UserScheme { impl UserScheme { pub fn new(inner: Weak<UserInner>) -> UserScheme { - UserScheme { - inner: inner - } + UserScheme { inner } } } @@ -394,10 +392,10 @@ impl Scheme for UserScheme { inner.fmap.lock().insert(id, (context_lock, desc, *map)); let result = inner.call_inner(Packet { - id: id, + id, pid: pid.into(), - uid: uid, - gid: gid, + uid, + gid, a: SYS_FMAP, b: file, c: address, diff --git a/src/syscall/fs.rs b/src/syscall/fs.rs index c4bcc6c9..0e71fea8 100644 --- a/src/syscall/fs.rs +++ b/src/syscall/fs.rs @@ -29,12 +29,12 @@ pub fn file_op(a: usize, fd: FileHandle, c: usize, d: usize) -> Result<usize> { let mut packet = Packet { id: 0, pid: pid.into(), - uid: uid, - gid: gid, - a: a, + uid, + gid, + a, b: file.description.read().number, - c: c, - d: d + c, + d }; scheme.handle(&mut packet); @@ -406,8 +406,7 @@ pub fn frename(fd: FileHandle, path: &[u8]) -> Result<usize> { let contexts = context::contexts(); let context_lock = contexts.current().ok_or(Error::new(ESRCH))?; let context = context_lock.read(); - let file = context.get_file(fd).ok_or(Error::new(EBADF))?; - file + context.get_file(fd).ok_or(Error::new(EBADF))? }; let (path_canon, uid, gid, scheme_ns) = { diff --git a/src/syscall/process.rs b/src/syscall/process.rs index 45baf3b1..8493e866 100644 --- a/src/syscall/process.rs +++ b/src/syscall/process.rs @@ -149,7 +149,7 @@ pub fn clone(flags: CloneFlags, stack_base: usize) -> Result<ContextId> { // Change the return address of the child // (previously syscall) to the arch-specific // clone_ret callback - let func_ptr = new_stack.as_mut_ptr().offset(offset as isize); + let func_ptr = new_stack.as_mut_ptr().add(offset); *(func_ptr as *mut usize) = interrupt::syscall::clone_ret as usize; } @@ -1044,7 +1044,6 @@ pub fn fexec(fd: FileHandle, arg_ptrs: &[[usize; 2]], var_ptrs: &[[usize; 2]]) - // Argument must be moved into kernel space before exec unmaps all memory args.push(arg.to_vec().into_boxed_slice()); } - drop(arg_ptrs); let mut vars = Vec::new(); for var_ptr in var_ptrs { @@ -1052,7 +1051,9 @@ pub fn fexec(fd: FileHandle, arg_ptrs: &[[usize; 2]], var_ptrs: &[[usize; 2]]) - // Argument must be moved into kernel space before exec unmaps all memory vars.push(var.to_vec().into_boxed_slice()); } - drop(var_ptrs); + + // Neither arg_ptrs nor var_ptrs should be used after this point, the kernel + // now has owned copies in args and vars fexec_kernel(fd, args.into_boxed_slice(), vars.into_boxed_slice(), None) } @@ -1125,10 +1126,8 @@ pub fn exit(status: usize) -> ! { if let Some(parent_lock) = contexts.get(ppid) { let waitpid = { let mut parent = parent_lock.write(); - if vfork { - if ! parent.unblock() { - println!("{}: {} not blocked for exit vfork unblock", pid.into(), ppid.into()); - } + if vfork && ! parent.unblock() { + println!("{}: {} not blocked for exit vfork unblock", pid.into(), ppid.into()); } Arc::clone(&parent.waitpid) }; diff --git a/src/syscall/validate.rs b/src/syscall/validate.rs index beb13b05..53c8ef4a 100644 --- a/src/syscall/validate.rs +++ b/src/syscall/validate.rs @@ -28,6 +28,7 @@ fn validate(address: usize, size: usize, flags: EntryFlags) -> Result<()> { } /// Convert a pointer and length to slice, if valid +//TODO: Mark unsafe pub fn validate_slice<T>(ptr: *const T, len: usize) -> Result<&'static [T]> { if len == 0 { Ok(&[]) @@ -38,6 +39,7 @@ pub fn validate_slice<T>(ptr: *const T, len: usize) -> Result<&'static [T]> { } /// Convert a pointer and length to slice, if valid +//TODO: Mark unsafe pub fn validate_slice_mut<T>(ptr: *mut T, len: usize) -> Result<&'static mut [T]> { if len == 0 { Ok(&mut []) -- GitLab