Resolve a huge portion of the clippy lints
This commit is contained in:
committed by
Jeremy Soller
parent
db8fb14614
commit
0931a7f49f
@@ -1,5 +1,5 @@
|
||||
use alloc::{string::String, vec::Vec};
|
||||
use core::{ascii, mem};
|
||||
use core::{ascii, fmt::Debug, mem};
|
||||
|
||||
use super::{
|
||||
copy_path_to_buf,
|
||||
@@ -13,7 +13,7 @@ use crate::{sync::CleanLockToken, syscall::error::Result};
|
||||
|
||||
struct ByteStr<'a>(&'a [u8]);
|
||||
|
||||
impl<'a> ::core::fmt::Debug for ByteStr<'a> {
|
||||
impl Debug for ByteStr<'_> {
|
||||
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
|
||||
write!(f, "\"")?;
|
||||
for i in self.0 {
|
||||
@@ -61,13 +61,13 @@ pub fn format_call(a: usize, b: usize, c: usize, d: usize, e: usize, f: usize) -
|
||||
SYS_DUP => format!(
|
||||
"dup({}, {:?})",
|
||||
b,
|
||||
debug_buf(c, d).as_ref().map(|b| ByteStr(&*b)),
|
||||
debug_buf(c, d).as_ref().map(|b| ByteStr(b)),
|
||||
),
|
||||
SYS_DUP2 => format!(
|
||||
"dup2({}, {}, {:?})",
|
||||
b,
|
||||
c,
|
||||
debug_buf(d, e).as_ref().map(|b| ByteStr(&*b)),
|
||||
debug_buf(d, e).as_ref().map(|b| ByteStr(b)),
|
||||
),
|
||||
SYS_SENDFD => format!("sendfd({}, {}, {:#0x} {:#0x} {:#0x})", b, c, d, e, f,),
|
||||
SYS_READ => format!("read({}, {:#X}, {})", b, c, d),
|
||||
@@ -222,6 +222,8 @@ pub fn debug_start([a, b, c, d, e, f]: [usize; 6], token: &mut CleanLockToken) {
|
||||
return;
|
||||
}
|
||||
|
||||
#[expect(clippy::overly_complex_bool_expr)]
|
||||
#[expect(clippy::needless_bool)]
|
||||
let do_debug = if false
|
||||
&& crate::context::current()
|
||||
.read(token.token())
|
||||
|
||||
+31
-33
@@ -76,8 +76,10 @@ fn is_legacy(path_buf: &String) -> bool {
|
||||
|
||||
/// Open syscall
|
||||
pub fn open(raw_path: UserSliceRo, flags: usize, token: &mut CleanLockToken) -> Result<FileHandle> {
|
||||
let (pid, uid, gid, scheme_ns) = match context::current().read(token.token()) {
|
||||
ref cx => (cx.pid.into(), cx.euid, cx.egid, cx.ens),
|
||||
let (pid, uid, gid, scheme_ns) = {
|
||||
let ctx = context::current();
|
||||
let cx = &ctx.read(token.token());
|
||||
(cx.pid, cx.euid, cx.egid, cx.ens)
|
||||
};
|
||||
|
||||
// TODO: BorrowedHtBuf!
|
||||
@@ -91,7 +93,7 @@ pub fn open(raw_path: UserSliceRo, flags: usize, token: &mut CleanLockToken) ->
|
||||
// Display a deprecation warning for any usage of the legacy scheme syntax (scheme:/path)
|
||||
// FIXME remove entries from this list as the respective programs get updated
|
||||
if path_buf.contains(':') && !is_legacy(&path_buf) {
|
||||
let name = context::current().read(token.token()).name.clone();
|
||||
let name = context::current().read(token.token()).name;
|
||||
if name.contains("cosmic") && (path_buf == "event:" || path_buf.starts_with("time:")) {
|
||||
// FIXME cosmic apps likely need crate updates
|
||||
} else {
|
||||
@@ -200,8 +202,10 @@ pub fn openat(
|
||||
}
|
||||
/// rmdir syscall
|
||||
pub fn rmdir(raw_path: UserSliceRo, token: &mut CleanLockToken) -> Result<()> {
|
||||
let (scheme_ns, caller_ctx) = match context::current().read(token.token()) {
|
||||
ref cx => (cx.ens, cx.caller_ctx()),
|
||||
let (scheme_ns, caller_ctx) = {
|
||||
let ctx = context::current();
|
||||
let cx = &ctx.read(token.token());
|
||||
(cx.ens, cx.caller_ctx())
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -224,8 +228,10 @@ pub fn rmdir(raw_path: UserSliceRo, token: &mut CleanLockToken) -> Result<()> {
|
||||
|
||||
/// Unlink syscall
|
||||
pub fn unlink(raw_path: UserSliceRo, token: &mut CleanLockToken) -> Result<()> {
|
||||
let (scheme_ns, caller_ctx) = match context::current().read(token.token()) {
|
||||
ref cx => (cx.ens, cx.caller_ctx()),
|
||||
let (scheme_ns, caller_ctx) = {
|
||||
let ctx = context::current();
|
||||
let cx = &ctx.read(token.token());
|
||||
(cx.ens, cx.caller_ctx())
|
||||
};
|
||||
/*
|
||||
let mut path_buf = BorrowedHtBuf::head()?;
|
||||
@@ -424,14 +430,9 @@ fn fdwrite_inner(
|
||||
let (scheme, number) = {
|
||||
let current_lock = context::current();
|
||||
let current = current_lock.read(token.token());
|
||||
match current
|
||||
.get_file(socket)
|
||||
.ok_or(Error::new(EBADF))?
|
||||
.description
|
||||
.read()
|
||||
{
|
||||
ref desc => (desc.scheme, desc.number),
|
||||
}
|
||||
let file_descriptor = current.get_file(socket).ok_or(Error::new(EBADF))?;
|
||||
let desc = &file_descriptor.description.read();
|
||||
(desc.scheme, desc.number)
|
||||
};
|
||||
let scheme = scheme::schemes(token.token())
|
||||
.get(scheme)
|
||||
@@ -483,14 +484,9 @@ fn call_fdread(
|
||||
let (scheme, number) = {
|
||||
let current_lock = context::current();
|
||||
let current = current_lock.read(token.token());
|
||||
match current
|
||||
.get_file(fd)
|
||||
.ok_or(Error::new(EBADF))?
|
||||
.description
|
||||
.read()
|
||||
{
|
||||
ref desc => (desc.scheme, desc.number),
|
||||
}
|
||||
let file_descriptor = current.get_file(fd).ok_or(Error::new(EBADF))?;
|
||||
let desc = file_descriptor.description.read();
|
||||
(desc.scheme, desc.number)
|
||||
};
|
||||
let scheme = scheme::schemes(token.token())
|
||||
.get(scheme)
|
||||
@@ -588,8 +584,10 @@ pub fn fcntl(fd: FileHandle, cmd: usize, arg: usize, token: &mut CleanLockToken)
|
||||
}
|
||||
|
||||
pub fn flink(fd: FileHandle, raw_path: UserSliceRo, token: &mut CleanLockToken) -> Result<()> {
|
||||
let (caller_ctx, scheme_ns) = match context::current().read(token.token()) {
|
||||
ref cx => (cx.caller_ctx(), cx.ens),
|
||||
let (caller_ctx, scheme_ns) = {
|
||||
let ctx = context::current();
|
||||
let cx = &ctx.read(token.token());
|
||||
(cx.caller_ctx(), cx.ens)
|
||||
};
|
||||
let file = context::current()
|
||||
.read(token.token())
|
||||
@@ -622,8 +620,10 @@ pub fn flink(fd: FileHandle, raw_path: UserSliceRo, token: &mut CleanLockToken)
|
||||
}
|
||||
|
||||
pub fn frename(fd: FileHandle, raw_path: UserSliceRo, token: &mut CleanLockToken) -> Result<()> {
|
||||
let (caller_ctx, scheme_ns) = match context::current().read(token.token()) {
|
||||
ref cx => (cx.caller_ctx(), cx.ens),
|
||||
let (caller_ctx, scheme_ns) = {
|
||||
let ctx = context::current();
|
||||
let cx = &ctx.read(token.token());
|
||||
(cx.caller_ctx(), cx.ens)
|
||||
};
|
||||
let file = context::current()
|
||||
.read(token.token())
|
||||
@@ -844,9 +844,8 @@ pub fn sys_read(fd: FileHandle, buf: UserSliceWo, token: &mut CleanLockToken) ->
|
||||
))
|
||||
})?;
|
||||
if desc.internal_flags.contains(InternalFlags::POSITIONED) {
|
||||
match desc_arc.write().offset {
|
||||
ref mut offset => *offset = offset.saturating_add(bytes_read as u64),
|
||||
}
|
||||
let offset = &mut desc_arc.write().offset;
|
||||
*offset = offset.saturating_add(bytes_read as u64)
|
||||
}
|
||||
Ok(bytes_read)
|
||||
}
|
||||
@@ -865,9 +864,8 @@ pub fn sys_write(fd: FileHandle, buf: UserSliceRo, token: &mut CleanLockToken) -
|
||||
))
|
||||
})?;
|
||||
if desc.internal_flags.contains(InternalFlags::POSITIONED) {
|
||||
match desc_arc.write().offset {
|
||||
ref mut offset => *offset = offset.saturating_add(bytes_written as u64),
|
||||
}
|
||||
let offset = &mut desc_arc.write().offset;
|
||||
*offset = offset.saturating_add(bytes_written as u64)
|
||||
}
|
||||
Ok(bytes_written)
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ pub fn futex(
|
||||
let addr_space_guard = current_addrsp.acquire_read();
|
||||
|
||||
let target_virtaddr = VirtualAddress::new(addr);
|
||||
let target_physaddr = validate_and_translate_virt(&*addr_space_guard, target_virtaddr)
|
||||
let target_physaddr = validate_and_translate_virt(&addr_space_guard, target_virtaddr)
|
||||
.ok_or(Error::new(EFAULT))?;
|
||||
|
||||
match op {
|
||||
@@ -128,9 +128,7 @@ pub fn futex(
|
||||
return Err(Error::new(EINVAL));
|
||||
}
|
||||
(
|
||||
u64::from(unsafe {
|
||||
(*(addr as *const AtomicU64)).load(Ordering::SeqCst)
|
||||
}),
|
||||
unsafe { (*(addr as *const AtomicU64)).load(Ordering::SeqCst) },
|
||||
val as u64,
|
||||
)
|
||||
}
|
||||
|
||||
+1
-1
@@ -233,7 +233,7 @@ pub fn syscall(
|
||||
),
|
||||
SYS_MREMAP => mremap(b, c, d, e, f, token),
|
||||
|
||||
_ => return Err(Error::new(ENOSYS)),
|
||||
_ => Err(Error::new(ENOSYS)),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,8 +8,10 @@ use super::{
|
||||
};
|
||||
|
||||
pub fn mkns(mut user_buf: UserSliceRo, token: &mut CleanLockToken) -> Result<usize> {
|
||||
let (uid, from) = match context::current().read(token.token()) {
|
||||
ref cx => (cx.euid, cx.ens),
|
||||
let (uid, from) = {
|
||||
let ctx = context::current();
|
||||
let cx = &ctx.read(token.token());
|
||||
(cx.euid, cx.ens)
|
||||
};
|
||||
|
||||
// TODO: Lift this restriction later?
|
||||
|
||||
@@ -52,7 +52,7 @@ pub fn exit_this_context(excp: Option<syscall::Exception>, token: &mut CleanLock
|
||||
guard.owner_proc_id
|
||||
};
|
||||
if let Some(owner) = owner {
|
||||
let _ = event::trigger(
|
||||
event::trigger(
|
||||
GlobalSchemes::Proc.scheme_id(),
|
||||
owner.get(),
|
||||
EventFlags::EVENT_READ,
|
||||
@@ -129,15 +129,14 @@ pub unsafe fn usermode_bootstrap(bootstrap: &Bootstrap, token: &mut CleanLockTok
|
||||
|
||||
// Start in a minimal environment without any stack.
|
||||
|
||||
match context::current()
|
||||
.write(token.token())
|
||||
let ctx = context::current();
|
||||
let mut lock = ctx.write(token.token());
|
||||
let regs = &mut lock
|
||||
.regs_mut()
|
||||
.expect("bootstrap needs registers to be available")
|
||||
.expect("bootstrap needs registers to be available");
|
||||
{
|
||||
ref mut regs => {
|
||||
regs.init();
|
||||
regs.set_instr_pointer(bootstrap_entry.try_into().unwrap());
|
||||
}
|
||||
regs.init();
|
||||
regs.set_instr_pointer(bootstrap_entry.try_into().unwrap());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -159,7 +159,7 @@ impl<const WRITE: bool> UserSlice<true, WRITE> {
|
||||
impl<const READ: bool> UserSlice<READ, true> {
|
||||
pub fn copy_from_slice(self, slice: &[u8]) -> Result<()> {
|
||||
// A zero sized slice will like have 0x1 as address
|
||||
debug_assert!(is_kernel_mem(slice) || slice.len() == 0);
|
||||
debug_assert!(is_kernel_mem(slice) || slice.is_empty());
|
||||
|
||||
if self.len != slice.len() {
|
||||
return Err(Error::new(EINVAL));
|
||||
|
||||
Reference in New Issue
Block a user