refactor: Fix clippy warnings

This commit is contained in:
Mark Poliakov 2024-07-27 14:49:20 +03:00
parent b9c1b15bd1
commit fe5f9649ff
19 changed files with 50 additions and 42 deletions

View File

@ -1,5 +1,6 @@
#![no_std]
#![feature(step_trait, const_trait_impl, never_type)]
#![allow(clippy::new_without_default)]
use alloc::vec::Vec;
use cpu::IpiQueue;

View File

@ -1,5 +1,6 @@
//! PCI/PCIe bus interfaces
#![no_std]
#![allow(clippy::missing_transmute_annotations)]
extern crate alloc;

View File

@ -1,5 +1,5 @@
#![feature(map_try_insert)]
#![allow(clippy::type_complexity)]
#![allow(clippy::type_complexity, clippy::new_without_default)]
#![no_std]
extern crate alloc;

View File

@ -1,5 +1,6 @@
#![feature(trait_alias)]
#![no_std]
#![allow(clippy::new_without_default)]
extern crate alloc;

View File

@ -1,4 +1,5 @@
#![no_std]
#![allow(clippy::missing_transmute_annotations)]
extern crate alloc;

View File

@ -7,6 +7,7 @@
const_trait_impl,
build_hasher_default_const_new
)]
#![allow(clippy::new_without_default)]
extern crate alloc;

View File

@ -168,7 +168,7 @@ fn setup_context(
})
}
fn setup_binary<S: Into<String>>(
fn setup_binary<S>(
name: S,
group_id: ProcessGroupId,
parent: Option<Weak<Process>>,

View File

@ -51,9 +51,7 @@ pub trait TerminalOutput: Sync {
fn write_multiple(&self, bytes: &[u8]) -> Result<usize, Error> {
let mut written = 0;
for &byte in bytes {
if let Err(error) = self.write(byte) {
return Err(error);
}
self.write(byte)?;
written += 1;
}
Ok(written)
@ -215,7 +213,7 @@ impl TerminalInput {
}
}
pub fn poll_read<'a>(&'a self, cx: &mut Context<'_>) -> Poll<()> {
pub fn poll_read(&self, cx: &mut Context<'_>) -> Poll<()> {
self.ready_ring.poll_readable(cx)
}

View File

@ -29,6 +29,7 @@
clippy::fn_to_numeric_cast,
clippy::match_ref_pats,
clippy::match_single_binding,
clippy::missing_transmute_annotations,
async_fn_in_trait
)]
#![deny(missing_docs)]

View File

@ -36,6 +36,10 @@ fn run_with_io_at<T, F: FnOnce(NodeRef, IrqSafeSpinlockGuard<ProcessIo>) -> Resu
}
/// Handles "return from signal" syscall
///
/// # Safety
///
/// Unsafe: manipulates current thread's context
pub unsafe fn handle_signal_exit<F: TaskFrame>(frame: &mut F) {
let saved_data: &SignalEntryData = match arg::ref_const(frame.argument() as _) {
Ok(r) => r,

View File

@ -117,26 +117,29 @@ impl<P: PageProvider> BucketAllocator<P> {
let aligned = layout.pad_to_align();
match aligned.size() {
..=32 => self.buckets_32.allocate(),
..=64 => self.buckets_64.allocate(),
..=128 => self.buckets_128.allocate(),
..=256 => self.buckets_256.allocate(),
..=512 => self.buckets_512.allocate(),
..=1024 => self.buckets_1024.allocate(),
size if size <= 32 => self.buckets_32.allocate(),
size if size <= 64 => self.buckets_64.allocate(),
size if size <= 128 => self.buckets_128.allocate(),
size if size <= 256 => self.buckets_256.allocate(),
size if size <= 512 => self.buckets_512.allocate(),
size if size <= 1024 => self.buckets_1024.allocate(),
size => P::map_pages((size + sys::PAGE_SIZE - 1) / sys::PAGE_SIZE),
}
}
/// # Safety
///
/// Unsafe: may cause double-free problem and panic
pub unsafe fn free(&mut self, ptr: NonNull<u8>, layout: Layout) {
let aligned = layout.pad_to_align();
match aligned.size() {
..=32 => self.buckets_32.free(ptr),
..=64 => self.buckets_64.free(ptr),
..=128 => self.buckets_128.free(ptr),
..=256 => self.buckets_256.free(ptr),
..=512 => self.buckets_512.free(ptr),
..=1024 => self.buckets_1024.free(ptr),
size if size <= 32 => self.buckets_32.free(ptr),
size if size <= 64 => self.buckets_64.free(ptr),
size if size <= 128 => self.buckets_128.free(ptr),
size if size <= 256 => self.buckets_256.free(ptr),
size if size <= 512 => self.buckets_512.free(ptr),
size if size <= 1024 => self.buckets_1024.free(ptr),
size => {
assert_eq!(usize::from(ptr.addr()) % sys::PAGE_SIZE, 0);
P::unmap_pages(ptr, (size + sys::PAGE_SIZE - 1) / sys::PAGE_SIZE);

View File

@ -8,7 +8,7 @@
allocator_api
)]
#![cfg_attr(not(test), no_std)]
#![allow(incomplete_features, unexpected_cfgs)]
#![allow(incomplete_features, unexpected_cfgs, clippy::new_without_default)]
#![deny(fuzzy_provenance_casts, lossy_provenance_casts)]
#[cfg(test)]

View File

@ -4,7 +4,7 @@ use core::fmt;
pub use abi::debug::{DebugFrame, DebugOperation};
///
/// Prints a debug message using DebugTrace syscall
#[macro_export]
macro_rules! debug_trace {
($($args:tt)+) => {

View File

@ -120,6 +120,7 @@ impl Syscall {
};
let v = quote! {
#[allow(clippy::missing_safety_doc)]
pub unsafe fn #name(#args) #return_type_arrow {
#wrapped
}

View File

@ -3,11 +3,11 @@ use std::{io, path::PathBuf};
#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error("I/O error: {0}")]
IoError(#[from] io::Error),
Io(#[from] io::Error),
#[error("ELF parse error: {0}")]
ElfParseError(#[from] elf::ParseError),
ElfParse(#[from] elf::ParseError),
#[error("Could not map memory ({0} bytes): {1:?}")]
MapError(usize, yggdrasil_rt::Error),
Map(usize, yggdrasil_rt::Error),
#[error("Could not locate library: {0}")]
LibraryNotFound(String),
#[error("Cannot perform the operation: object is not loaded yet")]

View File

@ -101,7 +101,7 @@ fn run<P: AsRef<Path>>(path: P, args: &[String]) -> Result<(), Error> {
return Err(Error::UndefinedReference);
}
let args = args.into_iter().map(|s| s.as_str()).collect::<Vec<_>>();
let args = args.iter().map(|s| s.as_str()).collect::<Vec<_>>();
// TODO pass environment to the program
let envs = vec![];
@ -153,7 +153,7 @@ If needed, the program can still be invoked like follows:
let args = &args[1..];
let program = PathBuf::from(&args[0]);
match run(program, &args) {
match run(program, args) {
// Normal execution doesn't return here, but if LD_TRACE_LOADED_OBJECTS is set,
// the loader will exit after printing everything
Ok(()) => ExitCode::SUCCESS,

View File

@ -65,10 +65,10 @@ impl Object {
// Extract info from .dynamic
let mut needed = vec![];
if let Some(dynamic) = elf.dynamic()? {
// TODO use filter() instead?
for entry in dynamic {
match entry.d_tag {
elf::abi::DT_NEEDED => needed.push(entry.d_val() as usize),
_ => (),
if entry.d_tag == elf::abi::DT_NEEDED {
needed.push(entry.d_val() as usize);
}
}
}
@ -202,10 +202,8 @@ impl Object {
for dynsym in self.dynamic_symbol_array.iter_mut() {
if dynsym.value.is_none() {
state.resolve_symbol(dynsym);
} else {
if dynsym.raw.st_shndx == elf::abi::SHN_UNDEF {
state.undefined_references.push(dynsym.name.clone());
}
} else if dynsym.raw.st_shndx == elf::abi::SHN_UNDEF {
state.undefined_references.push(dynsym.name.clone());
}
}
@ -265,7 +263,7 @@ impl Object {
impl ObjectMapping {
pub fn new(size: usize) -> Result<Self, Error> {
let base = unsafe { yggdrasil_rt::sys::map_memory(None, size, &MappingSource::Anonymous) }
.map_err(|e| Error::MapError(size, e))?;
.map_err(|e| Error::Map(size, e))?;
Ok(Self { base, size })
}

View File

@ -15,11 +15,11 @@ impl RelValue {
pub fn write(&self, mapping: &mut ObjectMapping, offset: u64) {
let addr = mapping.base + offset as usize;
unsafe {
match self {
&Self::QWord(value) => {
match *self {
Self::QWord(value) => {
(addr as *mut i64).write_volatile(value);
}
&Self::QDWord(word0, word1) => {
Self::QDWord(word0, word1) => {
(addr as *mut i64).write_volatile(word0);
(addr as *mut i64).add(1).write_volatile(word1);
}

View File

@ -94,12 +94,10 @@ impl State {
} else if !sym.name.is_empty() {
self.undefined_references.push(sym.name.clone());
}
} else {
if let Some((value, _)) = self.symbol_table.get(&sym.name) {
sym.value = Some(*value);
} else if !sym.name.is_empty() {
self.undefined_references.push(sym.name.clone());
}
} else if let Some((value, _)) = self.symbol_table.get(&sym.name) {
sym.value = Some(*value);
} else if !sym.name.is_empty() {
self.undefined_references.push(sym.name.clone());
}
}