From 2bbb2b7079f6c97f2cb2d6628fd96595a7e90877 Mon Sep 17 00:00:00 2001 From: llenotre Date: Thu, 19 Sep 2024 21:18:27 +0200 Subject: [PATCH] chore: update rust toolchain --- .github/workflows/check.yml | 8 ++++---- kernel/src/acpi/data.rs | 6 ++++-- kernel/src/cmdline.rs | 2 +- kernel/src/crypto/chacha20.rs | 27 +++++++++++++++------------ kernel/src/elf/relocation.rs | 2 +- kernel/src/file/fs/kernfs.rs | 12 +++++++----- kernel/src/file/fs/proc/mod.rs | 2 +- kernel/src/kernel.rs | 2 -- kernel/src/module/mod.rs | 3 +-- kernel/src/panic.rs | 4 +--- kernel/src/process/tss.rs | 9 +++++---- rust-toolchain.toml | 2 +- utils/src/cpio.rs | 2 +- utils/src/ptr/arc.rs | 2 +- 14 files changed, 43 insertions(+), 40 deletions(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 4d1d77be..af4555c3 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -7,18 +7,18 @@ jobs: - uses: actions/checkout@v4 - name: Macros working-directory: macros - run: cargo clippy --all-features --tests + run: cargo clippy --all-features --all-targets - name: Utils working-directory: utils - run: cargo clippy --all-features --tests + run: cargo clippy --all-features --all-targets - name: Kernel working-directory: kernel run: | cp default.build-config.toml build-config.toml - cargo clippy --all-features --tests + cargo clippy --all-features --all-targets - name: Integration tests working-directory: inttest - run: cargo clippy --all-features --tests + run: cargo clippy --all-features --all-targets format: runs-on: [self-hosted, linux] needs: clippy diff --git a/kernel/src/acpi/data.rs b/kernel/src/acpi/data.rs index e93e0e0b..bc044b3b 100644 --- a/kernel/src/acpi/data.rs +++ b/kernel/src/acpi/data.rs @@ -155,7 +155,8 @@ impl ACPIData { (self .data .as_ptr() - .add(*entries_ptr.add(i) as usize - self.off) as usize) as *const ACPITableHeader + .add(*entries_ptr.add(i) as usize - self.off) as usize) + as *const ACPITableHeader }; let header = unsafe { &*header_ptr }; @@ -199,7 +200,8 @@ impl ACPIData { (self .data .as_ptr() - .add(*entries_ptr.add(i) as usize - self.off) as usize) as *const ACPITableHeader + .add(*entries_ptr.add(i) as usize - self.off) as usize) + as *const ACPITableHeader }; let header = unsafe { &*header_ptr }; diff --git a/kernel/src/cmdline.rs b/kernel/src/cmdline.rs index bcc35d5a..0ed7c682 100644 --- a/kernel/src/cmdline.rs +++ b/kernel/src/cmdline.rs @@ -135,7 +135,7 @@ pub struct ArgsParser<'s> { impl<'s> ArgsParser<'s> { /// Parses the given command line and returns a new instance. - pub fn parse(cmdline: &'s [u8]) -> Result> { + pub fn parse(cmdline: &'s [u8]) -> Result> { let mut s = Self { root: None, init: None, diff --git a/kernel/src/crypto/chacha20.rs b/kernel/src/crypto/chacha20.rs index b5453749..2c948feb 100644 --- a/kernel/src/crypto/chacha20.rs +++ b/kernel/src/crypto/chacha20.rs @@ -30,21 +30,24 @@ macro_rules! rotl { /// Performs a quarter round on the given values. macro_rules! quarter_round { ($a:expr, $b:expr, $c:expr, $d:expr) => { - $a = $a.wrapping_add($b); - $d ^= $a; - $d = rotl!($d, 16); + #[allow(clippy::manual_rotate)] + { + $a = $a.wrapping_add($b); + $d ^= $a; + $d = rotl!($d, 16); - $c = $c.wrapping_add($d); - $b ^= $c; - $b = rotl!($b, 12); + $c = $c.wrapping_add($d); + $b ^= $c; + $b = rotl!($b, 12); - $a = $a.wrapping_add($b); - $d ^= $a; - $d = rotl!($d, 8); + $a = $a.wrapping_add($b); + $d ^= $a; + $d = rotl!($d, 8); - $c = $c.wrapping_add($d); - $b ^= $c; - $b = rotl!($b, 7); + $c = $c.wrapping_add($d); + $b ^= $c; + $b = rotl!($b, 7); + } }; } diff --git a/kernel/src/elf/relocation.rs b/kernel/src/elf/relocation.rs index 9cbf2f0c..80fc4720 100644 --- a/kernel/src/elf/relocation.rs +++ b/kernel/src/elf/relocation.rs @@ -73,7 +73,7 @@ pub trait Relocation { // The offset in the GOT entry for the symbol let got_offset = 0u32; // TODO - // The offset in the PLT entry for the symbol + // The offset in the PLT entry for the symbol let plt_offset = 0u32; // TODO // The value of the symbol diff --git a/kernel/src/file/fs/kernfs.rs b/kernel/src/file/fs/kernfs.rs index 96e3f32a..1eb5cb50 100644 --- a/kernel/src/file/fs/kernfs.rs +++ b/kernel/src/file/fs/kernfs.rs @@ -167,11 +167,13 @@ macro_rules! format_content { }}; } -/// A static symbolic link pointing to a constant target. +/// A static symbolic link. +/// +/// The inner value is the target of the symbolic link. #[derive(Debug, Default)] -pub struct StaticLink; +pub struct StaticLink(pub &'static [u8]); -impl NodeOps for StaticLink { +impl NodeOps for StaticLink { fn get_stat(&self, _loc: &FileLocation) -> EResult { Ok(Stat { mode: FileType::Link.to_mode() | 0o777, @@ -180,7 +182,7 @@ impl NodeOps for StaticLink { } fn read_content(&self, _loc: &FileLocation, off: u64, buf: &mut [u8]) -> EResult { - format_content!(off, buf, "{}", DisplayableStr(TARGET)) + format_content!(off, buf, "{}", DisplayableStr(self.0)) } } @@ -221,7 +223,7 @@ pub fn box_wrap<'n, N: 'n + NodeOps>(ops: N) -> AllocResult { - /// The directory's entries, sorted alphabeticaly by name. + /// The directory's entries, sorted alphabetically by name. /// /// **Warning**: If this array is not sorted correctly, the behaviour of /// [`NodeOps::entry_by_name`] is undefined. diff --git a/kernel/src/file/fs/proc/mod.rs b/kernel/src/file/fs/proc/mod.rs index 20b2ba37..64c177f0 100644 --- a/kernel/src/file/fs/proc/mod.rs +++ b/kernel/src/file/fs/proc/mod.rs @@ -93,7 +93,7 @@ impl RootDir { StaticEntryBuilder { name: b"mounts", entry_type: FileType::Link, - init: entry_init_default::>, + init: |_| box_wrap(StaticLink(b"self/mounts")), }, StaticEntryBuilder { name: b"self", diff --git a/kernel/src/kernel.rs b/kernel/src/kernel.rs index 0a2c658e..49bb0fd2 100644 --- a/kernel/src/kernel.rs +++ b/kernel/src/kernel.rs @@ -30,12 +30,10 @@ #![feature(allocator_api)] #![feature(allow_internal_unstable)] #![feature(array_chunks)] -#![feature(asm_const)] #![feature(core_intrinsics)] #![feature(custom_test_frameworks)] #![feature(lang_items)] #![feature(once_cell_try)] -#![feature(panic_info_message)] #![feature(pointer_is_aligned_to)] #![feature(ptr_metadata)] #![feature(strict_provenance)] diff --git a/kernel/src/module/mod.rs b/kernel/src/module/mod.rs index ef834106..1c651f40 100644 --- a/kernel/src/module/mod.rs +++ b/kernel/src/module/mod.rs @@ -192,9 +192,8 @@ impl Module { /// Loads a kernel module from the given image. pub fn load(image: &[u8]) -> EResult { - let parser = ELFParser::new(image).map_err(|e| { + let parser = ELFParser::new(image).inspect_err(|_| { crate::println!("Invalid ELF file as loaded module"); - e })?; // Allocate memory for the module let mem_size = Self::get_load_size(&parser); diff --git a/kernel/src/panic.rs b/kernel/src/panic.rs index 1eae0b35..07d09f2d 100644 --- a/kernel/src/panic.rs +++ b/kernel/src/panic.rs @@ -47,9 +47,7 @@ fn panic(panic_info: &PanicInfo) -> ! { crate::println!("--- KERNEL PANIC ---\n"); crate::println!("Kernel has been forced to halt due to internal problem, sorry :/"); - if let Some(msg) = panic_info.message() { - crate::print!("Reason: {msg}"); - } + crate::print!("Reason: {}", panic_info.message()); if let Some(loc) = panic_info.location() { crate::println!(" (location: {loc})"); } else { diff --git a/kernel/src/process/tss.rs b/kernel/src/process/tss.rs index d4852eb3..b06e1ae6 100644 --- a/kernel/src/process/tss.rs +++ b/kernel/src/process/tss.rs @@ -18,9 +18,10 @@ //! Under the x86 architecture, the TSS (Task State Segment) is a structure that //! is mostly deprecated but that must still be used in order to perform -//! software context switching because it allows to store the pointers to the -//! stacks to use whenever an interruption happens and requires switching the -//! protection ring, and thus the stack. +//! software context switching. +//! +//! It allows to store the pointers to the stacks to use whenever an interruption happens and +//! requires switching the protection ring, and thus the stack. //! //! The structure has to be registered into the GDT into the TSS segment, and must be loaded using //! instruction `ltr`. @@ -98,7 +99,7 @@ impl TSS { /// Initializes the TSS. pub fn init() { let limit = size_of::() as u64; - let base = unsafe { addr_of!(TSS) as u64 }; + let base = addr_of!(TSS) as u64; let flags = 0b0100000010001001_u64; let tss_value = (limit & 0xffff) | ((base & 0xffffff) << 16) diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 26432c5a..b375b519 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,5 +1,5 @@ [toolchain] -channel = "nightly-2024-05-24" +channel = "nightly-2024-09-18" components = ["rustfmt", "rustc-dev", "rust-src", "clippy", "miri"] targets = ["i686-unknown-linux-musl"] profile = "minimal" diff --git a/utils/src/cpio.rs b/utils/src/cpio.rs index 97fc6ad7..b6f130b6 100644 --- a/utils/src/cpio.rs +++ b/utils/src/cpio.rs @@ -29,7 +29,7 @@ use macros::AnyRepr; /// On PDP systems, long values (4 bytes) were stored as big endian, which means these values /// need to be rotated to be read correctly. pub fn rot_u32(v: u32) -> u32 { - (v >> 16) | (v << 16) + v.rotate_left(16) } /// A CPIO entry header. diff --git a/utils/src/ptr/arc.rs b/utils/src/ptr/arc.rs index ef9572f4..9b45b4cb 100644 --- a/utils/src/ptr/arc.rs +++ b/utils/src/ptr/arc.rs @@ -197,7 +197,7 @@ impl Eq for Arc {} impl PartialEq for Arc { fn eq(&self, other: &Self) -> bool { - Self::as_ref(self).eq(&other) + Self::as_ref(self).eq(other) } }