diff --git a/Cargo.toml b/Cargo.toml index 96397031c0..1adf60e09f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,7 @@ keywords = ["unikernel", "libos"] categories = ["os"] repository = "https://github.com/hermit-os/kernel" documentation = "https://hermit-os.github.io/kernel/hermit/" -edition = "2021" +edition = "2024" description = "A Rust-based library operating system" exclude = [ "/.github/*", diff --git a/build.rs b/build.rs index 1b3b25b1ac..e03045b216 100644 --- a/build.rs +++ b/build.rs @@ -4,7 +4,7 @@ use std::path::{Path, PathBuf}; use std::process::Command; use std::{env, fs}; -use anyhow::{anyhow, Context, Result}; +use anyhow::{Context, Result, anyhow}; use llvm_tools::LlvmTools; fn main() -> Result<()> { diff --git a/hermit-builtins/Cargo.toml b/hermit-builtins/Cargo.toml index a1840df8f2..5c664be635 100644 --- a/hermit-builtins/Cargo.toml +++ b/hermit-builtins/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "hermit-builtins" version = "0.1.0" -edition = "2021" +edition = "2024" [dependencies] libm = "0.2" diff --git a/hermit-macro/Cargo.toml b/hermit-macro/Cargo.toml index eb04386fb0..bcca10e8a8 100644 --- a/hermit-macro/Cargo.toml +++ b/hermit-macro/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "hermit-macro" version = "0.1.0" -edition = "2021" +edition = "2024" [lib] proc-macro = true diff --git a/hermit-macro/src/system.rs b/hermit-macro/src/system.rs index df3de042e4..a812f0bdc5 100644 --- a/hermit-macro/src/system.rs +++ b/hermit-macro/src/system.rs @@ -1,6 +1,6 @@ use proc_macro2::{Ident, Span}; use quote::quote; -use syn::{parse_quote, Abi, Attribute, FnArg, Item, ItemFn, Pat, Result, Signature, Visibility}; +use syn::{Abi, Attribute, FnArg, Item, ItemFn, Pat, Result, Signature, Visibility, parse_quote}; fn validate_vis(vis: &Visibility) -> Result<()> { if !matches!(vis, Visibility::Public(_)) { diff --git a/src/arch/aarch64/kernel/core_local.rs b/src/arch/aarch64/kernel/core_local.rs index e3d4c7ef55..dc4e2c2817 100644 --- a/src/arch/aarch64/kernel/core_local.rs +++ b/src/arch/aarch64/kernel/core_local.rs @@ -8,8 +8,8 @@ use core::sync::atomic::Ordering; #[cfg(feature = "smp")] use hermit_sync::InterruptTicketMutex; -use super::interrupts::{IrqStatistics, IRQ_COUNTERS}; use super::CPU_ONLINE; +use super::interrupts::{IRQ_COUNTERS, IrqStatistics}; use crate::executor::task::AsyncTask; #[cfg(feature = "smp")] use crate::scheduler::SchedulerInput; diff --git a/src/arch/aarch64/kernel/pci.rs b/src/arch/aarch64/kernel/pci.rs index 4876b91546..46f25e7427 100644 --- a/src/arch/aarch64/kernel/pci.rs +++ b/src/arch/aarch64/kernel/pci.rs @@ -6,14 +6,14 @@ use bit_field::BitField; use hermit_dtb::Dtb; use memory_addresses::arch::aarch64::{PhysAddr, VirtAddr}; use pci_types::{ - Bar, CommandRegister, ConfigRegionAccess, InterruptLine, InterruptPin, PciAddress, PciHeader, - MAX_BARS, + Bar, CommandRegister, ConfigRegionAccess, InterruptLine, InterruptPin, MAX_BARS, PciAddress, + PciHeader, }; use crate::arch::aarch64::kernel::interrupts::GIC; use crate::arch::aarch64::mm::paging::{self, BasePageSize, PageSize, PageTableEntryFlags}; use crate::arch::aarch64::mm::virtualmem; -use crate::drivers::pci::{PciDevice, PCI_DEVICES}; +use crate::drivers::pci::{PCI_DEVICES, PciDevice}; use crate::env; const PCI_MAX_DEVICE_NUMBER: u8 = 32; @@ -196,9 +196,7 @@ fn detect_interrupt( trace!( "Interrupt type {:#x}, number {:#x} flags {:#x}", - irq_type, - irq_number, - irq_flags + irq_type, irq_number, irq_flags ); if high.get_bits(0..24) == addr { @@ -250,7 +248,10 @@ pub fn init() { let pci_address = virtualmem::allocate_aligned(size.try_into().unwrap(), 0x1000_0000).unwrap(); - info!("Mapping PCI Enhanced Configuration Space interface to virtual address {:p} (size {:#X})", pci_address, size); + info!( + "Mapping PCI Enhanced Configuration Space interface to virtual address {:p} (size {:#X})", + pci_address, size + ); let mut flags = PageTableEntryFlags::empty(); flags.device().writable().execute_disable(); @@ -292,12 +293,9 @@ pub fn init() { if let Some(bar) = dev.get_bar(i.try_into().unwrap()) { match bar { Bar::Io { .. } => { - dev.set_bar( - i.try_into().unwrap(), - Bar::Io { - port: io_start.try_into().unwrap(), - }, - ); + dev.set_bar(i.try_into().unwrap(), Bar::Io { + port: io_start.try_into().unwrap(), + }); io_start += 0x20; cmd |= CommandRegister::IO_ENABLE | CommandRegister::BUS_MASTER_ENABLE; @@ -313,14 +311,11 @@ pub fn init() { size, prefetchable, } => { - dev.set_bar( - i.try_into().unwrap(), - Bar::Memory64 { - address: mem64_start, - size, - prefetchable, - }, - ); + dev.set_bar(i.try_into().unwrap(), Bar::Memory64 { + address: mem64_start, + size, + prefetchable, + }); mem64_start += size; cmd |= CommandRegister::MEMORY_ENABLE | CommandRegister::BUS_MASTER_ENABLE; diff --git a/src/arch/aarch64/kernel/processor.rs b/src/arch/aarch64/kernel/processor.rs index f752c28f00..fe26acc956 100644 --- a/src/arch/aarch64/kernel/processor.rs +++ b/src/arch/aarch64/kernel/processor.rs @@ -1,9 +1,9 @@ use core::arch::asm; use core::{fmt, str}; -use aarch64::regs::{Readable, CNTFRQ_EL0}; +use aarch64::regs::{CNTFRQ_EL0, Readable}; use hermit_dtb::Dtb; -use hermit_sync::{without_interrupts, Lazy}; +use hermit_sync::{Lazy, without_interrupts}; use crate::env; diff --git a/src/arch/aarch64/kernel/scheduler.rs b/src/arch/aarch64/kernel/scheduler.rs index 6f7360aaee..7daf7e6cca 100644 --- a/src/arch/aarch64/kernel/scheduler.rs +++ b/src/arch/aarch64/kernel/scheduler.rs @@ -1,7 +1,7 @@ //! Architecture dependent interface to initialize a task #[cfg(not(feature = "common-os"))] -use alloc::alloc::{alloc_zeroed, Layout}; +use alloc::alloc::{Layout, alloc_zeroed}; #[cfg(not(feature = "common-os"))] use alloc::boxed::Box; use core::arch::naked_asm; @@ -13,14 +13,14 @@ use core::{mem, ptr}; use align_address::Align; use memory_addresses::arch::aarch64::{PhysAddr, VirtAddr}; -use crate::arch::aarch64::kernel::core_local::core_scheduler; use crate::arch::aarch64::kernel::CURRENT_STACK_ADDRESS; +use crate::arch::aarch64::kernel::core_local::core_scheduler; use crate::arch::aarch64::mm::paging::{BasePageSize, PageSize, PageTableEntryFlags}; #[cfg(not(feature = "common-os"))] use crate::env; -use crate::scheduler::task::{Task, TaskFrame}; #[cfg(target_os = "none")] use crate::scheduler::PerCoreSchedulerExt; +use crate::scheduler::task::{Task, TaskFrame}; use crate::{DEFAULT_STACK_SIZE, KERNEL_STACK_SIZE}; #[derive(Debug)] @@ -297,15 +297,15 @@ impl TaskTLS { let raw = ptr::slice_from_raw_parts_mut(data, block_len) as *mut TaskTLS; let addr = (*raw).block.as_ptr().add(off).cast::<()>(); - (*raw).dtv.as_mut_ptr().write(Box::new([ - Dtv { counter: 1 }, - Dtv { + (*raw) + .dtv + .as_mut_ptr() + .write(Box::new([Dtv { counter: 1 }, Dtv { pointer: DtvPointer { val: addr, to_free: ptr::null(), }, - }, - ])); + }])); Box::from_raw(raw) }; diff --git a/src/arch/aarch64/kernel/start.rs b/src/arch/aarch64/kernel/start.rs index 673192113e..960f5505f9 100644 --- a/src/arch/aarch64/kernel/start.rs +++ b/src/arch/aarch64/kernel/start.rs @@ -1,10 +1,10 @@ use core::arch::{asm, naked_asm}; -use hermit_entry::boot_info::RawBootInfo; use hermit_entry::Entry; +use hermit_entry::boot_info::RawBootInfo; use crate::arch::aarch64::kernel::scheduler::TaskStacks; -use crate::{env, KERNEL_STACK_SIZE}; +use crate::{KERNEL_STACK_SIZE, env}; unsafe extern "C" { static vector_table: u8; diff --git a/src/arch/aarch64/mm/paging.rs b/src/arch/aarch64/mm/paging.rs index 1c1ff11590..96159e204c 100644 --- a/src/arch/aarch64/mm/paging.rs +++ b/src/arch/aarch64/mm/paging.rs @@ -10,7 +10,7 @@ use memory_addresses::{PhysAddr, VirtAddr}; use crate::arch::aarch64::kernel::{get_base_address, get_image_size, get_ram_address, processor}; use crate::arch::aarch64::mm::{physicalmem, virtualmem}; use crate::env::is_uhyve; -use crate::{mm, scheduler, KERNEL_STACK_SIZE}; +use crate::{KERNEL_STACK_SIZE, mm, scheduler}; /// Pointer to the root page table (called "Level 0" in ARM terminology). /// Setting the upper bits to zero tells the MMU to use TTBR0 for the base address for the first table. @@ -587,9 +587,7 @@ pub fn map( ) { trace!( "Mapping virtual address {:p} to physical address {:p} ({} pages)", - virtual_address, - physical_address, - count + virtual_address, physical_address, count ); let range = get_page_range::(virtual_address, count); @@ -620,8 +618,7 @@ pub fn map_heap(virt_addr: VirtAddr, count: usize) -> Result<(), us pub fn unmap(virtual_address: VirtAddr, count: usize) { trace!( "Unmapping virtual address {:p} ({} pages)", - virtual_address, - count + virtual_address, count ); let range = get_page_range::(virtual_address, count); diff --git a/src/arch/riscv64/kernel/interrupts.rs b/src/arch/riscv64/kernel/interrupts.rs index 40f123084d..a04cbc233e 100644 --- a/src/arch/riscv64/kernel/interrupts.rs +++ b/src/arch/riscv64/kernel/interrupts.rs @@ -8,11 +8,11 @@ use riscv::interrupt::{Exception, Interrupt, Trap}; use riscv::register::{scause, sie, sip, sstatus, stval}; use trapframe::TrapFrame; +use crate::drivers::InterruptHandlerQueue; #[cfg(not(feature = "pci"))] use crate::drivers::mmio::get_interrupt_handlers; #[cfg(feature = "pci")] use crate::drivers::pci::get_interrupt_handlers; -use crate::drivers::InterruptHandlerQueue; use crate::scheduler; /// base address of the PLIC, only one access at the same time is allowed diff --git a/src/arch/riscv64/kernel/mod.rs b/src/arch/riscv64/kernel/mod.rs index 0ff1e8bafa..1455819993 100644 --- a/src/arch/riscv64/kernel/mod.rs +++ b/src/arch/riscv64/kernel/mod.rs @@ -20,7 +20,7 @@ use fdt::Fdt; use memory_addresses::{PhysAddr, VirtAddr}; use riscv::register::sstatus; -use crate::arch::riscv64::kernel::core_local::{core_id, CoreLocal}; +use crate::arch::riscv64::kernel::core_local::{CoreLocal, core_id}; pub use crate::arch::riscv64::kernel::devicetree::init_drivers; use crate::arch::riscv64::kernel::processor::lsb; use crate::arch::riscv64::mm::physicalmem; diff --git a/src/arch/riscv64/kernel/processor.rs b/src/arch/riscv64/kernel/processor.rs index 0015686cfc..5624af95f2 100644 --- a/src/arch/riscv64/kernel/processor.rs +++ b/src/arch/riscv64/kernel/processor.rs @@ -4,7 +4,7 @@ use core::num::NonZeroU64; use riscv::register::{sie, sstatus, time}; -use crate::arch::riscv64::kernel::{get_timebase_freq, HARTS_AVAILABLE}; +use crate::arch::riscv64::kernel::{HARTS_AVAILABLE, get_timebase_freq}; use crate::scheduler::CoreId; /// Current FPU state. Saved at context switch when changed diff --git a/src/arch/riscv64/kernel/scheduler.rs b/src/arch/riscv64/kernel/scheduler.rs index c483d04cd9..a3d6eb2767 100644 --- a/src/arch/riscv64/kernel/scheduler.rs +++ b/src/arch/riscv64/kernel/scheduler.rs @@ -1,5 +1,5 @@ #[cfg(not(feature = "common-os"))] -use alloc::alloc::{alloc, dealloc, Layout}; +use alloc::alloc::{Layout, alloc, dealloc}; #[cfg(not(feature = "common-os"))] use alloc::boxed::Box; #[cfg(not(feature = "common-os"))] @@ -282,7 +282,7 @@ impl TaskTLS { // Yes, it does, so we have to allocate TLS memory. // Allocate enough space for the given size and one more variable of type usize, which holds the tls_pointer. let tls_allocation_size = tls_size.align_up(32usize); // + mem::size_of::(); - // We allocate in 128 byte granularity (= cache line size) to avoid false sharing + // We allocate in 128 byte granularity (= cache line size) to avoid false sharing let memory_size = tls_allocation_size.align_up(128usize); let layout = Layout::from_size_align(memory_size, 128).expect("TLS has an invalid size / alignment"); diff --git a/src/arch/riscv64/kernel/start.rs b/src/arch/riscv64/kernel/start.rs index 23205a4b63..531bad8389 100644 --- a/src/arch/riscv64/kernel/start.rs +++ b/src/arch/riscv64/kernel/start.rs @@ -2,14 +2,14 @@ use core::arch::naked_asm; use core::sync::atomic::Ordering; use fdt::Fdt; -use hermit_entry::boot_info::RawBootInfo; use hermit_entry::Entry; +use hermit_entry::boot_info::RawBootInfo; -use super::{get_dtb_ptr, CPU_ONLINE, CURRENT_BOOT_ID, HART_MASK, NUM_CPUS}; +use super::{CPU_ONLINE, CURRENT_BOOT_ID, HART_MASK, NUM_CPUS, get_dtb_ptr}; +use crate::arch::riscv64::kernel::CURRENT_STACK_ADDRESS; #[cfg(not(feature = "smp"))] use crate::arch::riscv64::kernel::processor; -use crate::arch::riscv64::kernel::CURRENT_STACK_ADDRESS; -use crate::{env, KERNEL_STACK_SIZE}; +use crate::{KERNEL_STACK_SIZE, env}; //static mut BOOT_STACK: [u8; KERNEL_STACK_SIZE] = [0; KERNEL_STACK_SIZE]; diff --git a/src/arch/riscv64/mm/paging.rs b/src/arch/riscv64/mm/paging.rs index 1a6e278146..1f9c24cf29 100644 --- a/src/arch/riscv64/mm/paging.rs +++ b/src/arch/riscv64/mm/paging.rs @@ -597,9 +597,7 @@ pub fn map( ) { trace!( "Mapping physical address {:#X} to virtual address {:#X} ({} pages)", - physical_address, - virtual_address, - count + physical_address, virtual_address, count ); let range = get_page_range::(virtual_address, count); @@ -631,8 +629,7 @@ pub fn map_heap(virt_addr: VirtAddr, count: usize) -> Result<(), us pub fn unmap(virtual_address: VirtAddr, count: usize) { trace!( "Unmapping virtual address {:#X} ({} pages)", - virtual_address, - count + virtual_address, count ); let range = get_page_range::(virtual_address, count); @@ -650,8 +647,7 @@ pub fn identity_map(memory: AddrRange) { trace!( "identity_map address {:#X} to address {:#X}", - first_page.virtual_address, - last_page.virtual_address, + first_page.virtual_address, last_page.virtual_address, ); /* assert!( diff --git a/src/arch/x86_64/kernel/acpi.rs b/src/arch/x86_64/kernel/acpi.rs index 959083a0f4..cf2b4372e5 100644 --- a/src/arch/x86_64/kernel/acpi.rs +++ b/src/arch/x86_64/kernel/acpi.rs @@ -264,11 +264,7 @@ fn verify_checksum(start_address: usize, length: usize) -> Result<(), ()> { let checksum = slice.iter().fold(0, |acc: u8, x| acc.wrapping_add(*x)); // This sum must equal to zero to be valid. - if checksum == 0 { - Ok(()) - } else { - Err(()) - } + if checksum == 0 { Ok(()) } else { Err(()) } } /// Tries to find the ACPI RSDP within the specified address range. diff --git a/src/arch/x86_64/kernel/apic.rs b/src/arch/x86_64/kernel/apic.rs index 53cc7d8d1e..6096f7c264 100644 --- a/src/arch/x86_64/kernel/apic.rs +++ b/src/arch/x86_64/kernel/apic.rs @@ -13,16 +13,16 @@ use align_address::Align; #[cfg(feature = "smp")] use arch::x86_64::kernel::core_local::*; use arch::x86_64::kernel::{interrupts, processor}; -use hermit_sync::{without_interrupts, OnceCell, SpinMutex}; +use hermit_sync::{OnceCell, SpinMutex, without_interrupts}; use memory_addresses::{AddrRange, PhysAddr, VirtAddr}; #[cfg(feature = "smp")] use x86::controlregs::*; use x86::msr::*; use super::interrupts::IDT; +use crate::arch::x86_64::kernel::CURRENT_STACK_ADDRESS; #[cfg(feature = "acpi")] use crate::arch::x86_64::kernel::acpi; -use crate::arch::x86_64::kernel::CURRENT_STACK_ADDRESS; use crate::arch::x86_64::mm::paging::{ BasePageSize, PageSize, PageTableEntryFlags, PageTableEntryFlagsExt, }; @@ -615,8 +615,8 @@ fn calibrate_timer() { .set(calibrated_counter_value) .unwrap(); debug!( - "Calibrated APIC Timer with a counter value of {calibrated_counter_value} for 1 microsecond", - ); + "Calibrated APIC Timer with a counter value of {calibrated_counter_value} for 1 microsecond", + ); } fn __set_oneshot_timer(wakeup_time: Option) { diff --git a/src/arch/x86_64/kernel/core_local.rs b/src/arch/x86_64/kernel/core_local.rs index b2010e230f..11791031db 100644 --- a/src/arch/x86_64/kernel/core_local.rs +++ b/src/arch/x86_64/kernel/core_local.rs @@ -9,12 +9,12 @@ use core::{mem, ptr}; #[cfg(feature = "smp")] use hermit_sync::InterruptTicketMutex; +use x86_64::VirtAddr; use x86_64::registers::model_specific::GsBase; use x86_64::structures::tss::TaskStateSegment; -use x86_64::VirtAddr; -use super::interrupts::{IrqStatistics, IRQ_COUNTERS}; use super::CPU_ONLINE; +use super::interrupts::{IRQ_COUNTERS, IrqStatistics}; use crate::executor::task::AsyncTask; #[cfg(feature = "smp")] use crate::scheduler::SchedulerInput; diff --git a/src/arch/x86_64/kernel/gdt.rs b/src/arch/x86_64/kernel/gdt.rs index a76d882e7d..a4e7549858 100644 --- a/src/arch/x86_64/kernel/gdt.rs +++ b/src/arch/x86_64/kernel/gdt.rs @@ -3,18 +3,18 @@ use alloc::boxed::Box; use core::alloc::Layout; use core::sync::atomic::Ordering; +use x86_64::VirtAddr; use x86_64::instructions::tables; -use x86_64::registers::segmentation::{Segment, CS, DS, ES, SS}; +use x86_64::registers::segmentation::{CS, DS, ES, SS, Segment}; #[cfg(feature = "common-os")] use x86_64::structures::gdt::DescriptorFlags; use x86_64::structures::gdt::{Descriptor, GlobalDescriptorTable}; use x86_64::structures::tss::TaskStateSegment; -use x86_64::VirtAddr; +use super::CURRENT_STACK_ADDRESS; use super::interrupts::{IST_ENTRIES, IST_SIZE}; use super::scheduler::TaskStacks; -use super::CURRENT_STACK_ADDRESS; -use crate::arch::x86_64::kernel::core_local::{core_scheduler, CoreLocal}; +use crate::arch::x86_64::kernel::core_local::{CoreLocal, core_scheduler}; use crate::arch::x86_64::mm::paging::{BasePageSize, PageSize}; use crate::config::KERNEL_STACK_SIZE; diff --git a/src/arch/x86_64/kernel/interrupts.rs b/src/arch/x86_64/kernel/interrupts.rs index 4158506192..251934d75d 100644 --- a/src/arch/x86_64/kernel/interrupts.rs +++ b/src/arch/x86_64/kernel/interrupts.rs @@ -14,13 +14,13 @@ pub use x86_64::structures::idt::InterruptStackFrame as ExceptionStackFrame; use crate::arch::x86_64::kernel::core_local::{core_scheduler, increment_irq_counter}; use crate::arch::x86_64::kernel::{apic, processor}; -use crate::arch::x86_64::mm::paging::{page_fault_handler, BasePageSize, PageSize}; +use crate::arch::x86_64::mm::paging::{BasePageSize, PageSize, page_fault_handler}; use crate::arch::x86_64::swapgs; +use crate::drivers::InterruptHandlerQueue; #[cfg(not(feature = "pci"))] use crate::drivers::mmio::get_interrupt_handlers; #[cfg(feature = "pci")] use crate::drivers::pci::get_interrupt_handlers; -use crate::drivers::InterruptHandlerQueue; use crate::scheduler::{self, CoreId}; static IRQ_HANDLERS: OnceCell> = OnceCell::new(); diff --git a/src/arch/x86_64/kernel/mmio.rs b/src/arch/x86_64/kernel/mmio.rs index e1ffdb77ff..edd214ea90 100644 --- a/src/arch/x86_64/kernel/mmio.rs +++ b/src/arch/x86_64/kernel/mmio.rs @@ -4,7 +4,7 @@ use core::ptr::NonNull; use core::{ptr, str}; use align_address::Align; -use hermit_sync::{without_interrupts, InterruptTicketMutex}; +use hermit_sync::{InterruptTicketMutex, without_interrupts}; use memory_addresses::PhysAddr; use virtio::mmio::{DeviceRegisters, DeviceRegistersVolatileFieldAccess}; use volatile::VolatileRef; diff --git a/src/arch/x86_64/kernel/mod.rs b/src/arch/x86_64/kernel/mod.rs index 1e71a1b774..4745f7b4d2 100644 --- a/src/arch/x86_64/kernel/mod.rs +++ b/src/arch/x86_64/kernel/mod.rs @@ -7,7 +7,7 @@ use core::task::Waker; use hermit_entry::boot_info::{PlatformInfo, RawBootInfo}; use memory_addresses::{PhysAddr, VirtAddr}; -use x86::controlregs::{cr0, cr0_write, cr4, Cr0}; +use x86::controlregs::{Cr0, cr0, cr0_write, cr4}; use self::serial::SerialPort; use crate::arch::x86_64::kernel::core_local::*; @@ -140,10 +140,10 @@ pub fn get_processor_count() -> u32 { } pub fn is_uhyve_with_pci() -> bool { - matches!( - env::boot_info().platform_info, - PlatformInfo::Uhyve { has_pci: true, .. } - ) + matches!(env::boot_info().platform_info, PlatformInfo::Uhyve { + has_pci: true, + .. + }) } pub fn args() -> Option<&'static str> { diff --git a/src/arch/x86_64/kernel/pci.rs b/src/arch/x86_64/kernel/pci.rs index a6f9ff2dac..d3377ce9b4 100644 --- a/src/arch/x86_64/kernel/pci.rs +++ b/src/arch/x86_64/kernel/pci.rs @@ -1,7 +1,7 @@ use pci_types::{ConfigRegionAccess, PciAddress, PciHeader}; use x86::io::*; -use crate::drivers::pci::{PciDevice, PCI_DEVICES}; +use crate::drivers::pci::{PCI_DEVICES, PciDevice}; const PCI_MAX_BUS_NUMBER: u8 = 32; const PCI_MAX_DEVICE_NUMBER: u8 = 32; diff --git a/src/arch/x86_64/kernel/processor.rs b/src/arch/x86_64/kernel/processor.rs index e5003674d2..90b65a760e 100644 --- a/src/arch/x86_64/kernel/processor.rs +++ b/src/arch/x86_64/kernel/processor.rs @@ -15,11 +15,11 @@ use x86::bits64::segmentation; use x86::controlregs::*; use x86::cpuid::*; use x86::msr::*; +use x86_64::VirtAddr; use x86_64::instructions::interrupts::int3; use x86_64::instructions::port::Port; use x86_64::instructions::tables::lidt; use x86_64::structures::DescriptorTablePointer; -use x86_64::VirtAddr; #[cfg(feature = "acpi")] use crate::arch::x86_64::kernel::acpi; diff --git a/src/arch/x86_64/kernel/scheduler.rs b/src/arch/x86_64/kernel/scheduler.rs index 5129baed7d..8e858aacaf 100644 --- a/src/arch/x86_64/kernel/scheduler.rs +++ b/src/arch/x86_64/kernel/scheduler.rs @@ -20,8 +20,8 @@ use crate::arch::x86_64::mm::paging::{ }; use crate::config::*; use crate::env; -use crate::scheduler::task::{Task, TaskFrame}; use crate::scheduler::PerCoreSchedulerExt; +use crate::scheduler::task::{Task, TaskFrame}; #[repr(C, packed)] struct State { diff --git a/src/arch/x86_64/kernel/start.rs b/src/arch/x86_64/kernel/start.rs index e7be4378dc..73255cd643 100644 --- a/src/arch/x86_64/kernel/start.rs +++ b/src/arch/x86_64/kernel/start.rs @@ -1,11 +1,11 @@ use core::arch::naked_asm; -use hermit_entry::boot_info::RawBootInfo; use hermit_entry::Entry; +use hermit_entry::boot_info::RawBootInfo; +use crate::KERNEL_STACK_SIZE; use crate::kernel::pre_init; use crate::kernel::scheduler::TaskStacks; -use crate::KERNEL_STACK_SIZE; #[unsafe(no_mangle)] #[naked] diff --git a/src/arch/x86_64/kernel/systemtime.rs b/src/arch/x86_64/kernel/systemtime.rs index d52156416c..0af760573e 100644 --- a/src/arch/x86_64/kernel/systemtime.rs +++ b/src/arch/x86_64/kernel/systemtime.rs @@ -1,7 +1,7 @@ use core::hint::spin_loop; use hermit_entry::boot_info::PlatformInfo; -use hermit_sync::{without_interrupts, OnceCell}; +use hermit_sync::{OnceCell, without_interrupts}; use time::OffsetDateTime; use x86::io::*; diff --git a/src/arch/x86_64/mm/paging.rs b/src/arch/x86_64/mm/paging.rs index 61f98b4938..8c3f6dadee 100644 --- a/src/arch/x86_64/mm/paging.rs +++ b/src/arch/x86_64/mm/paging.rs @@ -7,17 +7,17 @@ use x86_64::registers::control::{Cr0, Cr0Flags, Cr2, Cr3}; use x86_64::registers::segmentation::SegmentSelector; pub use x86_64::structures::idt::InterruptStackFrame as ExceptionStackFrame; use x86_64::structures::idt::PageFaultErrorCode; +pub use x86_64::structures::paging::PageTableFlags as PageTableEntryFlags; use x86_64::structures::paging::frame::PhysFrameRange; use x86_64::structures::paging::mapper::{MappedFrame, TranslateResult, UnmapError}; use x86_64::structures::paging::page::PageRange; -pub use x86_64::structures::paging::PageTableFlags as PageTableEntryFlags; use x86_64::structures::paging::{ Mapper, OffsetPageTable, Page, PageTable, PageTableIndex, PhysFrame, RecursivePageTable, Size2MiB, Size4KiB, Translate, }; use crate::arch::x86_64::kernel::processor; -use crate::arch::x86_64::mm::{physicalmem, PhysAddr, VirtAddr}; +use crate::arch::x86_64::mm::{PhysAddr, VirtAddr, physicalmem}; use crate::{env, mm, scheduler}; pub trait PageTableEntryFlagsExt { @@ -266,8 +266,7 @@ where { trace!( "Unmapping virtual address {:p} ({} pages)", - virtual_address, - count + virtual_address, count ); let first_page = Page::::containing_address(virtual_address.into()); diff --git a/src/arch/x86_64/mm/physicalmem.rs b/src/arch/x86_64/mm/physicalmem.rs index a3e0e38264..3a2ac0d0bd 100644 --- a/src/arch/x86_64/mm/physicalmem.rs +++ b/src/arch/x86_64/mm/physicalmem.rs @@ -6,8 +6,8 @@ use memory_addresses::{PhysAddr, VirtAddr}; use multiboot::information::{MemoryType, Multiboot}; use crate::arch::x86_64::kernel::{get_limit, get_mbinfo}; -use crate::arch::x86_64::mm::paging::{BasePageSize, PageSize}; use crate::arch::x86_64::mm::MultibootMemory; +use crate::arch::x86_64::mm::paging::{BasePageSize, PageSize}; use crate::{env, mm}; pub static PHYSICAL_FREE_LIST: InterruptTicketMutex> = @@ -67,11 +67,7 @@ fn detect_from_fdt() -> Result<(), ()> { } } - if found_ram { - Ok(()) - } else { - Err(()) - } + if found_ram { Ok(()) } else { Err(()) } } fn detect_from_multiboot_info() -> Result<(), ()> { diff --git a/src/arch/x86_64/mm/virtualmem.rs b/src/arch/x86_64/mm/virtualmem.rs index 5a8654adac..a0cd45c63a 100644 --- a/src/arch/x86_64/mm/virtualmem.rs +++ b/src/arch/x86_64/mm/virtualmem.rs @@ -2,8 +2,8 @@ use align_address::Align; use free_list::{AllocError, FreeList, PageLayout, PageRange}; use hermit_sync::InterruptTicketMutex; -use crate::arch::x86_64::mm::paging::{BasePageSize, PageSize}; use crate::arch::x86_64::mm::VirtAddr; +use crate::arch::x86_64::mm::paging::{BasePageSize, PageSize}; use crate::{env, mm}; static KERNEL_FREE_LIST: InterruptTicketMutex> = diff --git a/src/drivers/fs/virtio_fs.rs b/src/drivers/fs/virtio_fs.rs index e184d5d7d3..aea830adb0 100644 --- a/src/drivers/fs/virtio_fs.rs +++ b/src/drivers/fs/virtio_fs.rs @@ -4,12 +4,13 @@ use alloc::vec::Vec; use core::str; use pci_types::InterruptLine; -use virtio::fs::ConfigVolatileFieldAccess; use virtio::FeatureBits; -use volatile::access::ReadOnly; +use virtio::fs::ConfigVolatileFieldAccess; use volatile::VolatileRef; +use volatile::access::ReadOnly; use crate::config::VIRTIO_MAX_QUEUE_SIZE; +use crate::drivers::Driver; use crate::drivers::virtio::error::VirtioFsError; #[cfg(not(feature = "pci"))] use crate::drivers::virtio::transport::mmio::{ComCfg, IsrStatus, NotifCfg}; @@ -20,7 +21,6 @@ use crate::drivers::virtio::virtqueue::split::SplitVq; use crate::drivers::virtio::virtqueue::{ AvailBufferToken, BufferElem, BufferType, Virtq, VqIndex, VqSize, }; -use crate::drivers::Driver; use crate::fs::fuse::{self, FuseInterface, Rsp, RspHeader}; use crate::mm::device_alloc::DeviceAlloc; diff --git a/src/drivers/mmio.rs b/src/drivers/mmio.rs index df8a757f4a..d1bae5dcb0 100644 --- a/src/drivers/mmio.rs +++ b/src/drivers/mmio.rs @@ -7,9 +7,9 @@ use hashbrown::HashMap; #[cfg(any(feature = "tcp", feature = "udp"))] pub(crate) use crate::arch::kernel::mmio::get_network_driver; #[cfg(any(feature = "tcp", feature = "udp"))] -use crate::drivers::net::NetworkDriver; -#[cfg(any(feature = "tcp", feature = "udp"))] use crate::drivers::Driver; +#[cfg(any(feature = "tcp", feature = "udp"))] +use crate::drivers::net::NetworkDriver; use crate::drivers::{InterruptHandlerQueue, InterruptLine}; pub(crate) fn get_interrupt_handlers() -> HashMap diff --git a/src/drivers/net/rtl8139.rs b/src/drivers/net/rtl8139.rs index 222fb63c24..302a17ab9c 100644 --- a/src/drivers/net/rtl8139.rs +++ b/src/drivers/net/rtl8139.rs @@ -12,10 +12,10 @@ use x86::io::*; use crate::arch::kernel::interrupts::*; use crate::arch::mm::paging::virt_to_phys; use crate::arch::pci::PciConfigRegion; +use crate::drivers::Driver; use crate::drivers::error::DriverError; use crate::drivers::net::NetworkDriver; use crate::drivers::pci::PciDevice; -use crate::drivers::Driver; use crate::executor::device::{RxToken, TxToken}; /// size of the receive buffer diff --git a/src/drivers/net/virtio/mmio.rs b/src/drivers/net/virtio/mmio.rs index 595302f03c..8679ba52cd 100644 --- a/src/drivers/net/virtio/mmio.rs +++ b/src/drivers/net/virtio/mmio.rs @@ -10,11 +10,11 @@ use smoltcp::phy::ChecksumCapabilities; use virtio::mmio::{DeviceRegisters, DeviceRegistersVolatileFieldAccess}; use volatile::VolatileRef; +use crate::drivers::InterruptLine; use crate::drivers::net::virtio::{CtrlQueue, NetDevCfg, RxQueues, TxQueues, VirtioNetDriver}; use crate::drivers::virtio::error::{VirtioError, VirtioNetError}; use crate::drivers::virtio::transport::mmio::{ComCfg, IsrStatus, NotifCfg}; use crate::drivers::virtio::virtqueue::Virtq; -use crate::drivers::InterruptLine; // Backend-dependent interface for Virtio network driver impl VirtioNetDriver { diff --git a/src/drivers/net/virtio/mod.rs b/src/drivers/net/virtio/mod.rs index bfcca3b66c..1a6a47a8d3 100644 --- a/src/drivers/net/virtio/mod.rs +++ b/src/drivers/net/virtio/mod.rs @@ -15,11 +15,11 @@ use alloc::vec::Vec; use core::mem::MaybeUninit; use smoltcp::phy::{Checksum, ChecksumCapabilities}; -use smoltcp::wire::{EthernetFrame, Ipv4Packet, Ipv6Packet, ETHERNET_HEADER_LEN}; +use smoltcp::wire::{ETHERNET_HEADER_LEN, EthernetFrame, Ipv4Packet, Ipv6Packet}; use virtio::net::{ConfigVolatileFieldAccess, Hdr, HdrF}; use virtio::{DeviceConfigSpace, FeatureBits}; -use volatile::access::ReadOnly; use volatile::VolatileRef; +use volatile::access::ReadOnly; use self::constants::MAX_NUM_VQ; use self::error::VirtioNetError; @@ -114,16 +114,13 @@ impl RxQueues { fn fill_queue(vq: &mut dyn Virtq, num_packets: u16, packet_size: u32) { for _ in 0..num_packets { - let buff_tkn = match AvailBufferToken::new( - vec![], - vec![ - BufferElem::Sized(Box::::new_uninit_in(DeviceAlloc)), - BufferElem::Vector(Vec::with_capacity_in( - packet_size.try_into().unwrap(), - DeviceAlloc, - )), - ], - ) { + let buff_tkn = match AvailBufferToken::new(vec![], vec![ + BufferElem::Sized(Box::::new_uninit_in(DeviceAlloc)), + BufferElem::Vector(Vec::with_capacity_in( + packet_size.try_into().unwrap(), + DeviceAlloc, + )), + ]) { Ok(tkn) => tkn, Err(_vq_err) => { error!("Setup of network queue failed, which should not happen!"); @@ -523,13 +520,17 @@ impl VirtioNetDriver { Err(vnet_err) => { match vnet_err { VirtioNetError::FeatureRequirementsNotMet(features) => { - error!("Network drivers feature set {features:?} does not satisfy rules in section 5.1.3.1 of specification v1.1. Aborting!"); + error!( + "Network drivers feature set {features:?} does not satisfy rules in section 5.1.3.1 of specification v1.1. Aborting!" + ); return Err(vnet_err); } VirtioNetError::IncompatibleFeatureSets(drv_feats, dev_feats) => { // Create a new matching feature set for device and driver if the minimal set is met! if !dev_feats.contains(minimal_features) { - error!("Device features set, does not satisfy minimal features needed. Aborting!"); + error!( + "Device features set, does not satisfy minimal features needed. Aborting!" + ); return Err(VirtioNetError::FailFeatureNeg(self.dev_cfg.dev_id)); } @@ -543,19 +544,24 @@ impl VirtioNetDriver { features = common_features; match self.negotiate_features(features) { - Ok(()) => info!("Driver found a subset of features for virtio device {:x}. Features are: {features:?}", self.dev_cfg.dev_id), - Err(vnet_err) => { - match vnet_err { - VirtioNetError::FeatureRequirementsNotMet(features) => { - error!("Network device offers a feature set {features:?} when used completely does not satisfy rules in section 5.1.3.1 of specification v1.1. Aborting!"); - return Err(vnet_err); - }, - _ => { - error!("Feature Set after reduction still not usable. Set: {features:?}. Aborting!"); - return Err(vnet_err); - } - } - } + Ok(()) => info!( + "Driver found a subset of features for virtio device {:x}. Features are: {features:?}", + self.dev_cfg.dev_id + ), + Err(vnet_err) => match vnet_err { + VirtioNetError::FeatureRequirementsNotMet(features) => { + error!( + "Network device offers a feature set {features:?} when used completely does not satisfy rules in section 5.1.3.1 of specification v1.1. Aborting!" + ); + return Err(vnet_err); + } + _ => { + error!( + "Feature Set after reduction still not usable. Set: {features:?}. Aborting!" + ); + return Err(vnet_err); + } + }, } } VirtioNetError::FailFeatureNeg(_) => { diff --git a/src/drivers/pci.rs b/src/drivers/pci.rs index ef7dd5ba76..60732c6efc 100644 --- a/src/drivers/pci.rs +++ b/src/drivers/pci.rs @@ -6,14 +6,14 @@ use core::fmt; use ahash::RandomState; use hashbrown::HashMap; -use hermit_sync::without_interrupts; #[cfg(any(feature = "tcp", feature = "udp", feature = "fuse", feature = "vsock"))] use hermit_sync::InterruptTicketMutex; +use hermit_sync::without_interrupts; use memory_addresses::{PhysAddr, VirtAddr}; use pci_types::capability::CapabilityIterator; use pci_types::{ Bar, CommandRegister, ConfigRegionAccess, DeviceId, EndpointHeader, InterruptLine, - InterruptPin, PciAddress, PciHeader, StatusRegister, VendorId, MAX_BARS, + InterruptPin, MAX_BARS, PciAddress, PciHeader, StatusRegister, VendorId, }; use crate::arch::pci::PciConfigRegion; @@ -26,8 +26,6 @@ use crate::drivers::net::rtl8139::{self, RTL8139Driver}; any(feature = "tcp", feature = "udp") ))] use crate::drivers::net::virtio::VirtioNetDriver; -#[cfg(any(feature = "tcp", feature = "udp"))] -use crate::drivers::net::NetworkDriver; #[cfg(any( all( any(feature = "tcp", feature = "udp"), @@ -279,7 +277,10 @@ impl fmt::Display for PciDevice { size, prefetchable, } => { - write!(f, ", BAR{slot} Memory64 {{ address: {address:#X}, size: {size:#X}, prefetchable: {prefetchable} }}")?; + write!( + f, + ", BAR{slot} Memory64 {{ address: {address:#X}, size: {size:#X}, prefetchable: {prefetchable} }}" + )?; slot += 1; } Bar::Memory32 { @@ -287,7 +288,10 @@ impl fmt::Display for PciDevice { size, prefetchable, } => { - write!(f, ", BAR{slot} Memory32 {{ address: {address:#X}, size: {size:#X}, prefetchable: {prefetchable} }}")?; + write!( + f, + ", BAR{slot} Memory32 {{ address: {address:#X}, size: {size:#X}, prefetchable: {prefetchable} }}" + )?; } Bar::Io { port } => { write!(f, ", BAR{slot} IO {{ port: {port:#X} }}")?; diff --git a/src/drivers/virtio/env.rs b/src/drivers/virtio/env.rs index 2cf5f5592e..8feccf7df0 100644 --- a/src/drivers/virtio/env.rs +++ b/src/drivers/virtio/env.rs @@ -18,8 +18,8 @@ pub mod pci { use pci_types::MAX_BARS; use crate::arch::pci::PciConfigRegion; - use crate::drivers::pci::error::PciError; use crate::drivers::pci::PciDevice; + use crate::drivers::pci::error::PciError; use crate::drivers::virtio::transport::pci::PciBar as VirtioPciBar; /// Maps all memory areas indicated by the devices BAR's into diff --git a/src/drivers/virtio/mod.rs b/src/drivers/virtio/mod.rs index 8e94a63f4c..ce86771ec2 100644 --- a/src/drivers/virtio/mod.rs +++ b/src/drivers/virtio/mod.rs @@ -50,52 +50,132 @@ pub mod error { match self { #[cfg(not(feature = "pci"))] VirtioError::Unknown => write!(f, "Driver failure"), - #[cfg(feature = "pci")] + #[cfg(feature = "pci")] VirtioError::FromPci(pci_error) => match pci_error { - PciError::General(id) => write!(f, "Driver failed to initialize device with id: {id:#x}. Due to unknown reasosn!"), - PciError::NoBar(id ) => write!(f, "Driver failed to initialize device with id: {id:#x}. Reason: No BAR's found."), - PciError::NoCapPtr(id) => write!(f, "Driver failed to initialize device with id: {id:#x}. Reason: No Capabilities pointer found."), - PciError::NoVirtioCaps(id) => write!(f, "Driver failed to initialize device with id: {id:#x}. Reason: No Virtio capabilities were found."), - }, + PciError::General(id) => write!( + f, + "Driver failed to initialize device with id: {id:#x}. Due to unknown reasosn!" + ), + PciError::NoBar(id) => write!( + f, + "Driver failed to initialize device with id: {id:#x}. Reason: No BAR's found." + ), + PciError::NoCapPtr(id) => write!( + f, + "Driver failed to initialize device with id: {id:#x}. Reason: No Capabilities pointer found." + ), + PciError::NoVirtioCaps(id) => write!( + f, + "Driver failed to initialize device with id: {id:#x}. Reason: No Virtio capabilities were found." + ), + }, #[cfg(feature = "pci")] - VirtioError::NoComCfg(id) => write!(f, "Virtio driver failed, for device {id:x}, due to a missing or malformed common config!"), + VirtioError::NoComCfg(id) => write!( + f, + "Virtio driver failed, for device {id:x}, due to a missing or malformed common config!" + ), #[cfg(feature = "pci")] - VirtioError::NoIsrCfg(id) => write!(f, "Virtio driver failed, for device {id:x}, due to a missing or malformed ISR status config!"), + VirtioError::NoIsrCfg(id) => write!( + f, + "Virtio driver failed, for device {id:x}, due to a missing or malformed ISR status config!" + ), #[cfg(feature = "pci")] - VirtioError::NoNotifCfg(id) => write!(f, "Virtio driver failed, for device {id:x}, due to a missing or malformed notification config!"), - VirtioError::DevNotSupported(id) => write!(f, "Device with id {id:#x} not supported."), - #[cfg(all(not(all(target_arch = "x86_64", feature = "rtl8139")), any(feature = "tcp", feature = "udp")))] - VirtioError::NetDriver(net_error) => match net_error { + VirtioError::NoNotifCfg(id) => write!( + f, + "Virtio driver failed, for device {id:x}, due to a missing or malformed notification config!" + ), + VirtioError::DevNotSupported(id) => { + write!(f, "Device with id {id:#x} not supported.") + } + #[cfg(all( + not(all(target_arch = "x86_64", feature = "rtl8139")), + any(feature = "tcp", feature = "udp") + ))] + VirtioError::NetDriver(net_error) => match net_error { #[cfg(feature = "pci")] - VirtioNetError::NoDevCfg(id) => write!(f, "Virtio network driver failed, for device {id:x}, due to a missing or malformed device config!"), - VirtioNetError::FailFeatureNeg(id) => write!(f, "Virtio network driver failed, for device {id:x}, device did not acknowledge negotiated feature set!"), - VirtioNetError::FeatureRequirementsNotMet(features) => write!(f, "Virtio network driver tried to set feature bit without setting dependency feature. Feat set: {features:?}"), - VirtioNetError::IncompatibleFeatureSets(driver_features, device_features) => write!(f, "Feature set: {driver_features:?} , is incompatible with the device features: {device_features:?}"), - }, + VirtioNetError::NoDevCfg(id) => write!( + f, + "Virtio network driver failed, for device {id:x}, due to a missing or malformed device config!" + ), + VirtioNetError::FailFeatureNeg(id) => write!( + f, + "Virtio network driver failed, for device {id:x}, device did not acknowledge negotiated feature set!" + ), + VirtioNetError::FeatureRequirementsNotMet(features) => write!( + f, + "Virtio network driver tried to set feature bit without setting dependency feature. Feat set: {features:?}" + ), + VirtioNetError::IncompatibleFeatureSets(driver_features, device_features) => { + write!( + f, + "Feature set: {driver_features:?} , is incompatible with the device features: {device_features:?}" + ) + } + }, #[cfg(feature = "fuse")] VirtioError::FsDriver(fs_error) => match fs_error { #[cfg(feature = "pci")] - VirtioFsError::NoDevCfg(id) => write!(f, "Virtio filesystem driver failed, for device {id:x}, due to a missing or malformed device config!"), - VirtioFsError::FailFeatureNeg(id) => write!(f, "Virtio filesystem driver failed, for device {id:x}, device did not acknowledge negotiated feature set!"), - VirtioFsError::FeatureRequirementsNotMet(features) => write!(f, "Virtio filesystem driver tried to set feature bit without setting dependency feature. Feat set: {features:?}"), - VirtioFsError::IncompatibleFeatureSets(driver_features, device_features) => write!(f, "Feature set: {driver_features:?} , is incompatible with the device features: {device_features:?}", ), - VirtioFsError::Unknown => write!(f, "Virtio filesystem failed, driver failed due unknown reason!"), + VirtioFsError::NoDevCfg(id) => write!( + f, + "Virtio filesystem driver failed, for device {id:x}, due to a missing or malformed device config!" + ), + VirtioFsError::FailFeatureNeg(id) => write!( + f, + "Virtio filesystem driver failed, for device {id:x}, device did not acknowledge negotiated feature set!" + ), + VirtioFsError::FeatureRequirementsNotMet(features) => write!( + f, + "Virtio filesystem driver tried to set feature bit without setting dependency feature. Feat set: {features:?}" + ), + VirtioFsError::IncompatibleFeatureSets(driver_features, device_features) => { + write!( + f, + "Feature set: {driver_features:?} , is incompatible with the device features: {device_features:?}", + ) + } + VirtioFsError::Unknown => write!( + f, + "Virtio filesystem failed, driver failed due unknown reason!" + ), }, #[cfg(feature = "vsock")] - VirtioError::VsockDriver(vsock_error) => match vsock_error { + VirtioError::VsockDriver(vsock_error) => match vsock_error { + #[cfg(feature = "pci")] + VirtioVsockError::NoDevCfg(id) => write!( + f, + "Virtio socket device driver failed, for device {id:x}, due to a missing or malformed device config!" + ), #[cfg(feature = "pci")] - VirtioVsockError::NoDevCfg(id) => write!(f, "Virtio socket device driver failed, for device {id:x}, due to a missing or malformed device config!"), - #[cfg(feature = "pci")] - VirtioVsockError::NoComCfg(id) => write!(f, "Virtio socket device driver failed, for device {id:x}, due to a missing or malformed common config!"), - #[cfg(feature = "pci")] - VirtioVsockError::NoIsrCfg(id) => write!(f, "Virtio socket device driver failed, for device {id:x}, due to a missing or malformed ISR status config!"), - #[cfg(feature = "pci")] - VirtioVsockError::NoNotifCfg(id) => write!(f, "Virtio socket device driver failed, for device {id:x}, due to a missing or malformed notification config!"), - VirtioVsockError::FailFeatureNeg(id) => write!(f, "Virtio socket device driver failed, for device {id:x}, device did not acknowledge negotiated feature set!"), - VirtioVsockError::FeatureRequirementsNotMet(features) => write!(f, "Virtio socket driver tried to set feature bit without setting dependency feature. Feat set: {features:?}"), - VirtioVsockError::IncompatibleFeatureSets(driver_features, device_features) => write!(f, "Feature set: {driver_features:?} , is incompatible with the device features: {device_features:?}"), - }, - } + VirtioVsockError::NoComCfg(id) => write!( + f, + "Virtio socket device driver failed, for device {id:x}, due to a missing or malformed common config!" + ), + #[cfg(feature = "pci")] + VirtioVsockError::NoIsrCfg(id) => write!( + f, + "Virtio socket device driver failed, for device {id:x}, due to a missing or malformed ISR status config!" + ), + #[cfg(feature = "pci")] + VirtioVsockError::NoNotifCfg(id) => write!( + f, + "Virtio socket device driver failed, for device {id:x}, due to a missing or malformed notification config!" + ), + VirtioVsockError::FailFeatureNeg(id) => write!( + f, + "Virtio socket device driver failed, for device {id:x}, device did not acknowledge negotiated feature set!" + ), + VirtioVsockError::FeatureRequirementsNotMet(features) => write!( + f, + "Virtio socket driver tried to set feature bit without setting dependency feature. Feat set: {features:?}" + ), + VirtioVsockError::IncompatibleFeatureSets(driver_features, device_features) => { + write!( + f, + "Feature set: {driver_features:?} , is incompatible with the device features: {device_features:?}" + ) + } + }, + } } } } diff --git a/src/drivers/virtio/transport/mmio.rs b/src/drivers/virtio/transport/mmio.rs index 06ee3554a7..ce869b2be4 100644 --- a/src/drivers/virtio/transport/mmio.rs +++ b/src/drivers/virtio/transport/mmio.rs @@ -10,15 +10,15 @@ use virtio::mmio::{ DeviceRegisters, DeviceRegistersVolatileFieldAccess, DeviceRegistersVolatileWideFieldAccess, InterruptStatus, NotificationData, }; -use virtio::{le32, DeviceStatus}; +use virtio::{DeviceStatus, le32}; use volatile::access::ReadOnly; use volatile::{VolatilePtr, VolatileRef}; +use crate::drivers::InterruptLine; use crate::drivers::error::DriverError; #[cfg(any(feature = "tcp", feature = "udp"))] use crate::drivers::net::virtio::VirtioNetDriver; use crate::drivers::virtio::error::VirtioError; -use crate::drivers::InterruptLine; pub struct VqCfgHandler<'a> { vq_index: u16, diff --git a/src/drivers/virtio/transport/pci.rs b/src/drivers/virtio/transport/pci.rs index 65439af16d..c0f4bde2c9 100644 --- a/src/drivers/virtio/transport/pci.rs +++ b/src/drivers/virtio/transport/pci.rs @@ -13,7 +13,7 @@ use virtio::pci::{ CapCfgType, CapData, CommonCfg, CommonCfgVolatileFieldAccess, CommonCfgVolatileWideFieldAccess, IsrStatus as IsrStatusRaw, NotificationData, }; -use virtio::{le16, le32, DeviceStatus}; +use virtio::{DeviceStatus, le16, le32}; use volatile::access::ReadOnly; use volatile::{VolatilePtr, VolatileRef}; @@ -27,8 +27,8 @@ use crate::drivers::fs::virtio_fs::VirtioFsDriver; any(feature = "tcp", feature = "udp") ))] use crate::drivers::net::virtio::VirtioNetDriver; -use crate::drivers::pci::error::PciError; use crate::drivers::pci::PciDevice; +use crate::drivers::pci::error::PciError; use crate::drivers::virtio::error::VirtioError; #[cfg(feature = "vsock")] use crate::drivers::vsock::VirtioVsockDriver; @@ -51,7 +51,10 @@ pub fn map_dev_cfg(cap: &PciCap) -> Option<&'static mut T> { // Drivers MAY do this check. See Virtio specification v1.1. - 4.1.4.1 if cap.len() < mem::size_of::().try_into().unwrap() { - error!("Device specific config from device {:x}, does not represent actual structure specified by the standard!", cap.dev_id()); + error!( + "Device specific config from device {:x}, does not represent actual structure specified by the standard!", + cap.dev_id() + ); return None; } @@ -107,17 +110,19 @@ impl PciCap { /// Returns a reference to the actual structure inside the PCI devices memory space. fn map_common_cfg(&self) -> Option> { if self.bar.length < self.len() + self.offset() { - error!("Common config of the capability with id {} of device {:x} does not fit into memory specified by bar {:x}!", - self.cap.id, - self.dev_id, - self.bar.index - ); + error!( + "Common config of the capability with id {} of device {:x} does not fit into memory specified by bar {:x}!", + self.cap.id, self.dev_id, self.bar.index + ); return None; } // Drivers MAY do this check. See Virtio specification v1.1. - 4.1.4.1 if self.len() < mem::size_of::().try_into().unwrap() { - error!("Common config of with id {}, does not represent actual structure specified by the standard!", self.cap.id); + error!( + "Common config of with id {}, does not represent actual structure specified by the standard!", + self.cap.id + ); return None; } @@ -135,11 +140,10 @@ impl PciCap { fn map_isr_status(&self) -> Option> { if self.bar.length < self.len() + self.offset() { - error!("ISR status config with id {} of device {:x}, does not fit into memory specified by bar {:x}!", - self.cap.id, - self.dev_id, - self.bar.index - ); + error!( + "ISR status config with id {} of device {:x}, does not fit into memory specified by bar {:x}!", + self.cap.id, self.dev_id, self.bar.index + ); return None; } @@ -432,11 +436,10 @@ pub struct NotifCfg { impl NotifCfg { fn new(cap: &PciCap) -> Option { if cap.bar.length < cap.len() + cap.offset() { - error!("Notification config with id {} of device {:x}, does not fit into memory specified by bar {:x}!", - cap.cap.id, - cap.dev_id, - cap.bar.index - ); + error!( + "Notification config with id {} of device {:x}, does not fit into memory specified by bar {:x}!", + cap.cap.id, cap.dev_id, cap.bar.index + ); return None; } @@ -572,11 +575,10 @@ pub struct ShMemCfg { impl ShMemCfg { fn new(cap: &PciCap) -> Option { if cap.bar.length < cap.len() + cap.offset() { - error!("Shared memory config of with id {} of device {:x}, does not fit into memory specified by bar {:x}!", - cap.cap.id, - cap.dev_id, - cap.bar.index - ); + error!( + "Shared memory config of with id {} of device {:x}, does not fit into memory specified by bar {:x}!", + cap.cap.id, cap.dev_id, cap.bar.index + ); return None; } @@ -738,7 +740,10 @@ pub(crate) fn map_caps(device: &PciDevice) -> Result com_cfg = Some(ComCfg::new(cap, pci_cap.cap.id)), - None => error!("Common config capability with id {}, of device {:x}, could not be mapped!", pci_cap.cap.id, device_id), + None => error!( + "Common config capability with id {}, of device {:x}, could not be mapped!", + pci_cap.cap.id, device_id + ), } } } @@ -746,7 +751,10 @@ pub(crate) fn map_caps(device: &PciDevice) -> Result notif_cfg = Some(notif), - None => error!("Notification config capability with id {}, of device {device_id:x} could not be used!", pci_cap.cap.id), + None => error!( + "Notification config capability with id {}, of device {device_id:x} could not be used!", + pci_cap.cap.id + ), } } } @@ -754,13 +762,18 @@ pub(crate) fn map_caps(device: &PciDevice) -> Result isr_cfg = Some(IsrStatus::new(isr_stat, pci_cap.cap.id)), - None => error!("ISR status config capability with id {}, of device {device_id:x} could not be used!", pci_cap.cap.id), + None => error!( + "ISR status config capability with id {}, of device {device_id:x} could not be used!", + pci_cap.cap.id + ), } } } CapCfgType::SharedMemory => match ShMemCfg::new(&pci_cap) { Some(sh_mem) => sh_mem_cfg_list.push(sh_mem), - None => error!("Shared Memory config capability with id {}, of device {device_id:x} could not be used!", pci_cap.cap.id, + None => error!( + "Shared Memory config capability with id {}, of device {device_id:x} could not be used!", + pci_cap.cap.id, ), }, CapCfgType::Device => dev_cfg_list.push(pci_cap), diff --git a/src/drivers/virtio/virtqueue/packed.rs b/src/drivers/virtio/virtqueue/packed.rs index 9c98e374dd..ea845f1963 100644 --- a/src/drivers/virtio/virtqueue/packed.rs +++ b/src/drivers/virtio/virtqueue/packed.rs @@ -5,7 +5,7 @@ use alloc::boxed::Box; use alloc::vec::Vec; use core::cell::Cell; -use core::sync::atomic::{fence, Ordering}; +use core::sync::atomic::{Ordering, fence}; use core::{ops, ptr}; use align_address::Align; @@ -16,7 +16,7 @@ use virtio::mmio::NotificationData; use virtio::pci::NotificationData; use virtio::pvirtq::{EventSuppressDesc, EventSuppressFlags}; use virtio::virtq::DescF; -use virtio::{pvirtq, virtq, RingEventFlags}; +use virtio::{RingEventFlags, pvirtq, virtq}; #[cfg(not(feature = "pci"))] use super::super::transport::mmio::{ComCfg, NotifCfg, NotifCtrl}; diff --git a/src/drivers/vsock/mod.rs b/src/drivers/vsock/mod.rs index f6173e627d..19d04f23e8 100644 --- a/src/drivers/vsock/mod.rs +++ b/src/drivers/vsock/mod.rs @@ -9,10 +9,11 @@ use core::mem; use core::mem::MaybeUninit; use pci_types::InterruptLine; -use virtio::vsock::Hdr; use virtio::FeatureBits; +use virtio::vsock::Hdr; use crate::config::VIRTIO_MAX_QUEUE_SIZE; +use crate::drivers::Driver; use crate::drivers::virtio::error::VirtioVsockError; #[cfg(feature = "pci")] use crate::drivers::virtio::transport::pci::{ComCfg, IsrStatus, NotifCfg}; @@ -22,21 +23,17 @@ use crate::drivers::virtio::virtqueue::{ }; #[cfg(feature = "pci")] use crate::drivers::vsock::pci::VsockDevCfgRaw; -use crate::drivers::Driver; use crate::mm::device_alloc::DeviceAlloc; fn fill_queue(vq: &mut dyn Virtq, num_packets: u16, packet_size: u32) { for _ in 0..num_packets { - let buff_tkn = match AvailBufferToken::new( - vec![], - vec![ - BufferElem::Sized(Box::::new_uninit_in(DeviceAlloc)), - BufferElem::Vector(Vec::with_capacity_in( - packet_size.try_into().unwrap(), - DeviceAlloc, - )), - ], - ) { + let buff_tkn = match AvailBufferToken::new(vec![], vec![ + BufferElem::Sized(Box::::new_uninit_in(DeviceAlloc)), + BufferElem::Vector(Vec::with_capacity_in( + packet_size.try_into().unwrap(), + DeviceAlloc, + )), + ]) { Ok(tkn) => tkn, Err(_vq_err) => { error!("Setup of network queue failed, which should not happen!"); diff --git a/src/entropy.rs b/src/entropy.rs index d30fefd6ee..7cf54dac61 100644 --- a/src/entropy.rs +++ b/src/entropy.rs @@ -4,8 +4,8 @@ //! with random data provided by the processor. use hermit_sync::InterruptTicketMutex; -use rand_chacha::rand_core::{RngCore, SeedableRng}; use rand_chacha::ChaCha20Rng; +use rand_chacha::rand_core::{RngCore, SeedableRng}; use crate::arch::kernel::processor::{get_timer_ticks, seed_entropy}; use crate::errno::ENOSYS; diff --git a/src/env.rs b/src/env.rs index 9a00f508d1..92860a9407 100644 --- a/src/env.rs +++ b/src/env.rs @@ -6,8 +6,8 @@ use core::{ptr, str}; use ahash::RandomState; use fdt::Fdt; -use hashbrown::hash_map::Iter; use hashbrown::HashMap; +use hashbrown::hash_map::Iter; use hermit_entry::boot_info::{BootInfo, PlatformInfo, RawBootInfo}; use hermit_sync::OnceCell; diff --git a/src/executor/device.rs b/src/executor/device.rs index f6ff748f78..41b7568618 100644 --- a/src/executor/device.rs +++ b/src/executor/device.rs @@ -55,7 +55,9 @@ impl<'a> NetworkInterface<'a> { let mut device = HermitNet::new(mtu, checksums.clone()); if hermit_var!("HERMIT_IP").is_some() { - warn!("A static IP address is specified with the environment variable HERMIT_IP, but the device is configured to use DHCPv4!"); + warn!( + "A static IP address is specified with the environment variable HERMIT_IP, but the device is configured to use DHCPv4!" + ); } let ethernet_addr = EthernetAddress([mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]]); diff --git a/src/executor/network.rs b/src/executor/network.rs index 6630daf6aa..f098ed9aa7 100644 --- a/src/executor/network.rs +++ b/src/executor/network.rs @@ -7,6 +7,7 @@ use core::task::Poll; use hermit_sync::InterruptTicketMutex; use smoltcp::iface::{PollResult, SocketHandle, SocketSet}; +use smoltcp::socket::AnySocket; #[cfg(feature = "dhcpv4")] use smoltcp::socket::dhcpv4; #[cfg(feature = "dns")] @@ -15,7 +16,6 @@ use smoltcp::socket::dns::{self, GetQueryResultError, QueryHandle}; use smoltcp::socket::tcp; #[cfg(feature = "udp")] use smoltcp::socket::udp; -use smoltcp::socket::AnySocket; use smoltcp::time::{Duration, Instant}; #[cfg(feature = "dns")] use smoltcp::wire::{DnsQueryType, IpAddress}; diff --git a/src/executor/vsock.rs b/src/executor/vsock.rs index a2bed4154d..42500dd57a 100644 --- a/src/executor/vsock.rs +++ b/src/executor/vsock.rs @@ -11,7 +11,7 @@ use virtio::{le16, le32}; use crate::arch::kernel::mmio as hardware; #[cfg(feature = "pci")] use crate::drivers::pci as hardware; -use crate::executor::{spawn, WakerRegistration}; +use crate::executor::{WakerRegistration, spawn}; use crate::io; use crate::io::Error::EADDRINUSE; diff --git a/src/fd/eventfd.rs b/src/fd/eventfd.rs index 9100b1bb16..e35f41f23f 100644 --- a/src/fd/eventfd.rs +++ b/src/fd/eventfd.rs @@ -2,7 +2,7 @@ use alloc::boxed::Box; use alloc::collections::vec_deque::VecDeque; use core::future::{self, Future}; use core::mem; -use core::task::{ready, Poll, Waker}; +use core::task::{Poll, Waker, ready}; use async_lock::Mutex; use async_trait::async_trait; diff --git a/src/fd/socket/tcp.rs b/src/fd/socket/tcp.rs index 1b8a477c73..46a8b4ed54 100644 --- a/src/fd/socket/tcp.rs +++ b/src/fd/socket/tcp.rs @@ -13,7 +13,7 @@ use smoltcp::time::Duration; use crate::executor::block_on; use crate::executor::network::{Handle, NIC}; use crate::fd::{Endpoint, IoCtl, ListenEndpoint, ObjectInterface, PollEvent, SocketOption}; -use crate::{io, DEFAULT_KEEP_ALIVE_INTERVAL}; +use crate::{DEFAULT_KEEP_ALIVE_INTERVAL, io}; /// further receives will be disallowed pub const SHUT_RD: i32 = 0; diff --git a/src/fd/socket/vsock.rs b/src/fd/socket/vsock.rs index b8330523a4..30f957182d 100644 --- a/src/fd/socket/vsock.rs +++ b/src/fd/socket/vsock.rs @@ -12,7 +12,7 @@ use virtio::{le16, le32, le64}; use crate::arch::kernel::mmio as hardware; #[cfg(feature = "pci")] use crate::drivers::pci as hardware; -use crate::executor::vsock::{VsockState, VSOCK_MAP}; +use crate::executor::vsock::{VSOCK_MAP, VsockState}; use crate::fd::{Endpoint, IoCtl, ListenEndpoint, ObjectInterface, PollEvent}; use crate::io::{self, Error}; diff --git a/src/fs/fuse.rs b/src/fs/fuse.rs index 124d15a0b0..1943c0d850 100644 --- a/src/fs/fuse.rs +++ b/src/fs/fuse.rs @@ -95,14 +95,11 @@ pub(crate) mod ops { impl Init { pub(crate) fn create() -> (Cmd, u32) { - let cmd = Cmd::new( - FUSE_ROOT_ID, - fuse_init_in { - major: 7, - minor: 31, - ..Default::default() - }, - ); + let cmd = Cmd::new(FUSE_ROOT_ID, fuse_init_in { + major: 7, + minor: 31, + ..Default::default() + }); (cmd, 0) } } @@ -147,13 +144,10 @@ pub(crate) mod ops { impl Open { pub(crate) fn create(nid: u64, flags: u32) -> (Cmd, u32) { - let cmd = Cmd::new( - nid, - fuse_open_in { - flags, - ..Default::default() - }, - ); + let cmd = Cmd::new(nid, fuse_open_in { + flags, + ..Default::default() + }); (cmd, 0) } } @@ -198,15 +192,12 @@ pub(crate) mod ops { impl Read { pub(crate) fn create(nid: u64, fh: u64, size: u32, offset: u64) -> (Cmd, u32) { - let cmd = Cmd::new( - nid, - fuse_read_in { - fh, - offset, - size, - ..Default::default() - }, - ); + let cmd = Cmd::new(nid, fuse_read_in { + fh, + offset, + size, + ..Default::default() + }); (cmd, size) } } @@ -229,15 +220,12 @@ pub(crate) mod ops { offset: isize, whence: SeekWhence, ) -> (Cmd, u32) { - let cmd = Cmd::new( - nid, - fuse_lseek_in { - fh, - offset: offset.try_into().unwrap(), - whence: num::ToPrimitive::to_u32(&whence).unwrap(), - ..Default::default() - }, - ); + let cmd = Cmd::new(nid, fuse_lseek_in { + fh, + offset: offset.try_into().unwrap(), + whence: num::ToPrimitive::to_u32(&whence).unwrap(), + ..Default::default() + }); (cmd, 0) } } @@ -255,14 +243,11 @@ pub(crate) mod ops { impl Getattr { pub(crate) fn create(nid: u64, fh: u64, getattr_flags: u32) -> (Cmd, u32) { - let cmd = Cmd::new( - nid, - fuse_getattr_in { - getattr_flags, - fh, - ..Default::default() - }, - ); + let cmd = Cmd::new(nid, fuse_getattr_in { + getattr_flags, + fh, + ..Default::default() + }); (cmd, 0) } } @@ -298,13 +283,10 @@ pub(crate) mod ops { impl Release { pub(crate) fn create(nid: u64, fh: u64) -> (Cmd, u32) { - let cmd = Cmd::new( - nid, - fuse_release_in { - fh, - ..Default::default() - }, - ); + let cmd = Cmd::new(nid, fuse_release_in { + fh, + ..Default::default() + }); (cmd, 0) } } @@ -322,15 +304,12 @@ pub(crate) mod ops { impl Poll { pub(crate) fn create(nid: u64, fh: u64, kh: u64, event: PollEvent) -> (Cmd, u32) { - let cmd = Cmd::new( - nid, - fuse_poll_in { - fh, - kh, - events: event.bits() as u32, - ..Default::default() - }, - ); + let cmd = Cmd::new(nid, fuse_poll_in { + fh, + kh, + events: event.bits() as u32, + ..Default::default() + }); (cmd, 0) } } @@ -1279,7 +1258,9 @@ pub(crate) fn init() { entries.retain(|x| x != ".."); entries.retain(|x| x != "tmp"); entries.retain(|x| x != "proc"); - warn!("Fuse don't mount the host directories 'tmp' and 'proc' into the guest file system!"); + warn!( + "Fuse don't mount the host directories 'tmp' and 'proc' into the guest file system!" + ); for i in entries { let i_cstr = CString::new(i.clone()).unwrap(); diff --git a/src/fs/mod.rs b/src/fs/mod.rs index 770f7d0306..3a774fad3e 100644 --- a/src/fs/mod.rs +++ b/src/fs/mod.rs @@ -12,10 +12,10 @@ use async_trait::async_trait; use hermit_sync::OnceCell; use mem::MemDirectory; -use crate::fd::{insert_object, remove_object, AccessPermission, ObjectInterface, OpenOption}; +use crate::fd::{AccessPermission, ObjectInterface, OpenOption, insert_object, remove_object}; use crate::io; use crate::io::Write; -use crate::time::{timespec, SystemTime}; +use crate::time::{SystemTime, timespec}; static FILESYSTEM: OnceCell = OnceCell::new(); diff --git a/src/scheduler/mod.rs b/src/scheduler/mod.rs index 1cc50c4f5e..98c7bc7076 100644 --- a/src/scheduler/mod.rs +++ b/src/scheduler/mod.rs @@ -12,8 +12,8 @@ use core::ptr; #[cfg(all(target_arch = "x86_64", feature = "smp"))] use core::sync::atomic::AtomicBool; use core::sync::atomic::{AtomicI32, AtomicU32, Ordering}; -use core::task::ready; use core::task::Poll::Ready; +use core::task::ready; use ahash::RandomState; use crossbeam_utils::Backoff; @@ -149,15 +149,12 @@ impl PerCoreSchedulerExt for &mut PerCoreScheduler { } let reschedid = IntId::sgi(SGI_RESCHED.into()); - GicV3::send_sgi( - reschedid, - SgiTarget::List { - affinity3: 0, - affinity2: 0, - affinity1: 0, - target_list: 0b1, - }, - ); + GicV3::send_sgi(reschedid, SgiTarget::List { + affinity3: 0, + affinity2: 0, + affinity1: 0, + target_list: 0b1, + }); interrupts::enable(); } diff --git a/src/scheduler/task.rs b/src/scheduler/task.rs index c9c89b0e0e..45eb7f8927 100644 --- a/src/scheduler/task.rs +++ b/src/scheduler/task.rs @@ -659,11 +659,7 @@ impl BlockedTaskQueue { |node| match node.wakeup_time { Some(wt) => { if let Some(timer) = self.network_wakeup_time { - if wt < timer { - Some(wt) - } else { - Some(timer) - } + if wt < timer { Some(wt) } else { Some(timer) } } else { Some(wt) } @@ -734,11 +730,7 @@ impl BlockedTaskQueue { |node| match node.wakeup_time { Some(wt) => { if let Some(timer) = self.network_wakeup_time { - if wt < timer { - Some(wt) - } else { - Some(timer) - } + if wt < timer { Some(wt) } else { Some(timer) } } else { Some(wt) } diff --git a/src/shell.rs b/src/shell.rs index f9771ec625..78ea0b356c 100644 --- a/src/shell.rs +++ b/src/shell.rs @@ -10,36 +10,27 @@ pub(crate) fn init() { let (print, read) = (|s: &str| print!("{}", s), read); let mut shell = Shell::new(print, read); - shell.commands.insert( - "help", - ShellCommand { - help: "Print this help message", - func: |_, shell| { - shell.print_help_screen(); - Ok(()) - }, - aliases: &["?", "h"], + shell.commands.insert("help", ShellCommand { + help: "Print this help message", + func: |_, shell| { + shell.print_help_screen(); + Ok(()) }, - ); - shell.commands.insert( - "interrupts", - ShellCommand { - help: "Shows the number of received interrupts", - func: |_, _| { - print_statistics(); - Ok(()) - }, - aliases: &["i"], + aliases: &["?", "h"], + }); + shell.commands.insert("interrupts", ShellCommand { + help: "Shows the number of received interrupts", + func: |_, _| { + print_statistics(); + Ok(()) }, - ); - shell.commands.insert( - "shutdown", - ShellCommand { - help: "Shutdown HermitOS", - func: |_, _| crate::scheduler::shutdown(0), - aliases: &["s"], - }, - ); + aliases: &["i"], + }); + shell.commands.insert("shutdown", ShellCommand { + help: "Shutdown HermitOS", + func: |_, _| crate::scheduler::shutdown(0), + aliases: &["s"], + }); // Also supports async crate::executor::spawn(async move { shell.run_async().await }); diff --git a/src/synch/futex.rs b/src/synch/futex.rs index 26ffa32f8c..b923b94eb4 100644 --- a/src/synch/futex.rs +++ b/src/synch/futex.rs @@ -2,15 +2,15 @@ use core::sync::atomic::AtomicU32; use core::sync::atomic::Ordering::SeqCst; use ahash::RandomState; -use hashbrown::hash_map::Entry; use hashbrown::HashMap; +use hashbrown::hash_map::Entry; use hermit_sync::InterruptTicketMutex; use crate::arch::kernel::core_local::core_scheduler; use crate::arch::kernel::processor::get_timer_ticks; use crate::errno::{EAGAIN, EINVAL, ETIMEDOUT}; -use crate::scheduler::task::TaskHandlePriorityQueue; use crate::scheduler::PerCoreSchedulerExt; +use crate::scheduler::task::TaskHandlePriorityQueue; // TODO: Replace with a concurrent hashmap. static PARKING_LOT: InterruptTicketMutex> = diff --git a/src/synch/recmutex.rs b/src/synch/recmutex.rs index 441139b236..07688594cd 100644 --- a/src/synch/recmutex.rs +++ b/src/synch/recmutex.rs @@ -1,8 +1,8 @@ use hermit_sync::TicketMutex; use crate::arch::core_local::*; -use crate::scheduler::task::{TaskHandlePriorityQueue, TaskId}; use crate::scheduler::PerCoreSchedulerExt; +use crate::scheduler::task::{TaskHandlePriorityQueue, TaskId}; struct RecursiveMutexState { current_tid: Option, diff --git a/src/synch/semaphore.rs b/src/synch/semaphore.rs index 1c508fb8a0..1ae739eacf 100644 --- a/src/synch/semaphore.rs +++ b/src/synch/semaphore.rs @@ -3,8 +3,8 @@ use crossbeam_utils::Backoff; use hermit_sync::InterruptTicketMutex; use crate::arch::core_local::*; -use crate::scheduler::task::TaskHandlePriorityQueue; use crate::scheduler::PerCoreSchedulerExt; +use crate::scheduler::task::TaskHandlePriorityQueue; struct SemaphoreState { /// Resource available count diff --git a/src/syscalls/mod.rs b/src/syscalls/mod.rs index aa9558ad19..3d6107bbe1 100644 --- a/src/syscalls/mod.rs +++ b/src/syscalls/mod.rs @@ -2,7 +2,7 @@ #[cfg(all(target_os = "none", not(feature = "common-os")))] use core::alloc::{GlobalAlloc, Layout}; -use core::ffi::{c_char, CStr}; +use core::ffi::{CStr, c_char}; use core::marker::PhantomData; use core::ptr; @@ -21,8 +21,8 @@ pub use self::tasks::*; pub use self::timer::*; use crate::executor::block_on; use crate::fd::{ - dup_object, get_object, remove_object, AccessPermission, EventFlags, FileDescriptor, IoCtl, - OpenOption, PollFd, + AccessPermission, EventFlags, FileDescriptor, IoCtl, OpenOption, PollFd, dup_object, + get_object, remove_object, }; use crate::fs::{self, FileAttr}; #[cfg(all(target_os = "none", not(feature = "common-os")))] @@ -101,9 +101,7 @@ pub extern "C" fn sys_alloc(size: usize, align: usize) -> *mut u8 { trace!( "__sys_alloc: allocate memory at {:p} (size {:#x}, align {:#x})", - ptr, - size, - align + ptr, size, align ); ptr @@ -126,9 +124,7 @@ pub extern "C" fn sys_alloc_zeroed(size: usize, align: usize) -> *mut u8 { trace!( "__sys_alloc_zeroed: allocate memory at {:p} (size {:#x}, align {:#x})", - ptr, - size, - align + ptr, size, align ); ptr @@ -151,9 +147,7 @@ pub extern "C" fn sys_malloc(size: usize, align: usize) -> *mut u8 { trace!( "__sys_malloc: allocate memory at {:p} (size {:#x}, align {:#x})", - ptr, - size, - align + ptr, size, align ); ptr @@ -191,9 +185,9 @@ pub unsafe extern "C" fn sys_realloc( let layout_res = Layout::from_size_align(size, align); if layout_res.is_err() || size == 0 || new_size == 0 { warn!( - "__sys_realloc called with ptr {:p}, size {:#x}, align {:#x}, new_size {:#x} is an invalid layout!", - ptr, size, align, new_size - ); + "__sys_realloc called with ptr {:p}, size {:#x}, align {:#x}, new_size {:#x} is an invalid layout!", + ptr, size, align, new_size + ); return core::ptr::null_mut(); } let layout = layout_res.unwrap(); @@ -201,14 +195,13 @@ pub unsafe extern "C" fn sys_realloc( if new_ptr.is_null() { debug!( - "__sys_realloc failed to resize ptr {:p} with size {:#x}, align {:#x}, new_size {:#x} !", - ptr, size, align, new_size - ); + "__sys_realloc failed to resize ptr {:p} with size {:#x}, align {:#x}, new_size {:#x} !", + ptr, size, align, new_size + ); } else { trace!( "__sys_realloc: resized memory at {:p}, new address {:p}", - ptr, - new_ptr + ptr, new_ptr ); } new_ptr @@ -241,8 +234,7 @@ pub unsafe extern "C" fn sys_dealloc(ptr: *mut u8, size: usize, align: usize) { } else { trace!( "sys_free: deallocate memory at {:p} (size {:#x})", - ptr, - size + ptr, size ); } let layout = layout_res.unwrap(); @@ -266,8 +258,7 @@ pub unsafe extern "C" fn sys_free(ptr: *mut u8, size: usize, align: usize) { } else { trace!( "sys_free: deallocate memory at {:p} (size {:#x})", - ptr, - size + ptr, size ); } let layout = layout_res.unwrap(); diff --git a/src/syscalls/semaphore.rs b/src/syscalls/semaphore.rs index 4fe7e46fba..4ef6df90ca 100644 --- a/src/syscalls/semaphore.rs +++ b/src/syscalls/semaphore.rs @@ -2,7 +2,7 @@ use alloc::boxed::Box; use crate::errno::*; use crate::synch::semaphore::Semaphore; -use crate::syscalls::{sys_clock_gettime, CLOCK_REALTIME}; +use crate::syscalls::{CLOCK_REALTIME, sys_clock_gettime}; use crate::time::timespec; #[allow(non_camel_case_types)] @@ -100,11 +100,7 @@ unsafe fn sem_timedwait(sem: *mut sem_t, ms: u32) -> i32 { // Get a reference to the given semaphore and wait until we have acquired it or the wakeup time has elapsed. let semaphore = unsafe { &**sem }; - if semaphore.acquire(delay) { - 0 - } else { - -ETIME - } + if semaphore.acquire(delay) { 0 } else { -ETIME } } /// Try to acquire a lock on a semaphore. diff --git a/src/syscalls/socket.rs b/src/syscalls/socket.rs index 99604732f2..0f50e31157 100644 --- a/src/syscalls/socket.rs +++ b/src/syscalls/socket.rs @@ -12,7 +12,7 @@ use smoltcp::wire::{IpAddress, IpEndpoint, IpListenEndpoint}; use crate::errno::*; #[cfg(any(feature = "tcp", feature = "udp"))] -use crate::executor::network::{NetworkState, NIC}; +use crate::executor::network::{NIC, NetworkState}; #[cfg(feature = "tcp")] use crate::fd::socket::tcp; #[cfg(feature = "udp")] @@ -20,9 +20,9 @@ use crate::fd::socket::udp; #[cfg(feature = "vsock")] use crate::fd::socket::vsock::{self, VsockEndpoint, VsockListenEndpoint}; use crate::fd::{ - get_object, insert_object, Endpoint, ListenEndpoint, ObjectInterface, SocketOption, + Endpoint, ListenEndpoint, ObjectInterface, SocketOption, get_object, insert_object, }; -use crate::syscalls::{block_on, IoCtl}; +use crate::syscalls::{IoCtl, block_on}; pub const AF_INET: i32 = 0; pub const AF_INET6: i32 = 1; diff --git a/src/syscalls/tasks.rs b/src/syscalls/tasks.rs index ea47fa7d01..9b636c54ed 100644 --- a/src/syscalls/tasks.rs +++ b/src/syscalls/tasks.rs @@ -6,8 +6,8 @@ use crate::arch::core_local::*; use crate::arch::processor::{get_frequency, get_timestamp}; use crate::config::USER_STACK_SIZE; use crate::errno::*; -use crate::scheduler::task::{Priority, TaskHandle, TaskId}; use crate::scheduler::PerCoreSchedulerExt; +use crate::scheduler::task::{Priority, TaskHandle, TaskId}; use crate::time::timespec; use crate::{arch, scheduler}; diff --git a/xtask/Cargo.toml b/xtask/Cargo.toml index 49e315fd53..dbf256ea87 100644 --- a/xtask/Cargo.toml +++ b/xtask/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "xtask" version = "0.1.0" -edition = "2021" +edition = "2024" [dependencies] anyhow = "1.0" diff --git a/xtask/src/ci/qemu.rs b/xtask/src/ci/qemu.rs index b51ca787f8..01a77a07ae 100644 --- a/xtask/src/ci/qemu.rs +++ b/xtask/src/ci/qemu.rs @@ -6,7 +6,7 @@ use std::str::from_utf8; use std::time::Duration; use std::{env, fs, thread}; -use anyhow::{bail, ensure, Context, Result}; +use anyhow::{Context, Result, bail, ensure}; use clap::{Args, ValueEnum}; use sysinfo::{CpuRefreshKind, System}; use wait_timeout::ChildExt; @@ -296,7 +296,9 @@ impl Qemu { "-chardev".to_string(), "socket,id=char0,path=./vhostqemu".to_string(), "-device".to_string(), - format!("vhost-user-fs-pci,queue-size=1024{default_virtio_features},chardev=char0,tag=root"), + format!( + "vhost-user-fs-pci,queue-size=1024{default_virtio_features},chardev=char0,tag=root" + ), "-object".to_string(), format!("memory-backend-file,id=mem,size={memory}M,mem-path=/dev/shm,share=on"), "-numa".to_string(), @@ -321,7 +323,10 @@ fn spawn_virtiofsd() -> Result { sh.create_dir("shared")?; - let cmd = cmd!(sh, "virtiofsd --socket-path=./vhostqemu --shared-dir ./shared --announce-submounts --sandbox none --seccomp none --inode-file-handles=never"); + let cmd = cmd!( + sh, + "virtiofsd --socket-path=./vhostqemu --shared-dir ./shared --announce-submounts --sandbox none --seccomp none --inode-file-handles=never" + ); eprintln!("$ {cmd}"); diff --git a/xtask/src/doc.rs b/xtask/src/doc.rs index 57ffadfc12..f0eedd9501 100644 --- a/xtask/src/doc.rs +++ b/xtask/src/doc.rs @@ -15,8 +15,11 @@ impl Doc { for arch in Arch::all() { arch.install()?; let triple = arch.triple(); - cmd!(sh, "cargo doc --package hermit-kernel --no-deps --document-private-items --target={triple}") - .run()?; + cmd!( + sh, + "cargo doc --package hermit-kernel --no-deps --document-private-items --target={triple}" + ) + .run()?; } Ok(())