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: 2 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ jobs:
cargo update --package=half --precise=2.2.1
cargo update --package=flate2 --precise=1.0.35
cargo update --package=serde --precise=1.0.228
cargo update --package=web-sys --precise=0.3.104
cargo update --package=syn --precise=2.0.106
cargo update --package=textwrap --precise=0.16.1
cargo update --package=parking_lot --precise=0.12.4
Expand Down Expand Up @@ -596,6 +597,7 @@ jobs:
cargo update --package=half --precise=2.2.1
cargo update --package=flate2 --precise=1.0.35
cargo update --package=serde --precise=1.0.228
cargo update --package=web-sys --precise=0.3.104
cargo update --package=syn --precise=2.0.106
cargo update --package=textwrap --precise=0.16.1
cargo update --package=parking_lot --precise=0.12.4
Expand Down
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -274,3 +274,6 @@ check-cfg = [
'cfg(target_arch, values("xtensa"))',
'cfg(target_os, values("cygwin"))',
]

[patch.crates-io]
libc = { git = "https://github.com/rust-lang/libc", branch = "libc-0.2" }
31 changes: 16 additions & 15 deletions src/backend/libc/c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,30 +474,27 @@ mod readwrite_pv64v2 {
))]
pub(super) use readwrite_pv64v2::{preadv64v2 as preadv2, pwritev64v2 as pwritev2};

// Rust's libc crate lacks statx for Non-glibc targets.
// Rust's libc crate > v0.2.189 may also define these constants,
// so we use an explicit import.
#[cfg(feature = "fs")]
#[cfg(all(
linux_like,
linux_raw_dep,
not(any(
target_os = "android",
target_os = "emscripten",
target_env = "gnu",
all(target_arch = "loongarch64", target_env = "musl")
))
))]
mod statx_flags {
pub(crate) use linux_raw_sys::general::{
STATX_ALL, STATX_ATIME, STATX_BASIC_STATS, STATX_BLOCKS, STATX_BTIME, STATX_CTIME,
STATX_DIOALIGN, STATX_GID, STATX_INO, STATX_MNT_ID, STATX_MODE, STATX_MTIME, STATX_NLINK,
STATX_SIZE, STATX_TYPE, STATX_UID,
};

pub(crate) use linux_raw_sys::general::{
STATX_ATTR_APPEND, STATX_ATTR_AUTOMOUNT, STATX_ATTR_COMPRESSED, STATX_ATTR_DAX,
STATX_ATTR_ENCRYPTED, STATX_ATTR_IMMUTABLE, STATX_ATTR_MOUNT_ROOT, STATX_ATTR_NODUMP,
STATX_ATTR_VERITY,
};
}
pub(crate) use linux_raw_sys::general::{
STATX_ALL, STATX_ATIME, STATX_BASIC_STATS, STATX_BLOCKS, STATX_BTIME, STATX_CTIME,
STATX_DIOALIGN, STATX_GID, STATX_INO, STATX_MNT_ID, STATX_MODE, STATX_MTIME, STATX_NLINK,
STATX_SIZE, STATX_TYPE, STATX_UID,
};

// Rust's libc crate > v0.2.189 may also define these constants,
// so we use an explicit import.
#[cfg(feature = "fs")]
#[cfg(all(
linux_like,
Expand All @@ -509,7 +506,11 @@ mod statx_flags {
all(target_arch = "loongarch64", target_env = "musl")
))
))]
pub(crate) use statx_flags::*;
pub(crate) use linux_raw_sys::general::{
STATX_ATTR_APPEND, STATX_ATTR_AUTOMOUNT, STATX_ATTR_COMPRESSED, STATX_ATTR_DAX,
STATX_ATTR_ENCRYPTED, STATX_ATTR_IMMUTABLE, STATX_ATTR_MOUNT_ROOT, STATX_ATTR_NODUMP,
STATX_ATTR_VERITY,
};

#[cfg(feature = "fs")]
#[cfg(target_os = "android")]
Expand Down
6 changes: 3 additions & 3 deletions src/backend/libc/event/syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ pub(crate) unsafe fn epoll_wait(
if let Some(epoll_pwait2_func) = epoll_pwait2.get() {
return ret_u32(epoll_pwait2_func(
borrowed_fd(epoll),
events.0.cast::<c::epoll_event>(),
events.0.cast(),
events.1.try_into().unwrap_or(i32::MAX),
crate::utils::option_as_ptr(timeout).cast(),
null(),
Expand All @@ -604,7 +604,7 @@ pub(crate) unsafe fn epoll_wait(

ret_u32(epoll_pwait2(
borrowed_fd(epoll),
events.0.cast::<c::epoll_event>(),
events.0.cast(),
events.1.try_into().unwrap_or(i32::MAX),
crate::utils::option_as_ptr(timeout).cast(),
null(),
Expand All @@ -622,7 +622,7 @@ pub(crate) unsafe fn epoll_wait(

ret_u32(c::epoll_wait(
borrowed_fd(epoll),
events.0.cast::<c::epoll_event>(),
events.0.cast(),
events.1.try_into().unwrap_or(i32::MAX),
timeout,
))
Expand Down
60 changes: 28 additions & 32 deletions src/backend/libc/fs/syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ pub(crate) fn getdents_uninit(
unsafe {
ret_usize(getdents64(
borrowed_fd(fd),
buf.as_mut_ptr().cast::<c::c_void>(),
buf.as_mut_ptr().cast(),
buf.len(),
))
}
Expand Down Expand Up @@ -941,6 +941,7 @@ pub(crate) fn utimensat(
c::c_int
) -> c::c_int
}
#[cfg(not(any(target_os = "tvos", target_os = "watchos")))]
extern "C" {
fn setattrlist(
path: *const ffi::c_char,
Expand All @@ -950,6 +951,7 @@ pub(crate) fn utimensat(
options: c::c_ulong,
) -> c::c_int;
}
#[cfg(not(any(target_os = "tvos", target_os = "watchos")))]
const FSOPT_NOFOLLOW: c::c_ulong = 0x0000_0001;

// If we have `utimensat`, use it.
Expand All @@ -962,15 +964,22 @@ pub(crate) fn utimensat(
));
}

// Return `NOSYS` on platforms where `utimensat` cannot be emulated
// because `fork` is unavailable.
#[cfg(any(target_os = "tvos", target_os = "watchos"))]
return Err(io::Errno::NOSYS);

// Convert `times`. We only need this in the child, but do it before
// calling `fork` because it might fail.
#[cfg(not(any(target_os = "tvos", target_os = "watchos")))]
let (attrbuf_size, times, attrs) = times_to_attrlist(times)?;

// `setattrlistat` was introduced in 10.13 along with `utimensat`, so
// if we don't have `utimensat`, we don't have `setattrlistat` either.
// Emulate it using `fork`, and `fchdir` and [`setattrlist`].
//
// [`setattrlist`]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/setattrlist.2.html
#[cfg(not(any(target_os = "tvos", target_os = "watchos")))]
match c::fork() {
-1 => Err(io::Errno::IO),
0 => {
Expand Down Expand Up @@ -2377,7 +2386,7 @@ pub(crate) unsafe fn getxattr(
ret_usize(c::getxattr(
path.as_ptr(),
name.as_ptr(),
value.0.cast::<c::c_void>(),
value.0.cast(),
value.1,
))
}
Expand All @@ -2389,7 +2398,7 @@ pub(crate) unsafe fn getxattr(
let ptr = if value.1 == 0 {
core::ptr::null_mut()
} else {
value.0.cast::<c::c_void>()
value.0.cast()
};
ret_usize(c::getxattr(
path.as_ptr(),
Expand All @@ -2413,7 +2422,7 @@ pub(crate) unsafe fn lgetxattr(
ret_usize(c::lgetxattr(
path.as_ptr(),
name.as_ptr(),
value.0.cast::<c::c_void>(),
value.0.cast(),
value.1,
))
}
Expand All @@ -2425,7 +2434,7 @@ pub(crate) unsafe fn lgetxattr(
let ptr = if value.1 == 0 {
core::ptr::null_mut()
} else {
value.0.cast::<c::c_void>()
value.0.cast()
};

ret_usize(c::getxattr(
Expand All @@ -2450,7 +2459,7 @@ pub(crate) unsafe fn fgetxattr(
ret_usize(c::fgetxattr(
borrowed_fd(fd),
name.as_ptr(),
value.0.cast::<c::c_void>(),
value.0.cast(),
value.1,
))
}
Expand All @@ -2462,7 +2471,7 @@ pub(crate) unsafe fn fgetxattr(
let ptr = if value.1 == 0 {
core::ptr::null_mut()
} else {
value.0.cast::<c::c_void>()
value.0.cast()
};
ret_usize(c::fgetxattr(
borrowed_fd(fd),
Expand All @@ -2487,7 +2496,7 @@ pub(crate) fn setxattr(
ret(c::setxattr(
path.as_ptr(),
name.as_ptr(),
value.as_ptr().cast::<c::c_void>(),
value.as_ptr().cast(),
value.len(),
flags.bits() as i32,
))
Expand All @@ -2498,7 +2507,7 @@ pub(crate) fn setxattr(
ret(c::setxattr(
path.as_ptr(),
name.as_ptr(),
value.as_ptr().cast::<c::c_void>(),
value.as_ptr().cast(),
value.len(),
0,
flags.bits() as i32,
Expand All @@ -2518,7 +2527,7 @@ pub(crate) fn lsetxattr(
ret(c::lsetxattr(
path.as_ptr(),
name.as_ptr(),
value.as_ptr().cast::<c::c_void>(),
value.as_ptr().cast(),
value.len(),
flags.bits() as i32,
))
Expand All @@ -2529,7 +2538,7 @@ pub(crate) fn lsetxattr(
ret(c::setxattr(
path.as_ptr(),
name.as_ptr(),
value.as_ptr().cast::<c::c_void>(),
value.as_ptr().cast(),
value.len(),
0,
flags.bits() as i32 | c::XATTR_NOFOLLOW,
Expand All @@ -2549,7 +2558,7 @@ pub(crate) fn fsetxattr(
ret(c::fsetxattr(
borrowed_fd(fd),
name.as_ptr(),
value.as_ptr().cast::<c::c_void>(),
value.as_ptr().cast(),
value.len(),
flags.bits() as i32,
))
Expand All @@ -2560,7 +2569,7 @@ pub(crate) fn fsetxattr(
ret(c::fsetxattr(
borrowed_fd(fd),
name.as_ptr(),
value.as_ptr().cast::<c::c_void>(),
value.as_ptr().cast(),
value.len(),
0,
flags.bits() as i32,
Expand All @@ -2572,40 +2581,27 @@ pub(crate) fn fsetxattr(
pub(crate) unsafe fn listxattr(path: &CStr, list: (*mut u8, usize)) -> io::Result<usize> {
#[cfg(not(apple))]
{
ret_usize(c::listxattr(
path.as_ptr(),
list.0.cast::<ffi::c_char>(),
list.1,
))
ret_usize(c::listxattr(path.as_ptr(), list.0.cast(), list.1))
}

#[cfg(apple)]
{
ret_usize(c::listxattr(
path.as_ptr(),
list.0.cast::<ffi::c_char>(),
list.1,
0,
))
ret_usize(c::listxattr(path.as_ptr(), list.0.cast(), list.1, 0))
}
}

#[cfg(any(apple, linux_kernel, target_os = "hurd"))]
pub(crate) unsafe fn llistxattr(path: &CStr, list: (*mut u8, usize)) -> io::Result<usize> {
#[cfg(not(apple))]
{
ret_usize(c::llistxattr(
path.as_ptr(),
list.0.cast::<ffi::c_char>(),
list.1,
))
ret_usize(c::llistxattr(path.as_ptr(), list.0.cast(), list.1))
}

#[cfg(apple)]
{
ret_usize(c::listxattr(
path.as_ptr(),
list.0.cast::<ffi::c_char>(),
list.0.cast(),
list.1,
c::XATTR_NOFOLLOW,
))
Expand All @@ -2618,12 +2614,12 @@ pub(crate) unsafe fn flistxattr(fd: BorrowedFd<'_>, list: (*mut u8, usize)) -> i

#[cfg(not(apple))]
{
ret_usize(c::flistxattr(fd, list.0.cast::<ffi::c_char>(), list.1))
ret_usize(c::flistxattr(fd, list.0.cast(), list.1))
}

#[cfg(apple)]
{
ret_usize(c::flistxattr(fd, list.0.cast::<ffi::c_char>(), list.1, 0))
ret_usize(c::flistxattr(fd, list.0.cast(), list.1, 0))
}
}

Expand Down
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
Loading
Loading