Skip to content
Draft
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ rustc-std-workspace-alloc = { version = "1.0.0", optional = true } # not aliased
[target.'cfg(all(not(rustix_use_libc), not(miri), target_os = "linux", any(target_endian = "little", any(target_arch = "s390x", target_arch = "powerpc")), any(target_arch = "arm", all(target_arch = "aarch64", target_pointer_width = "64"), target_arch = "riscv64", all(rustix_use_experimental_asm, target_arch = "powerpc"), all(rustix_use_experimental_asm, target_arch = "powerpc64"), all(rustix_use_experimental_asm, target_arch = "s390x"), all(rustix_use_experimental_asm, target_arch = "mips"), all(rustix_use_experimental_asm, target_arch = "mips32r6"), all(rustix_use_experimental_asm, target_arch = "mips64"), all(rustix_use_experimental_asm, target_arch = "mips64r6"), target_arch = "x86", all(target_arch = "x86_64", target_pointer_width = "64"))))'.dependencies]
linux-raw-sys = { version = "0.12", default-features = false, features = ["auxvec", "general", "errno", "ioctl", "no_std", "elf"] }
libc_errno = { package = "errno", version = "0.3.10", default-features = false, optional = true }
libc = { version = "0.2.182", default-features = false, optional = true }
libc = { version = "0.2.186", default-features = false, optional = true }

# Dependencies for platforms where only libc is supported:
#
Expand Down
5 changes: 1 addition & 4 deletions src/backend/libc/conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@ pub(super) fn borrowed_fd(fd: BorrowedFd<'_>) -> LibcFd {
fd.as_raw_fd() as LibcFd
}

#[cfg(all(
feature = "alloc",
not(any(windows, target_os = "espidf", target_os = "redox"))
))]
#[cfg(all(feature = "alloc", not(any(windows, target_os = "espidf"))))]
#[inline]
pub(super) fn owned_fd(fd: OwnedFd) -> LibcFd {
fd.into_raw_fd() as LibcFd
Expand Down
2 changes: 1 addition & 1 deletion src/backend/libc/event/syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ pub(crate) fn port_send(
unsafe { ret(c::port_send(borrowed_fd(port), events, userdata)) }
}

#[cfg(not(any(target_os = "redox", target_os = "wasi")))]
#[cfg(not(target_os = "wasi"))]
pub(crate) fn pause() {
let r = unsafe { c::pause() };
let errno = libc_errno::errno().0;
Expand Down
13 changes: 10 additions & 3 deletions src/backend/libc/event/types.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
#[cfg(any(linux_kernel, target_os = "freebsd", target_os = "illumos"))]
#[cfg(any(
linux_kernel,
target_os = "freebsd",
target_os = "illumos",
target_os = "redox"
))]
use crate::backend::c;
#[cfg(any(
linux_kernel,
target_os = "freebsd",
target_os = "illumos",
target_os = "espidf"
target_os = "espidf",
target_os = "redox"
))]
use bitflags::bitflags;

#[cfg(any(
linux_kernel,
target_os = "freebsd",
target_os = "illumos",
target_os = "espidf"
target_os = "espidf",
target_os = "redox"
))]
bitflags! {
/// `EFD_*` flags for use with [`eventfd`].
Expand Down
2 changes: 1 addition & 1 deletion src/backend/libc/fs/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[cfg(all(feature = "alloc", not(any(target_os = "espidf", target_os = "redox"))))]
#[cfg(all(feature = "alloc", not(target_os = "espidf")))]
pub(crate) mod dir;
#[cfg(linux_kernel)]
pub mod inotify;
Expand Down
44 changes: 11 additions & 33 deletions src/backend/libc/fs/syscalls.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//! libc syscalls supporting `rustix::fs`.

use crate::backend::c;
#[cfg(any(not(target_os = "redox"), feature = "alloc"))]
use crate::backend::conv::ret_usize;
use crate::backend::conv::{borrowed_fd, c_str, ret, ret_c_int, ret_off_t, ret_owned_fd};
use crate::backend::conv::{
borrowed_fd, c_str, ret, ret_c_int, ret_off_t, ret_owned_fd, ret_usize,
};
use crate::fd::{BorrowedFd, OwnedFd};
#[allow(unused_imports)]
use crate::ffi;
Expand All @@ -12,7 +12,7 @@ use crate::ffi::CStr;
use crate::ffi::CString;
#[cfg(not(any(target_os = "espidf", target_os = "horizon", target_os = "vita")))]
use crate::fs::Access;
#[cfg(not(any(target_os = "espidf", target_os = "redox")))]
#[cfg(not(target_os = "espidf"))]
use crate::fs::AtFlags;
#[cfg(not(any(
netbsdlike,
Expand Down Expand Up @@ -51,13 +51,7 @@ use crate::fs::SealFlags;
use crate::fs::StatFs;
#[cfg(not(any(target_os = "espidf", target_os = "vita")))]
use crate::fs::Timestamps;
#[cfg(not(any(
apple,
target_os = "espidf",
target_os = "redox",
target_os = "vita",
target_os = "wasi"
)))]
#[cfg(not(any(apple, target_os = "espidf", target_os = "vita", target_os = "wasi")))]
use crate::fs::{Dev, FileType};
use crate::fs::{Mode, OFlags, SeekFrom, Stat};
#[cfg(not(target_os = "wasi"))]
Expand Down Expand Up @@ -205,7 +199,6 @@ fn openat_via_syscall(
}
}

#[cfg(not(target_os = "redox"))]
pub(crate) fn openat(
dirfd: BorrowedFd<'_>,
path: &CStr,
Expand Down Expand Up @@ -287,7 +280,6 @@ pub(crate) fn readlink(path: &CStr, buf: &mut [u8]) -> io::Result<usize> {
unsafe { ret_usize(c::readlink(c_str(path), buf.as_mut_ptr().cast(), buf.len()) as isize) }
}

#[cfg(not(target_os = "redox"))]
#[inline]
pub(crate) unsafe fn readlinkat(
dirfd: BorrowedFd<'_>,
Expand All @@ -301,7 +293,6 @@ pub(crate) fn mkdir(path: &CStr, mode: Mode) -> io::Result<()> {
unsafe { ret(c::mkdir(c_str(path), mode.bits() as c::mode_t)) }
}

#[cfg(not(target_os = "redox"))]
pub(crate) fn mkdirat(dirfd: BorrowedFd<'_>, path: &CStr, mode: Mode) -> io::Result<()> {
unsafe {
ret(c::mkdirat(
Expand Down Expand Up @@ -337,7 +328,7 @@ pub(crate) fn link(old_path: &CStr, new_path: &CStr) -> io::Result<()> {
unsafe { ret(c::link(c_str(old_path), c_str(new_path))) }
}

#[cfg(not(any(target_os = "espidf", target_os = "redox")))]
#[cfg(not(target_os = "espidf"))]
pub(crate) fn linkat(
old_dirfd: BorrowedFd<'_>,
old_path: &CStr,
Expand Down Expand Up @@ -400,7 +391,7 @@ pub(crate) fn unlink(path: &CStr) -> io::Result<()> {
unsafe { ret(c::unlink(c_str(path))) }
}

#[cfg(not(any(target_os = "espidf", target_os = "redox")))]
#[cfg(not(target_os = "espidf"))]
pub(crate) fn unlinkat(dirfd: BorrowedFd<'_>, path: &CStr, flags: AtFlags) -> io::Result<()> {
// macOS ≤ 10.9 lacks `unlinkat`.
#[cfg(target_os = "macos")]
Expand Down Expand Up @@ -627,7 +618,6 @@ pub(crate) fn symlink(old_path: &CStr, new_path: &CStr) -> io::Result<()> {
unsafe { ret(c::symlink(c_str(old_path), c_str(new_path))) }
}

#[cfg(not(target_os = "redox"))]
pub(crate) fn symlinkat(
old_path: &CStr,
new_dirfd: BorrowedFd<'_>,
Expand Down Expand Up @@ -729,7 +719,7 @@ pub(crate) fn lstat(path: &CStr) -> io::Result<Stat> {
}
}

#[cfg(not(any(target_os = "espidf", target_os = "redox")))]
#[cfg(not(target_os = "espidf"))]
pub(crate) fn statat(dirfd: BorrowedFd<'_>, path: &CStr, flags: AtFlags) -> io::Result<Stat> {
// See the comments in `fstat` about using `crate::fs::statx` here.
#[cfg(all(
Expand Down Expand Up @@ -811,7 +801,6 @@ pub(crate) fn access(path: &CStr, access: Access) -> io::Result<()> {
target_os = "emscripten",
target_os = "espidf",
target_os = "horizon",
target_os = "redox",
target_os = "vita"
)))]
pub(crate) fn accessat(
Expand Down Expand Up @@ -879,12 +868,7 @@ pub(crate) fn accessat(
Ok(())
}

#[cfg(not(any(
target_os = "espidf",
target_os = "horizon",
target_os = "redox",
target_os = "vita"
)))]
#[cfg(not(any(target_os = "espidf", target_os = "horizon", target_os = "vita")))]
pub(crate) fn utimensat(
dirfd: BorrowedFd<'_>,
path: &CStr,
Expand Down Expand Up @@ -1092,12 +1076,7 @@ pub(crate) fn chmod(path: &CStr, mode: Mode) -> io::Result<()> {
unsafe { ret(c::chmod(c_str(path), mode.bits() as c::mode_t)) }
}

#[cfg(not(any(
linux_kernel,
target_os = "espidf",
target_os = "redox",
target_os = "wasi"
)))]
#[cfg(not(any(linux_kernel, target_os = "espidf", target_os = "wasi")))]
pub(crate) fn chmodat(
dirfd: BorrowedFd<'_>,
path: &CStr,
Expand Down Expand Up @@ -1175,7 +1154,7 @@ pub(crate) fn fclonefileat(
}
}

#[cfg(not(any(target_os = "espidf", target_os = "redox", target_os = "wasi")))]
#[cfg(not(any(target_os = "espidf", target_os = "wasi")))]
pub(crate) fn chownat(
dirfd: BorrowedFd<'_>,
path: &CStr,
Expand All @@ -1199,7 +1178,6 @@ pub(crate) fn chownat(
apple,
target_os = "espidf",
target_os = "horizon",
target_os = "redox",
target_os = "vita",
target_os = "wasi"
)))]
Expand Down
1 change: 0 additions & 1 deletion src/backend/libc/fs/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,6 @@ impl FileType {
target_os = "espidf",
target_os = "haiku",
target_os = "nto",
target_os = "redox",
target_os = "vita"
)))]
#[inline]
Expand Down
2 changes: 0 additions & 2 deletions src/backend/libc/io/syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ pub(crate) fn writev(fd: BorrowedFd<'_>, bufs: &[IoSlice<'_>]) -> io::Result<usi
target_os = "haiku",
target_os = "horizon",
target_os = "nto",
target_os = "redox",
target_os = "solaris",
target_os = "vita",
)))]
Expand Down Expand Up @@ -129,7 +128,6 @@ pub(crate) fn preadv(
target_os = "haiku",
target_os = "nto",
target_os = "horizon",
target_os = "redox",
target_os = "solaris",
target_os = "vita",
)))]
Expand Down
3 changes: 0 additions & 3 deletions src/backend/libc/thread/syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,12 @@ use crate::pid::Pid;
target_os = "espidf",
target_os = "haiku",
target_os = "openbsd",
target_os = "redox",
target_os = "vita",
target_os = "wasi",
)))]
use crate::thread::ClockId;
#[cfg(linux_kernel)]
use crate::thread::{Cpuid, MembarrierCommand, MembarrierQuery};
#[cfg(not(target_os = "redox"))]
use crate::thread::{NanosleepRelativeResult, Timespec};
#[cfg(all(target_env = "gnu", fix_y2038))]
use crate::timespec::LibcTimespec;
Expand Down Expand Up @@ -54,7 +52,6 @@ weak!(fn __nanosleep64(*const LibcTimespec, *mut LibcTimespec) -> c::c_int);
target_os = "haiku",
target_os = "horizon",
target_os = "openbsd",
target_os = "redox",
target_os = "vita",
target_os = "wasi",
)))]
Expand Down
41 changes: 18 additions & 23 deletions src/backend/libc/time/syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ use crate::backend::conv::ret;
target_os = "freebsd",
target_os = "fuchsia",
target_os = "illumos",
target_os = "netbsd"
target_os = "netbsd",
target_os = "redox"
))]
#[cfg(any(all(target_env = "gnu", fix_y2038), not(fix_y2038)))]
use crate::backend::time::types::LibcItimerspec;
Expand All @@ -17,11 +18,7 @@ use crate::io;
#[cfg(not(fix_y2038))]
use crate::timespec::as_libc_timespec_mut_ptr;
#[cfg(not(fix_y2038))]
#[cfg(not(any(
target_os = "redox",
target_os = "wasi",
all(apple, not(target_os = "macos"))
)))]
#[cfg(not(any(target_os = "wasi", all(apple, not(target_os = "macos")))))]
use crate::timespec::as_libc_timespec_ptr;
#[cfg(all(target_env = "gnu", fix_y2038))]
use crate::timespec::LibcTimespec;
Expand All @@ -32,7 +29,8 @@ use core::mem::MaybeUninit;
target_os = "freebsd",
target_os = "fuchsia",
target_os = "illumos",
target_os = "netbsd"
target_os = "netbsd",
target_os = "redox"
))]
use {
crate::backend::conv::{borrowed_fd, ret_owned_fd},
Expand All @@ -53,7 +51,7 @@ weak!(fn __timerfd_gettime64(c::c_int, *mut LibcItimerspec) -> c::c_int);
#[cfg(all(target_env = "gnu", fix_y2038))]
weak!(fn __timerfd_settime64(c::c_int, c::c_int, *const LibcItimerspec, *mut LibcItimerspec) -> c::c_int);

#[cfg(not(any(target_os = "redox", target_os = "wasi")))]
#[cfg(not(target_os = "wasi"))]
#[inline]
#[must_use]
pub(crate) fn clock_getres(id: ClockId) -> Timespec {
Expand Down Expand Up @@ -258,11 +256,7 @@ fn clock_gettime_dynamic_old(id: c::clockid_t) -> io::Result<Timespec> {
})
}

#[cfg(not(any(
target_os = "redox",
target_os = "wasi",
all(apple, not(target_os = "macos"))
)))]
#[cfg(not(any(target_os = "wasi", all(apple, not(target_os = "macos")))))]
#[inline]
pub(crate) fn clock_settime(id: ClockId, timespec: Timespec) -> io::Result<()> {
// Old 32-bit version: libc has `clock_gettime` but it is not y2038 safe by
Expand Down Expand Up @@ -292,11 +286,7 @@ pub(crate) fn clock_settime(id: ClockId, timespec: Timespec) -> io::Result<()> {
}
}

#[cfg(not(any(
target_os = "redox",
target_os = "wasi",
all(apple, not(target_os = "macos"))
)))]
#[cfg(not(any(target_os = "wasi", all(apple, not(target_os = "macos")))))]
#[cfg(fix_y2038)]
fn clock_settime_old(id: ClockId, timespec: Timespec) -> io::Result<()> {
let old_timespec = c::timespec {
Expand All @@ -315,7 +305,8 @@ fn clock_settime_old(id: ClockId, timespec: Timespec) -> io::Result<()> {
target_os = "freebsd",
target_os = "fuchsia",
target_os = "illumos",
target_os = "netbsd"
target_os = "netbsd",
target_os = "redox"
))]
pub(crate) fn timerfd_create(id: TimerfdClockId, flags: TimerfdFlags) -> io::Result<OwnedFd> {
unsafe { ret_owned_fd(c::timerfd_create(id as c::clockid_t, bitflags_bits!(flags))) }
Expand All @@ -326,7 +317,8 @@ pub(crate) fn timerfd_create(id: TimerfdClockId, flags: TimerfdFlags) -> io::Res
target_os = "freebsd",
target_os = "fuchsia",
target_os = "illumos",
target_os = "netbsd"
target_os = "netbsd",
target_os = "redox"
))]
pub(crate) fn timerfd_settime(
fd: BorrowedFd<'_>,
Expand Down Expand Up @@ -374,7 +366,8 @@ pub(crate) fn timerfd_settime(
target_os = "freebsd",
target_os = "fuchsia",
target_os = "illumos",
target_os = "netbsd"
target_os = "netbsd",
target_os = "redox"
))]
#[cfg(fix_y2038)]
fn timerfd_settime_old(
Expand Down Expand Up @@ -447,7 +440,8 @@ fn timerfd_settime_old(
target_os = "freebsd",
target_os = "fuchsia",
target_os = "illumos",
target_os = "netbsd"
target_os = "netbsd",
target_os = "redox"
))]
pub(crate) fn timerfd_gettime(fd: BorrowedFd<'_>) -> io::Result<Itimerspec> {
// Old 32-bit version: libc has `timerfd_gettime` but it is not y2038 safe
Expand Down Expand Up @@ -484,7 +478,8 @@ pub(crate) fn timerfd_gettime(fd: BorrowedFd<'_>) -> io::Result<Itimerspec> {
target_os = "freebsd",
target_os = "fuchsia",
target_os = "illumos",
target_os = "netbsd"
target_os = "netbsd",
target_os = "redox"
))]
#[cfg(fix_y2038)]
fn timerfd_gettime_old(fd: BorrowedFd<'_>) -> io::Result<Itimerspec> {
Expand Down
Loading
Loading