From d01f93ca8fe6f0ccc878c759bd9ba005ebedc9d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Thu, 2 Jan 2025 12:33:02 +0100 Subject: [PATCH 1/6] fix: use `#[unsafe(no_mangle)]` --- hermit-builtins/src/math.rs | 8 ++-- hermit-macro/src/system.rs | 29 +++++++------- src/arch/aarch64/kernel/interrupts.rs | 10 ++--- src/arch/aarch64/kernel/scheduler.rs | 2 +- src/arch/aarch64/kernel/start.rs | 4 +- src/arch/riscv64/kernel/interrupts.rs | 2 +- src/arch/riscv64/kernel/scheduler.rs | 4 +- src/arch/riscv64/kernel/start.rs | 2 +- src/arch/x86_64/kernel/mod.rs | 2 +- src/arch/x86_64/kernel/start.rs | 2 +- src/arch/x86_64/kernel/syscall.rs | 2 +- src/errno.rs | 4 +- src/lib.rs | 2 +- src/syscalls/condvar.rs | 10 ++--- src/syscalls/entropy.rs | 10 ++--- src/syscalls/futex.rs | 4 +- src/syscalls/mmap.rs | 6 +-- src/syscalls/mod.rs | 54 +++++++++++++-------------- src/syscalls/processor.rs | 6 +-- src/syscalls/recmutex.rs | 8 ++-- src/syscalls/semaphore.rs | 10 ++--- src/syscalls/socket.rs | 38 +++++++++---------- src/syscalls/spinlock.rs | 16 ++++---- src/syscalls/system.rs | 2 +- src/syscalls/table.rs | 4 +- src/syscalls/tasks.rs | 44 +++++++++++----------- src/syscalls/timer.rs | 12 +++--- tests/basic_math.rs | 2 +- tests/basic_mem.rs | 2 +- tests/basic_print.rs | 2 +- tests/common/mod.rs | 2 +- tests/measure_startup_time.rs | 2 +- tests/thread.rs | 2 +- 33 files changed, 156 insertions(+), 153 deletions(-) diff --git a/hermit-builtins/src/math.rs b/hermit-builtins/src/math.rs index ad3cca5a16..4edc0737e0 100644 --- a/hermit-builtins/src/math.rs +++ b/hermit-builtins/src/math.rs @@ -5,7 +5,7 @@ macro_rules! export { ($(fn $fn:ident($($arg:ident: $argty:ty),+) -> $retty:ty;)+) => { $( - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn $fn($($arg: $argty),+) -> $retty { ::libm::$fn($($arg),+) } @@ -133,7 +133,7 @@ export! { macro_rules! export_out_param { ($(fn $fn:ident($($arg:ident: $argty:ty),+; $out:ident: $outty:ty) -> $retty:ty;)+) => { $( - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn $fn($($arg: $argty),+, $out: $outty) -> $retty { let (ret, out) = ::libm::$fn($($arg),+); *$out = out; @@ -154,12 +154,12 @@ export_out_param! { fn remquof(x: f32, y: f32; n: &mut i32) -> f32; } -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn sincos(x: f64, s: &mut f64, c: &mut f64) { (*s, *c) = libm::sincos(x); } -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn sincosf(x: f32, s: &mut f32, c: &mut f32) { (*s, *c) = libm::sincosf(x); } diff --git a/hermit-macro/src/system.rs b/hermit-macro/src/system.rs index 0bc144e99d..df3de042e4 100644 --- a/hermit-macro/src/system.rs +++ b/hermit-macro/src/system.rs @@ -61,24 +61,27 @@ fn parse_sig(sig: &Signature) -> Result { fn validate_attrs(attrs: &[Attribute]) -> Result<()> { let mut no_mangle_found = false; for attr in attrs { - if !attr.path().is_ident("cfg") - && !attr.path().is_ident("doc") - && !attr.path().is_ident("no_mangle") - { + if attr.path().is_ident("unsafe") { + if let Ok(ident) = attr.parse_args::() { + if ident == "no_mangle" { + no_mangle_found = true; + continue; + } + } + } + + if !attr.path().is_ident("cfg") && !attr.path().is_ident("doc") { bail!( attr, - "#[system] functions may only have `#[doc]`, `#[no_mangle]` and `#[cfg]` attributes" + "#[system] functions may only have `#[doc]`, `#[unsafe(no_mangle)]` and `#[cfg]` attributes" ); } - if attr.path().is_ident("no_mangle") { - no_mangle_found = true; - } } if !no_mangle_found { bail!( attrs.first(), - "#[system] functions must have `#[no_mangle]` attribute" + "#[system] functions must have `#[unsafe(no_mangle)]` attribute" ); } @@ -174,7 +177,7 @@ mod tests { /// /// This is very important. #[cfg(target_os = "none")] - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn sys_test(a: i8, b: i16) -> i32 { let c = i16::from(a) + b; i32::from(c) @@ -186,7 +189,7 @@ mod tests { /// /// This is very important. #[cfg(target_os = "none")] - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn sys_test(a: i8, b: i16) -> i32 { extern "C" fn __sys_test(a: i8, b: i16) -> i32 { #[allow(unreachable_code)] @@ -222,7 +225,7 @@ mod tests { /// /// This is very important. #[cfg(target_os = "none")] - #[no_mangle] + #[unsafe(no_mangle)] pub unsafe extern "C" fn sys_test(a: i8, b: i16) -> i32 { let c = i16::from(a) + b; i32::from(c) @@ -234,7 +237,7 @@ mod tests { /// /// This is very important. #[cfg(target_os = "none")] - #[no_mangle] + #[unsafe(no_mangle)] pub unsafe extern "C" fn sys_test(a: i8, b: i16) -> i32 { unsafe extern "C" fn __sys_test(a: i8, b: i16) -> i32 { #[allow(unreachable_code)] diff --git a/src/arch/aarch64/kernel/interrupts.rs b/src/arch/aarch64/kernel/interrupts.rs index b61c84d0ed..f60f71b032 100644 --- a/src/arch/aarch64/kernel/interrupts.rs +++ b/src/arch/aarch64/kernel/interrupts.rs @@ -114,7 +114,7 @@ pub(crate) fn install_handlers() { INTERRUPT_HANDLERS.set(handlers).unwrap(); } -#[no_mangle] +#[unsafe(no_mangle)] pub(crate) extern "C" fn do_fiq(_state: &State) -> *mut usize { if let Some(irqid) = GicV3::get_and_acknowledge_interrupt() { let vector: u8 = u32::from(irqid).try_into().unwrap(); @@ -142,7 +142,7 @@ pub(crate) extern "C" fn do_fiq(_state: &State) -> *mut usize { core::ptr::null_mut() } -#[no_mangle] +#[unsafe(no_mangle)] pub(crate) extern "C" fn do_irq(_state: &State) -> *mut usize { if let Some(irqid) = GicV3::get_and_acknowledge_interrupt() { let vector: u8 = u32::from(irqid).try_into().unwrap(); @@ -170,7 +170,7 @@ pub(crate) extern "C" fn do_irq(_state: &State) -> *mut usize { core::ptr::null_mut() } -#[no_mangle] +#[unsafe(no_mangle)] pub(crate) extern "C" fn do_sync(state: &State) { let irqid = GicV3::get_and_acknowledge_interrupt().unwrap(); let esr = ESR_EL1.get(); @@ -206,14 +206,14 @@ pub(crate) extern "C" fn do_sync(state: &State) { } } -#[no_mangle] +#[unsafe(no_mangle)] pub(crate) extern "C" fn do_bad_mode(_state: &State, reason: u32) -> ! { error!("Receive unhandled exception: {}", reason); scheduler::abort() } -#[no_mangle] +#[unsafe(no_mangle)] pub(crate) extern "C" fn do_error(_state: &State) -> ! { error!("Receive error interrupt"); diff --git a/src/arch/aarch64/kernel/scheduler.rs b/src/arch/aarch64/kernel/scheduler.rs index 73937a4757..6f7360aaee 100644 --- a/src/arch/aarch64/kernel/scheduler.rs +++ b/src/arch/aarch64/kernel/scheduler.rs @@ -401,7 +401,7 @@ impl TaskFrame for Task { } } -#[no_mangle] +#[unsafe(no_mangle)] pub(crate) extern "C" fn get_last_stack_pointer() -> u64 { core_scheduler().get_last_stack_pointer().as_u64() } diff --git a/src/arch/aarch64/kernel/start.rs b/src/arch/aarch64/kernel/start.rs index 261ddd1027..be9dbcd176 100644 --- a/src/arch/aarch64/kernel/start.rs +++ b/src/arch/aarch64/kernel/start.rs @@ -11,7 +11,7 @@ extern "C" { } /// Entrypoint - Initialize Stack pointer and Exception Table -#[no_mangle] +#[unsafe(no_mangle)] #[naked] pub unsafe extern "C" fn _start(boot_info: Option<&'static RawBootInfo>, cpu_id: u32) -> ! { // validate signatures @@ -50,7 +50,7 @@ pub unsafe extern "C" fn _start(boot_info: Option<&'static RawBootInfo>, cpu_id: } #[inline(never)] -#[no_mangle] +#[unsafe(no_mangle)] unsafe extern "C" fn pre_init(boot_info: Option<&'static RawBootInfo>, cpu_id: u32) -> ! { // set exception table unsafe { diff --git a/src/arch/riscv64/kernel/interrupts.rs b/src/arch/riscv64/kernel/interrupts.rs index bb5bdc5328..40f123084d 100644 --- a/src/arch/riscv64/kernel/interrupts.rs +++ b/src/arch/riscv64/kernel/interrupts.rs @@ -150,7 +150,7 @@ pub(crate) fn install_handlers() { /// Dispatch and handle interrupt. /// /// This function is called from `trap.S` which is in the trapframe crate. -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn trap_handler(tf: &mut TrapFrame) { let scause = scause::read(); let cause = scause.cause(); diff --git a/src/arch/riscv64/kernel/scheduler.rs b/src/arch/riscv64/kernel/scheduler.rs index bf2bbb2e20..b489a36c30 100644 --- a/src/arch/riscv64/kernel/scheduler.rs +++ b/src/arch/riscv64/kernel/scheduler.rs @@ -341,7 +341,7 @@ impl Drop for TaskTLS { } } -#[no_mangle] +#[unsafe(no_mangle)] extern "C" fn task_entry(func: extern "C" fn(usize), arg: usize) { use crate::scheduler::PerCoreSchedulerExt; @@ -446,7 +446,7 @@ pub fn wakeup_handler() { } #[inline(never)] -#[no_mangle] +#[unsafe(no_mangle)] pub fn set_current_kernel_stack() { core_scheduler().set_current_kernel_stack(); } diff --git a/src/arch/riscv64/kernel/start.rs b/src/arch/riscv64/kernel/start.rs index cbef7262a5..23205a4b63 100644 --- a/src/arch/riscv64/kernel/start.rs +++ b/src/arch/riscv64/kernel/start.rs @@ -14,7 +14,7 @@ use crate::{env, KERNEL_STACK_SIZE}; //static mut BOOT_STACK: [u8; KERNEL_STACK_SIZE] = [0; KERNEL_STACK_SIZE]; /// Entrypoint - Initialize Stack pointer and Exception Table -#[no_mangle] +#[unsafe(no_mangle)] #[naked] pub unsafe extern "C" fn _start(hart_id: usize, boot_info: Option<&'static RawBootInfo>) -> ! { // validate signatures diff --git a/src/arch/x86_64/kernel/mod.rs b/src/arch/x86_64/kernel/mod.rs index 53c93eb907..1e71a1b774 100644 --- a/src/arch/x86_64/kernel/mod.rs +++ b/src/arch/x86_64/kernel/mod.rs @@ -255,7 +255,7 @@ pub static CURRENT_STACK_ADDRESS: AtomicPtr = AtomicPtr::new(ptr::null_mut() #[cfg(target_os = "none")] #[inline(never)] -#[no_mangle] +#[unsafe(no_mangle)] unsafe extern "C" fn pre_init(boot_info: Option<&'static RawBootInfo>, cpu_id: u32) -> ! { // Enable caching unsafe { diff --git a/src/arch/x86_64/kernel/start.rs b/src/arch/x86_64/kernel/start.rs index 0f2ec7bfbd..e7be4378dc 100644 --- a/src/arch/x86_64/kernel/start.rs +++ b/src/arch/x86_64/kernel/start.rs @@ -7,7 +7,7 @@ use crate::kernel::pre_init; use crate::kernel::scheduler::TaskStacks; use crate::KERNEL_STACK_SIZE; -#[no_mangle] +#[unsafe(no_mangle)] #[naked] pub unsafe extern "C" fn _start(_boot_info: Option<&'static RawBootInfo>, cpu_id: u32) -> ! { // boot_info is in the `rdi` register diff --git a/src/arch/x86_64/kernel/syscall.rs b/src/arch/x86_64/kernel/syscall.rs index 21044477b7..91b5b603a7 100644 --- a/src/arch/x86_64/kernel/syscall.rs +++ b/src/arch/x86_64/kernel/syscall.rs @@ -4,7 +4,7 @@ use core::mem; use super::core_local::CoreLocal; use crate::syscalls::table::SYSHANDLER_TABLE; -#[no_mangle] +#[unsafe(no_mangle)] #[naked] pub(crate) unsafe extern "C" fn syscall_handler() -> ! { unsafe { diff --git a/src/errno.rs b/src/errno.rs index b3ad5401ac..5625bad685 100644 --- a/src/errno.rs +++ b/src/errno.rs @@ -405,14 +405,14 @@ pub(crate) static ERRNO: core::cell::UnsafeCell = core::cell::UnsafeCell::n /// Get the error number from the thread local storage #[cfg(not(feature = "nostd"))] -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn sys_get_errno() -> i32 { sys_errno() } /// Get the error number from the thread local storage #[cfg(not(feature = "nostd"))] -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn sys_errno() -> i32 { cfg_if::cfg_if! { if #[cfg(any(feature = "common-os", target_arch = "riscv64"))] { diff --git a/src/lib.rs b/src/lib.rs index a9ed4f27d3..8a379f058e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -89,7 +89,7 @@ hermit_entry::define_entry_version!(); #[cfg(test)] #[cfg(target_os = "none")] -#[no_mangle] +#[unsafe(no_mangle)] extern "C" fn runtime_entry(_argc: i32, _argv: *const *const u8, _env: *const *const u8) -> ! { println!("Executing hermit unittests. Any arguments are dropped"); test_main(); diff --git a/src/syscalls/condvar.rs b/src/syscalls/condvar.rs index 1c0049b255..aefff063f8 100644 --- a/src/syscalls/condvar.rs +++ b/src/syscalls/condvar.rs @@ -24,7 +24,7 @@ impl CondQueue { } #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn sys_destroy_queue(ptr: usize) -> i32 { unsafe { let id = ptr::with_exposed_provenance_mut::(ptr); @@ -43,7 +43,7 @@ pub unsafe extern "C" fn sys_destroy_queue(ptr: usize) -> i32 { } #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn sys_notify(ptr: usize, count: i32) -> i32 { unsafe { let id = ptr::with_exposed_provenance::(ptr); @@ -81,7 +81,7 @@ pub unsafe extern "C" fn sys_notify(ptr: usize, count: i32) -> i32 { } #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn sys_init_queue(ptr: usize) -> i32 { unsafe { let id = ptr::with_exposed_provenance_mut::(ptr); @@ -101,7 +101,7 @@ pub unsafe extern "C" fn sys_init_queue(ptr: usize) -> i32 { } #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn sys_add_queue(ptr: usize, timeout_ns: i64) -> i32 { unsafe { let id = ptr::with_exposed_provenance_mut::(ptr); @@ -130,7 +130,7 @@ pub unsafe extern "C" fn sys_add_queue(ptr: usize, timeout_ns: i64) -> i32 { } #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn sys_wait(ptr: usize) -> i32 { unsafe { let id = ptr::with_exposed_provenance_mut::(ptr); diff --git a/src/syscalls/entropy.rs b/src/syscalls/entropy.rs index fc6df9e35b..07bd2de40f 100644 --- a/src/syscalls/entropy.rs +++ b/src/syscalls/entropy.rs @@ -54,7 +54,7 @@ unsafe extern "C" fn __sys_read_entropy(buf: *mut u8, len: usize, flags: u32) -> /// Returns either the number of bytes written to buf (a positive value) or /// * `-EINVAL` if `flags` contains unknown flags. /// * `-ENOSYS` if the system does not support random data generation. -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn sys_read_entropy(buf: *mut u8, len: usize, flags: u32) -> isize { unsafe { kernel_function!(__sys_read_entropy(buf, len, flags)) } } @@ -64,7 +64,7 @@ pub unsafe extern "C" fn sys_read_entropy(buf: *mut u8, len: usize, flags: u32) /// the function returns `-1`. #[cfg(not(feature = "newlib"))] #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn sys_secure_rand32(value: *mut u32) -> i32 { let mut buf = value.cast(); let mut len = size_of::(); @@ -86,7 +86,7 @@ pub unsafe extern "C" fn sys_secure_rand32(value: *mut u32) -> i32 { /// the function returns -1. #[cfg(not(feature = "newlib"))] #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn sys_secure_rand64(value: *mut u64) -> i32 { let mut buf = value.cast(); let mut len = size_of::(); @@ -106,7 +106,7 @@ pub unsafe extern "C" fn sys_secure_rand64(value: *mut u64) -> i32 { /// The function computes a sequence of pseudo-random integers /// in the range of 0 to RAND_MAX #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn sys_rand() -> u32 { generate_park_miller_lehmer_random_number() } @@ -114,7 +114,7 @@ pub extern "C" fn sys_rand() -> u32 { /// The function sets its argument as the seed for a new sequence /// of pseudo-random numbers to be returned by rand() #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn sys_srand(seed: u32) { *(PARK_MILLER_LEHMER_SEED.lock()) = seed; } diff --git a/src/syscalls/futex.rs b/src/syscalls/futex.rs index ffe3d5e9f3..c0cc8e5192 100644 --- a/src/syscalls/futex.rs +++ b/src/syscalls/futex.rs @@ -11,7 +11,7 @@ use crate::time::timespec; /// * `timeout` is negative /// * `flags` contains unknown flags #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn sys_futex_wait( address: *mut u32, expected: u32, @@ -44,7 +44,7 @@ pub unsafe extern "C" fn sys_futex_wait( /// `address` is used only for its address. /// It is safe to pass a dangling pointer. #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn sys_futex_wake(address: *mut u32, count: i32) -> i32 { if address.is_null() { return -EINVAL; diff --git a/src/syscalls/mmap.rs b/src/syscalls/mmap.rs index 073a550883..00eb9c5faf 100644 --- a/src/syscalls/mmap.rs +++ b/src/syscalls/mmap.rs @@ -24,7 +24,7 @@ bitflags! { /// Creates a new virtual memory mapping of the `size` specified with /// protection bits specified in `prot_flags`. #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn sys_mmap(size: usize, prot_flags: MemoryProtection, ret: &mut *mut u8) -> i32 { let size = size.align_up(BasePageSize::SIZE as usize); let virtual_address = arch::mm::virtualmem::allocate(size).unwrap(); @@ -53,7 +53,7 @@ pub extern "C" fn sys_mmap(size: usize, prot_flags: MemoryProtection, ret: &mut /// Unmaps memory at the specified `ptr` for `size` bytes. #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn sys_munmap(ptr: *mut u8, size: usize) -> i32 { let virtual_address = VirtAddr::from_ptr(ptr); let size = size.align_up(BasePageSize::SIZE as usize); @@ -76,7 +76,7 @@ pub extern "C" fn sys_munmap(ptr: *mut u8, size: usize) -> i32 { /// /// Returns 0 on success and an error code on failure. #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn sys_mprotect(ptr: *mut u8, size: usize, prot_flags: MemoryProtection) -> i32 { let count = size / BasePageSize::SIZE as usize; let mut flags = PageTableEntryFlags::empty(); diff --git a/src/syscalls/mod.rs b/src/syscalls/mod.rs index 1b0a96af9b..aa9558ad19 100644 --- a/src/syscalls/mod.rs +++ b/src/syscalls/mod.rs @@ -86,7 +86,7 @@ pub(crate) fn init() { /// #[cfg(all(target_os = "none", not(feature = "common-os")))] #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn sys_alloc(size: usize, align: usize) -> *mut u8 { let layout_res = Layout::from_size_align(size, align); if layout_res.is_err() || size == 0 { @@ -111,7 +111,7 @@ pub extern "C" fn sys_alloc(size: usize, align: usize) -> *mut u8 { #[cfg(all(target_os = "none", not(feature = "common-os")))] #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn sys_alloc_zeroed(size: usize, align: usize) -> *mut u8 { let layout_res = Layout::from_size_align(size, align); if layout_res.is_err() || size == 0 { @@ -136,7 +136,7 @@ pub extern "C" fn sys_alloc_zeroed(size: usize, align: usize) -> *mut u8 { #[cfg(all(target_os = "none", not(feature = "common-os")))] #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn sys_malloc(size: usize, align: usize) -> *mut u8 { let layout_res = Layout::from_size_align(size, align); if layout_res.is_err() || size == 0 { @@ -180,7 +180,7 @@ pub extern "C" fn sys_malloc(size: usize, align: usize) -> *mut u8 { /// allocator, or if reallocation otherwise fails. #[cfg(all(target_os = "none", not(feature = "common-os")))] #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn sys_realloc( ptr: *mut u8, size: usize, @@ -227,7 +227,7 @@ pub unsafe extern "C" fn sys_realloc( /// May panic if debug assertions are enabled and invalid parameters `size` or `align` where passed. #[cfg(all(target_os = "none", not(feature = "common-os")))] #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn sys_dealloc(ptr: *mut u8, size: usize, align: usize) { unsafe { let layout_res = Layout::from_size_align(size, align); @@ -252,7 +252,7 @@ pub unsafe extern "C" fn sys_dealloc(ptr: *mut u8, size: usize, align: usize) { #[cfg(all(target_os = "none", not(feature = "common-os")))] #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn sys_free(ptr: *mut u8, size: usize, align: usize) { unsafe { let layout_res = Layout::from_size_align(size, align); @@ -287,7 +287,7 @@ pub(crate) fn shutdown(arg: i32) -> ! { } #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn sys_unlink(name: *const c_char) -> i32 { let name = unsafe { CStr::from_ptr(name) }.to_str().unwrap(); @@ -295,7 +295,7 @@ pub unsafe extern "C" fn sys_unlink(name: *const c_char) -> i32 { } #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn sys_mkdir(name: *const c_char, mode: u32) -> i32 { let name = unsafe { CStr::from_ptr(name) }.to_str().unwrap(); let Some(mode) = AccessPermission::from_bits(mode) else { @@ -307,7 +307,7 @@ pub unsafe extern "C" fn sys_mkdir(name: *const c_char, mode: u32) -> i32 { } #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn sys_rmdir(name: *const c_char) -> i32 { let name = unsafe { CStr::from_ptr(name) }.to_str().unwrap(); @@ -315,7 +315,7 @@ pub unsafe extern "C" fn sys_rmdir(name: *const c_char) -> i32 { } #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn sys_stat(name: *const c_char, stat: *mut FileAttr) -> i32 { let name = unsafe { CStr::from_ptr(name) }.to_str().unwrap(); @@ -329,7 +329,7 @@ pub unsafe extern "C" fn sys_stat(name: *const c_char, stat: *mut FileAttr) -> i } #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn sys_lstat(name: *const c_char, stat: *mut FileAttr) -> i32 { let name = unsafe { CStr::from_ptr(name) }.to_str().unwrap(); @@ -343,7 +343,7 @@ pub unsafe extern "C" fn sys_lstat(name: *const c_char, stat: *mut FileAttr) -> } #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn sys_fstat(fd: FileDescriptor, stat: *mut FileAttr) -> i32 { if stat.is_null() { return -crate::errno::EINVAL; @@ -359,7 +359,7 @@ pub unsafe extern "C" fn sys_fstat(fd: FileDescriptor, stat: *mut FileAttr) -> i } #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn sys_opendir(name: *const c_char) -> FileDescriptor { if let Ok(name) = unsafe { CStr::from_ptr(name) }.to_str() { crate::fs::opendir(name).unwrap_or_else(|e| -num::ToPrimitive::to_i32(&e).unwrap()) @@ -369,7 +369,7 @@ pub unsafe extern "C" fn sys_opendir(name: *const c_char) -> FileDescriptor { } #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn sys_open(name: *const c_char, flags: i32, mode: u32) -> FileDescriptor { let Some(flags) = OpenOption::from_bits(flags) else { return -crate::errno::EINVAL; @@ -387,14 +387,14 @@ pub unsafe extern "C" fn sys_open(name: *const c_char, flags: i32, mode: u32) -> } #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn sys_close(fd: FileDescriptor) -> i32 { let obj = remove_object(fd); obj.map_or_else(|e| -num::ToPrimitive::to_i32(&e).unwrap(), |_| 0) } #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn sys_read(fd: FileDescriptor, buf: *mut u8, len: usize) -> isize { let slice = unsafe { core::slice::from_raw_parts_mut(buf, len) }; crate::fd::read(fd, slice).map_or_else( @@ -419,7 +419,7 @@ pub unsafe extern "C" fn sys_read(fd: FileDescriptor, buf: *mut u8, len: usize) /// which data should be written. `readv()` will always fill an completely /// before proceeding to the next. #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn sys_readv(fd: i32, iov: *const iovec, iovcnt: usize) -> isize { if !(0..=IOV_MAX).contains(&iovcnt) { return (-crate::errno::EINVAL).try_into().unwrap(); @@ -459,7 +459,7 @@ unsafe fn write(fd: FileDescriptor, buf: *const u8, len: usize) -> isize { } #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn sys_write(fd: FileDescriptor, buf: *const u8, len: usize) -> isize { unsafe { write(fd, buf, len) } } @@ -480,7 +480,7 @@ pub unsafe extern "C" fn sys_write(fd: FileDescriptor, buf: *const u8, len: usiz /// which data should be written. `writev()` will always write a /// complete area before proceeding to the next. #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn sys_writev(fd: FileDescriptor, iov: *const iovec, iovcnt: usize) -> isize { if !(0..=IOV_MAX).contains(&iovcnt) { return (-crate::errno::EINVAL).try_into().unwrap(); @@ -512,7 +512,7 @@ pub unsafe extern "C" fn sys_writev(fd: FileDescriptor, iov: *const iovec, iovcn } #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn sys_ioctl( fd: FileDescriptor, cmd: i32, @@ -538,7 +538,7 @@ pub unsafe extern "C" fn sys_ioctl( /// manipulate file descriptor #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn sys_fcntl(fd: i32, cmd: i32, arg: i32) -> i32 { const F_SETFD: i32 = 2; const F_SETFL: i32 = 4; @@ -562,7 +562,7 @@ pub extern "C" fn sys_fcntl(fd: i32, cmd: i32, arg: i32) -> i32 { } #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn sys_lseek(fd: FileDescriptor, offset: isize, whence: i32) -> isize { crate::fd::lseek(fd, offset, num::FromPrimitive::from_i32(whence).unwrap()) .map_or_else(|e| -num::ToPrimitive::to_isize(&e).unwrap(), |_| 0) @@ -584,7 +584,7 @@ pub struct Dirent64 { } #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn sys_getdents64( fd: FileDescriptor, dirp: *mut Dirent64, @@ -638,13 +638,13 @@ pub unsafe extern "C" fn sys_getdents64( } #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn sys_dup(fd: i32) -> i32 { dup_object(fd).unwrap_or_else(|e| -num::ToPrimitive::to_i32(&e).unwrap()) } #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn sys_poll(fds: *mut PollFd, nfds: usize, timeout: i32) -> i32 { let slice = unsafe { core::slice::from_raw_parts_mut(fds, nfds) }; let timeout = if timeout >= 0 { @@ -668,7 +668,7 @@ pub unsafe extern "C" fn sys_poll(fds: *mut PollFd, nfds: usize, timeout: i32) - } #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn sys_eventfd(initval: u64, flags: i16) -> i32 { if let Some(flags) = EventFlags::from_bits(flags) { crate::fd::eventfd(initval, flags) @@ -679,7 +679,7 @@ pub extern "C" fn sys_eventfd(initval: u64, flags: i16) -> i32 { } #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn sys_image_start_addr() -> usize { crate::mm::kernel_start_address().as_usize() } diff --git a/src/syscalls/processor.rs b/src/syscalls/processor.rs index d462e87128..a18b3b532d 100644 --- a/src/syscalls/processor.rs +++ b/src/syscalls/processor.rs @@ -2,20 +2,20 @@ use crate::arch::get_processor_count; /// Returns the number of processors currently online. #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn sys_get_processor_count() -> usize { get_processor_count().try_into().unwrap() } #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn sys_available_parallelism() -> usize { get_processor_count().try_into().unwrap() } /// Returns the processor frequency in MHz. #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn sys_get_processor_frequency() -> u16 { crate::arch::processor::get_frequency() } diff --git a/src/syscalls/recmutex.rs b/src/syscalls/recmutex.rs index 94f0523d17..e705df07d1 100644 --- a/src/syscalls/recmutex.rs +++ b/src/syscalls/recmutex.rs @@ -4,7 +4,7 @@ use crate::errno::*; use crate::synch::recmutex::RecursiveMutex; #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn sys_recmutex_init(recmutex: *mut *mut RecursiveMutex) -> i32 { if recmutex.is_null() { return -EINVAL; @@ -20,7 +20,7 @@ pub unsafe extern "C" fn sys_recmutex_init(recmutex: *mut *mut RecursiveMutex) - } #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn sys_recmutex_destroy(recmutex: *mut RecursiveMutex) -> i32 { if recmutex.is_null() { return -EINVAL; @@ -36,7 +36,7 @@ pub unsafe extern "C" fn sys_recmutex_destroy(recmutex: *mut RecursiveMutex) -> } #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn sys_recmutex_lock(recmutex: *mut RecursiveMutex) -> i32 { if recmutex.is_null() { return -EINVAL; @@ -49,7 +49,7 @@ pub unsafe extern "C" fn sys_recmutex_lock(recmutex: *mut RecursiveMutex) -> i32 } #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn sys_recmutex_unlock(recmutex: *mut RecursiveMutex) -> i32 { if recmutex.is_null() { return -EINVAL; diff --git a/src/syscalls/semaphore.rs b/src/syscalls/semaphore.rs index f778943f31..4fe7e46fba 100644 --- a/src/syscalls/semaphore.rs +++ b/src/syscalls/semaphore.rs @@ -15,7 +15,7 @@ pub type sem_t = *const Semaphore; /// Stores the raw memory location of the new semaphore in parameter `sem`. /// Returns `0` on success, `-EINVAL` if `sem` is null. #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn sys_sem_init(sem: *mut sem_t, pshared: i32, value: u32) -> i32 { if sem.is_null() || pshared != 0 { return -EINVAL; @@ -35,7 +35,7 @@ pub unsafe extern "C" fn sys_sem_init(sem: *mut sem_t, pshared: i32, value: u32) /// /// Returns `0` on success, `-EINVAL` if `sem` is null. #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn sys_sem_destroy(sem: *mut sem_t) -> i32 { if sem.is_null() { return -EINVAL; @@ -57,7 +57,7 @@ pub unsafe extern "C" fn sys_sem_destroy(sem: *mut sem_t) -> i32 { /// /// Returns `0` on success, or `-EINVAL` if `sem` is null. #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn sys_sem_post(sem: *mut sem_t) -> i32 { if sem.is_null() { return -EINVAL; @@ -76,7 +76,7 @@ pub unsafe extern "C" fn sys_sem_post(sem: *mut sem_t) -> i32 { /// /// Returns `0` on lock acquire, `-EINVAL` if `sem` is null, or `-ECANCELED` if the decrement fails. #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn sys_sem_trywait(sem: *mut sem_t) -> i32 { if sem.is_null() { return -EINVAL; @@ -113,7 +113,7 @@ unsafe fn sem_timedwait(sem: *mut sem_t, ms: u32) -> i32 { /// /// Returns `0` on lock acquire, `-EINVAL` if sem is null, or `-ETIME` on timeout. #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn sys_sem_timedwait(sem: *mut sem_t, ts: *const timespec) -> i32 { if ts.is_null() { unsafe { sem_timedwait(sem, 0) } diff --git a/src/syscalls/socket.rs b/src/syscalls/socket.rs index 2552268d7b..99604732f2 100644 --- a/src/syscalls/socket.rs +++ b/src/syscalls/socket.rs @@ -318,7 +318,7 @@ pub struct linger { #[cfg(not(feature = "dns"))] #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn sys_getaddrbyname( _name: *const c_char, _inaddr: *mut u8, @@ -352,7 +352,7 @@ pub unsafe extern "C" fn sys_getaddrbyname( /// ``` #[cfg(feature = "dns")] #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn sys_getaddrbyname( name: *const c_char, inaddr: *mut u8, @@ -411,7 +411,7 @@ pub unsafe extern "C" fn sys_getaddrbyname( } #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn sys_socket(domain: i32, type_: SockType, protocol: i32) -> i32 { debug!( "sys_socket: domain {}, type {:?}, protocol {}", @@ -478,7 +478,7 @@ pub extern "C" fn sys_socket(domain: i32, type_: SockType, protocol: i32) -> i32 } #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn sys_accept(fd: i32, addr: *mut sockaddr, addrlen: *mut socklen_t) -> i32 { let obj = get_object(fd); obj.map_or_else( @@ -537,7 +537,7 @@ pub unsafe extern "C" fn sys_accept(fd: i32, addr: *mut sockaddr, addrlen: *mut } #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn sys_listen(fd: i32, backlog: i32) -> i32 { let obj = get_object(fd); obj.map_or_else( @@ -550,7 +550,7 @@ pub extern "C" fn sys_listen(fd: i32, backlog: i32) -> i32 { } #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn sys_bind(fd: i32, name: *const sockaddr, namelen: socklen_t) -> i32 { if name.is_null() { return -crate::errno::EINVAL; @@ -595,7 +595,7 @@ pub unsafe extern "C" fn sys_bind(fd: i32, name: *const sockaddr, namelen: sockl } #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn sys_connect(fd: i32, name: *const sockaddr, namelen: socklen_t) -> i32 { if name.is_null() { return -crate::errno::EINVAL; @@ -641,7 +641,7 @@ pub unsafe extern "C" fn sys_connect(fd: i32, name: *const sockaddr, namelen: so } #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn sys_getsockname( fd: i32, addr: *mut sockaddr, @@ -698,7 +698,7 @@ pub unsafe extern "C" fn sys_getsockname( } #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn sys_setsockopt( fd: i32, level: i32, @@ -736,7 +736,7 @@ pub unsafe extern "C" fn sys_setsockopt( } #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn sys_getsockopt( fd: i32, level: i32, @@ -781,7 +781,7 @@ pub unsafe extern "C" fn sys_getsockopt( } #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn sys_getpeername( fd: i32, addr: *mut sockaddr, @@ -837,11 +837,11 @@ pub unsafe extern "C" fn sys_getpeername( } #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn sys_freeaddrinfo(_ai: *mut addrinfo) {} #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn sys_getaddrinfo( _nodename: *const c_char, _servname: *const c_char, @@ -852,7 +852,7 @@ pub unsafe extern "C" fn sys_getaddrinfo( } #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn sys_send(s: i32, mem: *const c_void, len: usize, _flags: i32) -> isize { unsafe { super::write(s, mem.cast(), len) } } @@ -869,19 +869,19 @@ fn shutdown(sockfd: i32, how: i32) -> i32 { } #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn sys_shutdown(sockfd: i32, how: i32) -> i32 { shutdown(sockfd, how) } #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn sys_shutdown_socket(fd: i32, how: i32) -> i32 { shutdown(fd, how) } #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn sys_recv(fd: i32, buf: *mut u8, len: usize, flags: i32) -> isize { if flags == 0 { let slice = unsafe { core::slice::from_raw_parts_mut(buf, len) }; @@ -895,7 +895,7 @@ pub unsafe extern "C" fn sys_recv(fd: i32, buf: *mut u8, len: usize, flags: i32) } #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn sys_sendto( fd: i32, buf: *const u8, @@ -953,7 +953,7 @@ pub unsafe extern "C" fn sys_sendto( } #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn sys_recvfrom( fd: i32, buf: *mut u8, diff --git a/src/syscalls/spinlock.rs b/src/syscalls/spinlock.rs index 5fa3b89509..faddc106c2 100644 --- a/src/syscalls/spinlock.rs +++ b/src/syscalls/spinlock.rs @@ -15,7 +15,7 @@ pub struct SpinlockIrqSaveContainer<'a> { } #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn sys_spinlock_init(lock: *mut *mut SpinlockContainer<'_>) -> i32 { if lock.is_null() { return -EINVAL; @@ -32,7 +32,7 @@ pub unsafe extern "C" fn sys_spinlock_init(lock: *mut *mut SpinlockContainer<'_> } #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn sys_spinlock_destroy(lock: *mut SpinlockContainer<'_>) -> i32 { if lock.is_null() { return -EINVAL; @@ -46,7 +46,7 @@ pub unsafe extern "C" fn sys_spinlock_destroy(lock: *mut SpinlockContainer<'_>) } #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn sys_spinlock_lock(lock: *mut SpinlockContainer<'_>) -> i32 { if lock.is_null() { return -EINVAL; @@ -62,7 +62,7 @@ pub unsafe extern "C" fn sys_spinlock_lock(lock: *mut SpinlockContainer<'_>) -> } #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn sys_spinlock_unlock(lock: *mut SpinlockContainer<'_>) -> i32 { if lock.is_null() { return -EINVAL; @@ -78,7 +78,7 @@ pub unsafe extern "C" fn sys_spinlock_unlock(lock: *mut SpinlockContainer<'_>) - } #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn sys_spinlock_irqsave_init( lock: *mut *mut SpinlockIrqSaveContainer<'_>, ) -> i32 { @@ -97,7 +97,7 @@ pub unsafe extern "C" fn sys_spinlock_irqsave_init( } #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn sys_spinlock_irqsave_destroy( lock: *mut SpinlockIrqSaveContainer<'_>, ) -> i32 { @@ -113,7 +113,7 @@ pub unsafe extern "C" fn sys_spinlock_irqsave_destroy( } #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn sys_spinlock_irqsave_lock(lock: *mut SpinlockIrqSaveContainer<'_>) -> i32 { if lock.is_null() { return -EINVAL; @@ -129,7 +129,7 @@ pub unsafe extern "C" fn sys_spinlock_irqsave_lock(lock: *mut SpinlockIrqSaveCon } #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn sys_spinlock_irqsave_unlock( lock: *mut SpinlockIrqSaveContainer<'_>, ) -> i32 { diff --git a/src/syscalls/system.rs b/src/syscalls/system.rs index 2c4ed1785b..de963e3fed 100644 --- a/src/syscalls/system.rs +++ b/src/syscalls/system.rs @@ -2,7 +2,7 @@ use crate::arch::mm::paging::{BasePageSize, PageSize}; /// Returns the base page size, in bytes, of the current system. #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn sys_getpagesize() -> i32 { BasePageSize::SIZE.try_into().unwrap() } diff --git a/src/syscalls/table.rs b/src/syscalls/table.rs index 77f276127b..0747d52dea 100644 --- a/src/syscalls/table.rs +++ b/src/syscalls/table.rs @@ -36,7 +36,7 @@ extern "C" fn invalid_syscall(sys_no: u64) -> ! { } #[allow(unused_assignments)] -#[no_mangle] +#[unsafe(no_mangle)] #[naked] pub(crate) unsafe extern "C" fn sys_invalid() { unsafe { @@ -80,5 +80,5 @@ impl SyscallTable { unsafe impl Send for SyscallTable {} unsafe impl Sync for SyscallTable {} -#[no_mangle] +#[unsafe(no_mangle)] pub(crate) static SYSHANDLER_TABLE: SyscallTable = SyscallTable::new(); diff --git a/src/syscalls/tasks.rs b/src/syscalls/tasks.rs index 26f3224532..ea47fa7d01 100644 --- a/src/syscalls/tasks.rs +++ b/src/syscalls/tasks.rs @@ -16,14 +16,14 @@ pub type SignalHandler = extern "C" fn(i32); pub type Tid = i32; #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn sys_getpid() -> Tid { 0 } #[cfg(feature = "newlib")] #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn sys_getprio(id: *const Tid) -> i32 { let task = core_scheduler().get_current_task_handle(); @@ -36,7 +36,7 @@ pub unsafe extern "C" fn sys_getprio(id: *const Tid) -> i32 { #[cfg(feature = "newlib")] #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn sys_setprio(_id: *const Tid, _prio: i32) -> i32 { -ENOSYS } @@ -47,20 +47,20 @@ fn exit(arg: i32) -> ! { } #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn sys_exit(status: i32) -> ! { exit(status) } #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn sys_thread_exit(status: i32) -> ! { debug!("Exit thread with error code {}!", status); core_scheduler().exit(status) } #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn sys_abort() -> ! { exit(-1) } @@ -85,19 +85,19 @@ pub(super) fn usleep(usecs: u64) { } #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn sys_msleep(ms: u32) { usleep(u64::from(ms) * 1000); } #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn sys_usleep(usecs: u64) { usleep(usecs); } #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn sys_nanosleep(rqtp: *const timespec, _rmtp: *mut timespec) -> i32 { assert!( !rqtp.is_null(), @@ -119,7 +119,7 @@ pub unsafe extern "C" fn sys_nanosleep(rqtp: *const timespec, _rmtp: *mut timesp /// Creates a new thread based on the configuration of the current thread. #[cfg(feature = "newlib")] #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn sys_clone(id: *mut Tid, func: extern "C" fn(usize), arg: usize) -> i32 { let task_id = core_scheduler().clone(func, arg); @@ -133,14 +133,14 @@ pub unsafe extern "C" fn sys_clone(id: *mut Tid, func: extern "C" fn(usize), arg } #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn sys_yield() { core_scheduler().reschedule(); } #[cfg(feature = "newlib")] #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn sys_kill(dest: Tid, signum: i32) -> i32 { debug!( "sys_kill is unimplemented, returning -ENOSYS for killing {} with signal {}", @@ -151,14 +151,14 @@ pub extern "C" fn sys_kill(dest: Tid, signum: i32) -> i32 { #[cfg(feature = "newlib")] #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn sys_signal(_handler: SignalHandler) -> i32 { debug!("sys_signal is unimplemented"); 0 } #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn sys_spawn2( func: unsafe extern "C" fn(usize), arg: usize, @@ -170,7 +170,7 @@ pub unsafe extern "C" fn sys_spawn2( } #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn sys_spawn( id: *mut Tid, func: unsafe extern "C" fn(usize), @@ -192,7 +192,7 @@ pub unsafe extern "C" fn sys_spawn( } #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn sys_join(id: Tid) -> i32 { match scheduler::join(TaskId::from(id)) { Ok(()) => 0, @@ -216,21 +216,21 @@ fn block_current_task(timeout: Option) { /// Set the current task state to `blocked` #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn sys_block_current_task() { block_current_task(None); } /// Set the current task state to `blocked` #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn sys_block_current_task_with_timeout(timeout: u64) { block_current_task(Some(timeout)); } /// Wake up the task with the identifier `id` #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn sys_wakeup_task(id: Tid) { let task_id = TaskId::from(id); @@ -241,14 +241,14 @@ pub extern "C" fn sys_wakeup_task(id: Tid) { /// Determine the priority of the current thread #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn sys_get_priority() -> u8 { core_scheduler().get_current_task_prio().into() } /// Set priority of the thread with the identifier `id` #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn sys_set_priority(id: Tid, prio: u8) { if prio > 0 { core_scheduler() @@ -261,7 +261,7 @@ pub extern "C" fn sys_set_priority(id: Tid, prio: u8) { /// Set priority of the current thread #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn sys_set_current_task_priority(prio: u8) { if prio > 0 { core_scheduler().set_current_task_priority(Priority::from(prio)); diff --git a/src/syscalls/timer.rs b/src/syscalls/timer.rs index 48aab76dd1..1aa29689eb 100644 --- a/src/syscalls/timer.rs +++ b/src/syscalls/timer.rs @@ -23,7 +23,7 @@ pub(crate) const TIMER_ABSTIME: i32 = 4; /// - `CLOCK_THREAD_CPUTIME_ID` /// - `CLOCK_MONOTONIC` #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn sys_clock_getres(clock_id: clockid_t, res: *mut timespec) -> i32 { assert!( !res.is_null(), @@ -53,7 +53,7 @@ pub unsafe extern "C" fn sys_clock_getres(clock_id: clockid_t, res: *mut timespe /// - `CLOCK_REALTIME` /// - `CLOCK_MONOTONIC` #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn sys_clock_gettime(clock_id: clockid_t, tp: *mut timespec) -> i32 { assert!( !tp.is_null(), @@ -90,7 +90,7 @@ pub unsafe extern "C" fn sys_clock_gettime(clock_id: clockid_t, tp: *mut timespe /// - `CLOCK_REALTIME` /// - `CLOCK_MONOTONIC` #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn sys_clock_nanosleep( clock_id: clockid_t, flags: i32, @@ -128,7 +128,7 @@ pub unsafe extern "C" fn sys_clock_nanosleep( } #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn sys_clock_settime(_clock_id: clockid_t, _tp: *const timespec) -> i32 { // We don't support setting any clocks yet. debug!("sys_clock_settime is unimplemented, returning -EINVAL"); @@ -142,7 +142,7 @@ pub unsafe extern "C" fn sys_clock_settime(_clock_id: clockid_t, _tp: *const tim /// /// **Parameter `tz` should be set to `0` since tz is obsolete.** #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn sys_gettimeofday(tp: *mut timeval, tz: usize) -> i32 { if let Some(result) = unsafe { tp.as_mut() } { // Return the current time based on the wallclock time when we were booted up @@ -160,7 +160,7 @@ pub unsafe extern "C" fn sys_gettimeofday(tp: *mut timeval, tz: usize) -> i32 { } #[hermit_macro::system] -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn sys_setitimer( _which: i32, _value: *const itimerval, diff --git a/tests/basic_math.rs b/tests/basic_math.rs index f1bf705e61..91ec40a531 100644 --- a/tests/basic_math.rs +++ b/tests/basic_math.rs @@ -146,7 +146,7 @@ fn test_f64_arithmetic() { assert!(approx_eq!(f64, z, 0.8f64, ulps = 0)); } -#[no_mangle] +#[unsafe(no_mangle)] extern "C" fn runtime_entry(_argc: i32, _argv: *const *const u8, _env: *const *const u8) -> ! { test_main(); exit(false); diff --git a/tests/basic_mem.rs b/tests/basic_mem.rs index 5099fa0dc7..2eac5975d6 100644 --- a/tests/basic_mem.rs +++ b/tests/basic_mem.rs @@ -141,7 +141,7 @@ fn test_mem() { mem::(); } -#[no_mangle] +#[unsafe(no_mangle)] extern "C" fn runtime_entry(_argc: i32, _argv: *const *const u8, _env: *const *const u8) -> ! { test_main(); common::exit(false) diff --git a/tests/basic_print.rs b/tests/basic_print.rs index 13b109734e..9357a39e26 100644 --- a/tests/basic_print.rs +++ b/tests/basic_print.rs @@ -12,7 +12,7 @@ use alloc::string::String; use alloc::vec::Vec; /// Print all Strings the application got passed as arguments -#[no_mangle] +#[unsafe(no_mangle)] pub fn main(args: Vec) -> Result<(), String> { for s in args { println!("{}", &s); diff --git a/tests/common/mod.rs b/tests/common/mod.rs index a77a06d776..4be5f0aaa1 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -59,7 +59,7 @@ macro_rules! runtime_entry_with_args { } } - #[no_mangle] + #[unsafe(no_mangle)] extern "C" fn runtime_entry( argc: i32, argv: *const *const u8, diff --git a/tests/measure_startup_time.rs b/tests/measure_startup_time.rs index a0459fb0f8..c382007dc0 100644 --- a/tests/measure_startup_time.rs +++ b/tests/measure_startup_time.rs @@ -15,7 +15,7 @@ use alloc::vec::Vec; /// - hypervisor startup time /// - kernel boot-time /// - overhead of runtime_entry (test entry) -#[no_mangle] +#[unsafe(no_mangle)] pub fn main(_args: Vec) -> Result<(), String> { Ok(()) } diff --git a/tests/thread.rs b/tests/thread.rs index 4345c9b74a..ec495eb38e 100644 --- a/tests/thread.rs +++ b/tests/thread.rs @@ -119,7 +119,7 @@ pub fn test_thread_local() { } } -#[no_mangle] +#[unsafe(no_mangle)] extern "C" fn runtime_entry(_argc: i32, _argv: *const *const u8, _env: *const *const u8) -> ! { test_main(); common::exit(false) From 7e29caa213e1b53046e5fa96b9911f01abad1ef1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Thu, 2 Jan 2025 12:44:58 +0100 Subject: [PATCH 2/6] fix: mark `extern` blocks as `unsafe` --- src/arch/aarch64/kernel/start.rs | 2 +- src/arch/riscv64/kernel/scheduler.rs | 2 +- src/arch/riscv64/kernel/switch.rs | 2 +- src/lib.rs | 4 ++-- tests/basic_mem.rs | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/arch/aarch64/kernel/start.rs b/src/arch/aarch64/kernel/start.rs index be9dbcd176..673192113e 100644 --- a/src/arch/aarch64/kernel/start.rs +++ b/src/arch/aarch64/kernel/start.rs @@ -6,7 +6,7 @@ use hermit_entry::Entry; use crate::arch::aarch64::kernel::scheduler::TaskStacks; use crate::{env, KERNEL_STACK_SIZE}; -extern "C" { +unsafe extern "C" { static vector_table: u8; } diff --git a/src/arch/riscv64/kernel/scheduler.rs b/src/arch/riscv64/kernel/scheduler.rs index b489a36c30..c483d04cd9 100644 --- a/src/arch/riscv64/kernel/scheduler.rs +++ b/src/arch/riscv64/kernel/scheduler.rs @@ -420,7 +420,7 @@ impl TaskFrame for Task { } } -extern "C" { +unsafe extern "C" { fn task_start(func: extern "C" fn(usize), arg: usize, user_stack: u64); } diff --git a/src/arch/riscv64/kernel/switch.rs b/src/arch/riscv64/kernel/switch.rs index c62ac700ae..475c22eda6 100644 --- a/src/arch/riscv64/kernel/switch.rs +++ b/src/arch/riscv64/kernel/switch.rs @@ -2,6 +2,6 @@ use core::arch::global_asm; global_asm!(include_str!("switch.s")); -extern "C" { +unsafe extern "C" { pub fn switch_to_task(old_stack: *mut usize, new_stack: usize); } diff --git a/src/lib.rs b/src/lib.rs index 8a379f058e..768f388bdf 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -116,7 +116,7 @@ fn trivial_test() { /// Entry point of a kernel thread, which initialize the libos #[cfg(target_os = "none")] extern "C" fn initd(_arg: usize) { - extern "C" { + unsafe extern "C" { #[cfg(all(not(test), not(any(feature = "nostd", feature = "common-os"))))] fn runtime_entry(argc: i32, argv: *const *const u8, env: *const *const u8) -> !; #[cfg(all(not(test), any(feature = "nostd", feature = "common-os")))] @@ -190,7 +190,7 @@ fn boot_processor_main() -> ! { info!("FDT:\n{fdt:#?}"); } - extern "C" { + unsafe extern "C" { static mut __bss_start: u8; } let bss_ptr = core::ptr::addr_of_mut!(__bss_start); diff --git a/tests/basic_mem.rs b/tests/basic_mem.rs index 2eac5975d6..9fd287b03d 100644 --- a/tests/basic_mem.rs +++ b/tests/basic_mem.rs @@ -22,7 +22,7 @@ where T: core::fmt::Debug, T: num_traits::int::PrimInt, { - extern "C" { + unsafe extern "C" { fn memcpy(dest: *mut u8, src: *const u8, n: usize) -> *mut u8; fn memcmp(s1: *const u8, s2: *const u8, n: usize) -> i32; } From 26927122bebec261cc8760b182b014bb74b0dc64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Thu, 2 Jan 2025 12:55:47 +0100 Subject: [PATCH 3/6] fix(macros): `tail_expr_drop_order` --- src/macros.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/macros.rs b/src/macros.rs index 871fc798f8..c7c13ea5d6 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -244,7 +244,7 @@ macro_rules! hermit_var { /// Fetches according to [`hermit_var`] or returns the specified default value. #[allow(unused_macros)] macro_rules! hermit_var_or { - ($name:expr, $default:expr) => {{ + ($name:expr, $default:expr) => { hermit_var!($name).as_deref().unwrap_or($default) - }}; + }; } From 52a7dc889c0c5b44598117b96e153d00b64a2ff3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Thu, 2 Jan 2025 20:28:50 +0100 Subject: [PATCH 4/6] style: use Rust 2024 style edition --- build.rs | 2 +- hermit-macro/src/system.rs | 2 +- rustfmt.toml | 1 + src/arch/aarch64/kernel/core_local.rs | 2 +- src/arch/aarch64/kernel/pci.rs | 37 +++--- src/arch/aarch64/kernel/processor.rs | 4 +- src/arch/aarch64/kernel/scheduler.rs | 16 +-- src/arch/aarch64/kernel/start.rs | 4 +- src/arch/aarch64/mm/paging.rs | 9 +- src/arch/riscv64/kernel/interrupts.rs | 2 +- src/arch/riscv64/kernel/mod.rs | 2 +- src/arch/riscv64/kernel/processor.rs | 2 +- src/arch/riscv64/kernel/scheduler.rs | 4 +- src/arch/riscv64/kernel/start.rs | 8 +- src/arch/riscv64/mm/paging.rs | 10 +- src/arch/x86_64/kernel/acpi.rs | 6 +- src/arch/x86_64/kernel/apic.rs | 8 +- src/arch/x86_64/kernel/core_local.rs | 4 +- src/arch/x86_64/kernel/gdt.rs | 8 +- src/arch/x86_64/kernel/interrupts.rs | 4 +- src/arch/x86_64/kernel/mmio.rs | 2 +- src/arch/x86_64/kernel/mod.rs | 10 +- src/arch/x86_64/kernel/pci.rs | 2 +- src/arch/x86_64/kernel/processor.rs | 2 +- src/arch/x86_64/kernel/scheduler.rs | 2 +- src/arch/x86_64/kernel/start.rs | 4 +- src/arch/x86_64/kernel/systemtime.rs | 2 +- src/arch/x86_64/mm/paging.rs | 7 +- src/arch/x86_64/mm/physicalmem.rs | 8 +- src/arch/x86_64/mm/virtualmem.rs | 2 +- src/drivers/fs/virtio_fs.rs | 6 +- src/drivers/mmio.rs | 4 +- src/drivers/net/rtl8139.rs | 2 +- src/drivers/net/virtio/mmio.rs | 2 +- src/drivers/net/virtio/mod.rs | 60 +++++----- src/drivers/pci.rs | 18 ++- src/drivers/virtio/env.rs | 2 +- src/drivers/virtio/mod.rs | 150 +++++++++++++++++++------ src/drivers/virtio/transport/mmio.rs | 4 +- src/drivers/virtio/transport/pci.rs | 69 +++++++----- src/drivers/virtio/virtqueue/packed.rs | 4 +- src/drivers/vsock/mod.rs | 21 ++-- src/entropy.rs | 2 +- src/env.rs | 2 +- src/executor/device.rs | 4 +- src/executor/network.rs | 2 +- src/executor/vsock.rs | 2 +- src/fd/eventfd.rs | 2 +- src/fd/socket/tcp.rs | 2 +- src/fd/socket/vsock.rs | 2 +- src/fs/fuse.rs | 97 +++++++--------- src/fs/mod.rs | 4 +- src/scheduler/mod.rs | 17 ++- src/scheduler/task.rs | 12 +- src/shell.rs | 47 ++++---- src/synch/futex.rs | 4 +- src/synch/recmutex.rs | 2 +- src/synch/semaphore.rs | 2 +- src/syscalls/mod.rs | 39 +++---- src/syscalls/semaphore.rs | 8 +- src/syscalls/socket.rs | 6 +- src/syscalls/tasks.rs | 2 +- xtask/src/ci/qemu.rs | 11 +- xtask/src/doc.rs | 7 +- 64 files changed, 417 insertions(+), 377 deletions(-) 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-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/rustfmt.toml b/rustfmt.toml index 7e231d7f97..c3179e46aa 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -2,3 +2,4 @@ group_imports = "StdExternalCrate" hard_tabs = true hex_literal_case = "Lower" imports_granularity = "Module" +style_edition = "2024" 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..4fcb19500f 100644 --- a/src/drivers/pci.rs +++ b/src/drivers/pci.rs @@ -6,19 +6,21 @@ 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; #[cfg(feature = "fuse")] use crate::drivers::fs::virtio_fs::VirtioFsDriver; +#[cfg(any(feature = "tcp", feature = "udp"))] +use crate::drivers::net::NetworkDriver; #[cfg(all(target_arch = "x86_64", feature = "rtl8139"))] use crate::drivers::net::rtl8139::{self, RTL8139Driver}; #[cfg(all( @@ -26,8 +28,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 +279,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 +290,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/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(()) From bb2fac74598034c4cfcc6ce65ff6d8259efe98af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Thu, 2 Jan 2025 20:36:18 +0100 Subject: [PATCH 5/6] chore: add Rust 2024 style commit to `.git-blame-ignore-revs` --- .git-blame-ignore-revs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs index 4d6953854a..24ad06eec7 100644 --- a/.git-blame-ignore-revs +++ b/.git-blame-ignore-revs @@ -54,3 +54,5 @@ efc3f0a39209d1cc0fb0907842559cd0ba7f2626 6ffef254f5004176840a4ba5fa8a4ab78c9cb0b4 1980a19b283e405c12f172dda0d61f6e7392cbb3 12261cd05d69974fa470974b84fc46c73e3e4e07 +# Upgrade to Rust 2024 style edition +52a7dc889c0c5b44598117b96e153d00b64a2ff3 From f2ae8b5787de1c8522b265fc19501d97f3656642 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Thu, 2 Jan 2025 20:29:30 +0100 Subject: [PATCH 6/6] feat: upgrade to Rust 2024 --- Cargo.toml | 2 +- hermit-builtins/Cargo.toml | 2 +- hermit-macro/Cargo.toml | 2 +- rustfmt.toml | 1 - xtask/Cargo.toml | 2 +- 5 files changed, 4 insertions(+), 5 deletions(-) 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/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/rustfmt.toml b/rustfmt.toml index c3179e46aa..7e231d7f97 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -2,4 +2,3 @@ group_imports = "StdExternalCrate" hard_tabs = true hex_literal_case = "Lower" imports_granularity = "Module" -style_edition = "2024" 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"