subprojects: update to rustix 1.1.4 + downstream patches
Some checks are pending
macOS-CI / macOS-CI (dri) (push) Waiting to run
macOS-CI / macOS-CI (xlib) (push) Waiting to run

This contains downstream patches for Rustix, from:

 https://github.com/bytecodealliance/rustix/pull/1577

I think the people are cool with the changes generally,
but we're essentially running into https://xkcd.com/2347/
right now and the maintainer doesn't have time to even
look at it.

To ease in the development of mesa3d_util, it's better
to keep 3 downstream patches here, than potentially
diverging mesa3d_util for actual consumers.

Reviewed-by: LingMan
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/41321>
This commit is contained in:
Gurchetan Singh 2026-05-01 15:34:54 -07:00 committed by Marge Bot
parent e5ebc027ca
commit 653ef90403
6 changed files with 404 additions and 795 deletions

View file

@ -1,790 +0,0 @@
From bd19d4b3d439cfdf4f3882e1fe72691c0005fb9d Mon Sep 17 00:00:00 2001
From: gurchetansingh <gurchetansingh@chromium.org>
Date: Mon, 14 Jul 2025 08:08:17 -0700
Subject: [PATCH] BACKPORT: rustix: on Linux, support a build without
linux-raw-sys (#1478)
* rustix: on Android, support a build without linux-raw-sys
Rustix support was added to Mesa3D recently, but it only works
with the linux-raw-sys backend. On Linux, even the libc
backend, there is a dependency on linux-raw-sys for certain ABI
definitions.
When updating rustix in Android to support this, I realized only
the libc backend is supported in Android. This is because
Android as a platform wants to discourage raw syscalls, and to
be able to globally update libc.
Features like fdtrack would not work with the linux-raw-sys backend:
https://android.googlesource.com/platform/bionic/+/HEAD/docs/fdtrack.md
Given Android wants to incentize use of libc only, this MR introduces
the concept of "linux-raw-dep". This means that linux-raw-sys is
present as a dependency for the user. This will be on by default
even for the libc backend, but will be turned off for Android (this
is reflected in the build.rs script).
This will also help others who don't need all the features rustix
offers on Linux, so they have one less dependency to maintain. They
may append "--cfg=rustix_no_linux_raw" to Rust flags skip building
the linux raw backend. Mesa3D will use this.
Tested via:
cargo build --target arm-linux-androideabi --features=use-libc,net,std,alloc,event,fs,mm,param,pipe,use-libc-auxv,libc_errno
and on Linux with the proper RUSTFLAGS set. The Github workflows have
been modified to only use the current subset of features using in AOSP:
https://android.googlesource.com/platform/external/rust/android-crates-io/+/refs/heads/main/crates/rustix/Android.bp
That is the source of truth for an Android integration and the CI only
needs to test that. Additional features may be added as needed in the
future.
* rustix: fixes for Android musl build
Android doesn't only have a bionic toolchain, but musl
toolchain for components built on the build workstation.
---------
Co-authored-by: Gurchetan Singh <gurchetansingh@google.com>
---
build.rs | 9 ++++++
src/backend/libc/c.rs | 56 ++++++++++++++++-----------------
src/backend/libc/fs/mod.rs | 7 +++--
src/backend/libc/fs/syscalls.rs | 6 ++--
src/backend/libc/io/syscalls.rs | 6 ++--
src/backend/libc/io/types.rs | 12 +++----
src/backend/libc/mm/types.rs | 12 +++----
src/backend/libc/net/sockopt.rs | 6 ++--
src/fs/constants.rs | 6 ++--
src/fs/ioctl.rs | 8 ++---
src/fs/mod.rs | 6 ++--
src/fs/raw_dir.rs | 4 +++
src/io/read_write.rs | 6 ++--
src/ioctl/linux.rs | 4 +--
src/ioctl/mod.rs | 2 +-
src/net/sockopt.rs | 4 +--
src/net/types.rs | 48 ++++++++++++++--------------
src/timespec.rs | 2 +-
18 files changed, 109 insertions(+), 95 deletions(-)
diff --git a/build.rs b/build.rs
index d2d6541f..738492aa 100644
--- a/build.rs
+++ b/build.rs
@@ -35,6 +35,10 @@ fn main() {
// enable the libc backend even if rustix is depended on transitively.
let cfg_use_libc = var("CARGO_CFG_RUSTIX_USE_LIBC").is_ok();
+ // Check for `RUSTFLAGS=--cfg=rustix_no_linux_raw`. This allows Linux users to
+ // enable the libc backend without the linux raw dependency.
+ let cfg_no_linux_raw = var("CARGO_CFG_RUSTIX_NO_LINUX_RAW").is_ok();
+
// Check for `--features=rustc-dep-of-std`.
let rustc_dep_of_std = var("CARGO_FEATURE_RUSTC_DEP_OF_STD").is_ok();
@@ -103,10 +107,15 @@ fn main() {
|| arch.starts_with("mips"))
&& !rustix_use_experimental_asm);
if libc {
+ if os != "android" && os == "linux" && !cfg_no_linux_raw {
+ use_feature("linux_raw_dep");
+ }
+
// Use the libc backend.
use_feature("libc");
} else {
// Use the linux_raw backend.
+ use_feature("linux_raw_dep");
use_feature("linux_raw");
if rustix_use_experimental_asm {
use_feature("asm_experimental_arch");
diff --git a/src/backend/libc/c.rs b/src/backend/libc/c.rs
index 2f737c21..656c4388 100644
--- a/src/backend/libc/c.rs
+++ b/src/backend/libc/c.rs
@@ -19,49 +19,49 @@ pub(crate) const NFS_SUPER_MAGIC: u32 = 0x0000_6969;
pub(crate) const EXIT_SIGNALED_SIGABRT: c_int = 128 + SIGABRT as c_int;
// TODO: Upstream these.
-#[cfg(all(linux_kernel, feature = "net"))]
+#[cfg(all(linux_raw_dep, feature = "net"))]
pub(crate) const ETH_P_TSN: c_int = linux_raw_sys::if_ether::ETH_P_TSN as _;
-#[cfg(all(linux_kernel, feature = "net"))]
+#[cfg(all(linux_raw_dep, feature = "net"))]
pub(crate) const ETH_P_ERSPAN2: c_int = linux_raw_sys::if_ether::ETH_P_ERSPAN2 as _;
-#[cfg(all(linux_kernel, feature = "net"))]
+#[cfg(all(linux_raw_dep, feature = "net"))]
pub(crate) const ETH_P_ERSPAN: c_int = linux_raw_sys::if_ether::ETH_P_ERSPAN as _;
-#[cfg(all(linux_kernel, feature = "net"))]
+#[cfg(all(linux_raw_dep, feature = "net"))]
pub(crate) const ETH_P_PROFINET: c_int = linux_raw_sys::if_ether::ETH_P_PROFINET as _;
-#[cfg(all(linux_kernel, feature = "net"))]
+#[cfg(all(linux_raw_dep, feature = "net"))]
pub(crate) const ETH_P_REALTEK: c_int = linux_raw_sys::if_ether::ETH_P_REALTEK as _;
-#[cfg(all(linux_kernel, feature = "net"))]
+#[cfg(all(linux_raw_dep, feature = "net"))]
pub(crate) const ETH_P_ETHERCAT: c_int = linux_raw_sys::if_ether::ETH_P_ETHERCAT as _;
-#[cfg(all(linux_kernel, feature = "net"))]
+#[cfg(all(linux_raw_dep, feature = "net"))]
pub(crate) const ETH_P_PREAUTH: c_int = linux_raw_sys::if_ether::ETH_P_PREAUTH as _;
-#[cfg(all(linux_kernel, feature = "net"))]
+#[cfg(all(linux_raw_dep, feature = "net"))]
pub(crate) const ETH_P_LLDP: c_int = linux_raw_sys::if_ether::ETH_P_LLDP as _;
-#[cfg(all(linux_kernel, feature = "net"))]
+#[cfg(all(linux_raw_dep, feature = "net"))]
pub(crate) const ETH_P_MRP: c_int = linux_raw_sys::if_ether::ETH_P_MRP as _;
-#[cfg(all(linux_kernel, feature = "net"))]
+#[cfg(all(linux_raw_dep, feature = "net"))]
pub(crate) const ETH_P_NCSI: c_int = linux_raw_sys::if_ether::ETH_P_NCSI as _;
-#[cfg(all(linux_kernel, feature = "net"))]
+#[cfg(all(linux_raw_dep, feature = "net"))]
pub(crate) const ETH_P_CFM: c_int = linux_raw_sys::if_ether::ETH_P_CFM as _;
-#[cfg(all(linux_kernel, feature = "net"))]
+#[cfg(all(linux_raw_dep, feature = "net"))]
pub(crate) const ETH_P_IBOE: c_int = linux_raw_sys::if_ether::ETH_P_IBOE as _;
-#[cfg(all(linux_kernel, feature = "net"))]
+#[cfg(all(linux_raw_dep, feature = "net"))]
pub(crate) const ETH_P_HSR: c_int = linux_raw_sys::if_ether::ETH_P_HSR as _;
-#[cfg(all(linux_kernel, feature = "net"))]
+#[cfg(all(linux_raw_dep, feature = "net"))]
pub(crate) const ETH_P_NSH: c_int = linux_raw_sys::if_ether::ETH_P_NSH as _;
-#[cfg(all(linux_kernel, feature = "net"))]
+#[cfg(all(linux_raw_dep, feature = "net"))]
pub(crate) const ETH_P_DSA_8021Q: c_int = linux_raw_sys::if_ether::ETH_P_DSA_8021Q as _;
-#[cfg(all(linux_kernel, feature = "net"))]
+#[cfg(all(linux_raw_dep, feature = "net"))]
pub(crate) const ETH_P_DSA_A5PSW: c_int = linux_raw_sys::if_ether::ETH_P_DSA_A5PSW as _;
-#[cfg(all(linux_kernel, feature = "net"))]
+#[cfg(all(linux_raw_dep, feature = "net"))]
pub(crate) const ETH_P_IFE: c_int = linux_raw_sys::if_ether::ETH_P_IFE as _;
-#[cfg(all(linux_kernel, feature = "net"))]
+#[cfg(all(linux_raw_dep, feature = "net"))]
pub(crate) const ETH_P_CAN: c_int = linux_raw_sys::if_ether::ETH_P_CAN as _;
-#[cfg(all(linux_kernel, feature = "net"))]
+#[cfg(all(linux_raw_dep, feature = "net"))]
pub(crate) const ETH_P_CANXL: c_int = linux_raw_sys::if_ether::ETH_P_CANXL as _;
-#[cfg(all(linux_kernel, feature = "net"))]
+#[cfg(all(linux_raw_dep, feature = "net"))]
pub(crate) const ETH_P_XDSA: c_int = linux_raw_sys::if_ether::ETH_P_XDSA as _;
-#[cfg(all(linux_kernel, feature = "net"))]
+#[cfg(all(linux_raw_dep, feature = "net"))]
pub(crate) const ETH_P_MAP: c_int = linux_raw_sys::if_ether::ETH_P_MAP as _;
-#[cfg(all(linux_kernel, feature = "net"))]
+#[cfg(all(linux_raw_dep, feature = "net"))]
pub(crate) const ETH_P_MCTP: c_int = linux_raw_sys::if_ether::ETH_P_MCTP as _;
#[cfg(all(
@@ -89,7 +89,7 @@ pub(crate) const MSG_DONTWAIT: c_int = MSG_NONBLOCK;
// `O_LARGEFILE` can be automatically set by the kernel on Linux:
// <https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/fs/open.c?h=v6.13#n1423>
// so libc implementations may leave it undefined or defined to zero.
-#[cfg(linux_kernel)]
+#[cfg(linux_raw_dep)]
pub(crate) const O_LARGEFILE: c_int = linux_raw_sys::general::O_LARGEFILE as _;
// Gated under `_LARGEFILE_SOURCE` but automatically set by the kernel.
@@ -489,7 +489,8 @@ pub(super) use readwrite_pv64v2::{preadv64v2 as preadv2, pwritev64v2 as pwritev2
#[cfg(feature = "fs")]
#[cfg(all(
linux_like,
- not(any(target_os = "android", target_os = "emscripten", target_env = "gnu"))
+ linux_raw_dep,
+ not(any(target_os = "emscripten", target_env = "gnu"))
))]
mod statx_flags {
pub(crate) use linux_raw_sys::general::{
@@ -507,7 +508,8 @@ mod statx_flags {
#[cfg(feature = "fs")]
#[cfg(all(
linux_like,
- not(any(target_os = "android", target_os = "emscripten", target_env = "gnu"))
+ linux_raw_dep,
+ not(any(target_os = "emscripten", target_env = "gnu"))
))]
pub(crate) use statx_flags::*;
@@ -515,10 +517,6 @@ pub(crate) use statx_flags::*;
#[cfg(target_os = "android")]
pub(crate) use __fsid_t as fsid_t;
-#[cfg(feature = "mm")]
-#[cfg(target_os = "android")]
-pub(crate) const MAP_DROPPABLE: c_int = bitcast!(linux_raw_sys::general::MAP_DROPPABLE);
-
#[cfg(test)]
mod tests {
use super::*;
diff --git a/src/backend/libc/fs/mod.rs b/src/backend/libc/fs/mod.rs
index 264b955c..f75c6fb7 100644
--- a/src/backend/libc/fs/mod.rs
+++ b/src/backend/libc/fs/mod.rs
@@ -16,9 +16,12 @@ pub(crate) mod syscalls;
pub(crate) mod types;
// TODO: Fix linux-raw-sys to define ioctl codes for sparc.
-#[cfg(all(linux_kernel, any(target_arch = "sparc", target_arch = "sparc64")))]
+#[cfg(all(linux_raw_dep, any(target_arch = "sparc", target_arch = "sparc64")))]
pub(crate) const EXT4_IOC_RESIZE_FS: crate::ioctl::Opcode = 0x8008_6610;
-#[cfg(all(linux_kernel, not(any(target_arch = "sparc", target_arch = "sparc64"))))]
+#[cfg(all(
+ linux_raw_dep,
+ not(any(target_arch = "sparc", target_arch = "sparc64"))
+))]
pub(crate) const EXT4_IOC_RESIZE_FS: crate::ioctl::Opcode =
linux_raw_sys::ioctl::EXT4_IOC_RESIZE_FS as crate::ioctl::Opcode;
diff --git a/src/backend/libc/fs/syscalls.rs b/src/backend/libc/fs/syscalls.rs
index f2ac4f73..ef1033cc 100644
--- a/src/backend/libc/fs/syscalls.rs
+++ b/src/backend/libc/fs/syscalls.rs
@@ -1840,7 +1840,7 @@ pub(crate) fn memfd_create(name: &CStr, flags: MemfdFlags) -> io::Result<OwnedFd
unsafe { ret_owned_fd(memfd_create(c_str(name), bitflags_bits!(flags))) }
}
-#[cfg(linux_kernel)]
+#[cfg(linux_raw_dep)]
pub(crate) fn openat2(
dirfd: BorrowedFd<'_>,
path: &CStr,
@@ -2053,9 +2053,9 @@ pub(crate) fn statx(
// doesn't represent all the known flags.
//
// [it's deprecated]: https://patchwork.kernel.org/project/linux-fsdevel/patch/20200505095915.11275-7-mszeredi@redhat.com/
- #[cfg(not(any(target_os = "android", target_env = "musl")))]
+ #[cfg(any(not(linux_raw_dep), not(target_env = "musl")))]
const STATX__RESERVED: u32 = c::STATX__RESERVED as u32;
- #[cfg(any(target_os = "android", target_env = "musl"))]
+ #[cfg(target_env = "musl")]
const STATX__RESERVED: u32 = linux_raw_sys::general::STATX__RESERVED;
if (mask.bits() & STATX__RESERVED) == STATX__RESERVED {
return Err(io::Errno::INVAL);
diff --git a/src/backend/libc/io/syscalls.rs b/src/backend/libc/io/syscalls.rs
index f1231aaf..d91e983c 100644
--- a/src/backend/libc/io/syscalls.rs
+++ b/src/backend/libc/io/syscalls.rs
@@ -13,7 +13,7 @@ use crate::fd::{AsFd as _, BorrowedFd, OwnedFd, RawFd};
target_os = "wasi"
)))]
use crate::io::DupFlags;
-#[cfg(linux_kernel)]
+#[cfg(all(linux_kernel, not(target_os = "android")))]
use crate::io::ReadWriteFlags;
use crate::io::{self, FdFlags};
use crate::ioctl::{IoctlOutput, Opcode};
@@ -150,7 +150,7 @@ pub(crate) fn pwritev(fd: BorrowedFd<'_>, bufs: &[IoSlice<'_>], offset: u64) ->
}
}
-#[cfg(linux_kernel)]
+#[cfg(all(linux_kernel, not(target_os = "android")))]
pub(crate) fn preadv2(
fd: BorrowedFd<'_>,
bufs: &mut [IoSliceMut<'_>],
@@ -170,7 +170,7 @@ pub(crate) fn preadv2(
}
}
-#[cfg(linux_kernel)]
+#[cfg(all(linux_kernel, not(target_os = "android")))]
pub(crate) fn pwritev2(
fd: BorrowedFd<'_>,
bufs: &[IoSlice<'_>],
diff --git a/src/backend/libc/io/types.rs b/src/backend/libc/io/types.rs
index 510206f9..b434b68a 100644
--- a/src/backend/libc/io/types.rs
+++ b/src/backend/libc/io/types.rs
@@ -17,7 +17,7 @@ bitflags! {
}
}
-#[cfg(linux_kernel)]
+#[cfg(all(linux_kernel, not(target_os = "android")))]
bitflags! {
/// `RWF_*` constants for use with [`preadv2`] and [`pwritev2`].
///
@@ -27,15 +27,15 @@ bitflags! {
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct ReadWriteFlags: u32 {
/// `RWF_DSYNC` (since Linux 4.7)
- const DSYNC = linux_raw_sys::general::RWF_DSYNC;
+ const DSYNC = libc::RWF_DSYNC as u32;
/// `RWF_HIPRI` (since Linux 4.6)
- const HIPRI = linux_raw_sys::general::RWF_HIPRI;
+ const HIPRI = libc::RWF_HIPRI as u32;
/// `RWF_SYNC` (since Linux 4.7)
- const SYNC = linux_raw_sys::general::RWF_SYNC;
+ const SYNC = libc::RWF_SYNC as u32;
/// `RWF_NOWAIT` (since Linux 4.14)
- const NOWAIT = linux_raw_sys::general::RWF_NOWAIT;
+ const NOWAIT = libc::RWF_NOWAIT as u32;
/// `RWF_APPEND` (since Linux 4.16)
- const APPEND = linux_raw_sys::general::RWF_APPEND;
+ const APPEND = libc::RWF_APPEND as u32;
/// <https://docs.rs/bitflags/*/bitflags/#externally-defined-flags>
const _ = !0;
diff --git a/src/backend/libc/mm/types.rs b/src/backend/libc/mm/types.rs
index 0b99e3c4..6f7d24f5 100644
--- a/src/backend/libc/mm/types.rs
+++ b/src/backend/libc/mm/types.rs
@@ -44,19 +44,19 @@ bitflags! {
#[cfg(linux_kernel)]
const GROWSDOWN = bitcast!(c::PROT_GROWSDOWN);
/// `PROT_SEM`
- #[cfg(linux_kernel)]
+ #[cfg(linux_raw_dep)]
const SEM = linux_raw_sys::general::PROT_SEM;
/// `PROT_BTI`
- #[cfg(all(linux_kernel, target_arch = "aarch64"))]
+ #[cfg(all(linux_raw_dep, target_arch = "aarch64"))]
const BTI = linux_raw_sys::general::PROT_BTI;
/// `PROT_MTE`
- #[cfg(all(linux_kernel, target_arch = "aarch64"))]
+ #[cfg(all(linux_raw_dep, target_arch = "aarch64"))]
const MTE = linux_raw_sys::general::PROT_MTE;
/// `PROT_SAO`
- #[cfg(all(linux_kernel, any(target_arch = "powerpc", target_arch = "powerpc64")))]
+ #[cfg(all(linux_raw_dep, any(target_arch = "powerpc", target_arch = "powerpc64")))]
const SAO = linux_raw_sys::general::PROT_SAO;
/// `PROT_ADI`
- #[cfg(all(linux_kernel, any(target_arch = "sparc", target_arch = "sparc64")))]
+ #[cfg(all(linux_raw_dep, any(target_arch = "sparc", target_arch = "sparc64")))]
const ADI = linux_raw_sys::general::PROT_ADI;
/// <https://docs.rs/bitflags/*/bitflags/#externally-defined-flags>
@@ -252,7 +252,7 @@ bitflags! {
#[cfg(any())]
const UNINITIALIZED = bitcast!(c::MAP_UNINITIALIZED);
/// `MAP_DROPPABLE`
- #[cfg(linux_kernel)]
+ #[cfg(all(linux_kernel, not(target_os = "android")))]
const DROPPABLE = bitcast!(c::MAP_DROPPABLE);
/// <https://docs.rs/bitflags/*/bitflags/#externally-defined-flags>
diff --git a/src/backend/libc/net/sockopt.rs b/src/backend/libc/net/sockopt.rs
index 132ebe75..a9e32d37 100644
--- a/src/backend/libc/net/sockopt.rs
+++ b/src/backend/libc/net/sockopt.rs
@@ -76,7 +76,7 @@ use c::TCP_KEEPALIVE as TCP_KEEPIDLE;
use c::TCP_KEEPIDLE;
use core::mem::{size_of, MaybeUninit};
use core::time::Duration;
-#[cfg(target_os = "linux")]
+#[cfg(linux_raw_dep)]
use linux_raw_sys::xdp::{xdp_mmap_offsets, xdp_statistics, xdp_statistics_v1};
#[cfg(windows)]
use windows_sys::Win32::Foundation::BOOL;
@@ -1090,7 +1090,7 @@ pub(crate) fn set_xdp_rx_ring_size(fd: BorrowedFd<'_>, value: u32) -> io::Result
setsockopt(fd, c::SOL_XDP, c::XDP_RX_RING, value)
}
-#[cfg(target_os = "linux")]
+#[cfg(linux_raw_dep)]
#[inline]
pub(crate) fn xdp_mmap_offsets(fd: BorrowedFd<'_>) -> io::Result<XdpMmapOffsets> {
// The kernel will write `xdp_mmap_offsets` or `xdp_mmap_offsets_v1` to the
@@ -1177,7 +1177,7 @@ pub(crate) fn xdp_mmap_offsets(fd: BorrowedFd<'_>) -> io::Result<XdpMmapOffsets>
}
}
-#[cfg(target_os = "linux")]
+#[cfg(linux_raw_dep)]
#[inline]
pub(crate) fn xdp_statistics(fd: BorrowedFd<'_>) -> io::Result<XdpStatistics> {
let mut optlen = size_of::<xdp_statistics>().try_into().unwrap();
diff --git a/src/fs/constants.rs b/src/fs/constants.rs
index 5f106342..337b67e6 100644
--- a/src/fs/constants.rs
+++ b/src/fs/constants.rs
@@ -56,12 +56,12 @@ mod tests {
#[test]
fn test_layouts() {
- #[cfg(linux_kernel)]
+ #[cfg(linux_raw_dep)]
assert_eq_size!(FsWord, linux_raw_sys::general::__fsword_t);
// Don't test against `__kernel_mode_t` on platforms where it's a
// `u16`.
- #[cfg(linux_kernel)]
+ #[cfg(linux_raw_dep)]
#[cfg(not(any(
target_arch = "x86",
target_arch = "sparc",
@@ -70,7 +70,7 @@ mod tests {
)))]
assert_eq_size!(RawMode, linux_raw_sys::general::__kernel_mode_t);
- #[cfg(linux_kernel)]
+ #[cfg(linux_raw_dep)]
#[cfg(any(
target_arch = "x86",
target_arch = "sparc",
diff --git a/src/fs/ioctl.rs b/src/fs/ioctl.rs
index c126fdd1..16e0dda1 100644
--- a/src/fs/ioctl.rs
+++ b/src/fs/ioctl.rs
@@ -58,7 +58,7 @@ pub fn ioctl_ficlone<Fd: AsFd, SrcFd: AsFd>(fd: Fd, src_fd: SrcFd) -> io::Result
}
/// `ioctl(fd, EXT4_IOC_RESIZE_FS, blocks)`—Resize ext4 filesystem on fd.
-#[cfg(linux_kernel)]
+#[cfg(linux_raw_dep)]
#[inline]
#[doc(alias = "EXT4_IOC_RESIZE_FS")]
pub fn ext4_ioc_resize_fs<Fd: AsFd>(fd: Fd, blocks: u64) -> io::Result<()> {
@@ -94,7 +94,7 @@ unsafe impl ioctl::Ioctl for Ficlone<'_> {
}
}
-#[cfg(linux_kernel)]
+#[cfg(linux_raw_dep)]
bitflags! {
/// `FS_*` constants for use with [`ioctl_getflags`].
///
@@ -136,7 +136,7 @@ bitflags! {
/// `ioctl(fd, FS_IOC_GETFLAGS)`—Returns the [inode flags] attributes
///
/// [inode flags]: https://man7.org/linux/man-pages/man2/ioctl_iflags.2.html
-#[cfg(linux_kernel)]
+#[cfg(linux_raw_dep)]
#[inline]
#[doc(alias = "FS_IOC_GETFLAGS")]
pub fn ioctl_getflags<Fd: AsFd>(fd: Fd) -> io::Result<IFlags> {
@@ -153,7 +153,7 @@ pub fn ioctl_getflags<Fd: AsFd>(fd: Fd) -> io::Result<IFlags> {
/// `ioctl(fd, FS_IOC_SETFLAGS)`—Modify the [inode flags] attributes
///
/// [inode flags]: https://man7.org/linux/man-pages/man2/ioctl_iflags.2.html
-#[cfg(linux_kernel)]
+#[cfg(linux_raw_dep)]
#[inline]
#[doc(alias = "FS_IOC_SETFLAGS")]
pub fn ioctl_setflags<Fd: AsFd>(fd: Fd, flags: IFlags) -> io::Result<()> {
diff --git a/src/fs/mod.rs b/src/fs/mod.rs
index 505925f7..1807ada6 100644
--- a/src/fs/mod.rs
+++ b/src/fs/mod.rs
@@ -30,7 +30,7 @@ pub(crate) mod fd;
mod getpath;
#[cfg(not(target_os = "wasi"))] // WASI doesn't have get[gpu]id.
mod id;
-#[cfg(linux_kernel)]
+#[cfg(linux_raw_dep)]
pub mod inotify;
#[cfg(linux_kernel)]
mod ioctl;
@@ -45,7 +45,7 @@ mod ioctl;
mod makedev;
#[cfg(any(linux_kernel, target_os = "freebsd"))]
mod memfd_create;
-#[cfg(linux_kernel)]
+#[cfg(linux_raw_dep)]
mod openat2;
#[cfg(linux_kernel)]
mod raw_dir;
@@ -110,7 +110,7 @@ pub use ioctl::*;
pub use makedev::*;
#[cfg(any(linux_kernel, target_os = "freebsd"))]
pub use memfd_create::memfd_create;
-#[cfg(linux_kernel)]
+#[cfg(linux_raw_dep)]
pub use openat2::openat2;
#[cfg(linux_kernel)]
pub use raw_dir::{RawDir, RawDirEntry};
diff --git a/src/fs/raw_dir.rs b/src/fs/raw_dir.rs
index 7fec6fd7..9691ca71 100644
--- a/src/fs/raw_dir.rs
+++ b/src/fs/raw_dir.rs
@@ -7,6 +7,10 @@ use crate::fs::FileType;
use crate::io;
use core::fmt;
use core::mem::{align_of, MaybeUninit};
+
+#[cfg(not(linux_raw_dep))]
+use libc::dirent64 as linux_dirent64;
+#[cfg(linux_raw_dep)]
use linux_raw_sys::general::linux_dirent64;
/// A directory iterator implemented with getdents.
diff --git a/src/io/read_write.rs b/src/io/read_write.rs
index 572c7b65..0e096910 100644
--- a/src/io/read_write.rs
+++ b/src/io/read_write.rs
@@ -10,7 +10,7 @@ use backend::fd::AsFd;
#[cfg(not(windows))]
pub use crate::maybe_polyfill::io::{IoSlice, IoSliceMut};
-#[cfg(linux_kernel)]
+#[cfg(all(linux_kernel, not(target_os = "android")))]
pub use backend::io::types::ReadWriteFlags;
/// `read(fd, buf)`—Reads from a stream.
@@ -277,7 +277,7 @@ pub fn pwritev<Fd: AsFd>(fd: Fd, bufs: &[IoSlice<'_>], offset: u64) -> io::Resul
///
/// [Linux]: https://man7.org/linux/man-pages/man2/preadv2.2.html
/// [glibc]: https://sourceware.org/glibc/manual/latest/html_node/Scatter_002dGather.html#index-preadv64v2
-#[cfg(linux_kernel)]
+#[cfg(all(linux_kernel, not(target_os = "android")))]
#[inline]
pub fn preadv2<Fd: AsFd>(
fd: Fd,
@@ -298,7 +298,7 @@ pub fn preadv2<Fd: AsFd>(
///
/// [Linux]: https://man7.org/linux/man-pages/man2/pwritev2.2.html
/// [glibc]: https://sourceware.org/glibc/manual/latest/html_node/Scatter_002dGather.html#index-pwritev64v2
-#[cfg(linux_kernel)]
+#[cfg(all(linux_kernel, not(target_os = "android")))]
#[inline]
pub fn pwritev2<Fd: AsFd>(
fd: Fd,
diff --git a/src/ioctl/linux.rs b/src/ioctl/linux.rs
index 7215228a..8d96a1b2 100644
--- a/src/ioctl/linux.rs
+++ b/src/ioctl/linux.rs
@@ -88,12 +88,12 @@ mod tests {
#[allow(unused_imports)]
use super::*;
- #[cfg(not(any(
+ #[cfg(all(linux_raw_dep, not(any(
// These have no ioctl opcodes defined in linux_raw_sys so we can't use
// that as a known-good value for this test.
target_arch = "sparc",
target_arch = "sparc64"
-)))]
+))))]
#[test]
fn check_known_opcodes() {
use crate::backend::c::{c_long, c_uint};
diff --git a/src/ioctl/mod.rs b/src/ioctl/mod.rs
index e3e8f8e1..4beed113 100644
--- a/src/ioctl/mod.rs
+++ b/src/ioctl/mod.rs
@@ -344,7 +344,7 @@ type _Opcode = c::c_uint;
#[cfg(windows)]
type _Opcode = i32;
-#[cfg(linux_kernel)]
+#[cfg(linux_raw_dep)]
#[cfg(not(any(target_arch = "sparc", target_arch = "sparc64")))]
#[cfg(test)]
mod tests {
diff --git a/src/net/sockopt.rs b/src/net/sockopt.rs
index ef8176ae..145f32be 100644
--- a/src/net/sockopt.rs
+++ b/src/net/sockopt.rs
@@ -1604,7 +1604,7 @@ pub fn set_xdp_rx_ring_size<Fd: AsFd>(fd: Fd, value: u32) -> io::Result<()> {
/// - [Linux]
///
/// [Linux]: https://www.kernel.org/doc/html/next/networking/af_xdp.html
-#[cfg(target_os = "linux")]
+#[cfg(linux_raw_dep)]
#[doc(alias = "XDP_MMAP_OFFSETS")]
pub fn xdp_mmap_offsets<Fd: AsFd>(fd: Fd) -> io::Result<XdpMmapOffsets> {
backend::net::sockopt::xdp_mmap_offsets(fd.as_fd())
@@ -1616,7 +1616,7 @@ pub fn xdp_mmap_offsets<Fd: AsFd>(fd: Fd) -> io::Result<XdpMmapOffsets> {
/// - [Linux]
///
/// [Linux]: https://www.kernel.org/doc/html/next/networking/af_xdp.html#xdp-statistics-getsockopt
-#[cfg(target_os = "linux")]
+#[cfg(linux_raw_dep)]
#[doc(alias = "XDP_STATISTICS")]
pub fn xdp_statistics<Fd: AsFd>(fd: Fd) -> io::Result<XdpStatistics> {
backend::net::sockopt::xdp_statistics(fd.as_fd())
diff --git a/src/net/types.rs b/src/net/types.rs
index 057f944d..43dfa610 100644
--- a/src/net/types.rs
+++ b/src/net/types.rs
@@ -1321,10 +1321,10 @@ pub mod eth {
#[cfg(linux_kernel)]
pub const PUPAT: Protocol = Protocol(new_raw_protocol((c::ETH_P_PUPAT as u16).to_be() as u32));
/// `ETH_P_TSN`
- #[cfg(linux_kernel)]
+ #[cfg(linux_raw_dep)]
pub const TSN: Protocol = Protocol(new_raw_protocol((c::ETH_P_TSN as u16).to_be() as u32));
/// `ETH_P_ERSPAN2`
- #[cfg(linux_kernel)]
+ #[cfg(linux_raw_dep)]
pub const ERSPAN2: Protocol =
Protocol(new_raw_protocol((c::ETH_P_ERSPAN2 as u16).to_be() as u32));
/// `ETH_P_IP`
@@ -1395,7 +1395,7 @@ pub mod eth {
pub const P_8021Q: Protocol =
Protocol(new_raw_protocol((c::ETH_P_8021Q as u16).to_be() as u32));
/// `ETH_P_ERSPAN`
- #[cfg(linux_kernel)]
+ #[cfg(linux_raw_dep)]
pub const ERSPAN: Protocol =
Protocol(new_raw_protocol((c::ETH_P_ERSPAN as u16).to_be() as u32));
/// `ETH_P_IPX`
@@ -1445,18 +1445,18 @@ pub mod eth {
#[cfg(linux_kernel)]
pub const PAE: Protocol = Protocol(new_raw_protocol((c::ETH_P_PAE as u16).to_be() as u32));
/// `ETH_P_PROFINET`
- #[cfg(linux_kernel)]
+ #[cfg(linux_raw_dep)]
pub const PROFINET: Protocol =
Protocol(new_raw_protocol((c::ETH_P_PROFINET as u16).to_be() as u32));
/// `ETH_P_REALTEK`
- #[cfg(linux_kernel)]
+ #[cfg(linux_raw_dep)]
pub const REALTEK: Protocol =
Protocol(new_raw_protocol((c::ETH_P_REALTEK as u16).to_be() as u32));
/// `ETH_P_AOE`
#[cfg(linux_kernel)]
pub const AOE: Protocol = Protocol(new_raw_protocol((c::ETH_P_AOE as u16).to_be() as u32));
/// `ETH_P_ETHERCAT`
- #[cfg(linux_kernel)]
+ #[cfg(linux_raw_dep)]
pub const ETHERCAT: Protocol =
Protocol(new_raw_protocol((c::ETH_P_ETHERCAT as u16).to_be() as u32));
/// `ETH_P_8021AD`
@@ -1468,17 +1468,17 @@ pub mod eth {
pub const P_802_EX1: Protocol =
Protocol(new_raw_protocol((c::ETH_P_802_EX1 as u16).to_be() as u32));
/// `ETH_P_PREAUTH`
- #[cfg(linux_kernel)]
+ #[cfg(linux_raw_dep)]
pub const PREAUTH: Protocol =
Protocol(new_raw_protocol((c::ETH_P_PREAUTH as u16).to_be() as u32));
/// `ETH_P_TIPC`
#[cfg(linux_kernel)]
pub const TIPC: Protocol = Protocol(new_raw_protocol((c::ETH_P_TIPC as u16).to_be() as u32));
/// `ETH_P_LLDP`
- #[cfg(linux_kernel)]
+ #[cfg(linux_raw_dep)]
pub const LLDP: Protocol = Protocol(new_raw_protocol((c::ETH_P_LLDP as u16).to_be() as u32));
/// `ETH_P_MRP`
- #[cfg(linux_kernel)]
+ #[cfg(linux_raw_dep)]
pub const MRP: Protocol = Protocol(new_raw_protocol((c::ETH_P_MRP as u16).to_be() as u32));
/// `ETH_P_MACSEC`
#[cfg(linux_kernel)]
@@ -1495,19 +1495,19 @@ pub mod eth {
#[cfg(linux_kernel)]
pub const P_1588: Protocol = Protocol(new_raw_protocol((c::ETH_P_1588 as u16).to_be() as u32));
/// `ETH_P_NCSI`
- #[cfg(linux_kernel)]
+ #[cfg(linux_raw_dep)]
pub const NCSI: Protocol = Protocol(new_raw_protocol((c::ETH_P_NCSI as u16).to_be() as u32));
/// `ETH_P_PRP`
#[cfg(linux_kernel)]
pub const PRP: Protocol = Protocol(new_raw_protocol((c::ETH_P_PRP as u16).to_be() as u32));
/// `ETH_P_CFM`
- #[cfg(linux_kernel)]
+ #[cfg(linux_raw_dep)]
pub const CFM: Protocol = Protocol(new_raw_protocol((c::ETH_P_CFM as u16).to_be() as u32));
/// `ETH_P_FCOE`
#[cfg(linux_kernel)]
pub const FCOE: Protocol = Protocol(new_raw_protocol((c::ETH_P_FCOE as u16).to_be() as u32));
/// `ETH_P_IBOE`
- #[cfg(linux_kernel)]
+ #[cfg(linux_raw_dep)]
pub const IBOE: Protocol = Protocol(new_raw_protocol((c::ETH_P_IBOE as u16).to_be() as u32));
/// `ETH_P_TDLS`
#[cfg(linux_kernel)]
@@ -1520,10 +1520,10 @@ pub mod eth {
pub const P_80221: Protocol =
Protocol(new_raw_protocol((c::ETH_P_80221 as u16).to_be() as u32));
/// `ETH_P_HSR`
- #[cfg(linux_kernel)]
+ #[cfg(linux_raw_dep)]
pub const HSR: Protocol = Protocol(new_raw_protocol((c::ETH_P_HSR as u16).to_be() as u32));
/// `ETH_P_NSH`
- #[cfg(linux_kernel)]
+ #[cfg(linux_raw_dep)]
pub const NSH: Protocol = Protocol(new_raw_protocol((c::ETH_P_NSH as u16).to_be() as u32));
/// `ETH_P_LOOPBACK`
#[cfg(linux_kernel)]
@@ -1542,15 +1542,15 @@ pub mod eth {
#[cfg(linux_kernel)]
pub const EDSA: Protocol = Protocol(new_raw_protocol((c::ETH_P_EDSA as u16).to_be() as u32));
/// `ETH_P_DSA_8021Q`
- #[cfg(linux_kernel)]
+ #[cfg(linux_raw_dep)]
pub const DSA_8021Q: Protocol =
Protocol(new_raw_protocol((c::ETH_P_DSA_8021Q as u16).to_be() as u32));
/// `ETH_P_DSA_A5PSW`
- #[cfg(linux_kernel)]
+ #[cfg(linux_raw_dep)]
pub const DSA_A5PSW: Protocol =
Protocol(new_raw_protocol((c::ETH_P_DSA_A5PSW as u16).to_be() as u32));
/// `ETH_P_IFE`
- #[cfg(linux_kernel)]
+ #[cfg(linux_raw_dep)]
pub const IFE: Protocol = Protocol(new_raw_protocol((c::ETH_P_IFE as u16).to_be() as u32));
/// `ETH_P_AF_IUCV`
#[cfg(linux_kernel)]
@@ -1568,7 +1568,7 @@ pub mod eth {
#[cfg(linux_kernel)]
pub const AX25: Protocol = Protocol(new_raw_protocol((c::ETH_P_AX25 as u16).to_be() as u32));
/// `ETH_P_ALL`
- #[cfg(linux_kernel)]
+ #[cfg(linux_raw_dep)]
pub const ALL: Protocol = Protocol(new_raw_protocol((c::ETH_P_ALL as u16).to_be() as u32));
/// `ETH_P_802_2`
#[cfg(linux_kernel)]
@@ -1593,13 +1593,13 @@ pub mod eth {
pub const LOCALTALK: Protocol =
Protocol(new_raw_protocol((c::ETH_P_LOCALTALK as u16).to_be() as u32));
/// `ETH_P_CAN`
- #[cfg(linux_kernel)]
+ #[cfg(linux_raw_dep)]
pub const CAN: Protocol = Protocol(new_raw_protocol((c::ETH_P_CAN as u16).to_be() as u32));
/// `ETH_P_CANFD`
#[cfg(linux_kernel)]
pub const CANFD: Protocol = Protocol(new_raw_protocol((c::ETH_P_CANFD as u16).to_be() as u32));
/// `ETH_P_CANXL`
- #[cfg(linux_kernel)]
+ #[cfg(linux_raw_dep)]
pub const CANXL: Protocol = Protocol(new_raw_protocol((c::ETH_P_CANXL as u16).to_be() as u32));
/// `ETH_P_PPPTALK`
#[cfg(linux_kernel)]
@@ -1632,7 +1632,7 @@ pub mod eth {
pub const ARCNET: Protocol =
Protocol(new_raw_protocol((c::ETH_P_ARCNET as u16).to_be() as u32));
/// `ETH_P_DSA`
- #[cfg(linux_kernel)]
+ #[cfg(linux_raw_dep)]
pub const DSA: Protocol = Protocol(new_raw_protocol((c::ETH_P_DSA as u16).to_be() as u32));
/// `ETH_P_TRAILER`
#[cfg(linux_kernel)]
@@ -1650,13 +1650,13 @@ pub mod eth {
#[cfg(linux_kernel)]
pub const CAIF: Protocol = Protocol(new_raw_protocol((c::ETH_P_CAIF as u16).to_be() as u32));
/// `ETH_P_XDSA`
- #[cfg(linux_kernel)]
+ #[cfg(linux_raw_dep)]
pub const XDSA: Protocol = Protocol(new_raw_protocol((c::ETH_P_XDSA as u16).to_be() as u32));
/// `ETH_P_MAP`
- #[cfg(linux_kernel)]
+ #[cfg(linux_raw_dep)]
pub const MAP: Protocol = Protocol(new_raw_protocol((c::ETH_P_MAP as u16).to_be() as u32));
/// `ETH_P_MCTP`
- #[cfg(linux_kernel)]
+ #[cfg(linux_raw_dep)]
pub const MCTP: Protocol = Protocol(new_raw_protocol((c::ETH_P_MCTP as u16).to_be() as u32));
}
diff --git a/src/timespec.rs b/src/timespec.rs
index f5404ba4..a6458bbc 100644
--- a/src/timespec.rs
+++ b/src/timespec.rs
@@ -411,7 +411,7 @@ mod tests {
}
// Test that `Timespec` matches Linux's `__kernel_timespec`.
- #[cfg(linux_kernel)]
+ #[cfg(linux_raw_dep)]
#[test]
fn test_against_kernel_timespec() {
assert_eq_size!(Timespec, linux_raw_sys::general::__kernel_timespec);
--
2.50.0.727.gbf7dc18ff4-goog

View file

@ -0,0 +1,59 @@
From eec94e8888578c4f28607c2d5ef4e2f41480b802 Mon Sep 17 00:00:00 2001
From: Gurchetan Singh <gurchetan.singh.foss@gmail.com>
Date: Thu, 30 Jan 2025 13:38:39 -0800
Subject: [PATCH 1/4] rustix: add ioctl wrappers
These ioctl wrappers are used by rustix users. For example:
https://github.com/Smithay/drm-rs/blob/develop/drm-ffi/src/ioctl.rs#L6
Roughly, they match the ones provided by nix. I'm upstreaming the
portion I have personally tested.
---
src/ioctl/mod.rs | 30 ++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)
diff --git a/src/ioctl/mod.rs b/src/ioctl/mod.rs
index 70c69053..b6d8fe42 100644
--- a/src/ioctl/mod.rs
+++ b/src/ioctl/mod.rs
@@ -344,6 +344,36 @@ type _Opcode = c::c_uint;
#[cfg(windows)]
type _Opcode = i32;
+/// Convenience macro for Rustix's ioctl write
+#[macro_export]
+macro_rules! ioctl_write_ptr {
+ ($name:ident, $ioty:expr, $nr:expr, $ty:ty) => {
+ pub unsafe fn $name(fd: std::os::fd::BorrowedFd, data: &$ty) -> std::io::Result<()> {
+ const OPCODE: $crate::ioctl::Opcode =
+ $crate::ioctl::opcode::write::<$ty>($ioty as u8, $nr as u8);
+ Ok(rustix::ioctl::ioctl(
+ fd,
+ $crate::ioctl::Setter::<OPCODE, $ty>::new(*data),
+ )?)
+ }
+ };
+}
+
+/// Convenience macro for Rustix's ioctl read
+#[macro_export]
+macro_rules! ioctl_readwrite {
+ ($name:ident, $ioty:expr, $nr:expr, $ty:ty) => {
+ pub unsafe fn $name(fd: std::os::fd::BorrowedFd, data: &mut $ty) -> std::io::Result<()> {
+ const OPCODE: $crate::ioctl::Opcode =
+ $crate::ioctl::opcode::read_write::<$ty>($ioty as u8, $nr as u8);
+ Ok($crate::ioctl::ioctl(
+ fd,
+ $crate::ioctl::Updater::<OPCODE, $ty>::new(data),
+ )?)
+ }
+ };
+}
+
#[cfg(linux_raw_dep)]
#[cfg(not(any(target_arch = "sparc", target_arch = "sparc64")))]
#[cfg(test)]
--
2.54.0.545.g6539524ca2-goog

View file

@ -0,0 +1,85 @@
From 50c2d9e76170080ac1ab87672771ea65b9b33bcb Mon Sep 17 00:00:00 2001
From: Gurchetan Singh <gurchetan.singh.foss@gmail.com>
Date: Mon, 30 Jun 2025 11:24:05 -0700
Subject: [PATCH 2/4] rustix: improve for musl build without linux-raw-sys
Android likes to build host tools (adb, Cuttlefish, ..)
via musl, using the same hermetic tree as for Bionic
build.
And linux-raw-sys isn't in that hermetic tree, so add support
for the libc-backend.
---
src/backend/libc/fs/syscalls.rs | 4 ++--
src/fs/statx.rs | 34 +++++++++++++++++++++++++++++++++
2 files changed, 36 insertions(+), 2 deletions(-)
diff --git a/src/backend/libc/fs/syscalls.rs b/src/backend/libc/fs/syscalls.rs
index 71bc8b0a..1c687cc3 100644
--- a/src/backend/libc/fs/syscalls.rs
+++ b/src/backend/libc/fs/syscalls.rs
@@ -2071,10 +2071,10 @@ pub(crate) fn statx(
// doesn't represent all the known flags.
//
// [it's deprecated]: https://patchwork.kernel.org/project/linux-fsdevel/patch/20200505095915.11275-7-mszeredi@redhat.com/
- #[cfg(any(not(linux_raw_dep), not(target_env = "musl")))]
+ #[cfg(not(target_env = "musl"))]
const STATX__RESERVED: u32 = c::STATX__RESERVED as u32;
#[cfg(target_env = "musl")]
- const STATX__RESERVED: u32 = linux_raw_sys::general::STATX__RESERVED;
+ const STATX__RESERVED: u32 = 0x80000000;
if (mask.bits() & STATX__RESERVED) == STATX__RESERVED {
return Err(io::Errno::INVAL);
}
diff --git a/src/fs/statx.rs b/src/fs/statx.rs
index f8be29f7..e85d63aa 100644
--- a/src/fs/statx.rs
+++ b/src/fs/statx.rs
@@ -3,6 +3,7 @@
use crate::fd::AsFd;
use crate::fs::AtFlags;
use crate::{backend, io, path};
+#[cfg(any(linux_raw_dep, not(target_env = "musl")))]
use backend::c;
use bitflags::bitflags;
@@ -275,3 +276,36 @@ mod compat {
}
}
}
+
+// These are the actual values for the constants, needed for the fallback implementation.
+// TODO(https://github.com/bytecodealliance/rustix/issues/1589): try to upstream these
+// constants to libc.
+#[cfg(all(not(linux_raw_dep), target_env = "musl"))]
+mod c {
+ pub const STATX_TYPE: u32 = 0x00000001;
+ pub const STATX_MODE: u32 = 0x00000002;
+ pub const STATX_NLINK: u32 = 0x00000004;
+ pub const STATX_UID: u32 = 0x00000008;
+ pub const STATX_GID: u32 = 0x00000010;
+ pub const STATX_ATIME: u32 = 0x00000020;
+ pub const STATX_MTIME: u32 = 0x00000040;
+ pub const STATX_CTIME: u32 = 0x00000080;
+ pub const STATX_INO: u32 = 0x00000100;
+ pub const STATX_SIZE: u32 = 0x00000200;
+ pub const STATX_BLOCKS: u32 = 0x00000400;
+ pub const STATX_BASIC_STATS: u32 = 0x000007ff;
+ pub const STATX_BTIME: u32 = 0x00000800;
+ pub const STATX_MNT_ID: u32 = 0x00001000;
+ pub const STATX_DIOALIGN: u32 = 0x00002000; // Deprecated, but here for completeness
+ pub const STATX_ALL: u32 = 0x00000fff; // Note: Doesn't include newer flags
+
+ pub const STATX_ATTR_COMPRESSED: u64 = 0x00000004;
+ pub const STATX_ATTR_IMMUTABLE: u64 = 0x00000010;
+ pub const STATX_ATTR_APPEND: u64 = 0x00000020;
+ pub const STATX_ATTR_NODUMP: u64 = 0x00000040;
+ pub const STATX_ATTR_ENCRYPTED: u64 = 0x00000800;
+ pub const STATX_ATTR_AUTOMOUNT: u64 = 0x00001000;
+ pub const STATX_ATTR_MOUNT_ROOT: u64 = 0x00020000;
+ pub const STATX_ATTR_VERITY: u64 = 0x00100000;
+ pub const STATX_ATTR_DAX: u64 = 0x00200000;
+}
--
2.54.0.545.g6539524ca2-goog

View file

@ -0,0 +1,253 @@
From 680162aec19d93309123aeb9a983d361bdeeb38f Mon Sep 17 00:00:00 2001
From: Gurchetan Singh <gurchetan.singh.foss@gmail.com>
Date: Fri, 30 Jan 2026 07:41:51 -0800
Subject: [PATCH 3/4] rustix: enable rustix::thread::futex without
linux-raw-sys
It's desirable to enable futex for some cases that will be
run on Android. The strategy is just to define the constants
needed by the libc ourselves, if libc doesn't provide the
necessary constant. Long-term, that could make the libc
backend only depend on libc.
---
src/backend/libc/c.rs | 10 +++++++++
src/backend/libc/thread/futex.rs | 31 +++++++++++++++++-----------
src/backend/libc/thread/syscalls.rs | 32 +++++++++++++++++++++++++----
src/test_macro.rs | 3 +++
src/thread/mod.rs | 11 +++++-----
5 files changed, 66 insertions(+), 21 deletions(-)
create mode 100644 src/test_macro.rs
diff --git a/src/backend/libc/c.rs b/src/backend/libc/c.rs
index 5eeff953..1a319a0f 100644
--- a/src/backend/libc/c.rs
+++ b/src/backend/libc/c.rs
@@ -515,6 +515,16 @@ pub(crate) use statx_flags::*;
#[cfg(target_os = "android")]
pub(crate) use __fsid_t as fsid_t;
+// Android's libc crate is missing some constants.
+// TODO(https://github.com/bytecodealliance/rustix/issues/1589): try to upstream these
+// constants to libc.
+#[cfg(target_os = "android")]
+pub(crate) const CLONE_NEWTIME: c_int = 0x00000080;
+#[cfg(target_os = "android")]
+pub(crate) const FUTEX_WAITERS: u32 = 0x80000000;
+#[cfg(target_os = "android")]
+pub(crate) const FUTEX_OWNER_DIED: u32 = 0x40000000;
+
// FreeBSD added `timerfd_*` in FreeBSD 14. NetBSD added then in NetBSD 10.
#[cfg(all(feature = "time", any(target_os = "freebsd", target_os = "netbsd")))]
syscall!(pub(crate) fn timerfd_create(
diff --git a/src/backend/libc/thread/futex.rs b/src/backend/libc/thread/futex.rs
index 5e836a9a..6d2e1495 100644
--- a/src/backend/libc/thread/futex.rs
+++ b/src/backend/libc/thread/futex.rs
@@ -17,6 +17,16 @@ bitflags::bitflags! {
}
}
+// TODO(https://github.com/bytecodealliance/rustix/issues/1589): try to upstream these
+// constants to libc.
+const FUTEX2_SIZE_U8: u32 = 0;
+const FUTEX2_SIZE_U16: u32 = 1;
+const FUTEX2_SIZE_U32: u32 = 2;
+const FUTEX2_SIZE_U64: u32 = 3;
+const FUTEX2_SIZE_MASK: u32 = 3;
+const FUTEX2_NUMA: u32 = 4;
+const FUTEX2_PRIVATE: u32 = 128;
+
bitflags::bitflags! {
/// `FUTEX2_*` flags for use with the functions in [`Waitv`].
///
@@ -29,22 +39,19 @@ bitflags::bitflags! {
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct WaitFlags: u32 {
/// `FUTEX_U8`
- const SIZE_U8 = linux_raw_sys::general::FUTEX2_SIZE_U8;
+ const SIZE_U8 = FUTEX2_SIZE_U8;
/// `FUTEX_U16`
- const SIZE_U16 = linux_raw_sys::general::FUTEX2_SIZE_U16;
+ const SIZE_U16 = FUTEX2_SIZE_U16;
/// `FUTEX_U32`
- const SIZE_U32 = linux_raw_sys::general::FUTEX2_SIZE_U32;
+ const SIZE_U32 = FUTEX2_SIZE_U32;
/// `FUTEX_U64`
- const SIZE_U64 = linux_raw_sys::general::FUTEX2_SIZE_U64;
+ const SIZE_U64 = FUTEX2_SIZE_U64;
/// `FUTEX_SIZE_MASK`
- const SIZE_MASK = linux_raw_sys::general::FUTEX2_SIZE_MASK;
-
+ const SIZE_MASK = FUTEX2_SIZE_MASK;
/// `FUTEX2_NUMA`
- const NUMA = linux_raw_sys::general::FUTEX2_NUMA;
-
+ const NUMA = FUTEX2_NUMA;
/// `FUTEX2_PRIVATE`
- const PRIVATE = linux_raw_sys::general::FUTEX2_PRIVATE;
-
+ const PRIVATE = FUTEX2_PRIVATE;
/// <https://docs.rs/bitflags/*/bitflags/#externally-defined-flags>
const _ = !0;
}
@@ -85,7 +92,7 @@ pub(crate) enum Operation {
}
/// `FUTEX_WAITERS`
-pub const WAITERS: u32 = linux_raw_sys::general::FUTEX_WAITERS;
+pub const WAITERS: u32 = c::FUTEX_WAITERS;
/// `FUTEX_OWNER_DIED`
-pub const OWNER_DIED: u32 = linux_raw_sys::general::FUTEX_OWNER_DIED;
+pub const OWNER_DIED: u32 = c::FUTEX_OWNER_DIED;
diff --git a/src/backend/libc/thread/syscalls.rs b/src/backend/libc/thread/syscalls.rs
index 84356fee..5ea541fe 100644
--- a/src/backend/libc/thread/syscalls.rs
+++ b/src/backend/libc/thread/syscalls.rs
@@ -341,13 +341,13 @@ pub(crate) fn setns(fd: BorrowedFd<'_>, nstype: c::c_int) -> io::Result<c::c_int
unsafe { ret_c_int(setns(borrowed_fd(fd), nstype)) }
}
-#[cfg(linux_kernel)]
+#[cfg(all(linux_kernel, linux_raw_dep))]
#[inline]
pub(crate) unsafe fn unshare(flags: crate::thread::UnshareFlags) -> io::Result<()> {
ret(c::unshare(flags.bits() as i32))
}
-#[cfg(linux_kernel)]
+#[cfg(all(linux_kernel, linux_raw_dep))]
#[inline]
pub(crate) fn capget(
header: &mut linux_raw_sys::general::__user_cap_header_struct,
@@ -369,7 +369,7 @@ pub(crate) fn capget(
}
}
-#[cfg(linux_kernel)]
+#[cfg(all(linux_kernel, linux_raw_dep))]
#[inline]
pub(crate) fn capset(
header: &mut linux_raw_sys::general::__user_cap_header_struct,
@@ -477,6 +477,7 @@ pub(crate) unsafe fn futex_val2(
let timeout = val2 as usize as *const Timespec;
#[cfg(all(
+ linux_raw_dep,
target_pointer_width = "32",
not(any(target_arch = "aarch64", target_arch = "x86_64"))
))]
@@ -506,6 +507,16 @@ pub(crate) unsafe fn futex_val2(
))
}
+ #[cfg(all(
+ not(linux_raw_dep),
+ target_pointer_width = "32",
+ not(any(target_arch = "aarch64", target_arch = "x86_64"))
+ ))]
+ {
+ let _ = (uaddr, op, flags, val, timeout, uaddr2, val3);
+ Err(io::Errno::NOSYS)
+ }
+
#[cfg(any(
target_pointer_width = "64",
target_arch = "aarch64",
@@ -548,6 +559,7 @@ pub(crate) unsafe fn futex_timeout(
val3: u32,
) -> io::Result<usize> {
#[cfg(all(
+ linux_raw_dep,
target_pointer_width = "32",
not(any(target_arch = "aarch64", target_arch = "x86_64"))
))]
@@ -585,6 +597,16 @@ pub(crate) unsafe fn futex_timeout(
})
}
+ #[cfg(all(
+ not(linux_raw_dep),
+ target_pointer_width = "32",
+ not(any(target_arch = "aarch64", target_arch = "x86_64"))
+ ))]
+ {
+ let _ = (uaddr, op, flags, val, timeout, uaddr2, val3);
+ Err(io::Errno::NOSYS)
+ }
+
#[cfg(any(
target_pointer_width = "64",
target_arch = "aarch64",
@@ -618,6 +640,7 @@ pub(crate) unsafe fn futex_timeout(
/// The raw pointers must point to valid aligned memory.
#[cfg(linux_kernel)]
#[cfg(all(
+ linux_raw_dep,
target_pointer_width = "32",
not(any(target_arch = "aarch64", target_arch = "x86_64"))
))]
@@ -666,8 +689,9 @@ pub(crate) fn futex_waitv(
timeout: Option<&Timespec>,
clockid: ClockId,
) -> io::Result<usize> {
+ use crate::backend::c::clockid_t;
use futex::Wait as FutexWait;
- use linux_raw_sys::general::__kernel_clockid_t as clockid_t;
+
syscall! {
fn futex_waitv(
waiters: *const FutexWait,
diff --git a/src/test_macro.rs b/src/test_macro.rs
new file mode 100644
index 00000000..f6a11a8f
--- /dev/null
+++ b/src/test_macro.rs
@@ -0,0 +1,3 @@
+use crate::ioctl_readwrite;
+
+fn main() {}
diff --git a/src/thread/mod.rs b/src/thread/mod.rs
index 26d1de42..b5e7e844 100644
--- a/src/thread/mod.rs
+++ b/src/thread/mod.rs
@@ -6,16 +6,16 @@ mod clock;
pub mod futex;
#[cfg(linux_kernel)]
mod id;
-#[cfg(linux_kernel)]
+#[cfg(all(linux_kernel, linux_raw_dep))]
mod libcap;
#[cfg(linux_kernel)]
mod membarrier;
-#[cfg(linux_kernel)]
+#[cfg(all(linux_kernel, linux_raw_dep))]
mod prctl;
#[cfg(any(freebsdlike, linux_kernel, target_os = "fuchsia"))]
mod sched;
mod sched_yield;
-#[cfg(linux_kernel)]
+#[cfg(all(linux_kernel, linux_raw_dep))]
mod setns;
#[cfg(not(target_os = "redox"))]
@@ -25,13 +25,14 @@ pub use id::*;
#[cfg(linux_kernel)]
// #[expect(deprecated, reason = "CapabilityFlags is deprecated")]
#[allow(deprecated)]
+#[cfg(all(linux_kernel, linux_raw_dep))]
pub use libcap::{capabilities, set_capabilities, CapabilityFlags, CapabilitySet, CapabilitySets};
#[cfg(linux_kernel)]
pub use membarrier::*;
-#[cfg(linux_kernel)]
+#[cfg(all(linux_kernel, linux_raw_dep))]
pub use prctl::*;
#[cfg(any(freebsdlike, linux_kernel, target_os = "fuchsia"))]
pub use sched::*;
pub use sched_yield::sched_yield;
-#[cfg(linux_kernel)]
+#[cfg(all(linux_kernel, linux_raw_dep))]
pub use setns::*;
--
2.54.0.545.g6539524ca2-goog

View file

@ -4,7 +4,7 @@
project(
'rustix-1-rs',
'rust',
version : '1.1.2',
version : '1.1.4',
license : 'Apache-2.0 WITH LLVM-exception OR Apache-2.0 OR MIT',
meson_version : '>= 1.7.0',
)
@ -30,6 +30,7 @@ if host_machine.system() == 'linux' or host_machine.system() == 'android'
'--cfg', 'feature="net"',
'--cfg', 'feature="param"',
'--cfg', 'feature="pipe"',
'--cfg', 'feature="thread"',
]
elif host_machine.system() == 'darwin' or host_machine.system() == 'macos'
rustix_args += [

View file

@ -1,6 +1,7 @@
[wrap-file]
directory = rustix-1.1.2
source_url = https://crates.io/api/v1/crates/rustix/1.1.2/download
source_filename = rustix-1.1.2.tar.gz
source_hash = cd15f8a2c5551a84d56efdc1cd049089e409ac19a3072d5037a17fd70719ff3e
directory = rustix-1.1.4
source_url = https://crates.io/api/v1/crates/rustix/1.1.4/download
source_filename = rustix-1.1.4.tar.gz
source_hash = b6fe4565b9518b83ef4f91bb47ce29620ca828bd32cb7e408f0062e9930ba190
patch_directory = rustix-1-rs
diff_files = rustix-1-rs/0001-rustix-add-ioctl-wrappers.patch, rustix-1-rs/0002-rustix-improve-for-musl-build-without-linux-raw-sys.patch, rustix-1-rs/0003-rustix-enable-rustix-thread-futex-without-linux-raw-.patch