diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:20:39 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:20:39 +0000 |
commit | 1376c5a617be5c25655d0d7cb63e3beaa5a6e026 (patch) | |
tree | 3bb8d61aee02bc7a15eab3f36e3b921afc2075d0 /vendor/rustix/src/backend/libc/offset.rs | |
parent | Releasing progress-linux version 1.69.0+dfsg1-1~progress7.99u1. (diff) | |
download | rustc-1376c5a617be5c25655d0d7cb63e3beaa5a6e026.tar.xz rustc-1376c5a617be5c25655d0d7cb63e3beaa5a6e026.zip |
Merging upstream version 1.70.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/rustix/src/backend/libc/offset.rs')
-rw-r--r-- | vendor/rustix/src/backend/libc/offset.rs | 262 |
1 files changed, 134 insertions, 128 deletions
diff --git a/vendor/rustix/src/backend/libc/offset.rs b/vendor/rustix/src/backend/libc/offset.rs index 8aae9d073..9747eb954 100644 --- a/vendor/rustix/src/backend/libc/offset.rs +++ b/vendor/rustix/src/backend/libc/offset.rs @@ -3,96 +3,47 @@ #[cfg(not(windows))] use super::c; -#[cfg(not(any( - windows, - target_os = "android", - target_os = "emscripten", - target_os = "l4re", - target_os = "linux", -)))] +#[cfg(not(any(linux_like, windows)))] #[cfg(feature = "fs")] pub(super) use c::{ fstat as libc_fstat, fstatat as libc_fstatat, ftruncate as libc_ftruncate, lseek as libc_lseek, off_t as libc_off_t, }; -#[cfg(any( - target_os = "android", - target_os = "emscripten", - target_os = "l4re", - target_os = "linux", -))] +#[cfg(linux_like)] #[cfg(feature = "fs")] pub(super) use c::{ fstat64 as libc_fstat, fstatat64 as libc_fstatat, ftruncate64 as libc_ftruncate, lseek64 as libc_lseek, off64_t as libc_off_t, }; -#[cfg(any( - target_os = "android", - target_os = "emscripten", - target_os = "l4re", - target_os = "linux", -))] +#[cfg(linux_like)] pub(super) use c::rlimit64 as libc_rlimit; -#[cfg(not(any( - windows, - target_os = "android", - target_os = "emscripten", - target_os = "l4re", - target_os = "linux", - target_os = "wasi", -)))] +#[cfg(not(any(linux_like, windows, target_os = "wasi")))] #[cfg(feature = "mm")] pub(super) use c::mmap as libc_mmap; #[cfg(not(any( + linux_like, windows, - target_os = "android", - target_os = "emscripten", target_os = "fuchsia", - target_os = "l4re", - target_os = "linux", target_os = "redox", target_os = "wasi", )))] pub(super) use c::{rlimit as libc_rlimit, RLIM_INFINITY as LIBC_RLIM_INFINITY}; -#[cfg(not(any( - windows, - target_os = "android", - target_os = "fuchsia", - target_os = "emscripten", - target_os = "l4re", - target_os = "linux", - target_os = "wasi", -)))] +#[cfg(not(any(linux_like, windows, target_os = "fuchsia", target_os = "wasi")))] pub(super) use c::{getrlimit as libc_getrlimit, setrlimit as libc_setrlimit}; // TODO: Add `RLIM64_INFINITY` to upstream libc. -#[cfg(any( - target_os = "android", - target_os = "linux", - target_os = "emscripten", - target_os = "l4re", -))] +#[cfg(linux_like)] pub(super) const LIBC_RLIM_INFINITY: u64 = !0_u64; -#[cfg(any( - target_os = "android", - target_os = "linux", - target_os = "emscripten", - target_os = "l4re", -))] +#[cfg(linux_like)] pub(super) use c::{getrlimit64 as libc_getrlimit, setrlimit64 as libc_setrlimit}; -#[cfg(any( - target_os = "android", - target_os = "linux", - target_os = "emscripten", - target_os = "l4re", -))] +#[cfg(linux_like)] #[cfg(feature = "mm")] pub(super) use c::mmap64 as libc_mmap; @@ -152,22 +103,10 @@ pub(super) unsafe fn libc_prlimit( prlimit64(pid, resource, new_limit, old_limit) } -#[cfg(not(any( - windows, - target_os = "android", - target_os = "linux", - target_os = "emscripten", - target_os = "l4re", - target_os = "redox", -)))] +#[cfg(not(any(linux_like, windows, target_os = "redox")))] #[cfg(feature = "fs")] pub(super) use c::openat as libc_openat; -#[cfg(any( - target_os = "android", - target_os = "linux", - target_os = "emscripten", - target_os = "l4re", -))] +#[cfg(linux_like)] #[cfg(feature = "fs")] pub(super) use c::openat64 as libc_openat; @@ -178,29 +117,18 @@ pub(super) use c::fallocate as libc_fallocate; #[cfg(feature = "fs")] pub(super) use c::fallocate64 as libc_fallocate; #[cfg(not(any( + apple, + linux_like, + netbsdlike, + solarish, windows, - target_os = "android", target_os = "dragonfly", - target_os = "emscripten", target_os = "haiku", - target_os = "illumos", - target_os = "ios", - target_os = "linux", - target_os = "l4re", - target_os = "macos", - target_os = "netbsd", - target_os = "openbsd", target_os = "redox", - target_os = "solaris", )))] #[cfg(feature = "fs")] pub(super) use c::posix_fadvise as libc_posix_fadvise; -#[cfg(any( - target_os = "android", - target_os = "emscripten", - target_os = "linux", - target_os = "l4re", -))] +#[cfg(linux_like)] #[cfg(feature = "fs")] pub(super) use c::posix_fadvise64 as libc_posix_fadvise; @@ -213,8 +141,20 @@ pub(super) use c::posix_fadvise64 as libc_posix_fadvise; pub(super) use c::{pread as libc_pread, pwrite as libc_pwrite}; #[cfg(any(target_os = "android", target_os = "linux", target_os = "emscripten"))] pub(super) use c::{pread64 as libc_pread, pwrite64 as libc_pwrite}; +#[cfg(not(any( + apple, + windows, + target_os = "android", + target_os = "emscripten", + target_os = "haiku", + target_os = "linux", + target_os = "redox", + target_os = "solaris", +)))] +pub(super) use c::{preadv as libc_preadv, pwritev as libc_pwritev}; #[cfg(any(target_os = "linux", target_os = "emscripten"))] pub(super) use c::{preadv64 as libc_preadv, pwritev64 as libc_pwritev}; + #[cfg(target_os = "android")] mod readwrite_pv64 { use super::c; @@ -302,22 +242,11 @@ mod readwrite_pv64 { } } } -#[cfg(not(any( - windows, - target_os = "android", - target_os = "emscripten", - target_os = "haiku", - target_os = "ios", - target_os = "linux", - target_os = "macos", - target_os = "redox", - target_os = "solaris", -)))] -pub(super) use c::{preadv as libc_preadv, pwritev as libc_pwritev}; #[cfg(target_os = "android")] pub(super) use readwrite_pv64::{preadv64 as libc_preadv, pwritev64 as libc_pwritev}; + // macOS added preadv and pwritev in version 11.0 -#[cfg(any(target_os = "ios", target_os = "macos"))] +#[cfg(apple)] mod readwrite_pv { use super::c; @@ -337,26 +266,116 @@ mod readwrite_pv { ) -> c::ssize_t } } -#[cfg(all(target_os = "linux", target_env = "gnu"))] -pub(super) use c::{preadv64v2 as libc_preadv2, pwritev64v2 as libc_pwritev2}; -#[cfg(any(target_os = "ios", target_os = "macos"))] +#[cfg(apple)] pub(super) use readwrite_pv::{preadv as libc_preadv, pwritev as libc_pwritev}; +// GLIBC added `preadv64v2` and `pwritev64v2` in version 2.26. +#[cfg(all(target_os = "linux", target_env = "gnu"))] +mod readwrite_pv64v2 { + use super::c; + + // 64-bit offsets on 32-bit platforms are passed in endianness-specific + // lo/hi pairs. See src/backend/linux_raw/conv.rs for details. + #[cfg(all(target_endian = "little", target_pointer_width = "32"))] + fn lo(x: u64) -> usize { + (x >> 32) as usize + } + #[cfg(all(target_endian = "little", target_pointer_width = "32"))] + fn hi(x: u64) -> usize { + (x & 0xffff_ffff) as usize + } + #[cfg(all(target_endian = "big", target_pointer_width = "32"))] + fn lo(x: u64) -> usize { + (x & 0xffff_ffff) as usize + } + #[cfg(all(target_endian = "big", target_pointer_width = "32"))] + fn hi(x: u64) -> usize { + (x >> 32) as usize + } + + pub(in super::super) unsafe fn preadv64v2( + fd: c::c_int, + iov: *const c::iovec, + iovcnt: c::c_int, + offset: c::off64_t, + flags: c::c_int, + ) -> c::ssize_t { + // Older GLIBC lacks `preadv64v2`, so use the `weak!` mechanism to + // test for it, and call back to `c::syscall`. We don't use + // `weak_or_syscall` here because we need to pass the 64-bit offset + // specially. + weak! { + fn preadv64v2(c::c_int, *const c::iovec, c::c_int, c::off64_t, c::c_int) -> c::ssize_t + } + if let Some(fun) = preadv64v2.get() { + fun(fd, iov, iovcnt, offset, flags) + } else { + #[cfg(target_pointer_width = "32")] + { + c::syscall( + c::SYS_preadv, + fd, + iov, + iovcnt, + hi(offset as u64), + lo(offset as u64), + flags, + ) as c::ssize_t + } + #[cfg(target_pointer_width = "64")] + { + c::syscall(c::SYS_preadv2, fd, iov, iovcnt, offset, flags) as c::ssize_t + } + } + } + pub(in super::super) unsafe fn pwritev64v2( + fd: c::c_int, + iov: *const c::iovec, + iovcnt: c::c_int, + offset: c::off64_t, + flags: c::c_int, + ) -> c::ssize_t { + // See the comments in `preadv64v2`. + weak! { + fn pwritev64v2(c::c_int, *const c::iovec, c::c_int, c::off64_t, c::c_int) -> c::ssize_t + } + if let Some(fun) = pwritev64v2.get() { + fun(fd, iov, iovcnt, offset, flags) + } else { + #[cfg(target_pointer_width = "32")] + { + c::syscall( + c::SYS_pwritev, + fd, + iov, + iovcnt, + hi(offset as u64), + lo(offset as u64), + flags, + ) as c::ssize_t + } + #[cfg(target_pointer_width = "64")] + { + c::syscall(c::SYS_pwritev2, fd, iov, iovcnt, offset, flags) as c::ssize_t + } + } + } +} +#[cfg(all(target_os = "linux", target_env = "gnu"))] +pub(super) use readwrite_pv64v2::{preadv64v2 as libc_preadv2, pwritev64v2 as libc_pwritev2}; + #[cfg(not(any( + apple, + netbsdlike, + solarish, windows, target_os = "aix", target_os = "android", target_os = "dragonfly", target_os = "fuchsia", - target_os = "illumos", - target_os = "ios", target_os = "linux", target_os = "l4re", - target_os = "macos", - target_os = "netbsd", - target_os = "openbsd", target_os = "redox", - target_os = "solaris", )))] #[cfg(feature = "fs")] pub(super) use c::posix_fallocate as libc_posix_fallocate; @@ -364,41 +383,28 @@ pub(super) use c::posix_fallocate as libc_posix_fallocate; #[cfg(feature = "fs")] pub(super) use c::posix_fallocate64 as libc_posix_fallocate; #[cfg(not(any( + linux_like, + solarish, windows, - target_os = "android", - target_os = "emscripten", target_os = "haiku", - target_os = "illumos", - target_os = "linux", - target_os = "l4re", target_os = "netbsd", target_os = "redox", - target_os = "solaris", target_os = "wasi", )))] #[cfg(feature = "fs")] pub(super) use {c::fstatfs as libc_fstatfs, c::statfs as libc_statfs}; #[cfg(not(any( + linux_like, + solarish, windows, - target_os = "android", - target_os = "emscripten", target_os = "haiku", - target_os = "illumos", - target_os = "linux", - target_os = "l4re", target_os = "redox", - target_os = "solaris", target_os = "wasi", )))] #[cfg(feature = "fs")] pub(super) use {c::fstatvfs as libc_fstatvfs, c::statvfs as libc_statvfs}; -#[cfg(any( - target_os = "android", - target_os = "linux", - target_os = "emscripten", - target_os = "l4re", -))] +#[cfg(linux_like)] #[cfg(feature = "fs")] pub(super) use { c::fstatfs64 as libc_fstatfs, c::fstatvfs64 as libc_fstatvfs, c::statfs64 as libc_statfs, |