Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address clippy lints #118

Merged
merged 3 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/examples/root-task/spawn-task/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#![no_std]
#![no_main]
#![allow(clippy::useless_conversion)]

extern crate alloc;

Expand Down
2 changes: 1 addition & 1 deletion crates/examples/root-task/spawn-thread/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#![feature(never_type)]
#![feature(thread_local)]
#![allow(internal_features)]
#![allow(clippy::useless_conversion)]

#[cfg(feature = "alloc")]
extern crate alloc;
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions crates/sel4-async/time/src/sub_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
pub trait SubKey: Sized + Ord {
fn min() -> Self;

#[allow(dead_code)]
fn max() -> Self;

fn succ(&self) -> Option<Self>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion crates/sel4-capdl-initializer/types/Cargo.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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" ];
Expand Down
2 changes: 1 addition & 1 deletion crates/sel4-capdl-initializer/types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion crates/sel4-capdl-initializer/types/src/footprint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down
2 changes: 1 addition & 1 deletion crates/sel4-capdl-initializer/types/src/frame_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
2 changes: 1 addition & 1 deletion crates/sel4-capdl-initializer/types/src/indirect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
2 changes: 1 addition & 1 deletion crates/sel4-capdl-initializer/types/src/object_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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| {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
})
}

Expand Down
6 changes: 6 additions & 0 deletions crates/sel4-dlmalloc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,12 @@ impl<const N: usize> StaticHeap<N> {
}
}

impl<const N: usize> Default for StaticHeap<N> {
fn default() -> Self {
Self::new()
}
}

impl<const N: usize> GetStaticHeapBounds for &StaticHeap<N> {
fn bounds(self) -> StaticHeapBounds {
StaticHeapBounds::new(self.0.get().cast(), N)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,22 @@
//

use core::arch::{asm, global_asm};
use core::ptr;

#[used]
#[no_mangle]
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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
//

use core::arch::{asm, global_asm};
use core::ptr;
use core::sync::atomic::{AtomicUsize, Ordering};

#[used]
Expand All @@ -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");
Expand Down
6 changes: 6 additions & 0 deletions crates/sel4-microkit/src/defer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,9 @@ impl DeferredActionSlot {
self.defer(DeferredAction::new_irq_ack(channel))
}
}

impl Default for DeferredActionSlot {
fn default() -> Self {
Self::new()
}
}
10 changes: 8 additions & 2 deletions crates/sel4-newlib/src/heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<const N: usize>(UnsafeCell<[u8; N]>);
Expand Down Expand Up @@ -69,6 +69,12 @@ impl<const N: usize> StaticHeap<N> {
}
}

impl<const N: usize> Default for StaticHeap<N> {
fn default() -> Self {
Self::new()
}
}

#[macro_export]
macro_rules! declare_sbrk_with_static_heap {
($n:expr) => {
Expand Down
6 changes: 6 additions & 0 deletions crates/sel4-runtime-common/src/start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ impl<const N: usize> Stack<N> {
}
}

impl<const N: usize> Default for Stack<N> {
fn default() -> Self {
Self::new()
}
}

#[repr(transparent)]
pub struct StackTop(#[allow(dead_code)] *mut u8);

Expand Down
3 changes: 1 addition & 2 deletions crates/sel4-runtime-common/src/unwinding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
})?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,6 @@ impl SlotSemaphore for Rc<DummySlotSemaphore> {

#[cfg(feature = "async-unsync")]
mod async_unsync_impl {
use alloc::rc::Rc;

use async_unsync::semaphore::{Semaphore, TryAcquireError};

use super::*;
Expand Down
12 changes: 12 additions & 0 deletions crates/sel4-sync/src/mutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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")
Expand Down
24 changes: 11 additions & 13 deletions crates/sel4/bitfield-ops/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,26 +200,28 @@ fn checked_cast<T: TryInto<U>, U>(val: T) -> U {
val.try_into().map_err(|_| unreachable!()).unwrap()
}

pub fn set_bits_from_slice<T: UnsignedPrimInt, U: UnsignedPrimInt>(
pub fn set_bits_from_slice<T, U>(
dst: &mut [T],
dst_range: Range<usize>,
src: &[U],
src_start: usize,
) where
T: TryFrom<usize>,
T: UnsignedPrimInt + TryFrom<usize>,
U: UnsignedPrimInt,
usize: TryFrom<U>,
{
set_bits_from_slice_via::<_, _, usize>(dst, dst_range, src, src_start)
}

fn set_bits_from_slice_via<T: UnsignedPrimInt, U: UnsignedPrimInt, V: UnsignedPrimInt>(
fn set_bits_from_slice_via<T, U, V>(
dst: &mut [T],
dst_range: Range<usize>,
src: &[U],
src_start: usize,
) where
T: TryFrom<V>,
V: TryFrom<U>,
T: UnsignedPrimInt + TryFrom<V>,
U: UnsignedPrimInt,
V: UnsignedPrimInt + TryFrom<U>,
{
let num_bits = dst_range.len();

Expand Down Expand Up @@ -302,13 +304,9 @@ impl<T: AsRef<[U]>, U: UnsignedPrimInt> Bitfield<T, U> {
get_bits(self.bits(), range)
}

pub fn get_bits_into_slice<V: UnsignedPrimInt>(
&self,
range: Range<usize>,
dst: &mut [V],
dst_start: usize,
) where
V: TryFrom<usize>,
pub fn get_bits_into_slice<V>(&self, range: Range<usize>, dst: &mut [V], dst_start: usize)
where
V: UnsignedPrimInt + TryFrom<usize>,
usize: TryFrom<U>,
{
let dst_range = dst_start..(dst_start + range.len());
Expand Down Expand Up @@ -355,8 +353,8 @@ impl<T: AsMut<[U]>, U: UnsignedPrimInt> Bitfield<T, U> {
// // //

#[cfg(test)]
#[allow(unused_imports)]
mod test {
#![allow(unused_imports)]

extern crate std;

Expand Down
2 changes: 2 additions & 0 deletions crates/sel4/bitfield-parser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions crates/sel4/src/arch/riscv/vspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
// SPDX-License-Identifier: MIT
//

#![allow(clippy::eq_op)]

use sel4_config::sel4_cfg_wrap_match;

#[allow(unused_imports)]
Expand Down
Loading