Merge branch 'clippy-green3' into 'master'

tackle more clippy lints for redox

See merge request redox-os/relibc!1549
This commit is contained in:
Jeremy Soller
2026-07-15 10:27:40 -06:00
15 changed files with 97 additions and 70 deletions
+4 -5
View File
@@ -104,13 +104,12 @@ impl PalEpoll for Sys {
};
let callback = || {
let res = syscall::read(epfd as usize, unsafe {
syscall::read(epfd as usize, unsafe {
slice::from_raw_parts_mut(
events as *mut u8,
events.cast::<u8>(),
maxevents as usize * mem::size_of::<syscall::Event>(),
)
});
res
})
};
let bytes_read = if sigset.is_null() {
@@ -128,7 +127,7 @@ impl PalEpoll for Sys {
unsafe {
let event_ptr = events.add(i);
let target_ptr = events.add(count);
let event = *(event_ptr as *mut Event);
let event = *event_ptr.cast::<Event>();
*target_ptr = epoll_event {
events: event_flags_to_epoll(event.flags),
data: epoll_data {
+6 -6
View File
@@ -31,7 +31,7 @@ fn fexec_impl(
interp_override: new_interp_override,
} = redox_rt::proc::fexec_impl(
exec_file,
&RtTcb::current().thread_fd(),
RtTcb::current().thread_fd(),
redox_rt::current_proc_fd(),
path,
args,
@@ -49,11 +49,11 @@ fn fexec_impl(
// null-terminated. Violating this should therefore give the "format error" ENOEXEC.
let path_cstr = CStr::from_bytes_with_nul(&path).map_err(|_| Error::new(ENOEXEC))?;
return execve(
execve(
Executable::AtPath(path_cstr),
ArgEnv::Parsed { args, envs },
Some(new_interp_override),
);
)
}
pub enum ArgEnv<'a> {
@@ -111,9 +111,9 @@ pub fn execve(
let Resugid { ruid, rgid, .. } = redox_rt::sys::posix_getresugid();
let mode = if ruid == stat.st_uid {
(stat.st_mode >> 3 * 2) & 0o7
(stat.st_mode >> (3 * 2)) & 0o7
} else if rgid == stat.st_gid {
(stat.st_mode >> 3 * 1) & 0o7
(stat.st_mode >> 3) & 0o7
} else {
stat.st_mode & 0o7
};
@@ -162,7 +162,7 @@ pub fn execve(
let mut args: Vec<&[u8]> = Vec::with_capacity(len);
if let Some(interpreter) = &interpreter_path {
image_file = File::open(CStr::borrow(&interpreter), O_RDONLY as c_int)
image_file = File::open(CStr::borrow(interpreter), O_RDONLY as c_int)
.map_err(|_| Error::new(ENOENT))?;
// Push interpreter to arguments
+1 -1
View File
@@ -11,7 +11,7 @@ pub use redox_rt::proc::FdGuard;
#[unsafe(no_mangle)]
pub unsafe extern "C" fn redox_fpath(fd: c_int, buf: *mut c_void, count: size_t) -> ssize_t {
syscall::fpath(fd as usize, unsafe {
slice::from_raw_parts_mut(buf as *mut u8, count)
slice::from_raw_parts_mut(buf.cast::<u8>(), count)
})
.map_err(Errno::from)
.map(|l| l as ssize_t)
+4 -5
View File
@@ -1,8 +1,7 @@
use crate::{c_str::CStr, header::stdlib::getenv, platform::types::*};
use core::ptr;
use crate::{c_str::CStr, header::stdlib::getenv, platform::types::c_char};
use syscall::{EIO, ENOENT, Error, Result, flag::*};
pub const LIBC_SCHEME: &'static str = "libc:";
pub const LIBC_SCHEME: &str = "libc:";
const ENV_MAX_LEN: i32 = i32::MAX;
@@ -10,8 +9,8 @@ macro_rules! env_str {
($lit:expr) => {
#[allow(unused_unsafe)]
{
let val_bytes = unsafe { getenv(concat!($lit, "\0").as_ptr() as *const c_char) };
if val_bytes != ptr::null_mut() {
let val_bytes = unsafe { getenv(concat!($lit, "\0").as_ptr().cast::<c_char>()) };
if !val_bytes.is_null() {
if let Ok(val_str) = unsafe { CStr::from_ptr(val_bytes) }.to_str() {
Some(val_str)
} else {
+9 -10
View File
@@ -31,7 +31,7 @@ pub fn openat(dirfd: c_int, path: RedoxStr<'_>, oflag: c_int, mode: mode_t) -> R
((oflag as usize) & 0xFFFF_0000) | ((mode as usize) & 0xFFFF),
)?;
if let Err(_) = c_int::try_from(usize_fd) {
if c_int::try_from(usize_fd).is_err() {
let _ = redox_rt::sys::close(usize_fd);
return Err(Error::new(EMFILE));
}
@@ -42,7 +42,7 @@ pub fn fchmod(fd: usize, new_mode: u16) -> Result<()> {
std_fs_call_wo(
fd,
&[],
&StdFsCallMeta::new(StdFsCallKind::Fchmod, new_mode as u64, 0),
&StdFsCallMeta::new(StdFsCallKind::Fchmod, u64::from(new_mode), 0),
)?;
Ok(())
}
@@ -77,7 +77,7 @@ pub fn getdents(fd: usize, buf: &mut [u8], opaque: u64) -> Result<usize> {
}) => (),
other => {
//println!("REAL GETDENTS {:?}", other);
return Ok(other?);
return other;
}
}
@@ -87,7 +87,7 @@ pub fn getdents(fd: usize, buf: &mut [u8], opaque: u64) -> Result<usize> {
let (header, name) = buf.split_at_mut(mem::size_of::<DirentHeader>());
let bytes_read = Sys::pread(fd as c_int, name, opaque as i64)? as usize;
let bytes_read = Sys::pread(fd as c_int, name, opaque as i64)?;
if bytes_read == 0 {
return Ok(0);
}
@@ -122,7 +122,7 @@ pub unsafe fn fstat(fd: usize, buf: *mut crate::header::sys_stat::stat) -> Resul
if let Some(buf) = unsafe { buf.as_mut() } {
buf.st_dev = redox_buf.st_dev as dev_t;
buf.st_ino = redox_buf.st_ino as ino_t;
buf.st_nlink = redox_buf.st_nlink as nlink_t;
buf.st_nlink = nlink_t::from(redox_buf.st_nlink);
buf.st_mode = redox_buf.st_mode as mode_t;
buf.st_uid = redox_buf.st_uid as uid_t;
buf.st_gid = redox_buf.st_gid as gid_t;
@@ -202,7 +202,7 @@ pub unsafe fn futimens(fd: usize, times: *const timespec) -> Result<()> {
};
let redox_buf = unsafe {
slice::from_raw_parts(
times.as_ptr() as *const u8,
times.as_ptr().cast::<u8>(),
times.len() * mem::size_of::<syscall::TimeSpec>(),
)
};
@@ -215,7 +215,7 @@ pub unsafe fn futimens(fd: usize, times: *const timespec) -> Result<()> {
}
pub fn clock_gettime(clock: usize, mut tp: Out<timespec>) -> Result<()> {
let mut redox_tp = syscall::TimeSpec::default();
syscall::clock_gettime(clock as usize, &mut redox_tp)?;
syscall::clock_gettime(clock, &mut redox_tp)?;
tp.write((&redox_tp).into());
Ok(())
}
@@ -228,9 +228,8 @@ pub unsafe extern "C" fn redox_open_v1(
mode: u16,
) -> RawResult {
let path = unsafe { str::from_utf8_unchecked(slice::from_raw_parts(path_base, path_len)) };
let path = match RedoxStr::new(path) {
Some(path) => path,
None => return Error::mux(Err(Error::new(EINVAL))),
let Some(path) = RedoxStr::new(path) else {
return Error::mux(Err(Error::new(EINVAL)));
};
Error::mux(openat(AT_FDCWD, path, flags as c_int, mode as mode_t))
}
+9 -9
View File
@@ -29,7 +29,7 @@ pub fn chdir(path: RedoxStr<'_>) -> Result<()> {
let (redox, fd) = match path {
RedoxStr::Absolute(path) => {
let path = path.to_standard_canon();
let fd = FdGuard::open_into_upper(&path.as_reference(), O_STAT);
let fd = FdGuard::open_into_upper(path.as_reference(), O_STAT);
(path.into_owned(), fd)
}
RedoxStr::Relative(redox_reference) => {
@@ -112,7 +112,7 @@ pub struct Cwd<'a> {
static CWD: RwLock<Option<Cwd<'_>>> = RwLock::new(None);
pub fn to_cwd_path(path: &str) -> Result<CwdPath> {
ArrayString::from_str(&path).or(Err(Error::new(ENAMETOOLONG)))
ArrayString::from_str(path).or(Err(Error::new(ENAMETOOLONG)))
}
pub fn set_cwd_manual(path: CwdPath, fd: FdGuardUpper) -> Result<()> {
@@ -126,7 +126,7 @@ pub fn set_cwd_manual(path: CwdPath, fd: FdGuardUpper) -> Result<()> {
pub fn clone_cwd() -> Option<CwdPath> {
let _siglock = tmp_disable_signals();
CWD.read().as_ref().map(|cwd| cwd.path.clone())
CWD.read().as_ref().map(|cwd| cwd.path)
}
fn open_absolute(path: &str, flags: usize) -> Result<usize> {
@@ -138,9 +138,9 @@ fn open_absolute(path: &str, flags: usize) -> Result<usize> {
}
// Read symlink content
fn read_link_content<'a, 'b>(
fn read_link_content<'b>(
dirfd: Option<&FdGuard>,
path: &'a str,
path: &str,
is_relative: bool,
) -> Result<RedoxStr<'b>> {
let resolve_flags = O_CLOEXEC | O_SYMLINK | O_RDONLY;
@@ -156,7 +156,7 @@ fn read_link_content<'a, 'b>(
log::trace!(
"read_link_content ({:?} {:?} {}): {:?}",
dirfd,
&path,
path,
is_relative,
fd
);
@@ -180,7 +180,7 @@ fn resolve_sym_links<'a>(mut current_path_string: RedoxPath<'a>, flags: usize) -
let dirname = current_path_string.dirname();
let cow: Cow<'_, str> = current_path_string.into();
let initial_res = open_absolute(&cow, flags);
log::trace!("resolve_sym_links({:?}): {:?}", &cow, initial_res);
log::trace!("resolve_sym_links({:?}): {:?}", cow, initial_res);
match initial_res {
Ok(fd) => return Ok(fd),
Err(e) if e == Error::new(EXDEV) => {
@@ -384,14 +384,14 @@ fn at_flags_to_open_flags(at_flags: c_int) -> c_int {
/// # Arguments
/// * `dirfd` is a directory descriptor to which `path` is resolved.
/// * `path` is a relative or absolute path. Relative paths are resolved in relation to `dirfd`
/// while absolute paths skip `dirfd`.
/// while absolute paths skip `dirfd`.
/// * `at_flags` constrains how `path` is resolved.
/// * `oflags` are flags that are passed to open.
///
/// # Constants
/// `at_flags`:
/// * AT_EMPTY_PATH returns the path at `dirfd` itself if `path` is empty. If `path` is not
/// empty, it's resolved w.r.t `dirfd` like normal.
/// empty, it's resolved w.r.t `dirfd` like normal.
///
/// `dirfd`:
/// `AT_FDCWD` is a special constant for `dirfd` that resolves `path` under the current working
+3 -3
View File
@@ -60,7 +60,7 @@ pub fn init_state() -> &'static State {
if STATE.unsafe_ref().is_none() {
STATE.unsafe_set(Some(State::new()));
}
let state_ptr = STATE.unsafe_ref().as_ref().unwrap() as *const State;
let state_ptr = core::ptr::from_ref::<State>(STATE.unsafe_ref().as_ref().unwrap());
&*state_ptr
}
}
@@ -193,7 +193,7 @@ unsafe fn inner_ptrace(
Ok(0)
}
sys_ptrace::PTRACE_GETREGS => {
let c_regs = unsafe { &mut *(data as *mut user_regs_struct) };
let c_regs = unsafe { &mut *data.cast::<user_regs_struct>() };
let mut redox_regs = syscall::IntRegisters::default();
(&mut &session.regs).read(&mut redox_regs)?;
*c_regs = user_regs_struct {
@@ -228,7 +228,7 @@ unsafe fn inner_ptrace(
Ok(0)
}
sys_ptrace::PTRACE_SETREGS => {
let c_regs = unsafe { &*(data as *mut user_regs_struct) };
let c_regs = unsafe { &*data.cast::<user_regs_struct>() };
let redox_regs = syscall::IntRegisters {
r15: c_regs.r15 as _,
r14: c_regs.r14 as _,
+24 -4
View File
@@ -115,7 +115,14 @@ impl PalSignal for Sys {
SigactionKind::Handled {
handler: if c_act.sa_flags & crate::header::signal::SA_SIGINFO as c_int != 0 {
SignalHandler {
sigaction: unsafe { core::mem::transmute(c_act.sa_handler) },
sigaction: unsafe {
core::mem::transmute::<
core::option::Option<extern "C" fn(i32)>,
core::option::Option<
unsafe extern "C" fn(i32, *const (), *mut ()),
>,
>(c_act.sa_handler)
},
}
} else {
SignalHandler {
@@ -138,20 +145,33 @@ impl PalSignal for Sys {
if let (Some(c_oact), Some(old_action)) = (c_oact, old_action) {
*c_oact = match old_action.kind {
SigactionKind::Ignore => sigaction {
sa_handler: unsafe { core::mem::transmute(SIG_IGN) },
sa_handler: unsafe {
core::mem::transmute::<usize, core::option::Option<extern "C" fn(i32)>>(
SIG_IGN,
)
},
sa_flags: 0,
sa_restorer: None,
sa_mask: 0,
},
SigactionKind::Default => sigaction {
sa_handler: unsafe { core::mem::transmute(SIG_DFL) },
sa_handler: unsafe {
core::mem::transmute::<usize, core::option::Option<extern "C" fn(i32)>>(
SIG_DFL,
)
},
sa_flags: 0,
sa_restorer: None,
sa_mask: 0,
},
SigactionKind::Handled { handler } => sigaction {
sa_handler: if old_action.flags.contains(SigactionFlags::SIGINFO) {
unsafe { core::mem::transmute(handler.sigaction) }
unsafe {
core::mem::transmute::<
core::option::Option<unsafe extern "C" fn(i32, *const (), *mut ())>,
core::option::Option<extern "C" fn(i32)>,
>(handler.sigaction)
}
} else {
unsafe { handler.handler }
},