diff --git a/Cargo.lock b/Cargo.lock index b90ede75..1ee55272 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -499,7 +499,6 @@ dependencies = [ [[package]] name = "discrete_range_map" version = "0.6.2" -source = "git+https://git.alnyan.me/yggdrasil/discrete_range_map.git#6b54882b190b02fb013f22cbe9664f6273e846ae" dependencies = [ "btree_monstrousity", "either", diff --git a/Cargo.toml b/Cargo.toml index bd991cbc..acefd093 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -75,7 +75,8 @@ device-tree.path = "kernel/lib/device-tree" fdt-rs = { version = "0.4.5", default-features = false } aarch64-cpu = "10.0.0" -discrete_range_map = { git = "https://git.alnyan.me/yggdrasil/discrete_range_map.git" } +discrete_range_map.path = "/home/alnyan/build/sandbox/yggdrasil-packages/discrete_range_map-1dba7e4d76e4dd17/6b54882" +# discrete_range_map = { git = "https://git.alnyan.me/yggdrasil/discrete_range_map.git" } # Test dependencies tokio = { version = "1.42.0", default-features = false } diff --git a/etc/aarch64-unknown-none.json b/etc/aarch64-unknown-none.json index 059955ad..aa49667f 100644 --- a/etc/aarch64-unknown-none.json +++ b/etc/aarch64-unknown-none.json @@ -5,7 +5,7 @@ "llvm-target": "aarch64-unknown-none", "data-layout": "e-m:e-p270:32:32-p271:32:32-p272:64:64-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32", "max-atomic-width": 128, - "target-pointer-width": "64", + "target-pointer-width": 64, "features": "+v8a,+strict-align,-neon,-fp-armv8", "disable-redzone": true, diff --git a/etc/riscv64-unknown-none.json b/etc/riscv64-unknown-none.json index 2f475cae..0f5bde53 100644 --- a/etc/riscv64-unknown-none.json +++ b/etc/riscv64-unknown-none.json @@ -6,7 +6,7 @@ "llvm-target": "riscv64", "data-layout": "e-m:e-p:64:64-i64:64-i128:128-n32:64-S128", "max-atomic-width": 64, - "target-pointer-width": "64", + "target-pointer-width": 64, "features": "+m,+a,+c", "disable-redzone": true, diff --git a/etc/x86_64-unknown-none.json b/etc/x86_64-unknown-none.json index 87a75541..f993a6d6 100644 --- a/etc/x86_64-unknown-none.json +++ b/etc/x86_64-unknown-none.json @@ -7,7 +7,7 @@ "llvm-target": "x86_64-unknown-linux-gnu", "data-layout": "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128", "max-atomic-width": 64, - "target-pointer-width": "64", + "target-pointer-width": 64, "features": "-avx,-sse,-avx2,+soft-float", "disable-redzone": true, diff --git a/kernel/Cargo.toml b/kernel/Cargo.toml index fe19ef9e..db02c72f 100644 --- a/kernel/Cargo.toml +++ b/kernel/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "yggdrasil-kernel" version = "0.1.0" -edition = "2021" +edition = "2024" build = "build.rs" authors = ["Mark Poliakov "] diff --git a/kernel/arch/Cargo.toml b/kernel/arch/Cargo.toml index 996410a4..c8262ecc 100644 --- a/kernel/arch/Cargo.toml +++ b/kernel/arch/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "kernel-arch" version = "0.1.0" -edition = "2021" +edition = "2024" [target.'cfg(all(target_os = "none", target_arch = "x86_64"))'.dependencies] kernel-arch-x86_64.path = "x86_64" diff --git a/kernel/arch/aarch64/Cargo.toml b/kernel/arch/aarch64/Cargo.toml index c11c7ad1..7b5b7aaf 100644 --- a/kernel/arch/aarch64/Cargo.toml +++ b/kernel/arch/aarch64/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "kernel-arch-aarch64" version = "0.1.0" -edition = "2021" +edition = "2024" [dependencies] yggdrasil-abi.workspace = true diff --git a/kernel/arch/aarch64/src/context.rs b/kernel/arch/aarch64/src/context.rs index a10c8605..9abfd037 100644 --- a/kernel/arch/aarch64/src/context.rs +++ b/kernel/arch/aarch64/src/context.rs @@ -66,7 +66,7 @@ impl FpContext { /// /// It is up to the caller to ensure `this` is a valid pointer to store the FPU context in. pub unsafe fn store(this: *mut Self) { - __aarch64_fp_store_context(this as _) + unsafe { __aarch64_fp_store_context(this as _) } } /// Loads the FPU with the context stored in `this` pointer. @@ -75,7 +75,7 @@ impl FpContext { /// /// It is up to the caller to ensure `this` is a valid pointer to load the FPU context from. pub unsafe fn restore(this: *const Self) { - __aarch64_fp_restore_context(this as _) + unsafe { __aarch64_fp_restore_context(this as _) } } } @@ -177,7 +177,12 @@ impl ! { - FpContext::restore(self.fp_context.get()); - - __aarch64_enter_task(self.inner.get()) + unsafe { FpContext::restore(self.fp_context.get()) }; + unsafe { __aarch64_enter_task(self.inner.get()) } } unsafe fn switch(&self, from: &Self) { @@ -241,19 +245,20 @@ impl !; fn __aarch64_switch_task(to: *mut TaskContextInner, from: *mut TaskContextInner); fn __aarch64_switch_task_and_drop(to: *mut TaskContextInner, thread: *const ()) -> !; diff --git a/kernel/arch/aarch64/src/lib.rs b/kernel/arch/aarch64/src/lib.rs index beeea550..9adf4263 100644 --- a/kernel/arch/aarch64/src/lib.rs +++ b/kernel/arch/aarch64/src/lib.rs @@ -13,11 +13,11 @@ use aarch64_cpu::{ use alloc::{boxed::Box, sync::Arc, vec::Vec}; use device_api::interrupt::LocalInterruptController; use kernel_arch_interface::{ + Architecture, cpu::{CpuData, CpuImpl, IpiQueue}, guard::IrqGuard, task::Scheduler, util::OneTimeInit, - Architecture, }; use tock_registers::interfaces::{ReadWriteable, Readable, Writeable}; @@ -25,7 +25,7 @@ pub mod context; pub mod mem; pub use context::TaskContextImpl; -pub use mem::{process::ProcessAddressSpaceImpl, KernelTableManagerImpl}; +pub use mem::{KernelTableManagerImpl, process::ProcessAddressSpaceImpl}; pub struct ArchitectureImpl; @@ -101,7 +101,7 @@ impl Architecture for ArchitectureImpl { let id = (MPIDR_EL1.get() & 0xFF) as u32; let cpu = Box::leak(Box::new(CpuImpl::::new(id, data))); - cpu.set_local(); + unsafe { cpu.set_local() }; } fn local_cpu() -> *mut () { diff --git a/kernel/arch/aarch64/src/mem/fixed.rs b/kernel/arch/aarch64/src/mem/fixed.rs index d7f05281..4b22e0bd 100644 --- a/kernel/arch/aarch64/src/mem/fixed.rs +++ b/kernel/arch/aarch64/src/mem/fixed.rs @@ -1,7 +1,7 @@ use core::ops::Range; use aarch64_cpu::registers::{TTBR0_EL1, TTBR1_EL1}; -use kernel_arch_interface::{mem::DeviceMemoryAttributes, KERNEL_VIRT_OFFSET}; +use kernel_arch_interface::{KERNEL_VIRT_OFFSET, mem::DeviceMemoryAttributes}; use libk_mm_interface::{ address::PhysicalAddress, device::{DevicePageManager, DevicePageTableLevel}, @@ -10,7 +10,7 @@ use libk_mm_interface::{ use crate::mem::{ auto_lower_address, - table::{PageAttributes, PageEntry, PageTable, L1, L2, L3}, + table::{L1, L2, L3, PageAttributes, PageEntry, PageTable}, tlb_flush_range_va, }; @@ -98,22 +98,26 @@ impl DevicePageTableLevel for L3DeviceMemory { } pub unsafe fn setup() { - // 0..IDENTITY_SIZE_L1 -> lower RAM region - for i in 0..IDENTITY_SIZE_L1 { - let phys = PhysicalAddress::from_usize(i << L1::SHIFT); - KERNEL_L1[i] = PageEntry::normal_block(phys, PageAttributes::empty()); - } + unsafe { + // 0..IDENTITY_SIZE_L1 -> lower RAM region + for i in 0..IDENTITY_SIZE_L1 { + let phys = PhysicalAddress::from_usize(i << L1::SHIFT); + KERNEL_L1[i] = PageEntry::normal_block(phys, PageAttributes::empty()); + } - // DEVICE_L1 -> Device L2 table - // 0..DEVICE_MAPPING_L3_COUNT -> Device L3 tables -> Device L3 pages - // ..512 -> Device L2 pages - for i in 0..DEVICE_MAPPING_L3_COUNT { + // DEVICE_L1 -> Device L2 table + // 0..DEVICE_MAPPING_L3_COUNT -> Device L3 tables -> Device L3 pages + // ..512 -> Device L2 pages + for i in 0..DEVICE_MAPPING_L3_COUNT { + let phys = PhysicalAddress::from_usize(auto_lower_address( + &raw const DEVICE_MEMORY.normal.0[i], + )); + DEVICE_MEMORY.large.0[i] = PageEntry::table(phys, PageAttributes::empty()); + } let phys = - PhysicalAddress::from_usize(auto_lower_address(&raw const DEVICE_MEMORY.normal.0[i])); - DEVICE_MEMORY.large.0[i] = PageEntry::table(phys, PageAttributes::empty()); + PhysicalAddress::from_usize(auto_lower_address(&raw const DEVICE_MEMORY.large.0)); + KERNEL_L1[DEVICE_L1] = PageEntry::table(phys, PageAttributes::empty()); } - let phys = PhysicalAddress::from_usize(auto_lower_address(&raw const DEVICE_MEMORY.large.0)); - KERNEL_L1[DEVICE_L1] = PageEntry::table(phys, PageAttributes::empty()); } pub unsafe fn load() { diff --git a/kernel/arch/aarch64/src/mem/mod.rs b/kernel/arch/aarch64/src/mem/mod.rs index 38d9d3b7..9f03fa2f 100644 --- a/kernel/arch/aarch64/src/mem/mod.rs +++ b/kernel/arch/aarch64/src/mem/mod.rs @@ -4,9 +4,9 @@ use aarch64_cpu::{ registers::{MAIR_EL1, SCTLR_EL1, TCR_EL1}, }; use kernel_arch_interface::{ + KERNEL_VIRT_OFFSET, mem::{DeviceMemoryAttributes, KernelTableManager, RawDeviceMemoryMapping}, sync::IrqSafeSpinlock, - KERNEL_VIRT_OFFSET, }; use libk_mm_interface::{address::PhysicalAddress, table::EntryLevel}; use tock_registers::interfaces::{ReadWriteable, Writeable}; @@ -14,7 +14,7 @@ use yggdrasil_abi::error::Error; pub use intrinsics::*; -use crate::{mem::table::L1, ArchitectureImpl}; +use crate::{ArchitectureImpl, mem::table::L1}; pub mod fixed; pub mod intrinsics; @@ -52,14 +52,18 @@ impl KernelTableManager for KernelTableManagerImpl { attrs: DeviceMemoryAttributes, ) -> Result, Error> { let _lock = KERNEL_MEMORY_LOCK.lock(); - #[allow(static_mut_refs)] - fixed::DEVICE_MEMORY.map_device_pages(PhysicalAddress::from_u64(base), count, attrs) + unsafe { + #[allow(static_mut_refs)] + fixed::DEVICE_MEMORY.map_device_pages(PhysicalAddress::from_u64(base), count, attrs) + } } unsafe fn unmap_device_pages(mapping: &RawDeviceMemoryMapping) { let _lock = KERNEL_MEMORY_LOCK.lock(); - #[allow(static_mut_refs)] - fixed::DEVICE_MEMORY.unmap_device_pages(mapping); + unsafe { + #[allow(static_mut_refs)] + fixed::DEVICE_MEMORY.unmap_device_pages(mapping); + } } } @@ -132,15 +136,19 @@ unsafe fn enable_mmu() { SCTLR_EL1.modify(SCTLR_EL1::M::Enable); // Enable caches - enable_icache(); - enable_dcache(); + unsafe { + enable_icache(); + enable_dcache(); + } } pub unsafe fn init_lower(bsp: bool) { setup_memory_attributes(); - if bsp { - fixed::setup(); + unsafe { + if bsp { + fixed::setup(); + } + fixed::load(); + enable_mmu(); } - fixed::load(); - enable_mmu(); } diff --git a/kernel/arch/aarch64/src/mem/process.rs b/kernel/arch/aarch64/src/mem/process.rs index 730daa6a..06febcf7 100644 --- a/kernel/arch/aarch64/src/mem/process.rs +++ b/kernel/arch/aarch64/src/mem/process.rs @@ -14,11 +14,11 @@ use libk_mm_interface::{ }; use yggdrasil_abi::error::Error; -use crate::{mem::table::PageEntry, KernelTableManagerImpl}; +use crate::{KernelTableManagerImpl, mem::table::PageEntry}; use super::{ dc_cvac, ic_iallu, - table::{PageAttributes, PageTable, L1, L2, L3}, + table::{L1, L2, L3, PageAttributes, PageTable}, tlb_flush_asid, tlb_flush_vaae1, }; @@ -97,8 +97,10 @@ impl ProcessAddressSpaceManager for ProcessAddressSpaceI } unsafe fn clear(&mut self) { - self.l1 - .drop_range::(0..((Self::UPPER_LIMIT_PFN * L3::SIZE).page_index::())); + unsafe { + self.l1 + .drop_range::(0..((Self::UPPER_LIMIT_PFN * L3::SIZE).page_index::())) + }; } } diff --git a/kernel/arch/aarch64/src/mem/table.rs b/kernel/arch/aarch64/src/mem/table.rs index 880cbe03..d382cc61 100644 --- a/kernel/arch/aarch64/src/mem/table.rs +++ b/kernel/arch/aarch64/src/mem/table.rs @@ -103,8 +103,8 @@ impl PageTable { } } - pub fn new_zeroed<'a, TA: TableAllocator>( - ) -> Result, Error> { + pub fn new_zeroed<'a, TA: TableAllocator>() + -> Result, Error> { let physical = TA::allocate_page_table()?; let mut table = unsafe { PhysicalRefMut::<'a, Self, KernelTableManagerImpl>::map(physical) }; @@ -132,7 +132,7 @@ impl PageTable { return None; } - let inner = PhysicalRefMut::map(physical); + let inner = unsafe { PhysicalRefMut::map(physical) }; Some(inner) } } @@ -234,12 +234,16 @@ where let entry = self[index]; if let Some(table) = entry.as_table() { - let mut table_ref: PhysicalRefMut, KernelTableManagerImpl> = - PhysicalRefMut::map(table); + unsafe { + let mut table_ref: PhysicalRefMut< + PageTable, + KernelTableManagerImpl, + > = PhysicalRefMut::map(table); - table_ref.drop_all::(); + table_ref.drop_all::(); - TA::free_page_table(table); + TA::free_page_table(table); + } } else if entry.is_present() { // Memory must've been cleared beforehand, so no non-table entries must be present panic!( diff --git a/kernel/arch/hosted/src/lib.rs b/kernel/arch/hosted/src/lib.rs index 60582240..8662a426 100644 --- a/kernel/arch/hosted/src/lib.rs +++ b/kernel/arch/hosted/src/lib.rs @@ -7,12 +7,12 @@ use std::{ use device_api::dma::{DmaAllocation, DmaAllocator}; use kernel_arch_interface::{ + Architecture, cpu::{CpuData, IpiQueue}, mem::{ DeviceMemoryAttributes, KernelTableManager, PhysicalMemoryAllocator, RawDeviceMemoryMapping, }, task::{Scheduler, TaskContext, UserContextInfo}, - Architecture, }; use libk_mm_interface::{ address::PhysicalAddress, diff --git a/kernel/arch/interface/src/cpu.rs b/kernel/arch/interface/src/cpu.rs index 1fa5fc9c..65b20ead 100644 --- a/kernel/arch/interface/src/cpu.rs +++ b/kernel/arch/interface/src/cpu.rs @@ -7,7 +7,7 @@ use alloc::vec::Vec; use device_api::interrupt::IpiMessage; use crate::{ - guard::IrqGuard, sync::IrqSafeSpinlock, task::Scheduler, util::OneTimeInit, Architecture, + Architecture, guard::IrqGuard, sync::IrqSafeSpinlock, task::Scheduler, util::OneTimeInit, }; #[repr(C, align(0x10))] diff --git a/kernel/arch/interface/src/sync.rs b/kernel/arch/interface/src/sync.rs index ec70f4b6..f3a41439 100644 --- a/kernel/arch/interface/src/sync.rs +++ b/kernel/arch/interface/src/sync.rs @@ -6,7 +6,7 @@ use core::{ sync::atomic::{AtomicBool, Ordering}, }; -use crate::{guard::IrqGuard, Architecture}; +use crate::{Architecture, guard::IrqGuard}; pub struct Spinlock { value: UnsafeCell, diff --git a/kernel/arch/riscv64/src/context.rs b/kernel/arch/riscv64/src/context.rs index 85811a78..100ae7e5 100644 --- a/kernel/arch/riscv64/src/context.rs +++ b/kernel/arch/riscv64/src/context.rs @@ -1,9 +1,9 @@ use core::{arch::global_asm, cell::UnsafeCell, marker::PhantomData}; use kernel_arch_interface::{ + Architecture, mem::{KernelTableManager, PhysicalMemoryAllocator}, task::{StackBuilder, TaskContext, UserContextInfo}, - Architecture, }; use libk_mm_interface::address::PhysicalAddress; use tock_registers::{ @@ -13,9 +13,9 @@ use tock_registers::{ use yggdrasil_abi::error::Error; use crate::{ + ArchitectureImpl, PerCpuData, mem::{self}, registers::SATP, - ArchitectureImpl, PerCpuData, }; pub const CONTEXT_SIZE: usize = 14 * size_of::(); @@ -86,7 +86,7 @@ impl { diff --git a/kernel/arch/riscv64/src/mem/table.rs b/kernel/arch/riscv64/src/mem/table.rs index 626d7bcb..0000fa91 100644 --- a/kernel/arch/riscv64/src/mem/table.rs +++ b/kernel/arch/riscv64/src/mem/table.rs @@ -10,8 +10,8 @@ use libk_mm_interface::{ pointer::{PhysicalRef, PhysicalRefMut}, process::PageAttributeUpdate, table::{ - page_index, EntryLevel, EntryLevelDrop, NextPageTable, NonTerminalEntryLevel, - TableAllocator, + EntryLevel, EntryLevelDrop, NextPageTable, NonTerminalEntryLevel, TableAllocator, + page_index, }, }; use yggdrasil_abi::error::Error; @@ -109,8 +109,8 @@ impl PageTable { } } - pub fn new_zeroed<'a, TA: TableAllocator>( - ) -> Result, KernelTableManagerImpl>, Error> { + pub fn new_zeroed<'a, TA: TableAllocator>() + -> Result, KernelTableManagerImpl>, Error> { let physical = TA::allocate_page_table()?; let mut table = unsafe { PhysicalRefMut::<'a, Self, KernelTableManagerImpl>::map(physical) }; diff --git a/kernel/arch/riscv64/src/sbi.rs b/kernel/arch/riscv64/src/sbi.rs index f7b14569..3e652584 100644 --- a/kernel/arch/riscv64/src/sbi.rs +++ b/kernel/arch/riscv64/src/sbi.rs @@ -78,11 +78,7 @@ unsafe fn sbi_do_call( ); } let a0 = a0 as i64; - if a0 == 0 { - Ok(a1) - } else { - Err(a0.into()) - } + if a0 == 0 { Ok(a1) } else { Err(a0.into()) } } pub fn sbi_hart_start(hart_id: u64, start_addr: u64, opaque: u64) -> Result<(), Error> { diff --git a/kernel/arch/src/lib.rs b/kernel/arch/src/lib.rs index 3fbbafe6..44b0b9e5 100644 --- a/kernel/arch/src/lib.rs +++ b/kernel/arch/src/lib.rs @@ -35,7 +35,7 @@ cfg_if! { pub use imp::{ArchitectureImpl, KernelTableManagerImpl, ProcessAddressSpaceImpl, TaskContextImpl}; -pub use kernel_arch_interface::{guard, mem, sync, task, util, Architecture, KERNEL_VIRT_OFFSET}; +pub use kernel_arch_interface::{Architecture, KERNEL_VIRT_OFFSET, guard, mem, sync, task, util}; pub type CpuImpl = kernel_arch_interface::cpu::CpuImpl; pub type LocalCpuImpl<'a, S> = kernel_arch_interface::cpu::LocalCpuImpl<'a, ArchitectureImpl, S>; diff --git a/kernel/arch/x86/src/lib.rs b/kernel/arch/x86/src/lib.rs index 8afeeba9..171090be 100644 --- a/kernel/arch/x86/src/lib.rs +++ b/kernel/arch/x86/src/lib.rs @@ -1,4 +1,4 @@ -#![feature(iter_chain, new_zeroed_alloc, box_as_ptr)] +#![feature(box_as_ptr)] #![allow(clippy::new_without_default)] #![no_std] diff --git a/kernel/arch/x86_64/src/context.rs b/kernel/arch/x86_64/src/context.rs index b884752f..8010455c 100644 --- a/kernel/arch/x86_64/src/context.rs +++ b/kernel/arch/x86_64/src/context.rs @@ -4,14 +4,14 @@ use kernel_arch_interface::{ mem::{KernelTableManager, PhysicalMemoryAllocator}, task::{ForkFrame, StackBuilder, TaskContext, TaskFrame, UserContextInfo}, }; -use kernel_arch_x86::registers::{FpuContext, CR3, MSR_IA32_FS_BASE}; +use kernel_arch_x86::registers::{CR3, FpuContext, MSR_IA32_FS_BASE}; use libk_mm_interface::address::PhysicalAddress; use tock_registers::interfaces::Writeable; use yggdrasil_abi::{arch::SavedFrame, error::Error}; use crate::{ - mem::{auto_lower_address, fixed}, ArchitectureImpl, + mem::{auto_lower_address, fixed}, }; /// Frame saved onto the stack when taking an IRQ @@ -445,7 +445,7 @@ impl PageTable { } /// Allocates a new page table, filling it with non-preset entries - pub fn new_zeroed<'a, TA: TableAllocator>( - ) -> Result, Error> { + pub fn new_zeroed<'a, TA: TableAllocator>() + -> Result, Error> { let physical = TA::allocate_page_table()?; let mut table = unsafe { PhysicalRefMut::<'a, Self, KernelTableManagerImpl>::map(physical) }; diff --git a/kernel/build.rs b/kernel/build.rs index e1912380..a07572d5 100644 --- a/kernel/build.rs +++ b/kernel/build.rs @@ -6,9 +6,9 @@ use std::{ }; use abi_generator::{ - abi::{ty::TypeWidth, AbiBuilder}, - syntax::UnwrapFancy, TargetEnv, + abi::{AbiBuilder, ty::TypeWidth}, + syntax::UnwrapFancy, }; fn build_x86_64() { diff --git a/kernel/driver/acpi/src/handler.rs b/kernel/driver/acpi/src/handler.rs index 55e1992c..6d7fad75 100644 --- a/kernel/driver/acpi/src/handler.rs +++ b/kernel/driver/acpi/src/handler.rs @@ -7,7 +7,7 @@ use device_api::{ device::Device, interrupt::{InterruptHandler, Irq, IrqVector}, }; -use kernel_arch_x86::{intrinsics, ISA_IRQ_OFFSET}; +use kernel_arch_x86::{ISA_IRQ_OFFSET, intrinsics}; use libk::device::external_interrupt_controller; use libk_mm::{ address::{PhysicalAddress, Virtualize}, @@ -15,8 +15,8 @@ use libk_mm::{ }; use crate::{ - mem::{read_memory, write_memory}, ACPI_SYSTEM, + mem::{read_memory, write_memory}, }; #[derive(Clone, Copy)] diff --git a/kernel/driver/acpi/src/lib.rs b/kernel/driver/acpi/src/lib.rs index 1d55bb15..8cdca3ed 100644 --- a/kernel/driver/acpi/src/lib.rs +++ b/kernel/driver/acpi/src/lib.rs @@ -5,7 +5,7 @@ use acpi::AcpiTables; use acpi_system::{AcpiInterruptMethod, AcpiSleepState, AcpiSystem}; use alloc::boxed::Box; use libk::error::Error; -use libk_util::{sync::IrqSafeSpinlock, OneTimeInit}; +use libk_util::{OneTimeInit, sync::IrqSafeSpinlock}; extern crate alloc; diff --git a/kernel/driver/block/ahci/src/command.rs b/kernel/driver/block/ahci/src/command.rs index aba491f9..094a22c1 100644 --- a/kernel/driver/block/ahci/src/command.rs +++ b/kernel/driver/block/ahci/src/command.rs @@ -1,10 +1,10 @@ -use core::mem::{size_of, MaybeUninit}; +use core::mem::{MaybeUninit, size_of}; use device_api::dma::DmaAllocator; use libk::dma::{BusAddress, DmaBuffer, DmaSliceMut}; use tock_registers::register_structs; -use crate::{data::AtaString, error::AhciError, MAX_PRD_SIZE}; +use crate::{MAX_PRD_SIZE, data::AtaString, error::AhciError}; #[derive(Clone, Copy, PartialEq, Eq, Debug)] #[repr(u8)] diff --git a/kernel/driver/block/ahci/src/data.rs b/kernel/driver/block/ahci/src/data.rs index 1d015de1..2d431430 100644 --- a/kernel/driver/block/ahci/src/data.rs +++ b/kernel/driver/block/ahci/src/data.rs @@ -7,9 +7,9 @@ use libk_util::{ConstAssert, IsTrue}; use static_assertions::const_assert_eq; use crate::{ + MAX_PRD_SIZE, command::{AtaCommand, AtaIdentify, AtaIdentifyResponse}, error::AhciError, - MAX_PRD_SIZE, }; pub const COMMAND_LIST_LENGTH: usize = 32; @@ -20,7 +20,7 @@ const AHCI_FIS_REG_H2D: u8 = 0x27; #[repr(C)] pub struct AtaString where - ConstAssert<{ N % 2 == 0 }>: IsTrue, + ConstAssert<{ N.is_multiple_of(2) }>: IsTrue, { data: [u8; N], } @@ -243,7 +243,7 @@ impl AtaIdentifyResponse { impl AtaString where - ConstAssert<{ N % 2 == 0 }>: IsTrue, + ConstAssert<{ N.is_multiple_of(2) }>: IsTrue, { #[allow(clippy::inherent_to_string)] pub fn to_string(&self) -> String { diff --git a/kernel/driver/block/ahci/src/lib.rs b/kernel/driver/block/ahci/src/lib.rs index 362fa78b..b98fe4c9 100644 --- a/kernel/driver/block/ahci/src/lib.rs +++ b/kernel/driver/block/ahci/src/lib.rs @@ -15,18 +15,18 @@ use device_api::{ use error::AhciError; use libk::{device::manager::probe_partitions, dma::DmaBuffer, fs::devfs, task::runtime}; use libk_mm::device::DeviceMemoryIo; -use libk_util::{sync::IrqSafeSpinlock, OneTimeInit}; +use libk_util::{OneTimeInit, sync::IrqSafeSpinlock}; use port::AhciPort; use regs::{PortRegs, Regs}; use tock_registers::interfaces::{ReadWriteable, Readable, Writeable}; use ygg_driver_pci::{ + PciCommandRegister, PciConfigurationSpace, device::{PciDeviceInfo, PreferredInterruptMode}, macros::pci_driver, - PciCommandRegister, PciConfigurationSpace, }; use yggdrasil_abi::{error::Error, io::FileMode}; -use crate::regs::{Version, CAP, GHC, SSTS}; +use crate::regs::{CAP, GHC, SSTS, Version}; mod command; mod data; diff --git a/kernel/driver/block/ahci/src/port.rs b/kernel/driver/block/ahci/src/port.rs index 82dc3e34..90a9d587 100644 --- a/kernel/driver/block/ahci/src/port.rs +++ b/kernel/driver/block/ahci/src/port.rs @@ -16,18 +16,18 @@ use libk::{ error::Error, }; use libk_mm::{ - address::PhysicalAddress, device::DeviceMemoryIo, table::MapAttributes, OnDemandPage, - PageProvider, VirtualPage, + OnDemandPage, PageProvider, VirtualPage, address::PhysicalAddress, device::DeviceMemoryIo, + table::MapAttributes, }; -use libk_util::{sync::IrqSafeSpinlock, waker::QueueWaker, OneTimeInit}; +use libk_util::{OneTimeInit, sync::IrqSafeSpinlock, waker::QueueWaker}; use tock_registers::interfaces::{Readable, Writeable}; use crate::{ - command::{AtaCommand, AtaIdentify, AtaReadDmaEx}, - data::{CommandListEntry, CommandTable, ReceivedFis, COMMAND_LIST_LENGTH}, - error::AhciError, - regs::{PortRegs, CMD_PENDING, CMD_READY, IE, TFD}, AhciController, MAX_COMMANDS, MAX_PRD_SIZE, SECTOR_SIZE, + command::{AtaCommand, AtaIdentify, AtaReadDmaEx}, + data::{COMMAND_LIST_LENGTH, CommandListEntry, CommandTable, ReceivedFis}, + error::AhciError, + regs::{CMD_PENDING, CMD_READY, IE, PortRegs, TFD}, }; #[derive(Clone, Copy, PartialEq, Debug)] @@ -319,11 +319,11 @@ impl BlockDevice for AhciPort { position: u64, buffer: DmaSliceMut<'_, MaybeUninit>, ) -> Result<(), Error> { - if buffer.len() % SECTOR_SIZE != 0 { + if !buffer.len().is_multiple_of(SECTOR_SIZE) { log::warn!("ahci: misaligned buffer size: {}", buffer.len()); return Err(Error::InvalidOperation); } - if position % SECTOR_SIZE as u64 != 0 { + if !position.is_multiple_of(SECTOR_SIZE as u64) { log::warn!("ahci: misaligned read"); return Err(Error::InvalidOperation); } diff --git a/kernel/driver/block/nvme/Cargo.toml b/kernel/driver/block/nvme/Cargo.toml index e65c79c6..dd41eb90 100644 --- a/kernel/driver/block/nvme/Cargo.toml +++ b/kernel/driver/block/nvme/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "ygg_driver_nvme" version = "0.1.0" -edition = "2021" +edition = "2024" authors = ["Mark Poliakov "] [dependencies] diff --git a/kernel/driver/block/nvme/src/command.rs b/kernel/driver/block/nvme/src/command.rs index a40a4026..4f0a01ad 100644 --- a/kernel/driver/block/nvme/src/command.rs +++ b/kernel/driver/block/nvme/src/command.rs @@ -3,7 +3,7 @@ use core::fmt::{self, Write}; use libk::dma::BusAddress; -use tock_registers::{interfaces::Readable, register_structs, registers::ReadOnly, UIntLike}; +use tock_registers::{UIntLike, interfaces::Readable, register_structs, registers::ReadOnly}; use crate::queue::PhysicalRegionPage; diff --git a/kernel/driver/block/nvme/src/drive.rs b/kernel/driver/block/nvme/src/drive.rs index 56f38ce5..e3eab9d8 100644 --- a/kernel/driver/block/nvme/src/drive.rs +++ b/kernel/driver/block/nvme/src/drive.rs @@ -9,14 +9,14 @@ use libk::{ error::Error, }; use libk_mm::{ + OnDemandPage, PageProvider, PageSlice, VirtualPage, address::{AsPhysicalAddress, PhysicalAddress}, table::MapAttributes, - OnDemandPage, PageProvider, PageSlice, VirtualPage, }; -use crate::{command::IdentifyNamespaceRequest, register_nvme_namespace, IoDirection}; +use crate::{IoDirection, command::IdentifyNamespaceRequest, register_nvme_namespace}; -use super::{error::NvmeError, NvmeController}; +use super::{NvmeController, error::NvmeError}; #[allow(unused)] pub struct NvmeNamespace { @@ -92,10 +92,10 @@ impl BlockDevice for NvmeNamespace { position: u64, buffer: DmaSliceMut<'_, MaybeUninit>, ) -> Result<(), Error> { - if position % self.block_size() as u64 != 0 { + if !position.is_multiple_of(self.block_size() as u64) { return Err(Error::InvalidOperation); } - if buffer.len() % self.block_size() != 0 || buffer.is_empty() { + if !buffer.len().is_multiple_of(self.block_size()) || buffer.is_empty() { return Err(Error::InvalidOperation); } let lba = position / self.block_size() as u64; @@ -115,10 +115,10 @@ impl BlockDevice for NvmeNamespace { } async fn write_aligned(&self, position: u64, buffer: DmaSlice<'_, u8>) -> Result<(), Error> { - if position % self.block_size() as u64 != 0 { + if !position.is_multiple_of(self.block_size() as u64) { return Err(Error::InvalidOperation); } - if buffer.len() % self.block_size() != 0 || buffer.is_empty() { + if !buffer.len().is_multiple_of(self.block_size()) || buffer.is_empty() { return Err(Error::InvalidOperation); } let lba = position / self.block_size() as u64; diff --git a/kernel/driver/block/nvme/src/lib.rs b/kernel/driver/block/nvme/src/lib.rs index 4276109a..b56f02ff 100644 --- a/kernel/driver/block/nvme/src/lib.rs +++ b/kernel/driver/block/nvme/src/lib.rs @@ -1,4 +1,4 @@ -#![feature(const_trait_impl, let_chains, if_let_guard, maybe_uninit_slice)] +#![feature(const_trait_impl, if_let_guard)] #![allow(missing_docs)] #![no_std] // TODO @@ -7,7 +7,7 @@ extern crate alloc; use core::{ - mem::{size_of, MaybeUninit}, + mem::{MaybeUninit, size_of}, sync::atomic::{AtomicUsize, Ordering}, time::Duration, }; @@ -27,10 +27,10 @@ use libk::{ fs::devfs, task::{cpu_count, cpu_index, runtime}, }; -use libk_mm::{address::PhysicalAddress, device::DeviceMemoryIo, L3_PAGE_SIZE}; +use libk_mm::{L3_PAGE_SIZE, address::PhysicalAddress, device::DeviceMemoryIo}; use libk_util::{ - sync::{IrqGuard, IrqSafeSpinlock}, OneTimeInit, + sync::{IrqGuard, IrqSafeSpinlock}, }; use queue::PrpList; use regs::{CAP, CC}; @@ -40,9 +40,9 @@ use tock_registers::{ registers::{ReadOnly, ReadWrite, WriteOnly}, }; use ygg_driver_pci::{ + PciCommandRegister, PciConfigurationSpace, device::{PciDeviceInfo, PreferredInterruptMode}, macros::pci_driver, - PciCommandRegister, PciConfigurationSpace, }; use yggdrasil_abi::{error::Error, io::FileMode}; @@ -284,8 +284,8 @@ impl NvmeController { unsafe fn doorbell_pair(&self, idx: usize) -> (*mut u32, *mut u32) { let regs = self.regs.lock(); - let sq_ptr = regs.doorbell_ptr(self.doorbell_shift, false, idx); - let cq_ptr = regs.doorbell_ptr(self.doorbell_shift, true, idx); + let sq_ptr = unsafe { regs.doorbell_ptr(self.doorbell_shift, false, idx) }; + let cq_ptr = unsafe { regs.doorbell_ptr(self.doorbell_shift, true, idx) }; (sq_ptr, cq_ptr) } } diff --git a/kernel/driver/block/nvme/src/queue.rs b/kernel/driver/block/nvme/src/queue.rs index 3aa4254d..17426850 100644 --- a/kernel/driver/block/nvme/src/queue.rs +++ b/kernel/driver/block/nvme/src/queue.rs @@ -112,7 +112,7 @@ impl PrpList { size: usize, ) -> Result { // TODO hardcoded page size - if base.into_u64() % 0x1000 != 0 { + if !base.into_u64().is_multiple_of(0x1000) { todo!(); } diff --git a/kernel/driver/block/scsi/src/lib.rs b/kernel/driver/block/scsi/src/lib.rs index 6173462c..ea70c9f4 100644 --- a/kernel/driver/block/scsi/src/lib.rs +++ b/kernel/driver/block/scsi/src/lib.rs @@ -1,4 +1,4 @@ -#![feature(generic_const_exprs, maybe_uninit_slice)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] #![no_std] @@ -23,11 +23,11 @@ use libk::{ task::{runtime, sync::AsyncMutex}, }; use libk_mm::{ - address::PhysicalAddress, table::MapAttributes, OnDemandPage, PageProvider, VirtualPage, + OnDemandPage, PageProvider, VirtualPage, address::PhysicalAddress, table::MapAttributes, }; use libk_util::{ - sync::{spin_rwlock::IrqSafeRwLock, IrqSafeSpinlock}, OneTimeInit, + sync::{IrqSafeSpinlock, spin_rwlock::IrqSafeRwLock}, }; use transport::{ScsiTransport, ScsiTransportWrapper}; use yggdrasil_abi::io::FileMode; @@ -214,11 +214,11 @@ impl BlockDevice for ScsiUnit { position: u64, buffer: DmaSliceMut<'_, MaybeUninit>, ) -> Result<(), Error> { - if position % self.lba_size as u64 != 0 { + if !position.is_multiple_of(self.lba_size as u64) { log::warn!("scsi: misaligned read"); return Err(Error::InvalidArgument); } - if buffer.len() % self.lba_size != 0 { + if !buffer.len().is_multiple_of(self.lba_size) { log::warn!("scsi: misaligned buffer size"); return Err(Error::InvalidArgument); } diff --git a/kernel/driver/bsp/arm/src/pl011.rs b/kernel/driver/bsp/arm/src/pl011.rs index ac2fd05e..cb9c2bf1 100644 --- a/kernel/driver/bsp/arm/src/pl011.rs +++ b/kernel/driver/bsp/arm/src/pl011.rs @@ -3,14 +3,14 @@ use device_api::{ device::{Device, DeviceInitContext}, interrupt::{InterruptHandler, IrqHandle, IrqVector}, }; -use device_tree::driver::{device_tree_driver, Node, ProbeContext}; +use device_tree::driver::{Node, ProbeContext, device_tree_driver}; use libk::{ debug::DebugSink, device::manager::DEVICE_REGISTRY, vfs::{Terminal, TerminalInput, TerminalOutput}, }; use libk_mm::{address::PhysicalAddress, device::DeviceMemoryIo}; -use libk_util::{sync::IrqSafeSpinlock, OneTimeInit}; +use libk_util::{OneTimeInit, sync::IrqSafeSpinlock}; use tock_registers::{ interfaces::{ReadWriteable, Readable, Writeable}, register_bitfields, register_structs, diff --git a/kernel/driver/bsp/arm/src/pl031.rs b/kernel/driver/bsp/arm/src/pl031.rs index a7dbb731..e7a47288 100644 --- a/kernel/driver/bsp/arm/src/pl031.rs +++ b/kernel/driver/bsp/arm/src/pl031.rs @@ -1,6 +1,6 @@ use alloc::sync::Arc; use device_api::device::{Device, DeviceInitContext}; -use device_tree::driver::{device_tree_driver, Node, ProbeContext}; +use device_tree::driver::{Node, ProbeContext, device_tree_driver}; use libk::{ error::Error, fs::sysfs::{self, nodes::SysfsRtcNode}, diff --git a/kernel/driver/bsp/arm/src/pl061.rs b/kernel/driver/bsp/arm/src/pl061.rs index 47d4e747..f6fb53fc 100644 --- a/kernel/driver/bsp/arm/src/pl061.rs +++ b/kernel/driver/bsp/arm/src/pl061.rs @@ -11,11 +11,11 @@ use device_api::{ interrupt::{InterruptHandler, IrqHandle, IrqVector}, }; use device_tree::{ - driver::{ - device_tree_driver, util::generic_gpio_config, DeviceTreeGpioPins, DeviceTreePinController, - Node, ProbeContext, - }, DeviceTreePropertyRead, TProp, + driver::{ + DeviceTreeGpioPins, DeviceTreePinController, Node, ProbeContext, device_tree_driver, + util::generic_gpio_config, + }, }; use libk::event::signal_gpio_event; use libk_mm::device::DeviceMemoryIo; diff --git a/kernel/driver/bsp/bcm283x/src/aux.rs b/kernel/driver/bsp/bcm283x/src/aux.rs index 3308cba9..c15e4af3 100644 --- a/kernel/driver/bsp/bcm283x/src/aux.rs +++ b/kernel/driver/bsp/bcm283x/src/aux.rs @@ -4,11 +4,11 @@ use device_api::{ device::{Device, DeviceInitContext}, }; use device_tree::{ - driver::{device_tree_driver, DeviceTreeClockController, Node, ProbeContext}, DeviceTreePropertyRead, TProp, + driver::{DeviceTreeClockController, Node, ProbeContext, device_tree_driver}, }; use libk_mm::{address::PhysicalAddress, device::DeviceMemoryIo}; -use libk_util::{sync::IrqSafeSpinlock, OneTimeInit}; +use libk_util::{OneTimeInit, sync::IrqSafeSpinlock}; use tock_registers::{ interfaces::ReadWriteable, register_bitfields, register_structs, diff --git a/kernel/driver/bsp/bcm283x/src/aux_uart.rs b/kernel/driver/bsp/bcm283x/src/aux_uart.rs index f5e256e7..4d0ac333 100644 --- a/kernel/driver/bsp/bcm283x/src/aux_uart.rs +++ b/kernel/driver/bsp/bcm283x/src/aux_uart.rs @@ -4,14 +4,14 @@ use device_api::{ device::{Device, DeviceInitContext}, interrupt::{InterruptHandler, IrqHandle, IrqVector}, }; -use device_tree::driver::{device_tree_driver, Node, ProbeContext}; +use device_tree::driver::{Node, ProbeContext, device_tree_driver}; use libk::{ debug::DebugSink, device::manager::DEVICE_REGISTRY, vfs::{Terminal, TerminalInput, TerminalOutput}, }; use libk_mm::{address::PhysicalAddress, device::DeviceMemoryIo}; -use libk_util::{sync::IrqSafeSpinlock, OneTimeInit}; +use libk_util::{OneTimeInit, sync::IrqSafeSpinlock}; use tock_registers::{ interfaces::{ReadWriteable, Readable, Writeable}, register_bitfields, register_structs, diff --git a/kernel/driver/bsp/bcm283x/src/gpio.rs b/kernel/driver/bsp/bcm283x/src/gpio.rs index bdc5879f..005ca94c 100644 --- a/kernel/driver/bsp/bcm283x/src/gpio.rs +++ b/kernel/driver/bsp/bcm283x/src/gpio.rs @@ -5,11 +5,11 @@ use device_api::{ interrupt::{InterruptHandler, IrqHandle, IrqVector}, }; use device_tree::{ - driver::{ - device_tree_driver, util::generic_gpio_config, DeviceTreeGpioPins, DeviceTreePinController, - Node, ProbeContext, - }, DeviceTreePropertyRead, TProp, + driver::{ + DeviceTreeGpioPins, DeviceTreePinController, Node, ProbeContext, device_tree_driver, + util::generic_gpio_config, + }, }; use libk_mm::device::DeviceMemoryIo; use libk_util::sync::IrqSafeSpinlock; diff --git a/kernel/driver/bsp/bcm283x/src/mbox.rs b/kernel/driver/bsp/bcm283x/src/mbox.rs index 33664b7d..9ef66f37 100644 --- a/kernel/driver/bsp/bcm283x/src/mbox.rs +++ b/kernel/driver/bsp/bcm283x/src/mbox.rs @@ -2,7 +2,7 @@ use core::{cell::UnsafeCell, mem::MaybeUninit}; use alloc::sync::Arc; use device_api::device::{Device, DeviceInitContext}; -use device_tree::driver::{device_tree_driver, Node, ProbeContext}; +use device_tree::driver::{Node, ProbeContext, device_tree_driver}; use kernel_arch_aarch64::mem::table::L3; use libk::device::{ display::{ @@ -11,10 +11,10 @@ use libk::device::{ manager::DEVICE_REGISTRY, }; use libk_mm::{ + OnDemandPage, PageBox, PageProvider, VirtualPage, address::{AsPhysicalAddress, PhysicalAddress}, device::DeviceMemoryIo, table::{EntryLevel, MapAttributes}, - OnDemandPage, PageBox, PageProvider, VirtualPage, }; use libk_util::sync::IrqSafeSpinlock; use tock_registers::{ diff --git a/kernel/driver/bsp/jh7110/src/clocks.rs b/kernel/driver/bsp/jh7110/src/clocks.rs index 56764a84..360c7d7f 100644 --- a/kernel/driver/bsp/jh7110/src/clocks.rs +++ b/kernel/driver/bsp/jh7110/src/clocks.rs @@ -6,11 +6,11 @@ use device_api::{ device::{Device, DeviceInitContext}, }; use device_tree::{ - driver::{ - device_tree_driver, lookup_phandle, DeviceTreeClockController, DeviceTreeResetController, - DeviceTreeSyscon, Node, ProbeContext, - }, DeviceTreePropertyRead, TProp, + driver::{ + DeviceTreeClockController, DeviceTreeResetController, DeviceTreeSyscon, Node, ProbeContext, + device_tree_driver, lookup_phandle, + }, }; use libk_mm::{address::PhysicalAddress, device::DeviceMemoryIoMut}; use libk_util::sync::IrqSafeSpinlock; @@ -171,7 +171,7 @@ trait ClockDefinition { const CLOCKS: &'static [Option<(&'static str, ClockDef)>]; } -const SYSCRG_CLOCKS: &'static [Option<(&'static str, ClockDef)>] = &const { +const SYSCRG_CLOCKS: &[Option<(&'static str, ClockDef)>] = &const { use ClockDef::*; let mut t = [const { None }; SYSCRG_CLOCK_COUNT]; @@ -230,7 +230,7 @@ const SYSCRG_CLOCKS: &'static [Option<(&'static str, ClockDef)>] = &const { t }; -const AONCRG_CLOCKS: &'static [Option<(&'static str, ClockDef)>] = &const { +const AONCRG_CLOCKS: &[Option<(&'static str, ClockDef)>] = &const { use ClockDef::*; let mut t = [const { None }; AONCRG_CLOCK_COUNT]; @@ -262,7 +262,7 @@ const AONCRG_CLOCKS: &'static [Option<(&'static str, ClockDef)>] = &const { t }; -const STGCRG_CLOCKS: &'static [Option<(&'static str, ClockDef)>] = &const { +const STGCRG_CLOCKS: &[Option<(&'static str, ClockDef)>] = &const { use ClockDef::*; let mut t = [const { None }; STGCRG_CLOCK_COUNT]; diff --git a/kernel/driver/bsp/jh7110/src/lib.rs b/kernel/driver/bsp/jh7110/src/lib.rs index b0e44139..bcd7980f 100644 --- a/kernel/driver/bsp/jh7110/src/lib.rs +++ b/kernel/driver/bsp/jh7110/src/lib.rs @@ -1,4 +1,4 @@ -#![allow(unsafe_op_in_unsafe_fn)] +#![allow(unsafe_op_in_unsafe_fn, clippy::eq_op, clippy::erasing_op)] #![no_std] extern crate alloc; diff --git a/kernel/driver/bsp/jh7110/src/pinctrl.rs b/kernel/driver/bsp/jh7110/src/pinctrl.rs index 8d31e2c6..4a28a523 100644 --- a/kernel/driver/bsp/jh7110/src/pinctrl.rs +++ b/kernel/driver/bsp/jh7110/src/pinctrl.rs @@ -8,15 +8,14 @@ use device_api::{ }, }; use device_tree::{ - driver::{ - device_tree_driver, - util::{generic_gpio_config, GenericPinctrlBiasConfig, GenericPinctrlConfig}, - DeviceTreeGpioPins, DeviceTreePinController, Node, ProbeContext, - }, DeviceTreePropertyRead, TProp, + driver::{ + DeviceTreeGpioPins, DeviceTreePinController, Node, ProbeContext, device_tree_driver, + util::{GenericPinctrlBiasConfig, GenericPinctrlConfig, generic_gpio_config}, + }, }; use libk_mm::{address::PhysicalAddress, device::DeviceMemoryIoMut}; -use libk_util::{bit::BitField, sync::IrqSafeSpinlock, OneTimeInit}; +use libk_util::{OneTimeInit, bit::BitField, sync::IrqSafeSpinlock}; use yggdrasil_abi::error::Error; #[derive(Debug)] diff --git a/kernel/driver/bsp/riscv/src/goldfish_rtc.rs b/kernel/driver/bsp/riscv/src/goldfish_rtc.rs index a62a3810..0a3f497e 100644 --- a/kernel/driver/bsp/riscv/src/goldfish_rtc.rs +++ b/kernel/driver/bsp/riscv/src/goldfish_rtc.rs @@ -1,6 +1,6 @@ use alloc::sync::Arc; use device_api::device::{Device, DeviceInitContext}; -use device_tree::driver::{device_tree_driver, Node, ProbeContext}; +use device_tree::driver::{Node, ProbeContext, device_tree_driver}; use libk::{ error::Error, fs::sysfs::{self, nodes::SysfsRtcNode}, diff --git a/kernel/driver/bsp/riscv/src/plic.rs b/kernel/driver/bsp/riscv/src/plic.rs index f5277636..a46f9a58 100644 --- a/kernel/driver/bsp/riscv/src/plic.rs +++ b/kernel/driver/bsp/riscv/src/plic.rs @@ -7,15 +7,15 @@ use device_api::{ }, }; use device_tree::{ - driver::{ - device_tree_driver, lookup_phandle, DeviceTreeInterruptController, Node, ProbeContext, - }, DeviceTreePropertyRead, TProp, + driver::{ + DeviceTreeInterruptController, Node, ProbeContext, device_tree_driver, lookup_phandle, + }, }; use kernel_arch_riscv64::boot_hart_id; use libk::{arch::Cpu, device::register_external_interrupt_controller}; use libk_mm::{address::PhysicalAddress, device::DeviceMemoryIo}; -use libk_util::{sync::spin_rwlock::IrqSafeRwLock, OneTimeInit}; +use libk_util::{OneTimeInit, sync::spin_rwlock::IrqSafeRwLock}; use tock_registers::{ interfaces::{Readable, Writeable}, register_structs, diff --git a/kernel/driver/bus/pci/Cargo.toml b/kernel/driver/bus/pci/Cargo.toml index c06f5ee3..58ea3615 100644 --- a/kernel/driver/bus/pci/Cargo.toml +++ b/kernel/driver/bus/pci/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "ygg_driver_pci" version = "0.1.0" -edition = "2021" +edition = "2024" authors = ["Mark Poliakov "] [dependencies] diff --git a/kernel/driver/bus/pci/src/capability.rs b/kernel/driver/bus/pci/src/capability.rs index 8e53e948..f75ce327 100644 --- a/kernel/driver/bus/pci/src/capability.rs +++ b/kernel/driver/bus/pci/src/capability.rs @@ -498,7 +498,7 @@ impl MsiXVectorTableAccess<'_> { impl MsiXVectorTable<'_> { unsafe fn memory_from_raw_parts(base: PhysicalAddress, len: usize) -> Result { - let vectors = DeviceMemoryIoMut::map_slice(base, len, Default::default())?; + let vectors = unsafe { DeviceMemoryIoMut::map_slice(base, len, Default::default()) }?; Ok(Self { access: MsiXVectorTableAccess::Memory(vectors), len, diff --git a/kernel/driver/bus/pci/src/device.rs b/kernel/driver/bus/pci/src/device.rs index eb124996..770ef60d 100644 --- a/kernel/driver/bus/pci/src/device.rs +++ b/kernel/driver/bus/pci/src/device.rs @@ -9,13 +9,13 @@ use device_api::{ }, }; use libk::device::external_interrupt_controller; -use libk_util::{sync::spin_rwlock::IrqSafeRwLock, OneTimeInit}; +use libk_util::{OneTimeInit, sync::spin_rwlock::IrqSafeRwLock}; use yggdrasil_abi::error::Error; use crate::{ + PciAddress, PciCommandRegister, PciConfigSpace, PciConfigurationSpace, PciSegmentInfo, capability::{MsiCapability, MsiXCapability, MsiXVectorTable}, driver::PciDriver, - PciAddress, PciCommandRegister, PciConfigSpace, PciConfigurationSpace, PciSegmentInfo, }; /// Describes a PCI device @@ -152,22 +152,21 @@ impl PciDeviceInfo { let mut result = None; if want_msix && let Some(mut msix) = self.config_space.capability::() + && let Ok(mut vt) = msix.vector_table() { - if let Ok(mut vt) = msix.vector_table() { - if let Some(mut msi) = self.config_space.capability::() { - msi.set_enabled(false); - } - - vt.mask_all(); - - msix.set_function_mask(false); - msix.set_enabled(true); - - result = Some(ConfiguredInterruptMode::MsiX( - msi_route.controller.clone(), - vt, - )); + if let Some(mut msi) = self.config_space.capability::() { + msi.set_enabled(false); } + + vt.mask_all(); + + msix.set_function_mask(false); + msix.set_enabled(true); + + result = Some(ConfiguredInterruptMode::MsiX( + msi_route.controller.clone(), + vt, + )); } // Fall back to MSI if MSI-x is not available or not requested diff --git a/kernel/driver/bus/pci/src/interrupt.rs b/kernel/driver/bus/pci/src/interrupt.rs index e76ea9f9..3b1b99cc 100644 --- a/kernel/driver/bus/pci/src/interrupt.rs +++ b/kernel/driver/bus/pci/src/interrupt.rs @@ -5,8 +5,8 @@ use device_api::interrupt::MessageInterruptController; use libk::error::Error; use crate::{ - device::{PciInterrupt, PciInterruptRoute, PciMsiRoute}, PciAddress, + device::{PciInterrupt, PciInterruptRoute, PciMsiRoute}, }; #[derive(Debug)] diff --git a/kernel/driver/bus/pci/src/lib.rs b/kernel/driver/bus/pci/src/lib.rs index 9cf330a3..adab39b2 100644 --- a/kernel/driver/bus/pci/src/lib.rs +++ b/kernel/driver/bus/pci/src/lib.rs @@ -1,6 +1,6 @@ //! PCI/PCIe bus interfaces #![no_std] -#![feature(let_chains, decl_macro)] +#![feature(decl_macro)] #![allow(clippy::missing_transmute_annotations, clippy::identity_op)] extern crate alloc; @@ -20,7 +20,7 @@ use libk::{ fs::sysfs::{self, object::KObject}, }; use libk_mm::address::PhysicalAddress; -use libk_util::{sync::IrqSafeSpinlock, OneTimeInit}; +use libk_util::{OneTimeInit, sync::IrqSafeSpinlock}; use space::legacy; use yggdrasil_abi::{error::Error, primitive_enum}; @@ -36,9 +36,9 @@ mod nodes; mod space; pub use space::{ + PciConfigSpace, PciConfigurationSpace, ecam::PciEcam, legacy::{LegacyPciAccess, PciLegacyConfigurationSpace}, - PciConfigSpace, PciConfigurationSpace, }; bitflags! { diff --git a/kernel/driver/bus/pci/src/macros.rs b/kernel/driver/bus/pci/src/macros.rs index bb7e3f09..ab35844a 100644 --- a/kernel/driver/bus/pci/src/macros.rs +++ b/kernel/driver/bus/pci/src/macros.rs @@ -17,7 +17,7 @@ pub macro pci_driver( matches: [$($kind:ident $match:tt),+ $(,)?], driver: $driver:tt ) { - #[link_section = ".init_array"] + #[unsafe(link_section = ".init_array")] #[used] static __REGISTER_FN: extern "C" fn() = __register_fn; diff --git a/kernel/driver/bus/pci/src/nodes.rs b/kernel/driver/bus/pci/src/nodes.rs index 344cdd7b..d51c8bbb 100644 --- a/kernel/driver/bus/pci/src/nodes.rs +++ b/kernel/driver/bus/pci/src/nodes.rs @@ -8,7 +8,7 @@ use libk::{ }; use libk_util::sync::IrqSafeSpinlock; -use crate::{device::PciBusDevice, PciBaseAddress, PciCapabilityId, PciConfigurationSpace}; +use crate::{PciBaseAddress, PciCapabilityId, PciConfigurationSpace, device::PciBusDevice}; pub(crate) fn make_sysfs_object( device: PciBusDevice, diff --git a/kernel/driver/bus/pci/src/space/ecam.rs b/kernel/driver/bus/pci/src/space/ecam.rs index 15ab2744..d9aa708a 100644 --- a/kernel/driver/bus/pci/src/space/ecam.rs +++ b/kernel/driver/bus/pci/src/space/ecam.rs @@ -32,7 +32,7 @@ impl PciEcam { /// regions. The address must be aligned to a 4KiB boundary and be valid for accesses within a /// 4KiB-sized range. pub unsafe fn map(phys_addr: PhysicalAddress) -> Result { - let mapping = DeviceMemoryMapping::map(phys_addr, 0x1000, Default::default())?; + let mapping = unsafe { DeviceMemoryMapping::map(phys_addr, 0x1000, Default::default()) }?; Ok(Self { mapping }) } @@ -53,7 +53,7 @@ impl PciEcam { + address.function as usize) * 0x1000, ); - let this = Self::map(phys_addr)?; + let this = unsafe { Self::map(phys_addr) }?; Ok(if this.is_valid() { Some(this) } else { None }) } diff --git a/kernel/driver/bus/pci/src/space/mod.rs b/kernel/driver/bus/pci/src/space/mod.rs index 6b8326bf..f46558ad 100644 --- a/kernel/driver/bus/pci/src/space/mod.rs +++ b/kernel/driver/bus/pci/src/space/mod.rs @@ -2,7 +2,7 @@ use alloc::sync::Arc; use legacy::PciLegacyConfigurationSpace; use super::{PciAddress, PciBaseAddress, PciCapability, PciCapabilityId, PciEcam}; -use crate::{device::PciInterruptPin, PciCommandRegister, PciStatusRegister}; +use crate::{PciCommandRegister, PciStatusRegister, device::PciInterruptPin}; pub(super) mod ecam; pub(super) mod legacy; @@ -26,9 +26,7 @@ macro_rules! pci_config_field_setter { $self.write_u32($offset, $value) }; - ($self:ident, u16, $offset:expr, $value:expr) => {{ - $self.write_u16($offset, $value) - }}; + ($self:ident, u16, $offset:expr, $value:expr) => {{ $self.write_u16($offset, $value) }}; ($self:ident, u8, $offset:expr, $value:expr) => { $self.write_u8($offset, $value) @@ -222,11 +220,7 @@ pub trait PciConfigurationSpace { fn interrupt_line(&self) -> Option { let value = self.read_u8(0x3C); - if value < 16 { - Some(value) - } else { - None - } + if value < 16 { Some(value) } else { None } } /// # Safety @@ -248,7 +242,7 @@ pub trait PciConfigurationSpace { PciBaseAddress::Memory32(_) => PciBaseAddress::Memory32(0xFFFFFFF0), PciBaseAddress::Memory64(_) => PciBaseAddress::Memory64(0xFFFFFFFFFFFFFFF0), }; - self.set_bar(index, mask_value); + unsafe { self.set_bar(index, mask_value) }; let new_value = self.bar(index).unwrap(); let size = match new_value { @@ -258,7 +252,7 @@ pub trait PciConfigurationSpace { _ => 0, }; - self.set_bar(index, orig_value); + unsafe { self.set_bar(index, orig_value) }; self.set_command(cmd); size @@ -302,7 +296,7 @@ pub trait PciConfigurationSpace { fn bar(&self, index: usize) -> Option { assert!(index < 6); - if index % 2 == 0 { + if index.is_multiple_of(2) { let w0 = self.read_u32(0x10 + index * 4); match w0 & 1 { diff --git a/kernel/driver/bus/usb/src/bus.rs b/kernel/driver/bus/usb/src/bus.rs index 721a54a1..4583be40 100644 --- a/kernel/driver/bus/usb/src/bus.rs +++ b/kernel/driver/bus/usb/src/bus.rs @@ -4,9 +4,8 @@ use alloc::{collections::BTreeMap, sync::Arc}; use libk_util::{queue::UnboundedMpmcQueue, sync::spin_rwlock::IrqSafeRwLock}; use crate::{ - class_driver, + UsbHostController, class_driver, device::{UsbBusAddress, UsbDeviceAccess}, - UsbHostController, }; pub struct UsbBusManager { diff --git a/kernel/driver/bus/usb/src/class_driver/mass_storage.rs b/kernel/driver/bus/usb/src/class_driver/mass_storage.rs index c820a91c..8e5e3552 100644 --- a/kernel/driver/bus/usb/src/class_driver/mass_storage.rs +++ b/kernel/driver/bus/usb/src/class_driver/mass_storage.rs @@ -7,7 +7,7 @@ use libk::{ dma::{DmaBuffer, DmaSliceMut}, error::Error, }; -use ygg_driver_scsi::{transport::ScsiTransport, ScsiEnclosure}; +use ygg_driver_scsi::{ScsiEnclosure, transport::ScsiTransport}; use crate::{ communication::UsbDirection, diff --git a/kernel/driver/bus/usb/src/device.rs b/kernel/driver/bus/usb/src/device.rs index 90af7038..c56e3230 100644 --- a/kernel/driver/bus/usb/src/device.rs +++ b/kernel/driver/bus/usb/src/device.rs @@ -5,6 +5,7 @@ use async_trait::async_trait; use libk_util::sync::spin_rwlock::{IrqSafeRwLock, IrqSafeRwLockReadGuard}; use crate::{ + UsbHostController, error::UsbError, info::{ UsbConfigurationInfo, UsbDeviceInfo, UsbEndpointInfo, UsbEndpointType, UsbInterfaceInfo, @@ -17,7 +18,6 @@ use crate::{ UsbNormalPipeOut, }, }, - UsbHostController, }; // High-level structures for info provided through descriptors diff --git a/kernel/driver/bus/usb/src/lib.rs b/kernel/driver/bus/usb/src/lib.rs index 6fab4795..26f2ceec 100644 --- a/kernel/driver/bus/usb/src/lib.rs +++ b/kernel/driver/bus/usb/src/lib.rs @@ -1,10 +1,9 @@ #![no_std] -#![allow(clippy::new_without_default)] +#![allow(clippy::new_without_default, incomplete_features)] #![feature( + generic_const_exprs, iter_array_chunks, - maybe_uninit_slice, maybe_uninit_as_bytes, - maybe_uninit_write_slice, maybe_uninit_fill )] diff --git a/kernel/driver/bus/usb/src/pipe/control.rs b/kernel/driver/bus/usb/src/pipe/control.rs index 5133c31f..ad123717 100644 --- a/kernel/driver/bus/usb/src/pipe/control.rs +++ b/kernel/driver/bus/usb/src/pipe/control.rs @@ -1,5 +1,5 @@ use core::{ - mem::{size_of, MaybeUninit}, + mem::{MaybeUninit, size_of}, ops::Deref, }; @@ -66,7 +66,7 @@ impl UsbDeviceRequest for U { } fn decode_usb_string(bytes: &[u8]) -> Result { - if bytes.len() % 2 != 0 { + if !bytes.len().is_multiple_of(2) { return Err(UsbError::InvalidDescriptorField); } diff --git a/kernel/driver/fs/ext2/src/dir/mod.rs b/kernel/driver/fs/ext2/src/dir/mod.rs index 7b5a3fff..7ee99d86 100644 --- a/kernel/driver/fs/ext2/src/dir/mod.rs +++ b/kernel/driver/fs/ext2/src/dir/mod.rs @@ -18,7 +18,7 @@ use libk::{ use walk::{DirentIter, DirentIterMut}; use yggdrasil_abi::io::{DirectoryEntry, FileType}; -use crate::{file::RegularNode, inode::InodeAccess, symlink::SymlinkNode, Dirent, Ext2Fs, Inode}; +use crate::{Dirent, Ext2Fs, Inode, file::RegularNode, inode::InodeAccess, symlink::SymlinkNode}; mod walk; diff --git a/kernel/driver/fs/ext2/src/dir/walk.rs b/kernel/driver/fs/ext2/src/dir/walk.rs index 3265794e..9799b1e0 100644 --- a/kernel/driver/fs/ext2/src/dir/walk.rs +++ b/kernel/driver/fs/ext2/src/dir/walk.rs @@ -9,7 +9,7 @@ use yggdrasil_abi::{ util::FixedString, }; -use crate::{access::InodeBlock, data::FsRequiredFeatures, Dirent, Ext2Fs}; +use crate::{Dirent, Ext2Fs, access::InodeBlock, data::FsRequiredFeatures}; use super::DirentName; diff --git a/kernel/driver/fs/ext2/src/file.rs b/kernel/driver/fs/ext2/src/file.rs index 864b8f26..3d0e2c78 100644 --- a/kernel/driver/fs/ext2/src/file.rs +++ b/kernel/driver/fs/ext2/src/file.rs @@ -8,7 +8,7 @@ use libk::{ }; use yggdrasil_abi::io::OpenOptions; -use crate::{inode::InodeAccess, Ext2Fs}; +use crate::{Ext2Fs, inode::InodeAccess}; pub struct RegularNode { fs: Arc, diff --git a/kernel/driver/fs/ext2/src/inode/cache.rs b/kernel/driver/fs/ext2/src/inode/cache.rs index 90ba736d..a9183877 100644 --- a/kernel/driver/fs/ext2/src/inode/cache.rs +++ b/kernel/driver/fs/ext2/src/inode/cache.rs @@ -15,8 +15,8 @@ use yggdrasil_abi::{ }; use crate::{ - access::InodeBlock, data::InodeMode, dir::DirectoryNode, file::RegularNode, - symlink::SymlinkNode, Ext2Fs, Inode, + Ext2Fs, Inode, access::InodeBlock, data::InodeMode, dir::DirectoryNode, file::RegularNode, + symlink::SymlinkNode, }; pub struct InodeHolder { diff --git a/kernel/driver/fs/ext2/src/inode/mod.rs b/kernel/driver/fs/ext2/src/inode/mod.rs index e00bd9f1..ca80bfd6 100644 --- a/kernel/driver/fs/ext2/src/inode/mod.rs +++ b/kernel/driver/fs/ext2/src/inode/mod.rs @@ -4,8 +4,8 @@ use libk::error::Error; use yggdrasil_abi::io::FileType; use crate::{ - data::{FsReadonlyFeatures, DIRECT_BLOCK_COUNT}, Ext2Fs, Inode, + data::{DIRECT_BLOCK_COUNT, FsReadonlyFeatures}, }; pub mod cache; diff --git a/kernel/driver/fs/ext2/src/lib.rs b/kernel/driver/fs/ext2/src/lib.rs index 8265a48c..5936bc6b 100644 --- a/kernel/driver/fs/ext2/src/lib.rs +++ b/kernel/driver/fs/ext2/src/lib.rs @@ -9,12 +9,12 @@ use core::mem; use alloc::{boxed::Box, sync::Arc}; use async_trait::async_trait; use bytemuck::Zeroable; -use data::{FsReadonlyFeatures, FsRequiredFeatures, DIRECT_BLOCK_COUNT}; +use data::{DIRECT_BLOCK_COUNT, FsReadonlyFeatures, FsRequiredFeatures}; use dir::DirectoryNode; use file::RegularNode; use inode::{InodeAccess, InodeCache}; use libk::{ - device::block::{cache::DeviceMapper, BlockDevice}, + device::block::{BlockDevice, cache::DeviceMapper}, error::Error, vfs::{Filesystem, FilesystemMountOption, NodeRef}, }; diff --git a/kernel/driver/fs/ext2/src/symlink.rs b/kernel/driver/fs/ext2/src/symlink.rs index c50510b2..c1b005b8 100644 --- a/kernel/driver/fs/ext2/src/symlink.rs +++ b/kernel/driver/fs/ext2/src/symlink.rs @@ -8,7 +8,7 @@ use libk::{ }; use libk_util::sync::spin_rwlock::IrqSafeRwLock; -use crate::{inode::InodeAccess, Ext2Fs, Inode}; +use crate::{Ext2Fs, Inode, inode::InodeAccess}; pub struct SymlinkNode { fs: Arc, diff --git a/kernel/driver/fs/fat32/src/directory.rs b/kernel/driver/fs/fat32/src/directory.rs index 5be647ba..ad7e4ca5 100644 --- a/kernel/driver/fs/fat32/src/directory.rs +++ b/kernel/driver/fs/fat32/src/directory.rs @@ -12,7 +12,7 @@ use libk::{ }; use libk_util::{ get_le_u16, get_le_u32, - string::{chars_equal_ignore_case, Utf16LeStr}, + string::{Utf16LeStr, chars_equal_ignore_case}, }; use yggdrasil_abi::{ io::{DirectoryEntry, FileMode, GroupId, UserId}, @@ -21,9 +21,9 @@ use yggdrasil_abi::{ }; use crate::{ + Fat32Fs, data::{ClusterNumber, FatStr}, file::FileNode, - Fat32Fs, }; pub const DIRENT_SIZE: usize = 32; diff --git a/kernel/driver/fs/fat32/src/file.rs b/kernel/driver/fs/fat32/src/file.rs index 88e61e2f..12a8f5f9 100644 --- a/kernel/driver/fs/fat32/src/file.rs +++ b/kernel/driver/fs/fat32/src/file.rs @@ -9,7 +9,7 @@ use libk::{ }; use yggdrasil_abi::io::OpenOptions; -use crate::{data::ClusterNumber, Fat32Fs}; +use crate::{Fat32Fs, data::ClusterNumber}; pub struct FileNode { pub(crate) fs: Arc, diff --git a/kernel/driver/fs/fat32/src/lib.rs b/kernel/driver/fs/fat32/src/lib.rs index 480de9ec..a2ba2e69 100644 --- a/kernel/driver/fs/fat32/src/lib.rs +++ b/kernel/driver/fs/fat32/src/lib.rs @@ -5,7 +5,7 @@ use async_trait::async_trait; use data::{Bpb, ClusterNumber, Fat32Ebpb, Fat32FsInfo}; use directory::DirectoryNode; use libk::{ - device::block::{cache::DeviceMapper, BlockDevice}, + device::block::{BlockDevice, cache::DeviceMapper}, error::Error, vfs::{Filesystem, FilesystemMountOption, Metadata, Node, NodeFlags, NodeRef}, }; diff --git a/kernel/driver/fs/kernel-fs/src/devfs.rs b/kernel/driver/fs/kernel-fs/src/devfs.rs index e69de29b..8b137891 100644 --- a/kernel/driver/fs/kernel-fs/src/devfs.rs +++ b/kernel/driver/fs/kernel-fs/src/devfs.rs @@ -0,0 +1 @@ + diff --git a/kernel/driver/fs/memfs/src/block.rs b/kernel/driver/fs/memfs/src/block.rs index 62ba7042..9c0bd9d1 100644 --- a/kernel/driver/fs/memfs/src/block.rs +++ b/kernel/driver/fs/memfs/src/block.rs @@ -1,7 +1,7 @@ //! Block management interfaces and structures use core::{ marker::PhantomData, - mem::{size_of, MaybeUninit}, + mem::{MaybeUninit, size_of}, ops::{Deref, DerefMut}, ptr::NonNull, }; diff --git a/kernel/driver/fs/memfs/src/dir.rs b/kernel/driver/fs/memfs/src/dir.rs index 1ea35686..8365ec5e 100644 --- a/kernel/driver/fs/memfs/src/dir.rs +++ b/kernel/driver/fs/memfs/src/dir.rs @@ -3,12 +3,12 @@ use core::sync::atomic::Ordering; use alloc::sync::Arc; use libk::vfs::{ - impls::fixed_path_symlink_ext, CommonImpl, CreateFileType, CreateInfo, DirectoryImpl, - DirectoryOpenPosition, Metadata, Node, NodeFlags, NodeRef, + CommonImpl, CreateFileType, CreateInfo, DirectoryImpl, DirectoryOpenPosition, Metadata, Node, + NodeFlags, NodeRef, impls::fixed_path_symlink_ext, }; use yggdrasil_abi::error::Error; -use crate::{block::BlockAllocator, file::FileNode, MemoryFilesystem, INO_COUNTER}; +use crate::{INO_COUNTER, MemoryFilesystem, block::BlockAllocator, file::FileNode}; pub(crate) struct DirectoryNode { fs: Arc>, diff --git a/kernel/driver/fs/memfs/src/file.rs b/kernel/driver/fs/memfs/src/file.rs index d80f3f22..5f9484dc 100644 --- a/kernel/driver/fs/memfs/src/file.rs +++ b/kernel/driver/fs/memfs/src/file.rs @@ -2,10 +2,10 @@ use alloc::sync::Arc; use core::any::Any; use libk::vfs::{CommonImpl, InstanceData, Metadata, Node, NodeFlags, NodeRef, RegularImpl}; -use libk_util::sync::{spin_rwlock::IrqSafeRwLock, IrqSafeSpinlock}; +use libk_util::sync::{IrqSafeSpinlock, spin_rwlock::IrqSafeRwLock}; use yggdrasil_abi::{error::Error, io::OpenOptions}; -use crate::{block::BlockAllocator, bvec::BVec, MemoryFilesystem}; +use crate::{MemoryFilesystem, block::BlockAllocator, bvec::BVec}; pub(crate) struct FileNode { pub(crate) data: IrqSafeSpinlock>, diff --git a/kernel/driver/fs/memfs/src/lib.rs b/kernel/driver/fs/memfs/src/lib.rs index fdd3def1..5bf41643 100644 --- a/kernel/driver/fs/memfs/src/lib.rs +++ b/kernel/driver/fs/memfs/src/lib.rs @@ -13,7 +13,7 @@ use alloc::sync::Arc; use block::BlockAllocator; use dir::DirectoryNode; use file::FileNode; -use libk::vfs::{impls::fixed_path_symlink, AccessToken, Filename, Filesystem, Metadata, NodeRef}; +use libk::vfs::{AccessToken, Filename, Filesystem, Metadata, NodeRef, impls::fixed_path_symlink}; use libk_util::sync::IrqSafeSpinlock; use tar::TarEntry; use yggdrasil_abi::{ diff --git a/kernel/driver/fs/memfs/src/symlink.rs b/kernel/driver/fs/memfs/src/symlink.rs index e69de29b..8b137891 100644 --- a/kernel/driver/fs/memfs/src/symlink.rs +++ b/kernel/driver/fs/memfs/src/symlink.rs @@ -0,0 +1 @@ + diff --git a/kernel/driver/input/src/lib.rs b/kernel/driver/input/src/lib.rs index b3523d3a..39812673 100644 --- a/kernel/driver/input/src/lib.rs +++ b/kernel/driver/input/src/lib.rs @@ -8,7 +8,7 @@ use alloc::{boxed::Box, sync::Arc}; use async_trait::async_trait; use device_api::device::Device; use libk::{device::char::CharDevice, vfs::FileReadiness}; -use libk_util::{ring::LossyRingQueue, OneTimeInit}; +use libk_util::{OneTimeInit, ring::LossyRingQueue}; use yggdrasil_abi::{error::Error, io::KeyboardKeyEvent}; #[derive(Clone, Copy)] diff --git a/kernel/driver/net/core/Cargo.toml b/kernel/driver/net/core/Cargo.toml index 2c26d866..9af3681b 100644 --- a/kernel/driver/net/core/Cargo.toml +++ b/kernel/driver/net/core/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "ygg_driver_net_core" version = "0.1.0" -edition = "2021" +edition = "2024" [dependencies] yggdrasil-abi = { workspace = true, features = ["serde_kernel", "bytemuck"] } diff --git a/kernel/driver/net/core/src/config.rs b/kernel/driver/net/core/src/config.rs index 4aa4f012..c2ca1981 100644 --- a/kernel/driver/net/core/src/config.rs +++ b/kernel/driver/net/core/src/config.rs @@ -5,17 +5,17 @@ use yggdrasil_abi::{ error::Error, io::{ChannelPublisherId, MessageDestination}, net::{ + IpAddr, SubnetAddr, netconfig::{ InterfaceInfo, InterfaceQuery, NetConfigRequest, NetConfigResult, RouteInfo, RoutingInfo, }, - IpAddr, SubnetAddr, }, }; use crate::{ interface::NetworkInterface, - l3::{arp, Route}, + l3::{Route, arp}, }; async fn receive_request( diff --git a/kernel/driver/net/core/src/ethernet.rs b/kernel/driver/net/core/src/ethernet.rs index fa3a8ceb..ff484e1a 100644 --- a/kernel/driver/net/core/src/ethernet.rs +++ b/kernel/driver/net/core/src/ethernet.rs @@ -6,9 +6,9 @@ use libk::dma::DmaBuffer; use yggdrasil_abi::{ error::Error, net::{ + MacAddress, protocols::{EtherType, EthernetFrame}, types::NetValueImpl, - MacAddress, }, }; diff --git a/kernel/driver/net/core/src/interface.rs b/kernel/driver/net/core/src/interface.rs index f558675e..2c7dc56c 100644 --- a/kernel/driver/net/core/src/interface.rs +++ b/kernel/driver/net/core/src/interface.rs @@ -1,5 +1,5 @@ use core::{ - mem::{size_of, MaybeUninit}, + mem::{MaybeUninit, size_of}, net::IpAddr, sync::atomic::{AtomicU32, AtomicUsize, Ordering}, }; @@ -8,17 +8,17 @@ use alloc::{boxed::Box, collections::BTreeMap, format, sync::Arc}; use libk::dma::DmaBuffer; // TODO: link state management? use libk_util::{ - sync::spin_rwlock::{IrqSafeRwLock, IrqSafeRwLockReadGuard}, OneTimeInit, + sync::spin_rwlock::{IrqSafeRwLock, IrqSafeRwLockReadGuard}, }; use yggdrasil_abi::{ error::Error, - net::{link::LinkState, protocols::EthernetFrame, MacAddress}, + net::{MacAddress, link::LinkState, protocols::EthernetFrame}, }; use crate::{ - l3::{arp::ArpTable, Route}, TxPacketBuilder, + l3::{Route, arp::ArpTable}, }; pub trait NetworkDevice: Sync + Send { diff --git a/kernel/driver/net/core/src/l3/arp.rs b/kernel/driver/net/core/src/l3/arp.rs index e086f30f..2ecb91f6 100644 --- a/kernel/driver/net/core/src/l3/arp.rs +++ b/kernel/driver/net/core/src/l3/arp.rs @@ -13,13 +13,13 @@ use libk_util::{sync::spin_rwlock::IrqSafeRwLock, waker::QueueWaker}; use yggdrasil_abi::{ error::Error, net::{ + MacAddress, protocols::{ArpFrame, EtherType}, types::NetValueImpl, - MacAddress, }, }; -use crate::{ethernet, interface::NetworkInterface, L2Packet}; +use crate::{L2Packet, ethernet, interface::NetworkInterface}; struct Inner { entries: BTreeMap<(u32, A), (MacAddress, bool)>, diff --git a/kernel/driver/net/core/src/l3/ip.rs b/kernel/driver/net/core/src/l3/ip.rs index 20ff3223..70d7a372 100644 --- a/kernel/driver/net/core/src/l3/ip.rs +++ b/kernel/driver/net/core/src/l3/ip.rs @@ -12,7 +12,7 @@ use yggdrasil_abi::{ }, }; -use crate::{interface::NetworkInterface, L2Packet, L3Packet, ACCEPT_QUEUE}; +use crate::{ACCEPT_QUEUE, L2Packet, L3Packet, interface::NetworkInterface}; use super::IpFrame; diff --git a/kernel/driver/net/core/src/l3/mod.rs b/kernel/driver/net/core/src/l3/mod.rs index 2ecf2b0e..68d769af 100644 --- a/kernel/driver/net/core/src/l3/mod.rs +++ b/kernel/driver/net/core/src/l3/mod.rs @@ -13,13 +13,13 @@ use libk_util::sync::spin_rwlock::{ use yggdrasil_abi::{ error::Error, net::{ + MacAddress, SubnetAddr, protocols::{EtherType, EthernetFrame, InetChecksum, IpProtocol, Ipv4Frame}, types::NetValueImpl, - MacAddress, SubnetAddr, }, }; -use crate::{interface::NetworkInterface, l4, TxPacketBuilder}; +use crate::{TxPacketBuilder, interface::NetworkInterface, l4}; pub mod arp; pub mod ip; diff --git a/kernel/driver/net/core/src/l4/icmp.rs b/kernel/driver/net/core/src/l4/icmp.rs index 06d61f3d..0b5d5eac 100644 --- a/kernel/driver/net/core/src/l4/icmp.rs +++ b/kernel/driver/net/core/src/l4/icmp.rs @@ -6,15 +6,15 @@ use core::{ use yggdrasil_abi::{ error::Error, net::{ + SubnetAddr, SubnetV4Addr, protocols::{IcmpV4Frame, InetChecksum, IpProtocol}, types::NetValueImpl, - SubnetAddr, SubnetV4Addr, }, }; use crate::{ - l3::{self, Route}, L3Packet, + l3::{self, Route}, }; async fn send_v4_reply( @@ -29,7 +29,7 @@ async fn send_v4_reply( rest: icmp_frame.rest, }; - if icmp_data.len() % 2 != 0 { + if !icmp_data.len().is_multiple_of(2) { return Err(Error::InvalidArgument); } diff --git a/kernel/driver/net/core/src/l4/udp.rs b/kernel/driver/net/core/src/l4/udp.rs index d04b975b..62e5a547 100644 --- a/kernel/driver/net/core/src/l4/udp.rs +++ b/kernel/driver/net/core/src/l4/udp.rs @@ -11,7 +11,7 @@ use yggdrasil_abi::{ }, }; -use crate::{l3, socket::UdpSocket, L3Packet}; +use crate::{L3Packet, l3, socket::UdpSocket}; pub async fn send( source_port: u16, diff --git a/kernel/driver/net/core/src/lib.rs b/kernel/driver/net/core/src/lib.rs index 0c849ebf..55d588d9 100644 --- a/kernel/driver/net/core/src/lib.rs +++ b/kernel/driver/net/core/src/lib.rs @@ -1,4 +1,4 @@ -#![feature(map_try_insert, let_chains)] +#![feature(map_try_insert)] #![allow(clippy::type_complexity, clippy::new_without_default)] #![no_std] diff --git a/kernel/driver/net/core/src/socket/config.rs b/kernel/driver/net/core/src/socket/config.rs index 5982fc08..8033bcf5 100644 --- a/kernel/driver/net/core/src/socket/config.rs +++ b/kernel/driver/net/core/src/socket/config.rs @@ -14,19 +14,19 @@ use libk::{ use libk_mm::PageBox; use libk_util::queue::BoundedMpmcQueue; use yggdrasil_abi::{ - abi_serde::{wire, Serialize}, + abi_serde::{Serialize, wire}, net::{ + MacAddress, MessageHeader, MessageHeaderMut, SocketInterfaceQuery, SubnetAddr, netconfig::{ InterfaceBinding, InterfaceInfo, NetConfigRequest, NetConfigResult, RouteInfo, RoutingInfo, }, - MacAddress, MessageHeader, MessageHeaderMut, SocketInterfaceQuery, SubnetAddr, }, }; use crate::{ interface::NetworkInterface, - l3::{arp, Route}, + l3::{Route, arp}, }; pub struct NetConfigSocket { @@ -71,7 +71,7 @@ impl NetConfigSocket { None => { return self.write_response(NetConfigResult::::Err( "No such interface", - )) + )); } }; let result = match arp::lookup(iface.id(), query.address, true).await { @@ -123,7 +123,7 @@ impl NetConfigSocket { None => { return self.write_response(NetConfigResult::::Err( "No such interface", - )) + )); } }; let result = diff --git a/kernel/driver/net/core/src/socket/local/mod.rs b/kernel/driver/net/core/src/socket/local/mod.rs index 1e3e68b5..0b1cf25a 100644 --- a/kernel/driver/net/core/src/socket/local/mod.rs +++ b/kernel/driver/net/core/src/socket/local/mod.rs @@ -3,7 +3,7 @@ use alloc::sync::Arc; use libk::{error::Error, task::thread::Thread, vfs::File}; use yggdrasil_abi::{ abi_serde::wire, - net::{types::LocalSocketAddress, AncillaryMessage, MessageHeader, MessageHeaderMut}, + net::{AncillaryMessage, MessageHeader, MessageHeaderMut, types::LocalSocketAddress}, }; pub mod packet; @@ -35,8 +35,7 @@ pub fn read_ancillary(message: &MessageHeader) -> Result>, Erro } let ancillary: AncillaryMessage = wire::from_slice(message.ancillary)?; #[allow(irrefutable_let_patterns)] - let AncillaryMessage::File(fd) = ancillary - else { + let AncillaryMessage::File(fd) = ancillary else { log::warn!("local: invalid ancillary message: {ancillary:?}"); return Err(Error::InvalidArgument); }; diff --git a/kernel/driver/net/core/src/socket/local/packet.rs b/kernel/driver/net/core/src/socket/local/packet.rs index 1c10d1c0..cb913b6b 100644 --- a/kernel/driver/net/core/src/socket/local/packet.rs +++ b/kernel/driver/net/core/src/socket/local/packet.rs @@ -22,7 +22,7 @@ use libk_util::{ queue::BoundedMpmcQueue, sync::spin_rwlock::{IrqSafeRwLock, IrqSafeRwLockReadGuard}, }; -use yggdrasil_abi::net::{types::LocalSocketAddress, MessageHeader, MessageHeaderMut}; +use yggdrasil_abi::net::{MessageHeader, MessageHeaderMut, types::LocalSocketAddress}; use super::OwnedAddress; diff --git a/kernel/driver/net/core/src/socket/mod.rs b/kernel/driver/net/core/src/socket/mod.rs index f8b9a456..e161173c 100644 --- a/kernel/driver/net/core/src/socket/mod.rs +++ b/kernel/driver/net/core/src/socket/mod.rs @@ -1,7 +1,7 @@ use core::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6}; use alloc::{ - collections::{btree_map::Entry, BTreeMap}, + collections::{BTreeMap, btree_map::Entry}, sync::Arc, }; use yggdrasil_abi::error::Error; @@ -50,11 +50,7 @@ impl TwoWaySocketTable { const fn next_port_wrapping(port: u16) -> u16 { let port = port + 1; - if port >= u16::MAX - 1 { - 32768 - } else { - port - } + if port >= u16::MAX - 1 { 32768 } else { port } } fn try_insert_into_range Result, Error>, R: Iterator>( diff --git a/kernel/driver/net/core/src/socket/raw.rs b/kernel/driver/net/core/src/socket/raw.rs index 567914e7..f2c4cd4f 100644 --- a/kernel/driver/net/core/src/socket/raw.rs +++ b/kernel/driver/net/core/src/socket/raw.rs @@ -17,13 +17,13 @@ use libk_mm::PageBox; use libk_util::{queue::BoundedMpmcQueue, sync::spin_rwlock::IrqSafeRwLock}; use yggdrasil_abi::{ net::{ - options::{self, RawSocketOptionVariant}, MessageHeader, MessageHeaderMut, SocketInterfaceQuery, + options::{self, RawSocketOptionVariant}, }, option::OptionValue, }; -use crate::{ethernet::L2Packet, interface::NetworkInterface, TxPacketBuilder}; +use crate::{TxPacketBuilder, ethernet::L2Packet, interface::NetworkInterface}; enum RawPacket { Ingress(L2Packet), diff --git a/kernel/driver/net/core/src/socket/tcp/listener.rs b/kernel/driver/net/core/src/socket/tcp/listener.rs index ebf50098..cd28fccd 100644 --- a/kernel/driver/net/core/src/socket/tcp/listener.rs +++ b/kernel/driver/net/core/src/socket/tcp/listener.rs @@ -9,7 +9,7 @@ use core::{ use alloc::{collections::btree_map::BTreeMap, sync::Arc, vec::Vec}; use libk::error::Error; use libk_util::{ - sync::{spin_rwlock::IrqSafeRwLock, IrqSafeSpinlock, IrqSafeSpinlockGuard}, + sync::{IrqSafeSpinlock, IrqSafeSpinlockGuard, spin_rwlock::IrqSafeRwLock}, waker::QueueWaker, }; diff --git a/kernel/driver/net/core/src/socket/tcp/mod.rs b/kernel/driver/net/core/src/socket/tcp/mod.rs index 5b196d1b..f4b8ef99 100644 --- a/kernel/driver/net/core/src/socket/tcp/mod.rs +++ b/kernel/driver/net/core/src/socket/tcp/mod.rs @@ -16,8 +16,8 @@ use libk::{ use libk_util::sync::spin_rwlock::IrqSafeRwLock; use yggdrasil_abi::{ net::{ - options::{self, TcpSocketOptionVariant}, MessageHeader, MessageHeaderMut, + options::{self, TcpSocketOptionVariant}, }, option::OptionValue, }; diff --git a/kernel/driver/net/core/src/socket/tcp/stream.rs b/kernel/driver/net/core/src/socket/tcp/stream.rs index 26156fa1..c317da09 100644 --- a/kernel/driver/net/core/src/socket/tcp/stream.rs +++ b/kernel/driver/net/core/src/socket/tcp/stream.rs @@ -185,10 +185,8 @@ impl TcpStream { }) .await; - if remove_from_listener { - if let Some(listener) = self.listener.as_ref() { - listener.remove_stream(self.remote); - }; + if remove_from_listener && let Some(listener) = self.listener.as_ref() { + listener.remove_stream(self.remote); } Ok(()) diff --git a/kernel/driver/net/core/src/socket/udp.rs b/kernel/driver/net/core/src/socket/udp.rs index b39b1fbf..e42f6ead 100644 --- a/kernel/driver/net/core/src/socket/udp.rs +++ b/kernel/driver/net/core/src/socket/udp.rs @@ -19,8 +19,8 @@ use libk_util::{ }; use yggdrasil_abi::{ net::{ - options::{self, UdpSocketOptionVariant}, MessageHeader, MessageHeaderMut, + options::{self, UdpSocketOptionVariant}, }, option::OptionValue, }; diff --git a/kernel/driver/net/core/src/util.rs b/kernel/driver/net/core/src/util.rs index 1d012c69..0ba7bf0c 100644 --- a/kernel/driver/net/core/src/util.rs +++ b/kernel/driver/net/core/src/util.rs @@ -123,11 +123,7 @@ impl Assembler { /// Return length of the front contiguous range without removing it from the assembler pub fn peek_front(&self) -> usize { let front = self.front(); - if front.has_hole() { - 0 - } else { - front.data_size - } + if front.has_hole() { 0 } else { front.data_size } } fn back(&self) -> Contig { diff --git a/kernel/driver/net/igbe/src/lib.rs b/kernel/driver/net/igbe/src/lib.rs index 68b5121d..ce5f93c9 100644 --- a/kernel/driver/net/igbe/src/lib.rs +++ b/kernel/driver/net/igbe/src/lib.rs @@ -10,21 +10,22 @@ use device_api::{ }; use libk::{dma::DmaBuffer, error::Error}; use libk_util::{ - sync::{IrqSafeSpinlock, Spinlock}, OneTimeInit, + sync::{IrqSafeSpinlock, Spinlock}, }; -use regs::{Regs, ICR}; +use regs::{ICR, Regs}; use ring::{RxRing, TxRing}; use ygg_driver_net_core::{ + RxPacket, interface::{NetworkDevice, NetworkInterfaceType}, - register_interface, RxPacket, + register_interface, }; use ygg_driver_pci::{ + PciBaseAddress, PciConfigurationSpace, device::{PciDeviceInfo, PreferredInterruptMode}, macros::pci_driver, - PciBaseAddress, PciConfigurationSpace, }; -use yggdrasil_abi::net::{link::LinkState, MacAddress}; +use yggdrasil_abi::net::{MacAddress, link::LinkState}; use crate::regs::Revision; diff --git a/kernel/driver/net/igbe/src/regs.rs b/kernel/driver/net/igbe/src/regs.rs index 9b944834..3a53bee3 100644 --- a/kernel/driver/net/igbe/src/regs.rs +++ b/kernel/driver/net/igbe/src/regs.rs @@ -6,12 +6,12 @@ use libk::{ task::runtime::{psleep, pwait}, }; use libk_mm::{address::PhysicalAddress, device::RawDeviceMemoryMapping}; -use tock_registers::{fields::FieldValue, register_bitfields, LocalRegisterCopy, RegisterLongName}; -use ygg_driver_net_core::ephy::{MdioBus, PhyAccess, GBESR}; +use tock_registers::{LocalRegisterCopy, RegisterLongName, fields::FieldValue, register_bitfields}; +use ygg_driver_net_core::ephy::{GBESR, MdioBus, PhyAccess}; use ygg_driver_pci::PciBaseAddress; use yggdrasil_abi::net::{ - link::{Duplex, EthernetLinkState, EthernetSpeed}, MacAddress, + link::{Duplex, EthernetLinkState, EthernetSpeed}, }; use crate::{RxRing, TxRing}; diff --git a/kernel/driver/net/loopback/src/lib.rs b/kernel/driver/net/loopback/src/lib.rs index e7a79ff0..088d08e2 100644 --- a/kernel/driver/net/loopback/src/lib.rs +++ b/kernel/driver/net/loopback/src/lib.rs @@ -12,8 +12,8 @@ use device_api::dma::DmaAllocator; use libk::dma::{DmaBuffer, DummyDmaAllocator}; use libk_util::OneTimeInit; use ygg_driver_net_core::{ - interface::{NetworkDevice, NetworkInterfaceType}, RxPacket, + interface::{NetworkDevice, NetworkInterfaceType}, }; use yggdrasil_abi::{error::Error, net::MacAddress}; diff --git a/kernel/driver/net/rtl81xx/src/lib.rs b/kernel/driver/net/rtl81xx/src/lib.rs index 57d5f038..2939f441 100644 --- a/kernel/driver/net/rtl81xx/src/lib.rs +++ b/kernel/driver/net/rtl81xx/src/lib.rs @@ -6,12 +6,12 @@ use libk::error::Error; use rtl8139::Rtl8139; use rtl8168::Rtl8168; use ygg_driver_pci::{ + PciBaseAddress, PciCommandRegister, PciConfigurationSpace, capability::{ DevicePowerState, PciExpressCapability, PcieLinkControl, PowerManagementCapability, }, device::{PciDeviceInfo, PreferredInterruptMode}, macros::pci_driver, - PciBaseAddress, PciCommandRegister, PciConfigurationSpace, }; extern crate alloc; diff --git a/kernel/driver/net/rtl81xx/src/rtl8139.rs b/kernel/driver/net/rtl81xx/src/rtl8139.rs index 24bb96f6..d8e824ca 100644 --- a/kernel/driver/net/rtl81xx/src/rtl8139.rs +++ b/kernel/driver/net/rtl81xx/src/rtl8139.rs @@ -8,15 +8,15 @@ use device_api::{ }; use libk::{dma::DmaBuffer, error::Error}; use libk_mm::{address::PhysicalAddress, device::DeviceMemoryIo}; -use libk_util::{queue::BoundedQueue, sync::IrqSafeSpinlock, OneTimeInit}; +use libk_util::{OneTimeInit, queue::BoundedQueue, sync::IrqSafeSpinlock}; use tock_registers::{ interfaces::{ReadWriteable, Readable, Writeable}, register_bitfields, register_structs, registers::{ReadOnly, ReadWrite}, }; use ygg_driver_net_core::{ - interface::{NetworkDevice, NetworkInterfaceType}, RxPacket, + interface::{NetworkDevice, NetworkInterfaceType}, }; use ygg_driver_pci::device::PciDeviceInfo; use yggdrasil_abi::net::MacAddress; diff --git a/kernel/driver/net/rtl81xx/src/rtl8168.rs b/kernel/driver/net/rtl81xx/src/rtl8168.rs index 03f26dff..6944403c 100644 --- a/kernel/driver/net/rtl81xx/src/rtl8168.rs +++ b/kernel/driver/net/rtl81xx/src/rtl8168.rs @@ -16,25 +16,25 @@ use libk::{ error::Error, task::runtime::{self, psleep, pwait}, }; -use libk_mm::{address::PhysicalAddress, device::DeviceMemoryIo, L3_PAGE_SIZE}; -use libk_util::{event::BitmapEvent, sync::IrqSafeSpinlock, OneTimeInit}; +use libk_mm::{L3_PAGE_SIZE, address::PhysicalAddress, device::DeviceMemoryIo}; +use libk_util::{OneTimeInit, event::BitmapEvent, sync::IrqSafeSpinlock}; use tock_registers::{ + LocalRegisterCopy, interfaces::{ReadWriteable, Readable, Writeable}, register_bitfields, register_structs, registers::{ReadOnly, ReadWrite, WriteOnly}, - LocalRegisterCopy, }; use ygg_driver_net_core::{ - ephy::{MdioBus, PhyAccess, GBESR}, - interface::{NetworkDevice, NetworkInterfaceType}, RxPacket, + ephy::{GBESR, MdioBus, PhyAccess}, + interface::{NetworkDevice, NetworkInterfaceType}, }; use ygg_driver_pci::device::{PciDeviceInfo, PreferredInterruptMode}; use yggdrasil_abi::{ bitflags, net::{ - link::{Duplex, EthernetLinkState, EthernetSpeed, LinkState}, MacAddress, + link::{Duplex, EthernetLinkState, EthernetSpeed, LinkState}, }, }; diff --git a/kernel/driver/net/stmmac/src/lib.rs b/kernel/driver/net/stmmac/src/lib.rs index 598315f8..5a5ea7b1 100644 --- a/kernel/driver/net/stmmac/src/lib.rs +++ b/kernel/driver/net/stmmac/src/lib.rs @@ -11,7 +11,7 @@ use device_api::{ interrupt::{InterruptHandler, IrqHandle, IrqVector}, }; use device_tree::driver::{ - device_tree_driver, util::read_mac_address, InitSequence, Node, ProbeContext, + InitSequence, Node, ProbeContext, device_tree_driver, util::read_mac_address, }; use futures_util::task::AtomicWaker; use libk::{ @@ -20,25 +20,25 @@ use libk::{ task::runtime::{self, psleep, pwait}, }; use libk_mm::{address::PhysicalAddress, device::DeviceMemoryIo}; -use libk_util::{event::BitmapEvent, sync::IrqSafeSpinlock, OneTimeInit}; +use libk_util::{OneTimeInit, event::BitmapEvent, sync::IrqSafeSpinlock}; use regs::{ - dma::{DMACiCR, DMACiIER, DMACiSR, DMACiTXCR, DMAC0RXCR, DMAMR, DMASBMR}, + Regs, + dma::{DMAC0RXCR, DMACiCR, DMACiIER, DMACiSR, DMACiTXCR, DMAMR, DMASBMR}, mac::{ MACAiHR, MACAiLR, MACCR, MACIER, MACISR, MACPFR, MACPHYCSR, MACQ0TXFCR, MACRXFCR, MACRXQC0R, }, - mtl::{MTLRXQiOMR, MTLTXQiOMR, MTLOMR}, - Regs, + mtl::{MTLOMR, MTLRXQiOMR, MTLTXQiOMR}, }; use ring::{RxDescriptor, RxRing, TxDescriptor, TxRing}; use tock_registers::interfaces::{ReadWriteable, Readable, Writeable}; use ygg_driver_net_core::{ - ephy::{PhyAccess, GBESR}, - interface::{NetworkDevice, NetworkInterfaceType}, RxPacket, + ephy::{GBESR, PhyAccess}, + interface::{NetworkDevice, NetworkInterfaceType}, }; use yggdrasil_abi::net::{ - link::{Duplex, EthernetLinkState, EthernetSpeed, LinkState}, MacAddress, + link::{Duplex, EthernetLinkState, EthernetSpeed, LinkState}, }; extern crate alloc; diff --git a/kernel/driver/usb/xhci/src/controller.rs b/kernel/driver/usb/xhci/src/controller.rs index e45d67f9..77114fc6 100644 --- a/kernel/driver/usb/xhci/src/controller.rs +++ b/kernel/driver/usb/xhci/src/controller.rs @@ -16,21 +16,21 @@ use libk::{ task::runtime, }; use libk_util::{ - sync::{spin_rwlock::IrqSafeRwLock, IrqSafeSpinlock}, OneTimeInit, + sync::{IrqSafeSpinlock, spin_rwlock::IrqSafeRwLock}, }; use tock_registers::{ - interfaces::{ReadWriteable, Readable, Writeable}, LocalRegisterCopy, + interfaces::{ReadWriteable, Readable, Writeable}, }; -use ygg_driver_pci::{device::PciDeviceInfo, PciConfigurationSpace}; +use ygg_driver_pci::{PciConfigurationSpace, device::PciDeviceInfo}; use ygg_driver_usb::{ + UsbHostController, bus::UsbBusManager, device::{UsbBusAddress, UsbDeviceAccess, UsbSpeed}, error::UsbError, info::UsbVersion, pipe::control::UsbControlPipeAccess, - UsbHostController, }; use yggdrasil_abi::bitflags; @@ -39,16 +39,15 @@ use crate::{ device::XhciBusDevice, pipe::ControlPipe, regs::{ - self, + self, PortNumber, Regs, extended::ExtendedCapability, - operational::{PortRegs, CONFIG, PORTSC, USBCMD, USBSTS}, - PortNumber, Regs, + operational::{CONFIG, PORTSC, PortRegs, USBCMD, USBSTS}, }, ring::{ + CommandExecutor, GenericRing, command::CommandRing, event::{Event, EventRing, EventRingSegmentTable}, transfer::TransferRing, - CommandExecutor, GenericRing, }, util::EventBitmap, }; diff --git a/kernel/driver/usb/xhci/src/device.rs b/kernel/driver/usb/xhci/src/device.rs index 7d635641..eed06133 100644 --- a/kernel/driver/usb/xhci/src/device.rs +++ b/kernel/driver/usb/xhci/src/device.rs @@ -1,11 +1,12 @@ use alloc::{boxed::Box, collections::btree_map::BTreeMap, sync::Arc}; use async_trait::async_trait; use libk_util::{ - sync::{spin_rwlock::IrqSafeRwLock, IrqSafeSpinlock}, OneTimeInit, + sync::{IrqSafeSpinlock, spin_rwlock::IrqSafeRwLock}, }; use xhci_lib::context; use ygg_driver_usb::{ + UsbHostController, communication::UsbDirection, device::{UsbBusAddress, UsbDevice, UsbDeviceDetachHandler, UsbSpeed}, error::UsbError, @@ -14,15 +15,14 @@ use ygg_driver_usb::{ control::UsbControlPipeAccess, normal::{UsbNormalPipeIn, UsbNormalPipeOut}, }, - UsbHostController, }; use crate::{ + Xhci, context::{XhciDeviceContext, XhciInputContext}, pipe::{NormalInPipe, NormalOutPipe}, regs::PortNumber, ring::transfer::TransferRing, - Xhci, }; pub struct XhciBusDevice { diff --git a/kernel/driver/usb/xhci/src/lib.rs b/kernel/driver/usb/xhci/src/lib.rs index 6bbb0c78..0615b543 100644 --- a/kernel/driver/usb/xhci/src/lib.rs +++ b/kernel/driver/usb/xhci/src/lib.rs @@ -1,6 +1,6 @@ #![no_std] #![allow(clippy::new_without_default)] -#![feature(iter_array_chunks, let_chains, maybe_uninit_slice)] +#![feature(iter_array_chunks)] extern crate alloc; @@ -9,10 +9,10 @@ use controller::Xhci; use device_api::{device::Device, dma::DmaAllocator, interrupt::InterruptAffinity}; use regs::Regs; use ygg_driver_pci::{ + PciCommandRegister, PciConfigurationSpace, capability::{DevicePowerState, PowerManagementCapability}, device::{PciDeviceInfo, PreferredInterruptMode}, macros::pci_driver, - PciCommandRegister, PciConfigurationSpace, }; use yggdrasil_abi::error::Error; diff --git a/kernel/driver/usb/xhci/src/pipe.rs b/kernel/driver/usb/xhci/src/pipe.rs index d5ae0041..8ad7ee97 100644 --- a/kernel/driver/usb/xhci/src/pipe.rs +++ b/kernel/driver/usb/xhci/src/pipe.rs @@ -6,9 +6,9 @@ use libk::dma::{DmaBuffer, DmaSlice, DmaSliceMut}; use ygg_driver_usb::{ error::{TransferError, UsbError}, pipe::{ + UsbGenericPipe, control::{ControlTransferSetup, UsbControlPipe}, normal::{UsbNormalPipeIn, UsbNormalPipeOut}, - UsbGenericPipe, }, }; diff --git a/kernel/driver/usb/xhci/src/regs/mod.rs b/kernel/driver/usb/xhci/src/regs/mod.rs index 2034b76c..867f9d54 100644 --- a/kernel/driver/usb/xhci/src/regs/mod.rs +++ b/kernel/driver/usb/xhci/src/regs/mod.rs @@ -6,11 +6,11 @@ use extended::ExtendedCapability; use libk::error::Error; use libk_mm::{address::PhysicalAddress, device::DeviceMemoryIo}; use libk_util::sync::spin_rwlock::IrqSafeRwLock; -use operational::{OperationalRegs, PortRegs, PORTSC, USBCMD, USBSTS}; -use runtime::{RuntimeRegs, IMAN}; +use operational::{OperationalRegs, PORTSC, PortRegs, USBCMD, USBSTS}; +use runtime::{IMAN, RuntimeRegs}; use tock_registers::{ - interfaces::{ReadWriteable, Readable, Writeable}, LocalRegisterCopy, + interfaces::{ReadWriteable, Readable, Writeable}, }; pub mod capability; diff --git a/kernel/driver/usb/xhci/src/ring/command.rs b/kernel/driver/usb/xhci/src/ring/command.rs index e70d8465..d7b302ae 100644 --- a/kernel/driver/usb/xhci/src/ring/command.rs +++ b/kernel/driver/usb/xhci/src/ring/command.rs @@ -1,7 +1,7 @@ use core::{ fmt, future::poll_fn, - mem::{size_of, MaybeUninit}, + mem::{MaybeUninit, size_of}, task::Poll, }; @@ -10,7 +10,7 @@ use bytemuck::{Pod, Zeroable}; use device_api::dma::DmaAllocator; use libk::dma::{BusAddress, DmaBuffer}; use libk_util::{ - sync::{spin_rwlock::IrqSafeRwLock, IrqSafeSpinlock}, + sync::{IrqSafeSpinlock, spin_rwlock::IrqSafeRwLock}, waker::QueueWaker, }; use ygg_driver_usb::error::UsbError; diff --git a/kernel/driver/usb/xhci/src/ring/event.rs b/kernel/driver/usb/xhci/src/ring/event.rs index b3d3fc51..07cb832d 100644 --- a/kernel/driver/usb/xhci/src/ring/event.rs +++ b/kernel/driver/usb/xhci/src/ring/event.rs @@ -1,4 +1,4 @@ -use core::mem::{size_of, MaybeUninit}; +use core::mem::{MaybeUninit, size_of}; use bytemuck::{Pod, Zeroable}; use device_api::dma::DmaAllocator; @@ -7,7 +7,7 @@ use libk_util::sync::IrqSafeSpinlock; use ygg_driver_usb::error::UsbError; use yggdrasil_abi::define_bitfields; -use super::{command::CommandReply, GenericRing}; +use super::{GenericRing, command::CommandReply}; pub enum Event { PortChange(usize), diff --git a/kernel/driver/usb/xhci/src/ring/transfer.rs b/kernel/driver/usb/xhci/src/ring/transfer.rs index 241dac59..98cd9f85 100644 --- a/kernel/driver/usb/xhci/src/ring/transfer.rs +++ b/kernel/driver/usb/xhci/src/ring/transfer.rs @@ -15,7 +15,7 @@ use futures_util::task::AtomicWaker; use libk::dma::{BusAddress, DmaBuffer}; use libk_util::{ queue::BoundedQueue, - sync::{spin_rwlock::IrqSafeRwLock, IrqSafeSpinlock, IrqSafeSpinlockGuard}, + sync::{IrqSafeSpinlock, IrqSafeSpinlockGuard, spin_rwlock::IrqSafeRwLock}, }; use ygg_driver_usb::{ communication::UsbDirection, diff --git a/kernel/driver/virtio/blk/src/lib.rs b/kernel/driver/virtio/blk/src/lib.rs index 7d9cb333..c662def6 100644 --- a/kernel/driver/virtio/blk/src/lib.rs +++ b/kernel/driver/virtio/blk/src/lib.rs @@ -18,17 +18,17 @@ use libk::{ task::runtime, }; use libk_mm::{ - address::PhysicalAddress, table::MapAttributes, OnDemandPage, PageProvider, VirtualPage, + OnDemandPage, PageProvider, VirtualPage, address::PhysicalAddress, table::MapAttributes, }; -use libk_util::sync::{spin_rwlock::IrqSafeRwLock, IrqSafeSpinlock}; +use libk_util::sync::{IrqSafeSpinlock, spin_rwlock::IrqSafeRwLock}; use ygg_driver_pci::{ device::{PciDeviceInfo, PreferredInterruptMode}, macros::pci_driver, }; use ygg_driver_virtio_core::{ - queue::VirtQueue, - transport::{pci::PciTransport, Transport}, DeviceStatus, + queue::VirtQueue, + transport::{Transport, pci::PciTransport}, }; use yggdrasil_abi::{bitflags, io::FileMode}; @@ -252,7 +252,7 @@ impl BlockDevice for VirtioBlk { position: u64, buffer: DmaSliceMut<'_, MaybeUninit>, ) -> Result<(), Error> { - if position % 512 != 0 || buffer.len() % 512 != 0 { + if !position.is_multiple_of(512) || !buffer.len().is_multiple_of(512) { return Err(Error::InvalidArgument); } let lba = position / 512; @@ -287,7 +287,7 @@ impl BlockDevice for VirtioBlk { return Err(Error::ReadOnly); } - if position % 512 != 0 || buffer.len() % 512 != 0 { + if !position.is_multiple_of(512) || !buffer.len().is_multiple_of(512) { return Err(Error::InvalidArgument); } let lba = position / 512; diff --git a/kernel/driver/virtio/core/src/transport/mod.rs b/kernel/driver/virtio/core/src/transport/mod.rs index 4d4029df..790275d0 100644 --- a/kernel/driver/virtio/core/src/transport/mod.rs +++ b/kernel/driver/virtio/core/src/transport/mod.rs @@ -8,8 +8,8 @@ use tock_registers::{ }; use crate::{ - queue::{VirtQueue, VqNotificationMechanism}, CommonConfiguration, DeviceStatus, + queue::{VirtQueue, VqNotificationMechanism}, }; #[cfg(any(feature = "pci", rust_analyzer))] diff --git a/kernel/driver/virtio/core/src/transport/pci.rs b/kernel/driver/virtio/core/src/transport/pci.rs index 4ffb9401..8a66c203 100644 --- a/kernel/driver/virtio/core/src/transport/pci.rs +++ b/kernel/driver/virtio/core/src/transport/pci.rs @@ -4,14 +4,14 @@ use tock_registers::{ registers::{ReadOnly, WriteOnly}, }; use ygg_driver_pci::{ + PciCommandRegister, PciConfigurationSpace, capability::{ VirtioCapabilityData, VirtioCommonConfigCapability, VirtioDeviceConfigCapability, VirtioInterruptStatusCapability, VirtioNotifyConfigCapability, }, - PciCommandRegister, PciConfigurationSpace, }; -use crate::{error::Error, CommonConfiguration}; +use crate::{CommonConfiguration, error::Error}; use super::Transport; diff --git a/kernel/driver/virtio/gpu/src/lib.rs b/kernel/driver/virtio/gpu/src/lib.rs index 928403b3..f6659a6c 100644 --- a/kernel/driver/virtio/gpu/src/lib.rs +++ b/kernel/driver/virtio/gpu/src/lib.rs @@ -1,4 +1,3 @@ -#![feature(maybe_uninit_slice)] #![no_std] extern crate alloc; @@ -21,19 +20,19 @@ use libk::{ dma::DmaBuffer, }; use libk_mm::{ + L3_PAGE_SIZE, OnDemandPage, PageProvider, VirtualPage, address::{AsPhysicalAddress, PhysicalAddress}, table::MapAttributes, - OnDemandPage, PageProvider, VirtualPage, L3_PAGE_SIZE, }; use libk_util::{ - sync::{spin_rwlock::IrqSafeRwLock, IrqSafeSpinlock}, OneTimeInit, + sync::{IrqSafeSpinlock, spin_rwlock::IrqSafeRwLock}, }; use ygg_driver_pci::{device::PciDeviceInfo, macros::pci_driver}; use ygg_driver_virtio_core::{ - queue::{VirtQueue, VqManualNotification}, - transport::{pci::PciTransport, Transport}, DeviceStatus, + queue::{VirtQueue, VqManualNotification}, + transport::{Transport, pci::PciTransport}, }; use yggdrasil_abi::error::Error; diff --git a/kernel/driver/virtio/net/src/lib.rs b/kernel/driver/virtio/net/src/lib.rs index 76fc294c..4b06a222 100644 --- a/kernel/driver/virtio/net/src/lib.rs +++ b/kernel/driver/virtio/net/src/lib.rs @@ -3,7 +3,7 @@ extern crate alloc; -use core::mem::{size_of, MaybeUninit}; +use core::mem::{MaybeUninit, size_of}; use alloc::{boxed::Box, sync::Arc}; use bytemuck::{Pod, Zeroable}; @@ -15,23 +15,23 @@ use device_api::{ use futures_util::task::AtomicWaker; use libk::{dma::DmaBuffer, task::runtime}; use libk_util::{ + OneTimeInit, event::BitmapEvent, hash_table::DefaultHashTable, - sync::{spin_rwlock::IrqSafeRwLock, IrqSafeSpinlock}, - OneTimeInit, + sync::{IrqSafeSpinlock, spin_rwlock::IrqSafeRwLock}, }; use ygg_driver_net_core::{ - interface::{NetworkDevice, NetworkInterfaceType}, RxPacket, + interface::{NetworkDevice, NetworkInterfaceType}, }; use ygg_driver_pci::{ device::{PciDeviceInfo, PreferredInterruptMode}, macros::pci_driver, }; use ygg_driver_virtio_core::{ - queue::{VirtQueue, VqCallbackNotification, VqManualNotification}, - transport::{pci::PciTransport, Transport}, DeviceStatus, + queue::{VirtQueue, VqCallbackNotification, VqManualNotification}, + transport::{Transport, pci::PciTransport}, }; use yggdrasil_abi::{error::Error, net::MacAddress}; diff --git a/kernel/lib/device-api/macros/src/lib.rs b/kernel/lib/device-api/macros/src/lib.rs index e69de29b..8b137891 100644 --- a/kernel/lib/device-api/macros/src/lib.rs +++ b/kernel/lib/device-api/macros/src/lib.rs @@ -0,0 +1 @@ + diff --git a/kernel/lib/device-tree/Cargo.toml b/kernel/lib/device-tree/Cargo.toml index b9f5c1fc..fd9078eb 100644 --- a/kernel/lib/device-tree/Cargo.toml +++ b/kernel/lib/device-tree/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "device-tree" version = "0.1.0" -edition = "2021" +edition = "2024" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/kernel/lib/device-tree/src/driver/controller.rs b/kernel/lib/device-tree/src/driver/controller.rs index 183db688..1b89156d 100644 --- a/kernel/lib/device-tree/src/driver/controller.rs +++ b/kernel/lib/device-tree/src/driver/controller.rs @@ -7,9 +7,9 @@ use device_api::{ }; use fdt_rs::spec::Phandle; -use crate::{driver::DeviceTreeGpioPins, DeviceTreePropertyRead, TProp}; +use crate::{DeviceTreePropertyRead, TProp, driver::DeviceTreeGpioPins}; -use super::{lookup_phandle, Node}; +use super::{Node, lookup_phandle}; pub(crate) struct ClockIter<'dt> { pub(crate) clocks: TProp<'dt>, diff --git a/kernel/lib/device-tree/src/driver/macros.rs b/kernel/lib/device-tree/src/driver/macros.rs index 9a0d0d78..49f4eaee 100644 --- a/kernel/lib/device-tree/src/driver/macros.rs +++ b/kernel/lib/device-tree/src/driver/macros.rs @@ -16,7 +16,7 @@ pub macro device_tree_driver( impl $crate::driver::Driver for __DtDriver $driver static __DT_DRIVER: __DtDriver = __DtDriver; - #[link_section = ".init_array"] + #[unsafe(link_section = ".init_array")] #[used] static __REGISTER_FN: extern "C" fn() = __register_fn; diff --git a/kernel/lib/device-tree/src/driver/mod.rs b/kernel/lib/device-tree/src/driver/mod.rs index 75a8e442..862aa545 100644 --- a/kernel/lib/device-tree/src/driver/mod.rs +++ b/kernel/lib/device-tree/src/driver/mod.rs @@ -21,7 +21,7 @@ pub use traits::{ DeviceTreeClockController, DeviceTreeInterruptController, DeviceTreePinController, DeviceTreeResetController, Driver, ProbeContext, }; -pub use tree::{find_node, unflatten_device_tree, walk_device_tree, Node}; +pub use tree::{Node, find_node, unflatten_device_tree, walk_device_tree}; /// Contextual information about a GPIO pin being configured pub struct DeviceTreeGpioPins { diff --git a/kernel/lib/device-tree/src/driver/registry.rs b/kernel/lib/device-tree/src/driver/registry.rs index df23ddb3..25efd0b2 100644 --- a/kernel/lib/device-tree/src/driver/registry.rs +++ b/kernel/lib/device-tree/src/driver/registry.rs @@ -1,7 +1,7 @@ //! Device tree driver registration use alloc::{sync::Arc, vec::Vec}; use fdt_rs::spec::Phandle; -use libk_util::{hash_table::DefaultHashTable, sync::spin_rwlock::IrqSafeRwLock, OneTimeInit}; +use libk_util::{OneTimeInit, hash_table::DefaultHashTable, sync::spin_rwlock::IrqSafeRwLock}; use crate::DeviceTree; diff --git a/kernel/lib/device-tree/src/driver/syscon.rs b/kernel/lib/device-tree/src/driver/syscon.rs index 2f8e5972..072a9b9d 100644 --- a/kernel/lib/device-tree/src/driver/syscon.rs +++ b/kernel/lib/device-tree/src/driver/syscon.rs @@ -5,7 +5,7 @@ use libk::error::Error; use libk_mm::{address::PhysicalAddress, device::DeviceMemoryIoMut}; use libk_util::sync::IrqSafeSpinlock; -use crate::driver::{device_tree_driver, Node, ProbeContext}; +use crate::driver::{Node, ProbeContext, device_tree_driver}; /// System controller/register map interface pub trait DeviceTreeSyscon: Device { @@ -29,7 +29,7 @@ unsafe impl Sync for SimpleSyscon {} impl SimpleSyscon { fn validate_address(&self, address: usize) -> Result<(), Error> { - if address + 4 > self.regs_len || address % 4 != 0 { + if address + 4 > self.regs_len || !address.is_multiple_of(4) { log::error!("{}: invalid register access {:#x}", self.name, address); Err(Error::InvalidArgument) } else { @@ -60,7 +60,8 @@ impl DeviceTreeSyscon for SimpleSyscon { let mut lock = self.regs.lock(); let ptr = &raw mut lock[address / 4]; - Ok(unsafe { ptr.write_volatile(val) }) + unsafe { ptr.write_volatile(val) }; + Ok(()) } fn modify_register(&self, address: usize, clear: u32, set: u32) -> Result<(), Error> { diff --git a/kernel/lib/device-tree/src/driver/traits.rs b/kernel/lib/device-tree/src/driver/traits.rs index 359430bf..609a046e 100644 --- a/kernel/lib/device-tree/src/driver/traits.rs +++ b/kernel/lib/device-tree/src/driver/traits.rs @@ -11,7 +11,7 @@ use device_api::{ }; use libk::error::Error; -use crate::{driver::DeviceTreeGpioPins, TProp}; +use crate::{TProp, driver::DeviceTreeGpioPins}; use super::{InitSequence, Node}; diff --git a/kernel/lib/device-tree/src/driver/tree.rs b/kernel/lib/device-tree/src/driver/tree.rs index 47f65fdf..55a78b65 100644 --- a/kernel/lib/device-tree/src/driver/tree.rs +++ b/kernel/lib/device-tree/src/driver/tree.rs @@ -19,18 +19,19 @@ use libk_util::OneTimeInit; use yggdrasil_abi::error::Error; use crate::{ + DeviceTree, DeviceTreeNodeExt, DeviceTreePropertyRead, TNode, TProp, driver::{ - controller::GpioIter, traits::DeviceTreePinController, DeviceTreeGpioPins, DeviceTreeSyscon, + DeviceTreeGpioPins, DeviceTreeSyscon, controller::GpioIter, traits::DeviceTreePinController, }, - tree, DeviceTree, DeviceTreeNodeExt, DeviceTreePropertyRead, TNode, TProp, + tree, }; use super::{ - controller::{ClockIter, ResetIter}, - lookup_phandle, map_interrupt, - registry::{register_phandle, DEVICE_TREE, DRIVERS, ROOT}, DeviceTreeClockController, DeviceTreeInterruptController, DeviceTreeResetController, Driver, InitSequence, ProbeContext, + controller::{ClockIter, ResetIter}, + lookup_phandle, map_interrupt, + registry::{DEVICE_TREE, DRIVERS, ROOT, register_phandle}, }; /// Represents a single node in the device tree, which may or may not: @@ -104,16 +105,14 @@ impl Node { .as_str_list() .find_map(|c| drivers.iter().find(|d| d.matches(c))); - if libk::config::get().device_tree.log_missing { - if driver.is_none() { - // FIXME don't spam virtio missing stuff - if !name.map_or(false, |n| n.starts_with("virtio_mmio")) { - for (i, compatible) in compatible.as_str_list().enumerate() { - if i == 0 { - log::warn!("No driver for {name:?} ({compatible:?})"); - } else { - log::warn!(" also {compatible:?}"); - } + if libk::config::get().device_tree.log_missing && driver.is_none() { + // FIXME don't spam virtio missing stuff + if !name.is_some_and(|n| n.starts_with("virtio_mmio")) { + for (i, compatible) in compatible.as_str_list().enumerate() { + if i == 0 { + log::warn!("No driver for {name:?} ({compatible:?})"); + } else { + log::warn!(" also {compatible:?}"); } } } diff --git a/kernel/lib/device-tree/src/driver/util.rs b/kernel/lib/device-tree/src/driver/util.rs index 2406215d..a142c278 100644 --- a/kernel/lib/device-tree/src/driver/util.rs +++ b/kernel/lib/device-tree/src/driver/util.rs @@ -9,8 +9,8 @@ use fdt_rs::prelude::PropReader; use yggdrasil_abi::net::MacAddress; use crate::{ - driver::{lookup_phandle, map_interrupt_at, DeviceTreeGpioPins}, DeviceTreePropertyRead, TProp, + driver::{DeviceTreeGpioPins, lookup_phandle, map_interrupt_at}, }; use super::Node; diff --git a/kernel/lib/device-tree/src/dt.rs b/kernel/lib/device-tree/src/dt.rs index bdaa1e26..a93db7dd 100644 --- a/kernel/lib/device-tree/src/dt.rs +++ b/kernel/lib/device-tree/src/dt.rs @@ -2,7 +2,7 @@ use fdt_rs::{ base::DevTree, - index::{iters::DevTreeIndexNodeSiblingIter, DevTreeIndex, DevTreeIndexNode, DevTreeIndexProp}, + index::{DevTreeIndex, DevTreeIndexNode, DevTreeIndexProp, iters::DevTreeIndexNodeSiblingIter}, prelude::PropReader, spec::Phandle, }; diff --git a/kernel/lib/device-tree/src/lib.rs b/kernel/lib/device-tree/src/lib.rs index 54ba9c92..c1d60c2d 100644 --- a/kernel/lib/device-tree/src/lib.rs +++ b/kernel/lib/device-tree/src/lib.rs @@ -10,7 +10,7 @@ //! * `pl011` - basic peripheral usage with `reg` and `interrupts` //! * `gic` in aarch64 - interrupt controller/mapper implementation #![cfg_attr(any(not(test), rust_analyzer), no_std)] -#![feature(trait_alias, let_chains, decl_macro)] +#![feature(trait_alias, decl_macro)] #![allow(clippy::type_complexity)] #![warn(missing_docs)] diff --git a/kernel/lib/device-tree/src/tree.rs b/kernel/lib/device-tree/src/tree.rs index 0a07784d..29c460e5 100644 --- a/kernel/lib/device-tree/src/tree.rs +++ b/kernel/lib/device-tree/src/tree.rs @@ -50,7 +50,7 @@ impl<'a> DeviceTree<'a> { /// /// Accepts a raw address, unsafe. pub unsafe fn from_raw_with_index(address: usize, index: &'a mut [u8]) -> Result { - let tree = DevTree::from_raw_pointer(ptr::with_exposed_provenance(address)) + let tree = unsafe { DevTree::from_raw_pointer(ptr::with_exposed_provenance(address)) } .map_err(|_| Error::InvalidArgument)?; let index = DevTreeIndex::new(tree, index).map_err(|_| Error::InvalidArgument)?; Ok(Self { tree, index }) @@ -64,7 +64,9 @@ impl<'a> DeviceTree<'a> { pub unsafe fn from_raw(address: usize) -> Result { static mut BUFFER: FdtIndexBuffer = FdtIndexBuffer([0; FDT_INDEX_BUFFER_SIZE]); #[allow(static_mut_refs)] - Self::from_raw_with_index(address, &mut BUFFER.0[..]) + unsafe { + Self::from_raw_with_index(address, &mut BUFFER.0[..]) + } } /// Returns the total size in bytes of the underlying FDT blob @@ -190,7 +192,7 @@ impl<'a> DeviceTree<'a> { /// * `header` is at least u32-aligned; /// * `header` points to a slice of at least [DevTree::MIN_HEADER_SIZE] bytes. pub unsafe fn read_totalsize(header: &[u8]) -> Result { - DevTree::read_totalsize(header).map_err(|_| Error::InvalidArgument) + unsafe { DevTree::read_totalsize(header) }.map_err(|_| Error::InvalidArgument) } } diff --git a/kernel/lib/vmalloc/src/allocator.rs b/kernel/lib/vmalloc/src/allocator.rs index 43398b25..12a7c84e 100644 --- a/kernel/lib/vmalloc/src/allocator.rs +++ b/kernel/lib/vmalloc/src/allocator.rs @@ -1,6 +1,6 @@ use core::cmp::Ordering; -use alloc::collections::{linked_list::CursorMut, LinkedList}; +use alloc::collections::{LinkedList, linked_list::CursorMut}; use yggdrasil_abi::error::Error; use crate::VirtualMemoryRange; diff --git a/kernel/lib/vmalloc/src/lib.rs b/kernel/lib/vmalloc/src/lib.rs index e17217cb..a1cbcbd2 100644 --- a/kernel/lib/vmalloc/src/lib.rs +++ b/kernel/lib/vmalloc/src/lib.rs @@ -6,7 +6,7 @@ #![deny(missing_docs)] #![no_std] -#![feature(linked_list_cursors, let_chains, btree_extract_if)] +#![feature(linked_list_cursors)] extern crate alloc; diff --git a/kernel/libk/Cargo.toml b/kernel/libk/Cargo.toml index 0cf973d9..ee28fa1a 100644 --- a/kernel/libk/Cargo.toml +++ b/kernel/libk/Cargo.toml @@ -3,7 +3,7 @@ cargo-features = ["profile-rustflags"] [package] name = "libk" version = "0.1.0" -edition = "2021" +edition = "2024" authors = ["Mark Poliakov "] [lib] diff --git a/kernel/libk/libk-mm/interface/src/address.rs b/kernel/libk/libk-mm/interface/src/address.rs index 9b11d123..af9a31d8 100644 --- a/kernel/libk/libk-mm/interface/src/address.rs +++ b/kernel/libk/libk-mm/interface/src/address.rs @@ -76,7 +76,7 @@ impl PhysicalAddress { /// Returns `true` if the address is aligned to a boundary of a page at level `L` #[inline] pub const fn is_aligned_for(self) -> bool { - self.0 as usize % align_of::() == 0 + (self.0 as usize).is_multiple_of(align_of::()) } /// Converts a previously virtualized physical address back into its physical form. diff --git a/kernel/libk/libk-mm/src/address.rs b/kernel/libk/libk-mm/src/address.rs index d4706b8b..1f3d7e32 100644 --- a/kernel/libk/libk-mm/src/address.rs +++ b/kernel/libk/libk-mm/src/address.rs @@ -1,4 +1,4 @@ -use kernel_arch::{mem::KernelTableManager, KernelTableManagerImpl}; +use kernel_arch::{KernelTableManagerImpl, mem::KernelTableManager}; pub use libk_mm_interface::address::{AsPhysicalAddress, PhysicalAddress}; pub trait Virtualize { diff --git a/kernel/libk/libk-mm/src/heap.rs b/kernel/libk/libk-mm/src/heap.rs index e9113b8e..a0ade8b4 100644 --- a/kernel/libk/libk-mm/src/heap.rs +++ b/kernel/libk/libk-mm/src/heap.rs @@ -9,7 +9,7 @@ use libk_mm_interface::address::PhysicalAddress; use libk_util::sync::IrqSafeSpinlock; use libyalloc::{allocator::BucketAllocator, sys::PageProvider}; -use crate::{address::Virtualize, phys, L3_PAGE_SIZE}; +use crate::{L3_PAGE_SIZE, address::Virtualize, phys}; // TODO limits? diff --git a/kernel/libk/libk-mm/src/lib.rs b/kernel/libk/libk-mm/src/lib.rs index 69db9c7f..155a53f6 100644 --- a/kernel/libk/libk-mm/src/lib.rs +++ b/kernel/libk/libk-mm/src/lib.rs @@ -1,10 +1,8 @@ #![feature( - maybe_uninit_slice, slice_ptr_get, step_trait, const_trait_impl, maybe_uninit_as_bytes, - maybe_uninit_write_slice, negative_impls )] #![no_std] @@ -15,13 +13,13 @@ use core::{ alloc::Layout, fmt, marker::PhantomData, - mem::{size_of, MaybeUninit}, + mem::{MaybeUninit, size_of}, ops::{Deref, DerefMut}, slice::SliceIndex, }; use address::Virtualize; -use kernel_arch::{mem::PhysicalMemoryAllocator, Architecture, ArchitectureImpl}; +use kernel_arch::{Architecture, ArchitectureImpl, mem::PhysicalMemoryAllocator}; use libk_mm_interface::{ address::{AsPhysicalAddress, PhysicalAddress}, table::{MapAttributes, TableAllocator}, @@ -38,7 +36,7 @@ pub mod process; #[cfg(any(target_os = "none", rust_analyzer))] pub mod heap; -pub use libk_mm_interface::{table, PageFaultKind}; +pub use libk_mm_interface::{PageFaultKind, table}; pub struct TableAllocatorImpl; diff --git a/kernel/libk/libk-mm/src/phys/mod.rs b/kernel/libk/libk-mm/src/phys/mod.rs index cfaf7c29..186ba5ed 100644 --- a/kernel/libk/libk-mm/src/phys/mod.rs +++ b/kernel/libk/libk-mm/src/phys/mod.rs @@ -1,16 +1,16 @@ use core::ops::Range; -use kernel_arch::{mem::PhysicalMemoryAllocator, Architecture, ArchitectureImpl}; +use kernel_arch::{Architecture, ArchitectureImpl, mem::PhysicalMemoryAllocator}; use libk_mm_interface::address::PhysicalAddress; -use libk_util::{sync::IrqSafeSpinlock, OneTimeInit}; +use libk_util::{OneTimeInit, sync::IrqSafeSpinlock}; use yggdrasil_abi::{error::Error, system::SystemMemoryStats}; use crate::{ + L2_PAGE_SIZE, L3_PAGE_SIZE, phys::{ manager::BITMAP_WORD_SIZE, reserved::{is_reserved, reserve_region}, }, - L2_PAGE_SIZE, L3_PAGE_SIZE, }; use self::manager::{PhysicalMemoryManager, TRACKED_PAGE_LIMIT}; diff --git a/kernel/libk/libk-mm/src/phys/reserved.rs b/kernel/libk/libk-mm/src/phys/reserved.rs index 3fc746bd..642dc6bc 100644 --- a/kernel/libk/libk-mm/src/phys/reserved.rs +++ b/kernel/libk/libk-mm/src/phys/reserved.rs @@ -1,7 +1,7 @@ //! Utilities for handling reserved memory regions use libk_mm_interface::address::PhysicalAddress; -use libk_util::{sync::IrqSafeSpinlock, StaticVector}; +use libk_util::{StaticVector, sync::IrqSafeSpinlock}; use crate::phys::PhysicalMemoryRegion; diff --git a/kernel/libk/libk-mm/src/process.rs b/kernel/libk/libk-mm/src/process.rs index dafa3dc1..34a19157 100644 --- a/kernel/libk/libk-mm/src/process.rs +++ b/kernel/libk/libk-mm/src/process.rs @@ -3,19 +3,18 @@ use core::ops::{Deref, Range}; use alloc::sync::Arc; use kernel_arch::ProcessAddressSpaceImpl; use libk_mm_interface::{ + PageFaultKind, address::PhysicalAddress, process::{PageAttributeUpdate, ProcessAddressSpaceManager}, table::{MapAttributes, TableAllocator}, - PageFaultKind, }; use libk_util::sync::{IrqSafeSpinlock, IrqSafeSpinlockGuard}; use vmalloc::{RangeData, VirtualMemoryAllocator}; use yggdrasil_abi::error::Error; use crate::{ - phys, + L3_PAGE_SIZE, OnDemandPage, PageProvider, TableAllocatorImpl, VirtualPage, phys, pointer::{PhysicalRef, PhysicalRefMut}, - OnDemandPage, PageProvider, TableAllocatorImpl, VirtualPage, L3_PAGE_SIZE, }; /// Describes how the physical memory is provided for the mapping diff --git a/kernel/libk/libk-util/Cargo.toml b/kernel/libk/libk-util/Cargo.toml index 053d056d..fbbac8d8 100644 --- a/kernel/libk/libk-util/Cargo.toml +++ b/kernel/libk/libk-util/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "libk-util" version = "0.1.0" -edition = "2021" +edition = "2024" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/kernel/libk/libk-util/src/hash_table.rs b/kernel/libk/libk-util/src/hash_table.rs index 6857d68b..eb511bef 100644 --- a/kernel/libk/libk-util/src/hash_table.rs +++ b/kernel/libk/libk-util/src/hash_table.rs @@ -96,6 +96,6 @@ impl HashTable { let h = self.hasher.hash_one(key); let bucket = &self.buckets[h as usize % self.buckets.len()]; - bucket.iter().any(|(k, _)| (k.borrow() == key)) + bucket.iter().any(|(k, _)| k.borrow() == key) } } diff --git a/kernel/libk/libk-util/src/lib.rs b/kernel/libk/libk-util/src/lib.rs index 2c9e8c8b..bbcbd866 100644 --- a/kernel/libk/libk-util/src/lib.rs +++ b/kernel/libk/libk-util/src/lib.rs @@ -2,9 +2,7 @@ #![feature( linked_list_cursors, async_fn_traits, - maybe_uninit_slice, allocator_api, - let_chains, const_trait_impl, str_from_utf16_endian )] diff --git a/kernel/libk/libk-util/src/ring.rs b/kernel/libk/libk-util/src/ring.rs index 6927b23f..247d63be 100644 --- a/kernel/libk/libk-util/src/ring.rs +++ b/kernel/libk/libk-util/src/ring.rs @@ -122,7 +122,7 @@ impl RingBuffer { #[inline] pub unsafe fn read_single_unchecked(&mut self) -> T { let data = self.data.as_ref().unwrap(); - let res = data[self.rd].assume_init_read(); + let res = unsafe { data[self.rd].assume_init_read() }; self.rd = (self.rd + 1) % self.capacity; res } @@ -140,7 +140,7 @@ impl RingBuffer { let mut pos = (self.rd + pos) % self.capacity; let mut off = 0; while off < buffer.len() && self.is_readable_at(pos) { - buffer[off] = data[pos].assume_init(); + buffer[off] = unsafe { data[pos].assume_init() }; pos += 1; off += 1; } diff --git a/kernel/libk/libk-util/src/string.rs b/kernel/libk/libk-util/src/string.rs index 65a2b2cb..9386b6e8 100644 --- a/kernel/libk/libk-util/src/string.rs +++ b/kernel/libk/libk-util/src/string.rs @@ -28,7 +28,7 @@ impl Utf16LeStr { /// /// Does not validate the validity of the UTF-16 sequence. pub unsafe fn from_utf16le_unchecked(raw: &[u8]) -> &Self { - core::mem::transmute(raw) + unsafe { core::mem::transmute(raw) } } pub fn chars(&self) -> Utf16LeIter<'_> { @@ -38,7 +38,7 @@ impl Utf16LeStr { } fn validate(raw: &[u8]) -> Result<(), Utf16Error> { - if raw.len() % 2 != 0 { + if !raw.len().is_multiple_of(2) { return Err(Utf16Error::InvalidLength); } diff --git a/kernel/libk/libk-util/src/sync/spin_rwlock.rs b/kernel/libk/libk-util/src/sync/spin_rwlock.rs index e21b246d..b2dc9136 100644 --- a/kernel/libk/libk-util/src/sync/spin_rwlock.rs +++ b/kernel/libk/libk-util/src/sync/spin_rwlock.rs @@ -160,11 +160,11 @@ impl IrqSafeRwLock { } unsafe fn release_read(&self) { - self.inner.release_read(); + unsafe { self.inner.release_read() }; } unsafe fn release_write(&self) { - self.inner.release_write(); + unsafe { self.inner.release_write() }; } } diff --git a/kernel/libk/libk-util/src/waker.rs b/kernel/libk/libk-util/src/waker.rs index 3345f682..36bf2f48 100644 --- a/kernel/libk/libk-util/src/waker.rs +++ b/kernel/libk/libk-util/src/waker.rs @@ -26,14 +26,14 @@ impl WakeWeak { ); unsafe fn drop_waker(ptr: *const ()) { - let weak = Weak::from_raw(ptr as *const T); + let weak = unsafe { Weak::from_raw(ptr as *const T) }; // Explicitly drop the thing drop(weak); } unsafe fn wake(ptr: *const ()) { - let weak = Weak::from_raw(ptr as *const T); + let weak = unsafe { Weak::from_raw(ptr as *const T) }; if let Some(strong) = weak.upgrade() { strong.wake(); @@ -43,7 +43,7 @@ impl WakeWeak { } unsafe fn wake_by_ref(ptr: *const ()) { - let weak = Weak::from_raw(ptr as *const T); + let weak = unsafe { Weak::from_raw(ptr as *const T) }; if let Some(strong) = weak.upgrade() { strong.wake(); @@ -54,7 +54,7 @@ impl WakeWeak { } unsafe fn clone_waker(ptr: *const ()) -> RawWaker { - let weak = Weak::from_raw(ptr as *const T); + let weak = unsafe { Weak::from_raw(ptr as *const T) }; let waker = Self::weak_waker(weak.clone()); diff --git a/kernel/libk/src/arch.rs b/kernel/libk/src/arch.rs index b37a996c..ed5819e8 100644 --- a/kernel/libk/src/arch.rs +++ b/kernel/libk/src/arch.rs @@ -21,7 +21,7 @@ impl Cpu { id: Option, data: ::PerCpuData, ) { - ArchitectureImpl::init_local_cpu::(id, data) + unsafe { ArchitectureImpl::init_local_cpu::(id, data) } } /// Returns local CPU reference diff --git a/kernel/libk/src/config/general.rs b/kernel/libk/src/config/general.rs index 2c0188c8..bf166741 100644 --- a/kernel/libk/src/config/general.rs +++ b/kernel/libk/src/config/general.rs @@ -17,6 +17,7 @@ pub struct DebugOptions { /// Device-tree related options #[derive(Debug)] +#[allow(dead_code)] pub struct DeviceTreeOptions { /// If set, logs missing drivers for device tree nodes pub log_missing: bool, diff --git a/kernel/libk/src/debug/mod.rs b/kernel/libk/src/debug/mod.rs index 8ee5ccc9..ddd7b692 100644 --- a/kernel/libk/src/debug/mod.rs +++ b/kernel/libk/src/debug/mod.rs @@ -28,9 +28,9 @@ mod panic; mod ring; mod sink; -pub use panic::{panic_log, PanicLoggerSink}; +pub use panic::{PanicLoggerSink, panic_log}; pub use ring::add_kernel_log_file; -pub use sink::{add_early_sink, add_serial_sink, add_sink, disable_early_sinks, DebugSink}; +pub use sink::{DebugSink, add_early_sink, add_serial_sink, add_sink, disable_early_sinks}; static DEBUG_LOCK: AtomicU32 = AtomicU32::new(u32::MAX); static MUTE_DEBUG: AtomicBool = AtomicBool::new(false); diff --git a/kernel/libk/src/debug/panic.rs b/kernel/libk/src/debug/panic.rs index 4e0ef2c3..adb1de61 100644 --- a/kernel/libk/src/debug/panic.rs +++ b/kernel/libk/src/debug/panic.rs @@ -1,8 +1,8 @@ use core::fmt::Arguments; -use libk_util::{sync::spin_rwlock::IrqSafeRwLockReadGuard, StaticVector}; +use libk_util::{StaticVector, sync::spin_rwlock::IrqSafeRwLockReadGuard}; -use super::sink::{DebugSinkWrapper, DEBUG_SINKS, MAX_DEBUG_SINKS}; +use super::sink::{DEBUG_SINKS, DebugSinkWrapper, MAX_DEBUG_SINKS}; /// Locking log sink for dumping panic info pub struct PanicLoggerSink<'a> { diff --git a/kernel/libk/src/debug/sink.rs b/kernel/libk/src/debug/sink.rs index 383e22e0..8a154266 100644 --- a/kernel/libk/src/debug/sink.rs +++ b/kernel/libk/src/debug/sink.rs @@ -4,12 +4,12 @@ use core::{ }; use alloc::{format, sync::Arc}; -use libk_util::{sync::spin_rwlock::IrqSafeRwLock, StaticVector}; +use libk_util::{StaticVector, sync::spin_rwlock::IrqSafeRwLock}; use yggdrasil_abi::error::Error; use crate::{arch::Cpu, config, fs::sysfs, time::monotonic_time}; -use super::{make_sysfs_sink_object, LogLevel}; +use super::{LogLevel, make_sysfs_sink_object}; /// Generic interface for debug output pub trait DebugSink: Sync { diff --git a/kernel/libk/src/device/block/cache.rs b/kernel/libk/src/device/block/cache.rs index d038bfec..00a203cc 100644 --- a/kernel/libk/src/device/block/cache.rs +++ b/kernel/libk/src/device/block/cache.rs @@ -56,7 +56,7 @@ impl DeviceMapper { block_size: usize, filesystem: &str, ) -> Result { - if block_size % device.block_size() != 0 { + if !block_size.is_multiple_of(device.block_size()) { log::error!( "Couldn't create block mapper for {filesystem}: \ cache block size is not a multiple of device block size" @@ -118,7 +118,7 @@ impl UncachedCache { pos: u64, mapper: F, ) -> Result { - if pos % self.block_size as u64 != 0 { + if !pos.is_multiple_of(self.block_size as u64) { log::warn!( "uncached: position {pos} is not a multiple of block size {}", self.block_size @@ -139,7 +139,7 @@ impl UncachedCache { size: usize, mapper: F, ) -> Result { - if pos % self.block_size as u64 != 0 { + if !pos.is_multiple_of(self.block_size as u64) { log::warn!( "uncached: position {pos} is not a multiple of block size {}", self.block_size @@ -171,14 +171,14 @@ impl BlockCache { bucket_count: usize, filesystem: &str, ) -> Result { - if block_size % device.block_size() != 0 { + if block_size.is_multiple_of(device.block_size()) { log::error!( "Couldn't create block cache for {filesystem}: \ cache block size is not a multiple of device block size" ); return Err(Error::InvalidArgument); } - if segment_size % block_size != 0 { + if !segment_size.is_multiple_of(block_size) { log::error!( "Couldn't create block cache for {filesystem}: \ segment size is not a multiple of block size" @@ -193,7 +193,9 @@ impl BlockCache { return Err(Error::InvalidArgument); } - log::info!("New block cache: block: {block_size}B, segment: {segment_size}B, geometry: {bucket_capacity}x{bucket_count}"); + log::info!( + "New block cache: block: {block_size}B, segment: {segment_size}B, geometry: {bucket_capacity}x{bucket_count}" + ); log::info!( "Worst-case memory usage: {}K", (segment_size * bucket_capacity * bucket_count) / 1024 @@ -262,7 +264,7 @@ impl BlockCache { block_position: u64, mapper: F, ) -> Result { - if block_position % self.block_size as u64 != 0 { + if !block_position.is_multiple_of(self.block_size as u64) { log::warn!( "mapper: position {block_position} is not a multiple of block size {}", self.block_size @@ -282,7 +284,7 @@ impl BlockCache { _size: usize, mapper: F, ) -> Result { - if block_position % self.block_size as u64 != 0 { + if !block_position.is_multiple_of(self.block_size as u64) { log::warn!( "mapper: position {block_position} is not a multiple of block size {}", self.block_size diff --git a/kernel/libk/src/device/block/partition/mod.rs b/kernel/libk/src/device/block/partition/mod.rs index 490a1f11..50c24053 100644 --- a/kernel/libk/src/device/block/partition/mod.rs +++ b/kernel/libk/src/device/block/partition/mod.rs @@ -4,7 +4,7 @@ use alloc::{boxed::Box, sync::Arc}; use async_trait::async_trait; use device_api::device::Device; use libk_mm::{ - address::PhysicalAddress, table::MapAttributes, OnDemandPage, PageProvider, VirtualPage, + OnDemandPage, PageProvider, VirtualPage, address::PhysicalAddress, table::MapAttributes, }; use yggdrasil_abi::error::Error; diff --git a/kernel/libk/src/device/display/console.rs b/kernel/libk/src/device/display/console.rs index d8b48078..6fd97d58 100644 --- a/kernel/libk/src/device/display/console.rs +++ b/kernel/libk/src/device/display/console.rs @@ -5,8 +5,8 @@ use core::time::Duration; use alloc::{sync::Arc, vec, vec::Vec}; use bitflags::bitflags; use libk_util::{ - sync::{spin_rwlock::IrqSafeRwLock, IrqSafeSpinlock}, StaticVector, + sync::{IrqSafeSpinlock, spin_rwlock::IrqSafeRwLock}, }; use yggdrasil_abi::{error::Error, io::TerminalSize, primitive_enum}; @@ -66,11 +66,7 @@ impl ColorAttribute { let color = TABLE[*self as usize]; - if bold { - color.rgb_mul(2) - } else { - color - } + if bold { color.rgb_mul(2) } else { color } } } diff --git a/kernel/libk/src/device/display/fb_console.rs b/kernel/libk/src/device/display/fb_console.rs index 00c0ceb2..71c7688b 100644 --- a/kernel/libk/src/device/display/fb_console.rs +++ b/kernel/libk/src/device/display/fb_console.rs @@ -7,10 +7,10 @@ use yggdrasil_abi::error::Error; use crate::debug::DebugSink; use super::{ + Color, DisplayDevice, access::KernelFramebufferAccess, console::{self, Attributes, ConsoleBuffer, ConsoleState, DisplayConsole}, font::PcScreenFont, - Color, DisplayDevice, }; struct Inner { diff --git a/kernel/libk/src/device/display/mod.rs b/kernel/libk/src/device/display/mod.rs index 968e78de..870d748b 100644 --- a/kernel/libk/src/device/display/mod.rs +++ b/kernel/libk/src/device/display/mod.rs @@ -4,8 +4,8 @@ use alloc::{boxed::Box, sync::Arc}; use async_trait::async_trait; use device_api::device::Device; use libk_mm::{ - address::PhysicalAddress, table::MapAttributes, OnDemandPage, PageProvider, VirtualPage, - L3_PAGE_SIZE, + L3_PAGE_SIZE, OnDemandPage, PageProvider, VirtualPage, address::PhysicalAddress, + table::MapAttributes, }; use yggdrasil_abi::{ bitflags, diff --git a/kernel/libk/src/device/manager.rs b/kernel/libk/src/device/manager.rs index ad4800e1..0db9f705 100644 --- a/kernel/libk/src/device/manager.rs +++ b/kernel/libk/src/device/manager.rs @@ -4,7 +4,7 @@ use core::{ }; use alloc::{collections::BTreeMap, format, sync::Arc, vec::Vec}; -use libk_util::{sync::spin_rwlock::IrqSafeRwLock, OneTimeInit}; +use libk_util::{OneTimeInit, sync::spin_rwlock::IrqSafeRwLock}; use yggdrasil_abi::{error::Error, io::FileMode}; use crate::{ @@ -16,8 +16,8 @@ use crate::{ use super::{ block::{ - partition::{self, Partition}, BlockDevice, + partition::{self, Partition}, }, char::CharDevice, display::{DisplayDevice, DisplayWrapper}, diff --git a/kernel/libk/src/device/mod.rs b/kernel/libk/src/device/mod.rs index 8de93003..10edeb37 100644 --- a/kernel/libk/src/device/mod.rs +++ b/kernel/libk/src/device/mod.rs @@ -18,7 +18,7 @@ pub fn register_external_interrupt_controller(intc: Arc Result<&'static Arc, Error> { +pub fn external_interrupt_controller() +-> Result<&'static Arc, Error> { EXTERNAL_INTC.try_get().ok_or(Error::DoesNotExist) } diff --git a/kernel/libk/src/dma.rs b/kernel/libk/src/dma.rs index 45857321..51ea6fcf 100644 --- a/kernel/libk/src/dma.rs +++ b/kernel/libk/src/dma.rs @@ -9,8 +9,9 @@ use core::{ use bytemuck::{Pod, Zeroable}; use device_api::dma::{DmaAllocation, DmaAllocator}; use libk_mm::{ + L3_PAGE_SIZE, address::{AsPhysicalAddress, PhysicalAddress, Virtualize}, - phys, L3_PAGE_SIZE, + phys, }; use yggdrasil_abi::error::Error; diff --git a/kernel/libk/src/fs/devfs.rs b/kernel/libk/src/fs/devfs.rs index eb70fc90..59f2a35f 100644 --- a/kernel/libk/src/fs/devfs.rs +++ b/kernel/libk/src/fs/devfs.rs @@ -7,9 +7,9 @@ use yggdrasil_abi::{error::Error, io::FileMode}; use crate::{ device::{block::BlockDevice, char::CharDevice}, vfs::{ - impls::{fixed_path_symlink, MemoryDirectory}, - path::OwnedFilename, AccessToken, Filename, Metadata, Node, NodeFlags, NodeRef, + impls::{MemoryDirectory, fixed_path_symlink}, + path::OwnedFilename, }, }; diff --git a/kernel/libk/src/fs/sysfs/object.rs b/kernel/libk/src/fs/sysfs/object.rs index c618b108..067740f5 100644 --- a/kernel/libk/src/fs/sysfs/object.rs +++ b/kernel/libk/src/fs/sysfs/object.rs @@ -4,7 +4,7 @@ use alloc::sync::Arc; use libk_util::OneTimeInit; use yggdrasil_abi::{error::Error, io::FileMode}; -use crate::vfs::{impls::MemoryDirectory, path::OwnedFilename, Metadata, Node, NodeFlags, NodeRef}; +use crate::vfs::{Metadata, Node, NodeFlags, NodeRef, impls::MemoryDirectory, path::OwnedFilename}; use super::attribute::Attribute; diff --git a/kernel/libk/src/lib.rs b/kernel/libk/src/lib.rs index 06543138..a29709d0 100644 --- a/kernel/libk/src/lib.rs +++ b/kernel/libk/src/lib.rs @@ -5,13 +5,10 @@ async_fn_traits, new_range_api, associated_type_defaults, - maybe_uninit_slice, - maybe_uninit_write_slice, step_trait, const_trait_impl, slice_ptr_get, never_type, - let_chains, allocator_api, trait_alias, if_let_guard, diff --git a/kernel/libk/src/module.rs b/kernel/libk/src/module.rs index c5501a2f..fa7b41cb 100644 --- a/kernel/libk/src/module.rs +++ b/kernel/libk/src/module.rs @@ -8,7 +8,7 @@ use elf::{ symbol::Symbol as ElfSymbol, }; use libk_mm::PageBox; -use libk_util::{hash_table::DefaultHashTable, io::Read, sync::LockMethod, OneTimeInit}; +use libk_util::{OneTimeInit, hash_table::DefaultHashTable, io::Read, sync::LockMethod}; use yggdrasil_abi::{ error::Error, io::{FileMode, OpenOptions}, @@ -134,7 +134,10 @@ pub fn load(file: FileRef) -> Result { if sym.st_shndx == elf::abi::SHN_UNDEF && sym.st_bind() != elf::abi::STB_LOCAL { let Some(value) = lookup_symbol(name) else { - log::warn!("Could not load module: undefined reference to {:?} (possibly compiled against a different libk?)", name); + log::warn!( + "Could not load module: undefined reference to {:?} (possibly compiled against a different libk?)", + name + ); return Err(Error::InvalidArgument); }; sym.st_value = value as u64; @@ -191,8 +194,8 @@ pub fn load(file: FileRef) -> Result { // } let info = info_struct_addr - .map(|addr| unsafe { core::mem::transmute(addr) }) - .expect("TODO return error if module is missing MODULE info struct"); + .map(|addr| unsafe { &*core::ptr::with_exposed_provenance(addr) }) + .expect("TODO: return error if module is missing MODULE info struct"); Ok(LoadedModule { image_data, info }) } diff --git a/kernel/libk/src/random.rs b/kernel/libk/src/random.rs index 6bc079bd..6596e49a 100644 --- a/kernel/libk/src/random.rs +++ b/kernel/libk/src/random.rs @@ -1,6 +1,6 @@ //! Random generation utilities -use libk_util::{sync::IrqSafeSpinlock, OneTimeInit}; +use libk_util::{OneTimeInit, sync::IrqSafeSpinlock}; use crate::time::monotonic_time; diff --git a/kernel/libk/src/task/binary/elf.rs b/kernel/libk/src/task/binary/elf.rs index ea94f6c3..9d6301cb 100644 --- a/kernel/libk/src/task/binary/elf.rs +++ b/kernel/libk/src/task/binary/elf.rs @@ -4,16 +4,16 @@ use core::ops::DerefMut; use alloc::sync::Arc; use cfg_if::cfg_if; use elf::{ + ElfStream, ParseError, endian::AnyEndian, relocation::{Rel, Rela}, segment::ProgramHeader, - ElfStream, ParseError, }; use libk_mm::{ + L3_PAGE_SIZE, pointer::PhysicalRefMut, process::{ProcessAddressSpace, VirtualRangeBacking}, table::MapAttributes, - L3_PAGE_SIZE, }; use libk_util::io::{Read, Seek}; use yggdrasil_abi::{error::Error, io::SeekFrom, path::PathBuf}; @@ -155,7 +155,11 @@ pub fn open_elf_direct( let elf = ElfStream::::open_stream(file.clone()).map_err(from_parse_error)?; if elf.ehdr.e_machine != EXPECTED_ELF_MACHINE { - log::warn!("e_machine in ELF ({:#x}) does not match expected value for current architecture ({:#x})", elf.ehdr.e_machine, EXPECTED_ELF_MACHINE); + log::warn!( + "e_machine in ELF ({:#x}) does not match expected value for current architecture ({:#x})", + elf.ehdr.e_machine, + EXPECTED_ELF_MACHINE + ); return Err(Error::UnrecognizedExecutable); } diff --git a/kernel/libk/src/task/binary/mod.rs b/kernel/libk/src/task/binary/mod.rs index d4bd5803..ae2ea610 100644 --- a/kernel/libk/src/task/binary/mod.rs +++ b/kernel/libk/src/task/binary/mod.rs @@ -11,15 +11,15 @@ use yggdrasil_abi::{ error::Error, io::SeekFrom, path::Path, - process::{auxv, AuxValue, ProcessGroupId}, + process::{AuxValue, ProcessGroupId, auxv}, }; use crate::{ task::{ + TaskContextImpl, mem::ForeignPointer, process::{Process, ProcessCreateInfo, ProcessImage}, thread::Thread, - TaskContextImpl, }, vfs::IoContext, }; diff --git a/kernel/libk/src/task/mem.rs b/kernel/libk/src/task/mem.rs index 9252d2ba..da230d2d 100644 --- a/kernel/libk/src/task/mem.rs +++ b/kernel/libk/src/task/mem.rs @@ -111,7 +111,7 @@ pub trait ForeignAtomic { impl ForeignPointer for T { unsafe fn write_foreign_volatile(self: *mut Self, space: &ProcessAddressSpace, value: T) { - self.try_write_foreign_volatile(space, value) + unsafe { self.try_write_foreign_volatile(space, value) } .expect("Invalid foreign pointer, could not write") } @@ -133,7 +133,7 @@ impl ForeignPointer for T { let phys_page = space.translate(start_page)?; let virt_ptr = phys_page.add(page_offset).virtualize() as *mut T; - virt_ptr.write_unaligned(value); + unsafe { virt_ptr.write_unaligned(value) }; Ok(()) } @@ -153,7 +153,7 @@ impl ForeignPointer for T { let phys_page = space.translate(start_page)?; let virt_ptr = phys_page.add(page_offset).virtualize() as *const Self; - Ok(virt_ptr.read_unaligned()) + Ok(unsafe { virt_ptr.read_unaligned() }) } unsafe fn validate_user_slice_mut<'a>( @@ -167,7 +167,7 @@ impl ForeignPointer for T { validate_user_align_size(base, &layout)?; validate_user_region(space, base, layout.size(), true)?; - Ok(core::slice::from_raw_parts_mut(self, len)) + Ok(unsafe { core::slice::from_raw_parts_mut(self, len) }) } unsafe fn validate_user_slice<'a>( @@ -181,7 +181,7 @@ impl ForeignPointer for T { validate_user_align_size(base, &layout)?; validate_user_region(space, base, layout.size(), false)?; - Ok(core::slice::from_raw_parts(self, len)) + Ok(unsafe { core::slice::from_raw_parts(self, len) }) } unsafe fn validate_user_mut<'a>( @@ -198,7 +198,7 @@ impl ForeignPointer for T { // TODO for CoW this may differ validate_user_region(space, addr, layout.size(), true)?; - Ok(&mut *self) + Ok(unsafe { &mut *self }) } unsafe fn validate_user_ptr<'a>( @@ -212,7 +212,7 @@ impl ForeignPointer for T { validate_user_align_size(addr, &layout)?; validate_user_region(space, addr, layout.size(), false)?; - Ok(&*self) + Ok(unsafe { &*self }) } } @@ -223,7 +223,7 @@ impl ForeignAtomic for AtomicU32 { ordering: Ordering, ) -> Result { let virt = self.addr(); - if virt % size_of::() != 0 { + if !virt.is_multiple_of(size_of::()) { // Misaligned atomic return Err(Error::InvalidMemoryOperation); } @@ -239,7 +239,7 @@ fn validate_user_align_size(addr: usize, layout: &Layout) -> Result<(), Error> { return Err(Error::InvalidArgument); } // Validate alignment - if addr % layout.align() != 0 { + if !addr.is_multiple_of(layout.align()) { return Err(Error::InvalidArgument); } if addr + layout.size() > KERNEL_VIRT_OFFSET { diff --git a/kernel/libk/src/task/process.rs b/kernel/libk/src/task/process.rs index 9a9cafac..455907be 100644 --- a/kernel/libk/src/task/process.rs +++ b/kernel/libk/src/task/process.rs @@ -6,30 +6,30 @@ use core::{ use abi_lib::SyscallRegister; use alloc::{ - collections::{btree_map, BTreeMap}, + collections::{BTreeMap, btree_map}, format, string::String, sync::{Arc, Weak}, vec::Vec, }; use kernel_arch::{ - task::{TaskContext, UserContextInfo}, KernelTableManagerImpl, + task::{TaskContext, UserContextInfo}, }; use libk_mm::{phys::GlobalPhysicalAllocator, process::ProcessAddressSpace}; use libk_util::{ event::{BoolEvent, OneTimeEvent}, sync::{ - spin_rwlock::{IrqSafeRwLock, IrqSafeRwLockReadGuard, IrqSafeRwLockWriteGuard}, IrqSafeSpinlock, + spin_rwlock::{IrqSafeRwLock, IrqSafeRwLockReadGuard, IrqSafeRwLockWriteGuard}, }, }; use yggdrasil_abi::{ error::Error, option::OptionValue, process::{ - options::ProcessOptionVariant, ExitCode, ProcessGroupId, ProcessId, Signal, ThreadEvent, - ThreadSpawnOptions, WaitFlags, + ExitCode, ProcessGroupId, ProcessId, Signal, ThreadEvent, ThreadSpawnOptions, WaitFlags, + options::ProcessOptionVariant, }, }; @@ -40,7 +40,7 @@ use crate::{ object::KObject, }, task::{ - futex::UserspaceMutex, thread::Thread, types::AllocateProcessId, TaskContextImpl, ThreadId, + TaskContextImpl, ThreadId, futex::UserspaceMutex, thread::Thread, types::AllocateProcessId, }, vfs::{FileReadiness, FileSet, IoContext, NodeRef}, }; @@ -275,7 +275,7 @@ impl Process { let src_thread = Thread::current(); let src_process = src_thread.process(); - let value = src_process.fork_inner(frame).into_syscall_register(); + let value = unsafe { src_process.fork_inner(frame).into_syscall_register() }; frame.set_return_value(value as _); } @@ -515,10 +515,10 @@ impl Process { self.remove_sysfs_node(); self.io.lock().handle_exit(); inner.threads.clear(); - if let Some(space) = inner.space.take() { - if let Err(err) = space.clear() { - log::error!("Address space cleanup error: {err:?}"); - } + if let Some(space) = inner.space.take() + && let Err(err) = space.clear() + { + log::error!("Address space cleanup error: {err:?}"); } } diff --git a/kernel/libk/src/task/runtime/executor.rs b/kernel/libk/src/task/runtime/executor.rs index 1eb7b7c4..7aaed552 100644 --- a/kernel/libk/src/task/runtime/executor.rs +++ b/kernel/libk/src/task/runtime/executor.rs @@ -1,12 +1,12 @@ use core::task::{Context, Poll, Waker}; use alloc::{boxed::Box, format, sync::Arc}; -use futures_util::{task::waker_ref, Future}; +use futures_util::{Future, task::waker_ref}; use kernel_arch::task::TaskContext; use libk_util::waker::WakeWeak; use yggdrasil_abi::error::Error; -use crate::task::{thread::Thread, TaskContextImpl}; +use crate::task::{TaskContextImpl, thread::Thread}; use super::{ task::{Task, Termination}, @@ -24,16 +24,18 @@ pub fn spawn_async_worker(index: usize) -> Result<(), Error> { let thread = Thread::new_kthread( name, - TaskContextImpl::kernel_closure(move || loop { - let task = task_queue::pop_task().unwrap(); - let mut future_slot = task.future.lock(); + TaskContextImpl::kernel_closure(move || { + loop { + let task = task_queue::pop_task().unwrap(); + let mut future_slot = task.future.lock(); - if let Some(mut future) = future_slot.take() { - let waker = waker_ref(&task); - let context = &mut Context::from_waker(&waker); + if let Some(mut future) = future_slot.take() { + let waker = waker_ref(&task); + let context = &mut Context::from_waker(&waker); - if future.as_mut().poll(context).is_pending() { - *future_slot = Some(future); + if future.as_mut().poll(context).is_pending() { + *future_slot = Some(future); + } } } })?, @@ -70,11 +72,11 @@ pub fn run_to_completion<'a, T, F: Future + 'a>(future: F) -> Result match future.as_mut().poll(context) { Poll::Ready(value) => break Ok(value), Poll::Pending => { - if let Some(thread) = unsafe { Thread::upgrade(&weak) } { - if let Err(error) = thread.suspend() { - log::warn!("Future cancelled: {error:?}"); - break Err(error); - } + if let Some(thread) = unsafe { Thread::upgrade(&weak) } + && let Err(error) = thread.suspend() + { + log::warn!("Future cancelled: {error:?}"); + break Err(error); } } } diff --git a/kernel/libk/src/task/runtime/mod.rs b/kernel/libk/src/task/runtime/mod.rs index 21fe84f0..2694b570 100644 --- a/kernel/libk/src/task/runtime/mod.rs +++ b/kernel/libk/src/task/runtime/mod.rs @@ -9,5 +9,5 @@ mod timer; pub use executor::{run_to_completion, spawn, spawn_async_worker}; pub use task_queue::init_task_queue; pub use timer::{ - maybe_timeout, psleep, pwait, pwait_try, sleep, sleep_until, tick, with_timeout, SleepFuture, + SleepFuture, maybe_timeout, psleep, pwait, pwait_try, sleep, sleep_until, tick, with_timeout, }; diff --git a/kernel/libk/src/task/runtime/task.rs b/kernel/libk/src/task/runtime/task.rs index 3a39c1b6..7c20b6e3 100644 --- a/kernel/libk/src/task/runtime/task.rs +++ b/kernel/libk/src/task/runtime/task.rs @@ -1,7 +1,7 @@ use core::{fmt, sync::atomic::AtomicBool}; use alloc::sync::Arc; -use futures_util::{future::BoxFuture, task::ArcWake, Future, FutureExt}; +use futures_util::{Future, FutureExt, future::BoxFuture, task::ArcWake}; use libk_util::sync::IrqSafeSpinlock; use super::executor; diff --git a/kernel/libk/src/task/runtime/task_queue.rs b/kernel/libk/src/task/runtime/task_queue.rs index b9d205e7..1057e2e5 100644 --- a/kernel/libk/src/task/runtime/task_queue.rs +++ b/kernel/libk/src/task/runtime/task_queue.rs @@ -2,7 +2,7 @@ use core::sync::atomic::Ordering; use alloc::sync::Arc; use crossbeam_queue::ArrayQueue; -use libk_util::{sync::IrqGuard, OneTimeInit}; +use libk_util::{OneTimeInit, sync::IrqGuard}; use yggdrasil_abi::error::Error; use crate::task::thread::Thread; diff --git a/kernel/libk/src/task/sched.rs b/kernel/libk/src/task/sched.rs index 962a7277..a6aa3521 100644 --- a/kernel/libk/src/task/sched.rs +++ b/kernel/libk/src/task/sched.rs @@ -7,14 +7,14 @@ use core::{ use alloc::{sync::Arc, vec::Vec}; use crossbeam_queue::SegQueue; use kernel_arch::{ - task::{Scheduler, TaskContext}, Architecture, ArchitectureImpl, CpuImpl, + task::{Scheduler, TaskContext}, }; -use libk_util::{sync::IrqGuard, OneTimeInit}; +use libk_util::{OneTimeInit, sync::IrqGuard}; use yggdrasil_abi::time::SystemTime; use crate::{ - task::{thread::Thread, TaskContextImpl, ThreadId, ThreadState}, + task::{TaskContextImpl, ThreadId, ThreadState, thread::Thread}, time::monotonic_time, }; @@ -74,7 +74,7 @@ impl CpuQueue { pub unsafe fn enter(&self) -> ! { let _guard = IrqGuard::acquire(); - (*self.idle.as_ptr()).enter() + unsafe { (*self.idle.as_ptr()).enter() } } fn pop(&self) -> (Option>, Option) { @@ -178,10 +178,10 @@ impl Scheduler for CpuQueue { let current = current_id.and_then(Thread::get); let t = monotonic_time(); - if let Some(t0) = self.last_stats_measure.get() { - if let Some(dt) = t.checked_sub_time(&t0) { - self.update_stats(dt, current.as_ref()); - } + if let Some(t0) = self.last_stats_measure.get() + && let Some(dt) = t.checked_sub_time(&t0) + { + self.update_stats(dt, current.as_ref()); } self.last_stats_measure.set(Some(t)); @@ -242,9 +242,9 @@ impl Scheduler for CpuQueue { if !core::ptr::eq(current_ctx, next_ctx) { // Perform the switch if drop_current { - (*next_ctx).switch_and_drop(Arc::into_raw(current.unwrap()) as _); + unsafe { (*next_ctx).switch_and_drop(Arc::into_raw(current.unwrap()) as _) }; } else { - (*next_ctx).switch(&*current_ctx); + unsafe { (*next_ctx).switch(&*current_ctx) }; } true diff --git a/kernel/libk/src/task/sync.rs b/kernel/libk/src/task/sync.rs index 04f5f0a4..8761fb30 100644 --- a/kernel/libk/src/task/sync.rs +++ b/kernel/libk/src/task/sync.rs @@ -206,14 +206,14 @@ impl<'q> LockMethod<'q> for ThreadedMutexInner { } unsafe fn release(&self) { - if self.lock.swap(Self::UNLOCKED, Ordering::Release) == Self::LOCKED { - if let Some(t) = self.queue.pop() { - t.enqueue(); + if self.lock.swap(Self::UNLOCKED, Ordering::Release) == Self::LOCKED + && let Some(t) = self.queue.pop() + { + t.enqueue(); - // Yield current thread to avoid congestion - unsafe { - CpuQueue::local().yield_cpu(); - } + // Yield current thread to avoid congestion + unsafe { + CpuQueue::local().yield_cpu(); } } } @@ -244,7 +244,7 @@ impl<'q, T> LockMethod<'q> for Mutex { } unsafe fn release(&self) { - self.lock.release(); + unsafe { self.lock.release() }; } } diff --git a/kernel/libk/src/task/thread.rs b/kernel/libk/src/task/thread.rs index 024d6c24..60b29985 100644 --- a/kernel/libk/src/task/thread.rs +++ b/kernel/libk/src/task/thread.rs @@ -16,14 +16,14 @@ use alloc::{ use crossbeam_queue::SegQueue; use futures_util::task::ArcWake; use kernel_arch::{ - task::{Scheduler, TaskContext, TaskFrame}, CpuImpl, + task::{Scheduler, TaskContext, TaskFrame}, }; -use libk_mm::{process::ProcessAddressSpace, PageFaultKind}; +use libk_mm::{PageFaultKind, process::ProcessAddressSpace}; use libk_util::{ event::BoolEvent, ring::LossyRingQueue, - sync::{spin_rwlock::IrqSafeRwLock, IrqGuard, IrqSafeSpinlock, IrqSafeSpinlockGuard}, + sync::{IrqGuard, IrqSafeSpinlock, IrqSafeSpinlockGuard, spin_rwlock::IrqSafeRwLock}, }; use yggdrasil_abi::{ arch::SavedFrame, @@ -31,8 +31,8 @@ use yggdrasil_abi::{ error::Error, option::{OptionValue, RequestValue}, process::{ - thread::{ThreadOptionVariant, ThreadSignalStack}, ExitCode, ProcessId, Signal, SignalEntryData, ThreadEvent, + thread::{ThreadOptionVariant, ThreadSignalStack}, }, }; @@ -42,10 +42,10 @@ use crate::{ object::KObject, }, task::{ + TaskContextImpl, mem::ForeignPointer, sched::CpuQueue, types::{ThreadAffinity, ThreadId, ThreadState}, - TaskContextImpl, }, time::monotonic_time, }; @@ -124,11 +124,11 @@ struct GlobalThreadList { static THREADS: IrqSafeRwLock = IrqSafeRwLock::new(GlobalThreadList::new()); // TODO this is ugly? -#[no_mangle] +#[unsafe(no_mangle)] unsafe extern "C" fn __arch_drop_thread(thread_ptr: *const Thread) { - let thread = Arc::from_raw(thread_ptr); + let thread = unsafe { Arc::from_raw(thread_ptr) }; Thread::remove_from_list(thread.id); - Arc::decrement_strong_count(thread_ptr); + unsafe { Arc::decrement_strong_count(thread_ptr) }; } impl Thread { @@ -867,13 +867,15 @@ impl CurrentThread { let frame_ptr = usp as *mut SignalEntryData; let saved_frame = frame.store(); - frame_ptr.write_foreign_volatile( - self.address_space(), - SignalEntryData { - signal, - frame: saved_frame, - }, - ); + unsafe { + frame_ptr.write_foreign_volatile( + self.address_space(), + SignalEntryData { + signal, + frame: saved_frame, + }, + ); + } // Setup return to signal handler log::debug!( @@ -951,11 +953,9 @@ impl ThreadEvents { pub async fn wait(&self, with_trace: bool) -> ThreadEvent { poll_fn(|cx| { - if with_trace { - if let Poll::Ready(mut lock) = self.trace.poll_lock(cx) { - let event = unsafe { lock.read_single_unchecked() }; - return Poll::Ready(ThreadEvent::Trace(event)); - } + if with_trace && let Poll::Ready(mut lock) = self.trace.poll_lock(cx) { + let event = unsafe { lock.read_single_unchecked() }; + return Poll::Ready(ThreadEvent::Trace(event)); } if self.exit.poll(cx).is_ready() { diff --git a/kernel/libk/src/vfs/file/mod.rs b/kernel/libk/src/vfs/file/mod.rs index 8c68410d..4016a5ad 100644 --- a/kernel/libk/src/vfs/file/mod.rs +++ b/kernel/libk/src/vfs/file/mod.rs @@ -7,24 +7,24 @@ use core::{ use alloc::{ boxed::Box, - collections::{btree_map::Entry, BTreeMap}, + collections::{BTreeMap, btree_map::Entry}, sync::Arc, }; use async_trait::async_trait; use device::{BlockFile, CharFile}; use libk_mm::{ - address::PhysicalAddress, table::MapAttributes, OnDemandPage, PageProvider, VirtualPage, + OnDemandPage, PageProvider, VirtualPage, address::PhysicalAddress, table::MapAttributes, }; use libk_util::{ io::{ReadAt, WriteAt}, - sync::{spin_rwlock::IrqSafeRwLock, IrqSafeSpinlock}, + sync::{IrqSafeSpinlock, spin_rwlock::IrqSafeRwLock}, }; use yggdrasil_abi::{ error::Error, io::{ - options::{self, FileOptionVariant}, DirectoryEntry, FileMode, OpenOptions, RawFd, SeekFrom, TerminalOptions, TerminalSize, TimerOptions, + options::{self, FileOptionVariant}, }, net::{MessageHeader, MessageHeaderMut}, option::{OptionValue, RequestValue}, @@ -35,19 +35,19 @@ use crate::{ device::{block::BlockDeviceFile, char::CharDeviceFile}, task::process::Process, vfs::{ + FdPoll, FileReadiness, Node, SharedMemory, TimerFile, node::NodeRef, traits::{Read, Seek, Write}, - FdPoll, FileReadiness, Node, SharedMemory, TimerFile, }, }; use self::{directory::DirectoryFile, pipe::PipeEnd, regular::RegularFile}; use super::{ + Metadata, pid::PidFile, pty::{self, PseudoTerminalMaster, PseudoTerminalSlave}, socket::SocketWrapper, - Metadata, }; mod device; @@ -692,11 +692,11 @@ mod tests { }; use crate::vfs::{ + FileReadiness, Filename, InstanceData, file::DirectoryOpenPosition, impls::const_value_node, node::{AccessToken, CommonImpl, DirectoryImpl, Node, NodeFlags, NodeRef, RegularImpl}, traits::{Read, Seek, Write}, - FileReadiness, Filename, InstanceData, }; #[test] diff --git a/kernel/libk/src/vfs/file/regular.rs b/kernel/libk/src/vfs/file/regular.rs index a63320a7..f6319cde 100644 --- a/kernel/libk/src/vfs/file/regular.rs +++ b/kernel/libk/src/vfs/file/regular.rs @@ -1,6 +1,6 @@ use libk_mm::{ - address::PhysicalAddress, phys, pointer::PhysicalRef, table::MapAttributes, OnDemandPage, - PageBox, PageProvider, VirtualPage, L3_PAGE_SIZE, + L3_PAGE_SIZE, OnDemandPage, PageBox, PageProvider, VirtualPage, address::PhysicalAddress, phys, + pointer::PhysicalRef, table::MapAttributes, }; use libk_util::sync::IrqSafeSpinlock; use yggdrasil_abi::{error::Error, io::SeekFrom}; diff --git a/kernel/libk/src/vfs/ioctx.rs b/kernel/libk/src/vfs/ioctx.rs index 06c868b3..886e6d6d 100644 --- a/kernel/libk/src/vfs/ioctx.rs +++ b/kernel/libk/src/vfs/ioctx.rs @@ -5,11 +5,11 @@ use yggdrasil_abi::{ }; use crate::vfs::{ - node::{AccessToken, CreateInfo}, FileRef, Filename, NodeRef, + node::{AccessToken, CreateInfo}, }; -use super::{node::CreateFileType, Node}; +use super::{Node, node::CreateFileType}; /// Describes a general filesystem access pub enum Action { @@ -580,9 +580,9 @@ mod tests { }; use crate::vfs::{ + Node, Read, impls::{const_value_node, fixed_hardlink, fixed_path_symlink, mdir, value_node}, node::AccessToken, - Node, Read, }; use super::IoContext; diff --git a/kernel/libk/src/vfs/mod.rs b/kernel/libk/src/vfs/mod.rs index ec85f075..8eba13cd 100644 --- a/kernel/libk/src/vfs/mod.rs +++ b/kernel/libk/src/vfs/mod.rs @@ -19,13 +19,13 @@ pub(crate) mod traits; pub use file::{DirectoryOpenPosition, File, FileRef, FileSet, InstanceData}; pub use filesystem::{ - parse_mount_options, register_root, roots as filesystem_roots, Filesystem, - FilesystemMountOption, + Filesystem, FilesystemMountOption, parse_mount_options, register_root, + roots as filesystem_roots, }; pub use ioctx::{Action, IoContext}; pub use node::{ - impls, AccessToken, CommonImpl, CreateFileType, CreateInfo, DirectoryImpl, Metadata, Node, - NodeFlags, NodeRef, RegularImpl, SymlinkImpl, + AccessToken, CommonImpl, CreateFileType, CreateInfo, DirectoryImpl, Metadata, Node, NodeFlags, + NodeRef, RegularImpl, SymlinkImpl, impls, }; pub use path::{Filename, OwnedFilename}; pub use poll::FdPoll; diff --git a/kernel/libk/src/vfs/node/impls.rs b/kernel/libk/src/vfs/node/impls.rs index a72ffe29..268e2630 100644 --- a/kernel/libk/src/vfs/node/impls.rs +++ b/kernel/libk/src/vfs/node/impls.rs @@ -13,11 +13,11 @@ use yggdrasil_abi::{ io::{FileMode, FileType, OpenOptions}, }; -use crate::vfs::{path::OwnedFilename, DirectoryOpenPosition, InstanceData}; +use crate::vfs::{DirectoryOpenPosition, InstanceData, path::OwnedFilename}; use super::{ - traits::HardlinkImpl, CommonImpl, DirectoryImpl, Metadata, Node, NodeFlags, NodeRef, - RegularImpl, SymlinkImpl, + CommonImpl, DirectoryImpl, Metadata, Node, NodeFlags, NodeRef, RegularImpl, SymlinkImpl, + traits::HardlinkImpl, }; trait SliceRead { @@ -513,8 +513,8 @@ mod tests { use crate::vfs::{ node::{ - impls::{const_value_node, value_node}, AccessToken, + impls::{const_value_node, value_node}, }, traits::{Read, Seek, Write}, }; diff --git a/kernel/libk/src/vfs/node/mod.rs b/kernel/libk/src/vfs/node/mod.rs index c2927c65..531e2333 100644 --- a/kernel/libk/src/vfs/node/mod.rs +++ b/kernel/libk/src/vfs/node/mod.rs @@ -8,7 +8,7 @@ use alloc::{ }; use libk_util::{ ext::OptionExt, - sync::{spin_rwlock::IrqSafeRwLock, IrqSafeSpinlock}, + sync::{IrqSafeSpinlock, spin_rwlock::IrqSafeRwLock}, }; use traits::HardlinkImpl; use yggdrasil_abi::{ @@ -39,9 +39,9 @@ use crate::{ }; use super::{ + Filename, Filesystem, path::OwnedFilename, pty::{PseudoTerminalMaster, PseudoTerminalSlave}, - Filename, Filesystem, }; /// Wrapper type for a [Node] shared reference @@ -552,7 +552,7 @@ mod tests { use core::any::Any; use std::sync::Arc; - use crate::vfs::{node::NodeFlags, Filename}; + use crate::vfs::{Filename, node::NodeFlags}; use super::{CommonImpl, DirectoryImpl, Node, RegularImpl}; diff --git a/kernel/libk/src/vfs/node/ops.rs b/kernel/libk/src/vfs/node/ops.rs index a77a4197..eb243f21 100644 --- a/kernel/libk/src/vfs/node/ops.rs +++ b/kernel/libk/src/vfs/node/ops.rs @@ -7,9 +7,9 @@ use yggdrasil_abi::{ }; use crate::vfs::{ + Filename, file::{File, FileRef}, path::OwnedFilename, - Filename, }; use super::{AccessToken, CreateInfo, DirectoryData, Metadata, Node, NodeFlags, NodeImpl, NodeRef}; diff --git a/kernel/libk/src/vfs/node/traits.rs b/kernel/libk/src/vfs/node/traits.rs index 5bcf96cf..f1126e1b 100644 --- a/kernel/libk/src/vfs/node/traits.rs +++ b/kernel/libk/src/vfs/node/traits.rs @@ -7,8 +7,8 @@ use yggdrasil_abi::{ }; use crate::vfs::{ - file::{DirectoryOpenPosition, InstanceData}, Filename, + file::{DirectoryOpenPosition, InstanceData}, }; use super::{CreateInfo, Metadata, NodeRef}; diff --git a/kernel/libk/src/vfs/path.rs b/kernel/libk/src/vfs/path.rs index c39971c7..9c637312 100644 --- a/kernel/libk/src/vfs/path.rs +++ b/kernel/libk/src/vfs/path.rs @@ -34,7 +34,7 @@ impl Filename { /// the filename validity invariants. #[inline(always)] pub const unsafe fn from_str_unchecked(name: &str) -> &Self { - mem::transmute(name) + unsafe { mem::transmute(name) } } } diff --git a/kernel/libk/src/vfs/poll.rs b/kernel/libk/src/vfs/poll.rs index bd82d02c..e584096b 100644 --- a/kernel/libk/src/vfs/poll.rs +++ b/kernel/libk/src/vfs/poll.rs @@ -6,7 +6,7 @@ use core::{ use alloc::collections::BTreeMap; -use futures_util::{future::BoxFuture, FutureExt}; +use futures_util::{FutureExt, future::BoxFuture}; use libk_util::sync::LockMethod; use yggdrasil_abi::{error::Error, io::RawFd}; diff --git a/kernel/libk/src/vfs/shared_memory.rs b/kernel/libk/src/vfs/shared_memory.rs index 71c2fc45..4357fe2b 100644 --- a/kernel/libk/src/vfs/shared_memory.rs +++ b/kernel/libk/src/vfs/shared_memory.rs @@ -2,9 +2,9 @@ use core::mem::MaybeUninit; use alloc::vec::Vec; use libk_mm::{ + L3_PAGE_SIZE, OnDemandPage, PageBox, PageProvider, VirtualPage, address::{AsPhysicalAddress, PhysicalAddress}, table::MapAttributes, - OnDemandPage, PageBox, PageProvider, VirtualPage, L3_PAGE_SIZE, }; use yggdrasil_abi::error::Error; diff --git a/kernel/libk/src/vfs/socket.rs b/kernel/libk/src/vfs/socket.rs index 2149d1d6..3fd92572 100644 --- a/kernel/libk/src/vfs/socket.rs +++ b/kernel/libk/src/vfs/socket.rs @@ -10,8 +10,8 @@ use libk_util::sync::spin_rwlock::IrqSafeRwLock; use yggdrasil_abi::{ error::Error, net::{ - options::{self, SocketOptionVariant}, MessageHeader, MessageHeaderMut, SocketShutdown, + options::{self, SocketOptionVariant}, }, option::OptionValue, }; @@ -95,7 +95,7 @@ pub trait Socket: FileReadiness + fmt::Debug + Send { ) -> Result; fn receive_nonblocking(self: Arc, message: &mut MessageHeaderMut) - -> Result; + -> Result; async fn receive_message( self: Arc, message: &mut MessageHeaderMut, diff --git a/kernel/libk/src/vfs/terminal.rs b/kernel/libk/src/vfs/terminal.rs index fe74f58d..e4c2a119 100644 --- a/kernel/libk/src/vfs/terminal.rs +++ b/kernel/libk/src/vfs/terminal.rs @@ -9,14 +9,14 @@ use async_trait::async_trait; use device_api::device::Device; use libk_util::{ ring::{LossyRingQueue, RingBuffer}, - sync::{spin_rwlock::IrqSafeRwLock, IrqSafeSpinlock}, + sync::{IrqSafeSpinlock, spin_rwlock::IrqSafeRwLock}, }; use yggdrasil_abi::{ error::Error, io::{ - device::{self, TerminalRequestVariant}, KeyboardKey, KeyboardKeyEvent, TerminalInputOptions, TerminalLineOptions, TerminalOptions, TerminalOutputOptions, TerminalSize, + device::{self, TerminalRequestVariant}, }, option::RequestValue, process::{ProcessGroupId, Signal}, diff --git a/kernel/src/arch/aarch64/boot/mod.rs b/kernel/src/arch/aarch64/boot/mod.rs index 83647e21..d57e4363 100644 --- a/kernel/src/arch/aarch64/boot/mod.rs +++ b/kernel/src/arch/aarch64/boot/mod.rs @@ -8,15 +8,15 @@ use core::{ use aarch64_cpu::{ asm::barrier, registers::{ - CNTHCTL_EL2, CNTHP_CTL_EL2, CNTKCTL_EL1, CNTVOFF_EL2, CPACR_EL1, ELR_EL2, HCR_EL2, - SPSR_EL2, SP_EL1, TTBR0_EL1, + CNTHCTL_EL2, CNTHP_CTL_EL2, CNTKCTL_EL1, CNTVOFF_EL2, CPACR_EL1, ELR_EL2, HCR_EL2, SP_EL1, + SPSR_EL2, TTBR0_EL1, }, }; use elf::{abi, relocation::Elf64_Rela}; use kernel_arch::{Architecture, ArchitectureImpl, KERNEL_VIRT_OFFSET}; use kernel_arch_aarch64::{ - mem::{self, table::L3}, CPU_COUNT, + mem::{self, table::L3}, }; use libk::{ fs::{devfs, sysfs}, @@ -31,8 +31,8 @@ use tock_registers::interfaces::{ReadWriteable, Writeable}; use crate::{ arch::{ - aarch64::{exception, BootStack, BOOT_STACK_SIZE}, PLATFORM, + aarch64::{BOOT_STACK_SIZE, BootStack, exception}, }, kernel_main, kernel_secondary_main, }; @@ -92,7 +92,7 @@ unsafe fn long_jump(pc: usize, sp: usize) -> ! { unsafe extern "C" fn bsp_entry_upper() -> ! { // Relocate the kernel again - extern "C" { + unsafe extern "C" { static __rela_start: u8; static __rela_end: u8; } @@ -161,13 +161,13 @@ unsafe extern "C" fn ap_entry_upper() -> ! { unsafe extern "C" fn bsp_entry_el1() -> ! { setup_cpu_common(); mem::init_lower(true); - let pc = (bsp_entry_upper as usize) + KERNEL_VIRT_OFFSET; + let pc = (bsp_entry_upper as *const ()).addr() + KERNEL_VIRT_OFFSET; let sp = BSP_STACK.top_addr() + KERNEL_VIRT_OFFSET; long_jump(pc, sp) } unsafe extern "C" fn bsp_entry_el2() -> ! { - leave_el2(bsp_entry_el1 as usize, BSP_STACK.top_addr(), 0) + leave_el2((bsp_entry_el1 as *const ()).addr(), BSP_STACK.top_addr(), 0) } unsafe extern "C" fn ap_entry_el1(sp: usize) -> ! { @@ -181,12 +181,12 @@ unsafe extern "C" fn ap_entry_el1(sp: usize) -> ! { let stack_base = stack_pages.virtualize(); let sp = stack_base + L3::SIZE * AP_STACK_PAGES; - let pc = (ap_entry_upper as usize) + KERNEL_VIRT_OFFSET; + let pc = (ap_entry_upper as *const ()).addr() + KERNEL_VIRT_OFFSET; long_jump(pc, sp) } unsafe extern "C" fn ap_entry_el2(sp: usize) -> ! { - leave_el2(ap_entry_el1 as usize, sp, sp) + leave_el2((ap_entry_el1 as *const ()).addr(), sp, sp) } global_asm!( diff --git a/kernel/src/arch/aarch64/exception.rs b/kernel/src/arch/aarch64/exception.rs index 7d41dab0..26443e02 100644 --- a/kernel/src/arch/aarch64/exception.rs +++ b/kernel/src/arch/aarch64/exception.rs @@ -12,14 +12,14 @@ use aarch64_cpu::{ TTBR1_EL1, VBAR_EL1, }, }; -use abi::{process::Signal, SyscallFunction}; -use kernel_arch::{sync::hack_locks, Architecture, ArchitectureImpl}; +use abi::{SyscallFunction, process::Signal}; +use kernel_arch::{Architecture, ArchitectureImpl, sync::hack_locks}; use kernel_arch_aarch64::{ context::ExceptionFrame, - mem::table::{EntryType, PageTable, L1, L2, L3}, + mem::table::{EntryType, L1, L2, L3, PageTable}, }; use libk::{device::external_interrupt_controller, task::thread::Thread}; -use libk_mm::{address::PhysicalAddress, table::EntryLevelExt, PageFaultKind}; +use libk_mm::{PageFaultKind, address::PhysicalAddress, table::EntryLevelExt}; use tock_registers::interfaces::{Readable, Writeable}; use crate::{ @@ -30,7 +30,7 @@ use crate::{ /// Initializes the exception/interrupt vectors. May be called repeatedly (though that makes no /// sense). pub fn init_exceptions() { - extern "C" { + unsafe extern "C" { static __aarch64_el1_vectors: u8; } let vbar = unsafe { &__aarch64_el1_vectors as *const _ }; @@ -146,7 +146,7 @@ fn dump_irrecoverable_exception(frame: &ExceptionFrame, ec: u64, iss: u64) { log::error!(target: ":raw", "TPIDR_EL0 = {:#x}\n", TPIDR_EL0.get()); } -#[no_mangle] +#[unsafe(no_mangle)] extern "C" fn __aa64_el0_sync_handler(frame: *mut ExceptionFrame) { assert!(ArchitectureImpl::interrupt_mask()); let frame = unsafe { &mut *frame }; @@ -159,7 +159,7 @@ extern "C" fn __aa64_el0_sync_handler(frame: *mut ExceptionFrame) { } } -#[no_mangle] +#[unsafe(no_mangle)] extern "C" fn __aa64_el0_irq_handler(frame: *mut ExceptionFrame) { assert!(ArchitectureImpl::interrupt_mask()); let frame = unsafe { &mut *frame }; @@ -172,12 +172,12 @@ extern "C" fn __aa64_el0_irq_handler(frame: *mut ExceptionFrame) { } } -#[no_mangle] +#[unsafe(no_mangle)] extern "C" fn __aa64_el0_fiq_handler() { unimplemented!() } -#[no_mangle] +#[unsafe(no_mangle)] extern "C" fn __aa64_el0_serror_handler() { unimplemented!() } @@ -185,7 +185,7 @@ extern "C" fn __aa64_el0_serror_handler() { // EL1 static EL1_FAULT_TAKEN: AtomicBool = AtomicBool::new(false); -#[no_mangle] +#[unsafe(no_mangle)] extern "C" fn __aa64_el1_sync_handler(frame: *mut ExceptionFrame) { if EL1_FAULT_TAKEN.swap(true, Ordering::Release) { // Fault already taken @@ -204,17 +204,17 @@ extern "C" fn __aa64_el1_sync_handler(frame: *mut ExceptionFrame) { panic!("Irrecoverable exception in kernel mode"); } -#[no_mangle] +#[unsafe(no_mangle)] extern "C" fn __aa64_el1_irq_handler(_frame: *mut ExceptionFrame) { irq_common(); } -#[no_mangle] +#[unsafe(no_mangle)] extern "C" fn __aa64_el1_fiq_handler() { unimplemented!() } -#[no_mangle] +#[unsafe(no_mangle)] extern "C" fn __aa64_el1_serror_handler() { unimplemented!() } diff --git a/kernel/src/arch/aarch64/gic/gicv2m.rs b/kernel/src/arch/aarch64/gic/gicv2m.rs index 8fb41723..61a6aefb 100644 --- a/kernel/src/arch/aarch64/gic/gicv2m.rs +++ b/kernel/src/arch/aarch64/gic/gicv2m.rs @@ -10,11 +10,11 @@ use device_api::{ IrqOptions, IrqTrigger, IrqVector, MessageInterruptController, MsiInfo, }, }; -use device_tree::driver::{device_tree_driver, Node, ProbeContext}; +use device_tree::driver::{Node, ProbeContext, device_tree_driver}; use libk_mm::{address::PhysicalAddress, device::DeviceMemoryIo}; use libk_util::{ - sync::{spin_rwlock::IrqSafeRwLock, IrqSafeSpinlock}, OneTimeInit, + sync::{IrqSafeSpinlock, spin_rwlock::IrqSafeRwLock}, }; use tock_registers::{ interfaces::Readable, diff --git a/kernel/src/arch/aarch64/gic/mod.rs b/kernel/src/arch/aarch64/gic/mod.rs index 547a8b61..72c74b79 100644 --- a/kernel/src/arch/aarch64/gic/mod.rs +++ b/kernel/src/arch/aarch64/gic/mod.rs @@ -14,10 +14,10 @@ use device_api::{ }, }; use device_tree::{ - driver::{device_tree_driver, DeviceTreeInterruptController, Node, ProbeContext}, DeviceTreePropertyRead, TProp, + driver::{DeviceTreeInterruptController, Node, ProbeContext, device_tree_driver}, }; -use kernel_arch_aarch64::{GicInterface, CPU_COUNT}; +use kernel_arch_aarch64::{CPU_COUNT, GicInterface}; use libk::{arch::Cpu, device::register_external_interrupt_controller, task::cpu_index}; use libk_mm::{ address::PhysicalAddress, diff --git a/kernel/src/arch/aarch64/mod.rs b/kernel/src/arch/aarch64/mod.rs index cdb2120f..7ac310da 100644 --- a/kernel/src/arch/aarch64/mod.rs +++ b/kernel/src/arch/aarch64/mod.rs @@ -5,30 +5,30 @@ use core::sync::atomic::{self, Ordering}; use aarch64_cpu::registers::{CNTP_CTL_EL0, CNTP_TVAL_EL0}; use alloc::sync::Arc; use device_api::{ - interrupt::{IpiDeliveryTarget, IpiMessage, Irq, LocalInterruptController}, ResetDevice, + interrupt::{IpiDeliveryTarget, IpiMessage, Irq, LocalInterruptController}, }; use device_tree::{ - driver::{unflatten_device_tree, InitSequence}, DeviceTree, DeviceTreeNodeExt, + driver::{InitSequence, unflatten_device_tree}, }; use kernel_arch::Architecture; -use kernel_arch_aarch64::{mem, ArchitectureImpl, PerCpuData, CPU_COUNT}; +use kernel_arch_aarch64::{ArchitectureImpl, CPU_COUNT, PerCpuData, mem}; use libk::{arch::Cpu, config, debug, device::external_interrupt_controller, error::Error}; use libk_mm::{ address::PhysicalAddress, - phys::{self, reserved::reserve_region, PhysicalMemoryRegion}, + phys::{self, PhysicalMemoryRegion, reserved::reserve_region}, pointer::PhysicalRef, table::EntryLevelExt, }; -use libk_util::{sync::SpinFence, OneTimeInit}; +use libk_util::{OneTimeInit, sync::SpinFence}; use tock_registers::interfaces::Writeable; use ygg_driver_pci::PciBusManager; use crate::{ - arch::{aarch64::gic::Gic, Platform}, - device::{power::arm_psci::Psci, MACHINE_NAME}, - fs::{Initrd, INITRD_DATA}, + arch::{Platform, aarch64::gic::Gic}, + device::{MACHINE_NAME, power::arm_psci::Psci}, + fs::{INITRD_DATA, Initrd}, panic, util::call_init_array, }; @@ -74,11 +74,11 @@ static SHUTDOWN_FENCE: SpinFence = SpinFence::new(); impl Platform for AArch64 { unsafe fn start_application_processors(&self) { - if let Some(compatible) = self.machine_compatible.try_get() { - if *compatible == "raspberrypi,4-model-b" { - log::warn!("raspi4b: cache workaround disable SMP"); - return; - } + if let Some(compatible) = self.machine_compatible.try_get() + && *compatible == "raspberrypi,4-model-b" + { + log::warn!("raspi4b: cache workaround disable SMP"); + return; } let dt = self.dt.get(); diff --git a/kernel/src/arch/aarch64/smp.rs b/kernel/src/arch/aarch64/smp.rs index 8f2eb7b0..099cd706 100644 --- a/kernel/src/arch/aarch64/smp.rs +++ b/kernel/src/arch/aarch64/smp.rs @@ -1,7 +1,7 @@ //! Simultaneous multiprocessing support for aarch64 use core::{ ptr, - sync::atomic::{compiler_fence, AtomicU64, Ordering}, + sync::atomic::{AtomicU64, Ordering, compiler_fence}, }; use aarch64_cpu::asm::barrier; @@ -12,13 +12,13 @@ use kernel_arch_aarch64::CPU_COUNT; use libk_mm::address::{PhysicalAddress, Virtualize}; use crate::{ - arch::{aarch64::boot::SPIN_TABLE_STACK, PLATFORM}, + arch::{PLATFORM, aarch64::boot::SPIN_TABLE_STACK}, mem::KERNEL_VIRT_OFFSET, }; -use super::{BootStack, BOOT_STACK_SIZE}; +use super::{BOOT_STACK_SIZE, BootStack}; -#[link_section = ".bss"] +#[unsafe(link_section = ".bss")] static AP_TRAMPOLINE_STACK: BootStack = BootStack::zeroed(); #[derive(Debug)] @@ -66,7 +66,7 @@ fn enumerate_cpus<'a>(dt: &'a DeviceTree) -> impl Iterator> { impl CpuEnableMethod { unsafe fn start_cpu(&self, id: usize, ip: usize, sp: usize) -> Result<(), Error> { - extern "C" { + unsafe extern "C" { fn __aarch64_ap_spin_table_entry(); } @@ -92,7 +92,8 @@ impl CpuEnableMethod { let release_ptr = ptr::with_exposed_provenance_mut::(cpu_release_addr.virtualize()); let release_atomic = AtomicU64::from_ptr(release_ptr); - let spin_entry_addr = __aarch64_ap_spin_table_entry as usize - KERNEL_VIRT_OFFSET; + let spin_entry_addr = + (__aarch64_ap_spin_table_entry as *const ()).addr() - KERNEL_VIRT_OFFSET; release_atomic.store(spin_entry_addr as u64, Ordering::Release); @@ -120,7 +121,7 @@ impl CpuEnableMethod { /// The caller must ensure the physical memory manager was initialized, virtual memory tables are /// set up and the function has not been called before. pub unsafe fn start_ap_cores(dt: &DeviceTree) -> Result<(), Error> { - extern "C" { + unsafe extern "C" { fn __aarch64_ap_entry(); } @@ -140,7 +141,7 @@ pub unsafe fn start_ap_cores(dt: &DeviceTree) -> Result<(), Error> { let old_count = CPU_COUNT.load(Ordering::Acquire); // Safety: safe, the function is inside the kernel - let ip = __aarch64_ap_entry as usize - KERNEL_VIRT_OFFSET; + let ip = (__aarch64_ap_entry as *const ()).addr() - KERNEL_VIRT_OFFSET; barrier::dsb(barrier::ISH); barrier::isb(barrier::SY); diff --git a/kernel/src/arch/aarch64/timer.rs b/kernel/src/arch/aarch64/timer.rs index 8e7e1d61..515fae69 100644 --- a/kernel/src/arch/aarch64/timer.rs +++ b/kernel/src/arch/aarch64/timer.rs @@ -2,14 +2,14 @@ use core::sync::atomic::{AtomicU64, Ordering}; -use aarch64_cpu::registers::{CNTFRQ_EL0, CNTPCT_EL0, CNTP_CTL_EL0, CNTP_TVAL_EL0}; +use aarch64_cpu::registers::{CNTFRQ_EL0, CNTP_CTL_EL0, CNTP_TVAL_EL0, CNTPCT_EL0}; use abi::{error::Error, time::NANOSECONDS_IN_SECOND}; use alloc::sync::Arc; use device_api::{ device::{Device, DeviceInitContext}, interrupt::{InterruptHandler, IrqHandle, IrqVector}, }; -use device_tree::driver::{device_tree_driver, Node, ProbeContext}; +use device_tree::driver::{Node, ProbeContext, device_tree_driver}; use kernel_arch::task::Scheduler; use libk::{arch::Cpu, task::runtime, time}; use tock_registers::interfaces::{ReadWriteable, Readable, Writeable}; diff --git a/kernel/src/arch/mod.rs b/kernel/src/arch/mod.rs index d1343df3..a655a1ed 100644 --- a/kernel/src/arch/mod.rs +++ b/kernel/src/arch/mod.rs @@ -19,7 +19,7 @@ pub use x86_64::{L3, PLATFORM, X86_64 as PlatformImpl}; #[cfg(any(target_arch = "riscv64", rust_analyzer))] pub mod riscv64; #[cfg(any(target_arch = "riscv64", rust_analyzer))] -pub use riscv64::{Riscv64 as PlatformImpl, L3, PLATFORM}; +pub use riscv64::{L3, PLATFORM, Riscv64 as PlatformImpl}; #[cfg(not(any( target_arch = "x86_64", diff --git a/kernel/src/arch/riscv64/boot/mod.rs b/kernel/src/arch/riscv64/boot/mod.rs index 7029e7d7..da88140f 100644 --- a/kernel/src/arch/riscv64/boot/mod.rs +++ b/kernel/src/arch/riscv64/boot/mod.rs @@ -2,24 +2,24 @@ use core::{ arch::global_asm, - sync::atomic::{self, compiler_fence, Ordering}, + sync::atomic::{self, Ordering, compiler_fence}, }; use elf::{abi, relocation::Elf64_Rela}; use kernel_arch::{Architecture, ArchitectureImpl}; -use kernel_arch_riscv64::{mem, BOOT_HART_ID, CPU_COUNT}; +use kernel_arch_riscv64::{BOOT_HART_ID, CPU_COUNT, mem}; use libk::{ debug, fs::{devfs, sysfs}, task::runtime, }; use libk_mm::{ - address::{PhysicalAddress, Virtualize}, PageBox, + address::{PhysicalAddress, Virtualize}, }; use crate::{ - arch::{riscv64::smp::SecondaryContext, PLATFORM}, + arch::{PLATFORM, riscv64::smp::SecondaryContext}, kernel_main, kernel_secondary_main, mem::KERNEL_VIRT_OFFSET, }; @@ -63,7 +63,7 @@ unsafe fn long_jump(pc: usize, sp: usize, a0: usize) -> ! { unsafe extern "C" fn bsp_entry_upper() -> ! { // Relocate the kernel again - extern "C" { + unsafe extern "C" { static __rela_start: u8; static __rela_end: u8; } @@ -106,7 +106,7 @@ unsafe extern "C" fn bsp_entry_upper() -> ! { unsafe extern "C" fn bsp_smode_entry() -> ! { mem::enable_mmu(); - let pc = bsp_entry_upper as usize + KERNEL_VIRT_OFFSET; + let pc = (bsp_entry_upper as *const ()).addr() + KERNEL_VIRT_OFFSET; let sp = (&raw const BOOT_STACK).addr() + BOOT_STACK_SIZE + KERNEL_VIRT_OFFSET; long_jump(pc, sp, 0) } @@ -130,7 +130,7 @@ unsafe extern "C" fn ap_smode_entry(context: PhysicalAddress, sp: PhysicalAddres compiler_fence(Ordering::SeqCst); mem::enable_mmu(); compiler_fence(Ordering::SeqCst); - let pc = ap_smode_upper as usize + KERNEL_VIRT_OFFSET; + let pc = (ap_smode_upper as *const ()).addr() + KERNEL_VIRT_OFFSET; let sp = sp.virtualize(); long_jump(pc, sp, context.into_usize()) } diff --git a/kernel/src/arch/riscv64/exception.rs b/kernel/src/arch/riscv64/exception.rs index 5d079176..8c71fe5c 100644 --- a/kernel/src/arch/riscv64/exception.rs +++ b/kernel/src/arch/riscv64/exception.rs @@ -1,7 +1,7 @@ //! RISC-V exception handling functions use core::arch::global_asm; -use abi::{arch::SavedFrame, primitive_enum, process::Signal, SyscallFunction}; +use abi::{SyscallFunction, arch::SavedFrame, primitive_enum, process::Signal}; use kernel_arch::task::TaskFrame; use libk::{device::external_interrupt_controller, task::thread::Thread}; use libk_mm::PageFaultKind; @@ -54,7 +54,7 @@ pub struct TrapFrame { /// Sets up kernel exception handling pub fn init_smode_exceptions() { - extern "C" { + unsafe extern "C" { static __rv64_smode_trap_vectors: u8; } let address = (&raw const __rv64_smode_trap_vectors).addr(); diff --git a/kernel/src/arch/riscv64/mod.rs b/kernel/src/arch/riscv64/mod.rs index c0816e75..36c6a492 100644 --- a/kernel/src/arch/riscv64/mod.rs +++ b/kernel/src/arch/riscv64/mod.rs @@ -4,19 +4,19 @@ use core::sync::atomic::{self, Ordering}; use abi::error::Error; use device_api::clock::Hertz; use device_tree::{ - driver::{unflatten_device_tree, InitSequence}, DeviceTree, DeviceTreeNodeExt, + driver::{InitSequence, unflatten_device_tree}, }; use kernel_arch::{Architecture, ArchitectureImpl}; use kernel_arch_riscv64::{ - mem, + PerCpuData, mem, registers::{SIE, SSTATUS}, - sbi, PerCpuData, + sbi, }; use libk::{arch::Cpu, config}; use libk_mm::{ address::PhysicalAddress, - phys::{self, reserved::reserve_region, PhysicalMemoryRegion}, + phys::{self, PhysicalMemoryRegion, reserved::reserve_region}, pointer::PhysicalRef, table::EntryLevelExt, }; @@ -27,7 +27,7 @@ use ygg_driver_pci::PciBusManager; use crate::{ arch::Platform, device::MACHINE_NAME, - fs::{Initrd, INITRD_DATA}, + fs::{INITRD_DATA, Initrd}, util::call_init_array, }; diff --git a/kernel/src/arch/riscv64/smp.rs b/kernel/src/arch/riscv64/smp.rs index ff2ed384..e0f30a62 100644 --- a/kernel/src/arch/riscv64/smp.rs +++ b/kernel/src/arch/riscv64/smp.rs @@ -6,12 +6,12 @@ use abi::error::Error; use device_api::interrupt::{IpiDeliveryTarget, IpiMessage}; use device_tree::{DeviceTree, DeviceTreeNodeExt}; use kernel_arch_riscv64::{ - boot_hart_id, mem::auto_lower_address, registers::SIP, sbi, ArchitectureImpl, CPU_COUNT, + ArchitectureImpl, CPU_COUNT, boot_hart_id, mem::auto_lower_address, registers::SIP, sbi, }; use libk::arch::Cpu; use libk_mm::{ - address::{AsPhysicalAddress, PhysicalAddress}, PageBox, + address::{AsPhysicalAddress, PhysicalAddress}, }; use tock_registers::interfaces::ReadWriteable; @@ -31,7 +31,7 @@ pub struct SecondaryContext { } fn start_secondary_hart(hart_id: u64) -> Result<(), Error> { - extern "C" { + unsafe extern "C" { fn __riscv64_ap_entry(); } diff --git a/kernel/src/arch/riscv64/timer.rs b/kernel/src/arch/riscv64/timer.rs index 36280b85..f5c915ad 100644 --- a/kernel/src/arch/riscv64/timer.rs +++ b/kernel/src/arch/riscv64/timer.rs @@ -26,12 +26,12 @@ pub fn handle_interrupt() { if Cpu::local().is_bootstrap() { let last = LAST_TICK.swap(now, Ordering::Release); - if frequency != 0 { - if let Some(delta) = now.checked_sub(last) { - // Only update time from local CPU - let dt = delta * NANOSECONDS_IN_SECOND / frequency; - time::add_nanoseconds(dt); - } + if frequency != 0 + && let Some(delta) = now.checked_sub(last) + { + // Only update time from local CPU + let dt = delta * NANOSECONDS_IN_SECOND / frequency; + time::add_nanoseconds(dt); } LAST_TICK.store(now, Ordering::Release); diff --git a/kernel/src/arch/x86/mod.rs b/kernel/src/arch/x86/mod.rs index 60a3f25e..9e7e79df 100644 --- a/kernel/src/arch/x86/mod.rs +++ b/kernel/src/arch/x86/mod.rs @@ -23,7 +23,7 @@ use libk_mm::{ use peripherals::{i8253::I8253, ps2::PS2Controller, rtc::Rtc, serial::ComPort}; use ygg_driver_pci::PciBusManager; -use crate::fs::{Initrd, INITRD_DATA}; +use crate::fs::{INITRD_DATA, Initrd}; use super::L3; diff --git a/kernel/src/arch/x86/peripherals/i8253.rs b/kernel/src/arch/x86/peripherals/i8253.rs index 44659499..844d1a8b 100644 --- a/kernel/src/arch/x86/peripherals/i8253.rs +++ b/kernel/src/arch/x86/peripherals/i8253.rs @@ -5,11 +5,11 @@ use device_api::{ interrupt::{InterruptHandler, Irq, IrqVector}, }; use kernel_arch_x86::{ - intrinsics::{IoPort, IoPortAccess}, ISA_IRQ_OFFSET, + intrinsics::{IoPort, IoPortAccess}, }; use libk::{device::external_interrupt_controller, task::runtime, time}; -use libk_util::{sync::IrqSafeSpinlock, OneTimeInit}; +use libk_util::{OneTimeInit, sync::IrqSafeSpinlock}; const FREQUENCY: u32 = 1193180; diff --git a/kernel/src/arch/x86/peripherals/ps2/mod.rs b/kernel/src/arch/x86/peripherals/ps2/mod.rs index 05a907ee..8dd4d28b 100644 --- a/kernel/src/arch/x86/peripherals/ps2/mod.rs +++ b/kernel/src/arch/x86/peripherals/ps2/mod.rs @@ -9,8 +9,8 @@ use device_api::{ interrupt::{InterruptHandler, Irq, IrqVector}, }; use kernel_arch_x86::{ - intrinsics::{IoPort, IoPortAccess}, ISA_IRQ_OFFSET, + intrinsics::{IoPort, IoPortAccess}, }; use libk::device::external_interrupt_controller; use libk_util::sync::IrqSafeSpinlock; diff --git a/kernel/src/arch/x86/peripherals/rtc.rs b/kernel/src/arch/x86/peripherals/rtc.rs index d09290ff..5ce0788c 100644 --- a/kernel/src/arch/x86/peripherals/rtc.rs +++ b/kernel/src/arch/x86/peripherals/rtc.rs @@ -2,7 +2,7 @@ use abi::error::Error; use alloc::sync::Arc; use device_api::device::Device; use kernel_arch::{Architecture, ArchitectureImpl}; -use kernel_arch_x86::intrinsics::{io_wait, IoPort, IoPortAccess}; +use kernel_arch_x86::intrinsics::{IoPort, IoPortAccess, io_wait}; use libk::fs::sysfs::{self, nodes::SysfsRtcNode}; use libk_util::sync::IrqSafeSpinlock; diff --git a/kernel/src/arch/x86_64/apic/ioapic.rs b/kernel/src/arch/x86_64/apic/ioapic.rs index f54acf4c..80e6a176 100644 --- a/kernel/src/arch/x86_64/apic/ioapic.rs +++ b/kernel/src/arch/x86_64/apic/ioapic.rs @@ -11,7 +11,7 @@ use device_api::{ }; use kernel_arch_x86::ISA_IRQ_OFFSET; use libk_mm::{address::PhysicalAddress, device::DeviceMemoryIo}; -use libk_util::sync::{spin_rwlock::IrqSafeRwLock, IrqSafeSpinlock}; +use libk_util::sync::{IrqSafeSpinlock, spin_rwlock::IrqSafeRwLock}; use tock_registers::{ interfaces::{Readable, Writeable}, register_structs, diff --git a/kernel/src/arch/x86_64/apic/local.rs b/kernel/src/arch/x86_64/apic/local.rs index 90578d3d..d04b7196 100644 --- a/kernel/src/arch/x86_64/apic/local.rs +++ b/kernel/src/arch/x86_64/apic/local.rs @@ -11,12 +11,12 @@ use device_api::{ }, }; use kernel_arch_x86::registers::MSR_IA32_APIC_BASE; -use kernel_arch_x86_64::{mem::table::L3, LocalApicInterface, CPU_COUNT}; +use kernel_arch_x86_64::{CPU_COUNT, LocalApicInterface, mem::table::L3}; use libk::arch::Cpu; use libk_mm::{address::PhysicalAddress, device::DeviceMemoryIo, table::EntryLevelExt}; use libk_util::{ - sync::{spin_rwlock::IrqSafeRwLock, IrqGuard}, OneTimeInit, + sync::{IrqGuard, spin_rwlock::IrqSafeRwLock}, }; use tock_registers::{ interfaces::{ReadWriteable, Readable, Writeable}, diff --git a/kernel/src/arch/x86_64/apic/mod.rs b/kernel/src/arch/x86_64/apic/mod.rs index 42d05b84..9768bdee 100644 --- a/kernel/src/arch/x86_64/apic/mod.rs +++ b/kernel/src/arch/x86_64/apic/mod.rs @@ -46,7 +46,7 @@ const_assert_eq!(APIC_MSI_OFFSET + MAX_MSI_VECTORS, APIC_SPURIOUS_VECTOR); /// Fills the IDT with interrupt vectors for this APIC pub fn setup_vectors(idt: &mut [exception::Entry]) { - extern "C" { + unsafe extern "C" { // IRQ vectors static __x86_64_apic_vectors: [usize; 224]; } diff --git a/kernel/src/arch/x86_64/boot/mod.rs b/kernel/src/arch/x86_64/boot/mod.rs index 454b49dc..8e8c70cf 100644 --- a/kernel/src/arch/x86_64/boot/mod.rs +++ b/kernel/src/arch/x86_64/boot/mod.rs @@ -7,8 +7,8 @@ use kernel_arch_x86_64::CPU_COUNT; use libk_mm::address::{PhysicalAddress, Virtualize}; use tock_registers::interfaces::Writeable; use yboot_proto::{ + KERNEL_MAGIC, LOADER_MAGIC, LoadProtocolHeader, LoadProtocolV1, PROTOCOL_VERSION_1, v1::{FramebufferOption, MemoryMap}, - LoadProtocolHeader, LoadProtocolV1, KERNEL_MAGIC, LOADER_MAGIC, PROTOCOL_VERSION_1, }; use crate::{arch::PLATFORM, kernel_main, kernel_secondary_main, mem::KERNEL_VIRT_OFFSET}; @@ -67,7 +67,7 @@ static mut BSP_STACK: BootStack = BootStack { }; #[used] -#[link_section = ".data.yboot"] +#[unsafe(link_section = ".data.yboot")] static YBOOT_DATA: LoadProtocolV1 = LoadProtocolV1 { header: LoadProtocolHeader { kernel_magic: KERNEL_MAGIC, diff --git a/kernel/src/arch/x86_64/exception.rs b/kernel/src/arch/x86_64/exception.rs index 4035c067..36b90b53 100644 --- a/kernel/src/arch/x86_64/exception.rs +++ b/kernel/src/arch/x86_64/exception.rs @@ -9,7 +9,7 @@ use libk_mm::PageFaultKind; use libk_util::sync::spin_rwlock::IrqSafeRwLock; use tock_registers::interfaces::Readable; -use crate::arch::x86_64::{apic, X86_64}; +use crate::arch::x86_64::{X86_64, apic}; primitive_enum! { enum ExceptionKind: u64 { @@ -248,7 +248,7 @@ extern "C" fn __x86_64_nmi_handler() -> ! { pub unsafe fn init_exceptions(cpu_index: usize) { if cpu_index == 0 { let mut idt = IDT.write(); - extern "C" { + unsafe extern "C" { static __x86_64_exception_vectors: [usize; 32]; } diff --git a/kernel/src/arch/x86_64/mod.rs b/kernel/src/arch/x86_64/mod.rs index 37fa0b75..ee12bcef 100644 --- a/kernel/src/arch/x86_64/mod.rs +++ b/kernel/src/arch/x86_64/mod.rs @@ -3,7 +3,7 @@ use core::{ptr::null_mut, sync::atomic::Ordering}; use abi::error::Error; -use acpi::{mcfg::Mcfg, AcpiTables, HpetInfo, InterruptModel}; +use acpi::{AcpiTables, HpetInfo, InterruptModel, mcfg::Mcfg}; use alloc::sync::Arc; use device_api::{ device::Device, @@ -14,12 +14,12 @@ use kernel_arch_x86::{ cpuid::{self, CpuFeatures, EcxFeatures, EdxFeatures, ExtEdxFeatures}, gdt, }; -use kernel_arch_x86_64::{mem, LocalApicInterface, PerCpuData, CPU_COUNT}; +use kernel_arch_x86_64::{CPU_COUNT, LocalApicInterface, PerCpuData, mem}; use libk::{ arch::Cpu, config, debug, device::{ - display::{fb_console::FramebufferConsole, DriverFlags, PixelFormat}, + display::{DriverFlags, PixelFormat, fb_console::FramebufferConsole}, manager::DEVICE_REGISTRY, register_external_interrupt_controller, }, @@ -27,29 +27,29 @@ use libk::{ }; use libk_mm::{ address::PhysicalAddress, - phys::{self, reserved::reserve_region, PhysicalMemoryRegion}, + phys::{self, PhysicalMemoryRegion, reserved::reserve_region}, pointer::PhysicalRef, table::EntryLevel, }; use libk_util::{ - sync::{IrqGuard, SpinFence}, OneTimeInit, + sync::{IrqGuard, SpinFence}, }; use yboot_proto::{ - v1::{self, AvailableMemoryRegion}, LoadProtocolV1, + v1::{self, AvailableMemoryRegion}, }; use ygg_driver_acpi::{AcpiAllocator, AcpiHandlerImpl, EventAction, FixedEvent}; use ygg_driver_pci::PciBusManager; use crate::{ arch::{ - x86::{self, peripherals::hpet::Hpet, InitrdSource}, + Platform, + x86::{self, InitrdSource, peripherals::hpet::Hpet}, x86_64::{ apic::{ioapic::IoApic, local::LocalApic}, boot::BootData, }, - Platform, }, device::display::linear_fb::LinearFramebuffer, panic, @@ -220,10 +220,10 @@ impl X86_64 { let cmdline = self.boot_data.get().cmdline(); let mut early = x86::init_platform_early(cmdline)?; - if !config::get().x86.disable_boot_fb { - if let Err(error) = self.init_framebuffer() { - log::error!("Could not initialize boot framebuffer: {error:?}"); - } + if !config::get().x86.disable_boot_fb + && let Err(error) = self.init_framebuffer() + { + log::error!("Could not initialize boot framebuffer: {error:?}"); } if let Some(acpi) = self.acpi.try_get() { @@ -240,7 +240,7 @@ impl X86_64 { x86::init_platform_devices(early); - extern "C" { + unsafe extern "C" { static __kernel_start: u8; } @@ -383,10 +383,9 @@ impl X86_64 { // Switch fbconsole to the new framebuffer if let Some(fbconsole) = PLATFORM.fbconsole.try_get() && fbconsole.uses_boot_framebuffer() + && let Err(error) = fbconsole.set_display(device.clone()) { - if let Err(error) = fbconsole.set_display(device.clone()) { - log::error!("Couldn't set fb console display: {error:?}"); - } + log::error!("Couldn't set fb console display: {error:?}"); } // Switch /dev/fb0 to the new node diff --git a/kernel/src/arch/x86_64/smp.rs b/kernel/src/arch/x86_64/smp.rs index 6fffa07e..f417ff8f 100644 --- a/kernel/src/arch/x86_64/smp.rs +++ b/kernel/src/arch/x86_64/smp.rs @@ -4,18 +4,18 @@ use core::sync::atomic::Ordering; use ::acpi::platform::{ProcessorInfo, ProcessorState}; use kernel_arch::{Architecture, ArchitectureImpl}; use kernel_arch_x86_64::{ + CPU_COUNT, mem::{ auto_lower_address, fixed, flush_tlb_entry, - table::{PageAttributes, PageEntry, PageTable, L1, L2}, + table::{L1, L2, PageAttributes, PageEntry, PageTable}, }, - CPU_COUNT, }; use libk::arch::Cpu; use libk_mm::{ + TableAllocatorImpl, address::{AsPhysicalAddress, PhysicalAddress, Virtualize}, phys, pointer::PhysicalRefMut, - TableAllocatorImpl, }; use ygg_driver_acpi::AcpiAllocator; @@ -52,7 +52,7 @@ unsafe fn start_ap_core(apic_id: u32) { cr3, stack_base, stack_size, - entry: ap_entry as usize, + entry: (ap_entry as *const ()).addr(), }; let mut data_ref = PhysicalRefMut::::map(AP_BOOTSTRAP_DATA); diff --git a/kernel/src/arch/x86_64/syscall.rs b/kernel/src/arch/x86_64/syscall.rs index 26f34569..a1468e76 100644 --- a/kernel/src/arch/x86_64/syscall.rs +++ b/kernel/src/arch/x86_64/syscall.rs @@ -57,12 +57,12 @@ extern "C" fn __x86_64_syscall_handler(frame: *mut SyscallFrame) { /// /// Only meant to be called once per each CPU during their init. pub unsafe fn init_syscall() { - extern "C" { + unsafe extern "C" { fn __x86_64_syscall_vector(); } // Initialize syscall vector - MSR_IA32_LSTAR.set(__x86_64_syscall_vector as u64); + MSR_IA32_LSTAR.set((__x86_64_syscall_vector as *const ()).addr() as u64); MSR_IA32_SFMASK.write(MSR_IA32_SFMASK::IF::Masked + MSR_IA32_SFMASK::TF::Masked); MSR_IA32_STAR.write( // On sysret, CS = val + 16 (0x23), SS = val + 8 (0x1B) diff --git a/kernel/src/device/bus/pci_host_ecam_generic.rs b/kernel/src/device/bus/pci_host_ecam_generic.rs index bf458d43..af689fbd 100644 --- a/kernel/src/device/bus/pci_host_ecam_generic.rs +++ b/kernel/src/device/bus/pci_host_ecam_generic.rs @@ -3,18 +3,17 @@ use alloc::{collections::btree_map::BTreeMap, sync::Arc, vec::Vec}; use device_api::{device::Device, interrupt::Irq}; use device_tree::{ - driver::{ - device_tree_driver, - util::{pcie_interrupt_map, pcie_msi_map}, - Node, ProbeContext, - }, DeviceTreePropertyRead, + driver::{ + Node, ProbeContext, device_tree_driver, + util::{pcie_interrupt_map, pcie_msi_map}, + }, }; use libk_mm::address::PhysicalAddress; use ygg_driver_pci::{ + PciAddress, PciAddressRange, PciBusManager, PciRangeType, device::{PciInterrupt, PciInterruptPin, PciInterruptRoute}, interrupt::{PciFixedMsiMap, PciFixedMsiMapping, PciInterruptMap, PciMsiMap}, - PciAddress, PciAddressRange, PciBusManager, PciRangeType, }; #[derive(Debug)] diff --git a/kernel/src/device/bus/simple_bus.rs b/kernel/src/device/bus/simple_bus.rs index f2d7aff4..661d92ef 100644 --- a/kernel/src/device/bus/simple_bus.rs +++ b/kernel/src/device/bus/simple_bus.rs @@ -12,8 +12,8 @@ use device_api::{ device::{Device, DeviceInitContext}, }; use device_tree::{ - driver::{device_tree_driver, Node, ProbeContext}, DeviceTreePropertyRead, + driver::{Node, ProbeContext, device_tree_driver}, }; struct SimpleBus { diff --git a/kernel/src/device/clock/fixed.rs b/kernel/src/device/clock/fixed.rs index d6960dd6..d531e618 100644 --- a/kernel/src/device/clock/fixed.rs +++ b/kernel/src/device/clock/fixed.rs @@ -6,8 +6,8 @@ use device_api::{ device::{Device, DeviceInitContext}, }; use device_tree::{ - driver::{device_tree_driver, DeviceTreeClockController, Node, ProbeContext}, DeviceTreePropertyRead, TProp, + driver::{DeviceTreeClockController, Node, ProbeContext, device_tree_driver}, }; struct FixedClock { diff --git a/kernel/src/device/display/console.rs b/kernel/src/device/display/console.rs index e69de29b..8b137891 100644 --- a/kernel/src/device/display/console.rs +++ b/kernel/src/device/display/console.rs @@ -0,0 +1 @@ + diff --git a/kernel/src/device/display/linear_fb.rs b/kernel/src/device/display/linear_fb.rs index 0b761788..ebcb4860 100644 --- a/kernel/src/device/display/linear_fb.rs +++ b/kernel/src/device/display/linear_fb.rs @@ -8,10 +8,10 @@ use libk::device::display::{ DisplayDevice, DisplayMode, DisplayOwner, DriverFlags, FramebufferInfo, PixelFormat, }; use libk_mm::{ + OnDemandPage, PageProvider, VirtualPage, address::PhysicalAddress, device::{DeviceMemoryAttributes, DeviceMemoryCaching, RawDeviceMemoryMapping}, table::{EntryLevel, MapAttributes}, - OnDemandPage, PageProvider, VirtualPage, }; use libk_util::sync::IrqSafeSpinlock; diff --git a/kernel/src/device/gpio.rs b/kernel/src/device/gpio.rs index 0548f4ef..3d8a7b79 100644 --- a/kernel/src/device/gpio.rs +++ b/kernel/src/device/gpio.rs @@ -6,7 +6,7 @@ use device_api::{ device::{Device, DeviceInitContext}, gpio::{GpioInterrupt, GpioInterruptMode, GpioOutput, GpioPinLevel, PinHandle}, }; -use device_tree::driver::{device_tree_driver, DeviceTreeGpioPins, Node, ProbeContext}; +use device_tree::driver::{DeviceTreeGpioPins, Node, ProbeContext, device_tree_driver}; use libk::event::{self, GpioEvent}; enum LedFunction { @@ -95,6 +95,7 @@ impl Pin for LedPin { fn configure(self: &Arc) -> Result<(), Error> { self.handle.configure()?; + #[allow(clippy::single_match)] match self.function { LedFunction::Heartbeat => { log::info!("Register led {:?} as heartbeat indicator", self.name); diff --git a/kernel/src/device/power/arm_psci.rs b/kernel/src/device/power/arm_psci.rs index 130dfdbf..bf4c3eca 100644 --- a/kernel/src/device/power/arm_psci.rs +++ b/kernel/src/device/power/arm_psci.rs @@ -3,12 +3,12 @@ use abi::error::Error; use alloc::sync::Arc; use device_api::{ - device::{Device, DeviceInitContext}, CpuBringupDevice, ResetDevice, + device::{Device, DeviceInitContext}, }; use device_tree::{ - driver::{device_tree_driver, Node, ProbeContext}, DeviceTreePropertyRead, + driver::{Node, ProbeContext, device_tree_driver}, }; use kernel_arch::{Architecture, ArchitectureImpl}; @@ -76,7 +76,11 @@ impl Psci { x0 } - /// Shut down the system + /// Shut down the system. + /// + /// # Safety + /// + /// Unsafe: requires caller to perform all the necessary shutdown preparations. pub unsafe fn power_off(&self) -> Result { self.call(Self::SYSTEM_OFF as _, 0, 0, 0); unreachable!() diff --git a/kernel/src/device/serial/ns16550a.rs b/kernel/src/device/serial/ns16550a.rs index 2213fb54..6d3752c8 100644 --- a/kernel/src/device/serial/ns16550a.rs +++ b/kernel/src/device/serial/ns16550a.rs @@ -5,14 +5,14 @@ use device_api::{ device::{Device, DeviceInitContext}, interrupt::{InterruptHandler, IrqHandle, IrqVector}, }; -use device_tree::driver::{device_tree_driver, Node, ProbeContext}; +use device_tree::driver::{Node, ProbeContext, device_tree_driver}; use libk::{ debug::DebugSink, device::manager::DEVICE_REGISTRY, vfs::{Terminal, TerminalInput, TerminalOutput}, }; use libk_mm::{address::PhysicalAddress, device::DeviceMemoryIo}; -use libk_util::{sync::IrqSafeSpinlock, OneTimeInit}; +use libk_util::{OneTimeInit, sync::IrqSafeSpinlock}; use tock_registers::{ interfaces::{ReadWriteable, Readable, Writeable}, register_bitfields, register_structs, diff --git a/kernel/src/device/serial/snps_dw_apb_uart.rs b/kernel/src/device/serial/snps_dw_apb_uart.rs index 01a553bf..c19bf55c 100644 --- a/kernel/src/device/serial/snps_dw_apb_uart.rs +++ b/kernel/src/device/serial/snps_dw_apb_uart.rs @@ -6,14 +6,14 @@ use device_api::{ device::{Device, DeviceInitContext}, interrupt::{InterruptHandler, IrqHandle, IrqVector}, }; -use device_tree::driver::{device_tree_driver, Node, ProbeContext}; +use device_tree::driver::{Node, ProbeContext, device_tree_driver}; use libk::{ debug::{self, DebugSink}, device::manager::DEVICE_REGISTRY, vfs::{Terminal, TerminalInput, TerminalOutput}, }; use libk_mm::{address::PhysicalAddress, device::DeviceMemoryIo}; -use libk_util::{sync::IrqSafeSpinlock, OneTimeInit}; +use libk_util::{OneTimeInit, sync::IrqSafeSpinlock}; use tock_registers::{ interfaces::{ReadWriteable, Readable, Writeable}, register_bitfields, register_structs, diff --git a/kernel/src/device/timer.rs b/kernel/src/device/timer.rs index 26e54743..6a38fc1e 100644 --- a/kernel/src/device/timer.rs +++ b/kernel/src/device/timer.rs @@ -3,7 +3,7 @@ use core::time::Duration; use abi::{error::Error, time::SystemTime}; -use device_api::{timer::RealTimeProviderDevice, Device}; +use device_api::{Device, timer::RealTimeProviderDevice}; use libk_util::sync::spin_rwlock::IrqSafeRwLock; /// Centralized global time provider diff --git a/kernel/src/fs/mod.rs b/kernel/src/fs/mod.rs index 7ba5be20..325ccc80 100644 --- a/kernel/src/fs/mod.rs +++ b/kernel/src/fs/mod.rs @@ -8,7 +8,7 @@ use ext2::Ext2Fs; use libk::{ block, fs::{devfs, sysfs}, - vfs::{self, register_root, Filesystem, FilesystemMountOption, IoContext, NodeRef}, + vfs::{self, Filesystem, FilesystemMountOption, IoContext, NodeRef, register_root}, }; use libk_mm::{ address::{PhysicalAddress, Virtualize}, @@ -114,10 +114,8 @@ pub fn global_control(option: u32, buffer: &mut [u8], len: usize) -> Result(address: PhysicalAddress) -> T { let io = DeviceMemoryMapping::map(address, size_of::(), Default::default()).unwrap(); let address = io.address(); - if address % align_of::() == 0 { + if address.is_multiple_of(align_of::()) { (address as *const T).read_volatile() } else { (address as *const T).read_unaligned() @@ -37,29 +37,29 @@ pub unsafe fn write_memory(address: PhysicalAddress, value: T) { let io = DeviceMemoryMapping::map(address, size_of::(), Default::default()).unwrap(); let address = io.address(); - if address % align_of::() == 0 { + if address.is_multiple_of(align_of::()) { (address as *mut T).write_volatile(value) } else { (address as *mut T).write_unaligned(value) } } -#[no_mangle] +#[unsafe(no_mangle)] unsafe extern "C" fn memcpy(p0: *mut c_void, p1: *const c_void, len: usize) -> *mut c_void { compiler_builtins::mem::memcpy(p0 as _, p1 as _, len) as _ } -#[no_mangle] +#[unsafe(no_mangle)] unsafe extern "C" fn memcmp(p0: *const c_void, p1: *const c_void, len: usize) -> i32 { compiler_builtins::mem::memcmp(p0 as _, p1 as _, len) } -#[no_mangle] +#[unsafe(no_mangle)] unsafe extern "C" fn memmove(dst: *mut c_void, src: *const c_void, len: usize) -> *mut c_void { compiler_builtins::mem::memmove(dst as _, src as _, len) as _ } -#[no_mangle] +#[unsafe(no_mangle)] unsafe extern "C" fn memset(dst: *mut c_void, val: i32, len: usize) -> *mut c_void { compiler_builtins::mem::memset(dst as _, val, len) as _ } diff --git a/kernel/src/panic.rs b/kernel/src/panic.rs index 8a9ac073..e17e75a9 100644 --- a/kernel/src/panic.rs +++ b/kernel/src/panic.rs @@ -10,7 +10,7 @@ use libk::{ }; use libk_util::sync::SpinFence; -use crate::arch::{Platform, PLATFORM}; +use crate::arch::{PLATFORM, Platform}; static PANIC_HANDLED_FENCE: SpinFence = SpinFence::new(); diff --git a/kernel/src/syscall/imp/mod.rs b/kernel/src/syscall/imp/mod.rs index c668fb79..218fdc9d 100644 --- a/kernel/src/syscall/imp/mod.rs +++ b/kernel/src/syscall/imp/mod.rs @@ -27,7 +27,7 @@ use libk::{ use libk_mm::phys; use crate::{ - arch::{Platform, PLATFORM}, + arch::{PLATFORM, Platform}, fs, }; diff --git a/kernel/src/syscall/imp/sys_debug.rs b/kernel/src/syscall/imp/sys_debug.rs index 161f5635..c00fac3b 100644 --- a/kernel/src/syscall/imp/sys_debug.rs +++ b/kernel/src/syscall/imp/sys_debug.rs @@ -1,7 +1,7 @@ use abi::{debug::TraceLevel, error::Error}; use libk::{ debug, - task::{thread::Thread, ThreadId}, + task::{ThreadId, thread::Thread}, }; pub(crate) fn debug_trace(level: TraceLevel, message: &str) { diff --git a/kernel/src/syscall/imp/sys_process.rs b/kernel/src/syscall/imp/sys_process.rs index 2b66749c..e299fc1c 100644 --- a/kernel/src/syscall/imp/sys_process.rs +++ b/kernel/src/syscall/imp/sys_process.rs @@ -4,15 +4,15 @@ use abi::{ error::Error, mem::{MappingFlags, MappingSource}, process::{ - options::ProcessOptionVariant, thread::ThreadOptionVariant, ExitCode, MutexOperation, - ProcessGroupId, ProcessId, ProcessWait, Signal, SpawnFlags, SpawnOption, SpawnOptions, - ThreadEvent, ThreadSpawnOptions, WaitFlags, + ExitCode, MutexOperation, ProcessGroupId, ProcessId, ProcessWait, Signal, SpawnFlags, + SpawnOption, SpawnOptions, ThreadEvent, ThreadSpawnOptions, WaitFlags, + options::ProcessOptionVariant, thread::ThreadOptionVariant, }, }; use alloc::sync::Arc; use libk::{ block, - task::{binary::LoadOptions, process::Process, runtime, thread::Thread, ThreadId}, + task::{ThreadId, binary::LoadOptions, process::Process, runtime, thread::Thread}, time::monotonic_time, vfs::IoContext, }; @@ -90,7 +90,7 @@ pub(crate) fn spawn_process(options: &SpawnOptions<'_>) -> Result) -> Result &'static str { pub unsafe fn call_init_array() { type InitFn = extern "C" fn(); - extern "C" { + unsafe extern "C" { static __init_array_start: u8; static __init_array_end: u8; } diff --git a/lib/abi-serde/src/impls/alloc.rs b/lib/abi-serde/src/impls/alloc.rs index 67cf06b7..fcbb396c 100644 --- a/lib/abi-serde/src/impls/alloc.rs +++ b/lib/abi-serde/src/impls/alloc.rs @@ -1,6 +1,6 @@ use alloc::{boxed::Box, vec::Vec}; -use crate::{des::Deserializer, ser::Serializer, Deserialize, Serialize}; +use crate::{Deserialize, Serialize, des::Deserializer, ser::Serializer}; impl Serialize for Vec { fn serialize(&self, serializer: &mut S) -> Result<(), S::Error> { diff --git a/lib/abi-serde/src/impls/base.rs b/lib/abi-serde/src/impls/base.rs index 235ef5fe..06e8c256 100644 --- a/lib/abi-serde/src/impls/base.rs +++ b/lib/abi-serde/src/impls/base.rs @@ -1,9 +1,9 @@ use core::mem::MaybeUninit; use crate::{ + Deserialize, Serialize, des::{DeserializeError, Deserializer}, ser::Serializer, - Deserialize, Serialize, }; macro impl_primitive_serde($($ty:ty : [$read:ident, $write:ident]),+) { diff --git a/lib/abi-serde/src/impls/net.rs b/lib/abi-serde/src/impls/net.rs index 1ab47a4f..4a0e2b0b 100644 --- a/lib/abi-serde/src/impls/net.rs +++ b/lib/abi-serde/src/impls/net.rs @@ -1,9 +1,9 @@ use core::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6}; use crate::{ + Deserialize, Serialize, des::{DeserializeError, Deserializer}, ser::Serializer, - Deserialize, Serialize, }; impl<'de> Deserialize<'de> for Ipv4Addr { diff --git a/lib/abi-serde/src/impls/time.rs b/lib/abi-serde/src/impls/time.rs index 401d9330..784dfb2a 100644 --- a/lib/abi-serde/src/impls/time.rs +++ b/lib/abi-serde/src/impls/time.rs @@ -1,6 +1,6 @@ use core::time::Duration; -use crate::{des::Deserializer, ser::Serializer, Deserialize, Serialize}; +use crate::{Deserialize, Serialize, des::Deserializer, ser::Serializer}; impl<'de> Deserialize<'de> for Duration { fn deserialize>(deserializer: &mut D) -> Result { diff --git a/lib/abi-serde/src/lib.rs b/lib/abi-serde/src/lib.rs index f7e29490..074c45bb 100644 --- a/lib/abi-serde/src/lib.rs +++ b/lib/abi-serde/src/lib.rs @@ -1,4 +1,5 @@ #![feature(decl_macro, ip_from, maybe_uninit_array_assume_init)] +#![allow(stable_features)] #![no_std] #[cfg(not(feature = "rustc-dep-of-std"))] diff --git a/lib/abi-serde/src/test.rs b/lib/abi-serde/src/test.rs index d9deec65..8a4ca753 100644 --- a/lib/abi-serde/src/test.rs +++ b/lib/abi-serde/src/test.rs @@ -1,6 +1,6 @@ use core::fmt::Debug; -use crate::{wire, Deserialize, Serialize}; +use crate::{Deserialize, Serialize, wire}; #[track_caller] pub fn test_serialize_reversibility<'de, T: PartialEq + Serialize + Deserialize<'de> + Debug>( diff --git a/lib/abi-serde/src/wire.rs b/lib/abi-serde/src/wire.rs index c61b5467..0ce9a0fc 100644 --- a/lib/abi-serde/src/wire.rs +++ b/lib/abi-serde/src/wire.rs @@ -1,7 +1,7 @@ use crate::{ + Deserialize, Serialize, des::{DeserializeError, Deserializer}, ser::Serializer, - Deserialize, Serialize, }; #[derive(Debug)] diff --git a/lib/abi/build.rs b/lib/abi/build.rs index b6cd444c..063b7a06 100644 --- a/lib/abi/build.rs +++ b/lib/abi/build.rs @@ -1,9 +1,9 @@ use std::{env, fs, path::Path}; use abi_generator::{ - abi::{ty::TypeWidth, AbiBuilder}, - syntax::UnwrapFancy, TargetEnv, + abi::{AbiBuilder, ty::TypeWidth}, + syntax::UnwrapFancy, }; fn load_abi_definitions>(path: P) -> String { diff --git a/lib/abi/src/net/dns.rs b/lib/abi/src/net/dns.rs index f778b644..61be024b 100644 --- a/lib/abi/src/net/dns.rs +++ b/lib/abi/src/net/dns.rs @@ -1,4 +1,5 @@ //! DNS-related protocol structures +#![allow(unused)] use core::{ fmt, diff --git a/lib/abi/src/net/link.rs b/lib/abi/src/net/link.rs index ffd3c255..1b29be96 100644 --- a/lib/abi/src/net/link.rs +++ b/lib/abi/src/net/link.rs @@ -3,9 +3,9 @@ use core::fmt; use abi_serde::{ + Deserialize, Serialize, des::{DeserializeError, Deserializer}, ser::Serializer, - Deserialize, Serialize, }; use crate::primitive_enum; diff --git a/lib/abi/src/net/mod.rs b/lib/abi/src/net/mod.rs index 322cf79a..741ce87c 100644 --- a/lib/abi/src/net/mod.rs +++ b/lib/abi/src/net/mod.rs @@ -14,8 +14,8 @@ pub use crate::generated::{SocketShutdown, SocketType}; use crate::io::RawFd; pub use types::{ - subnet_addr::{SubnetAddr, SubnetV4Addr}, MacAddress, + subnet_addr::{SubnetAddr, SubnetV4Addr}, }; /// Message structure describing how data + metadata should be sent to the other side of some diff --git a/lib/abi/src/net/netconfig.rs b/lib/abi/src/net/netconfig.rs index 6461a32f..4f137d07 100644 --- a/lib/abi/src/net/netconfig.rs +++ b/lib/abi/src/net/netconfig.rs @@ -3,13 +3,13 @@ use core::net::IpAddr; use abi_serde::{ + Deserialize, Serialize, des::{DeserializeError, Deserializer}, ser::Serializer, - Deserialize, Serialize, }; use alloc::boxed::Box; -use super::{link::LinkState, MacAddress, SocketInterfaceQuery, SubnetAddr}; +use super::{MacAddress, SocketInterfaceQuery, SubnetAddr, link::LinkState}; /// Describes the binding between interfaces and their IDs #[derive(Clone, Debug, PartialEq)] diff --git a/lib/abi/src/net/protocols.rs b/lib/abi/src/net/protocols.rs index c8b9f57f..8fef3a07 100644 --- a/lib/abi/src/net/protocols.rs +++ b/lib/abi/src/net/protocols.rs @@ -1,14 +1,13 @@ // TODO don't really want to document this now -#![allow(missing_docs)] +#![allow(missing_docs, unused)] use core::{fmt, mem::size_of}; -use crate::bitflags; - use super::{ - types::{net_value::WrappedValue, NetValue, NetValueImpl}, MacAddress, + types::{NetValue, NetValueImpl, net_value::WrappedValue}, }; +use crate::bitflags; /////////// Layer 2 protocols //////////// @@ -219,6 +218,7 @@ impl InetChecksum { }; self.state = self.state.wrapping_add(word as u32); } + #[allow(clippy::manual_is_multiple_of)] if len % 2 != 0 { let word = if reorder { (bytes[len - 1] as u16) << 8 diff --git a/lib/abi/src/net/types/mod.rs b/lib/abi/src/net/types/mod.rs index 8e37e0b8..f75913d1 100644 --- a/lib/abi/src/net/types/mod.rs +++ b/lib/abi/src/net/types/mod.rs @@ -1,5 +1,7 @@ //! Various network types +#![allow(unused)] + use core::fmt; // pub mod ip_addr; diff --git a/lib/abi/src/option.rs b/lib/abi/src/option.rs index 9efd7135..bab50532 100644 --- a/lib/abi/src/option.rs +++ b/lib/abi/src/option.rs @@ -1,6 +1,6 @@ #![allow(missing_docs)] -use abi_serde::{wire, Deserialize, Serialize}; +use abi_serde::{Deserialize, Serialize, wire}; use crate::error::Error; diff --git a/lib/abi/src/process/exit.rs b/lib/abi/src/process/exit.rs index 4b2b493b..319237c0 100644 --- a/lib/abi/src/process/exit.rs +++ b/lib/abi/src/process/exit.rs @@ -2,9 +2,9 @@ use core::num::NonZeroI32; use abi_lib::SyscallRegister; use abi_serde::{ + Deserialize, Serialize, des::{DeserializeError, Deserializer}, ser::Serializer, - Deserialize, Serialize, }; use crate::debug::TraceEvent; diff --git a/lib/abi/src/process/mod.rs b/lib/abi/src/process/mod.rs index f04c1de8..99917eeb 100644 --- a/lib/abi/src/process/mod.rs +++ b/lib/abi/src/process/mod.rs @@ -13,9 +13,9 @@ pub use crate::generated::{ ThreadId, ThreadSpawnOptions, WaitFlags, }; use abi_serde::{ + Deserialize, Serialize, des::{DeserializeError, Deserializer}, ser::Serializer, - Deserialize, Serialize, }; pub use exit::{ExitCode, ThreadEvent}; diff --git a/lib/abi/src/time.rs b/lib/abi/src/time.rs index a1230247..ba2a9ac2 100644 --- a/lib/abi/src/time.rs +++ b/lib/abi/src/time.rs @@ -195,7 +195,7 @@ impl Sub for SystemTime { mod tests { use core::time::Duration; - use super::{SystemTime, NANOSECONDS_IN_SECOND}; + use super::{NANOSECONDS_IN_SECOND, SystemTime}; #[test] fn time_sub_time() { @@ -258,9 +258,10 @@ mod tests { .unwrap(), SystemTime::new(u64::MAX, NANOSECONDS_IN_SECOND - 1) ); - assert!(t1 - .checked_add_duration(&Duration::new(0, NANOSECONDS_IN_SECOND as u32 - 1)) - .is_none()); + assert!( + t1.checked_add_duration(&Duration::new(0, NANOSECONDS_IN_SECOND as u32 - 1)) + .is_none() + ); assert!(t1.checked_add_duration(&Duration::new(1, 0)).is_none()); } } diff --git a/lib/libyalloc/src/allocator.rs b/lib/libyalloc/src/allocator.rs index 8b74e52c..6c59dee8 100644 --- a/lib/libyalloc/src/allocator.rs +++ b/lib/libyalloc/src/allocator.rs @@ -9,7 +9,7 @@ use crate::{ struct BucketList where [u64; M / 64]: Sized, - Assert<{ M % 64 == 0 }>: IsTrue, + Assert<{ M.is_multiple_of(64) }>: IsTrue, { head: Option>>, } @@ -32,7 +32,7 @@ pub struct BucketAllocator { impl BucketList where [u64; M / 64]: Sized, - Assert<{ M % 64 == 0 }>: IsTrue, + Assert<{ M.is_multiple_of(64) }>: IsTrue, { const fn new() -> Self { Self { head: None } @@ -72,14 +72,17 @@ where node = bucket.next; } - panic!("Possible double free detected: pointer {:p} from bucket list {}x{}B, no corresponding bucket found", ptr, N, M); + panic!( + "Possible double free detected: pointer {:p} from bucket list {}x{}B, no corresponding bucket found", + ptr, N, M + ); } } impl Index for BucketList where [u64; M / 64]: Sized, - Assert<{ M % 64 == 0 }>: IsTrue, + Assert<{ M.is_multiple_of(64) }>: IsTrue, { type Output = Bucket; diff --git a/lib/libyalloc/src/bucket.rs b/lib/libyalloc/src/bucket.rs index 03898b3a..c83fa993 100644 --- a/lib/libyalloc/src/bucket.rs +++ b/lib/libyalloc/src/bucket.rs @@ -1,5 +1,5 @@ use core::{ - mem::{size_of, MaybeUninit}, + mem::{MaybeUninit, size_of}, ptr::NonNull, }; @@ -11,7 +11,7 @@ use crate::{ pub struct Bucket where [u64; M / 64]: Sized, - Assert<{ M % 64 == 0 }>: IsTrue, + Assert<{ M.is_multiple_of(64) }>: IsTrue, { pub(crate) data: NonNull, bitmap: [u64; M / 64], @@ -22,7 +22,7 @@ where impl Bucket where [u64; M / 64]: Sized, - Assert<{ M % 64 == 0 }>: IsTrue, + Assert<{ M.is_multiple_of(64) }>: IsTrue, { pub fn new() -> Option> { let data_page_count = (M * N).div_ceil(0x1000); diff --git a/lib/libyalloc/src/global.rs b/lib/libyalloc/src/global.rs index 6d71f245..411de36d 100644 --- a/lib/libyalloc/src/global.rs +++ b/lib/libyalloc/src/global.rs @@ -1,6 +1,6 @@ use core::{ alloc::{AllocError, Allocator, GlobalAlloc, Layout}, - ptr::{null_mut, NonNull}, + ptr::{NonNull, null_mut}, }; use crate::{allocator::BucketAllocator, sys::OsPageProvider, util::Spinlock}; diff --git a/lib/libyalloc/src/lib.rs b/lib/libyalloc/src/lib.rs index b945b2bc..fcb3f0e0 100644 --- a/lib/libyalloc/src/lib.rs +++ b/lib/libyalloc/src/lib.rs @@ -3,10 +3,16 @@ arbitrary_self_types, let_chains, test, - allocator_api + allocator_api, + unsigned_is_multiple_of )] #![cfg_attr(not(test), no_std)] -#![allow(incomplete_features, unexpected_cfgs, clippy::new_without_default)] +#![allow( + incomplete_features, + unexpected_cfgs, + clippy::new_without_default, + stable_features +)] #[cfg(test)] extern crate test; diff --git a/lib/qemu/src/aarch64.rs b/lib/qemu/src/aarch64.rs index 0e8e07b3..c4fa744d 100644 --- a/lib/qemu/src/aarch64.rs +++ b/lib/qemu/src/aarch64.rs @@ -84,7 +84,7 @@ impl Architecture for QemuAArch64 { #[cfg(test)] mod tests { - use crate::{aarch64::Machine, device::QemuSerialTarget, Qemu}; + use crate::{Qemu, aarch64::Machine, device::QemuSerialTarget}; use super::{Cpu, Image}; diff --git a/lib/qemu/src/lib.rs b/lib/qemu/src/lib.rs index 995f8f75..fd93ef97 100644 --- a/lib/qemu/src/lib.rs +++ b/lib/qemu/src/lib.rs @@ -1,5 +1,3 @@ -#![feature(let_chains)] - use std::{ fmt::Debug, path::{Path, PathBuf}, @@ -213,7 +211,7 @@ impl IntoArgs for Qemu { #[cfg(test)] mod tests { - use crate::{device::QemuSerialTarget, Qemu}; + use crate::{Qemu, device::QemuSerialTarget}; #[test] fn empty() { diff --git a/lib/runtime/build.rs b/lib/runtime/build.rs index c8bf3260..06ff24bc 100644 --- a/lib/runtime/build.rs +++ b/lib/runtime/build.rs @@ -1,9 +1,9 @@ use std::{env, fs, path::Path}; use abi_generator::{ - abi::{ty::TypeWidth, AbiBuilder}, - syntax::UnwrapFancy, TargetEnv, + abi::{AbiBuilder, ty::TypeWidth}, + syntax::UnwrapFancy, }; fn add_file<'a>(build: &'a mut cc::Build, name: &'a str) -> &'a mut cc::Build { diff --git a/lib/runtime/src/io/device.rs b/lib/runtime/src/io/device.rs index da70e98a..4a9adfaf 100644 --- a/lib/runtime/src/io/device.rs +++ b/lib/runtime/src/io/device.rs @@ -1,4 +1,4 @@ -pub use abi::io::{device::*, MountOptions, UnmountOptions}; +pub use abi::io::{MountOptions, UnmountOptions, device::*}; use abi::{error::Error, io::RawFd, option::RequestValue}; diff --git a/lib/runtime/src/io/mod.rs b/lib/runtime/src/io/mod.rs index 5bef99d7..59feb235 100644 --- a/lib/runtime/src/io/mod.rs +++ b/lib/runtime/src/io/mod.rs @@ -5,9 +5,9 @@ pub mod poll { } pub use abi::io::{ - options, AccessMode, DirectoryEntry, FileAttr, FileMetadataUpdate, FileMetadataUpdateMode, - FileMode, FileSync, FileTimesUpdate, FileType, OpenOptions, RawFd, RemoveFlags, Rename, - SeekFrom, TimerOptions, + AccessMode, DirectoryEntry, FileAttr, FileMetadataUpdate, FileMetadataUpdateMode, FileMode, + FileSync, FileTimesUpdate, FileType, OpenOptions, RawFd, RemoveFlags, Rename, SeekFrom, + TimerOptions, options, }; pub use abi::option::OptionSizeHint; diff --git a/lib/runtime/src/net/mod.rs b/lib/runtime/src/net/mod.rs index 040cec42..6bdc9672 100644 --- a/lib/runtime/src/net/mod.rs +++ b/lib/runtime/src/net/mod.rs @@ -5,7 +5,7 @@ pub mod dns; pub mod socket; -pub use abi::net::{options, MacAddress, SocketInterfaceQuery, SocketShutdown, SocketType}; +pub use abi::net::{MacAddress, SocketInterfaceQuery, SocketShutdown, SocketType, options}; pub use socket::{ bind_raw, bind_tcp, bind_udp, connect_tcp, connect_udp, get_socket_option, local_address, diff --git a/lib/runtime/src/net/socket.rs b/lib/runtime/src/net/socket.rs index 1d6fe184..bd2e78b1 100644 --- a/lib/runtime/src/net/socket.rs +++ b/lib/runtime/src/net/socket.rs @@ -4,7 +4,7 @@ use core::{net::SocketAddr, time::Duration}; use abi::{ error::Error, io::RawFd, - net::{options, MessageHeader, MessageHeaderMut, SocketInterfaceQuery, SocketType}, + net::{MessageHeader, MessageHeaderMut, SocketInterfaceQuery, SocketType, options}, option::{OptionSizeHint, OptionValue}, }; use abi_serde::wire; diff --git a/lib/runtime/src/process/mod.rs b/lib/runtime/src/process/mod.rs index 5ed78bcf..39a89db8 100644 --- a/lib/runtime/src/process/mod.rs +++ b/lib/runtime/src/process/mod.rs @@ -3,10 +3,10 @@ use core::{mem::MaybeUninit, time::Duration}; pub use abi::process::{ - auxv, AuxValue, AuxValueIter, ExecveOptions, ExitCode, MutexOperation, ProcessGroupId, - ProcessId, ProcessInfoElement, ProcessWait, ProgramArgumentInner, Signal, SignalEntryData, - SpawnFlags, SpawnOption, SpawnOptions, StringArgIter, ThreadEvent, ThreadId, - ThreadSpawnOptions, WaitFlags, + AuxValue, AuxValueIter, ExecveOptions, ExitCode, MutexOperation, ProcessGroupId, ProcessId, + ProcessInfoElement, ProcessWait, ProgramArgumentInner, Signal, SignalEntryData, SpawnFlags, + SpawnOption, SpawnOptions, StringArgIter, ThreadEvent, ThreadId, ThreadSpawnOptions, WaitFlags, + auxv, }; use abi::{ error::Error, diff --git a/lib/runtime/src/process/options.rs b/lib/runtime/src/process/options.rs index e69de29b..8b137891 100644 --- a/lib/runtime/src/process/options.rs +++ b/lib/runtime/src/process/options.rs @@ -0,0 +1 @@ + diff --git a/lib/runtime/src/process/signal.rs b/lib/runtime/src/process/signal.rs index a69b017d..b5f10349 100644 --- a/lib/runtime/src/process/signal.rs +++ b/lib/runtime/src/process/signal.rs @@ -153,7 +153,7 @@ pub fn setup_signal_full(size: usize) -> Result<(), Error> { let (base, size) = allocate_signal_stack(size)?; unsafe { set_signal_stack(base, size); - set_signal_entry(imp::signal_entry as usize); + set_signal_entry((imp::signal_entry as *const ()).addr()); } Ok(()) } diff --git a/lib/runtime/src/process/thread_local/mod.rs b/lib/runtime/src/process/thread_local/mod.rs index 595076d3..c362ccc5 100644 --- a/lib/runtime/src/process/thread_local/mod.rs +++ b/lib/runtime/src/process/thread_local/mod.rs @@ -1,14 +1,14 @@ //! Yggdrasil Runtime functions for handling Thread-Local Storage use core::{ ffi::c_void, - ptr::{null_mut, NonNull}, + ptr::{NonNull, null_mut}, }; use alloc::{boxed::Box, vec::Vec}; use abi::{ error::Error, - process::{auxv, AuxValue}, + process::{AuxValue, auxv}, }; #[cfg(any(target_arch = "aarch64", rust_analyzer))] diff --git a/lib/runtime/src/sys/mod.rs b/lib/runtime/src/sys/mod.rs index 92157d18..de604974 100644 --- a/lib/runtime/src/sys/mod.rs +++ b/lib/runtime/src/sys/mod.rs @@ -14,6 +14,7 @@ mod riscv64; mod generated { // Import all the necessary types from generated ABI use abi::{ + SyscallFunction, debug::TraceLevel, error::Error, io::{ @@ -27,7 +28,6 @@ mod generated { ExecveOptions, ProcessGroupId, ProcessId, Signal, SignalEntryData, SpawnOptions, ThreadSpawnOptions, WaitFlags, }, - SyscallFunction, }; include!(concat!(env!("OUT_DIR"), "/generated_calls.rs")); diff --git a/userspace/lib/ygglibc/etc/aarch64-unknown-none.json b/userspace/lib/ygglibc/etc/aarch64-unknown-none.json index 1cade7f4..c4bd387e 100644 --- a/userspace/lib/ygglibc/etc/aarch64-unknown-none.json +++ b/userspace/lib/ygglibc/etc/aarch64-unknown-none.json @@ -4,7 +4,7 @@ "llvm-target": "aarch64-unknown-none", "data-layout": "e-m:e-p270:32:32-p271:32:32-p272:64:64-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32", "max-atomic-width": 128, - "target-pointer-width": "64", + "target-pointer-width": 64, "features": "+v8a,+strict-align,+neon,+fp-armv8", "disable-redzone": true, diff --git a/userspace/lib/ygglibc/etc/riscv64-unknown-none.json b/userspace/lib/ygglibc/etc/riscv64-unknown-none.json index b339c659..0510c5ef 100644 --- a/userspace/lib/ygglibc/etc/riscv64-unknown-none.json +++ b/userspace/lib/ygglibc/etc/riscv64-unknown-none.json @@ -5,7 +5,7 @@ "llvm-target": "riscv64", "data-layout": "e-m:e-p:64:64-i64:64-i128:128-n32:64-S128", "max-atomic-width": 64, - "target-pointer-width": "64", + "target-pointer-width": 64, "features": "+m,+a,+f,+d,+c", "disable-redzone": true, diff --git a/userspace/lib/ygglibc/etc/x86_64-unknown-none.json b/userspace/lib/ygglibc/etc/x86_64-unknown-none.json index bc3c66dc..2ac50f7d 100644 --- a/userspace/lib/ygglibc/etc/x86_64-unknown-none.json +++ b/userspace/lib/ygglibc/etc/x86_64-unknown-none.json @@ -5,7 +5,7 @@ "llvm-target": "x86_64-unknown-linux-gnu", "data-layout": "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128", "max-atomic-width": 64, - "target-pointer-width": "64", + "target-pointer-width": 64, "features": "+sse,-soft-float", "disable-redzone": true, diff --git a/userspace/lib/ygglibc/src/allocator.rs b/userspace/lib/ygglibc/src/allocator.rs index 4f92966a..c7ddd41b 100644 --- a/userspace/lib/ygglibc/src/allocator.rs +++ b/userspace/lib/ygglibc/src/allocator.rs @@ -1,7 +1,7 @@ use core::{ alloc::{GlobalAlloc, Layout}, ffi::c_void, - ptr::{self, null_mut, NonNull}, + ptr::{self, NonNull, null_mut}, }; use libyalloc::{allocator::BucketAllocator, sys::PageProvider}; diff --git a/userspace/lib/ygglibc/src/env.rs b/userspace/lib/ygglibc/src/env.rs index 5e3c4cdf..18682186 100644 --- a/userspace/lib/ygglibc/src/env.rs +++ b/userspace/lib/ygglibc/src/env.rs @@ -1,8 +1,8 @@ #![allow(non_upper_case_globals, static_mut_refs)] use core::{ - ffi::{c_char, CStr}, - ptr::{null_mut, NonNull}, + ffi::{CStr, c_char}, + ptr::{NonNull, null_mut}, slice::memchr, }; diff --git a/userspace/lib/ygglibc/src/error.rs b/userspace/lib/ygglibc/src/error.rs index bb70d7b6..6ef4cc5e 100644 --- a/userspace/lib/ygglibc/src/error.rs +++ b/userspace/lib/ygglibc/src/error.rs @@ -2,7 +2,7 @@ use core::{ convert::Infallible, ffi::c_int, ops::{ControlFlow, FromResidual, Try}, - ptr::{null_mut, NonNull}, + ptr::{NonNull, null_mut}, }; use yggdrasil_rt::io::RawFd; diff --git a/userspace/lib/ygglibc/src/headers/dirent/mod.rs b/userspace/lib/ygglibc/src/headers/dirent/mod.rs index 3d0a1dd8..0de243ca 100644 --- a/userspace/lib/ygglibc/src/headers/dirent/mod.rs +++ b/userspace/lib/ygglibc/src/headers/dirent/mod.rs @@ -9,7 +9,7 @@ use yggdrasil_rt::io::{DirectoryEntry, RawFd}; use crate::{ error::{CIntZeroResult, CPtrResult, EResult, TryFromExt}, - io::{dir::DirReader, FromRawFd}, + io::{FromRawFd, dir::DirReader}, util::{PointerExt, PointerStrExt}, }; diff --git a/userspace/lib/ygglibc/src/headers/fcntl/mod.rs b/userspace/lib/ygglibc/src/headers/fcntl/mod.rs index 8ec059a0..27d90f52 100644 --- a/userspace/lib/ygglibc/src/headers/fcntl/mod.rs +++ b/userspace/lib/ygglibc/src/headers/fcntl/mod.rs @@ -1,10 +1,10 @@ -use core::ffi::{c_char, c_int, c_short, VaList}; +use core::ffi::{VaList, c_char, c_int, c_short}; use yggdrasil_rt::io::{FileMode, OpenOptions}; use crate::{ error::{CFdResult, CIntCountResult, EResult, TryFromExt}, - io::{raw::RawFile, IntoRawFd}, + io::{IntoRawFd, raw::RawFile}, util::{self, PointerStrExt}, }; @@ -170,8 +170,8 @@ unsafe extern "C" fn creat(pathname: *const c_char, mode: mode_t) -> CFdResult { } #[no_mangle] -unsafe extern "C" fn open(pathname: *const c_char, opts: c_int, mut args: ...) -> CFdResult { - vopenat(AT_FDCWD, pathname, opts, args.as_va_list()) +unsafe extern "C" fn open(pathname: *const c_char, opts: c_int, args: ...) -> CFdResult { + vopenat(AT_FDCWD, pathname, opts, args) } #[no_mangle] @@ -179,9 +179,9 @@ unsafe extern "C" fn openat( atfd: c_int, pathname: *const c_char, opts: c_int, - mut args: ... + args: ... ) -> CFdResult { - vopenat(atfd, pathname, opts, args.as_va_list()) + vopenat(atfd, pathname, opts, args) } #[no_mangle] diff --git a/userspace/lib/ygglibc/src/headers/netinet_in/mod.rs b/userspace/lib/ygglibc/src/headers/netinet_in/mod.rs index ff375a0e..8a071959 100644 --- a/userspace/lib/ygglibc/src/headers/netinet_in/mod.rs +++ b/userspace/lib/ygglibc/src/headers/netinet_in/mod.rs @@ -9,7 +9,7 @@ use crate::{ util::PointerExt, }; -use super::sys_socket::{sa_family_t, socklen_t, SocketAddrExt, SOL_SOCKOPT_IPV6, SOL_SOCKOPT_TCP}; +use super::sys_socket::{SOL_SOCKOPT_IPV6, SOL_SOCKOPT_TCP, SocketAddrExt, sa_family_t, socklen_t}; pub type in_port_t = u16; pub type in_addr_t = u32; diff --git a/userspace/lib/ygglibc/src/headers/pthread/attr.rs b/userspace/lib/ygglibc/src/headers/pthread/attr.rs index 16c868a0..d7a24c6c 100644 --- a/userspace/lib/ygglibc/src/headers/pthread/attr.rs +++ b/userspace/lib/ygglibc/src/headers/pthread/attr.rs @@ -1,6 +1,6 @@ use core::{ ffi::{c_int, c_void}, - ptr::{null_mut, NonNull}, + ptr::{NonNull, null_mut}, }; use crate::{ diff --git a/userspace/lib/ygglibc/src/headers/signal/mod.rs b/userspace/lib/ygglibc/src/headers/signal/mod.rs index 792d76cb..27c87e69 100644 --- a/userspace/lib/ygglibc/src/headers/signal/mod.rs +++ b/userspace/lib/ygglibc/src/headers/signal/mod.rs @@ -1,9 +1,9 @@ use core::{ - ffi::{c_char, c_int, c_long, c_void, CStr}, + ffi::{CStr, c_char, c_int, c_long, c_void}, ptr::NonNull, }; -use yggdrasil_rt::process::{signal as rt, Signal}; +use yggdrasil_rt::process::{Signal, signal as rt}; use crate::{ error::{self, CIntZeroResult, CResult, EResult}, @@ -315,11 +315,7 @@ unsafe extern "C" fn sigismember(mask: *const sigset_t, signum: c_int) -> c_int return -1; } let mask = *mask.ensure(); - if mask & (1 << signum) != 0 { - 1 - } else { - 0 - } + if mask & (1 << signum) != 0 { 1 } else { 0 } } #[no_mangle] diff --git a/userspace/lib/ygglibc/src/headers/stdio/file.rs b/userspace/lib/ygglibc/src/headers/stdio/file.rs index 50699b36..2b2467ee 100644 --- a/userspace/lib/ygglibc/src/headers/stdio/file.rs +++ b/userspace/lib/ygglibc/src/headers/stdio/file.rs @@ -1,6 +1,6 @@ use core::{ ffi::{c_char, c_int, c_long, c_void}, - ptr::{null_mut, NonNull}, + ptr::{NonNull, null_mut}, }; use alloc::boxed::Box; @@ -16,14 +16,13 @@ use crate::{ }, headers::{errno::Errno, sys_types::off_t}, io::{ - self, - managed::{FileOpenSource, FILE}, - Seek, Write, + self, Seek, Write, + managed::{FILE, FileOpenSource}, }, util::{PointerExt, PointerStrExt}, }; -use super::{fpos_t, SEEK_SET, _IOFBF, _IOLBF, _IONBF}; +use super::{_IOFBF, _IOLBF, _IONBF, SEEK_SET, fpos_t}; fn open_inner(source: O, mode_str: &[u8]) -> EResult> { let opts = match mode_str { @@ -185,11 +184,7 @@ unsafe extern "C" fn ftello(fp: *mut FILE) -> COffsetResult { #[no_mangle] unsafe extern "C" fn ftrylockfile(fp: *mut FILE) -> c_int { let fp = fp.ensure_mut(); - if fp.try_lock() { - 0 - } else { - -1 - } + if fp.try_lock() { 0 } else { -1 } } #[no_mangle] diff --git a/userspace/lib/ygglibc/src/headers/stdio/get_put.rs b/userspace/lib/ygglibc/src/headers/stdio/get_put.rs index fc321c9a..e4629322 100644 --- a/userspace/lib/ygglibc/src/headers/stdio/get_put.rs +++ b/userspace/lib/ygglibc/src/headers/stdio/get_put.rs @@ -2,7 +2,7 @@ use core::{ ffi::{c_char, c_int}, - ptr::{null_mut, NonNull}, + ptr::{NonNull, null_mut}, }; use crate::{ @@ -10,8 +10,8 @@ use crate::{ error::{CEofResult, CIsizeResult, CPtrResult, CResult, EResult}, headers::errno::Errno, io::{ - managed::{stdin, stdout, FILE}, Read, Write, + managed::{FILE, stdin, stdout}, }, util::{PointerExt, PointerStrExt}, }; diff --git a/userspace/lib/ygglibc/src/headers/stdio/io.rs b/userspace/lib/ygglibc/src/headers/stdio/io.rs index da82b1be..e2300129 100644 --- a/userspace/lib/ygglibc/src/headers/stdio/io.rs +++ b/userspace/lib/ygglibc/src/headers/stdio/io.rs @@ -2,7 +2,7 @@ use core::ffi::c_void; use crate::{ error::CUsizeResult, - io::{managed::FILE, Read, Write}, + io::{Read, Write, managed::FILE}, util::PointerExt, }; diff --git a/userspace/lib/ygglibc/src/headers/stdio/printf/float.rs b/userspace/lib/ygglibc/src/headers/stdio/printf/float.rs index aa4c0166..b0bc0b67 100644 --- a/userspace/lib/ygglibc/src/headers/stdio/printf/float.rs +++ b/userspace/lib/ygglibc/src/headers/stdio/printf/float.rs @@ -7,11 +7,7 @@ use crate::{error::EResult, headers::errno::Errno, io::Write}; use super::format::FmtOpts; fn abs(f: c_double) -> c_double { - if f.is_sign_negative() { - -f - } else { - f - } + if f.is_sign_negative() { -f } else { f } } fn float_exp(mut val: c_double) -> (c_double, isize) { diff --git a/userspace/lib/ygglibc/src/headers/stdio/printf/format.rs b/userspace/lib/ygglibc/src/headers/stdio/printf/format.rs index a1ce9f14..35d4abc4 100644 --- a/userspace/lib/ygglibc/src/headers/stdio/printf/format.rs +++ b/userspace/lib/ygglibc/src/headers/stdio/printf/format.rs @@ -1,6 +1,6 @@ use core::{ ffi::{ - c_char, c_double, c_int, c_long, c_longlong, c_uint, c_ulong, c_ulonglong, CStr, VaList, + CStr, VaList, c_char, c_double, c_int, c_long, c_longlong, c_uint, c_ulong, c_ulonglong, }, fmt, }; diff --git a/userspace/lib/ygglibc/src/headers/stdio/printf/mod.rs b/userspace/lib/ygglibc/src/headers/stdio/printf/mod.rs index 81ad9d2a..6e2c0304 100644 --- a/userspace/lib/ygglibc/src/headers/stdio/printf/mod.rs +++ b/userspace/lib/ygglibc/src/headers/stdio/printf/mod.rs @@ -1,5 +1,5 @@ use core::{ - ffi::{c_char, c_int, VaList}, + ffi::{VaList, c_char, c_int}, ptr::NonNull, }; @@ -9,7 +9,7 @@ use writer::{AllocatedStringWriter, FileWriter, FmtWriter, StringWriter}; use crate::{ error::{CIntCountResult, EResult, TryFromExt}, io::{ - managed::{stdout, FILE}, + managed::{FILE, stdout}, raw::RawFile, }, util::{PointerExt, PointerStrExt}, @@ -124,9 +124,9 @@ fn printf_inner(output: &mut W, format: &[u8], mut ap: VaList) -> unsafe extern "C" fn asprintf( dst: *mut *mut c_char, fmt: *const c_char, - mut args: ... + args: ... ) -> CIntCountResult { - vasprintf(dst, fmt, args.as_va_list()) + vasprintf(dst, fmt, args) } #[no_mangle] @@ -149,8 +149,8 @@ unsafe extern "C" fn vasprintf( } #[no_mangle] -unsafe extern "C" fn dprintf(fd: c_int, fmt: *const c_char, mut args: ...) -> CIntCountResult { - vdprintf(fd, fmt, args.as_va_list()) +unsafe extern "C" fn dprintf(fd: c_int, fmt: *const c_char, args: ...) -> CIntCountResult { + vdprintf(fd, fmt, args) } #[no_mangle] @@ -163,8 +163,8 @@ unsafe extern "C" fn vdprintf(fd: c_int, fmt: *const c_char, args: VaList) -> CI } #[no_mangle] -unsafe extern "C" fn printf(fmt: *const c_char, mut args: ...) -> CIntCountResult { - vfprintf(stdout, fmt, args.as_va_list()) +unsafe extern "C" fn printf(fmt: *const c_char, args: ...) -> CIntCountResult { + vfprintf(stdout, fmt, args) } #[no_mangle] @@ -173,8 +173,8 @@ unsafe extern "C" fn vprintf(fmt: *const c_char, args: VaList) -> CIntCountResul } #[no_mangle] -unsafe extern "C" fn fprintf(fp: *mut FILE, fmt: *const c_char, mut args: ...) -> CIntCountResult { - vfprintf(fp, fmt, args.as_va_list()) +unsafe extern "C" fn fprintf(fp: *mut FILE, fmt: *const c_char, args: ...) -> CIntCountResult { + vfprintf(fp, fmt, args) } #[no_mangle] @@ -190,9 +190,9 @@ unsafe extern "C" fn vfprintf(fp: *mut FILE, fmt: *const c_char, args: VaList) - unsafe extern "C" fn sprintf( buffer: *mut c_char, fmt: *const c_char, - mut args: ... + args: ... ) -> CIntCountResult { - vsnprintf(buffer, usize::MAX, fmt, args.as_va_list()) + vsnprintf(buffer, usize::MAX, fmt, args) } #[no_mangle] @@ -200,9 +200,9 @@ unsafe extern "C" fn snprintf( buffer: *mut c_char, capacity: usize, fmt: *const c_char, - mut args: ... + args: ... ) -> CIntCountResult { - vsnprintf(buffer, capacity, fmt, args.as_va_list()) + vsnprintf(buffer, capacity, fmt, args) } #[no_mangle] diff --git a/userspace/lib/ygglibc/src/headers/stdio/scanf/format.rs b/userspace/lib/ygglibc/src/headers/stdio/scanf/format.rs index 1ca7a69a..d52c120f 100644 --- a/userspace/lib/ygglibc/src/headers/stdio/scanf/format.rs +++ b/userspace/lib/ygglibc/src/headers/stdio/scanf/format.rs @@ -1,12 +1,12 @@ use core::ffi::{ - c_char, c_int, c_long, c_longlong, c_short, c_uchar, c_uint, c_ulong, c_ulonglong, c_ushort, - c_void, VaList, + VaList, c_char, c_int, c_long, c_longlong, c_short, c_uchar, c_uint, c_ulong, c_ulonglong, + c_ushort, c_void, }; use super::{ + ConversionError, char_set::ScanCharSet, reader::{GetChar, ScanReader}, - ConversionError, }; pub enum ScanRadix { diff --git a/userspace/lib/ygglibc/src/headers/stdio/scanf/mod.rs b/userspace/lib/ygglibc/src/headers/stdio/scanf/mod.rs index 27b796ad..76878e40 100644 --- a/userspace/lib/ygglibc/src/headers/stdio/scanf/mod.rs +++ b/userspace/lib/ygglibc/src/headers/stdio/scanf/mod.rs @@ -1,4 +1,4 @@ -use core::ffi::{c_char, VaList}; +use core::ffi::{VaList, c_char}; use char_set::ScanCharSet; use format::{ScanOpt, ScanRadix, ScanSize, ScanSpec}; @@ -7,7 +7,7 @@ use reader::{GetChar, ScanReader}; use crate::{ error::{CEofResult, EResult}, headers::errno::Errno, - io::managed::{stdin, FILE}, + io::managed::{FILE, stdin}, util::{PointerExt, PointerStrExt}, }; @@ -153,13 +153,13 @@ fn scanf_inner( } #[no_mangle] -unsafe extern "C" fn scanf(format: *const c_char, mut args: ...) -> CEofResult { - vfscanf(stdin, format, args.as_va_list()) +unsafe extern "C" fn scanf(format: *const c_char, args: ...) -> CEofResult { + vfscanf(stdin, format, args) } #[no_mangle] -unsafe extern "C" fn fscanf(fp: *mut FILE, format: *const c_char, mut args: ...) -> CEofResult { - vfscanf(fp, format, args.as_va_list()) +unsafe extern "C" fn fscanf(fp: *mut FILE, format: *const c_char, args: ...) -> CEofResult { + vfscanf(fp, format, args) } #[no_mangle] @@ -177,12 +177,8 @@ unsafe extern "C" fn vfscanf(fp: *mut FILE, format: *const c_char, args: VaList) } #[no_mangle] -unsafe extern "C" fn sscanf( - input: *const c_char, - format: *const c_char, - mut args: ... -) -> CEofResult { - vsscanf(input, format, args.as_va_list()) +unsafe extern "C" fn sscanf(input: *const c_char, format: *const c_char, args: ...) -> CEofResult { + vsscanf(input, format, args) } #[no_mangle] diff --git a/userspace/lib/ygglibc/src/headers/stdio/scanf/reader.rs b/userspace/lib/ygglibc/src/headers/stdio/scanf/reader.rs index c7f7170b..d20519c2 100644 --- a/userspace/lib/ygglibc/src/headers/stdio/scanf/reader.rs +++ b/userspace/lib/ygglibc/src/headers/stdio/scanf/reader.rs @@ -1,6 +1,6 @@ use crate::{ error::EResult, - io::{managed::FILE, Read}, + io::{Read, managed::FILE}, }; pub trait GetChar { diff --git a/userspace/lib/ygglibc/src/headers/stdio/util.rs b/userspace/lib/ygglibc/src/headers/stdio/util.rs index f146d74f..8a8bc19f 100644 --- a/userspace/lib/ygglibc/src/headers/stdio/util.rs +++ b/userspace/lib/ygglibc/src/headers/stdio/util.rs @@ -8,7 +8,7 @@ use yggdrasil_rt::{ use crate::{ error::{self, CIntZeroResult, CPtrResult, ResultExt}, headers::{errno::Errno, fcntl::AT_FDCWD}, - io::managed::{stderr, FILE}, + io::managed::{FILE, stderr}, util::{self, PointerExt, PointerStrExt}, }; diff --git a/userspace/lib/ygglibc/src/headers/stdlib/conv.rs b/userspace/lib/ygglibc/src/headers/stdlib/conv.rs index 2c187c6c..c428a278 100644 --- a/userspace/lib/ygglibc/src/headers/stdlib/conv.rs +++ b/userspace/lib/ygglibc/src/headers/stdlib/conv.rs @@ -1,6 +1,6 @@ use core::{ ffi::{c_char, c_double, c_float, c_int, c_long, c_longlong, c_ulong, c_ulonglong}, - ptr::{null_mut, NonNull}, + ptr::{NonNull, null_mut}, }; use crate::{headers::locale::locale_t, util::cstr_matches_insensitive}; diff --git a/userspace/lib/ygglibc/src/headers/string/str.rs b/userspace/lib/ygglibc/src/headers/string/str.rs index 2e124197..9ff21319 100644 --- a/userspace/lib/ygglibc/src/headers/string/str.rs +++ b/userspace/lib/ygglibc/src/headers/string/str.rs @@ -1,7 +1,7 @@ use core::{ cmp::Ordering, ffi::{c_char, c_int}, - ptr::{null_mut, NonNull}, + ptr::{NonNull, null_mut}, }; use crate::{ diff --git a/userspace/lib/ygglibc/src/headers/sys_socket/io.rs b/userspace/lib/ygglibc/src/headers/sys_socket/io.rs index 5cf824a5..d29b9c28 100644 --- a/userspace/lib/ygglibc/src/headers/sys_socket/io.rs +++ b/userspace/lib/ygglibc/src/headers/sys_socket/io.rs @@ -16,7 +16,7 @@ use crate::{ util::PointerExt, }; -use super::{msghdr, sockaddr, socklen_t, SocketAddrExt}; +use super::{SocketAddrExt, msghdr, sockaddr, socklen_t}; #[no_mangle] unsafe extern "C" fn recv( diff --git a/userspace/lib/ygglibc/src/headers/sys_socket/socket.rs b/userspace/lib/ygglibc/src/headers/sys_socket/socket.rs index b30fb95e..cdeaebe4 100644 --- a/userspace/lib/ygglibc/src/headers/sys_socket/socket.rs +++ b/userspace/lib/ygglibc/src/headers/sys_socket/socket.rs @@ -8,7 +8,7 @@ use crate::{ headers::{ errno::Errno, sys_socket::{ - SocketAddrExt, AF_INET, SHUT_RD, SHUT_RDWR, SHUT_WR, SOCK_DGRAM, SOCK_STREAM, + AF_INET, SHUT_RD, SHUT_RDWR, SHUT_WR, SOCK_DGRAM, SOCK_STREAM, SocketAddrExt, }, }, }; diff --git a/userspace/lib/ygglibc/src/headers/sys_stat/mod.rs b/userspace/lib/ygglibc/src/headers/sys_stat/mod.rs index e195f665..69ef992f 100644 --- a/userspace/lib/ygglibc/src/headers/sys_stat/mod.rs +++ b/userspace/lib/ygglibc/src/headers/sys_stat/mod.rs @@ -1,6 +1,6 @@ use core::{ ffi::{c_char, c_int}, - ptr::{null, NonNull}, + ptr::{NonNull, null}, }; use yggdrasil_rt::io::{ diff --git a/userspace/lib/ygglibc/src/headers/sys_yggdrasil/mod.rs b/userspace/lib/ygglibc/src/headers/sys_yggdrasil/mod.rs index 3461e734..c0fd457d 100644 --- a/userspace/lib/ygglibc/src/headers/sys_yggdrasil/mod.rs +++ b/userspace/lib/ygglibc/src/headers/sys_yggdrasil/mod.rs @@ -1,4 +1,4 @@ -use core::ffi::{c_char, CStr}; +use core::ffi::{CStr, c_char}; #[no_mangle] unsafe extern "C" fn ygg_panic(message: *const c_char) -> ! { diff --git a/userspace/lib/ygglibc/src/headers/time/convert.rs b/userspace/lib/ygglibc/src/headers/time/convert.rs index b7b95eea..89fb88eb 100644 --- a/userspace/lib/ygglibc/src/headers/time/convert.rs +++ b/userspace/lib/ygglibc/src/headers/time/convert.rs @@ -4,7 +4,7 @@ use chrono::Utc; use crate::headers::{sys_types::time_t, time::tm}; -use super::{get_timezone, CDateTime}; +use super::{CDateTime, get_timezone}; #[allow(static_mut_refs)] #[no_mangle] diff --git a/userspace/lib/ygglibc/src/headers/time/string.rs b/userspace/lib/ygglibc/src/headers/time/string.rs index 88178083..93cd9cf3 100644 --- a/userspace/lib/ygglibc/src/headers/time/string.rs +++ b/userspace/lib/ygglibc/src/headers/time/string.rs @@ -1,6 +1,6 @@ use core::{ ffi::c_char, - ptr::{null_mut, NonNull}, + ptr::{NonNull, null_mut}, }; use chrono::{Datelike, TimeZone, Timelike, Utc}; @@ -10,7 +10,7 @@ use crate::{ util::CStringWriter, }; -use super::{get_timezone, tm, CDateTime}; +use super::{CDateTime, get_timezone, tm}; unsafe fn fmt_time( t: &T, diff --git a/userspace/lib/ygglibc/src/headers/unistd/exec.rs b/userspace/lib/ygglibc/src/headers/unistd/exec.rs index 383243ff..eb8507a2 100644 --- a/userspace/lib/ygglibc/src/headers/unistd/exec.rs +++ b/userspace/lib/ygglibc/src/headers/unistd/exec.rs @@ -1,4 +1,4 @@ -use core::ffi::{c_char, c_int, va_list, VaList}; +use core::ffi::{VaList, c_char, c_int, va_list}; use crate::error::CIntZeroResult; diff --git a/userspace/lib/ygglibc/src/headers/unistd/fs.rs b/userspace/lib/ygglibc/src/headers/unistd/fs.rs index cde3cda0..894b2912 100644 --- a/userspace/lib/ygglibc/src/headers/unistd/fs.rs +++ b/userspace/lib/ygglibc/src/headers/unistd/fs.rs @@ -1,6 +1,6 @@ use core::{ ffi::{c_char, c_int, c_long}, - ptr::{null_mut, NonNull}, + ptr::{NonNull, null_mut}, }; use yggdrasil_rt::{ @@ -15,7 +15,7 @@ use crate::{ fcntl::{AT_FDCWD, AT_REMOVEDIR}, sys_types::{gid_t, off_t, uid_t}, }, - io::{self, raw::RawFile, FromRawFd}, + io::{self, FromRawFd, raw::RawFile}, util::{self, PointerExt, PointerStrExt}, }; diff --git a/userspace/lib/ygglibc/src/headers/unistd/io.rs b/userspace/lib/ygglibc/src/headers/unistd/io.rs index 7a04e450..89a0af01 100644 --- a/userspace/lib/ygglibc/src/headers/unistd/io.rs +++ b/userspace/lib/ygglibc/src/headers/unistd/io.rs @@ -11,7 +11,7 @@ use crate::{ errno::Errno, sys_types::{off_t, pid_t}, }, - io::{self, raw::RawFile, IntoRawFd, Read, ReadAt, Seek, Write, WriteAt}, + io::{self, IntoRawFd, Read, ReadAt, Seek, Write, WriteAt, raw::RawFile}, util::PointerExt, }; diff --git a/userspace/lib/ygglibc/src/headers/unistd/util.rs b/userspace/lib/ygglibc/src/headers/unistd/util.rs index 6cdb2f8e..580750aa 100644 --- a/userspace/lib/ygglibc/src/headers/unistd/util.rs +++ b/userspace/lib/ygglibc/src/headers/unistd/util.rs @@ -1,4 +1,4 @@ -use core::ffi::{c_char, c_int, c_long, c_uint, c_void, CStr}; +use core::ffi::{CStr, c_char, c_int, c_long, c_uint, c_void}; use crate::{ env::get_env, diff --git a/userspace/lib/ygglibc/src/headers/wchar/io.rs b/userspace/lib/ygglibc/src/headers/wchar/io.rs index 76f16ee5..9e539a79 100644 --- a/userspace/lib/ygglibc/src/headers/wchar/io.rs +++ b/userspace/lib/ygglibc/src/headers/wchar/io.rs @@ -1,4 +1,4 @@ -use core::ffi::{c_int, VaList}; +use core::ffi::{VaList, c_int}; use crate::{io::managed::FILE, types::wchar_t}; diff --git a/userspace/lib/ygglibc/src/io/managed.rs b/userspace/lib/ygglibc/src/io/managed.rs index 4ba41e97..f8038605 100644 --- a/userspace/lib/ygglibc/src/io/managed.rs +++ b/userspace/lib/ygglibc/src/io/managed.rs @@ -4,7 +4,7 @@ use core::{ ffi::{c_char, c_int}, fmt, ops::{Deref, DerefMut}, - ptr::{null_mut, NonNull}, + ptr::{NonNull, null_mut}, }; use alloc::{boxed::Box, collections::btree_set::BTreeSet, vec::Vec}; @@ -19,14 +19,14 @@ use crate::{ error::{EResult, TryFromExt}, headers::{ errno::Errno, - stdio::{BUFSIZ, UNGETC_MAX, _IOFBF, _IOLBF, _IONBF}, + stdio::{_IOFBF, _IOLBF, _IONBF, BUFSIZ, UNGETC_MAX}, }, }; use super::{ + AsRawFd, BufRead, FromRawFd, Read, Seek, Write, buffer::{FileWriter, FullBufferedWriter, LineBufferedWriter, ReadBuffer, UnbufferedWriter}, raw::RawFile, - AsRawFd, BufRead, FromRawFd, Read, Seek, Write, }; macro locked_op($self:expr, $op:expr) {{ diff --git a/userspace/lib/ygglibc/src/lib.rs b/userspace/lib/ygglibc/src/lib.rs index aa3e347a..2e0db02c 100644 --- a/userspace/lib/ygglibc/src/lib.rs +++ b/userspace/lib/ygglibc/src/lib.rs @@ -4,12 +4,10 @@ maybe_uninit_array_assume_init, c_variadic, arbitrary_self_types_pointers, - maybe_uninit_slice, slice_internals, linkage, rustc_private, thread_local, - let_chains, int_roundings, link_llvm_intrinsics )] diff --git a/userspace/lib/ygglibc/src/panic.rs b/userspace/lib/ygglibc/src/panic.rs index a44edfb4..a91d7c15 100644 --- a/userspace/lib/ygglibc/src/panic.rs +++ b/userspace/lib/ygglibc/src/panic.rs @@ -1,8 +1,8 @@ use core::{fmt, sync::atomic::AtomicUsize}; use crate::io::{ - managed::{stderr, FILE}, Write, + managed::{FILE, stderr}, }; struct PanicPrinter { diff --git a/userspace/lib/ygglibc/src/process.rs b/userspace/lib/ygglibc/src/process.rs index c6cbf8c8..79df9842 100644 --- a/userspace/lib/ygglibc/src/process.rs +++ b/userspace/lib/ygglibc/src/process.rs @@ -1,5 +1,5 @@ use core::{ - ffi::{c_char, c_int, c_void, CStr}, + ffi::{CStr, c_char, c_int, c_void}, mem::MaybeUninit, time::Duration, }; diff --git a/userspace/lib/ygglibc/src/signal.rs b/userspace/lib/ygglibc/src/signal.rs index 821b86a9..ae15aac0 100644 --- a/userspace/lib/ygglibc/src/signal.rs +++ b/userspace/lib/ygglibc/src/signal.rs @@ -2,8 +2,8 @@ use core::ffi::c_int; use yggdrasil_rt::{ process::{ - signal::{self, SignalHandler}, ExitCode, Signal, + signal::{self, SignalHandler}, }, sync::rwlock::RwLock, }; @@ -12,7 +12,7 @@ use crate::{ error::EResult, headers::{ errno::Errno, - signal::{sig_handler_t, signum_to_int, SIGNAL_MAX}, + signal::{SIGNAL_MAX, sig_handler_t, signum_to_int}, }, }; @@ -52,8 +52,8 @@ pub unsafe fn set(sig: c_int, handler: sig_handler_t) -> EResult let address = handler as usize; let handler = match handler { // Transform special cases into Rust signal handlers instead - _ if address == __sig_terminate as usize => todo!(), - _ if address == __sig_ignore as usize => todo!(), + _ if address == (__sig_terminate as *const ()).addr() => todo!(), + _ if address == (__sig_ignore as *const ()).addr() => todo!(), // This is safe: handler essentially has the same type, just in a wrapper _ => handler, }; diff --git a/userspace/lib/ygglibc/src/thread/mod.rs b/userspace/lib/ygglibc/src/thread/mod.rs index 8b529b98..65a16869 100644 --- a/userspace/lib/ygglibc/src/thread/mod.rs +++ b/userspace/lib/ygglibc/src/thread/mod.rs @@ -3,8 +3,9 @@ use core::{cell::RefCell, ffi::c_void, ptr::null_mut}; use alloc::{boxed::Box, collections::BTreeMap, vec::Vec}; use yggdrasil_rt::{ process::{ + ProgramArgumentInner, thread::{self as rt, ThreadCreateInfo}, - thread_local, ProgramArgumentInner, + thread_local, }, sync::mutex::Mutex, }; diff --git a/userspace/lib/ygglibc/src/util.rs b/userspace/lib/ygglibc/src/util.rs index d06fd801..4f9a9785 100644 --- a/userspace/lib/ygglibc/src/util.rs +++ b/userspace/lib/ygglibc/src/util.rs @@ -1,5 +1,5 @@ use core::{ - ffi::{c_char, c_int, CStr}, + ffi::{CStr, c_char, c_int}, fmt, panic::Location, ptr::NonNull, diff --git a/userspace/sysutils/src/login.rs b/userspace/sysutils/src/login.rs index facdd3ab..9f7b3753 100644 --- a/userspace/sysutils/src/login.rs +++ b/userspace/sysutils/src/login.rs @@ -2,12 +2,14 @@ use std::{ env, - io::{self, stdin, stdout, BufRead, Write}, + io::{self, BufRead, Write, stdin, stdout}, os::{ fd::AsRawFd, yggdrasil::{io::terminal::start_terminal_session, rt::io::device}, }, process::{Command, ExitCode}, + thread, + time::Duration, }; fn login_readline( @@ -56,9 +58,19 @@ fn main() -> ExitCode { // TODO check that `terminal` is a terminal log::info!("Starting a session at {}", terminal); - if let Err(err) = unsafe { start_terminal_session(terminal) } { - log::error!("Error: {:?}", err); - eprintln!("Could not setup a session at {}: {:?}", terminal, err); + let mut success = false; + for _ in 0..3 { + if let Err(err) = unsafe { start_terminal_session(terminal) } { + log::error!("{terminal}: {err:?}"); + eprintln!("Could not setup a session at {terminal}: {err:?}"); + } else { + success = true; + break; + } + + thread::sleep(Duration::from_secs(1)); + } + if !success { return ExitCode::FAILURE; } diff --git a/userspace/tools/init/src/lib.rs b/userspace/tools/init/src/lib.rs index 7c7e2560..4876bdc7 100644 --- a/userspace/tools/init/src/lib.rs +++ b/userspace/tools/init/src/lib.rs @@ -1,4 +1,4 @@ -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; #[derive(Serialize, Deserialize, Debug)] pub struct StartService { @@ -8,5 +8,5 @@ pub struct StartService { #[derive(Serialize, Deserialize, Debug)] pub enum InitMsg { - StartService(StartService) + StartService(StartService), } diff --git a/xtask/src/build/cargo.rs b/xtask/src/build/cargo.rs index f71d3237..b9fdef97 100644 --- a/xtask/src/build/cargo.rs +++ b/xtask/src/build/cargo.rs @@ -85,8 +85,9 @@ impl<'e> CargoBuilder<'e> { .display(), env.arch ); - let build_std_features = - "compiler-builtins-mangled-names,compiler-builtins-mem".to_owned(); + let build_std_features = "compiler-builtins".to_owned(); + // let build_std_features = + // "compiler-builtins-mangled-names,compiler-builtins-mem".to_owned(); command .arg(arg)