Merge branch 'clippy-green3' into 'master'
tackle more clippy lints for redox See merge request redox-os/relibc!1549
This commit is contained in:
@@ -68,13 +68,13 @@ impl<'a> From<&'a syscall::TimeSpec> for timespec {
|
||||
fn from(value: &'a syscall::TimeSpec) -> Self {
|
||||
Self {
|
||||
tv_sec: value.tv_sec as _,
|
||||
tv_nsec: value.tv_nsec as _,
|
||||
tv_nsec: value.tv_nsec.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "redox")]
|
||||
impl<'a> From<&'a timespec> for syscall::TimeSpec {
|
||||
impl From<×pec> for syscall::TimeSpec {
|
||||
fn from(tp: ×pec) -> Self {
|
||||
Self {
|
||||
tv_sec: tp.tv_sec as _,
|
||||
|
||||
@@ -5,7 +5,7 @@ pub fn split(line: &mut [u8]) -> Option<passwd> {
|
||||
let mut parts = line.split_mut(|&c| c == b'\0');
|
||||
Some(passwd {
|
||||
pw_name: parts.next()?.as_mut_ptr().cast::<c_char>(),
|
||||
pw_passwd: c"x".as_ptr() as *const c_char as *mut c_char,
|
||||
pw_passwd: c"x".as_ptr().cast::<c_char>().cast_mut(),
|
||||
pw_uid: parsed(parts.next())?,
|
||||
pw_gid: parsed(parts.next())?,
|
||||
pw_gecos: parts.next()?.as_mut_ptr().cast::<c_char>(),
|
||||
|
||||
@@ -22,7 +22,9 @@ fn dup_read<T>(fd: c_int, name: &str, t: &mut T) -> syscall::Result<usize> {
|
||||
|
||||
let size = mem::size_of::<T>();
|
||||
|
||||
let bytes = dup.read(unsafe { slice::from_raw_parts_mut(t as *mut T as *mut u8, size) })?;
|
||||
let bytes = dup.read(unsafe {
|
||||
slice::from_raw_parts_mut(core::ptr::from_mut::<T>(t).cast::<u8>(), size)
|
||||
})?;
|
||||
|
||||
Ok(bytes / size)
|
||||
}
|
||||
@@ -33,7 +35,8 @@ fn dup_write<T>(fd: c_int, name: &str, t: &T) -> Result<usize> {
|
||||
|
||||
let size = mem::size_of::<T>();
|
||||
|
||||
let bytes = dup.write(unsafe { slice::from_raw_parts(t as *const T as *const u8, size) })?;
|
||||
let bytes = dup
|
||||
.write(unsafe { slice::from_raw_parts(core::ptr::from_ref::<T>(t).cast::<u8>(), size) })?;
|
||||
|
||||
Ok(bytes / size)
|
||||
}
|
||||
@@ -50,13 +53,13 @@ impl IoctlBuffer {
|
||||
unsafe fn read<T>(&self) -> Result<T> {
|
||||
let (ptr, size) = match *self {
|
||||
Self::Write(ptr, size) => (ptr, size),
|
||||
Self::ReadWrite(ptr, size) => (ptr as *const c_void, size),
|
||||
Self::ReadWrite(ptr, size) => (ptr.cast_const(), size),
|
||||
_ => {
|
||||
return Err(Errno(EINVAL));
|
||||
}
|
||||
};
|
||||
if size == mem::size_of::<T>() {
|
||||
let value = unsafe { ptr::read(ptr as *const T) };
|
||||
let value = unsafe { ptr::read(ptr.cast::<T>()) };
|
||||
Ok(value)
|
||||
} else {
|
||||
Err(Errno(EINVAL))
|
||||
@@ -64,14 +67,11 @@ impl IoctlBuffer {
|
||||
}
|
||||
|
||||
unsafe fn write<T>(&mut self, value: T) -> Result<()> {
|
||||
let (ptr, size) = match *self {
|
||||
Self::Read(ptr, size) | Self::ReadWrite(ptr, size) => (ptr, size),
|
||||
_ => {
|
||||
return Err(Errno(EINVAL));
|
||||
}
|
||||
let (Self::Read(ptr, size) | Self::ReadWrite(ptr, size)) = *self else {
|
||||
return Err(Errno(EINVAL));
|
||||
};
|
||||
if size == mem::size_of::<T>() {
|
||||
unsafe { ptr::write(ptr as *mut T, value) };
|
||||
unsafe { ptr::write(ptr.cast::<T>(), value) };
|
||||
Ok(())
|
||||
} else {
|
||||
Err(Errno(EINVAL))
|
||||
@@ -83,7 +83,7 @@ pub unsafe fn ioctl_inner(fd: c_int, request: c_ulong, out: *mut c_void) -> Resu
|
||||
match request {
|
||||
FIONBIO => {
|
||||
let mut flags = Sys::fcntl(fd, fcntl::F_GETFL, 0)?;
|
||||
flags = if unsafe { *(out as *mut c_int) } == 0 {
|
||||
flags = if unsafe { *out.cast::<c_int>() } == 0 {
|
||||
flags & !fcntl::O_NONBLOCK
|
||||
} else {
|
||||
flags | fcntl::O_NONBLOCK
|
||||
@@ -91,7 +91,7 @@ pub unsafe fn ioctl_inner(fd: c_int, request: c_ulong, out: *mut c_void) -> Resu
|
||||
Sys::fcntl(fd, fcntl::F_SETFL, flags as c_ulonglong)?;
|
||||
}
|
||||
TCGETS => {
|
||||
let termios = unsafe { &mut *(out as *mut termios::termios) };
|
||||
let termios = unsafe { &mut *out.cast::<termios::termios>() };
|
||||
dup_read(fd, "termios", termios)?;
|
||||
}
|
||||
// TODO: give these different behaviors
|
||||
@@ -119,7 +119,7 @@ pub unsafe fn ioctl_inner(fd: c_int, request: c_ulong, out: *mut c_void) -> Resu
|
||||
todo_skip!(0, "ioctl TIOCSCTTY");
|
||||
}
|
||||
TIOCGPGRP => {
|
||||
let pgrp = unsafe { &mut *(out as *mut pid_t) };
|
||||
let pgrp = unsafe { &mut *out.cast::<pid_t>() };
|
||||
dup_read(fd, "pgrp", pgrp)?;
|
||||
}
|
||||
TIOCSPGRP => {
|
||||
@@ -127,7 +127,7 @@ pub unsafe fn ioctl_inner(fd: c_int, request: c_ulong, out: *mut c_void) -> Resu
|
||||
dup_write(fd, "pgrp", pgrp)?;
|
||||
}
|
||||
TIOCGWINSZ => {
|
||||
let winsize = unsafe { &mut *(out as *mut winsize) };
|
||||
let winsize = unsafe { &mut *out.cast::<winsize>() };
|
||||
dup_read(fd, "winsize", winsize)?;
|
||||
}
|
||||
TIOCSWINSZ => {
|
||||
@@ -135,7 +135,7 @@ pub unsafe fn ioctl_inner(fd: c_int, request: c_ulong, out: *mut c_void) -> Resu
|
||||
dup_write(fd, "winsize", winsize)?;
|
||||
}
|
||||
TIOCGPTLCK => {
|
||||
let lock = unsafe { &mut *(out as *mut c_int) };
|
||||
let lock = unsafe { &mut *out.cast::<c_int>() };
|
||||
dup_read(fd, "ptlock", lock)?;
|
||||
}
|
||||
TIOCSPTLCK => {
|
||||
@@ -143,7 +143,7 @@ pub unsafe fn ioctl_inner(fd: c_int, request: c_ulong, out: *mut c_void) -> Resu
|
||||
dup_write(fd, "ptlock", lock)?;
|
||||
}
|
||||
TIOCGPTN => {
|
||||
let name = unsafe { &mut *(out as *mut c_int) };
|
||||
let name = unsafe { &mut *out.cast::<c_int>() };
|
||||
dup_read(fd, "ptsname", name)?;
|
||||
}
|
||||
SIOCATMARK => {
|
||||
|
||||
@@ -72,7 +72,7 @@ pub(crate) struct timer_internal_t {
|
||||
#[cfg(target_os = "redox")]
|
||||
impl timer_internal_t {
|
||||
pub unsafe fn from_raw(timerid: timer_t) -> &'static mut Self {
|
||||
unsafe { &mut *(timerid as *mut Self) }
|
||||
unsafe { &mut *timerid.cast::<Self>() }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
/// sysconf.h: <https://pubs.opengroup.org/onlinepubs/9799919799/functions/sysconf.html>.
|
||||
//! `sysconf.h` implementation.
|
||||
//!
|
||||
//! See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/sysconf.html>.
|
||||
|
||||
#[cfg(target_os = "redox")]
|
||||
#[path = "sysconf/redox.rs"]
|
||||
|
||||
@@ -40,7 +40,7 @@ pub(super) fn sysconf_impl(name: c_int) -> c_long {
|
||||
_SC_TIMEOUTS => 202405,
|
||||
_SC_TIMERS => 202405,
|
||||
_SC_SYMLOOP_MAX => -1,
|
||||
_SC_HOST_NAME_MAX => limits::HOST_NAME_MAX.try_into().unwrap_or(-1),
|
||||
_SC_HOST_NAME_MAX => limits::HOST_NAME_MAX,
|
||||
_SC_NPROCESSORS_CONF => get_cpu_count().unwrap_or(None).unwrap_or(1),
|
||||
_SC_NPROCESSORS_ONLN => get_cpu_count().unwrap_or(None).unwrap_or(1),
|
||||
_SC_PHYS_PAGES => get_mem_stat().map(|s| s.f_blocks as c_long).unwrap_or(-1),
|
||||
@@ -77,6 +77,6 @@ pub fn get_mem_stat() -> Result<sys_statvfs::statvfs, Errno> {
|
||||
let mut buf = sys_statvfs::statvfs::default();
|
||||
let res = Sys::fstatvfs(fd, Out::from_mut(&mut buf));
|
||||
if let Ok(()) = Sys::close(fd) {}; // TODO handle error
|
||||
let _ = res?;
|
||||
return Ok(buf);
|
||||
res?;
|
||||
Ok(buf)
|
||||
}
|
||||
|
||||
+11
-3
@@ -630,14 +630,18 @@ impl Linker {
|
||||
let new_tcb_len = new_tcb.generic.tcb_len;
|
||||
|
||||
// Unmap just the TCB page.
|
||||
Sys::munmap(new_tcb as *mut Tcb as *mut c_void, syscall::PAGE_SIZE).unwrap();
|
||||
Sys::munmap(
|
||||
core::ptr::from_mut::<Tcb>(new_tcb).cast::<c_void>(),
|
||||
syscall::PAGE_SIZE,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let new_addr = ptr::addr_of!(*new_tcb) as usize;
|
||||
|
||||
assert_eq!(
|
||||
syscall::syscall5(
|
||||
syscall::SYS_MREMAP,
|
||||
old_tcb as *mut Tcb as usize,
|
||||
core::ptr::from_mut::<Tcb>(old_tcb) as usize,
|
||||
syscall::PAGE_SIZE,
|
||||
new_addr,
|
||||
syscall::PAGE_SIZE,
|
||||
@@ -658,7 +662,11 @@ impl Linker {
|
||||
new_tcb.generic.tcb_len = new_tcb_len;
|
||||
|
||||
drop(_guard);
|
||||
(new_tcb, old_tcb as *mut Tcb as *mut c_void, thr_fd)
|
||||
(
|
||||
new_tcb,
|
||||
core::ptr::from_mut::<Tcb>(old_tcb).cast::<c_void>(),
|
||||
thr_fd,
|
||||
)
|
||||
};
|
||||
|
||||
#[cfg(not(target_os = "redox"))]
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 _,
|
||||
|
||||
@@ -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 }
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user