Skip to content
Open
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 src/backend/libc/io/errno.rs
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ impl Errno {
#[cfg(not(target_os = "l4re"))]
pub const NOTSOCK: Self = Self(c::ENOTSOCK);
/// `ENOTSUP`
#[cfg(not(any(windows, target_os = "redox")))]
#[cfg(not(any(windows, target_os = "hermit", target_os = "redox")))]
pub const NOTSUP: Self = Self(c::ENOTSUP);
/// `ENOTTY`
#[cfg(not(windows))]
Expand Down
19 changes: 13 additions & 6 deletions src/backend/libc/io/syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ pub(crate) fn write(fd: BorrowedFd<'_>, buf: &[u8]) -> io::Result<usize> {
}
}

#[cfg(not(target_os = "hermit"))]
pub(crate) unsafe fn pread(
fd: BorrowedFd<'_>,
buf: (*mut u8, usize),
Expand All @@ -59,6 +60,7 @@ pub(crate) unsafe fn pread(
ret_usize(c::pread(borrowed_fd(fd), buf.0.cast(), len, offset))
}

#[cfg(not(target_os = "hermit"))]
pub(crate) fn pwrite(fd: BorrowedFd<'_>, buf: &[u8], offset: u64) -> io::Result<usize> {
let len = min(buf.len(), READ_LIMIT);

Expand All @@ -76,8 +78,8 @@ pub(crate) fn readv(fd: BorrowedFd<'_>, bufs: &mut [IoSliceMut<'_>]) -> io::Resu
unsafe {
ret_usize(c::readv(
borrowed_fd(fd),
bufs.as_ptr().cast::<c::iovec>(),
min(bufs.len(), MAX_IOV) as c::c_int,
bufs.as_ptr().cast(),
min(bufs.len(), MAX_IOV) as _,
))
}
}
Expand All @@ -87,8 +89,8 @@ pub(crate) fn writev(fd: BorrowedFd<'_>, bufs: &[IoSlice<'_>]) -> io::Result<usi
unsafe {
ret_usize(c::writev(
borrowed_fd(fd),
bufs.as_ptr().cast::<c::iovec>(),
min(bufs.len(), MAX_IOV) as c::c_int,
bufs.as_ptr().cast(),
min(bufs.len(), MAX_IOV) as _,
))
}
}
Expand All @@ -97,6 +99,7 @@ pub(crate) fn writev(fd: BorrowedFd<'_>, bufs: &[IoSlice<'_>]) -> io::Result<usi
target_os = "cygwin",
target_os = "espidf",
target_os = "haiku",
target_os = "hermit",
target_os = "horizon",
target_os = "nto",
target_os = "redox",
Expand Down Expand Up @@ -128,6 +131,7 @@ pub(crate) fn preadv(
target_os = "cygwin",
target_os = "espidf",
target_os = "haiku",
target_os = "hermit",
target_os = "nto",
target_os = "horizon",
target_os = "redox",
Expand Down Expand Up @@ -234,16 +238,18 @@ pub(crate) unsafe fn ioctl_readonly(
ioctl(fd, request, arg)
}

#[cfg(not(target_os = "hermit"))]
pub(crate) fn fcntl_getfd(fd: BorrowedFd<'_>) -> io::Result<FdFlags> {
let flags = unsafe { ret_c_int(c::fcntl(borrowed_fd(fd), c::F_GETFD))? };
Ok(FdFlags::from_bits_retain(bitcast!(flags)))
}

#[cfg(not(target_os = "hermit"))]
pub(crate) fn fcntl_setfd(fd: BorrowedFd<'_>, flags: FdFlags) -> io::Result<()> {
unsafe { ret(c::fcntl(borrowed_fd(fd), c::F_SETFD, flags.bits())) }
}

#[cfg(not(any(target_os = "espidf", target_os = "wasi")))]
#[cfg(not(any(target_os = "espidf", target_os = "hermit", target_os = "wasi")))]
pub(crate) fn fcntl_dupfd_cloexec(fd: BorrowedFd<'_>, min: RawFd) -> io::Result<OwnedFd> {
unsafe { ret_owned_fd(c::fcntl(borrowed_fd(fd), c::F_DUPFD_CLOEXEC, min)) }
}
Expand All @@ -259,7 +265,7 @@ pub(crate) fn dup(fd: BorrowedFd<'_>) -> io::Result<OwnedFd> {
}

#[allow(clippy::needless_pass_by_ref_mut)]
#[cfg(not(target_os = "wasi"))]
#[cfg(not(any(target_os = "hermit", target_os = "wasi")))]
pub(crate) fn dup2(fd: BorrowedFd<'_>, new: &mut OwnedFd) -> io::Result<()> {
unsafe { ret_discarded_fd(c::dup2(borrowed_fd(fd), borrowed_fd(new.as_fd()))) }
}
Expand All @@ -272,6 +278,7 @@ pub(crate) fn dup2(fd: BorrowedFd<'_>, new: &mut OwnedFd) -> io::Result<()> {
target_os = "dragonfly",
target_os = "espidf",
target_os = "haiku",
target_os = "hermit",
target_os = "horizon",
target_os = "nto",
target_os = "redox",
Expand Down
1 change: 1 addition & 0 deletions src/backend/libc/io/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ bitflags! {
apple,
target_os = "aix",
target_os = "android",
target_os = "hermit",
target_os = "redox",
)))] // Android 5.0 has dup3, but libc doesn't have bindings
const CLOEXEC = bitcast!(c::O_CLOEXEC);
Expand Down
3 changes: 2 additions & 1 deletion src/io/dup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ pub fn dup<Fd: AsFd>(fd: Fd) -> io::Result<OwnedFd> {
/// [`stdio::dup2_stdin`]: crate::stdio::dup2_stdin
/// [`stdio::dup2_stdout`]: crate::stdio::dup2_stdout
/// [`stdio::dup2_stderr`]: crate::stdio::dup2_stderr
#[cfg(not(target_os = "wasi"))]
#[cfg(not(any(target_os = "hermit", target_os = "wasi")))]
#[inline]
pub fn dup2<Fd: AsFd>(fd: Fd, new: &mut OwnedFd) -> io::Result<()> {
backend::io::syscalls::dup2(fd.as_fd(), new)
Expand Down Expand Up @@ -114,6 +114,7 @@ pub fn dup2<Fd: AsFd>(fd: Fd, new: &mut OwnedFd) -> io::Result<()> {
#[cfg(not(any(
target_os = "aix",
target_os = "espidf",
target_os = "hermit",
target_os = "horizon",
target_os = "nto",
target_os = "vita",
Expand Down
4 changes: 3 additions & 1 deletion src/io/fcntl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub use backend::io::types::FdFlags;
/// [DragonFly BSD]: https://man.dragonflybsd.org/?command=fcntl&section=2
/// [illumos]: https://illumos.org/man/2/fcntl
/// [glibc]: https://sourceware.org/glibc/manual/latest/html_node/Control-Operations.html#index-fcntl-function
#[cfg(not(target_os = "hermit"))]
#[inline]
#[doc(alias = "F_GETFD")]
pub fn fcntl_getfd<Fd: AsFd>(fd: Fd) -> io::Result<FdFlags> {
Expand Down Expand Up @@ -63,6 +64,7 @@ pub fn fcntl_getfd<Fd: AsFd>(fd: Fd) -> io::Result<FdFlags> {
/// [DragonFly BSD]: https://man.dragonflybsd.org/?command=fcntl&section=2
/// [illumos]: https://illumos.org/man/2/fcntl
/// [glibc]: https://sourceware.org/glibc/manual/latest/html_node/Control-Operations.html#index-fcntl-function
#[cfg(not(target_os = "hermit"))]
#[inline]
#[doc(alias = "F_SETFD")]
pub fn fcntl_setfd<Fd: AsFd>(fd: Fd, flags: FdFlags) -> io::Result<()> {
Expand Down Expand Up @@ -99,7 +101,7 @@ pub fn fcntl_setfd<Fd: AsFd>(fd: Fd, flags: FdFlags) -> io::Result<()> {
/// [illumos]: https://illumos.org/man/2/fcntl
/// [glibc]: https://sourceware.org/glibc/manual/latest/html_node/Control-Operations.html#index-fcntl-function
/// [file description]: https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/V1_chap03.html#tag_03_258
#[cfg(not(any(target_os = "espidf", target_os = "wasi")))]
#[cfg(not(any(target_os = "espidf", target_os = "hermit", target_os = "wasi")))]
#[inline]
#[doc(alias = "F_DUPFD_CLOEXEC")]
pub fn fcntl_dupfd_cloexec<Fd: AsFd>(fd: Fd, min: RawFd) -> io::Result<OwnedFd> {
Expand Down
7 changes: 6 additions & 1 deletion src/io/ioctl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,12 @@ pub fn ioctl_fionbio<Fd: AsFd>(fd: Fd, value: bool) -> io::Result<()> {
/// [FreeBSD]: https://man.freebsd.org/cgi/man.cgi?query=ioctl&sektion=2#GENERIC%09IOCTLS
/// [NetBSD]: https://man.netbsd.org/ioctl.2#GENERIC%20IOCTLS
/// [OpenBSD]: https://man.openbsd.org/ioctl.2#GENERIC_IOCTLS
#[cfg(not(any(target_os = "espidf", target_os = "horizon", target_os = "vita")))]
#[cfg(not(any(
target_os = "espidf",
target_os = "hermit",
target_os = "horizon",
target_os = "vita"
)))]
#[inline]
#[doc(alias = "FIONREAD")]
pub fn ioctl_fionread<Fd: AsFd>(fd: Fd) -> io::Result<u64> {
Expand Down
6 changes: 4 additions & 2 deletions src/io/read_write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ pub fn write<Fd: AsFd>(fd: Fd, buf: &[u8]) -> io::Result<usize> {
/// [DragonFly BSD]: https://man.dragonflybsd.org/?command=pread&section=2
/// [illumos]: https://illumos.org/man/2/pread
/// [glibc]: https://sourceware.org/glibc/manual/latest/html_node/I_002fO-Primitives.html#index-pread64
#[cfg(not(windows))]
#[cfg(not(any(windows, target_os = "hermit")))]
#[inline]
pub fn pread<Fd: AsFd, Buf: Buffer<u8>>(
fd: Fd,
Expand Down Expand Up @@ -131,7 +131,7 @@ pub fn pread<Fd: AsFd, Buf: Buffer<u8>>(
/// [DragonFly BSD]: https://man.dragonflybsd.org/?command=pwrite&section=2
/// [illumos]: https://illumos.org/man/2/pwrite
/// [glibc]: https://sourceware.org/glibc/manual/latest/html_node/I_002fO-Primitives.html#index-pwrite64
#[cfg(not(windows))]
#[cfg(not(any(windows, target_os = "hermit")))]
#[inline]
pub fn pwrite<Fd: AsFd>(fd: Fd, buf: &[u8], offset: u64) -> io::Result<usize> {
backend::io::syscalls::pwrite(fd.as_fd(), buf, offset)
Expand Down Expand Up @@ -217,6 +217,7 @@ pub fn writev<Fd: AsFd>(fd: Fd, bufs: &[IoSlice<'_>]) -> io::Result<usize> {
target_os = "cygwin",
target_os = "espidf",
target_os = "haiku",
target_os = "hermit",
target_os = "horizon",
target_os = "nto",
target_os = "redox",
Expand Down Expand Up @@ -256,6 +257,7 @@ pub fn preadv<Fd: AsFd>(fd: Fd, bufs: &mut [IoSliceMut<'_>], offset: u64) -> io:
target_os = "cygwin",
target_os = "espidf",
target_os = "haiku",
target_os = "hermit",
target_os = "horizon",
target_os = "nto",
target_os = "redox",
Expand Down
1 change: 1 addition & 0 deletions src/ioctl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ type _Opcode = c::c_ulong;
target_os = "aix",
target_os = "cygwin",
target_os = "fuchsia",
target_os = "hermit",
target_os = "emscripten",
target_os = "nto",
target_os = "wasi",
Expand Down
10 changes: 9 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,15 @@ pub(crate) mod msan;
// versions of libc and not others.
#[cfg(any(
all(linux_raw, feature = "use-libc-auxv"),
all(libc, not(any(windows, target_os = "espidf", target_os = "wasi")))
all(
libc,
not(any(
windows,
target_os = "espidf",
target_os = "hermit",
target_os = "wasi"
))
)
))]
#[macro_use]
mod weak;
Expand Down
28 changes: 24 additions & 4 deletions src/maybe_polyfill/no_std/os/fd/owned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,12 @@ impl BorrowedFd<'_> {
impl OwnedFd {
/// Creates a new `OwnedFd` instance that shares the same underlying file handle
/// as the existing `OwnedFd` instance.
#[cfg(not(target_arch = "wasm32"))]
#[cfg(not(any(
target_os = "hermit",
target_os = "motor",
target_os = "trusty",
target_os = "wasi"
)))]
pub fn try_clone(&self) -> crate::io::Result<Self> {
// We want to atomically duplicate this file descriptor and set the
// CLOEXEC flag, and currently that's done via F_DUPFD_CLOEXEC. This
Expand All @@ -121,7 +126,12 @@ impl OwnedFd {

/// Creates a new `OwnedFd` instance that shares the same underlying file handle
/// as the existing `OwnedFd` instance.
#[cfg(target_arch = "wasm32")]
#[cfg(any(
target_os = "hermit",
target_os = "motor",
target_os = "trusty",
target_os = "wasi"
))]
pub fn try_clone(&self) -> crate::io::Result<Self> {
Err(crate::io::Errno::NOSYS)
}
Expand All @@ -130,7 +140,12 @@ impl OwnedFd {
impl BorrowedFd<'_> {
/// Creates a new `OwnedFd` instance that shares the same underlying file
/// description as the existing `BorrowedFd` instance.
#[cfg(not(any(target_arch = "wasm32", target_os = "hermit")))]
#[cfg(not(any(
target_os = "hermit",
target_os = "motor",
target_os = "trusty",
target_os = "wasi"
)))]
#[cfg_attr(staged_api, stable(feature = "io_safety", since = "1.63.0"))]
pub fn try_clone_to_owned(&self) -> crate::io::Result<OwnedFd> {
// Avoid using file descriptors below 3 as they are used for stdio
Expand All @@ -153,7 +168,12 @@ impl BorrowedFd<'_> {

/// Creates a new `OwnedFd` instance that shares the same underlying file
/// description as the existing `BorrowedFd` instance.
#[cfg(any(target_arch = "wasm32", target_os = "hermit"))]
#[cfg(any(
target_os = "hermit",
target_os = "motor",
target_os = "trusty",
target_os = "wasi"
))]
#[cfg_attr(staged_api, stable(feature = "io_safety", since = "1.63.0"))]
pub fn try_clone_to_owned(&self) -> crate::io::Result<OwnedFd> {
Err(crate::io::Errno::NOSYS)
Expand Down
2 changes: 1 addition & 1 deletion src/maybe_polyfill/no_std/os/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[cfg(any(unix, target_os = "wasi"))]
#[cfg(any(unix, target_os = "hermit", target_os = "wasi"))]
pub mod fd;
#[cfg(windows)]
pub mod windows;
7 changes: 6 additions & 1 deletion src/maybe_polyfill/std/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ pub mod os {
pub mod fd {
// Change to use `std::os::fd` when MSRV becomes Rust 1.66 or higher.

#[cfg(target_os = "wasi")]
#[cfg(any(
target_os = "hermit",
target_os = "motor",
target_os = "trusty",
target_os = "wasi"
))]
pub use std::os::fd::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, OwnedFd, RawFd};
#[cfg(unix)]
pub use std::os::unix::io::{
Expand Down
2 changes: 1 addition & 1 deletion tests/backends.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ fn test_backends() {

#[cfg(windows)]
let libc_dep = "windows-sys";
#[cfg(any(unix, target_os = "wasi"))]
#[cfg(not(windows))]
let libc_dep = "libc";

// Test the use-libc crate, which enables the "use-libc" cargo feature.
Expand Down
7 changes: 6 additions & 1 deletion tests/io/ioctl.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
// `ioctl_fionread` on Windows doesn't work on files.
#[cfg(not(any(windows, target_os = "cygwin", target_os = "haiku")))]
#[cfg(not(any(
windows,
target_os = "cygwin",
target_os = "hermit",
target_os = "haiku"
)))]
#[test]
fn test_ioctls() {
let file = std::fs::File::open("Cargo.toml").unwrap();
Expand Down
Loading