From 9ee046b6f939cf15500b39d671a4bc9deda82bb1 Mon Sep 17 00:00:00 2001 From: Kevin Boos Date: Fri, 27 Oct 2023 19:02:05 -0700 Subject: [PATCH 1/5] Upgrade to latest Rust nightly v1.75 --- kernel/logger/src/lib.rs | 4 ++-- kernel/mod_mgmt/src/lib.rs | 24 +++++++++++++++++++----- rust-toolchain.toml | 2 +- tools/uefi_builder/aarch64/Cargo.lock | 4 ++-- tools/uefi_builder/common/Cargo.lock | 11 ++--------- tools/uefi_builder/x86_64/Cargo.lock | 4 ++-- 6 files changed, 28 insertions(+), 21 deletions(-) diff --git a/kernel/logger/src/lib.rs b/kernel/logger/src/lib.rs index 44499e6e89..75b7d9993f 100644 --- a/kernel/logger/src/lib.rs +++ b/kernel/logger/src/lib.rs @@ -20,7 +20,7 @@ extern crate sync_irq; extern crate serial_port_basic; use log::{Record, Level, Metadata, Log}; -use core::{borrow::Borrow, fmt::{self, Write}, ops::Deref}; +use core::{fmt::{self, Write}, ops::Deref}; use sync_irq::IrqSafeMutex; use serial_port_basic::SerialPort; use alloc::{sync::Arc, vec::Vec}; @@ -210,7 +210,7 @@ impl DummyLogger { fn write_fmt(&self, arguments: fmt::Arguments) -> fmt::Result { if let Some(logger) = &*LOGGER.lock() { for writer in logger.writers.iter() { - let _ = writer.deref().borrow().lock().write_fmt(arguments); + let _ = writer.deref().lock().write_fmt(arguments); } } else { let _ = EARLY_LOGGER.lock().write_fmt(arguments); diff --git a/kernel/mod_mgmt/src/lib.rs b/kernel/mod_mgmt/src/lib.rs index 737e1c3e3d..1e382226c5 100644 --- a/kernel/mod_mgmt/src/lib.rs +++ b/kernel/mod_mgmt/src/lib.rs @@ -1082,13 +1082,27 @@ impl CrateNamespace { return Err("not a relocatable elf file"); } - // If a `.theseus_merged` section exists, then the object file's sections have been merged by a partial relinking step. + // If a `.theseus_merged` section exists (it should come before any .text section), + // then the object file's sections have been merged by a partial relinking step. // If so, then we can use a much faster version of loading/linking. const THESEUS_MERGED_SEC_NAME: &str = ".theseus_merged"; - const THESEUS_MERGED_SEC_SHNDX: u16 = 1; - let sections_are_merged = elf_file.section_header(THESEUS_MERGED_SEC_SHNDX) - .map(|sec| sec.get_name(&elf_file) == Ok(THESEUS_MERGED_SEC_NAME)) - .unwrap_or(false); + let sections_are_merged = { + let mut found = false; + for sec_name in elf_file + .section_iter() + .filter_map(|sec| sec.get_name(&elf_file).ok()) + { + if sec_name == THESEUS_MERGED_SEC_NAME { + found = true; + break; + } + else if sec_name.starts_with(TEXT_SECTION_NAME) { + found = false; + break; + } + } + found + }; // Allocate enough space to load the sections let section_pages = allocate_section_pages(&elf_file, kernel_mmi_ref)?; diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 5fbcf5cc1e..088ea75c22 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,5 +1,5 @@ [toolchain] -channel = "nightly-2023-06-22" +channel = "nightly-2023-10-27" components = [ "rust-src", "clippy" ] ## Rustup always installs the host target by default, so we don't need to specify it here. ## All we need to specify is the uefi targets used to build our `uefi-bootloader`. diff --git a/tools/uefi_builder/aarch64/Cargo.lock b/tools/uefi_builder/aarch64/Cargo.lock index 1bfabe0256..3cc98f3b7e 100644 --- a/tools/uefi_builder/aarch64/Cargo.lock +++ b/tools/uefi_builder/aarch64/Cargo.lock @@ -481,9 +481,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.52" +version = "1.0.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d0e1ae9e836cc3beddd63db0df682593d7e2d3d891ae8c9083d2113e1744224" +checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9" dependencies = [ "unicode-ident", ] diff --git a/tools/uefi_builder/common/Cargo.lock b/tools/uefi_builder/common/Cargo.lock index 4bff603e8b..5560ddfd80 100644 --- a/tools/uefi_builder/common/Cargo.lock +++ b/tools/uefi_builder/common/Cargo.lock @@ -385,12 +385,6 @@ version = "6.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b7820b9daea5457c9f21c69448905d723fbd21136ccf521748f23fd49e723ee" -[[package]] -name = "ovmf-prebuilt" -version = "0.1.0-alpha.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa50141d081512ab30fd9e7e7692476866df5098b028536ad6680212e717fa8d" - [[package]] name = "proc-macro-error" version = "1.0.4" @@ -417,9 +411,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.49" +version = "1.0.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57a8eca9f9c4ffde41714334dee777596264c7825420f521abc92b5b5deb63a5" +checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9" dependencies = [ "unicode-ident", ] @@ -530,7 +524,6 @@ dependencies = [ "clap", "fatfs", "gpt", - "ovmf-prebuilt", "tempfile", ] diff --git a/tools/uefi_builder/x86_64/Cargo.lock b/tools/uefi_builder/x86_64/Cargo.lock index 10dea21aa4..469d3af8e2 100644 --- a/tools/uefi_builder/x86_64/Cargo.lock +++ b/tools/uefi_builder/x86_64/Cargo.lock @@ -481,9 +481,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.52" +version = "1.0.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d0e1ae9e836cc3beddd63db0df682593d7e2d3d891ae8c9083d2113e1744224" +checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9" dependencies = [ "unicode-ident", ] From 2cda74032b93608731ade47c2a82459a2d313c9b Mon Sep 17 00:00:00 2001 From: Klimenty Tsoutsman Date: Sat, 28 Oct 2023 13:27:06 +1100 Subject: [PATCH 2/5] Fix clippy warnings Signed-off-by: Klimenty Tsoutsman --- Cargo.lock | 38 ++++++++++++++---------- applications/hull/src/builtin.rs | 2 +- applications/loadc/src/lib.rs | 2 +- applications/ping/src/lib.rs | 2 +- applications/serial_echo/src/lib.rs | 2 +- applications/shell/src/lib.rs | 2 +- kernel/frame_allocator/src/lib.rs | 6 ++-- kernel/framebuffer_compositor/src/lib.rs | 7 ++--- kernel/gdt/Cargo.toml | 2 +- kernel/mod_mgmt/src/lib.rs | 2 +- kernel/net/src/lib.rs | 2 +- kernel/scheduler_priority/src/lib.rs | 12 ++++---- kernel/spawn/src/lib.rs | 2 +- kernel/thread_local_macro/src/lib.rs | 6 ++-- kernel/wasi_interpreter/src/lib.rs | 2 +- kernel/window_manager/src/lib.rs | 2 +- 16 files changed, 47 insertions(+), 44 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c3b9f24bad..67f3ce939f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -177,7 +177,7 @@ dependencies = [ name = "ata" version = "0.1.0" dependencies = [ - "bitflags", + "bitflags 1.3.2", "interrupts", "io", "log", @@ -282,6 +282,12 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "bitflags" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" + [[package]] name = "block-buffer" version = "0.10.3" @@ -337,7 +343,7 @@ dependencies = [ name = "boot_info" version = "0.1.0" dependencies = [ - "bitflags", + "bitflags 1.3.2", "kernel_config", "memory_structs", "multiboot2", @@ -652,7 +658,7 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bd420c52d86c5b08c494e7e3d16bce23f08f3f6544cccce2d6cc986d3144dca1" dependencies = [ - "bitflags", + "bitflags 1.3.2", ] [[package]] @@ -838,7 +844,7 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3a0ae7494d9bff013d7b89471f4c424356a71e9752e0c78abe7e6c608a16bb3" dependencies = [ - "bitflags", + "bitflags 1.3.2", "defmt-macros", ] @@ -1142,7 +1148,7 @@ name = "fatfs" version = "0.4.0" source = "git+https://github.com/rafalh/rust-fatfs#87fc1ed5074a32b4e0344fcdde77359ef9e75432" dependencies = [ - "bitflags", + "bitflags 1.3.2", "log", ] @@ -1338,7 +1344,7 @@ version = "0.1.0" dependencies = [ "atomic_linked_list", "bit_field 0.7.0", - "bitflags", + "bitflags 2.4.1", "cpu", "log", "memory", @@ -1663,7 +1669,7 @@ dependencies = [ name = "iommu" version = "0.1.0" dependencies = [ - "bitflags", + "bitflags 1.3.2", "log", "memory", "spin 0.9.4", @@ -1749,7 +1755,7 @@ dependencies = [ name = "keycodes_ascii" version = "0.1.0" dependencies = [ - "bitflags", + "bitflags 1.3.2", "num_enum", ] @@ -2010,7 +2016,7 @@ version = "0.1.0" dependencies = [ "atomic_linked_list", "bit_field 0.7.0", - "bitflags", + "bitflags 1.3.2", "boot_info", "frame_allocator", "kernel_config", @@ -2252,7 +2258,7 @@ version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6170b6f12ea75d8d0f5621e3ed780b041a666c4a5b904c77261fe343d0e798d" dependencies = [ - "bitflags", + "bitflags 1.3.2", ] [[package]] @@ -2826,7 +2832,7 @@ dependencies = [ name = "pte_flags" version = "0.1.0" dependencies = [ - "bitflags", + "bitflags 1.3.2", "cfg-if 1.0.0", ] @@ -2928,7 +2934,7 @@ version = "10.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a6823ea29436221176fe662da99998ad3b4db2c7f31e7b6f5fe43adccd6320bb" dependencies = [ - "bitflags", + "bitflags 1.3.2", ] [[package]] @@ -2969,7 +2975,7 @@ checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244" name = "region" version = "3.0.0" dependencies = [ - "bitflags", + "bitflags 1.3.2", "core2", "libc", "mach", @@ -3417,7 +3423,7 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8d2e3a36ac8fea7b94e666dfa3871063d6e0a5c9d5d4fec9a1a6b7b6760f0229" dependencies = [ - "bitflags", + "bitflags 1.3.2", "byteorder", "cfg-if 1.0.0", "defmt", @@ -3959,7 +3965,7 @@ dependencies = [ name = "text_terminal" version = "0.1.0" dependencies = [ - "bitflags", + "bitflags 1.3.2", "core2", "derive_more", "event_types", @@ -4670,7 +4676,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "958cd5cb28e720db2f59ee9dc4235b5f82a183d079fb0e6caf43ad074cfdc66a" dependencies = [ "bit_field 0.10.1", - "bitflags", + "bitflags 1.3.2", "rustversion", "volatile 0.4.4", ] diff --git a/applications/hull/src/builtin.rs b/applications/hull/src/builtin.rs index 436d6a6c7b..265f608a05 100644 --- a/applications/hull/src/builtin.rs +++ b/applications/hull/src/builtin.rs @@ -135,7 +135,7 @@ impl Shell { // TODO: Sort IDs. for (id, job) in self.jobs.lock().iter() { // TODO: Separate job parts if they are in different states. - let Some(state) = &job.parts.get(0).map(|part| &part.state) else { + let Some(state) = &job.parts.first().map(|part| &part.state) else { continue; }; let line = &job.string; diff --git a/applications/loadc/src/lib.rs b/applications/loadc/src/lib.rs index c9ee6b1dde..9634fa7d08 100644 --- a/applications/loadc/src/lib.rs +++ b/applications/loadc/src/lib.rs @@ -71,7 +71,7 @@ fn rmain(matches: Matches) -> Result { ) ).map_err(|_| String::from("failed to get current task"))?; - let path = matches.free.get(0).ok_or_else(|| "Missing path to ELF executable".to_string())?; + let path = matches.free.first().ok_or_else(|| "Missing path to ELF executable".to_string())?; let path = Path::new(path.clone()); let file_ref = path.get_file(&curr_wd) .ok_or_else(|| format!("Failed to access file at {path:?}"))?; diff --git a/applications/ping/src/lib.rs b/applications/ping/src/lib.rs index cd00999fa7..dd5e53523b 100644 --- a/applications/ping/src/lib.rs +++ b/applications/ping/src/lib.rs @@ -67,7 +67,7 @@ pub fn main(args: Vec) -> isize { } fn _main(matches: Matches) -> Result<(), &'static str> { - let remote = IpAddress::from_str(matches.free.get(0).ok_or("no arguments_provided")?) + let remote = IpAddress::from_str(matches.free.first().ok_or("no arguments_provided")?) .map_err(|_| "invalid argument")?; let interface = net::get_default_interface().ok_or("no network interfaces available")?; diff --git a/applications/serial_echo/src/lib.rs b/applications/serial_echo/src/lib.rs index 2a9c52b48d..2cf4f21660 100644 --- a/applications/serial_echo/src/lib.rs +++ b/applications/serial_echo/src/lib.rs @@ -25,7 +25,7 @@ use serial_port::{SerialPort, SerialPortAddress, get_serial_port}; pub fn main(args: Vec) -> isize { - let serial_port_address = args.get(0) + let serial_port_address = args.first() .and_then(|s| SerialPortAddress::try_from(&**s).ok()) .unwrap_or(SerialPortAddress::COM1); diff --git a/applications/shell/src/lib.rs b/applications/shell/src/lib.rs index 748f7ec303..c60211f11d 100644 --- a/applications/shell/src/lib.rs +++ b/applications/shell/src/lib.rs @@ -792,7 +792,7 @@ impl Shell { /// Try to match the incomplete command against all internal commands. Returns a /// vector that contains all matching results. fn find_internal_cmd_match(&mut self, incomplete_cmd: &String) -> Result, &'static str> { - let internal_cmds = vec!["fg", "bg", "jobs", "clear"]; + let internal_cmds = ["fg", "bg", "jobs", "clear"]; let mut match_cmds = Vec::new(); for cmd in internal_cmds.iter() { if cmd.starts_with(incomplete_cmd) { diff --git a/kernel/frame_allocator/src/lib.rs b/kernel/frame_allocator/src/lib.rs index 2bc3a5de4a..90d46b3091 100644 --- a/kernel/frame_allocator/src/lib.rs +++ b/kernel/frame_allocator/src/lib.rs @@ -1196,13 +1196,13 @@ pub fn allocate_frames_deferred( // because we are searching the general frames list, it doesn't matter if part of the chunk was found // since we only create new reserved frames. trace!("Only part of the requested allocation was found in the general frames list."); - return Err(alloc_err).map_err(From::from); + return Err(From::from(alloc_err)); } - Err(_other) => return Err(alloc_err).map_err(From::from), + Err(_other) => return Err(From::from(alloc_err)), } }, AllocationError::ContiguousChunkNotFound(f, numf) => (f, numf), - _ => return Err(alloc_err).map_err(From::from), + _ => return Err(From::from(alloc_err)), } }; diff --git a/kernel/framebuffer_compositor/src/lib.rs b/kernel/framebuffer_compositor/src/lib.rs index 391efeef39..5b7780a59f 100644 --- a/kernel/framebuffer_compositor/src/lib.rs +++ b/kernel/framebuffer_compositor/src/lib.rs @@ -29,7 +29,7 @@ extern crate shapes; use alloc::collections::BTreeMap; use alloc::vec::{Vec}; -use core::hash::{Hash, Hasher, BuildHasher}; +use core::hash::{Hash, BuildHasher}; use hashbrown::hash_map::{DefaultHashBuilder}; use compositor::{Compositor, FramebufferUpdates, CompositableRegion}; use framebuffer::{Framebuffer, Pixel}; @@ -268,8 +268,5 @@ impl Compositor for FrameCompositor { /// Gets the hash of an item fn hash(item: T) -> u64 { - let builder = DefaultHashBuilder::default(); - let mut hasher = builder.build_hasher(); - item.hash(&mut hasher); - hasher.finish() + DefaultHashBuilder::default().hash_one(&item) } diff --git a/kernel/gdt/Cargo.toml b/kernel/gdt/Cargo.toml index d20598ebe7..216652e635 100644 --- a/kernel/gdt/Cargo.toml +++ b/kernel/gdt/Cargo.toml @@ -9,7 +9,7 @@ edition = "2021" spin = "0.9.4" x86_64 = "0.14.8" bit_field = "0.7.0" -bitflags = "1.1.0" +bitflags = "2.4.1" log = "0.4.8" [dependencies.atomic_linked_list] diff --git a/kernel/mod_mgmt/src/lib.rs b/kernel/mod_mgmt/src/lib.rs index 1e382226c5..7320fce6d2 100644 --- a/kernel/mod_mgmt/src/lib.rs +++ b/kernel/mod_mgmt/src/lib.rs @@ -141,7 +141,7 @@ fn parse_bootloader_modules_into_files( // Closure to create the directory for a new namespace. let create_dir = |dir_name: &str| -> Result { - VFSDirectory::create(dir_name.to_string(), &namespaces_dir).map(|d| NamespaceDir(d)) + VFSDirectory::create(dir_name.to_string(), &namespaces_dir).map(NamespaceDir) }; let mut process_module = |name: &str, size, pages| -> Result<_, &'static str> { diff --git a/kernel/net/src/lib.rs b/kernel/net/src/lib.rs index ea8b632b6e..1760150fef 100644 --- a/kernel/net/src/lib.rs +++ b/kernel/net/src/lib.rs @@ -63,7 +63,7 @@ pub fn get_interfaces() -> &'static Mutex>> { /// Returns the first available interface. pub fn get_default_interface() -> Option> { - NETWORK_INTERFACES.lock().get(0).cloned() + NETWORK_INTERFACES.lock().first().cloned() } /// Returns a port in the range reserved for private, dynamic, and ephemeral diff --git a/kernel/scheduler_priority/src/lib.rs b/kernel/scheduler_priority/src/lib.rs index 1c11e6b6b8..85107ac951 100644 --- a/kernel/scheduler_priority/src/lib.rs +++ b/kernel/scheduler_priority/src/lib.rs @@ -144,16 +144,16 @@ impl PartialEq for PriorityTaskRef { impl PartialOrd for PriorityTaskRef { fn partial_cmp(&self, other: &Self) -> Option { - match self.priority.cmp(&other.priority) { - // Tasks that were ran longer ago should be prioritised. - Ordering::Equal => Some(self.last_ran.cmp(&other.last_ran).reverse()), - ordering => Some(ordering), - } + Some(self.cmp(other)) } } impl Ord for PriorityTaskRef { fn cmp(&self, other: &Self) -> core::cmp::Ordering { - self.priority.cmp(&other.priority) + match self.priority.cmp(&other.priority) { + // Tasks that were ran longer ago should be prioritised. + Ordering::Equal => self.last_ran.cmp(&other.last_ran).reverse(), + ordering => ordering, + } } } diff --git a/kernel/spawn/src/lib.rs b/kernel/spawn/src/lib.rs index d0ff408b87..0ee33c4a99 100755 --- a/kernel/spawn/src/lib.rs +++ b/kernel/spawn/src/lib.rs @@ -889,7 +889,7 @@ fn task_cleanup_final_internal(current_task: &ExitableTaskRef) { // that were lazily initialized during this execution of this task. for tls_dtor in thread_local_macro::take_current_tls_destructors().into_iter() { unsafe { - (tls_dtor.dtor)(tls_dtor.object_ptr as *mut u8); + (tls_dtor.dtor)(tls_dtor.object_ptr); } } diff --git a/kernel/thread_local_macro/src/lib.rs b/kernel/thread_local_macro/src/lib.rs index f3ccf2b2ac..3e0104da97 100644 --- a/kernel/thread_local_macro/src/lib.rs +++ b/kernel/thread_local_macro/src/lib.rs @@ -95,9 +95,9 @@ fn register_dtor(object_ptr: *mut u8, dtor: unsafe extern "C" fn(*mut u8)) { } -////////////////////////////////////////////////////////////////////////////////////// -//// Everything below here is a modified version of thread_local!() from Rust std //// -////////////////////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////////////// +// Everything below here is a modified version of thread_local!() from Rust std // +////////////////////////////////////////////////////////////////////////////////// use core::cell::{Cell, UnsafeCell}; use core::fmt; diff --git a/kernel/wasi_interpreter/src/lib.rs b/kernel/wasi_interpreter/src/lib.rs index 3441239ecc..88ab2b95a5 100644 --- a/kernel/wasi_interpreter/src/lib.rs +++ b/kernel/wasi_interpreter/src/lib.rs @@ -80,7 +80,7 @@ impl Externals for HostExternals { /// pub fn execute_binary(wasm_binary: Vec, args: Vec, preopen_dirs: Vec) -> isize { // Load wasm binary and prepare it for instantiation. - let module = Module::from_buffer(&wasm_binary).unwrap(); + let module = Module::from_buffer(wasm_binary).unwrap(); // Construct wasmi WebAssembly state machine. let state_machine = wasmi_state_machine::ProcessStateMachine::new( diff --git a/kernel/window_manager/src/lib.rs b/kernel/window_manager/src/lib.rs index 39d4ec8103..4dac069a9a 100644 --- a/kernel/window_manager/src/lib.rs +++ b/kernel/window_manager/src/lib.rs @@ -493,7 +493,7 @@ impl WindowManager { bottom_right: self.mouse + (MOUSE_POINTER_SIZE_X as isize, MOUSE_POINTER_SIZE_Y as isize) }); - self.refresh_top(bounding_box.into_iter()) + self.refresh_top(bounding_box) } /// Move mouse. `relative` indicates the new position relative to current position. From 254ba6505fe58e6622801cabf5454032979ef1b9 Mon Sep 17 00:00:00 2001 From: Klimenty Tsoutsman Date: Sat, 28 Oct 2023 13:39:04 +1100 Subject: [PATCH 3/5] Fix merged clippy warnings Signed-off-by: Klimenty Tsoutsman --- kernel/path/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/path/src/lib.rs b/kernel/path/src/lib.rs index 3791ee497a..6bf49fa80a 100644 --- a/kernel/path/src/lib.rs +++ b/kernel/path/src/lib.rs @@ -397,8 +397,8 @@ impl Path { } (None, _) => comps.push(Component::ParentDir), (Some(a), Some(b)) if comps.is_empty() && a == b => (), - (Some(a), Some(b)) if b == Component::CurDir => comps.push(a), - (Some(_), Some(b)) if b == Component::ParentDir => return None, + (Some(a), Some(Component::CurDir)) => comps.push(a), + (Some(_), Some(Component::ParentDir)) => return None, (Some(a), Some(_)) => { comps.push(Component::ParentDir); for _ in itb { From 984e780e83d6f682d1990d3bc5badf221aa713db Mon Sep 17 00:00:00 2001 From: Klimenty Tsoutsman Date: Sat, 28 Oct 2023 13:53:17 +1100 Subject: [PATCH 4/5] Fix `bitflags` clippy warnings Signed-off-by: Klimenty Tsoutsman --- Cargo.lock | 14 +++++++------- kernel/ata/Cargo.toml | 2 +- kernel/ata/src/lib.rs | 3 +++ kernel/boot_info/Cargo.toml | 2 +- kernel/iommu/Cargo.toml | 2 +- kernel/iommu/src/regs.rs | 1 + kernel/memory/Cargo.toml | 2 +- kernel/pte_flags/Cargo.toml | 2 +- kernel/pte_flags/src/lib.rs | 5 +++-- kernel/pte_flags/src/pte_flags_aarch64.rs | 23 ++++++++++++----------- kernel/pte_flags/src/pte_flags_x86_64.rs | 7 ++++--- kernel/text_terminal/Cargo.toml | 2 +- kernel/text_terminal/src/ansi_style.rs | 2 +- libs/keycodes_ascii/Cargo.toml | 2 +- libs/keycodes_ascii/src/lib.rs | 1 + 15 files changed, 39 insertions(+), 31 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 816e389cba..35c2f6ea2c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -177,7 +177,7 @@ dependencies = [ name = "ata" version = "0.1.0" dependencies = [ - "bitflags 1.3.2", + "bitflags 2.4.1", "interrupts", "io", "log", @@ -343,7 +343,7 @@ dependencies = [ name = "boot_info" version = "0.1.0" dependencies = [ - "bitflags 1.3.2", + "bitflags 2.4.1", "kernel_config", "memory_structs", "multiboot2", @@ -1669,7 +1669,7 @@ dependencies = [ name = "iommu" version = "0.1.0" dependencies = [ - "bitflags 1.3.2", + "bitflags 2.4.1", "log", "memory", "spin 0.9.4", @@ -1755,7 +1755,7 @@ dependencies = [ name = "keycodes_ascii" version = "0.1.0" dependencies = [ - "bitflags 1.3.2", + "bitflags 2.4.1", "num_enum", ] @@ -2016,7 +2016,7 @@ version = "0.1.0" dependencies = [ "atomic_linked_list", "bit_field 0.7.0", - "bitflags 1.3.2", + "bitflags 2.4.1", "boot_info", "frame_allocator", "kernel_config", @@ -2828,7 +2828,7 @@ dependencies = [ name = "pte_flags" version = "0.1.0" dependencies = [ - "bitflags 1.3.2", + "bitflags 2.4.1", "cfg-if 1.0.0", ] @@ -3961,7 +3961,7 @@ dependencies = [ name = "text_terminal" version = "0.1.0" dependencies = [ - "bitflags 1.3.2", + "bitflags 2.4.1", "core2", "derive_more", "event_types", diff --git a/kernel/ata/Cargo.toml b/kernel/ata/Cargo.toml index 2c5b978dc4..663f7805ad 100644 --- a/kernel/ata/Cargo.toml +++ b/kernel/ata/Cargo.toml @@ -6,7 +6,7 @@ version = "0.1.0" edition = "2018" [dependencies] -bitflags = "1.1.0" +bitflags = "2.4.1" log = "0.4.8" spin = "0.9.4" x86_64 = "0.14.8" diff --git a/kernel/ata/src/lib.rs b/kernel/ata/src/lib.rs index 0742ca585d..8c98a90807 100644 --- a/kernel/ata/src/lib.rs +++ b/kernel/ata/src/lib.rs @@ -41,6 +41,7 @@ const PCI_BAR_PORT_MASK: u16 = 0xFFFC; bitflags! { /// The possible error values found in an ATA drive's error port. + #[derive(Clone, Copy, Debug, Eq, PartialEq)] pub struct AtaError: u8 { const BAD_BLOCK = 0x80; const UNCORRECTABLE_DATA = 0x40; @@ -55,6 +56,7 @@ bitflags! { bitflags! { /// The possible status values found in an ATA drive's status port. + #[derive(Clone, Copy, Debug, Eq, PartialEq)] pub struct AtaStatus: u8 { /// When set, the drive's port values are still changing, so ports shouldn't be accessed. const BUSY = 0x80; @@ -73,6 +75,7 @@ bitflags! { bitflags! { /// The possible control values used in an ATA drive's status port. + #[derive(Clone, Copy, Debug, Eq, PartialEq)] struct AtaControl: u8 { /// Set this to read back the High Order Byte of the last-written LBA48 value. const HOB = 0x80; diff --git a/kernel/boot_info/Cargo.toml b/kernel/boot_info/Cargo.toml index 835a0ce11a..ef6e2bf3f8 100644 --- a/kernel/boot_info/Cargo.toml +++ b/kernel/boot_info/Cargo.toml @@ -6,7 +6,7 @@ description = "Abstraction over multiboot2 and UEFI boot information" edition = "2021" [dependencies] -bitflags = "1.3" +bitflags = "2.4.1" kernel_config = { path = "../kernel_config" } memory_structs = { path = "../memory_structs" } multiboot2 = { version = "0.14", optional = true } diff --git a/kernel/iommu/Cargo.toml b/kernel/iommu/Cargo.toml index c2672f185f..17d5a6c902 100644 --- a/kernel/iommu/Cargo.toml +++ b/kernel/iommu/Cargo.toml @@ -9,7 +9,7 @@ log = "0.4.8" spin = "0.9.4" volatile = "0.2.7" zerocopy = "0.5.0" -bitflags = "1.3.2" +bitflags = "2.4.1" [dependencies.sync_irq] path = "../../libs/sync_irq" diff --git a/kernel/iommu/src/regs.rs b/kernel/iommu/src/regs.rs index 52e169cbdb..277e21a38e 100644 --- a/kernel/iommu/src/regs.rs +++ b/kernel/iommu/src/regs.rs @@ -183,6 +183,7 @@ bitflags! { /// /// The least significant bits `[22:0]` are `RsvdZ`, /// meaning that they are reserved for future usage and must be set to 0. + #[derive(Clone, Copy, Debug, Eq, PartialEq)] pub struct GlobalStatus: u32 { /// Compatibility Format Interrupt Status const CFIS = 1 << 23; diff --git a/kernel/memory/Cargo.toml b/kernel/memory/Cargo.toml index e88940a918..899e8abaa0 100644 --- a/kernel/memory/Cargo.toml +++ b/kernel/memory/Cargo.toml @@ -7,7 +7,7 @@ edition = "2021" [dependencies] spin = "0.9.4" -bitflags = "1.1.0" +bitflags = "2.4.1" xmas-elf = { version = "0.6.2", git = "https://github.com/theseus-os/xmas-elf.git" } bit_field = "0.7.0" zerocopy = "0.5.0" diff --git a/kernel/pte_flags/Cargo.toml b/kernel/pte_flags/Cargo.toml index 27605766da..e9a7cdd086 100644 --- a/kernel/pte_flags/Cargo.toml +++ b/kernel/pte_flags/Cargo.toml @@ -7,4 +7,4 @@ edition = "2021" [dependencies] cfg-if = "1.0.0" -bitflags = "1.3.2" +bitflags = "2.4.1" diff --git a/kernel/pte_flags/src/lib.rs b/kernel/pte_flags/src/lib.rs index bd499b84f6..65a87fac12 100644 --- a/kernel/pte_flags/src/lib.rs +++ b/kernel/pte_flags/src/lib.rs @@ -64,6 +64,7 @@ bitflags! { /// /// This type can also be converted *from* `PteFlagsX86_64` and `PteFlagsAarch64`, /// but it may be lossy as only the bit flags defined herein are preserved. + #[derive(Clone, Copy, Debug, Eq, PartialEq)] pub struct PteFlags: u64 { /// * If set, this page is currently "present" in memory. /// * If not set, this page is not in memory, which could mean one of several things: @@ -184,8 +185,8 @@ impl PteFlags { /// that we don't care about. pub const fn new() -> Self { Self::from_bits_truncate( - Self::ACCESSED.bits - | Self::NOT_EXECUTABLE.bits + Self::ACCESSED.bits() + | Self::NOT_EXECUTABLE.bits() ) } diff --git a/kernel/pte_flags/src/pte_flags_aarch64.rs b/kernel/pte_flags/src/pte_flags_aarch64.rs index 00ff1d6a6a..3204731b61 100644 --- a/kernel/pte_flags/src/pte_flags_aarch64.rs +++ b/kernel/pte_flags/src/pte_flags_aarch64.rs @@ -33,6 +33,7 @@ bitflags! { /// /// [MAIR]: https://docs.rs/cortex-a/latest/cortex_a/registers/MAIR_EL1/index.html #[doc(cfg(target_arch = "aarch64"))] + #[derive(Clone, Copy, Debug, Eq, PartialEq)] pub struct PteFlagsAarch64: u64 { /// * If set, this page is currently "present" in memory. /// * If not set, this page is not in memory, which could mean one of several things: @@ -52,7 +53,7 @@ bitflags! { /// This page maps "normal" memory, i.e., non-device memory. /// /// Theseus uses `MAIR_INDEX_0` for this type of memory. - const NORMAL_MEMORY = Self::_MAIR_INDEX_0.bits; + const NORMAL_MEMORY = Self::_MAIR_INDEX_0.bits(); /// Indicates the page's cacheability is described by MAIR Index 1. /// /// Theseus uses this index for "device" memory. @@ -60,7 +61,7 @@ bitflags! { /// This page maps device memory, i.e., memory-mapped I/O registers. /// /// Theseus uses `MAIR_INDEX_1` for this type of memory. - const DEVICE_MEMORY = Self::_MAIR_INDEX_1.bits; + const DEVICE_MEMORY = Self::_MAIR_INDEX_1.bits(); /// Indicates the page's cacheability is described by MAIR Index 2. /// /// This is unused in Theseus. @@ -179,7 +180,7 @@ bitflags! { const _USER_EXEC_NEVER = 1 << 54; /// * If set, this page is not executable. /// * If not set, this page is executable. - const NOT_EXECUTABLE = Self::_PRIV_EXEC_NEVER.bits | Self::_USER_EXEC_NEVER.bits; + const NOT_EXECUTABLE = Self::_PRIV_EXEC_NEVER.bits() | Self::_USER_EXEC_NEVER.bits(); /// See [PteFlags::EXCLUSIVE]. /// We use bit 55 because it is available for custom OS usage on both x86_64 and aarch64. @@ -217,13 +218,13 @@ impl PteFlagsAarch64 { /// that we don't care about. pub const fn new() -> Self { Self::from_bits_truncate( - Self::NORMAL_MEMORY.bits - | Self::OUTER_SHAREABLE.bits - | Self::READ_ONLY.bits - | Self::PAGE_DESCRIPTOR.bits - | Self::ACCESSED.bits - | Self::_NOT_GLOBAL.bits - | Self::NOT_EXECUTABLE.bits + Self::NORMAL_MEMORY.bits() + | Self::OUTER_SHAREABLE.bits() + | Self::READ_ONLY.bits() + | Self::PAGE_DESCRIPTOR.bits() + | Self::ACCESSED.bits() + | Self::_NOT_GLOBAL.bits() + | Self::NOT_EXECUTABLE.bits() ) } @@ -361,7 +362,7 @@ impl PteFlagsAarch64 { /// * The three bits `[2:4]` for MAIR index values. /// * The two bits `[8:9]` for shareability. pub const MASKED_BITS_FOR_CONVERSION: PteFlagsAarch64 = PteFlagsAarch64::from_bits_truncate( - SHAREABLE_BITS_MASK.bits | MAIR_BITS_MASK.bits + SHAREABLE_BITS_MASK.bits() | MAIR_BITS_MASK.bits() ); /// Returns a copy of this `PteFlagsAarch64` with its flags adjusted diff --git a/kernel/pte_flags/src/pte_flags_x86_64.rs b/kernel/pte_flags/src/pte_flags_x86_64.rs index d8c0ffc568..c47a6880d0 100644 --- a/kernel/pte_flags/src/pte_flags_x86_64.rs +++ b/kernel/pte_flags/src/pte_flags_x86_64.rs @@ -22,6 +22,7 @@ bitflags! { /// * Bits `[52:62]` (inclusive) are available for custom OS usage. /// * Bit `63` is reserved by hardware for access flags (noexec). #[doc(cfg(target_arch = "x86_64"))] + #[derive(Clone, Copy, Debug, Eq, PartialEq)] pub struct PteFlagsX86_64: u64 { /// * If set, this page is currently "present" in memory. /// * If not set, this page is not in memory, which could mean one of several things: @@ -49,7 +50,7 @@ bitflags! { /// that index is used to determine the PAT entry that holds the /// memory caching type that is applied to this page. const WRITE_THROUGH = 1 << 3; - const PAT_BIT0 = Self::WRITE_THROUGH.bits; + const PAT_BIT0 = Self::WRITE_THROUGH.bits(); /// * If set, this page's content is never cached, neither for read nor writes. /// * If not set, this page's content is cached as normal, both for read nor writes. @@ -60,8 +61,8 @@ bitflags! { /// memory caching type that is applied to this page. const CACHE_DISABLE = 1 << 4; /// An alias for [`Self::CACHE_DISABLE`] in order to ease compatibility with aarch64. - const DEVICE_MEMORY = Self::CACHE_DISABLE.bits; - const PAT_BIT1 = Self::CACHE_DISABLE.bits; + const DEVICE_MEMORY = Self::CACHE_DISABLE.bits(); + const PAT_BIT1 = Self::CACHE_DISABLE.bits(); /// * The hardware will set this bit when the page is accessed. /// * The OS can then clear this bit once it has acknowledged that the page was accessed, diff --git a/kernel/text_terminal/Cargo.toml b/kernel/text_terminal/Cargo.toml index a79b5af16d..95ab31da2f 100644 --- a/kernel/text_terminal/Cargo.toml +++ b/kernel/text_terminal/Cargo.toml @@ -5,7 +5,7 @@ authors = ["Kevin Boos "] description = "A text-based terminal emulator that supports ANSI, VT100, xterm, and other standards." [dependencies] -bitflags = "1.1.0" +bitflags = "2.4.1" core2 = { version = "0.4.0", default-features = false, features = ["alloc", "nightly"] } unicode-width = "0.1.8" vte = "0.10.1" diff --git a/kernel/text_terminal/src/ansi_style.rs b/kernel/text_terminal/src/ansi_style.rs index e2913f4755..1178c0fe38 100644 --- a/kernel/text_terminal/src/ansi_style.rs +++ b/kernel/text_terminal/src/ansi_style.rs @@ -419,7 +419,7 @@ bitflags! { /// /// This set of flags is completely self-contained within each `Unit` /// and does not need to reference any previous `Unit`'s flag as an anchor. - #[derive(Default)] + #[derive(Clone, Copy, Debug, Default, Eq, PartialEq)] pub struct FormatFlags: u8 { /// If set, this character is displayed in a bright color, which is sometimes called "bold". const BRIGHT = 1 << 0; diff --git a/libs/keycodes_ascii/Cargo.toml b/libs/keycodes_ascii/Cargo.toml index 5b12474c42..4414cc2ba2 100644 --- a/libs/keycodes_ascii/Cargo.toml +++ b/libs/keycodes_ascii/Cargo.toml @@ -8,7 +8,7 @@ license = "MIT" edition = "2021" [dependencies] -bitflags = "1.1.0" +bitflags = "2.4.1" [dependencies.num_enum] version = "0.5.7" diff --git a/libs/keycodes_ascii/src/lib.rs b/libs/keycodes_ascii/src/lib.rs index 2c43634191..7d3c87c2ba 100644 --- a/libs/keycodes_ascii/src/lib.rs +++ b/libs/keycodes_ascii/src/lib.rs @@ -12,6 +12,7 @@ bitflags! { /// To save space, this is expressed using bitflags /// rather than a series of individual booleans, /// because Rust's `bool` type is a whole byte. + #[derive(Clone, Copy, Debug, Eq, PartialEq)] pub struct KeyboardModifiers: u16 { const CONTROL_LEFT = 1 << 0; const CONTROL_RIGHT = 1 << 1; From 9810d8005a439d6c566cc6c88f8e5e8020eed101 Mon Sep 17 00:00:00 2001 From: Kevin Boos Date: Mon, 30 Oct 2023 14:52:04 -0700 Subject: [PATCH 5/5] allow internal_features --- kernel/panic_entry/src/lib.rs | 1 + kernel/thread_local_macro/src/lib.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/kernel/panic_entry/src/lib.rs b/kernel/panic_entry/src/lib.rs index 95dee82617..68a6416703 100644 --- a/kernel/panic_entry/src/lib.rs +++ b/kernel/panic_entry/src/lib.rs @@ -6,6 +6,7 @@ #![no_std] #![feature(alloc_error_handler)] +#![allow(internal_features)] #![feature(lang_items)] #![feature(panic_info_message)] diff --git a/kernel/thread_local_macro/src/lib.rs b/kernel/thread_local_macro/src/lib.rs index 3e0104da97..e59ae985c3 100644 --- a/kernel/thread_local_macro/src/lib.rs +++ b/kernel/thread_local_macro/src/lib.rs @@ -29,6 +29,7 @@ #![no_std] #![feature(thread_local)] +#![allow(internal_features)] #![feature(allow_internal_unstable)] // The code from Rust std uses unsafe blocks within unsafe functions,