From 67df3d6a7c56ef1efdd543ceefc004274f2498b4 Mon Sep 17 00:00:00 2001 From: Nick Spinale Date: Mon, 18 Mar 2024 08:09:34 +0000 Subject: [PATCH 1/3] crates/sel4-capdl-initializer/types: Fix features Signed-off-by: Nick Spinale --- crates/sel4-capdl-initializer/types/Cargo.nix | 2 +- crates/sel4-capdl-initializer/types/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/sel4-capdl-initializer/types/Cargo.nix b/crates/sel4-capdl-initializer/types/Cargo.nix index 8cd01ca00..9c4c6f9e3 100644 --- a/crates/sel4-capdl-initializer/types/Cargo.nix +++ b/crates/sel4-capdl-initializer/types/Cargo.nix @@ -19,7 +19,7 @@ mk { sel4 = localCrates.sel4 // { optional = true; default-features = false; }; }; features = { - std = [ "alloc" "serde_json" ]; + std = [ "alloc" "serde" "serde_json" ]; alloc = [ "miniz_oxide?/with-alloc" ]; serde = [ "alloc" "dep:serde" ]; deflate = [ "dep:miniz_oxide" ]; diff --git a/crates/sel4-capdl-initializer/types/Cargo.toml b/crates/sel4-capdl-initializer/types/Cargo.toml index 17a35c76d..1acbb9c82 100644 --- a/crates/sel4-capdl-initializer/types/Cargo.toml +++ b/crates/sel4-capdl-initializer/types/Cargo.toml @@ -21,7 +21,7 @@ alloc = ["miniz_oxide?/with-alloc"] borrowed-indirect = [] deflate = ["dep:miniz_oxide"] serde = ["alloc", "dep:serde"] -std = ["alloc", "serde_json"] +std = ["alloc", "serde", "serde_json"] [dependencies] cfg-if = "1.0.0" From 70749ce22040f9276a8665ad990fb45b4e4549c7 Mon Sep 17 00:00:00 2001 From: Nick Spinale Date: Mon, 18 Mar 2024 08:15:34 +0000 Subject: [PATCH 2/3] crates/sel4-capdl-initializer/types: Address clippy lint Signed-off-by: Nick Spinale --- crates/sel4-capdl-initializer/types/src/footprint.rs | 2 +- crates/sel4-capdl-initializer/types/src/frame_init.rs | 2 +- crates/sel4-capdl-initializer/types/src/indirect.rs | 2 +- crates/sel4-capdl-initializer/types/src/object_name.rs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/sel4-capdl-initializer/types/src/footprint.rs b/crates/sel4-capdl-initializer/types/src/footprint.rs index 7442f6e1c..63dd77223 100644 --- a/crates/sel4-capdl-initializer/types/src/footprint.rs +++ b/crates/sel4-capdl-initializer/types/src/footprint.rs @@ -6,7 +6,7 @@ use core::mem::size_of_val; -#[cfg(feature = "alloc")] +#[cfg(all(feature = "alloc", not(feature = "std")))] use alloc::string::String; use crate::frame_init::*; diff --git a/crates/sel4-capdl-initializer/types/src/frame_init.rs b/crates/sel4-capdl-initializer/types/src/frame_init.rs index 1166a2439..4c037dfcb 100644 --- a/crates/sel4-capdl-initializer/types/src/frame_init.rs +++ b/crates/sel4-capdl-initializer/types/src/frame_init.rs @@ -10,7 +10,7 @@ use core::ops::Range; #[cfg(feature = "deflate")] use core::iter; -#[cfg(feature = "alloc")] +#[cfg(all(feature = "alloc", not(feature = "std")))] use alloc::{string::String, vec::Vec}; #[cfg(feature = "serde")] diff --git a/crates/sel4-capdl-initializer/types/src/indirect.rs b/crates/sel4-capdl-initializer/types/src/indirect.rs index edb7b2b40..704e2295f 100644 --- a/crates/sel4-capdl-initializer/types/src/indirect.rs +++ b/crates/sel4-capdl-initializer/types/src/indirect.rs @@ -11,7 +11,7 @@ use core::ops::Deref; #[cfg(feature = "alloc")] use core::marker::PhantomData; -#[cfg(feature = "alloc")] +#[cfg(all(feature = "alloc", not(feature = "std")))] use alloc::boxed::Box; #[cfg(feature = "serde")] diff --git a/crates/sel4-capdl-initializer/types/src/object_name.rs b/crates/sel4-capdl-initializer/types/src/object_name.rs index bf9e23b8f..8ca2633ee 100644 --- a/crates/sel4-capdl-initializer/types/src/object_name.rs +++ b/crates/sel4-capdl-initializer/types/src/object_name.rs @@ -7,7 +7,7 @@ use core::ops::Range; use core::str; -#[cfg(feature = "alloc")] +#[cfg(all(feature = "alloc", not(feature = "std")))] use alloc::string::String; #[cfg(feature = "serde")] From 3d4819f628cad1e257931017ec0c036248cc1e7d Mon Sep 17 00:00:00 2001 From: Nick Spinale Date: Mon, 18 Mar 2024 08:26:27 +0000 Subject: [PATCH 3/3] Address clippy lints Signed-off-by: Nick Spinale --- .../examples/root-task/spawn-task/src/main.rs | 1 + .../root-task/spawn-thread/src/main.rs | 2 +- .../sel4-simple-task/runtime/src/lib.rs | 3 ++- crates/sel4-async/time/src/sub_key.rs | 1 + .../addr2line-context-helper/src/lib.rs | 1 - .../embedded-spec/validate/src/lib.rs | 5 +--- .../with-embedded-spec/src/main.rs | 3 ++- crates/sel4-dlmalloc/src/lib.rs | 6 +++++ .../arm/arch/aarch32/drivers/spin_table.rs | 5 ++-- .../arm/arch/aarch64/drivers/spin_table.rs | 3 ++- crates/sel4-microkit/src/defer.rs | 6 +++++ crates/sel4-newlib/src/heap.rs | 10 ++++++-- crates/sel4-runtime-common/src/start.rs | 6 +++++ crates/sel4-runtime-common/src/unwinding.rs | 3 +-- .../bookkeeping/src/slot_set_semaphore.rs | 2 -- crates/sel4-sync/src/mutex.rs | 12 ++++++++++ crates/sel4/bitfield-ops/src/lib.rs | 24 +++++++++---------- crates/sel4/bitfield-parser/src/lib.rs | 2 ++ crates/sel4/src/arch/riscv/vspace.rs | 2 ++ 19 files changed, 67 insertions(+), 30 deletions(-) diff --git a/crates/examples/root-task/spawn-task/src/main.rs b/crates/examples/root-task/spawn-task/src/main.rs index 589c6b9b5..78e000932 100644 --- a/crates/examples/root-task/spawn-task/src/main.rs +++ b/crates/examples/root-task/spawn-task/src/main.rs @@ -6,6 +6,7 @@ #![no_std] #![no_main] +#![allow(clippy::useless_conversion)] extern crate alloc; diff --git a/crates/examples/root-task/spawn-thread/src/main.rs b/crates/examples/root-task/spawn-thread/src/main.rs index daec71c1c..835ae95c9 100644 --- a/crates/examples/root-task/spawn-thread/src/main.rs +++ b/crates/examples/root-task/spawn-thread/src/main.rs @@ -134,7 +134,7 @@ fn create_user_context(f: SecondaryThreadFn) -> sel4::UserContext { let mut ctx = sel4::UserContext::default(); *ctx.sp_mut() = SECONDARY_THREAD_STACK.top().try_into().unwrap(); - *ctx.pc_mut() = secondary_thread_entrypoint as sel4::Word; + *ctx.pc_mut() = (secondary_thread_entrypoint as usize).try_into().unwrap(); *ctx.c_param_mut(0) = f.into_arg(); let tls_reservation = TlsReservation::new(&get_tls_image()); diff --git a/crates/private/support/sel4-simple-task/runtime/src/lib.rs b/crates/private/support/sel4-simple-task/runtime/src/lib.rs index a9f185c7e..b06182762 100644 --- a/crates/private/support/sel4-simple-task/runtime/src/lib.rs +++ b/crates/private/support/sel4-simple-task/runtime/src/lib.rs @@ -8,6 +8,7 @@ #![feature(never_type)] #![feature(thread_local)] #![allow(internal_features)] +#![allow(clippy::useless_conversion)] #[cfg(feature = "alloc")] extern crate alloc; @@ -95,7 +96,7 @@ pub unsafe extern "C" fn cont_fn(cont_arg: *mut sel4_runtime_common::ContArg) -> let reply_authority = { sel4::sel4_cfg_if! { if #[sel4_cfg(KERNEL_MCS)] { - sel4::cap::Reply::from_bits(thread_config.reply_authority().unwrap()) + sel4::cap::Reply::from_bits(thread_config.reply_authority().unwrap().try_into().unwrap()) } else { assert!(thread_config.reply_authority().is_none()); sel4::ImplicitReplyAuthority diff --git a/crates/sel4-async/time/src/sub_key.rs b/crates/sel4-async/time/src/sub_key.rs index 4954c25e4..155fa3448 100644 --- a/crates/sel4-async/time/src/sub_key.rs +++ b/crates/sel4-async/time/src/sub_key.rs @@ -7,6 +7,7 @@ pub trait SubKey: Sized + Ord { fn min() -> Self; + #[allow(dead_code)] fn max() -> Self; fn succ(&self) -> Option; diff --git a/crates/sel4-backtrace/addr2line-context-helper/src/lib.rs b/crates/sel4-backtrace/addr2line-context-helper/src/lib.rs index 1104a7f46..7f298bec1 100644 --- a/crates/sel4-backtrace/addr2line-context-helper/src/lib.rs +++ b/crates/sel4-backtrace/addr2line-context-helper/src/lib.rs @@ -11,7 +11,6 @@ extern crate alloc; use alloc::borrow::Cow; use alloc::rc::Rc; -use addr2line::gimli; use addr2line::object::{Object, ObjectSection}; use addr2line::Context as AbstractContext; diff --git a/crates/sel4-capdl-initializer/with-embedded-spec/embedded-spec/validate/src/lib.rs b/crates/sel4-capdl-initializer/with-embedded-spec/embedded-spec/validate/src/lib.rs index 1c8ffeb0c..3492904b4 100644 --- a/crates/sel4-capdl-initializer/with-embedded-spec/embedded-spec/validate/src/lib.rs +++ b/crates/sel4-capdl-initializer/with-embedded-spec/embedded-spec/validate/src/lib.rs @@ -35,10 +35,7 @@ pub fn run(tell_cargo: bool) { let input = &embedding.spec; let adapted_input: SpecCommon = input .traverse_names_with_context(|named_obj| { - embedding - .object_names_level - .apply(named_obj) - .map(Clone::clone) + embedding.object_names_level.apply(named_obj).cloned() }) .traverse_data(|key| embedding.fill_map.get(key).to_vec()) .traverse_embedded_frames(|fill| { diff --git a/crates/sel4-capdl-initializer/with-embedded-spec/src/main.rs b/crates/sel4-capdl-initializer/with-embedded-spec/src/main.rs index a4b251909..46f40e631 100644 --- a/crates/sel4-capdl-initializer/with-embedded-spec/src/main.rs +++ b/crates/sel4-capdl-initializer/with-embedded-spec/src/main.rs @@ -8,6 +8,7 @@ #![no_main] use core::ops::Range; +use core::ptr; use sel4_capdl_initializer_core::{Initializer, InitializerBuffers, PerObjectBuffer}; use sel4_capdl_initializer_types::SpecWithSources; @@ -39,7 +40,7 @@ fn main(bootinfo: &sel4::BootInfoPtr) -> ! { embedded_frame_source: &trivial_source, }; Initializer::initialize(bootinfo, user_image_bounds(), &spec_with_sources, unsafe { - &mut BUFFERS + ptr::addr_of_mut!(BUFFERS).as_mut().unwrap() }) } diff --git a/crates/sel4-dlmalloc/src/lib.rs b/crates/sel4-dlmalloc/src/lib.rs index 45be4103d..147412d21 100644 --- a/crates/sel4-dlmalloc/src/lib.rs +++ b/crates/sel4-dlmalloc/src/lib.rs @@ -197,6 +197,12 @@ impl StaticHeap { } } +impl Default for StaticHeap { + fn default() -> Self { + Self::new() + } +} + impl GetStaticHeapBounds for &StaticHeap { fn bounds(self) -> StaticHeapBounds { StaticHeapBounds::new(self.0.get().cast(), N) diff --git a/crates/sel4-kernel-loader/src/arch/arm/arch/aarch32/drivers/spin_table.rs b/crates/sel4-kernel-loader/src/arch/arm/arch/aarch32/drivers/spin_table.rs index b9bf8de2b..51cd91b91 100644 --- a/crates/sel4-kernel-loader/src/arch/arm/arch/aarch32/drivers/spin_table.rs +++ b/crates/sel4-kernel-loader/src/arch/arm/arch/aarch32/drivers/spin_table.rs @@ -5,6 +5,7 @@ // use core::arch::{asm, global_asm}; +use core::ptr; #[used] #[no_mangle] @@ -12,14 +13,14 @@ static mut spin_table_secondary_stack_bottom: usize = 0; pub(crate) fn start_secondary_core(spin_table: &[usize], core_id: usize, sp: usize) { unsafe { - core::ptr::addr_of_mut!(spin_table_secondary_stack_bottom).write(sp); + ptr::addr_of_mut!(spin_table_secondary_stack_bottom).write(sp); let start = spin_table_secondary_entry as *const SpinTableSecondaryEntryFn as usize; let start_ptr = spin_table[core_id] as *mut usize; start_ptr.write_volatile(start); - clean_dcache_entry(&spin_table_secondary_stack_bottom as *const _ as usize); + clean_dcache_entry(ptr::addr_of!(spin_table_secondary_stack_bottom) as usize); // Barrier ensure both strl and dc cvac happen before sev asm!("dsb sy"); diff --git a/crates/sel4-kernel-loader/src/arch/arm/arch/aarch64/drivers/spin_table.rs b/crates/sel4-kernel-loader/src/arch/arm/arch/aarch64/drivers/spin_table.rs index 6ffd08dd2..fca7ba1ed 100644 --- a/crates/sel4-kernel-loader/src/arch/arm/arch/aarch64/drivers/spin_table.rs +++ b/crates/sel4-kernel-loader/src/arch/arm/arch/aarch64/drivers/spin_table.rs @@ -5,6 +5,7 @@ // use core::arch::{asm, global_asm}; +use core::ptr; use core::sync::atomic::{AtomicUsize, Ordering}; #[used] @@ -23,7 +24,7 @@ pub(crate) fn start_secondary_core(spin_table: &[usize], core_id: usize, sp: usi AtomicUsize::from_ptr(start_ptr).store(start, Ordering::Release); dc_cvac(start_ptr as usize); - dc_cvac(&spin_table_secondary_stack_bottom as *const _ as usize); + dc_cvac(ptr::addr_of!(spin_table_secondary_stack_bottom) as usize); // Barrier ensure both strl and dc cvac happen before sev asm!("dsb sy"); diff --git a/crates/sel4-microkit/src/defer.rs b/crates/sel4-microkit/src/defer.rs index d0c6c2665..facda19a3 100644 --- a/crates/sel4-microkit/src/defer.rs +++ b/crates/sel4-microkit/src/defer.rs @@ -120,3 +120,9 @@ impl DeferredActionSlot { self.defer(DeferredAction::new_irq_ack(channel)) } } + +impl Default for DeferredActionSlot { + fn default() -> Self { + Self::new() + } +} diff --git a/crates/sel4-newlib/src/heap.rs b/crates/sel4-newlib/src/heap.rs index 795139a37..5186b8f9d 100644 --- a/crates/sel4-newlib/src/heap.rs +++ b/crates/sel4-newlib/src/heap.rs @@ -4,14 +4,14 @@ // SPDX-License-Identifier: BSD-2-Clause // -use super::*; - use core::cell::UnsafeCell; use core::ffi::{c_int, c_void}; use core::sync::atomic::{AtomicIsize, Ordering}; use sel4_panicking_env::abort; +use crate::errno; + // NOTE(rustc_wishlist) use SyncUnsafeCell once #![feature(sync_unsafe_cell)] stabilizes #[repr(align(4096))] // no real reason for this struct BackingMemory(UnsafeCell<[u8; N]>); @@ -69,6 +69,12 @@ impl StaticHeap { } } +impl Default for StaticHeap { + fn default() -> Self { + Self::new() + } +} + #[macro_export] macro_rules! declare_sbrk_with_static_heap { ($n:expr) => { diff --git a/crates/sel4-runtime-common/src/start.rs b/crates/sel4-runtime-common/src/start.rs index 8f06fbb6f..20241d7fc 100644 --- a/crates/sel4-runtime-common/src/start.rs +++ b/crates/sel4-runtime-common/src/start.rs @@ -35,6 +35,12 @@ impl Stack { } } +impl Default for Stack { + fn default() -> Self { + Self::new() + } +} + #[repr(transparent)] pub struct StackTop(#[allow(dead_code)] *mut u8); diff --git a/crates/sel4-runtime-common/src/unwinding.rs b/crates/sel4-runtime-common/src/unwinding.rs index f05f6c195..3a3362b2c 100644 --- a/crates/sel4-runtime-common/src/unwinding.rs +++ b/crates/sel4-runtime-common/src/unwinding.rs @@ -31,8 +31,7 @@ unsafe impl EhFrameFinder for EhFrameFinderImpl { let eh_frame_hdr = phdrs.iter().find_map(|phdr| { if phdr.p_type == PT_GNU_EH_FRAME { - let eh_frame_hdr = phdr.p_vaddr.try_into().unwrap(); - return Some(eh_frame_hdr); + return Some(phdr.p_vaddr); } None })?; diff --git a/crates/sel4-shared-ring-buffer/bookkeeping/src/slot_set_semaphore.rs b/crates/sel4-shared-ring-buffer/bookkeeping/src/slot_set_semaphore.rs index 1105f34d5..233955f86 100644 --- a/crates/sel4-shared-ring-buffer/bookkeeping/src/slot_set_semaphore.rs +++ b/crates/sel4-shared-ring-buffer/bookkeeping/src/slot_set_semaphore.rs @@ -259,8 +259,6 @@ impl SlotSemaphore for Rc { #[cfg(feature = "async-unsync")] mod async_unsync_impl { - use alloc::rc::Rc; - use async_unsync::semaphore::{Semaphore, TryAcquireError}; use super::*; diff --git a/crates/sel4-sync/src/mutex.rs b/crates/sel4-sync/src/mutex.rs index a5328124f..301855f0e 100644 --- a/crates/sel4-sync/src/mutex.rs +++ b/crates/sel4-sync/src/mutex.rs @@ -126,6 +126,12 @@ impl DeferredNotificationMutexSyncOps { } } +impl Default for DeferredNotificationMutexSyncOps { + fn default() -> Self { + Self::new() + } +} + impl MutexSyncOpsWithNotification for DeferredNotificationMutexSyncOps { fn notification(&self) -> sel4::cap::Notification { *self.inner.get().unwrap() @@ -188,6 +194,12 @@ impl PanickingMutexSyncOps { } } +impl Default for PanickingMutexSyncOps { + fn default() -> Self { + Self::new() + } +} + impl MutexSyncOps for PanickingMutexSyncOps { fn signal(&self) { panic!("unexpected contention: signal") diff --git a/crates/sel4/bitfield-ops/src/lib.rs b/crates/sel4/bitfield-ops/src/lib.rs index ec5b29159..a37bac695 100644 --- a/crates/sel4/bitfield-ops/src/lib.rs +++ b/crates/sel4/bitfield-ops/src/lib.rs @@ -200,26 +200,28 @@ fn checked_cast, U>(val: T) -> U { val.try_into().map_err(|_| unreachable!()).unwrap() } -pub fn set_bits_from_slice( +pub fn set_bits_from_slice( dst: &mut [T], dst_range: Range, src: &[U], src_start: usize, ) where - T: TryFrom, + T: UnsignedPrimInt + TryFrom, + U: UnsignedPrimInt, usize: TryFrom, { set_bits_from_slice_via::<_, _, usize>(dst, dst_range, src, src_start) } -fn set_bits_from_slice_via( +fn set_bits_from_slice_via( dst: &mut [T], dst_range: Range, src: &[U], src_start: usize, ) where - T: TryFrom, - V: TryFrom, + T: UnsignedPrimInt + TryFrom, + U: UnsignedPrimInt, + V: UnsignedPrimInt + TryFrom, { let num_bits = dst_range.len(); @@ -302,13 +304,9 @@ impl, U: UnsignedPrimInt> Bitfield { get_bits(self.bits(), range) } - pub fn get_bits_into_slice( - &self, - range: Range, - dst: &mut [V], - dst_start: usize, - ) where - V: TryFrom, + pub fn get_bits_into_slice(&self, range: Range, dst: &mut [V], dst_start: usize) + where + V: UnsignedPrimInt + TryFrom, usize: TryFrom, { let dst_range = dst_start..(dst_start + range.len()); @@ -355,8 +353,8 @@ impl, U: UnsignedPrimInt> Bitfield { // // // #[cfg(test)] +#[allow(unused_imports)] mod test { - #![allow(unused_imports)] extern crate std; diff --git a/crates/sel4/bitfield-parser/src/lib.rs b/crates/sel4/bitfield-parser/src/lib.rs index 744f9a662..558326fa0 100644 --- a/crates/sel4/bitfield-parser/src/lib.rs +++ b/crates/sel4/bitfield-parser/src/lib.rs @@ -4,6 +4,8 @@ // SPDX-License-Identifier: BSD-2-Clause // +#![allow(clippy::empty_docs)] // for #[derive(Parser)] + use pest::{iterators::Pair, Parser}; use pest_derive::Parser; use regex::Regex; diff --git a/crates/sel4/src/arch/riscv/vspace.rs b/crates/sel4/src/arch/riscv/vspace.rs index f499d6d37..a8c762a64 100644 --- a/crates/sel4/src/arch/riscv/vspace.rs +++ b/crates/sel4/src/arch/riscv/vspace.rs @@ -4,6 +4,8 @@ // SPDX-License-Identifier: MIT // +#![allow(clippy::eq_op)] + use sel4_config::sel4_cfg_wrap_match; #[allow(unused_imports)]