From afabf76ec451a6e3d5b2c3486a08254cb501f113 Mon Sep 17 00:00:00 2001 From: Aelin Reidel Date: Sun, 13 Sep 2026 14:15:08 +0200 Subject: [PATCH 01/33] ci: Test riscv64gc-unknown-linux-musl This is a tier 2 with host tools target since 1.99. (backport ) (cherry picked from commit 33a18fd7e82ac7f5c65265885e9b66a19c5f4966) --- .github/workflows/ci.yaml | 4 ++++ Cargo.toml | 2 +- .../riscv64gc-unknown-linux-musl/Dockerfile | 24 +++++++++++++++++++ ci/install-musl.sh | 7 ++++++ ci/verify-build.py | 2 +- 5 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 ci/docker/riscv64gc-unknown-linux-musl/Dockerfile diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index c6685945d7f62..564f33f1c9d3f 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -223,6 +223,10 @@ jobs: env: { TEST_MUSL_V1_2: 1 } artifact-tag: new-musl - target: riscv64gc-unknown-linux-gnu + - target: riscv64gc-unknown-linux-musl + - target: riscv64gc-unknown-linux-musl + env: { TEST_MUSL_V1_2: 1 } + artifact-tag: new-musl - target: s390x-unknown-linux-gnu - target: sparc64-unknown-linux-gnu - target: wasm32-unknown-emscripten diff --git a/Cargo.toml b/Cargo.toml index e0629f11f7bf2..c8eaaadfe6a69 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -52,6 +52,7 @@ targets = [ "powerpc64le-unknown-linux-gnu", "powerpc64le-unknown-linux-musl", "riscv64gc-unknown-linux-gnu", + "riscv64gc-unknown-linux-musl", "s390x-unknown-linux-gnu", "sparcv9-sun-solaris", "x86_64-apple-darwin", @@ -85,7 +86,6 @@ targets = [ "i686-unknown-freebsd", "i686-unknown-linux-musl", "nvptx64-nvidia-cuda", - "riscv64gc-unknown-linux-musl", "sparc64-unknown-linux-gnu", "thumbv7neon-linux-androideabi", "thumbv7neon-unknown-linux-gnueabihf", diff --git a/ci/docker/riscv64gc-unknown-linux-musl/Dockerfile b/ci/docker/riscv64gc-unknown-linux-musl/Dockerfile new file mode 100644 index 0000000000000..6890ff885488b --- /dev/null +++ b/ci/docker/riscv64gc-unknown-linux-musl/Dockerfile @@ -0,0 +1,24 @@ +FROM ubuntu:26.04 + +RUN apt-get update && apt-get install -y --no-install-recommends \ + ca-certificates \ + curl \ + gcc \ + gcc-riscv64-linux-gnu \ + git \ + libc6-dev \ + make \ + patch \ + rsync \ + qemu-user \ + xz-utils + +ARG MUSL_VERSION +COPY . /ci +RUN ci/install-musl.sh riscv64 "$MUSL_VERSION" + +ENV PATH=$PATH:/musl-riscv64/bin:/rust/bin \ + CC_riscv64gc_unknown_linux_musl=musl-gcc \ + CARGO_TARGET_RISCV64GC_UNKNOWN_LINUX_MUSL_LINKER=musl-gcc \ + CARGO_TARGET_RISCV64GC_UNKNOWN_LINUX_MUSL_RUNNER="qemu-riscv64 -L /musl-riscv64" \ + EXTRA_RUSTFLAGS="-Ctarget-feature=+crt-static -Clink-args=-L/musl-riscv64/lib" diff --git a/ci/install-musl.sh b/ci/install-musl.sh index 8627f580facc6..4d2a1ed504291 100755 --- a/ci/install-musl.sh +++ b/ci/install-musl.sh @@ -107,6 +107,13 @@ case ${1} in ./configure --prefix="/musl-${musl_arch}" --enable-wrapper=yes make install -j4 ;; + riscv64) + musl_arch=riscv64 + kernel_arch=riscv + CC=riscv64-linux-gnu-gcc \ + ./configure --prefix="/musl-${musl_arch}" --enable-wrapper=yes + make install -j4 + ;; *) echo "Unknown target arch: \"${1}\"" exit 1 diff --git a/ci/verify-build.py b/ci/verify-build.py index 89e4e58208cc3..7465c9971c1f3 100755 --- a/ci/verify-build.py +++ b/ci/verify-build.py @@ -108,6 +108,7 @@ class TargetResult: Target("powerpc64le-unknown-linux-gnu"), Target("powerpc64le-unknown-linux-musl", min_toolchain=Toolchain.STABLE), Target("riscv64gc-unknown-linux-gnu"), + Target("riscv64gc-unknown-linux-musl", min_toolchain=Toolchain.STABLE), Target("s390x-unknown-linux-gnu"), Target("sparcv9-sun-solaris"), Target("x86_64-apple-darwin"), @@ -141,7 +142,6 @@ class TargetResult: Target("i686-unknown-freebsd"), Target("i686-unknown-linux-musl"), Target("nvptx64-nvidia-cuda", min_toolchain=Toolchain.STABLE), - Target("riscv64gc-unknown-linux-musl", min_toolchain=Toolchain.STABLE), Target("sparc64-unknown-linux-gnu"), Target("thumbv7neon-linux-androideabi", min_toolchain=Toolchain.STABLE), Target("thumbv7neon-unknown-linux-gnueabihf", min_toolchain=Toolchain.STABLE), From 1d24b9fb8cc1a3de70ef4169bf0bd62a731bed87 Mon Sep 17 00:00:00 2001 From: Aelin Reidel Date: Sun, 13 Sep 2026 15:01:58 +0200 Subject: [PATCH 02/33] musl: riscv64: REG_NARGS does not exist glibc defines this, musl has no idea what it is. (backport ) (cherry picked from commit 6a39a50f5116a423d67d8ddfdf353e8eecafd5d2) --- src/unix/linux_like/linux/musl/b64/riscv64/mod.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/unix/linux_like/linux/musl/b64/riscv64/mod.rs b/src/unix/linux_like/linux/musl/b64/riscv64/mod.rs index 863003fe7ba5a..02881d76b32c7 100644 --- a/src/unix/linux_like/linux/musl/b64/riscv64/mod.rs +++ b/src/unix/linux_like/linux/musl/b64/riscv64/mod.rs @@ -642,4 +642,3 @@ pub const REG_S0: usize = 8; pub const REG_S1: usize = 9; pub const REG_A0: usize = 10; pub const REG_S2: usize = 18; -pub const REG_NARGS: usize = 8; From 68a55b4ff230ae749245189f31ce3ad6a32c3864 Mon Sep 17 00:00:00 2001 From: Aelin Reidel Date: Sun, 13 Sep 2026 15:02:16 +0200 Subject: [PATCH 03/33] musl: riscv64: Remove REG_* definitions gated under _GNU_SOURCE See also https://git.musl-libc.org/cgit/musl/tree/arch/riscv64/bits/signal.h#n38 (backport ) (cherry picked from commit ecb0e0d0476bef1ec0ceab7929ad3ea5cf909173) --- src/unix/linux_like/linux/musl/b64/riscv64/mod.rs | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/unix/linux_like/linux/musl/b64/riscv64/mod.rs b/src/unix/linux_like/linux/musl/b64/riscv64/mod.rs index 02881d76b32c7..b6e34d73edb8d 100644 --- a/src/unix/linux_like/linux/musl/b64/riscv64/mod.rs +++ b/src/unix/linux_like/linux/musl/b64/riscv64/mod.rs @@ -634,11 +634,3 @@ pub const TOSTOP: crate::tcflag_t = 0x00000100; pub const FLUSHO: crate::tcflag_t = 0x00001000; pub const NGREG: usize = 32; -pub const REG_PC: usize = 0; -pub const REG_RA: usize = 1; -pub const REG_SP: usize = 2; -pub const REG_TP: usize = 4; -pub const REG_S0: usize = 8; -pub const REG_S1: usize = 9; -pub const REG_A0: usize = 10; -pub const REG_S2: usize = 18; From 122fce14c3e032ad4e1536813f8d23700630bafa Mon Sep 17 00:00:00 2001 From: Aelin Reidel Date: Sun, 13 Sep 2026 15:02:31 +0200 Subject: [PATCH 04/33] musl: riscv64: Fix name of uc_flags field in ucontext_t https://git.musl-libc.org/cgit/musl/tree/arch/riscv64/bits/signal.h#n67 (backport ) (cherry picked from commit 4086aaf3c4859216d1d9fa3a1d36febb8bd88063) --- src/unix/linux_like/linux/musl/b64/riscv64/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/unix/linux_like/linux/musl/b64/riscv64/mod.rs b/src/unix/linux_like/linux/musl/b64/riscv64/mod.rs index b6e34d73edb8d..df47e81076b31 100644 --- a/src/unix/linux_like/linux/musl/b64/riscv64/mod.rs +++ b/src/unix/linux_like/linux/musl/b64/riscv64/mod.rs @@ -63,7 +63,7 @@ s! { s_no_extra_traits! { pub struct ucontext_t { - pub __uc_flags: c_ulong, + pub uc_flags: c_ulong, pub uc_link: *mut ucontext_t, pub uc_stack: crate::stack_t, pub uc_sigmask: crate::sigset_t, From 72a86ef21b67bf3084aae558854a86944f6e0715 Mon Sep 17 00:00:00 2001 From: Aelin Reidel Date: Sun, 13 Sep 2026 15:07:49 +0200 Subject: [PATCH 05/33] musl: riscv64: Fix definition of ipc_perm riscv64 musl uses the generic definition of ipc_perm found here: https://git.musl-libc.org/cgit/musl/tree/arch/generic/bits/ipc.h (backport ) (cherry picked from commit 49863e1752024f2fcd43aa67d0084083356708ec) --- src/unix/linux_like/linux/musl/b64/riscv64/mod.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/unix/linux_like/linux/musl/b64/riscv64/mod.rs b/src/unix/linux_like/linux/musl/b64/riscv64/mod.rs index df47e81076b31..2d346317ff0da 100644 --- a/src/unix/linux_like/linux/musl/b64/riscv64/mod.rs +++ b/src/unix/linux_like/linux/musl/b64/riscv64/mod.rs @@ -37,12 +37,10 @@ s! { pub gid: crate::gid_t, pub cuid: crate::uid_t, pub cgid: crate::gid_t, - pub mode: c_ushort, - __pad1: Padding, - pub __seq: c_ushort, - __pad2: Padding, - __unused1: Padding, - __unused2: Padding, + pub mode: crate::mode_t, + pub __ipc_perm_seq: c_int, + __pad1: Padding, + __pad2: Padding, } #[repr(align(8))] From 47747f1336369ed5bc88d73506fd0fd0447ae209 Mon Sep 17 00:00:00 2001 From: Aelin Reidel Date: Sun, 13 Sep 2026 15:12:51 +0200 Subject: [PATCH 06/33] musl: riscv64: Add SYS_futex_waitv https://git.musl-libc.org/cgit/musl/tree/arch/riscv64/bits/syscall.h.in#n305 (backport ) (cherry picked from commit 00f5e5c126a6e9224f07fbe1f41253bb3149b9ad) --- src/unix/linux_like/linux/musl/b64/riscv64/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/unix/linux_like/linux/musl/b64/riscv64/mod.rs b/src/unix/linux_like/linux/musl/b64/riscv64/mod.rs index 2d346317ff0da..210b453349e8a 100644 --- a/src/unix/linux_like/linux/musl/b64/riscv64/mod.rs +++ b/src/unix/linux_like/linux/musl/b64/riscv64/mod.rs @@ -397,6 +397,7 @@ pub const SYS_mount_setattr: c_long = 442; pub const SYS_landlock_create_ruleset: c_long = 444; pub const SYS_landlock_add_rule: c_long = 445; pub const SYS_landlock_restrict_self: c_long = 446; +pub const SYS_futex_waitv: c_long = 449; pub const O_APPEND: c_int = 1024; pub const O_DIRECT: c_int = 0x4000; From c3bf7a4851c72c50f4342c81ec18ca08c845da6a Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Thu, 17 Sep 2026 04:01:30 -0400 Subject: [PATCH 07/33] musl: riscv64: Fix the name of `__riscv_mc_q_ext_state.__reserved` The musl implementation doesn't call it `__glibc_reserved`. [ note: I also marked this field private to match `main` since it's a more recent target, and nobody should be accessing it anyway - Trevor ] (backport ) (cherry picked from commit 35c8b7d847f64265cb578343dc5d1be467fe63db) --- src/unix/linux_like/linux/musl/b64/riscv64/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/unix/linux_like/linux/musl/b64/riscv64/mod.rs b/src/unix/linux_like/linux/musl/b64/riscv64/mod.rs index 210b453349e8a..5cbcb717fb055 100644 --- a/src/unix/linux_like/linux/musl/b64/riscv64/mod.rs +++ b/src/unix/linux_like/linux/musl/b64/riscv64/mod.rs @@ -94,7 +94,7 @@ s_no_extra_traits! { pub struct __riscv_mc_q_ext_state { pub __f: [c_ulonglong; 64], pub __fcsr: c_uint, - pub __glibc_reserved: [c_uint; 3], + __reserved: Padding<[c_uint; 3]>, } } From 8824255ec034a080e736643841fdafe080fa944c Mon Sep 17 00:00:00 2001 From: Adam Martinez <149513579+dybucc@users.noreply.github.com> Date: Sun, 20 Sep 2026 11:38:10 +0200 Subject: [PATCH 08/33] ci: skip aix targets Skip AIX targets from CI tests while rust-lang/rust#162979 gets sorted out. (backport ) (cherry picked from commit d770f3e518be836e318d12593134844b4d5f9eab) --- ci/verify-build.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ci/verify-build.py b/ci/verify-build.py index 7465c9971c1f3..9d9ed6083d5a5 100755 --- a/ci/verify-build.py +++ b/ci/verify-build.py @@ -192,7 +192,8 @@ class TargetResult: Target("powerpc-unknown-netbsd", dist=False), Target("powerpc-wrs-vxworks", dist=False), Target("powerpc-wrs-vxworks-spe", dist=False), - Target("powerpc64-ibm-aix", dist=False), + # FIXME(rust-lang/rust#162979) + # Target("powerpc64-ibm-aix", dist=False), Target("powerpc64-unknown-freebsd", dist=False), Target("powerpc64-unknown-linux-gnuelfv2", dist=False), Target("powerpc64-wrs-vxworks", dist=False), From 0d6e222b0ae2fba90348e53cb8061b89193a5b0d Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Sun, 20 Sep 2026 16:26:51 -0500 Subject: [PATCH 09/33] uclibc: Replace `linux_time_bits64` with a new `uclibc32_time64` cfg `linux_time_bits64` should correlate to the kernel's `__USE_TIME_BITS64`, which is set on both 32- and 64-bit platforms where `time_t` is 64 bits. The uclibc version of this config is `UCLIBC_USE_TIME64` which is only set on 32-bit platforms. Split this up by introducing `uclibc32_time64` to closer match `UCLIBC_USE_TIME64`. As an effect, setting `libc_unstable_uclibc_time64` no longer crashes builds for 64-bit uclibc targets. The setup also closer matches what is done for GNU targets. Note that `linux_time_bits64` is not actually the "64-bit time_t on any platform" yet that the kernel's version is, so it still isn't set on 64-bit platforms after this change. * `UCLIBC_USE_TIME64` definition: https://github.com/wbx-github/uclibc-ng/blob/3f2ef085d8455a13fcdc4d4d473c0385dd65d55e/extra/Configs/Config.in#L1036-L1055 * Implication of `__USE_TIME_BITS64`: https://github.com/wbx-github/uclibc-ng/blob/3f2ef085d8455a13fcdc4d4d473c0385dd65d55e/include/features.h#L458-L460 * Entrypoint for 64-bit `time_t`: https://github.com/wbx-github/uclibc-ng/blob/3f2ef085d8455a13fcdc4d4d473c0385dd65d55e/libc/sysdeps/linux/common/bits/typesizes.h#L50-L54 * Arm `struct shimd_ds`: https://github.com/wbx-github/uclibc-ng/blob/3f2ef085d8455a13fcdc4d4d473c0385dd65d55e/libc/sysdeps/linux/arm/bits/shm.h#L48-L69 (backport ) (cherry picked from commit 3de6a1a1e6d29536f785bc8991db8269eb29c88b) --- build.rs | 32 +++++++++++++++++---- libc-test/build/main.rs | 8 ++++-- src/unix/linux_like/linux/uclibc/arm/mod.rs | 6 ++-- src/unix/linux_like/linux/uclibc/mod.rs | 2 +- 4 files changed, 36 insertions(+), 12 deletions(-) diff --git a/build.rs b/build.rs index 7da580c94ecbb..47d74cff2febb 100644 --- a/build.rs +++ b/build.rs @@ -54,6 +54,9 @@ enum Cfg { /// transition to 64-bit `time_t` and thus need `__*_time64` redirects. Implies `musl_v1_2` /// and 32-bit arch. MuslRedirTime64, + /// Corresponds to the `UCLIBC_USE_TIME64` config / `__UCLIBC_USE_TIME64__` define. Indicates + /// that `*time64` syscalls should be used. Implies 32-bit. + Uclibc32Time64, } const ALLOWED_CFGS: &[Cfg] = &[ @@ -76,6 +79,7 @@ const ALLOWED_CFGS: &[Cfg] = &[ Cfg::MuslV1_2, Cfg::Musl32Time64, Cfg::MuslRedirTime64, + Cfg::Uclibc32Time64, ]; impl fmt::Display for Cfg { @@ -100,6 +104,7 @@ impl fmt::Display for Cfg { Cfg::MuslV1_2 => "musl_v1_2", Cfg::Musl32Time64 => "musl32_time64", Cfg::MuslRedirTime64 => "musl_redir_time64", + Cfg::Uclibc32Time64 => "uclibc32_time64", }) } } @@ -267,12 +272,6 @@ fn main() { } } - let uclibc_time64_env = env_flag("CARGO_CFG_LIBC_UNSTABLE_UCLIBC_TIME64"); - let uclibc_time64 = target_env == "uclibc" && uclibc_time64_env; - if uclibc_time64 { - cfgs.push(Cfg::LinuxTimeBits64); - } - let mut gnu_tb_env = env::var("CARGO_CFG_LIBC_UNSTABLE_GNU_TIME_BITS"); // FIXME: remove these fallbacks in a few releases @@ -319,6 +318,17 @@ fn main() { cfgs.push(Cfg::GnuTimeBits64); } + let uclibc_time64_env = env_flag("CARGO_CFG_LIBC_UNSTABLE_UCLIBC_TIME64"); + let uclibc = target_env == "uclibc"; + let uclibc32_time64 = uclibc && target_ptr_width == "32" && uclibc_time64_env; + + if uclibc32_time64 { + if target_os == "linux" { + cfgs.push(Cfg::LinuxTimeBits64); + } + cfgs.push(Cfg::Uclibc32Time64); + } + // On CI: deny all warnings if libc_ci { cfgs.push(Cfg::LibcDenyWarnings); @@ -497,6 +507,16 @@ fn validate_cfg(list: &[Cfg], target_env: &str, target_os: &str, target_ptr_widt "{cfg:?} set on non-musl1.2 platform" ) } + Cfg::Uclibc32Time64 => { + assert_eq!(target_env, "uclibc", "{cfg:?} set on non-gnu platform"); + assert_eq!(target_ptr_width, "32", "{cfg:?} set on non-32-bit platform"); + if target_os == "linux" { + assert!( + list.contains(&Cfg::LinuxTimeBits64), + "missing 64-bit time_t Linux config" + ) + } + } } } } diff --git a/libc-test/build/main.rs b/libc-test/build/main.rs index f97a0e7d13c5a..1d3c40a142596 100755 --- a/libc-test/build/main.rs +++ b/libc-test/build/main.rs @@ -4135,10 +4135,14 @@ fn test_linux(t: &Target) { } } - let uclibc_use_time64 = env_flag("CARGO_CFG_LIBC_UNSTABLE_UCLIBC_TIME64"); - if uclibc && uclibc_use_time64 { + let uclibc_time64_env = env_flag("CARGO_CFG_LIBC_UNSTABLE_UCLIBC_TIME64"); + let uclibc32_time64 = uclibc && p32 && uclibc_time64_env; + + if uclibc32_time64 { cfg.cfg("linux_time_bits64", None); + cfg.cfg("uclibc32_time64", None); } + cfg.define("_GNU_SOURCE", None) // This macro re-defines fscanf,scanf,sscanf to link to the symbols that are // deprecated since glibc >= 2.29. This allows Rust binaries to link against diff --git a/src/unix/linux_like/linux/uclibc/arm/mod.rs b/src/unix/linux_like/linux/uclibc/arm/mod.rs index 948f9aeda1331..9314ac4a7720b 100644 --- a/src/unix/linux_like/linux/uclibc/arm/mod.rs +++ b/src/unix/linux_like/linux/uclibc/arm/mod.rs @@ -220,13 +220,13 @@ s! { pub shm_perm: crate::ipc_perm, pub shm_segsz: size_t, pub shm_atime: crate::time_t, - #[cfg(not(linux_time_bits64))] + #[cfg(not(uclibc32_time64))] __unused1: Padding, pub shm_dtime: crate::time_t, - #[cfg(not(linux_time_bits64))] + #[cfg(not(uclibc32_time64))] __unused2: Padding, pub shm_ctime: crate::time_t, - #[cfg(not(linux_time_bits64))] + #[cfg(not(uclibc32_time64))] __unused3: Padding, pub shm_cpid: crate::pid_t, pub shm_lpid: crate::pid_t, diff --git a/src/unix/linux_like/linux/uclibc/mod.rs b/src/unix/linux_like/linux/uclibc/mod.rs index 39964530e2f06..51a97f16ad317 100644 --- a/src/unix/linux_like/linux/uclibc/mod.rs +++ b/src/unix/linux_like/linux/uclibc/mod.rs @@ -14,7 +14,7 @@ pub type __priority_which_t = c_uint; cfg_if! { // Set `--cfg=libc_unstable_uclibc_time64` in RUSTFLAGS if your uClibc has 64-bit `time_t`. - if #[cfg(linux_time_bits64)] { + if #[cfg(uclibc32_time64)] { pub type time_t = i64; pub type suseconds_t = i64; } else { From 187fedda8ca6b3a0a6f85d063bcba49cef6525ce Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Sun, 20 Sep 2026 16:40:45 -0500 Subject: [PATCH 10/33] ci: Check building uclibc with `libc_unstable_uclibc_time64` (backport ) (cherry picked from commit 9b0c6f2efc0d5514de7dcd839035eaeb63c11b70) --- ci/verify-build.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ci/verify-build.py b/ci/verify-build.py index 9d9ed6083d5a5..b626742c192fb 100755 --- a/ci/verify-build.py +++ b/ci/verify-build.py @@ -421,6 +421,10 @@ def test_target(cfg: Cfg, target: Target) -> TargetResult: # Check with breaking changes from musl, including 64-bit time_t on 32-bit run(cmd, rustflags=f"{rustflags} --cfg=libc_unstable_musl_v1_2") + if "uclibc" in target_env: + # Equivalent of UCLIBC_USE_TIME64 on 32-bit targets, ignored on 64-bit + run(cmd, rustflags=f"{rustflags} --cfg=libc_unstable_uclibc_time64") + # Test again without default features, i.e. without `std` run([*cmd, "--no-default-features"], rustflags=rustflags) run([*cmd, "--no-default-features", "--features=extra_traits"], rustflags=rustflags) From d2d065be787d900972f39963a84c835f62dac0b2 Mon Sep 17 00:00:00 2001 From: Adam Martinez <149513579+dybucc@users.noreply.github.com> Date: Fri, 14 Aug 2026 08:35:51 +0200 Subject: [PATCH 11/33] crate: expose `cfg` for general time64 Add `cfg` enabling `time64` functionality across all supported targets. This ensures users have a simple entry point to the crate functionality gated behind one of `linux_time_bits64`, `uclibc_time64` and `gnu_time_bits64`. The new `cfg` goes by the name `libc_unstable_time64`. (backport ) (cherry picked from commit 9a1b7f8172e989a34b4dc235eb1c9f3961dbe739) --- build.rs | 9 ++++++--- libc-test/build/main.rs | 15 ++++++++++----- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/build.rs b/build.rs index 47d74cff2febb..52c37fe35b8a9 100644 --- a/build.rs +++ b/build.rs @@ -256,9 +256,12 @@ fn main() { || target_env == "ohos" || target_abi == "pauthtest"; + // Single entry-point to enable `time64` on supported platforms. + let time64 = env_flag("CARGO_CFG_LIBC_UNSTABLE_TIME64"); + // OpenHarmony uses a fork of the musl libc let musl = target_env == "musl" || target_env == "ohos"; - let musl_v1_2 = musl && (musl_v1_2_env || only_v1_2_on_musl); + let musl_v1_2 = musl && (musl_v1_2_env || only_v1_2_on_musl || time64); if musl_v1_2 { cfgs.push(Cfg::MuslV1_2); @@ -306,7 +309,7 @@ fn main() { || target_arch == "x86_64" || !matches!(target_os.as_str(), "linux" | "windows" | "hurd"); let gnu = target_env == "gnu"; - let gnu32_time64 = gnu && target_ptr_width == "32" && gnu32_timebits == "64"; + let gnu32_time64 = gnu && target_ptr_width == "32" && (gnu32_timebits == "64" || time64); if gnu32_time64 && !gnu32_already_time64 { // These configs all set up nonstandard options. They are not needed on platforms like @@ -320,7 +323,7 @@ fn main() { let uclibc_time64_env = env_flag("CARGO_CFG_LIBC_UNSTABLE_UCLIBC_TIME64"); let uclibc = target_env == "uclibc"; - let uclibc32_time64 = uclibc && target_ptr_width == "32" && uclibc_time64_env; + let uclibc32_time64 = uclibc && target_ptr_width == "32" && (uclibc_time64_env || time64); if uclibc32_time64 { if target_os == "linux" { diff --git a/libc-test/build/main.rs b/libc-test/build/main.rs index 1d3c40a142596..257edaccd8be0 100755 --- a/libc-test/build/main.rs +++ b/libc-test/build/main.rs @@ -808,7 +808,8 @@ fn test_windows(t: &Target) { } cfg.define("_WIN32_WINNT", Some("0x8000")); - let win_gnu_x86_time64 = match env::var("CARGO_CFG_LIBC_UNSTABLE_GNU_TIME_BITS") { + let time64 = env_flag("CARGO_CFG_LIBC_UNSTABLE_TIME64"); + let mut win_gnu_x86_time64 = match env::var("CARGO_CFG_LIBC_UNSTABLE_GNU_TIME_BITS") { Ok(v) if v == "64" => true, Ok(v) if v == "32" => false, Ok(_) => { @@ -816,6 +817,7 @@ fn test_windows(t: &Target) { } Err(_) => false, }; + win_gnu_x86_time64 |= time64; // Needed for the Windows `time_t` test. println!("cargo::rustc-check-cfg=cfg(gnu_time_bits64)"); @@ -4017,6 +4019,7 @@ fn config_gnu_bits(t: &Target, cfg: &mut ctest::TestGenerator) { if t.gnu() && t.linux() && !t.x32() && !t.riscv32() && t.pointer_width == P32 { let defaultbits = "32"; let mut tb_env = env::var("CARGO_CFG_LIBC_UNSTABLE_GNU_TIME_BITS"); + let time64 = env_flag("CARGO_CFG_LIBC_UNSTABLE_TIME64"); // FIXME: remove these fallbacks in a few releases if let Ok(old_tb_env) = env::var("RUST_LIBC_UNSTABLE_GNU_TIME_BITS") { @@ -4045,7 +4048,7 @@ fn config_gnu_bits(t: &Target, cfg: &mut ctest::TestGenerator) { } }; - if timebits == "64" { + if timebits == "64" || time64 { cfg.define("_TIME_BITS", Some("64")); cfg.define("_FILE_OFFSET_BITS", Some("64")); cfg.cfg("linux_time_bits64", None); @@ -4110,13 +4113,15 @@ fn test_linux(t: &Target) { None => panic!("failed to detect kernel version for Linux target {t:?}",), }; + let time64 = env_flag("CARGO_CFG_LIBC_UNSTABLE_TIME64"); + let mut musl_v1_2 = env_flag("CARGO_CFG_LIBC_UNSTABLE_MUSL_V1_2"); if musl_v1_2 { assert!(musl); } // Some platforms only exist with recent musl. Keep in sync with libc's build.rs. - if musl && (loongarch64 || hexagon || pauthtest/* || ohos */) { + if musl && (loongarch64 || hexagon || pauthtest/* || ohos */ || time64) { musl_v1_2 = true; } @@ -4124,7 +4129,7 @@ fn test_linux(t: &Target) { let mut cfg = ctest_cfg(); - if musl_v1_2 { + if musl && musl_v1_2 { cfg.cfg("musl_v1_2", None); if p32 { cfg.cfg("musl32_time64", None); @@ -4136,7 +4141,7 @@ fn test_linux(t: &Target) { } let uclibc_time64_env = env_flag("CARGO_CFG_LIBC_UNSTABLE_UCLIBC_TIME64"); - let uclibc32_time64 = uclibc && p32 && uclibc_time64_env; + let uclibc32_time64 = uclibc && p32 && (uclibc_time64_env || time64); if uclibc32_time64 { cfg.cfg("linux_time_bits64", None); From 94ce88c7c721eda9b187a3ce1e46cfba061d3e18 Mon Sep 17 00:00:00 2001 From: Adam Martinez <149513579+dybucc@users.noreply.github.com> Date: Sat, 29 Aug 2026 09:18:08 +0200 Subject: [PATCH 12/33] ci: make prevalent use of time64 `cfg` Switch as many uses of other target-specific `cfg`s with the `time64` `cfg` introduced in the prior patch. (backport ) (cherry picked from commit 39f6b9bc73e2345e09d437fc6c1500b051b1efc9) --- ci/run-docker.sh | 2 +- ci/run.sh | 2 +- ci/verify-build.py | 15 ++++++++------- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/ci/run-docker.sh b/ci/run-docker.sh index 9597ff1f3ca5a..9127e9a798909 100755 --- a/ci/run-docker.sh +++ b/ci/run-docker.sh @@ -51,7 +51,7 @@ run() { if [ -n "${TEST_UCLIBC_TIME64:-}" ]; then build_args+=("--build-arg=TEST_UCLIBC_TIME64=1") - RUSTFLAGS="$RUSTFLAGS --cfg=libc_unstable_uclibc_time64" + RUSTFLAGS="$RUSTFLAGS --cfg=libc_unstable_time64" fi if [[ "$run_target" = *-linux-uclibc* ]]; then if [ "${UCLIBC_TOOLCHAIN_URL:-}" ]; then diff --git a/ci/run.sh b/ci/run.sh index 9c9775f498326..711751ed2be58 100755 --- a/ci/run.sh +++ b/ci/run.sh @@ -52,5 +52,5 @@ $cmd --features extra_traits -- $test_flags if [ "$env" = "gnu" ] && [ "$bits" = "32" ]; then # shellcheck disable=SC2086 - RUSTFLAGS="$RUSTFLAGS --cfg=libc_unstable_gnu_time_bits=\"64\"" $cmd -- $test_flags + RUSTFLAGS="$RUSTFLAGS --cfg=libc_unstable_time64" $cmd -- $test_flags fi diff --git a/ci/verify-build.py b/ci/verify-build.py index b626742c192fb..757222c9ce4c0 100755 --- a/ci/verify-build.py +++ b/ci/verify-build.py @@ -413,13 +413,14 @@ def test_target(cfg: Cfg, target: Target) -> TargetResult: run(cmd, rustflags=rustflags) run([*cmd, "--features=extra_traits"], rustflags=rustflags) - if "gnu" in target_env and target_bits == "32": - # Equivalent of _TIME_BITS=64 - run(cmd, rustflags=f'{rustflags} --cfg=libc_unstable_gnu_time_bits="64"') - - if "musl" in target_env: - # Check with breaking changes from musl, including 64-bit time_t on 32-bit - run(cmd, rustflags=f"{rustflags} --cfg=libc_unstable_musl_v1_2") + if ( + ("gnu" in target_env and target_bits == "32") + or "musl" in target_env + or "uclibc" in target_env + ): + # Global toggle for `_TIME_BITS=64` on glibc, musl breaking changes and + # uClibc buil-time options concerning 64-bit `time_t`. + run(cmd, rustflags=f"{rustflags} --cfg=libc_unstable_time64") if "uclibc" in target_env: # Equivalent of UCLIBC_USE_TIME64 on 32-bit targets, ignored on 64-bit From 6492fede48da837ac6a752c6f224e127c5e0263e Mon Sep 17 00:00:00 2001 From: Adam Martinez <149513579+dybucc@users.noreply.github.com> Date: Tue, 1 Sep 2026 16:49:01 +0200 Subject: [PATCH 13/33] ci: format yaml - Change indentation of two YAML arrays to consistently appear as nested within the key that corresponds with the array. - Change one inconsistent use of single quotes with double quotes for YAML strings. (backport ) (cherry picked from commit 76f110d49350d9dd20c216b5acdd43292170bbb2) --- .github/workflows/ci.yaml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 564f33f1c9d3f..d205c5945449d 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -67,7 +67,7 @@ jobs: - toolchain: nightly half: 2 - toolchain: beta - only: '(aarch64|x86_64)' # just a spot check for beta + only: "(aarch64|x86_64)" # just a spot check for beta - toolchain: stable - toolchain: 1.65.0 # msrv runs-on: ubuntu-26.04 @@ -384,14 +384,14 @@ jobs: runs-on: ubuntu-26.04 timeout-minutes: 10 steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - with: - persist-credentials: false - - name: Install Rust - # FIXME(rust-lang/rust#160439): unpin once the issue is fixed - run: rustup update nightly-2026-08-02 --no-self-update && rustup default nightly-2026-08-02 - - uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2.9.2 - - run: cargo doc --workspace --no-deps + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - name: Install Rust + # FIXME(rust-lang/rust#160439): unpin once the issue is fixed + run: rustup update nightly-2026-08-02 --no-self-update && rustup default nightly-2026-08-02 + - uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2.9.2 + - run: cargo doc --workspace --no-deps zizmor: name: Zizmor (Static analysis for GitHub Actions) From b28c81fc19b503655fe7edbcef8b7a64ab8c176f Mon Sep 17 00:00:00 2001 From: Adam Martinez <149513579+dybucc@users.noreply.github.com> Date: Thu, 10 Sep 2026 14:10:39 +0200 Subject: [PATCH 14/33] ci: use `TEST_MUSL_V1_2` in powerpc runs Replace use of `RUST_LIBC_UNSTABLE_MUSL_V1_2` with `TEST_MUSL_V1_2` in the PowerPC CI runs. The former is deprecated; The latter is used in CI scripts to set the right unstable `cfg` for functionality gated behind musl's v1.2. (backport ) (cherry picked from commit dde449d069c607c67b22159c1e9e069ac2526dca) --- .github/workflows/ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index d205c5945449d..3d2b7e05a41d3 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -215,7 +215,7 @@ jobs: - target: powerpc64-unknown-linux-gnu - target: powerpc64-unknown-linux-musl - target: powerpc64-unknown-linux-musl - env: { RUST_LIBC_UNSTABLE_MUSL_V1_2: 1 } + env: { TEST_MUSL_V1_2: 1 } artifact-tag: new-musl - target: powerpc64le-unknown-linux-gnu - target: powerpc64le-unknown-linux-musl From e9e6e9cb70cff5716647799c20215b14582d6951 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Sun, 20 Sep 2026 19:59:34 -0500 Subject: [PATCH 15/33] ci: Drop `du` commands that are no longer needed (backport ) (cherry picked from commit 21e32ef0a4e88a5268841a53c99e32510ef493af) --- .github/workflows/ci.yaml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 3d2b7e05a41d3..1d4e16efe0c38 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -91,14 +91,9 @@ jobs: if: matrix.toolchain == 'stable' run: ./ci/prep-semver-baseline.sh - # FIXME(ci): These `du` statements are temporary for debugging cache - - name: Target size before restoring cache - run: du -sh target | sort -k 2 || true - uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2.9.2 with: key: ${{ matrix.os }}-${{ matrix.toolchain }} - - name: Target size after restoring cache - run: du -sh target | sort -k 2 || true - name: Execute build check run: | @@ -118,8 +113,6 @@ jobs: ${BASELINE_CRATE_DIR:+"--baseline-crate-dir" "$BASELINE_CRATE_DIR"} \ ${{ matrix.only && format('--only "{0}"', matrix.only) }} \ ${{ matrix.half && format('--half "{0}"', matrix.half) }} - - name: Target size after job completion - run: du -sh target | sort -k 2 test_tier1: name: Test tier1 From f3576d4e8ecd11c6065bdbc727c19ab675e1739a Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Sun, 20 Sep 2026 20:11:52 -0500 Subject: [PATCH 16/33] test: Skip `AT_HANDLE_FID` for kernel < 6.5 and glibc < 2.39 Make the skip more accurate to cover ppc32 as well. Link: https://github.com/torvalds/linux/commit/96b2b072ee62be8ae68c8ecf14854c4d0505a8f8 Link: https://github.com/sailfishos-mirror/glibc/commit/2399ab0d2076b485aa81855e048a7a44d3c12eaa (backport ) (cherry picked from commit a8738a8db1d09755d25170e716e2b26a75931e3b) --- libc-test/build/main.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/libc-test/build/main.rs b/libc-test/build/main.rs index 257edaccd8be0..327b5ce1dc843 100755 --- a/libc-test/build/main.rs +++ b/libc-test/build/main.rs @@ -4083,7 +4083,6 @@ fn test_linux(t: &Target) { } let arm32 = t.arm32(); - let eabihf = t.eabihf(); let aarch64 = t.aarch64(); let ppc = t.ppc(); let ppc64 = t.ppc64(); @@ -4112,6 +4111,7 @@ fn test_linux(t: &Target) { None if l4re => (0, 0), None => panic!("failed to detect kernel version for Linux target {t:?}",), }; + let glibc = versions.glibc; let time64 = env_flag("CARGO_CFG_LIBC_UNSTABLE_TIME64"); @@ -5000,6 +5000,10 @@ fn test_linux(t: &Target) { "PTRACE_SET_SYSCALL_INFO" => kernel < (6, 16), "TLS_INFO_TX_MAX_PAYLOAD_LEN" | "TLS_INFO_MAX" => kernel < (6, 19), + // Available in fcntl since kernel 6.5 but we don't import that header, so can only + // get it via recent glibc. + "AT_HANDLE_FID" => kernel < (6, 5) || glibc.is_some_and(|v| v < (2, 39)) || musl, + // statx mask and attribute bits "STATX_MNT_ID_UNIQUE" => kernel < (6, 8), "STATX_SUBVOL" => kernel < (6, 10), @@ -5019,10 +5023,6 @@ fn test_linux(t: &Target) { } } - // FIXME(musl): This value is not yet in musl. - // eabihf targets are tested using an older version of glibc - "AT_HANDLE_FID" if musl || eabihf => true, - // Added in 7.2 "FUTEX_ROBUST_UNLOCK" => kernel < (7, 2), "FUTEX_ROBUST_LIST32" => kernel < (7, 2), From 45393528867b7fc589b240ea7d65d6ac17a1ac63 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Sun, 20 Sep 2026 20:13:54 -0500 Subject: [PATCH 17/33] test: Skip `PR_MDWE_NO_INHERIT` for kernel < 6.7 Make the skip more accurate to cover ppc32 as well. Link: https://github.com/torvalds/linux/commit/24e41bf8a6b424c76c5902fb999e9eca61bdf83d (backport ) (cherry picked from commit 2cf22d549c9c2f74da7443c578f3333904f51115) --- libc-test/build/main.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/libc-test/build/main.rs b/libc-test/build/main.rs index 327b5ce1dc843..b665ea61561cb 100755 --- a/libc-test/build/main.rs +++ b/libc-test/build/main.rs @@ -4936,9 +4936,6 @@ fn test_linux(t: &Target) { // FIXME(linux32): Requires >= 6.6 kernel headers. "XDP_USE_SG" | "XDP_PKT_CONTD" if p32 => kernel < (6, 6), - // FIXME(linux): Missing only on this platform for some reason - "PR_MDWE_NO_INHERIT" if gnueabihf => true, - // FIXME(musl): Not yet in musl // FIXME(linux32): Requires >= 6.8 kernel headers. "XDP_UMEM_TX_SW_CSUM" @@ -4997,6 +4994,7 @@ fn test_linux(t: &Target) { "AT_HWCAP3" | "AT_HWCAP4" if old_musl => true, "AT_HWCAP3" | "AT_HWCAP4" => kernel < (6, 9), "BCACHEFS_SUPER_MAGIC" => kernel < (6, 10), + "PR_MDWE_NO_INHERIT" => kernel < (6, 7), "PTRACE_SET_SYSCALL_INFO" => kernel < (6, 16), "TLS_INFO_TX_MAX_PAYLOAD_LEN" | "TLS_INFO_MAX" => kernel < (6, 19), From 85d80cfbbdc0c9f8ed2dbc271623231438fff742 Mon Sep 17 00:00:00 2001 From: LoveSy Date: Wed, 23 Sep 2026 08:31:16 +0800 Subject: [PATCH 18/33] android: Fix RISC-V open flag radix Fix incorrect radix of 4 Android/RISCV constants; see: https://android.googlesource.com/platform/bionic/+/731631f300090436d7f5df80d50b6275c8c60a93/libc/kernel/uapi/asm-generic/fcntl.h#40 (backport ) (cherry picked from commit ca9b70f76d1179279b8844fe2f1c85f24a5f6683) --- src/unix/linux_like/android/b64/riscv64/mod.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/unix/linux_like/android/b64/riscv64/mod.rs b/src/unix/linux_like/android/b64/riscv64/mod.rs index 2d68a99b5a73d..b5536ebbb8af8 100644 --- a/src/unix/linux_like/android/b64/riscv64/mod.rs +++ b/src/unix/linux_like/android/b64/riscv64/mod.rs @@ -60,10 +60,10 @@ s_no_extra_traits! { } } -pub const O_DIRECT: c_int = 0x40000; -pub const O_DIRECTORY: c_int = 0x200000; -pub const O_NOFOLLOW: c_int = 0x400000; -pub const O_LARGEFILE: c_int = 0x100000; +pub const O_DIRECT: c_int = 0o40000; +pub const O_DIRECTORY: c_int = 0o200000; +pub const O_NOFOLLOW: c_int = 0o400000; +pub const O_LARGEFILE: c_int = 0o100000; pub const SIGSTKSZ: size_t = 8192; pub const MINSIGSTKSZ: size_t = 2048; From 6e2855d9346d97a1774a4cfedf23b937ad6ca95b Mon Sep 17 00:00:00 2001 From: Yasser-Ameur Date: Sat, 26 Sep 2026 14:36:23 +0200 Subject: [PATCH 19/33] unix: add HOST_NAME_MAX POSIX requires HOST_NAME_MAX in for use with gethostname, and it was missing everywhere except Fuchsia. Added it per family, glibc and uclibc at 64 and the musl-derived and BSD-ish libcs at 255, skipping FreeBSD, NetBSD, DragonFly, Apple, Solaris/illumos and Hurd, which deliberately leave it undefined for sysconf instead. glibc 64: https://github.com/bminor/glibc/blob/04e750e75b73957cf1c791535a3f4319534a52fc/sysdeps/unix/sysv/linux/bits/local_lim.h#L93 uclibc-ng 64: https://github.com/kraj/uclibc-ng/blob/f6f9f40cb17ae95610c4fe36f6ee77cfbcf05df1/libc/sysdeps/linux/common/bits/local_lim.h#L93 musl 255: https://git.musl-libc.org/cgit/musl/tree/include/limits.h?id=5e9972eaef08ccf55dabe254ac829a30329793d3#n56 android bionic 255: https://github.com/aosp-mirror/platform_bionic/blob/731631f300090436d7f5df80d50b6275c8c60a93/libc/include/bits/posix_limits.h#L135 openbsd 255: https://github.com/openbsd/src/blob/78e3ccc2aa1724882faaab7fa2366e535f039976/sys/sys/syslimits.h#L76 haiku 255: https://github.com/haiku/haiku/blob/89141b6857474342330f6205850b59435165187b/headers/posix/limits.h#L35 redox 255: https://github.com/redox-os/relibc/blob/381772ec81fced6d055f0f0ba6fa92c7f3256fbb/src/header/limits/mod.rs#L145 emscripten 255: https://github.com/emscripten-core/emscripten/blob/06e8b0d84d8b409b1b5ee59832948877bda6137e/system/lib/libc/musl/include/limits.h#L63 wasi 255: https://github.com/WebAssembly/wasi-libc/blob/06513b9ae0c1b14ca3010924939c007ed27628a1/libc-top-half/musl/include/limits.h#L56 cygwin 255: https://github.com/cygwin/cygwin/blob/00208dc31e790b8c130f32c4a0528c781fc07328/winsup/cygwin/include/cygwin/limits.h#L22 (backport ) (cherry picked from commit 904efa2ed4e97622151d93baa0520e86e9af2dc4) --- libc-test/semver/android.txt | 1 + libc-test/semver/cygwin.txt | 1 + libc-test/semver/emscripten.txt | 1 + libc-test/semver/linux.txt | 1 + libc-test/semver/openbsd.txt | 1 + libc-test/semver/redox.txt | 1 + libc-test/semver/wasi.txt | 1 + src/unix/bsd/netbsdlike/openbsd/mod.rs | 1 + src/unix/cygwin/mod.rs | 1 + src/unix/haiku/mod.rs | 1 + src/unix/linux_like/android/mod.rs | 1 + src/unix/linux_like/emscripten/mod.rs | 1 + src/unix/linux_like/linux/gnu/mod.rs | 1 + src/unix/linux_like/linux/musl/mod.rs | 1 + src/unix/linux_like/linux/uclibc/mod.rs | 2 ++ src/unix/redox/mod.rs | 1 + src/wasi/mod.rs | 1 + 17 files changed, 18 insertions(+) diff --git a/libc-test/semver/android.txt b/libc-test/semver/android.txt index a29e7ecf7408d..999e4ebe76b51 100644 --- a/libc-test/semver/android.txt +++ b/libc-test/semver/android.txt @@ -731,6 +731,7 @@ GRND_INSECURE GRND_NONBLOCK GRND_RANDOM GRPQUOTA +HOST_NAME_MAX HPFS_SUPER_MAGIC HUGETLBFS_MAGIC HUGETLB_FLAG_ENCODE_SHIFT diff --git a/libc-test/semver/cygwin.txt b/libc-test/semver/cygwin.txt index 6fa71843e3084..fd0b798c74305 100644 --- a/libc-test/semver/cygwin.txt +++ b/libc-test/semver/cygwin.txt @@ -160,6 +160,7 @@ F_UNLCK F_WRLCK GRND_NONBLOCK GRND_RANDOM +HOST_NAME_MAX IFF_BROADCAST IFF_DORMANT IFF_LOOPBACK diff --git a/libc-test/semver/emscripten.txt b/libc-test/semver/emscripten.txt index 879b096a39b14..c532a50d795ca 100644 --- a/libc-test/semver/emscripten.txt +++ b/libc-test/semver/emscripten.txt @@ -18,6 +18,7 @@ EPOLL_CLOEXEC EPOLL_CTL_ADD EPOLL_CTL_DEL EPOLL_CTL_MOD +HOST_NAME_MAX SIGEV_THREAD_ID epoll_create epoll_create1 diff --git a/libc-test/semver/linux.txt b/libc-test/semver/linux.txt index 57b90559426b9..3549123363bd4 100644 --- a/libc-test/semver/linux.txt +++ b/libc-test/semver/linux.txt @@ -1018,6 +1018,7 @@ GLOB_NOSPACE GRND_INSECURE GRND_NONBLOCK GRND_RANDOM +HOST_NAME_MAX HWTSTAMP_FILTER_ALL HWTSTAMP_FILTER_NONE HWTSTAMP_FILTER_NTP_ALL diff --git a/libc-test/semver/openbsd.txt b/libc-test/semver/openbsd.txt index 330f8da09e068..d2f05bfaaf5e1 100644 --- a/libc-test/semver/openbsd.txt +++ b/libc-test/semver/openbsd.txt @@ -260,6 +260,7 @@ GLOB_NOMATCH GLOB_NOSORT GLOB_NOSPACE GLOB_NOSYS +HOST_NAME_MAX HW_BATTERY HW_BATTERY_CHARGEMODE HW_BATTERY_CHARGESTART diff --git a/libc-test/semver/redox.txt b/libc-test/semver/redox.txt index f30f4f9ae6bc6..3102ba75fc53d 100644 --- a/libc-test/semver/redox.txt +++ b/libc-test/semver/redox.txt @@ -104,6 +104,7 @@ EXFULL FILENAME_MAX FIONREAD F_DUPFD_CLOEXEC +HOST_NAME_MAX IMAXBEL IPPROTO_ICMP IPPROTO_IDP diff --git a/libc-test/semver/wasi.txt b/libc-test/semver/wasi.txt index 7fa658bb78021..f9a3ae91f3c10 100644 --- a/libc-test/semver/wasi.txt +++ b/libc-test/semver/wasi.txt @@ -1,6 +1,7 @@ FD_ISSET FD_SET FD_ZERO +HOST_NAME_MAX LC_ALL LC_COLLATE LC_CTYPE diff --git a/src/unix/bsd/netbsdlike/openbsd/mod.rs b/src/unix/bsd/netbsdlike/openbsd/mod.rs index fdf70dffb35ed..3df5365299ed4 100644 --- a/src/unix/bsd/netbsdlike/openbsd/mod.rs +++ b/src/unix/bsd/netbsdlike/openbsd/mod.rs @@ -1253,6 +1253,7 @@ pub const _SC_PHYS_PAGES: c_int = 500; pub const _SC_AVPHYS_PAGES: c_int = 501; pub const _SC_NPROCESSORS_CONF: c_int = 502; pub const _SC_NPROCESSORS_ONLN: c_int = 503; +pub const HOST_NAME_MAX: c_int = 255; pub const FD_SETSIZE: usize = 1024; diff --git a/src/unix/cygwin/mod.rs b/src/unix/cygwin/mod.rs index 6681080e81d66..08a1a81774d34 100644 --- a/src/unix/cygwin/mod.rs +++ b/src/unix/cygwin/mod.rs @@ -907,6 +907,7 @@ pub const PIPE_BUF: usize = 4096; /// Constants may change across releases. See the [usage guidelines](crate#usage-guidelines) /// for details. pub const NGROUPS_MAX: c_int = 1024; +pub const HOST_NAME_MAX: c_int = 255; pub const FILENAME_MAX: c_int = 4096; diff --git a/src/unix/haiku/mod.rs b/src/unix/haiku/mod.rs index ca30428a1667b..c1ef35b04de24 100644 --- a/src/unix/haiku/mod.rs +++ b/src/unix/haiku/mod.rs @@ -939,6 +939,7 @@ pub const RTLD_DEFAULT: *mut c_void = ptr::null_mut(); pub const BUFSIZ: c_uint = 8192; pub const FILENAME_MAX: c_uint = 256; pub const FOPEN_MAX: c_uint = 128; +pub const HOST_NAME_MAX: c_int = 255; pub const L_tmpnam: c_uint = 512; pub const TMP_MAX: c_uint = 32768; diff --git a/src/unix/linux_like/android/mod.rs b/src/unix/linux_like/android/mod.rs index fb63c640bf542..2ab3aab679cb3 100644 --- a/src/unix/linux_like/android/mod.rs +++ b/src/unix/linux_like/android/mod.rs @@ -755,6 +755,7 @@ pub const FALLOC_FL_UNSHARE_RANGE: c_int = 0x40; pub const BUFSIZ: c_uint = 1024; pub const FILENAME_MAX: c_uint = 4096; pub const FOPEN_MAX: c_uint = 20; +pub const HOST_NAME_MAX: c_int = 255; pub const POSIX_FADV_DONTNEED: c_int = 4; pub const POSIX_FADV_NOREUSE: c_int = 5; pub const POSIX_SPAWN_RESETIDS: c_short = 1; diff --git a/src/unix/linux_like/emscripten/mod.rs b/src/unix/linux_like/emscripten/mod.rs index c4c73bfe2202c..36f532574f8eb 100644 --- a/src/unix/linux_like/emscripten/mod.rs +++ b/src/unix/linux_like/emscripten/mod.rs @@ -493,6 +493,7 @@ pub const NOSTR: crate::nl_item = 0x50003; pub const FILENAME_MAX: c_uint = 4096; pub const L_tmpnam: c_uint = 20; +pub const HOST_NAME_MAX: c_int = 255; pub const _PC_LINK_MAX: c_int = 0; pub const _PC_MAX_CANON: c_int = 1; pub const _PC_MAX_INPUT: c_int = 2; diff --git a/src/unix/linux_like/linux/gnu/mod.rs b/src/unix/linux_like/linux/gnu/mod.rs index f46adbbcaaa0f..ca864710efd47 100644 --- a/src/unix/linux_like/linux/gnu/mod.rs +++ b/src/unix/linux_like/linux/gnu/mod.rs @@ -601,6 +601,7 @@ pub const BUFSIZ: c_uint = 8192; pub const TMP_MAX: c_uint = 238328; pub const FOPEN_MAX: c_uint = 16; pub const FILENAME_MAX: c_uint = 4096; +pub const HOST_NAME_MAX: c_int = 64; pub const _CS_GNU_LIBC_VERSION: c_int = 2; pub const _CS_GNU_LIBPTHREAD_VERSION: c_int = 3; pub const _CS_V6_ENV: c_int = 1148; diff --git a/src/unix/linux_like/linux/musl/mod.rs b/src/unix/linux_like/linux/musl/mod.rs index ba04f8d435891..d57fabb431e3b 100644 --- a/src/unix/linux_like/linux/musl/mod.rs +++ b/src/unix/linux_like/linux/musl/mod.rs @@ -518,6 +518,7 @@ pub const BUFSIZ: c_uint = 1024; pub const TMP_MAX: c_uint = 10000; pub const FOPEN_MAX: c_uint = 1000; pub const FILENAME_MAX: c_uint = 4096; +pub const HOST_NAME_MAX: c_int = 255; pub const O_PATH: c_int = 0o10000000; pub const O_EXEC: c_int = 0o10000000; pub const O_SEARCH: c_int = 0o10000000; diff --git a/src/unix/linux_like/linux/uclibc/mod.rs b/src/unix/linux_like/linux/uclibc/mod.rs index 51a97f16ad317..7a8ac3a7ea574 100644 --- a/src/unix/linux_like/linux/uclibc/mod.rs +++ b/src/unix/linux_like/linux/uclibc/mod.rs @@ -202,6 +202,8 @@ pub const IPV6_LEAVE_GROUP: c_int = 21; // Different than Gnu. pub const FILENAME_MAX: c_uint = 4095; +pub const HOST_NAME_MAX: c_int = 64; + pub const PRIO_PROCESS: crate::__priority_which_t = 0; pub const PRIO_PGRP: crate::__priority_which_t = 1; pub const PRIO_USER: crate::__priority_which_t = 2; diff --git a/src/unix/redox/mod.rs b/src/unix/redox/mod.rs index 87f618a8faf4f..51a49dea24e3e 100644 --- a/src/unix/redox/mod.rs +++ b/src/unix/redox/mod.rs @@ -445,6 +445,7 @@ cfg_if! { /// Constants may change across releases. See the [usage guidelines](crate#usage-guidelines) /// for details. pub const PATH_MAX: c_int = 4096; +pub const HOST_NAME_MAX: c_int = 255; // fcntl.h pub const F_GETLK: c_int = 5; diff --git a/src/wasi/mod.rs b/src/wasi/mod.rs index b386ecf696ea4..628ba244a166d 100644 --- a/src/wasi/mod.rs +++ b/src/wasi/mod.rs @@ -547,6 +547,7 @@ pub const _SC_THREAD_ROBUST_PRIO_INHERIT: c_int = 247; pub const _SC_THREAD_ROBUST_PRIO_PROTECT: c_int = 248; pub const _SC_MINSIGSTKSZ: c_int = 249; pub const _SC_SIGSTKSZ: c_int = 250; +pub const HOST_NAME_MAX: c_int = 255; // FIXME(msrv): `addr_of!(EXTERN_STATIC)` is now safe; remove `unsafe` when MSRV >= 1.82 #[allow(unused_unsafe)] From bc8507867e01c768fd3b897c1950611c4fe08bb0 Mon Sep 17 00:00:00 2001 From: xjtu-ctgg <1093656961@qq.com> Date: Fri, 25 Sep 2026 20:57:36 +0800 Subject: [PATCH 20/33] freebsd: add `renameat2` `renameat2` first appeared in FreeBSD 15.1 (freebsd/freebsd-src@28599a1e5f1b), so it is skipped in libc-test while CI runs 14.4 and 15.0. Source: https://github.com/freebsd/freebsd-src/blob/b5f0e7f36afc20bf17e9e955454b445d686cda06/include/stdio.h#L409 (backport ) (cherry picked from commit f9bac8dfd5a908d46519ba8d9a6c020f5b690282) --- libc-test/build/main.rs | 5 +++++ libc-test/semver/freebsd.txt | 1 + src/unix/bsd/freebsdlike/freebsd/mod.rs | 7 +++++++ 3 files changed, 13 insertions(+) diff --git a/libc-test/build/main.rs b/libc-test/build/main.rs index b665ea61561cb..1d03ce07206ff 100755 --- a/libc-test/build/main.rs +++ b/libc-test/build/main.rs @@ -3221,6 +3221,11 @@ fn test_freebsd(t: &Target) { // Those are introduced in FreeBSD 14.1. "kcmp" => true, + // FIXME(freebsd): `renameat2` was introduced in FreeBSD 15.1, and + // `freebsd_ver` only tracks the major version, so skip it until CI + // moves to a release that has it. + "renameat2" if Some(16) > freebsd_ver => true, + _ => false, } }); diff --git a/libc-test/semver/freebsd.txt b/libc-test/semver/freebsd.txt index 5db4e7ef57783..afa4bc555b604 100644 --- a/libc-test/semver/freebsd.txt +++ b/libc-test/semver/freebsd.txt @@ -2337,6 +2337,7 @@ regfree register_t regmatch_t regoff_t +renameat2 rt_metrics rt_msghdr rtprio diff --git a/src/unix/bsd/freebsdlike/freebsd/mod.rs b/src/unix/bsd/freebsdlike/freebsd/mod.rs index 1ef120c056b7b..bb140f219895a 100644 --- a/src/unix/bsd/freebsdlike/freebsd/mod.rs +++ b/src/unix/bsd/freebsdlike/freebsd/mod.rs @@ -5037,6 +5037,13 @@ extern "C" { idx1: c_ulong, idx2: c_ulong, ) -> c_int; + pub fn renameat2( + olddirfd: c_int, + oldpath: *const c_char, + newdirfd: c_int, + newpath: *const c_char, + flags: c_uint, + ) -> c_int; pub fn dlvsym( handle: *mut c_void, symbol: *const c_char, From bb531df394e1e46c4e7041be6b213d1d030b725e Mon Sep 17 00:00:00 2001 From: xjtu-ctgg <1093656961@qq.com> Date: Thu, 24 Sep 2026 16:42:50 +0800 Subject: [PATCH 21/33] ci: use plain seconds for `sleep` in `bsd-prepare.sh` NetBSD's sleep(1) only accepts a number of seconds and rejects `3s` with "usage: sleep seconds". The script runs with `set -e`, so the first failed install exits the script instead of being retried, and the retry loop has never worked on NetBSD. `sleep 3` is the POSIX form, so it works everywhere this script runs. (backport ) (cherry picked from commit a73f8542b37cb0980cf32351998ff503d09efeeb) --- ci/bsd-prepare.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/bsd-prepare.sh b/ci/bsd-prepare.sh index d28e280989fd5..b7e7cae4a9a9f 100755 --- a/ci/bsd-prepare.sh +++ b/ci/bsd-prepare.sh @@ -20,7 +20,7 @@ success=false while [ $count -lt 3 ]; do $deps && success=true || true [ $success = true ] && break - sleep 3s + sleep 3 count=$(( count + 1)) done From ce224981f9fb60ff65d0174b65ffe16d646854b3 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Mon, 21 Sep 2026 01:03:05 +0000 Subject: [PATCH 22/33] Revert "ci: Pin docs toolchain to nightly-2026-08-02" [1] has been fixed. This reverts commit 297152ad0564a528315a19bc528e44545af0d57e. [1]: https://github.com/rust-lang/rust/issues/160439 (backport ) (cherry picked from commit a7522fada1583c4750728196d8e846fd4872e8b7) --- .github/workflows/ci.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 1d4e16efe0c38..1e063889afc5d 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -381,8 +381,7 @@ jobs: with: persist-credentials: false - name: Install Rust - # FIXME(rust-lang/rust#160439): unpin once the issue is fixed - run: rustup update nightly-2026-08-02 --no-self-update && rustup default nightly-2026-08-02 + run: rustup update nightly --no-self-update && rustup default nightly - uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2.9.2 - run: cargo doc --workspace --no-deps From 56a57fbc41f8bcc34901ebfb27b300aa37e9c71e Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Mon, 28 Sep 2026 22:43:45 -0500 Subject: [PATCH 23/33] test: Read FreeBSD version from the headers rather than environment This should match the `freebsd-version` command anyway, but is more consistent with what we do on other platforms. (backport ) (cherry picked from commit 33021a4c76d2bc9847b839f9c45e90f4d784ab62) --- libc-test/build/main.rs | 225 +++++++++++++--------------------------- 1 file changed, 71 insertions(+), 154 deletions(-) diff --git a/libc-test/build/main.rs b/libc-test/build/main.rs index 1d03ce07206ff..b73f76452bd5f 100755 --- a/libc-test/build/main.rs +++ b/libc-test/build/main.rs @@ -2595,38 +2595,13 @@ fn test_android(t: &Target) { fn test_freebsd(t: &Target) { assert!(t.freebsd()); let mut cfg = ctest_cfg(); - - // FIXME: this can be removed in 1-2 releases - println!("cargo:rerun-if-env-changed=RUST_LIBC_UNSTABLE_FREEBSD_VERSION"); - if env::var("RUST_LIBC_UNSTABLE_FREEBSD_VERSION").is_ok() { - println!( - "cargo:warning=RUST_LIBC_UNSTABLE_FREEBSD_VERSION has been removed; set \ - the cfg libc_unstable_freebsd_version via RUSTFLAGS instead" - ); - } - - let freebsd_ver = if let Ok(version) = env::var("CARGO_CFG_LIBC_UNSTABLE_FREEBSD_VERSION") { - let vers = version.parse().unwrap(); - println!("cargo:warning=setting FreeBSD version to {vers}"); - Some(vers) - } else { - match &try_command_output("freebsd-version", &[]) { - Some(s) if s.starts_with("10") => Some(10), - Some(s) if s.starts_with("11") => Some(11), - Some(s) if s.starts_with("12") => Some(12), - Some(s) if s.starts_with("13") => Some(13), - Some(s) if s.starts_with("14") => Some(14), - Some(s) if s.starts_with("15") => Some(15), - Some(_) | None => None, - } - }; - - match freebsd_ver { - Some(12) => cfg.cfg("freebsd12", None), - Some(13) => cfg.cfg("freebsd13", None), - Some(14) => cfg.cfg("freebsd14", None), - Some(15) => cfg.cfg("freebsd15", None), - _ => &mut cfg, + let freebsd = VERSIONS.freebsd.unwrap(); + match freebsd { + (12, _) => cfg.cfg("freebsd12", None), + (13, _) => cfg.cfg("freebsd13", None), + (14, _) => cfg.cfg("freebsd14", None), + (15, _) => cfg.cfg("freebsd15", None), + _ => panic!("unknown FreeBSD version {freebsd:?}"), }; // For sched linux compat fn @@ -2636,9 +2611,9 @@ fn test_freebsd(t: &Target) { // Required for making freebsd11_stat available in the headers cfg.define("_WANT_FREEBSD11_STAT", None); - let freebsd13 = matches!(freebsd_ver, Some(n) if n >= 13); - let freebsd14 = matches!(freebsd_ver, Some(n) if n >= 14); - let freebsd15 = matches!(freebsd_ver, Some(n) if n >= 15); + let freebsd_ge_13 = matches!(freebsd, (n, _) if n >= 13); + let freebsd_ge_14 = matches!(freebsd, (n, _) if n >= 14); + let freebsd_ge_15 = matches!(freebsd, (n, _) if n >= 15); headers!( cfg, @@ -2705,7 +2680,7 @@ fn test_freebsd(t: &Target) { "sys/domainset.h", "sys/eui64.h", "sys/event.h", - (freebsd13, "sys/eventfd.h"), + (freebsd_ge_13, "sys/eventfd.h"), "sys/extattr.h", "sys/file.h", "sys/ioctl.h", @@ -2726,15 +2701,18 @@ fn test_freebsd(t: &Target) { "sys/shm.h", "sys/socket.h", "sys/socketvar.h", - (freebsd15, "sys/ktls.h"), + (freebsd_ge_15, "sys/ktls.h"), "netinet/in_pcb.h", // must be after sys/socketvar.h, sys/ktls.h "sys/stat.h", "sys/statvfs.h", "sys/sysctl.h", "sys/thr.h", "sys/time.h", - (freebsd14 || freebsd15, "sys/timerfd.h"), - (freebsd13 || freebsd14 || freebsd15, "dev/evdev/input.h"), + (freebsd_ge_14 || freebsd_ge_15, "sys/timerfd.h"), + ( + freebsd_ge_13 || freebsd_ge_14 || freebsd_ge_15, + "dev/evdev/input.h" + ), "sys/times.h", "sys/timex.h", "sys/types.h", @@ -2819,30 +2797,20 @@ fn test_freebsd(t: &Target) { match constant.ident() { // These constants were introduced in FreeBSD 13: "F_ADD_SEALS" | "F_GET_SEALS" | "F_SEAL_SEAL" | "F_SEAL_SHRINK" | "F_SEAL_GROW" - | "F_SEAL_WRITE" - if Some(13) > freebsd_ver => - { - true - } + | "F_SEAL_WRITE" => freebsd < (13, 0), // These constants were introduced in FreeBSD 13: - "EFD_CLOEXEC" | "EFD_NONBLOCK" | "EFD_SEMAPHORE" if Some(13) > freebsd_ver => true, + "EFD_CLOEXEC" | "EFD_NONBLOCK" | "EFD_SEMAPHORE" => freebsd < (13, 0), // These constants were introduced in FreeBSD 12: - "AT_RESOLVE_BENEATH" | "O_RESOLVE_BENEATH" if Some(12) > freebsd_ver => true, + "AT_RESOLVE_BENEATH" | "O_RESOLVE_BENEATH" => freebsd < (12, 0), // These constants were introduced in FreeBSD 13: - "O_DSYNC" | "O_PATH" | "O_EMPTY_PATH" | "AT_EMPTY_PATH" if Some(13) > freebsd_ver => { - true - } + "O_DSYNC" | "O_PATH" | "O_EMPTY_PATH" | "AT_EMPTY_PATH" => freebsd < (13, 0), // These aliases were introduced in FreeBSD 13: // (note however that the constants themselves work on any version) - "CLOCK_BOOTTIME" | "CLOCK_REALTIME_COARSE" | "CLOCK_MONOTONIC_COARSE" - if Some(13) > freebsd_ver => - { - true - } + "CLOCK_REALTIME_COARSE" | "CLOCK_MONOTONIC_COARSE" => freebsd < (13, 0), // FIXME(deprecated): These are deprecated - remove in a couple of releases. // These constants were removed in FreeBSD 11 (svn r262489), @@ -2898,10 +2866,10 @@ fn test_freebsd(t: &Target) { // This was changed to 96(0x60) in FreeBSD 13: // https://github.com/freebsd/freebsd/ // commit/06b00ceaa914a3907e4e27bad924f44612bae1d7 - "MINCORE_SUPER" if Some(13) <= freebsd_ver => true, + "MINCORE_SUPER" => freebsd < (13, 0), // Added in FreeBSD 13.0 (r356667) - "GRND_INSECURE" if Some(13) > freebsd_ver => true, + "GRND_INSECURE" => freebsd < (13, 0), // Added in FreeBSD 13.0 (r349609) "PROC_PROTMAX_CTL" @@ -2918,17 +2886,13 @@ fn test_freebsd(t: &Target) { | "PROC_WXMAP_STATUS" | "PROC_WX_MAPPINGS_PERMIT" | "PROC_WX_MAPPINGS_DISALLOW_EXEC" - | "PROC_WXORX_ENFORCE" - if Some(13) > freebsd_ver => - { - true - } + | "PROC_WXORX_ENFORCE" => freebsd < (13, 0), // Added in FreeBSD 13.0 (r367776 and r367287) - "SCM_CREDS2" | "LOCAL_CREDS_PERSISTENT" if Some(13) > freebsd_ver => true, + "SCM_CREDS2" | "LOCAL_CREDS_PERSISTENT" => freebsd < (13, 0), // Added in FreeBSD 14 - "SPACECTL_DEALLOC" if Some(14) > freebsd_ver => true, + "SPACECTL_DEALLOC" => freebsd < (14, 0), // Added in FreeBSD 13. "KERN_PROC_SIGFASTBLK" @@ -2940,42 +2904,26 @@ fn test_freebsd(t: &Target) { | "P2_PROTMAX_ENABLE" | "P2_PROTMAX_DISABLE" | "CTLFLAG_NEEDGIANT" - | "CTL_SYSCTL_NEXTNOSKIP" - if Some(13) > freebsd_ver => - { - true - } - + | "CTL_SYSCTL_NEXTNOSKIP" => freebsd < (13, 0), // Added in freebsd 14. - "IFCAP_MEXTPG" if Some(14) > freebsd_ver => true, + "IFCAP_MEXTPG" => freebsd < (14, 0), // Added in freebsd 13. "IFCAP_TXTLS4" | "IFCAP_TXTLS6" | "IFCAP_VXLAN_HWCSUM" | "IFCAP_VXLAN_HWTSO" - | "IFCAP_TXTLS_RTLMT" | "IFCAP_TXTLS" - if Some(13) > freebsd_ver => - { - true - } + | "IFCAP_TXTLS_RTLMT" | "IFCAP_TXTLS" => freebsd < (13, 0), + // Added in FreeBSD 13. - "PS_FST_TYPE_EVENTFD" if Some(13) > freebsd_ver => true, + "PS_FST_TYPE_EVENTFD" => freebsd < (13, 0), // Added in FreeBSD 14. - "MNT_RECURSE" | "MNT_DEFERRED" if Some(14) > freebsd_ver => true, + "MNT_RECURSE" | "MNT_DEFERRED" => freebsd < (14, 0), // Added in FreeBSD 13. "MNT_EXTLS" | "MNT_EXTLSCERT" | "MNT_EXTLSCERTUSER" | "MNT_NOCOVER" - | "MNT_EMPTYDIR" - if Some(13) > freebsd_ver => - { - true - } + | "MNT_EMPTYDIR" => freebsd < (13, 0), // Added in FreeBSD 14. "PT_COREDUMP" | "PC_ALL" | "PC_COMPRESS" | "PT_GETREGSET" | "PT_SETREGSET" - | "PT_SC_REMOTE" - if Some(14) > freebsd_ver => - { - true - } + | "PT_SC_REMOTE" => freebsd < (14, 0), // Added in FreeBSD 14. "F_KINFO" => true, // FIXME(freebsd): depends how frequent freebsd 14 is updated on CI, this addition went this week only. @@ -2999,11 +2947,7 @@ fn test_freebsd(t: &Target) { | "MFD_HUGE_512MB" | "MFD_HUGE_1GB" | "MFD_HUGE_2GB" - | "MFD_HUGE_16GB" - if Some(13) > freebsd_ver => - { - true - } + | "MFD_HUGE_16GB" => freebsd < (13, 0), // Flags introduced in FreeBSD 14. "TCP_MAXUNACKTIME" @@ -3015,24 +2959,19 @@ fn test_freebsd(t: &Target) { | "TCP_SHARED_CWND_ALLOWED" | "TCP_PROC_ACCOUNTING" | "TCP_USE_CMP_ACKS" - | "TCP_PERF_INFO" - | "TCP_LRD" - if Some(14) > freebsd_ver => - { - true - } + | "TCP_PERF_INFO" => freebsd < (14, 0), // Introduced in FreeBSD 14 then removed ? - "TCP_LRD" if freebsd_ver >= Some(15) => true, + "TCP_LRD" => freebsd.0 != 14, // Added in FreeBSD 14 - "LIO_READV" | "LIO_WRITEV" | "LIO_VECTORED" if Some(14) > freebsd_ver => true, + "LIO_READV" | "LIO_WRITEV" | "LIO_VECTORED" => freebsd < (14, 0), // Added in FreeBSD 13 - "FIOSSHMLPGCNF" if Some(13) > freebsd_ver => true, + "FIOSSHMLPGCNF" => freebsd < (13, 0), // Added in FreeBSD 14 - "IFCAP_NV" if Some(14) > freebsd_ver => true, + "IFCAP_NV" => freebsd < (14, 0), // FIXME(freebsd): Removed in https://reviews.freebsd.org/D38574 and https://reviews.freebsd.org/D38822 // We maybe should deprecate them once a stable release ships them. @@ -3042,33 +2981,29 @@ fn test_freebsd(t: &Target) { "KERN_VNODE" => true, // Added in FreeBSD 14 - "EV_KEEPUDATA" if Some(14) > freebsd_ver => true, + "EV_KEEPUDATA" => freebsd < (14, 0), // Added in FreeBSD 13.2 - "AT_USRSTACKBASE" | "AT_USRSTACKLIM" if Some(13) > freebsd_ver => true, + "AT_USRSTACKBASE" | "AT_USRSTACKLIM" => freebsd < (13, 0), // Added in FreeBSD 14 - "TFD_CLOEXEC" | "TFD_NONBLOCK" | "TFD_TIMER_ABSTIME" | "TFD_TIMER_CANCEL_ON_SET" - if Some(14) > freebsd_ver => - { - true + "TFD_CLOEXEC" | "TFD_NONBLOCK" | "TFD_TIMER_ABSTIME" | "TFD_TIMER_CANCEL_ON_SET" => { + freebsd < (14, 0) } // Added in FreeBSD 14.1 - "KCMP_FILE" | "KCMP_FILEOBJ" | "KCMP_FILES" | "KCMP_SIGHAND" | "KCMP_VM" - if Some(14) > freebsd_ver => - { - true + "KCMP_FILE" | "KCMP_FILEOBJ" | "KCMP_FILES" | "KCMP_SIGHAND" | "KCMP_VM" => { + freebsd < (14, 0) } // FIXME(freebsd): Removed in FreeBSD 15: - "LOCAL_CONNWAIT" if freebsd_ver >= Some(15) => true, + "LOCAL_CONNWAIT" => freebsd >= (15, 0), // FIXME(freebsd): The values has been changed in FreeBSD 15: - "CLOCK_BOOTTIME" if Some(15) <= freebsd_ver => true, + "CLOCK_BOOTTIME" => freebsd < (13, 0) || freebsd >= (15, 0), // Added in FreeBSD 14.0 - "TCP_FUNCTION_ALIAS" if Some(14) > freebsd_ver => true, + "TCP_FUNCTION_ALIAS" => freebsd < (14, 0), // These constants may change or disappear in future OS releases, and they probably // have no legitimate use in applications anyway. @@ -3079,27 +3014,23 @@ fn test_freebsd(t: &Target) { "TCP_PCAP_OUT" | "TCP_PCAP_IN" => true, // Added in FreeBSD 14.2 - "SO_SPLICE" if Some(14) > freebsd_ver => true, + "SO_SPLICE" => freebsd < (14, 2), // FIXME(deprecated): deprecated in 0.2, removed in main "TIOCMGDTRWAIT" | "TIOCMSDTRWAIT" => true, // Added in FreeBSD 15 - "AT_HWCAP3" | "AT_HWCAP4" if Some(15) > freebsd_ver => true, + "AT_HWCAP3" | "AT_HWCAP4" => freebsd < (15, 0), // Added in FreeBSD 15 - "DTYPE_INOTIFY" | "DTYPE_JAILDESC" if Some(15) > freebsd_ver => true, + "DTYPE_INOTIFY" | "DTYPE_JAILDESC" => freebsd < (15, 0), // Added in FreeBSD 15 "PROC_LOGSIGEXIT_CTL" | "PROC_LOGSIGEXIT_STATUS" | "PROC_LOGSIGEXIT_CTL_NOFORCE" | "PROC_LOGSIGEXIT_CTL_FORCE_ENABLE" - | "PROC_LOGSIGEXIT_CTL_FORCE_DISABLE" - if Some(15) > freebsd_ver => - { - true - } + | "PROC_LOGSIGEXIT_CTL_FORCE_DISABLE" => freebsd < (15, 0), _ => false, } @@ -3111,7 +3042,7 @@ fn test_freebsd(t: &Target) { // for now, it doesn't matter too much... "kvm_t" => true, // `eventfd(2)` and things come with it are added in FreeBSD 13 - "eventfd_t" if Some(13) > freebsd_ver => true, + "eventfd_t" => freebsd < (13, 0), _ => false, } @@ -3123,17 +3054,17 @@ fn test_freebsd(t: &Target) { "procstat" => true, // `spacectl_range` was introduced in FreeBSD 14 - "spacectl_range" if Some(14) > freebsd_ver => true, + "spacectl_range" => freebsd < (14, 0), // `ptrace_coredump` introduced in FreeBSD 14. - "ptrace_coredump" if Some(14) > freebsd_ver => true, + "ptrace_coredump" => freebsd < (14, 0), // `ptrace_sc_remote` introduced in FreeBSD 14. - "ptrace_sc_remote" if Some(14) > freebsd_ver => true, + "ptrace_sc_remote" => freebsd < (14, 0), // `sockcred2` is not available in FreeBSD 12. - "sockcred2" if Some(13) > freebsd_ver => true, + "sockcred2" => freebsd < (13, 0), // `shm_largepage_conf` was introduced in FreeBSD 13. - "shm_largepage_conf" if Some(13) > freebsd_ver => true, + "shm_largepage_conf" => freebsd < (13, 0), // Those are private types "memory_type" => true, @@ -3147,13 +3078,13 @@ fn test_freebsd(t: &Target) { | "sctp_stream_reset_event" => true, // FIXME(freebsd): Changed in FreeBSD 15 - "tcp_info" | "sockstat" if Some(15) >= freebsd_ver => true, + "tcp_info" | "sockstat" => freebsd >= (15, 0), // `splice` introduced in FreeBSD 14.2 - "splice" if Some(14) > freebsd_ver => true, + "splice" => freebsd < (14, 2), // Those are introduced in FreeBSD 15. - "xktls_session_onedir" | "xktls_session" if Some(15) > freebsd_ver => true, + "xktls_session_onedir" | "xktls_session" => freebsd < (15, 0), // Extern types "DIR" | "FILE" | "fpos_t" | "timezone" => true, @@ -3182,11 +3113,7 @@ fn test_freebsd(t: &Target) { // Those are introduced in FreeBSD 12. "clock_nanosleep" | "getrandom" | "elf_aux_info" | "setproctitle_fast" - | "timingsafe_bcmp" | "timingsafe_memcmp" - if Some(12) > freebsd_ver => - { - true - } + | "timingsafe_bcmp" | "timingsafe_memcmp" => freebsd < (12, 0), // Those are introduced in FreeBSD 13. "memfd_create" @@ -3200,31 +3127,21 @@ fn test_freebsd(t: &Target) { | "aio_writev" | "copy_file_range" | "eventfd_read" - | "eventfd_write" - if Some(13) > freebsd_ver => - { - true - } + | "eventfd_write" => freebsd < (13, 0), // Those are introduced in FreeBSD 14. - "sched_getaffinity" | "sched_setaffinity" | "sched_getcpu" | "fspacectl" - if Some(14) > freebsd_ver => - { - true + "sched_getaffinity" | "sched_setaffinity" | "sched_getcpu" | "fspacectl" => { + freebsd < (14, 0) } // Those are introduced in FreeBSD 14. - "timerfd_create" | "timerfd_gettime" | "timerfd_settime" if Some(14) > freebsd_ver => { - true - } + "timerfd_create" | "timerfd_gettime" | "timerfd_settime" => freebsd < (14, 0), // Those are introduced in FreeBSD 14.1. - "kcmp" => true, + "kcmp" => freebsd < (14, 1), - // FIXME(freebsd): `renameat2` was introduced in FreeBSD 15.1, and - // `freebsd_ver` only tracks the major version, so skip it until CI - // moves to a release that has it. - "renameat2" if Some(16) > freebsd_ver => true, + // Those are introduced in FreeBSD 15.1. + "renameat2" => freebsd < (15, 1), _ => false, } From 299d42ddf11c65f5592be623e82729c242dc8bba Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Tue, 29 Sep 2026 02:08:01 -0500 Subject: [PATCH 24/33] ci: Verify docs build without warnings on all targets (backport ) (cherry picked from commit 223361b35e1855b7abc4617cefd11793483f9f91) --- .github/workflows/ci.yaml | 14 -------------- ci/run.sh | 2 ++ 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 1e063889afc5d..987bb4b5dbe0a 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -372,19 +372,6 @@ jobs: prepare: ./ci/bsd-prepare.sh ${{ matrix.target }} run: ./ci/bsd-run.sh ${{ matrix.target }} - docs: - name: Ensure docs build - runs-on: ubuntu-26.04 - timeout-minutes: 10 - steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - with: - persist-credentials: false - - name: Install Rust - run: rustup update nightly --no-self-update && rustup default nightly - - uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2.9.2 - - run: cargo doc --workspace --no-deps - zizmor: name: Zizmor (Static analysis for GitHub Actions) runs-on: ubuntu-26.04 @@ -411,7 +398,6 @@ jobs: - test_tier2 - test_tier2_vm - verify_build - - docs - clippy - zizmor # GitHub branch protection is exceedingly silly and treats "jobs skipped because a dependency diff --git a/ci/run.sh b/ci/run.sh index 711751ed2be58..e77cd7cf89190 100755 --- a/ci/run.sh +++ b/ci/run.sh @@ -48,6 +48,8 @@ $cmd -- $test_flags # shellcheck disable=SC2086 $cmd --features extra_traits -- $test_flags +cargo doc --target "$target" --workspace --no-deps + # On relevant platforms, also test with our optional settings if [ "$env" = "gnu" ] && [ "$bits" = "32" ]; then From a9c951c099044c63a01d4fc202b97e5b7b3bf303 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Tue, 29 Sep 2026 02:16:25 -0500 Subject: [PATCH 25/33] ci: Remove a redundant profile setting (backport ) (cherry picked from commit 513b995a627f9f1c3d724597293251f1cfacdf43) --- ci/install-rust.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/ci/install-rust.sh b/ci/install-rust.sh index 9425d1a694d10..1a653ed21e0df 100755 --- a/ci/install-rust.sh +++ b/ci/install-rust.sh @@ -20,7 +20,6 @@ esac if [ "$os" = "windows" ] && [ -n "${TARGET:-}" ]; then toolchain="$toolchain-${RUST_HOST:-$TARGET}" - rustup set profile minimal fi rustup set profile minimal From c7922a1b6400477a9bdc221d3bdde11ca0442ff1 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Mon, 21 Sep 2026 02:32:13 -0500 Subject: [PATCH 26/33] linux: Move `socket.h` bits from `arch` to `src/new` I believe this also corrects the value of `SO_TIMESTAMP*` and `SO_{SND,RCV}TIMEO` on sparc32 with 64-bit `time_t`. Link: https://github.com/torvalds/linux/blob/93f51579e7df248780214094418f205253383cc5/include/uapi/asm-generic/socket.h#L161 Link: https://github.com/torvalds/linux/blob/93f51579e7df248780214094418f205253383cc5/arch/mips/include/uapi/asm/socket.h Link: https://github.com/torvalds/linux/blob/93f51579e7df248780214094418f205253383cc5/arch/powerpc/include/uapi/asm/socket.h Link: https://github.com/torvalds/linux/blob/93f51579e7df248780214094418f205253383cc5/arch/sparc/include/uapi/asm/socket.h (backport ) (cherry picked from commit 78be2c133bf14c76cb3e4bdef72bfb5a65f37da0) --- src/new/linux_uapi/arch/mips/asm/socket.rs | 180 ++++++++++++++ src/new/linux_uapi/arch/powerpc/asm/socket.rs | 15 ++ src/new/linux_uapi/arch/sparc/asm/socket.rs | 190 +++++++++++++++ src/new/linux_uapi/asm/mod.rs | 21 ++ src/new/linux_uapi/asm/socket.rs | 223 ++++++++++++++++++ src/new/linux_uapi/mod.rs | 1 + src/new/mod.rs | 1 + src/unix/linux_like/android/mod.rs | 3 +- src/unix/linux_like/emscripten/mod.rs | 2 + src/unix/linux_like/l4re/mod.rs | 4 +- src/unix/linux_like/linux/arch/generic/mod.rs | 153 ------------ src/unix/linux_like/linux/arch/mips/mod.rs | 125 ---------- src/unix/linux_like/linux/arch/powerpc/mod.rs | 126 ---------- src/unix/linux_like/linux/arch/sparc/mod.rs | 102 -------- src/unix/linux_like/mod.rs | 4 - 15 files changed, 638 insertions(+), 512 deletions(-) create mode 100644 src/new/linux_uapi/arch/mips/asm/socket.rs create mode 100644 src/new/linux_uapi/arch/powerpc/asm/socket.rs create mode 100644 src/new/linux_uapi/arch/sparc/asm/socket.rs create mode 100644 src/new/linux_uapi/asm/mod.rs create mode 100644 src/new/linux_uapi/asm/socket.rs diff --git a/src/new/linux_uapi/arch/mips/asm/socket.rs b/src/new/linux_uapi/arch/mips/asm/socket.rs new file mode 100644 index 0000000000000..298c770584757 --- /dev/null +++ b/src/new/linux_uapi/arch/mips/asm/socket.rs @@ -0,0 +1,180 @@ +//! Header: `arch/mips/include/uapi/asm/socket.h` + +use crate::prelude::*; + +pub const SOL_SOCKET: c_int = 0xffff; + +pub const SO_DEBUG: c_int = 0x0001; +pub const SO_REUSEADDR: c_int = 0x0004; +pub const SO_KEEPALIVE: c_int = 0x0008; +pub const SO_DONTROUTE: c_int = 0x0010; +pub const SO_BROADCAST: c_int = 0x0020; +pub const SO_LINGER: c_int = 0x0080; +pub const SO_OOBINLINE: c_int = 0x0100; +pub const SO_REUSEPORT: c_int = 0x0200; + +pub const SO_TYPE: c_int = 0x1008; +// pub const SO_STYLE: c_int = SO_TYPE; +pub const SO_ERROR: c_int = 0x1007; +pub const SO_SNDBUF: c_int = 0x1001; +pub const SO_RCVBUF: c_int = 0x1002; +pub const SO_SNDLOWAT: c_int = 0x1003; +pub const SO_RCVLOWAT: c_int = 0x1004; +const SO_SNDTIMEO_OLD: c_int = 0x1005; +const SO_RCVTIMEO_OLD: c_int = 0x1006; +pub const SO_ACCEPTCONN: c_int = 0x1009; +pub const SO_PROTOCOL: c_int = 0x1028; +pub const SO_DOMAIN: c_int = 0x1029; + +pub const SO_NO_CHECK: c_int = 11; +pub const SO_PRIORITY: c_int = 12; +pub const SO_BSDCOMPAT: c_int = 14; + +pub const SO_PASSCRED: c_int = 17; +pub const SO_PEERCRED: c_int = 18; + +pub const SO_SECURITY_AUTHENTICATION: c_int = 22; +pub const SO_SECURITY_ENCRYPTION_TRANSPORT: c_int = 23; +pub const SO_SECURITY_ENCRYPTION_NETWORK: c_int = 24; + +pub const SO_BINDTODEVICE: c_int = 25; + +pub const SO_ATTACH_FILTER: c_int = 26; +pub const SO_DETACH_FILTER: c_int = 27; +pub const SO_GET_FILTER: c_int = SO_ATTACH_FILTER; + +pub const SO_PEERNAME: c_int = 28; + +pub const SO_PEERSEC: c_int = 30; +pub const SO_SNDBUFFORCE: c_int = 31; +pub const SO_RCVBUFFORCE: c_int = 33; +pub const SO_PASSSEC: c_int = 34; + +pub const SO_MARK: c_int = 36; + +pub const SO_RXQ_OVFL: c_int = 40; + +pub const SO_WIFI_STATUS: c_int = 41; +pub const SCM_WIFI_STATUS: c_int = SO_WIFI_STATUS; +pub const SO_PEEK_OFF: c_int = 42; + +pub const SO_NOFCS: c_int = 43; + +pub const SO_LOCK_FILTER: c_int = 44; + +pub const SO_SELECT_ERR_QUEUE: c_int = 45; + +pub const SO_BUSY_POLL: c_int = 46; + +pub const SO_MAX_PACING_RATE: c_int = 47; + +pub const SO_BPF_EXTENSIONS: c_int = 48; + +pub const SO_INCOMING_CPU: c_int = 49; + +pub const SO_ATTACH_BPF: c_int = 50; +pub const SO_DETACH_BPF: c_int = SO_DETACH_FILTER; + +pub const SO_ATTACH_REUSEPORT_CBPF: c_int = 51; +pub const SO_ATTACH_REUSEPORT_EBPF: c_int = 52; + +pub const SO_CNX_ADVICE: c_int = 53; + +pub const SCM_TIMESTAMPING_OPT_STATS: c_int = 54; + +pub const SO_MEMINFO: c_int = 55; + +pub const SO_INCOMING_NAPI_ID: c_int = 56; + +pub const SO_COOKIE: c_int = 57; + +pub const SCM_TIMESTAMPING_PKTINFO: c_int = 58; + +pub const SO_PEERGROUPS: c_int = 59; + +pub const SO_ZEROCOPY: c_int = 60; + +pub const SO_TXTIME: c_int = 61; +pub const SCM_TXTIME: c_int = SO_TXTIME; + +pub const SO_BINDTOIFINDEX: c_int = 62; + +const SO_TIMESTAMP_OLD: c_int = 29; +const SO_TIMESTAMPNS_OLD: c_int = 35; +const SO_TIMESTAMPING_OLD: c_int = 37; + +const SO_TIMESTAMP_NEW: c_int = 63; +const SO_TIMESTAMPNS_NEW: c_int = 64; +const SO_TIMESTAMPING_NEW: c_int = 65; + +const SO_RCVTIMEO_NEW: c_int = 66; +const SO_SNDTIMEO_NEW: c_int = 67; + +pub const SO_DETACH_REUSEPORT_BPF: c_int = 68; + +pub const SO_PREFER_BUSY_POLL: c_int = 69; +pub const SO_BUSY_POLL_BUDGET: c_int = 70; + +pub const SO_NETNS_COOKIE: c_int = 71; + +pub const SO_BUF_LOCK: c_int = 72; + +pub const SO_RESERVE_MEM: c_int = 73; + +pub const SO_TXREHASH: c_int = 74; + +pub const SO_RCVMARK: c_int = 75; + +pub const SO_PASSPIDFD: c_int = 76; +pub const SO_PEERPIDFD: c_int = 77; + +pub const SO_DEVMEM_LINEAR: c_int = 78; +pub const SCM_DEVMEM_LINEAR: c_int = SO_DEVMEM_LINEAR; +pub const SO_DEVMEM_DMABUF: c_int = 79; +pub const SCM_DEVMEM_DMABUF: c_int = SO_DEVMEM_DMABUF; +pub const SO_DEVMEM_DONTNEED: c_int = 80; + +cfg_if! { + if #[cfg(target_pointer_width = "64")] { + pub const SO_TIMESTAMP: c_int = SO_TIMESTAMP_OLD; + pub const SO_TIMESTAMPNS: c_int = SO_TIMESTAMPNS_OLD; + pub const SO_TIMESTAMPING: c_int = SO_TIMESTAMPING_OLD; + + pub const SO_RCVTIMEO: c_int = SO_RCVTIMEO_OLD; + pub const SO_SNDTIMEO: c_int = SO_SNDTIMEO_OLD; + } else { + #[allow(deprecated)] + const TIME_T_LONG: bool = size_of::() == size_of::(); + + pub const SO_TIMESTAMP: c_int = if TIME_T_LONG { + SO_TIMESTAMP_OLD + } else { + SO_TIMESTAMP_NEW + }; + pub const SO_TIMESTAMPNS: c_int = if TIME_T_LONG { + SO_TIMESTAMPNS_OLD + } else { + SO_TIMESTAMPNS_NEW + }; + pub const SO_TIMESTAMPING: c_int = if TIME_T_LONG { + SO_TIMESTAMPING_OLD + } else { + SO_TIMESTAMPING_NEW + }; + + pub const SO_RCVTIMEO: c_int = if TIME_T_LONG { + SO_RCVTIMEO_OLD + } else { + SO_RCVTIMEO_NEW + }; + pub const SO_SNDTIMEO: c_int = if TIME_T_LONG { + SO_SNDTIMEO_OLD + } else { + SO_SNDTIMEO_NEW + }; + } +} + +pub const SCM_TIMESTAMP: c_int = SO_TIMESTAMP; +pub const SCM_TIMESTAMPNS: c_int = SO_TIMESTAMPNS; +pub const SCM_TIMESTAMPING: c_int = SO_TIMESTAMPING; diff --git a/src/new/linux_uapi/arch/powerpc/asm/socket.rs b/src/new/linux_uapi/arch/powerpc/asm/socket.rs new file mode 100644 index 0000000000000..6d94483adca70 --- /dev/null +++ b/src/new/linux_uapi/arch/powerpc/asm/socket.rs @@ -0,0 +1,15 @@ +//! Header: `arch/powerpc/include/uapi/asm/socket.h` + +use crate::prelude::*; + +pub const SO_RCVLOWAT: c_int = 16; +pub const SO_SNDLOWAT: c_int = 17; +const SO_RCVTIMEO_OLD: c_int = 18; +const SO_SNDTIMEO_OLD: c_int = 19; +pub const SO_PASSCRED: c_int = 20; +pub const SO_PEERCRED: c_int = 21; + +#[path = "../../../asm/socket.rs"] +mod asm_generic; + +pub use asm_generic::*; diff --git a/src/new/linux_uapi/arch/sparc/asm/socket.rs b/src/new/linux_uapi/arch/sparc/asm/socket.rs new file mode 100644 index 0000000000000..66073ebf0b77d --- /dev/null +++ b/src/new/linux_uapi/arch/sparc/asm/socket.rs @@ -0,0 +1,190 @@ +//! Header: `arch/sparc/include/uapi/asm/socket.h` + +use crate::prelude::*; + +pub const SOL_SOCKET: c_int = 0xffff; + +pub const SO_DEBUG: c_int = 0x0001; +pub const SO_PASSCRED: c_int = 0x0002; +pub const SO_REUSEADDR: c_int = 0x0004; +pub const SO_KEEPALIVE: c_int = 0x0008; +pub const SO_DONTROUTE: c_int = 0x0010; +pub const SO_BROADCAST: c_int = 0x0020; +pub const SO_PEERCRED: c_int = 0x0040; +pub const SO_LINGER: c_int = 0x0080; +pub const SO_OOBINLINE: c_int = 0x0100; +pub const SO_REUSEPORT: c_int = 0x0200; +pub const SO_BSDCOMPAT: c_int = 0x0400; +pub const SO_RCVLOWAT: c_int = 0x0800; +pub const SO_SNDLOWAT: c_int = 0x1000; +pub const SO_RCVTIMEO_OLD: c_int = 0x2000; +pub const SO_SNDTIMEO_OLD: c_int = 0x4000; +pub const SO_ACCEPTCONN: c_int = 0x8000; + +pub const SO_SNDBUF: c_int = 0x1001; +pub const SO_RCVBUF: c_int = 0x1002; +pub const SO_SNDBUFFORCE: c_int = 0x100a; +pub const SO_RCVBUFFORCE: c_int = 0x100b; +pub const SO_ERROR: c_int = 0x1007; +pub const SO_TYPE: c_int = 0x1008; +pub const SO_PROTOCOL: c_int = 0x1028; +pub const SO_DOMAIN: c_int = 0x1029; + +/* Linux specific, keep the same. */ +pub const SO_NO_CHECK: c_int = 0x000b; +pub const SO_PRIORITY: c_int = 0x000c; + +pub const SO_BINDTODEVICE: c_int = 0x000d; + +pub const SO_ATTACH_FILTER: c_int = 0x001a; +pub const SO_DETACH_FILTER: c_int = 0x001b; +pub const SO_GET_FILTER: c_int = SO_ATTACH_FILTER; + +pub const SO_PEERNAME: c_int = 0x001c; + +pub const SO_PEERSEC: c_int = 0x001e; +pub const SO_PASSSEC: c_int = 0x001f; + +pub const SO_MARK: c_int = 0x0022; + +pub const SO_RXQ_OVFL: c_int = 0x0024; + +pub const SO_WIFI_STATUS: c_int = 0x0025; +pub const SCM_WIFI_STATUS: c_int = SO_WIFI_STATUS; +pub const SO_PEEK_OFF: c_int = 0x0026; + +pub const SO_NOFCS: c_int = 0x0027; + +pub const SO_LOCK_FILTER: c_int = 0x0028; + +pub const SO_SELECT_ERR_QUEUE: c_int = 0x0029; + +pub const SO_BUSY_POLL: c_int = 0x0030; + +pub const SO_MAX_PACING_RATE: c_int = 0x0031; + +pub const SO_BPF_EXTENSIONS: c_int = 0x0032; + +pub const SO_INCOMING_CPU: c_int = 0x0033; + +pub const SO_ATTACH_BPF: c_int = 0x0034; +pub const SO_DETACH_BPF: c_int = SO_DETACH_FILTER; + +pub const SO_ATTACH_REUSEPORT_CBPF: c_int = 0x0035; +pub const SO_ATTACH_REUSEPORT_EBPF: c_int = 0x0036; + +pub const SO_CNX_ADVICE: c_int = 0x0037; + +pub const SCM_TIMESTAMPING_OPT_STATS: c_int = 0x0038; + +pub const SO_MEMINFO: c_int = 0x0039; + +pub const SO_INCOMING_NAPI_ID: c_int = 0x003a; + +pub const SO_COOKIE: c_int = 0x003b; + +pub const SCM_TIMESTAMPING_PKTINFO: c_int = 0x003c; + +pub const SO_PEERGROUPS: c_int = 0x003d; + +pub const SO_ZEROCOPY: c_int = 0x003e; + +pub const SO_TXTIME: c_int = 0x003f; +pub const SCM_TXTIME: c_int = SO_TXTIME; + +pub const SO_BINDTOIFINDEX: c_int = 0x0041; + +pub const SO_SECURITY_AUTHENTICATION: c_int = 0x5001; +pub const SO_SECURITY_ENCRYPTION_TRANSPORT: c_int = 0x5002; +pub const SO_SECURITY_ENCRYPTION_NETWORK: c_int = 0x5004; + +const SO_TIMESTAMP_OLD: c_int = 0x001d; +const SO_TIMESTAMPNS_OLD: c_int = 0x0021; +const SO_TIMESTAMPING_OLD: c_int = 0x0023; + +// `SO_*_NEW` constants defined in `cfg` block + +pub const SO_DETACH_REUSEPORT_BPF: c_int = 0x0047; + +pub const SO_PREFER_BUSY_POLL: c_int = 0x0048; +pub const SO_BUSY_POLL_BUDGET: c_int = 0x0049; + +pub const SO_NETNS_COOKIE: c_int = 0x0050; + +pub const SO_BUF_LOCK: c_int = 0x0051; + +pub const SO_RESERVE_MEM: c_int = 0x0052; + +pub const SO_TXREHASH: c_int = 0x0053; + +pub const SO_RCVMARK: c_int = 0x0054; + +pub const SO_PASSPIDFD: c_int = 0x0055; +pub const SO_PEERPIDFD: c_int = 0x0056; + +pub const SO_DEVMEM_LINEAR: c_int = 0x0057; +pub const SCM_DEVMEM_LINEAR: c_int = SO_DEVMEM_LINEAR; +pub const SO_DEVMEM_DMABUF: c_int = 0x0058; +pub const SCM_DEVMEM_DMABUF: c_int = SO_DEVMEM_DMABUF; +pub const SO_DEVMEM_DONTNEED: c_int = 0x0059; + +pub const SCM_TS_OPT_ID: c_int = 0x005a; + +pub const SO_RCVPRIORITY: c_int = 0x005b; + +pub const SO_PASSRIGHTS: c_int = 0x005c; + +pub const SO_INQ: c_int = 0x005d; +pub const SCM_INQ: c_int = SO_INQ; + +cfg_if! { + if #[cfg(target_pointer_width = "64")] { + pub const SO_TIMESTAMP: c_int = SO_TIMESTAMP_OLD; + pub const SO_TIMESTAMPNS: c_int = SO_TIMESTAMPNS_OLD; + pub const SO_TIMESTAMPING: c_int = SO_TIMESTAMPING_OLD; + + pub const SO_RCVTIMEO: c_int = SO_RCVTIMEO_OLD; + pub const SO_SNDTIMEO: c_int = SO_SNDTIMEO_OLD; + } else { + #[allow(deprecated)] + const TIME_T_LONG: bool = size_of::() == size_of::(); + + const SO_TIMESTAMP_NEW: c_int = 0x0046; + const SO_TIMESTAMPNS_NEW: c_int = 0x0042; + const SO_TIMESTAMPING_NEW: c_int = 0x0043; + + const SO_RCVTIMEO_NEW: c_int = 0x0044; + const SO_SNDTIMEO_NEW: c_int = 0x0045; + + pub const SO_TIMESTAMP: c_int = if TIME_T_LONG { + SO_TIMESTAMP_OLD + } else { + SO_TIMESTAMP_NEW + }; + pub const SO_TIMESTAMPNS: c_int = if TIME_T_LONG { + SO_TIMESTAMPNS_OLD + } else { + SO_TIMESTAMPNS_NEW + }; + pub const SO_TIMESTAMPING: c_int = if TIME_T_LONG { + SO_TIMESTAMPING_OLD + } else { + SO_TIMESTAMPING_NEW + }; + + pub const SO_RCVTIMEO: c_int = if TIME_T_LONG { + SO_RCVTIMEO_OLD + } else { + SO_RCVTIMEO_NEW + }; + pub const SO_SNDTIMEO: c_int = if TIME_T_LONG { + SO_SNDTIMEO_OLD + } else { + SO_SNDTIMEO_NEW + }; + } +} + +pub const SCM_TIMESTAMP: c_int = SO_TIMESTAMP; +pub const SCM_TIMESTAMPNS: c_int = SO_TIMESTAMPNS; +pub const SCM_TIMESTAMPING: c_int = SO_TIMESTAMPING; diff --git a/src/new/linux_uapi/asm/mod.rs b/src/new/linux_uapi/asm/mod.rs new file mode 100644 index 0000000000000..720e923c77393 --- /dev/null +++ b/src/new/linux_uapi/asm/mod.rs @@ -0,0 +1,21 @@ +//! Directory: `arch/*/include/uapi/asm/` (arch-specific versions) +//! Directory: `include/uapi/asm-generic/` (default versions) + +#[cfg_attr( + any( + target_arch = "mips", + target_arch = "mips32r6", + target_arch = "mips", + target_arch = "mips32r6", + ), + path = "../arch/mips/asm/socket.rs" +)] +#[cfg_attr( + any(target_arch = "powerpc", target_arch = "powerpc64"), + path = "../arch/powerpc/asm/socket.rs" +)] +#[cfg_attr( + any(target_arch = "sparc", target_arch = "sparc64"), + path = "../arch/sparc/asm/socket.rs" +)] +pub(crate) mod socket; diff --git a/src/new/linux_uapi/asm/socket.rs b/src/new/linux_uapi/asm/socket.rs new file mode 100644 index 0000000000000..1051b282cdf30 --- /dev/null +++ b/src/new/linux_uapi/asm/socket.rs @@ -0,0 +1,223 @@ +//! Header: `include/uapi/asm-generic/socket.h` + +use crate::prelude::*; + +pub const SOL_SOCKET: c_int = 1; + +pub const SO_DEBUG: c_int = 1; +pub const SO_REUSEADDR: c_int = 2; +pub const SO_TYPE: c_int = 3; +pub const SO_ERROR: c_int = 4; +pub const SO_DONTROUTE: c_int = 5; +pub const SO_BROADCAST: c_int = 6; +pub const SO_SNDBUF: c_int = 7; +pub const SO_RCVBUF: c_int = 8; +pub const SO_SNDBUFFORCE: c_int = 32; +pub const SO_RCVBUFFORCE: c_int = 33; +pub const SO_KEEPALIVE: c_int = 9; +pub const SO_OOBINLINE: c_int = 10; +pub const SO_NO_CHECK: c_int = 11; +pub const SO_PRIORITY: c_int = 12; +pub const SO_LINGER: c_int = 13; +pub const SO_BSDCOMPAT: c_int = 14; +pub const SO_REUSEPORT: c_int = 15; + +cfg_if! { + if #[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))] { + // powerpc only differs in these + pub const SO_PASSCRED: c_int = 16; + pub const SO_PEERCRED: c_int = 17; + pub const SO_RCVLOWAT: c_int = 18; + pub const SO_SNDLOWAT: c_int = 19; + const SO_RCVTIMEO_OLD: c_int = 20; + const SO_SNDTIMEO_OLD: c_int = 21; + } else { + use super::{ + SO_RCVTIMEO_OLD, + SO_SNDTIMEO_OLD, + }; + } +} + +// Security levels - as per NRL IPv6 - don't actually do anything +pub const SO_SECURITY_AUTHENTICATION: c_int = 22; +pub const SO_SECURITY_ENCRYPTION_TRANSPORT: c_int = 23; +pub const SO_SECURITY_ENCRYPTION_NETWORK: c_int = 24; + +pub const SO_BINDTODEVICE: c_int = 25; + +// Socket filtering +pub const SO_ATTACH_FILTER: c_int = 26; +pub const SO_DETACH_FILTER: c_int = 27; +pub const SO_GET_FILTER: c_int = SO_ATTACH_FILTER; + +pub const SO_PEERNAME: c_int = 28; + +pub const SO_ACCEPTCONN: c_int = 30; + +pub const SO_PEERSEC: c_int = 31; +pub const SO_PASSSEC: c_int = 34; + +pub const SO_MARK: c_int = 36; + +pub const SO_PROTOCOL: c_int = 38; +pub const SO_DOMAIN: c_int = 39; + +pub const SO_RXQ_OVFL: c_int = 40; + +pub const SO_WIFI_STATUS: c_int = 41; +pub const SCM_WIFI_STATUS: c_int = SO_WIFI_STATUS; +pub const SO_PEEK_OFF: c_int = 42; + +// Instruct lower device to use last 4-bytes of skb data as FCS +pub const SO_NOFCS: c_int = 43; + +pub const SO_LOCK_FILTER: c_int = 44; + +pub const SO_SELECT_ERR_QUEUE: c_int = 45; + +pub const SO_BUSY_POLL: c_int = 46; + +pub const SO_MAX_PACING_RATE: c_int = 47; + +pub const SO_BPF_EXTENSIONS: c_int = 48; + +pub const SO_INCOMING_CPU: c_int = 49; + +pub const SO_ATTACH_BPF: c_int = 50; +pub const SO_DETACH_BPF: c_int = SO_DETACH_FILTER; + +pub const SO_ATTACH_REUSEPORT_CBPF: c_int = 51; +pub const SO_ATTACH_REUSEPORT_EBPF: c_int = 52; + +pub const SO_CNX_ADVICE: c_int = 53; + +pub const SCM_TIMESTAMPING_OPT_STATS: c_int = 54; + +pub const SO_MEMINFO: c_int = 55; + +pub const SO_INCOMING_NAPI_ID: c_int = 56; + +pub const SO_COOKIE: c_int = 57; + +pub const SCM_TIMESTAMPING_PKTINFO: c_int = 58; + +pub const SO_PEERGROUPS: c_int = 59; + +pub const SO_ZEROCOPY: c_int = 60; + +pub const SO_TXTIME: c_int = 61; +pub const SCM_TXTIME: c_int = SO_TXTIME; + +pub const SO_BINDTOIFINDEX: c_int = 62; + +const SO_TIMESTAMP_OLD: c_int = 29; +const SO_TIMESTAMPNS_OLD: c_int = 35; +const SO_TIMESTAMPING_OLD: c_int = 37; + +cfg_if! { + // Some of these platforms in CI already have these constants. + // But they may still not have those _OLD ones. + if #[cfg(all( + any( + target_arch = "x86", + target_arch = "x86_64", + target_arch = "arm", + target_arch = "aarch64", + target_arch = "csky", + target_arch = "loongarch64" + ), + not(any(target_env = "musl", target_env = "ohos")) + ))] { + pub const SO_TIMESTAMP_NEW: c_int = 63; + pub const SO_TIMESTAMPNS_NEW: c_int = 64; + pub const SO_TIMESTAMPING_NEW: c_int = 65; + + pub const SO_RCVTIMEO_NEW: c_int = 66; + pub const SO_SNDTIMEO_NEW: c_int = 67; + } else if #[cfg(not(any( + target_pointer_width = "64", + all(target_arch = "x86_64", target_pointer_width = "32") + )))] { + // Otherwise the constants are nonpublic. Only used on platforms with legacy 32-bit + // `time_t`. + const SO_TIMESTAMP_NEW: c_int = 63; + const SO_TIMESTAMPNS_NEW: c_int = 64; + const SO_TIMESTAMPING_NEW: c_int = 65; + + const SO_RCVTIMEO_NEW: c_int = 66; + const SO_SNDTIMEO_NEW: c_int = 67; + } +} + +pub const SO_DETACH_REUSEPORT_BPF: c_int = 68; + +pub const SO_PREFER_BUSY_POLL: c_int = 69; +pub const SO_BUSY_POLL_BUDGET: c_int = 70; + +pub const SO_NETNS_COOKIE: c_int = 71; + +pub const SO_BUF_LOCK: c_int = 72; + +pub const SO_RESERVE_MEM: c_int = 73; + +pub const SO_TXREHASH: c_int = 74; + +pub const SO_RCVMARK: c_int = 75; + +pub const SO_PASSPIDFD: c_int = 76; +pub const SO_PEERPIDFD: c_int = 77; + +pub const SO_DEVMEM_LINEAR: c_int = 78; +pub const SCM_DEVMEM_LINEAR: c_int = SO_DEVMEM_LINEAR; +pub const SO_DEVMEM_DMABUF: c_int = 79; +pub const SCM_DEVMEM_DMABUF: c_int = SO_DEVMEM_DMABUF; +pub const SO_DEVMEM_DONTNEED: c_int = 80; + +cfg_if! { + if #[cfg(any( + target_pointer_width = "64", + all(target_arch = "x86_64", target_pointer_width = "32") + ))] { + pub const SO_TIMESTAMP: c_int = SO_TIMESTAMP_OLD; + pub const SO_TIMESTAMPNS: c_int = SO_TIMESTAMPNS_OLD; + pub const SO_TIMESTAMPING: c_int = SO_TIMESTAMPING_OLD; + + pub const SO_RCVTIMEO: c_int = SO_RCVTIMEO_OLD; + pub const SO_SNDTIMEO: c_int = SO_SNDTIMEO_OLD; + } else { + #[allow(deprecated)] + const TIME_T_LONG: bool = size_of::() == size_of::(); + + pub const SO_TIMESTAMP: c_int = if TIME_T_LONG { + SO_TIMESTAMP_OLD + } else { + SO_TIMESTAMP_NEW + }; + pub const SO_TIMESTAMPNS: c_int = if TIME_T_LONG { + SO_TIMESTAMPNS_OLD + } else { + SO_TIMESTAMPNS_NEW + }; + pub const SO_TIMESTAMPING: c_int = if TIME_T_LONG { + SO_TIMESTAMPING_OLD + } else { + SO_TIMESTAMPING_NEW + }; + + pub const SO_RCVTIMEO: c_int = if TIME_T_LONG { + SO_RCVTIMEO_OLD + } else { + SO_RCVTIMEO_NEW + }; + pub const SO_SNDTIMEO: c_int = if TIME_T_LONG { + SO_SNDTIMEO_OLD + } else { + SO_SNDTIMEO_NEW + }; + } +} + +pub const SCM_TIMESTAMP: c_int = SO_TIMESTAMP; +pub const SCM_TIMESTAMPNS: c_int = SO_TIMESTAMPNS; +pub const SCM_TIMESTAMPING: c_int = SO_TIMESTAMPING; diff --git a/src/new/linux_uapi/mod.rs b/src/new/linux_uapi/mod.rs index 8ac3022d16578..9e04b39066326 100644 --- a/src/new/linux_uapi/mod.rs +++ b/src/new/linux_uapi/mod.rs @@ -1,3 +1,4 @@ //! This directory maps to `include/uapi` in the Linux source tree. +pub(crate) mod asm; pub(crate) mod linux; diff --git a/src/new/mod.rs b/src/new/mod.rs index 557717d733b1c..1694fd7cc2d48 100644 --- a/src/new/mod.rs +++ b/src/new/mod.rs @@ -180,6 +180,7 @@ cfg_if! { pub use linux::types::*; pub use sys::socket::*; } else if #[cfg(target_os = "linux")] { + pub use asm::socket::*; pub use linux::can::bcm::*; pub use linux::can::error::*; pub use linux::can::j1939::*; diff --git a/src/unix/linux_like/android/mod.rs b/src/unix/linux_like/android/mod.rs index 2ab3aab679cb3..116047c66ce40 100644 --- a/src/unix/linux_like/android/mod.rs +++ b/src/unix/linux_like/android/mod.rs @@ -1163,6 +1163,7 @@ pub const DCCP_SOCKOPT_CCID_TX_INFO: c_int = 192; /// maximum number of services provided on the same listening port pub const DCCP_SERVICE_LIST_MAX_LEN: c_int = 32; +pub const SO_DEBUG: c_int = 1; pub const SO_REUSEADDR: c_int = 2; pub const SO_TYPE: c_int = 3; pub const SO_ERROR: c_int = 4; @@ -1213,7 +1214,7 @@ pub const SO_TIMESTAMPING_NEW: c_int = 65; pub const SO_DETACH_REUSEPORT_BPF: c_int = 68; // Defined in unix/linux_like/mod.rs -// pub const SCM_TIMESTAMP: c_int = SO_TIMESTAMP; +pub const SCM_TIMESTAMP: c_int = SO_TIMESTAMP; pub const SCM_TIMESTAMPNS: c_int = SO_TIMESTAMPNS; pub const SCM_TIMESTAMPING: c_int = SO_TIMESTAMPING; diff --git a/src/unix/linux_like/emscripten/mod.rs b/src/unix/linux_like/emscripten/mod.rs index 36f532574f8eb..61c25658d6234 100644 --- a/src/unix/linux_like/emscripten/mod.rs +++ b/src/unix/linux_like/emscripten/mod.rs @@ -1097,6 +1097,7 @@ pub const B3500000: crate::speed_t = 0o010016; pub const B4000000: crate::speed_t = 0o010017; pub const SO_BINDTODEVICE: c_int = 25; +pub const SCM_TIMESTAMP: c_int = SO_TIMESTAMP; pub const SO_TIMESTAMP: c_int = 63; pub const SO_MARK: c_int = 36; pub const SO_RXQ_OVFL: c_int = 40; @@ -1165,6 +1166,7 @@ pub const IPPROTO_MAX: c_int = 263; pub const SOL_SOCKET: c_int = 1; +pub const SO_DEBUG: c_int = 1; pub const SO_REUSEADDR: c_int = 2; pub const SO_TYPE: c_int = 3; pub const SO_ERROR: c_int = 4; diff --git a/src/unix/linux_like/l4re/mod.rs b/src/unix/linux_like/l4re/mod.rs index e9bd6104c2d6d..6e5122538260b 100644 --- a/src/unix/linux_like/l4re/mod.rs +++ b/src/unix/linux_like/l4re/mod.rs @@ -129,7 +129,7 @@ pub const RLIM_NLIMITS: crate::__rlimit_resource_t = 16; pub const SOL_SOCKET: c_int = 1; -// pub const SO_DEBUG: c_int = 1; +pub const SO_DEBUG: c_int = 1; pub const SO_REUSEADDR: c_int = 2; pub const SO_TYPE: c_int = 3; pub const SO_ERROR: c_int = 4; @@ -160,6 +160,8 @@ pub const SO_PEERNAME: c_int = 28; pub const SO_ACCEPTCONN: c_int = 30; pub const SO_PEERSEC: c_int = 31; +pub const SCM_TIMESTAMP: c_int = SO_TIMESTAMP; + pub const TCGETS: Ioctl = 0x5401; pub const TCSETS: Ioctl = 0x5402; pub const TCSETSW: Ioctl = 0x5403; diff --git a/src/unix/linux_like/linux/arch/generic/mod.rs b/src/unix/linux_like/linux/arch/generic/mod.rs index 9b9a11dd53471..7710dcb47b564 100644 --- a/src/unix/linux_like/linux/arch/generic/mod.rs +++ b/src/unix/linux_like/linux/arch/generic/mod.rs @@ -14,159 +14,6 @@ s! { } } -// include/uapi/asm-generic/socket.h -// arch/alpha/include/uapi/asm/socket.h -// tools/include/uapi/asm-generic/socket.h -// arch/mips/include/uapi/asm/socket.h -pub const SOL_SOCKET: c_int = 1; - -// Defined in unix/linux_like/mod.rs -// pub const SO_DEBUG: c_int = 1; -pub const SO_REUSEADDR: c_int = 2; -pub const SO_TYPE: c_int = 3; -pub const SO_ERROR: c_int = 4; -pub const SO_DONTROUTE: c_int = 5; -pub const SO_BROADCAST: c_int = 6; -pub const SO_SNDBUF: c_int = 7; -pub const SO_RCVBUF: c_int = 8; -pub const SO_KEEPALIVE: c_int = 9; -pub const SO_OOBINLINE: c_int = 10; -pub const SO_NO_CHECK: c_int = 11; -pub const SO_PRIORITY: c_int = 12; -pub const SO_LINGER: c_int = 13; -pub const SO_BSDCOMPAT: c_int = 14; -pub const SO_REUSEPORT: c_int = 15; -pub const SO_PASSCRED: c_int = 16; -pub const SO_PEERCRED: c_int = 17; -pub const SO_RCVLOWAT: c_int = 18; -pub const SO_SNDLOWAT: c_int = 19; -pub const SO_SECURITY_AUTHENTICATION: c_int = 22; -pub const SO_SECURITY_ENCRYPTION_TRANSPORT: c_int = 23; -pub const SO_SECURITY_ENCRYPTION_NETWORK: c_int = 24; -pub const SO_BINDTODEVICE: c_int = 25; -pub const SO_ATTACH_FILTER: c_int = 26; -pub const SO_DETACH_FILTER: c_int = 27; -pub const SO_GET_FILTER: c_int = SO_ATTACH_FILTER; -pub const SO_PEERNAME: c_int = 28; - -cfg_if! { - if #[cfg(all( - linux_time_bits64, - any(target_arch = "arm", target_arch = "x86"), - not(any(target_env = "musl", target_env = "ohos")) - ))] { - pub const SO_TIMESTAMP: c_int = SO_TIMESTAMP_NEW; - pub const SO_TIMESTAMPNS: c_int = SO_TIMESTAMPNS_NEW; - pub const SO_TIMESTAMPING: c_int = SO_TIMESTAMPING_NEW; - pub const SO_RCVTIMEO: c_int = SO_RCVTIMEO_NEW; - pub const SO_SNDTIMEO: c_int = SO_SNDTIMEO_NEW; - } else if #[cfg(all( - linux_time_bits64, - any(target_arch = "arm", target_arch = "x86"), - any(target_env = "musl", target_env = "ohos") - ))] { - pub const SO_TIMESTAMP: c_int = 63; - pub const SO_TIMESTAMPNS: c_int = 64; - pub const SO_TIMESTAMPING: c_int = 65; - pub const SO_RCVTIMEO: c_int = 66; - pub const SO_SNDTIMEO: c_int = 67; - } else { - const SO_TIMESTAMP_OLD: c_int = 29; - const SO_TIMESTAMPNS_OLD: c_int = 35; - const SO_TIMESTAMPING_OLD: c_int = 37; - const SO_RCVTIMEO_OLD: c_int = 20; - const SO_SNDTIMEO_OLD: c_int = 21; - - pub const SO_TIMESTAMP: c_int = SO_TIMESTAMP_OLD; - pub const SO_TIMESTAMPNS: c_int = SO_TIMESTAMPNS_OLD; - pub const SO_TIMESTAMPING: c_int = SO_TIMESTAMPING_OLD; - pub const SO_RCVTIMEO: c_int = SO_RCVTIMEO_OLD; - pub const SO_SNDTIMEO: c_int = SO_SNDTIMEO_OLD; - } -} - -pub const SO_ACCEPTCONN: c_int = 30; -pub const SO_PEERSEC: c_int = 31; -pub const SO_SNDBUFFORCE: c_int = 32; -pub const SO_RCVBUFFORCE: c_int = 33; -pub const SO_PASSSEC: c_int = 34; -pub const SO_MARK: c_int = 36; -pub const SO_PROTOCOL: c_int = 38; -pub const SO_DOMAIN: c_int = 39; -pub const SO_RXQ_OVFL: c_int = 40; -pub const SO_WIFI_STATUS: c_int = 41; -pub const SCM_WIFI_STATUS: c_int = SO_WIFI_STATUS; -pub const SO_PEEK_OFF: c_int = 42; -pub const SO_NOFCS: c_int = 43; -pub const SO_LOCK_FILTER: c_int = 44; -pub const SO_SELECT_ERR_QUEUE: c_int = 45; -pub const SO_BUSY_POLL: c_int = 46; -pub const SO_MAX_PACING_RATE: c_int = 47; -pub const SO_BPF_EXTENSIONS: c_int = 48; -pub const SO_INCOMING_CPU: c_int = 49; -pub const SO_ATTACH_BPF: c_int = 50; -pub const SO_DETACH_BPF: c_int = SO_DETACH_FILTER; -pub const SO_ATTACH_REUSEPORT_CBPF: c_int = 51; -pub const SO_ATTACH_REUSEPORT_EBPF: c_int = 52; -pub const SO_CNX_ADVICE: c_int = 53; -pub const SCM_TIMESTAMPING_OPT_STATS: c_int = 54; -pub const SO_MEMINFO: c_int = 55; -pub const SO_INCOMING_NAPI_ID: c_int = 56; -pub const SO_COOKIE: c_int = 57; -pub const SCM_TIMESTAMPING_PKTINFO: c_int = 58; -pub const SO_PEERGROUPS: c_int = 59; -pub const SO_ZEROCOPY: c_int = 60; -pub const SO_TXTIME: c_int = 61; -pub const SCM_TXTIME: c_int = SO_TXTIME; -pub const SO_BINDTOIFINDEX: c_int = 62; -cfg_if! { - // Some of these platforms in CI already have these constants. - // But they may still not have those _OLD ones. - if #[cfg(all( - any( - target_arch = "x86", - target_arch = "x86_64", - target_arch = "arm", - target_arch = "aarch64", - target_arch = "csky", - target_arch = "loongarch64" - ), - // FIXME(musl): - // Musl hardcodes the SO_* constants instead - // of inheriting them from the kernel headers. - // For new constants you might need consider updating - // musl in the CI as well. - not(any(target_env = "musl", target_env = "ohos")) - ))] { - pub const SO_TIMESTAMP_NEW: c_int = 63; - pub const SO_TIMESTAMPNS_NEW: c_int = 64; - pub const SO_TIMESTAMPING_NEW: c_int = 65; - pub const SO_RCVTIMEO_NEW: c_int = 66; - pub const SO_SNDTIMEO_NEW: c_int = 67; - } -} -pub const SO_DETACH_REUSEPORT_BPF: c_int = 68; -pub const SO_PREFER_BUSY_POLL: c_int = 69; -pub const SO_BUSY_POLL_BUDGET: c_int = 70; -pub const SO_NETNS_COOKIE: c_int = 71; -pub const SO_BUF_LOCK: c_int = 72; -pub const SO_RESERVE_MEM: c_int = 73; -pub const SO_TXREHASH: c_int = 74; -pub const SO_RCVMARK: c_int = 75; -pub const SO_PASSPIDFD: c_int = 76; -pub const SO_PEERPIDFD: c_int = 77; -pub const SO_DEVMEM_LINEAR: c_int = 78; -pub const SO_DEVMEM_DMABUF: c_int = 79; -pub const SO_DEVMEM_DONTNEED: c_int = 80; - -// Defined in unix/linux_like/mod.rs -// pub const SCM_TIMESTAMP: c_int = SO_TIMESTAMP; -pub const SCM_TIMESTAMPNS: c_int = SO_TIMESTAMPNS; -pub const SCM_TIMESTAMPING: c_int = SO_TIMESTAMPING; - -pub const SCM_DEVMEM_LINEAR: c_int = SO_DEVMEM_LINEAR; -pub const SCM_DEVMEM_DMABUF: c_int = SO_DEVMEM_DMABUF; - // Ioctl Constants pub const TCGETS: Ioctl = 0x5401; diff --git a/src/unix/linux_like/linux/arch/mips/mod.rs b/src/unix/linux_like/linux/arch/mips/mod.rs index 44c5f124d4e1a..682341d021ae8 100644 --- a/src/unix/linux_like/linux/arch/mips/mod.rs +++ b/src/unix/linux_like/linux/arch/mips/mod.rs @@ -14,131 +14,6 @@ s! { } } -// arch/mips/include/uapi/asm/socket.h -pub const SOL_SOCKET: c_int = 0xffff; - -// Defined in unix/linux_like/mod.rs -// pub const SO_DEBUG: c_int = 0x0001; -pub const SO_REUSEADDR: c_int = 0x0004; -pub const SO_KEEPALIVE: c_int = 0x0008; -pub const SO_DONTROUTE: c_int = 0x0010; -pub const SO_BROADCAST: c_int = 0x0020; -pub const SO_LINGER: c_int = 0x0080; -pub const SO_OOBINLINE: c_int = 0x0100; -pub const SO_REUSEPORT: c_int = 0x0200; -pub const SO_TYPE: c_int = 0x1008; -// pub const SO_STYLE: c_int = SO_TYPE; -pub const SO_ERROR: c_int = 0x1007; -pub const SO_SNDBUF: c_int = 0x1001; -pub const SO_RCVBUF: c_int = 0x1002; -pub const SO_SNDLOWAT: c_int = 0x1003; -pub const SO_RCVLOWAT: c_int = 0x1004; -cfg_if! { - if #[cfg(linux_time_bits64)] { - const SO_RCVTIMEO_NEW: c_int = 66; - const SO_SNDTIMEO_NEW: c_int = 67; - - pub const SO_SNDTIMEO: c_int = SO_SNDTIMEO_NEW; - pub const SO_RCVTIMEO: c_int = SO_RCVTIMEO_NEW; - } else { - const SO_SNDTIMEO_OLD: c_int = 0x1005; - const SO_RCVTIMEO_OLD: c_int = 0x1006; - - pub const SO_SNDTIMEO: c_int = SO_SNDTIMEO_OLD; - pub const SO_RCVTIMEO: c_int = SO_RCVTIMEO_OLD; - } -} -pub const SO_ACCEPTCONN: c_int = 0x1009; -pub const SO_PROTOCOL: c_int = 0x1028; -pub const SO_DOMAIN: c_int = 0x1029; - -pub const SO_NO_CHECK: c_int = 11; -pub const SO_PRIORITY: c_int = 12; -pub const SO_BSDCOMPAT: c_int = 14; -pub const SO_PASSCRED: c_int = 17; -pub const SO_PEERCRED: c_int = 18; -pub const SO_SECURITY_AUTHENTICATION: c_int = 22; -pub const SO_SECURITY_ENCRYPTION_TRANSPORT: c_int = 23; -pub const SO_SECURITY_ENCRYPTION_NETWORK: c_int = 24; -pub const SO_BINDTODEVICE: c_int = 25; -pub const SO_ATTACH_FILTER: c_int = 26; -pub const SO_DETACH_FILTER: c_int = 27; -pub const SO_GET_FILTER: c_int = SO_ATTACH_FILTER; -pub const SO_PEERNAME: c_int = 28; -pub const SO_PEERSEC: c_int = 30; -pub const SO_SNDBUFFORCE: c_int = 31; -pub const SO_RCVBUFFORCE: c_int = 33; -pub const SO_PASSSEC: c_int = 34; -pub const SO_MARK: c_int = 36; -pub const SO_RXQ_OVFL: c_int = 40; -pub const SO_WIFI_STATUS: c_int = 41; -pub const SCM_WIFI_STATUS: c_int = SO_WIFI_STATUS; -pub const SO_PEEK_OFF: c_int = 42; -pub const SO_NOFCS: c_int = 43; -pub const SO_LOCK_FILTER: c_int = 44; -pub const SO_SELECT_ERR_QUEUE: c_int = 45; -pub const SO_BUSY_POLL: c_int = 46; -pub const SO_MAX_PACING_RATE: c_int = 47; -pub const SO_BPF_EXTENSIONS: c_int = 48; -pub const SO_INCOMING_CPU: c_int = 49; -pub const SO_ATTACH_BPF: c_int = 50; -pub const SO_DETACH_BPF: c_int = SO_DETACH_FILTER; -pub const SO_ATTACH_REUSEPORT_CBPF: c_int = 51; -pub const SO_ATTACH_REUSEPORT_EBPF: c_int = 52; -pub const SO_CNX_ADVICE: c_int = 53; -pub const SCM_TIMESTAMPING_OPT_STATS: c_int = 54; -pub const SO_MEMINFO: c_int = 55; -pub const SO_INCOMING_NAPI_ID: c_int = 56; -pub const SO_COOKIE: c_int = 57; -pub const SCM_TIMESTAMPING_PKTINFO: c_int = 58; -pub const SO_PEERGROUPS: c_int = 59; -pub const SO_ZEROCOPY: c_int = 60; -pub const SO_TXTIME: c_int = 61; -pub const SCM_TXTIME: c_int = SO_TXTIME; -pub const SO_BINDTOIFINDEX: c_int = 62; - -cfg_if! { - if #[cfg(linux_time_bits64)] { - const SO_TIMESTAMP_NEW: c_int = 63; - const SO_TIMESTAMPNS_NEW: c_int = 64; - const SO_TIMESTAMPING_NEW: c_int = 65; - - pub const SO_TIMESTAMP: c_int = SO_TIMESTAMP_NEW; - pub const SO_TIMESTAMPNS: c_int = SO_TIMESTAMPNS_NEW; - pub const SO_TIMESTAMPING: c_int = SO_TIMESTAMPING_NEW; - } else { - const SO_TIMESTAMP_OLD: c_int = 29; - const SO_TIMESTAMPNS_OLD: c_int = 35; - const SO_TIMESTAMPING_OLD: c_int = 37; - - pub const SO_TIMESTAMP: c_int = SO_TIMESTAMP_OLD; - pub const SO_TIMESTAMPNS: c_int = SO_TIMESTAMPNS_OLD; - pub const SO_TIMESTAMPING: c_int = SO_TIMESTAMPING_OLD; - } -} - -pub const SO_DETACH_REUSEPORT_BPF: c_int = 68; -pub const SO_PREFER_BUSY_POLL: c_int = 69; -pub const SO_BUSY_POLL_BUDGET: c_int = 70; -pub const SO_NETNS_COOKIE: c_int = 71; -pub const SO_BUF_LOCK: c_int = 72; -pub const SO_RESERVE_MEM: c_int = 73; -pub const SO_TXREHASH: c_int = 74; -pub const SO_RCVMARK: c_int = 75; -pub const SO_PASSPIDFD: c_int = 76; -pub const SO_PEERPIDFD: c_int = 77; -pub const SO_DEVMEM_LINEAR: c_int = 78; -pub const SO_DEVMEM_DMABUF: c_int = 79; -pub const SO_DEVMEM_DONTNEED: c_int = 80; - -// Defined in unix/linux_like/mod.rs -// pub const SCM_TIMESTAMP: c_int = SO_TIMESTAMP; -pub const SCM_TIMESTAMPNS: c_int = SO_TIMESTAMPNS; -pub const SCM_TIMESTAMPING: c_int = SO_TIMESTAMPING; - -pub const SCM_DEVMEM_LINEAR: c_int = SO_DEVMEM_LINEAR; -pub const SCM_DEVMEM_DMABUF: c_int = SO_DEVMEM_DMABUF; - // Ioctl Constants pub const TCGETS: Ioctl = 0x540d; diff --git a/src/unix/linux_like/linux/arch/powerpc/mod.rs b/src/unix/linux_like/linux/arch/powerpc/mod.rs index 1aaa4c7e0597c..257ea1bf5aa4f 100644 --- a/src/unix/linux_like/linux/arch/powerpc/mod.rs +++ b/src/unix/linux_like/linux/arch/powerpc/mod.rs @@ -1,132 +1,6 @@ use crate::prelude::*; use crate::Ioctl; -// arch/powerpc/include/uapi/asm/socket.h - -pub const SOL_SOCKET: c_int = 1; - -// Defined in unix/linux_like/mod.rs -// pub const SO_DEBUG: c_int = 1; -pub const SO_REUSEADDR: c_int = 2; -pub const SO_TYPE: c_int = 3; -pub const SO_ERROR: c_int = 4; -pub const SO_DONTROUTE: c_int = 5; -pub const SO_BROADCAST: c_int = 6; -pub const SO_SNDBUF: c_int = 7; -pub const SO_RCVBUF: c_int = 8; -pub const SO_KEEPALIVE: c_int = 9; -pub const SO_OOBINLINE: c_int = 10; -pub const SO_NO_CHECK: c_int = 11; -pub const SO_PRIORITY: c_int = 12; -pub const SO_LINGER: c_int = 13; -pub const SO_BSDCOMPAT: c_int = 14; -pub const SO_REUSEPORT: c_int = 15; -// powerpc only differs in these -pub const SO_RCVLOWAT: c_int = 16; -pub const SO_SNDLOWAT: c_int = 17; - -cfg_if! { - if #[cfg(linux_time_bits64)] { - const SO_RCVTIMEO_NEW: c_int = 66; - const SO_SNDTIMEO_NEW: c_int = 67; - - pub const SO_RCVTIMEO: c_int = SO_RCVTIMEO_NEW; - pub const SO_SNDTIMEO: c_int = SO_SNDTIMEO_NEW; - } else { - const SO_RCVTIMEO_OLD: c_int = 18; - const SO_SNDTIMEO_OLD: c_int = 19; - - pub const SO_RCVTIMEO: c_int = SO_RCVTIMEO_OLD; - pub const SO_SNDTIMEO: c_int = SO_SNDTIMEO_OLD; - } -} - -pub const SO_PASSCRED: c_int = 20; -pub const SO_PEERCRED: c_int = 21; -// end -pub const SO_SECURITY_AUTHENTICATION: c_int = 22; -pub const SO_SECURITY_ENCRYPTION_TRANSPORT: c_int = 23; -pub const SO_SECURITY_ENCRYPTION_NETWORK: c_int = 24; -pub const SO_BINDTODEVICE: c_int = 25; -pub const SO_ATTACH_FILTER: c_int = 26; -pub const SO_DETACH_FILTER: c_int = 27; -pub const SO_GET_FILTER: c_int = SO_ATTACH_FILTER; -pub const SO_PEERNAME: c_int = 28; -cfg_if! { - if #[cfg(linux_time_bits64)] { - const SO_TIMESTAMP_NEW: c_int = 63; - const SO_TIMESTAMPNS_NEW: c_int = 64; - const SO_TIMESTAMPING_NEW: c_int = 65; - - pub const SO_TIMESTAMP: c_int = SO_TIMESTAMP_NEW; - pub const SO_TIMESTAMPNS: c_int = SO_TIMESTAMPNS_NEW; - pub const SO_TIMESTAMPING: c_int = SO_TIMESTAMPING_NEW; - } else { - const SO_TIMESTAMP_OLD: c_int = 29; - const SO_TIMESTAMPNS_OLD: c_int = 35; - const SO_TIMESTAMPING_OLD: c_int = 37; - - pub const SO_TIMESTAMP: c_int = SO_TIMESTAMP_OLD; - pub const SO_TIMESTAMPNS: c_int = SO_TIMESTAMPNS_OLD; - pub const SO_TIMESTAMPING: c_int = SO_TIMESTAMPING_OLD; - } -} -pub const SO_ACCEPTCONN: c_int = 30; -pub const SO_PEERSEC: c_int = 31; -pub const SO_SNDBUFFORCE: c_int = 32; -pub const SO_RCVBUFFORCE: c_int = 33; -pub const SO_PASSSEC: c_int = 34; -pub const SO_MARK: c_int = 36; -pub const SO_PROTOCOL: c_int = 38; -pub const SO_DOMAIN: c_int = 39; -pub const SO_RXQ_OVFL: c_int = 40; -pub const SO_WIFI_STATUS: c_int = 41; -pub const SCM_WIFI_STATUS: c_int = SO_WIFI_STATUS; -pub const SO_PEEK_OFF: c_int = 42; -pub const SO_NOFCS: c_int = 43; -pub const SO_LOCK_FILTER: c_int = 44; -pub const SO_SELECT_ERR_QUEUE: c_int = 45; -pub const SO_BUSY_POLL: c_int = 46; -pub const SO_MAX_PACING_RATE: c_int = 47; -pub const SO_BPF_EXTENSIONS: c_int = 48; -pub const SO_INCOMING_CPU: c_int = 49; -pub const SO_ATTACH_BPF: c_int = 50; -pub const SO_DETACH_BPF: c_int = SO_DETACH_FILTER; -pub const SO_ATTACH_REUSEPORT_CBPF: c_int = 51; -pub const SO_ATTACH_REUSEPORT_EBPF: c_int = 52; -pub const SO_CNX_ADVICE: c_int = 53; -pub const SCM_TIMESTAMPING_OPT_STATS: c_int = 54; -pub const SO_MEMINFO: c_int = 55; -pub const SO_INCOMING_NAPI_ID: c_int = 56; -pub const SO_COOKIE: c_int = 57; -pub const SCM_TIMESTAMPING_PKTINFO: c_int = 58; -pub const SO_PEERGROUPS: c_int = 59; -pub const SO_ZEROCOPY: c_int = 60; -pub const SO_TXTIME: c_int = 61; -pub const SCM_TXTIME: c_int = SO_TXTIME; -pub const SO_BINDTOIFINDEX: c_int = 62; -pub const SO_DETACH_REUSEPORT_BPF: c_int = 68; -pub const SO_PREFER_BUSY_POLL: c_int = 69; -pub const SO_BUSY_POLL_BUDGET: c_int = 70; -pub const SO_NETNS_COOKIE: c_int = 71; -pub const SO_BUF_LOCK: c_int = 72; -pub const SO_RESERVE_MEM: c_int = 73; -pub const SO_TXREHASH: c_int = 74; -pub const SO_RCVMARK: c_int = 75; -pub const SO_PASSPIDFD: c_int = 76; -pub const SO_PEERPIDFD: c_int = 77; -pub const SO_DEVMEM_LINEAR: c_int = 78; -pub const SO_DEVMEM_DMABUF: c_int = 79; -pub const SO_DEVMEM_DONTNEED: c_int = 80; - -// Defined in unix/linux_like/mod.rs -// pub const SCM_TIMESTAMP: c_int = SO_TIMESTAMP; -pub const SCM_TIMESTAMPNS: c_int = SO_TIMESTAMPNS; -pub const SCM_TIMESTAMPING: c_int = SO_TIMESTAMPING; - -pub const SCM_DEVMEM_LINEAR: c_int = SO_DEVMEM_LINEAR; -pub const SCM_DEVMEM_DMABUF: c_int = SO_DEVMEM_DMABUF; - // Ioctl Constants cfg_if! { diff --git a/src/unix/linux_like/linux/arch/sparc/mod.rs b/src/unix/linux_like/linux/arch/sparc/mod.rs index 42799cdd442e5..6137e39862f75 100644 --- a/src/unix/linux_like/linux/arch/sparc/mod.rs +++ b/src/unix/linux_like/linux/arch/sparc/mod.rs @@ -14,108 +14,6 @@ s! { } } -// arch/sparc/include/uapi/asm/socket.h -pub const SOL_SOCKET: c_int = 0xffff; - -// Defined in unix/linux_like/mod.rs -// pub const SO_DEBUG: c_int = 0x0001; -pub const SO_PASSCRED: c_int = 0x0002; -pub const SO_REUSEADDR: c_int = 0x0004; -pub const SO_KEEPALIVE: c_int = 0x0008; -pub const SO_DONTROUTE: c_int = 0x0010; -pub const SO_BROADCAST: c_int = 0x0020; -pub const SO_PEERCRED: c_int = 0x0040; -pub const SO_LINGER: c_int = 0x0080; -pub const SO_OOBINLINE: c_int = 0x0100; -pub const SO_REUSEPORT: c_int = 0x0200; -pub const SO_BSDCOMPAT: c_int = 0x0400; -pub const SO_RCVLOWAT: c_int = 0x0800; -pub const SO_SNDLOWAT: c_int = 0x1000; -pub const SO_RCVTIMEO: c_int = 0x2000; -pub const SO_SNDTIMEO: c_int = 0x4000; -// pub const SO_RCVTIMEO_OLD: c_int = 0x2000; -// pub const SO_SNDTIMEO_OLD: c_int = 0x4000; -pub const SO_ACCEPTCONN: c_int = 0x8000; -pub const SO_SNDBUF: c_int = 0x1001; -pub const SO_RCVBUF: c_int = 0x1002; -pub const SO_SNDBUFFORCE: c_int = 0x100a; -pub const SO_RCVBUFFORCE: c_int = 0x100b; -pub const SO_ERROR: c_int = 0x1007; -pub const SO_TYPE: c_int = 0x1008; -pub const SO_PROTOCOL: c_int = 0x1028; -pub const SO_DOMAIN: c_int = 0x1029; -pub const SO_NO_CHECK: c_int = 0x000b; -pub const SO_PRIORITY: c_int = 0x000c; -pub const SO_BINDTODEVICE: c_int = 0x000d; -pub const SO_ATTACH_FILTER: c_int = 0x001a; -pub const SO_DETACH_FILTER: c_int = 0x001b; -pub const SO_GET_FILTER: c_int = SO_ATTACH_FILTER; -pub const SO_PEERNAME: c_int = 0x001c; -pub const SO_PEERSEC: c_int = 0x001e; -pub const SO_PASSSEC: c_int = 0x001f; -pub const SO_MARK: c_int = 0x0022; -pub const SO_RXQ_OVFL: c_int = 0x0024; -pub const SO_WIFI_STATUS: c_int = 0x0025; -pub const SCM_WIFI_STATUS: c_int = SO_WIFI_STATUS; -pub const SO_PEEK_OFF: c_int = 0x0026; -pub const SO_NOFCS: c_int = 0x0027; -pub const SO_LOCK_FILTER: c_int = 0x0028; -pub const SO_SELECT_ERR_QUEUE: c_int = 0x0029; -pub const SO_BUSY_POLL: c_int = 0x0030; -pub const SO_MAX_PACING_RATE: c_int = 0x0031; -pub const SO_BPF_EXTENSIONS: c_int = 0x0032; -pub const SO_INCOMING_CPU: c_int = 0x0033; -pub const SO_ATTACH_BPF: c_int = 0x0034; -pub const SO_DETACH_BPF: c_int = SO_DETACH_FILTER; -pub const SO_ATTACH_REUSEPORT_CBPF: c_int = 0x0035; -pub const SO_ATTACH_REUSEPORT_EBPF: c_int = 0x0036; -pub const SO_CNX_ADVICE: c_int = 0x0037; -pub const SCM_TIMESTAMPING_OPT_STATS: c_int = 0x0038; -pub const SO_MEMINFO: c_int = 0x0039; -pub const SO_INCOMING_NAPI_ID: c_int = 0x003a; -pub const SO_COOKIE: c_int = 0x003b; -pub const SCM_TIMESTAMPING_PKTINFO: c_int = 0x003c; -pub const SO_PEERGROUPS: c_int = 0x003d; -pub const SO_ZEROCOPY: c_int = 0x003e; -pub const SO_TXTIME: c_int = 0x003f; -pub const SCM_TXTIME: c_int = SO_TXTIME; -pub const SO_BINDTOIFINDEX: c_int = 0x0041; -pub const SO_SECURITY_AUTHENTICATION: c_int = 0x5001; -pub const SO_SECURITY_ENCRYPTION_TRANSPORT: c_int = 0x5002; -pub const SO_SECURITY_ENCRYPTION_NETWORK: c_int = 0x5004; -pub const SO_TIMESTAMP: c_int = 0x001d; -pub const SO_TIMESTAMPNS: c_int = 0x0021; -pub const SO_TIMESTAMPING: c_int = 0x0023; -// pub const SO_TIMESTAMP_OLD: c_int = 0x001d; -// pub const SO_TIMESTAMPNS_OLD: c_int = 0x0021; -// pub const SO_TIMESTAMPING_OLD: c_int = 0x0023; -// pub const SO_TIMESTAMP_NEW: c_int = 0x0046; -// pub const SO_TIMESTAMPNS_NEW: c_int = 0x0042; -// pub const SO_TIMESTAMPING_NEW: c_int = 0x0043; -// pub const SO_RCVTIMEO_NEW: c_int = 0x0044; -// pub const SO_SNDTIMEO_NEW: c_int = 0x0045; -pub const SO_DETACH_REUSEPORT_BPF: c_int = 0x0047; -pub const SO_PREFER_BUSY_POLL: c_int = 0x0048; -pub const SO_BUSY_POLL_BUDGET: c_int = 0x0049; -pub const SO_NETNS_COOKIE: c_int = 0x0050; -pub const SO_BUF_LOCK: c_int = 0x0051; -pub const SO_RESERVE_MEM: c_int = 0x0052; -pub const SO_TXREHASH: c_int = 0x0053; -pub const SO_RCVMARK: c_int = 0x0054; -pub const SO_PASSPIDFD: c_int = 0x0055; -pub const SO_PEERPIDFD: c_int = 0x0056; -pub const SO_DEVMEM_LINEAR: c_int = 0x0057; -pub const SO_DEVMEM_DMABUF: c_int = 0x0058; -pub const SO_DEVMEM_DONTNEED: c_int = 0x0059; - -// Defined in unix/linux_like/mod.rs -// pub const SCM_TIMESTAMP: c_int = SO_TIMESTAMP; -pub const SCM_TIMESTAMPNS: c_int = SO_TIMESTAMPNS; -pub const SCM_TIMESTAMPING: c_int = SO_TIMESTAMPING; - -pub const SCM_DEVMEM_LINEAR: c_int = SO_DEVMEM_LINEAR; -pub const SCM_DEVMEM_DMABUF: c_int = SO_DEVMEM_DMABUF; - // Ioctl Constants pub const TCGETS: Ioctl = 0x40245408; diff --git a/src/unix/linux_like/mod.rs b/src/unix/linux_like/mod.rs index 8797a0bd354d2..ef18088d0f07e 100644 --- a/src/unix/linux_like/mod.rs +++ b/src/unix/linux_like/mod.rs @@ -762,8 +762,6 @@ pub const MSG_WAITFORONE: c_int = 0x10000; pub const MSG_FASTOPEN: c_int = 0x20000000; pub const MSG_CMSG_CLOEXEC: c_int = 0x40000000; -pub const SCM_TIMESTAMP: c_int = SO_TIMESTAMP; - pub const IP_TOS: c_int = 1; pub const IP_TTL: c_int = 2; pub const IP_HDRINCL: c_int = 3; @@ -1013,8 +1011,6 @@ cfg_if! { } } -pub const SO_DEBUG: c_int = 1; - pub const LOCK_SH: c_int = 1; pub const LOCK_EX: c_int = 2; pub const LOCK_NB: c_int = 4; From d1b504f9138762ada258b20239dafa3bf81780d0 Mon Sep 17 00:00:00 2001 From: drakeo338 Date: Tue, 29 Sep 2026 08:06:58 +0000 Subject: [PATCH 27/33] freebsd: Add `AT_RENAME_*` and `RENAME_*` constants Bind the flags for FreeBSD's `renameat2`. `AT_RENAME_NOREPLACE` and `RENAME_NOREPLACE` first ship in FreeBSD 15.1; `AT_RENAME_EXCHANGE` and `RENAME_EXCHANGE` were merged to stable/15 after releng/15.1 branched, so they first ship in 15.2. libc-test skips each pair below that version. The `AT_RENAME_*` flags are `c_int` like the other FreeBSD `AT_*` flags; the `RENAME_*` aliases are `c_uint`, matching the Linux and Redox bindings and the `unsigned int` flags argument of `renameat2`. Link: https://github.com/freebsd/freebsd-src/blob/96841ea08dcfa84b954a32dc5ae1a26c28966cf4/sys/sys/fcntl.h#L255-L256 Link: https://github.com/freebsd/freebsd-src/commit/e0fe82303f0d8474849103cf77976198380af1a5 (backport ) (cherry picked from commit c2744242b816317ea8b5c8e306eb829c080cb2b9) --- libc-test/build/main.rs | 6 ++++++ libc-test/semver/freebsd.txt | 4 ++++ src/unix/bsd/freebsdlike/freebsd/mod.rs | 4 ++++ 3 files changed, 14 insertions(+) diff --git a/libc-test/build/main.rs b/libc-test/build/main.rs index b73f76452bd5f..51493fb3ef963 100755 --- a/libc-test/build/main.rs +++ b/libc-test/build/main.rs @@ -2808,6 +2808,12 @@ fn test_freebsd(t: &Target) { // These constants were introduced in FreeBSD 13: "O_DSYNC" | "O_PATH" | "O_EMPTY_PATH" | "AT_EMPTY_PATH" => freebsd < (13, 0), + // These constants were introduced in FreeBSD 15.1: + "AT_RENAME_NOREPLACE" | "RENAME_NOREPLACE" => freebsd < (15, 1), + + // These constants were introduced in FreeBSD 15.2: + "AT_RENAME_EXCHANGE" | "RENAME_EXCHANGE" => freebsd < (15, 2), + // These aliases were introduced in FreeBSD 13: // (note however that the constants themselves work on any version) "CLOCK_REALTIME_COARSE" | "CLOCK_MONOTONIC_COARSE" => freebsd < (13, 0), diff --git a/libc-test/semver/freebsd.txt b/libc-test/semver/freebsd.txt index afa4bc555b604..7d1797320a6f9 100644 --- a/libc-test/semver/freebsd.txt +++ b/libc-test/semver/freebsd.txt @@ -108,6 +108,8 @@ AT_PHDR AT_PHENT AT_PHNUM AT_REMOVEDIR +AT_RENAME_EXCHANGE +AT_RENAME_NOREPLACE AT_RESOLVE_BENEATH AT_SYMLINK_FOLLOW AT_SYMLINK_NOFOLLOW @@ -1239,6 +1241,8 @@ REG_NOTEOL REG_PEND REG_STARTEND REG_TRACE +RENAME_EXCHANGE +RENAME_NOREPLACE RFCFDG RFFDG RFLINUXTHPN diff --git a/src/unix/bsd/freebsdlike/freebsd/mod.rs b/src/unix/bsd/freebsdlike/freebsd/mod.rs index bb140f219895a..b1c4305bf4b62 100644 --- a/src/unix/bsd/freebsdlike/freebsd/mod.rs +++ b/src/unix/bsd/freebsdlike/freebsd/mod.rs @@ -3346,6 +3346,10 @@ pub const AT_SYMLINK_FOLLOW: c_int = 0x400; pub const AT_REMOVEDIR: c_int = 0x800; pub const AT_RESOLVE_BENEATH: c_int = 0x2000; pub const AT_EMPTY_PATH: c_int = 0x4000; +pub const AT_RENAME_NOREPLACE: c_int = 0x0001; +pub const AT_RENAME_EXCHANGE: c_int = 0x0002; +pub const RENAME_NOREPLACE: c_uint = AT_RENAME_NOREPLACE as c_uint; +pub const RENAME_EXCHANGE: c_uint = AT_RENAME_EXCHANGE as c_uint; pub const AT_NULL: c_int = 0; pub const AT_IGNORE: c_int = 1; From b37d653e35fcb2848eb75a78359a91817fe508e3 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Wed, 30 Sep 2026 14:25:32 -0500 Subject: [PATCH 28/33] unix, apple: Switch uses of `s!` to `s2!` Give these structs the impls for `Default`. (backport ) (cherry picked from commit e66976af38212b89a60b4f6adb2b905cd549ebff) --- src/unix/bsd/apple/b32/mod.rs | 6 +- src/unix/bsd/apple/b64/aarch64/mod.rs | 4 +- src/unix/bsd/apple/b64/mod.rs | 6 +- src/unix/bsd/apple/b64/x86_64/mod.rs | 6 +- src/unix/bsd/apple/mod.rs | 197 +++++++++++++++++++++++++- src/unix/bsd/mod.rs | 40 +++++- src/unix/mod.rs | 35 ++++- 7 files changed, 275 insertions(+), 19 deletions(-) diff --git a/src/unix/bsd/apple/b32/mod.rs b/src/unix/bsd/apple/b32/mod.rs index f6e861abc3434..c5b66777118c1 100644 --- a/src/unix/bsd/apple/b32/mod.rs +++ b/src/unix/bsd/apple/b32/mod.rs @@ -4,7 +4,8 @@ use crate::prelude::*; pub type boolean_t = c_int; -s! { +s2! { + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct if_data { pub ifi_type: c_uchar, pub ifi_typelen: c_uchar, @@ -37,6 +38,7 @@ s! { pub ifi_reserved2: u32, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 #[cfg(target_os = "macos")] pub struct bpf_hdr { pub bh_tstamp: crate::timeval, @@ -50,7 +52,7 @@ s! { } } -s_no_extra_traits! { +s_no_extra_traits2! { #[repr(align(16))] pub struct max_align_t { priv_: [f64; 2], diff --git a/src/unix/bsd/apple/b64/aarch64/mod.rs b/src/unix/bsd/apple/b64/aarch64/mod.rs index b5cbe8ff5175f..5aefa0abfd648 100644 --- a/src/unix/bsd/apple/b64/aarch64/mod.rs +++ b/src/unix/bsd/apple/b64/aarch64/mod.rs @@ -2,13 +2,13 @@ use crate::prelude::*; pub type boolean_t = c_int; -s! { +s2! { pub struct malloc_zone_t { __private: [crate::uintptr_t; 18], // FIXME(macos): needs arm64 auth pointers support } } -s_no_extra_traits! { +s_no_extra_traits2! { pub struct max_align_t { priv_: f64, } diff --git a/src/unix/bsd/apple/b64/mod.rs b/src/unix/bsd/apple/b64/mod.rs index 541d16e3e5608..fe928f591f10c 100644 --- a/src/unix/bsd/apple/b64/mod.rs +++ b/src/unix/bsd/apple/b64/mod.rs @@ -2,13 +2,14 @@ use crate::prelude::*; -s! { - #[derive(Default)] +s2! { + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct timeval32 { pub tv_sec: i32, pub tv_usec: i32, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct if_data { pub ifi_type: c_uchar, pub ifi_typelen: c_uchar, @@ -41,6 +42,7 @@ s! { pub ifi_reserved2: u32, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 #[cfg(target_os = "macos")] pub struct bpf_hdr { pub bh_tstamp: crate::timeval32, diff --git a/src/unix/bsd/apple/b64/x86_64/mod.rs b/src/unix/bsd/apple/b64/x86_64/mod.rs index dac8c9e3d336d..641e89432e172 100644 --- a/src/unix/bsd/apple/b64/x86_64/mod.rs +++ b/src/unix/bsd/apple/b64/x86_64/mod.rs @@ -2,7 +2,7 @@ use crate::prelude::*; pub type boolean_t = c_uint; -s! { +s2! { pub struct malloc_introspection_t { _private: [crate::uintptr_t; 16], // FIXME(macos): keeping private for now } @@ -34,6 +34,7 @@ s! { ) -> *mut c_void, >, pub destroy: Option, + #[custom_default(ptr::null_mut())] pub zone_name: *const c_char, pub batch_malloc: Option< unsafe extern "C" fn( @@ -50,6 +51,7 @@ s! { num_to_be_freed: c_uint, ), >, + #[custom_default(ptr::null_mut())] pub introspect: *mut malloc_introspection_t, pub version: c_uint, pub memalign: Option< @@ -69,7 +71,7 @@ s! { } } -s_no_extra_traits! { +s_no_extra_traits2! { #[repr(align(16))] pub struct max_align_t { priv_: [f64; 2], diff --git a/src/unix/bsd/apple/mod.rs b/src/unix/bsd/apple/mod.rs index 2a2ee82c060d4..8697759222d2f 100644 --- a/src/unix/bsd/apple/mod.rs +++ b/src/unix/bsd/apple/mod.rs @@ -236,27 +236,32 @@ impl Clone for sysdir_search_path_domain_mask_t { } } -s! { +s2! { + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct ip_mreq { pub imr_multiaddr: in_addr, pub imr_interface: in_addr, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct ip_mreqn { pub imr_multiaddr: in_addr, pub imr_address: in_addr, pub imr_ifindex: c_int, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct ip_mreq_source { pub imr_multiaddr: in_addr, pub imr_sourceaddr: in_addr, pub imr_interface: in_addr, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct aiocb { pub aio_fildes: c_int, pub aio_offset: off_t, + #[custom_default(ptr::null_mut())] pub aio_buf: *mut c_void, pub aio_nbytes: size_t, pub aio_reqprio: c_int, @@ -269,6 +274,7 @@ s! { __unused1: Padding, pub gl_offs: size_t, __unused2: Padding, + #[custom_default(ptr::null_mut())] pub gl_pathv: *mut *mut c_char, __unused3: Padding<*mut c_void>, @@ -280,6 +286,7 @@ s! { __unused8: Padding<*mut c_void>, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct tm { pub tm_sec: c_int, pub tm_min: c_int, @@ -291,20 +298,26 @@ s! { pub tm_yday: c_int, pub tm_isdst: c_int, pub tm_gmtoff: c_long, + #[custom_default(ptr::null_mut())] pub tm_zone: *mut c_char, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct addrinfo { pub ai_flags: c_int, pub ai_family: c_int, pub ai_socktype: c_int, pub ai_protocol: c_int, pub ai_addrlen: crate::socklen_t, + #[custom_default(ptr::null_mut())] pub ai_canonname: *mut c_char, + #[custom_default(ptr::null_mut())] pub ai_addr: *mut crate::sockaddr, + #[custom_default(ptr::null_mut())] pub ai_next: *mut addrinfo, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 #[cfg(target_os = "macos")] #[deprecated(since = "0.2.55", note = "Use the `mach2` crate instead")] pub struct mach_timebase_info { @@ -312,6 +325,7 @@ s! { pub denom: u32, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct stat { pub st_dev: dev_t, pub st_mode: mode_t, @@ -344,12 +358,14 @@ s! { pub si_pid: crate::pid_t, pub si_uid: crate::uid_t, pub si_status: c_int, + #[custom_default(ptr::null_mut())] pub si_addr: *mut c_void, //Requires it to be union for tests //pub si_value: crate::sigval, _pad: Padding<[usize; 9]>, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct sigaction { // FIXME(union): this field is actually a union pub sa_sigaction: crate::sighandler_t, @@ -357,12 +373,15 @@ s! { pub sa_flags: c_int, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct stack_t { + #[custom_default(ptr::null_mut())] pub ss_sp: *mut c_void, pub ss_size: size_t, pub ss_flags: c_int, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct fstore_t { pub fst_flags: c_uint, pub fst_posmode: c_int, @@ -371,6 +390,7 @@ s! { pub fst_bytesalloc: off_t, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct fpunchhole_t { pub fp_flags: c_uint, /* unused */ pub reserved: c_uint, /* (to maintain 8-byte alignment) */ @@ -378,11 +398,13 @@ s! { pub fp_length: off_t, /* IN: size of the region */ } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct ftrimactivefile_t { pub fta_offset: off_t, pub fta_length: off_t, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct fspecread_t { pub fsr_flags: c_uint, pub reserved: c_uint, @@ -390,11 +412,13 @@ s! { pub fsr_length: off_t, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct radvisory { pub ra_offset: off_t, pub ra_count: c_int, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct statvfs { pub f_bsize: c_ulong, pub f_frsize: c_ulong, @@ -409,13 +433,19 @@ s! { pub f_namemax: c_ulong, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct Dl_info { + #[custom_default(ptr::null_mut())] pub dli_fname: *const c_char, + #[custom_default(ptr::null_mut())] pub dli_fbase: *mut c_void, + #[custom_default(ptr::null_mut())] pub dli_sname: *const c_char, + #[custom_default(ptr::null_mut())] pub dli_saddr: *mut c_void, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct sockaddr_in { pub sin_len: u8, pub sin_family: crate::sa_family_t, @@ -424,6 +454,7 @@ s! { pub sin_zero: [c_char; 8], } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct kevent64_s { pub ident: u64, pub filter: i16, @@ -434,6 +465,7 @@ s! { pub ext: [u64; 2], } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct dqblk { pub dqb_bhardlimit: u64, pub dqb_bsoftlimit: u64, @@ -447,6 +479,7 @@ s! { pub dqb_spare: [u32; 4], } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct if_msghdr { pub ifm_msglen: c_ushort, pub ifm_version: c_uchar, @@ -457,6 +490,7 @@ s! { pub ifm_data: if_data, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct ifa_msghdr { pub ifam_msglen: c_ushort, pub ifam_version: c_uchar, @@ -467,6 +501,7 @@ s! { pub ifam_metric: c_int, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct ifma_msghdr { pub ifmam_msglen: c_ushort, pub ifmam_version: c_uchar, @@ -476,6 +511,7 @@ s! { pub ifmam_index: c_ushort, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct ifma_msghdr2 { pub ifmam_msglen: c_ushort, pub ifmam_version: c_uchar, @@ -487,6 +523,7 @@ s! { } #[cfg(target_os = "macos")] + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct rt_metrics { pub rmx_locks: u32, pub rmx_mtu: u32, @@ -504,6 +541,7 @@ s! { pub rmx_filler: [u32; 3], } + #[exhaustive] // FIXME(exhaustive): review for 1.0 #[cfg(target_os = "macos")] pub struct rt_msghdr { pub rtm_msglen: c_ushort, @@ -520,6 +558,7 @@ s! { pub rtm_rmx: rt_metrics, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 #[cfg(target_os = "macos")] pub struct rt_msghdr2 { pub rtm_msglen: c_ushort, @@ -536,6 +575,7 @@ s! { pub rtm_rmx: rt_metrics, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct termios { pub c_iflag: crate::tcflag_t, pub c_oflag: crate::tcflag_t, @@ -546,6 +586,7 @@ s! { pub c_ospeed: crate::speed_t, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct flock { pub l_start: off_t, pub l_len: off_t, @@ -554,23 +595,37 @@ s! { pub l_whence: c_short, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct sf_hdtr { + #[custom_default(ptr::null_mut())] pub headers: *mut crate::iovec, pub hdr_cnt: c_int, + #[custom_default(ptr::null_mut())] pub trailers: *mut crate::iovec, pub trl_cnt: c_int, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct lconv { + #[custom_default(ptr::null_mut())] pub decimal_point: *mut c_char, + #[custom_default(ptr::null_mut())] pub thousands_sep: *mut c_char, + #[custom_default(ptr::null_mut())] pub grouping: *mut c_char, + #[custom_default(ptr::null_mut())] pub int_curr_symbol: *mut c_char, + #[custom_default(ptr::null_mut())] pub currency_symbol: *mut c_char, + #[custom_default(ptr::null_mut())] pub mon_decimal_point: *mut c_char, + #[custom_default(ptr::null_mut())] pub mon_thousands_sep: *mut c_char, + #[custom_default(ptr::null_mut())] pub mon_grouping: *mut c_char, + #[custom_default(ptr::null_mut())] pub positive_sign: *mut c_char, + #[custom_default(ptr::null_mut())] pub negative_sign: *mut c_char, pub int_frac_digits: c_char, pub frac_digits: c_char, @@ -588,6 +643,7 @@ s! { pub int_n_sign_posn: c_char, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 #[cfg(target_os = "macos")] pub struct proc_taskinfo { pub pti_virtual_size: u64, @@ -610,6 +666,7 @@ s! { pub pti_priority: i32, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 #[cfg(target_os = "macos")] pub struct proc_bsdinfo { pub pbi_flags: u32, @@ -666,12 +723,14 @@ s! { pbsi_rfu: Padding, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 #[cfg(target_os = "macos")] pub struct proc_taskallinfo { pub pbsd: proc_bsdinfo, pub ptinfo: proc_taskinfo, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct xsw_usage { pub xsu_total: u64, pub xsu_avail: u64, @@ -680,6 +739,7 @@ s! { pub xsu_encrypted: crate::boolean_t, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct xucred { pub cr_version: c_uint, pub cr_uid: crate::uid_t, @@ -687,6 +747,7 @@ s! { pub cr_groups: [crate::gid_t; 16], } + #[exhaustive] // FIXME(exhaustive): review for 1.0 #[cfg(target_os = "macos")] #[deprecated(since = "0.2.55", note = "Use the `mach2` crate instead")] pub struct mach_header { @@ -699,6 +760,7 @@ s! { pub flags: u32, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 #[cfg(target_os = "macos")] #[deprecated(since = "0.2.55", note = "Use the `mach2` crate instead")] pub struct mach_header_64 { @@ -712,6 +774,7 @@ s! { pub reserved: u32, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct segment_command { pub cmd: u32, pub cmdsize: u32, @@ -726,6 +789,7 @@ s! { pub flags: u32, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct segment_command_64 { pub cmd: u32, pub cmdsize: u32, @@ -740,11 +804,13 @@ s! { pub flags: u32, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct load_command { pub cmd: u32, pub cmdsize: u32, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct sockaddr_dl { pub sdl_len: c_uchar, pub sdl_family: c_uchar, @@ -756,6 +822,7 @@ s! { pub sdl_data: [c_char; 12], } + #[exhaustive] // FIXME(exhaustive): review for 1.0 #[cfg(target_os = "macos")] pub struct sockaddr_inarp { pub sin_len: c_uchar, @@ -767,6 +834,7 @@ s! { pub sin_other: c_ushort, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 #[cfg(target_os = "macos")] pub struct sockaddr_ctl { pub sc_len: c_uchar, @@ -777,12 +845,14 @@ s! { pub sc_reserved: [u32; 5], } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct in_pktinfo { pub ipi_ifindex: c_uint, pub ipi_spec_dst: crate::in_addr, pub ipi_addr: crate::in_addr, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct in6_pktinfo { pub ipi6_addr: crate::in6_addr, pub ipi6_ifindex: c_uint, @@ -790,6 +860,7 @@ s! { // sys/ipc.h: + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct ipc_perm { pub uid: crate::uid_t, pub gid: crate::gid_t, @@ -801,6 +872,7 @@ s! { } // sys/sem.h + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct sembuf { pub sem_num: c_ushort, pub sem_op: c_short, @@ -808,6 +880,7 @@ s! { } // sys/if_arp.h + #[exhaustive] // FIXME(exhaustive): review for 1.0 #[cfg(target_os = "macos")] pub struct arphdr { pub ar_hrd: u16, @@ -817,11 +890,13 @@ s! { pub ar_op: u16, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct in_addr { pub s_addr: crate::in_addr_t, } // net/ndrv.h + #[exhaustive] // FIXME(exhaustive): review for 1.0 #[cfg(target_os = "macos")] pub struct sockaddr_ndrv { pub snd_len: c_uchar, @@ -831,14 +906,18 @@ s! { // sys/socket.h + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct sa_endpoints_t { - pub sae_srcif: c_uint, // optional source interface + pub sae_srcif: c_uint, // optional source interface + #[custom_default(ptr::null_mut())] pub sae_srcaddr: *const crate::sockaddr, // optional source address - pub sae_srcaddrlen: crate::socklen_t, // size of source address + pub sae_srcaddrlen: crate::socklen_t, // size of source address + #[custom_default(ptr::null_mut())] pub sae_dstaddr: *const crate::sockaddr, // destination address - pub sae_dstaddrlen: crate::socklen_t, // size of destination address + pub sae_dstaddrlen: crate::socklen_t, // size of destination address } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct timex { pub modes: c_uint, pub offset: c_long, @@ -859,6 +938,7 @@ s! { pub stbcnt: c_long, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct ntptimeval { pub time: crate::timespec, pub maxerror: c_long, @@ -867,14 +947,17 @@ s! { pub time_state: c_int, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct thread_standard_policy { pub no_data: natural_t, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct thread_extended_policy { pub timeshare: boolean_t, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct thread_time_constraint_policy { pub period: u32, pub computation: u32, @@ -882,27 +965,33 @@ s! { pub preemptible: boolean_t, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct thread_precedence_policy { pub importance: integer_t, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct thread_affinity_policy { pub affinity_tag: integer_t, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct thread_background_policy { pub priority: integer_t, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct thread_latency_qos_policy { pub thread_latency_qos_tier: thread_latency_qos_t, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct thread_throughput_qos_policy { pub thread_throughput_qos_tier: thread_throughput_qos_t, } // malloc/malloc.h + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct malloc_statistics_t { pub blocks_in_use: c_uint, pub size_in_use: size_t, @@ -910,6 +999,7 @@ s! { pub size_allocated: size_t, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct mstats { pub bytes_total: size_t, pub chunks_used: size_t, @@ -918,11 +1008,13 @@ s! { pub bytes_free: size_t, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct vm_range_t { pub address: crate::vm_address_t, pub size: crate::vm_size_t, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 #[cfg(target_os = "macos")] pub struct vinfo_stat { pub vst_dev: u32, @@ -948,6 +1040,7 @@ s! { pub vst_qspare: [i64; 2], } + #[exhaustive] // FIXME(exhaustive): review for 1.0 #[cfg(target_os = "macos")] pub struct vnode_info { pub vi_stat: vinfo_stat, @@ -956,6 +1049,7 @@ s! { pub vi_fsid: crate::fsid_t, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 #[cfg(target_os = "macos")] pub struct vnode_info_path { pub vip_vi: vnode_info, @@ -964,12 +1058,14 @@ s! { pub vip_path: [[c_char; 32]; 32], } + #[exhaustive] // FIXME(exhaustive): review for 1.0 #[cfg(target_os = "macos")] pub struct proc_vnodepathinfo { pub pvi_cdir: vnode_info_path, pub pvi_rdir: vnode_info_path, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct vm_statistics { pub free_count: natural_t, pub active_count: natural_t, @@ -988,11 +1084,13 @@ s! { pub speculative_count: natural_t, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct task_thread_times_info { pub user_time: time_value_t, pub system_time: time_value_t, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct rusage_info_v0 { pub ri_uuid: [u8; 16], pub ri_user_time: u64, @@ -1007,6 +1105,7 @@ s! { pub ri_proc_exit_abstime: u64, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct rusage_info_v1 { pub ri_uuid: [u8; 16], pub ri_user_time: u64, @@ -1027,6 +1126,7 @@ s! { pub ri_child_elapsed_abstime: u64, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct rusage_info_v2 { pub ri_uuid: [u8; 16], pub ri_user_time: u64, @@ -1049,6 +1149,7 @@ s! { pub ri_diskio_byteswritten: u64, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct rusage_info_v3 { pub ri_uuid: [u8; 16], pub ri_user_time: u64, @@ -1080,6 +1181,7 @@ s! { pub ri_serviced_system_time: u64, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct rusage_info_v4 { pub ri_uuid: [u8; 16], pub ri_user_time: u64, @@ -1119,11 +1221,13 @@ s! { pub ri_runnable_time: u64, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct image_offset { pub uuid: crate::uuid_t, pub offset: u32, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct attrlist { pub bitmapcount: c_ushort, pub reserved: u16, @@ -1134,16 +1238,19 @@ s! { pub forkattr: attrgroup_t, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct attrreference_t { pub attr_dataoffset: i32, pub attr_length: u32, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct vol_capabilities_attr_t { pub capabilities: vol_capabilities_set_t, pub valid: vol_capabilities_set_t, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct attribute_set_t { pub commonattr: attrgroup_t, pub volattr: attrgroup_t, @@ -1152,6 +1259,7 @@ s! { pub forkattr: attrgroup_t, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct vol_attributes_attr_t { pub validattr: attribute_set_t, pub nativeattr: attribute_set_t, @@ -1200,6 +1308,7 @@ s! { pub tcpi_rxretransmitpackets: u64, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 #[cfg(target_os = "macos")] pub struct in6_addrlifetime { pub ia6t_expire: time_t, @@ -1208,6 +1317,7 @@ s! { pub ia6t_pltime: u32, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 #[cfg(target_os = "macos")] pub struct in6_ifstat { pub ifs6_in_receive: crate::u_quad_t, @@ -1237,6 +1347,7 @@ s! { pub ifs6_defrtr_expiry_cnt: crate::u_quad_t, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 #[cfg(target_os = "macos")] pub struct icmp6_ifstat { pub ifs6_in_msg: crate::u_quad_t, @@ -1276,11 +1387,13 @@ s! { } // mach/host_info.h + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct host_cpu_load_info { pub cpu_ticks: [crate::natural_t; CPU_STATE_MAX as usize], } // net/if_mib.h + #[exhaustive] // FIXME(exhaustive): review for 1.0 #[cfg(target_os = "macos")] pub struct ifmibdata { /// Name of interface @@ -1301,6 +1414,7 @@ s! { pub ifmd_data: if_data64, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 #[cfg(target_os = "macos")] pub struct ifs_iso_8802_3 { pub dot3StatsAlignmentErrors: u32, @@ -1322,19 +1436,23 @@ s! { } // kern_control.h + #[exhaustive] // FIXME(exhaustive): review for 1.0 #[cfg(target_os = "macos")] pub struct ctl_info { pub ctl_id: u32, + #[custom_default([0; MAX_KCTL_NAME])] pub ctl_name: [c_char; MAX_KCTL_NAME], } // sys/proc_info.h + #[exhaustive] // FIXME(exhaustive): review for 1.0 #[cfg(target_os = "macos")] pub struct proc_fdinfo { pub proc_fd: i32, pub proc_fdtype: u32, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 #[repr(packed(4))] pub struct kevent { pub ident: crate::uintptr_t, @@ -1342,9 +1460,11 @@ s! { pub flags: u16, pub fflags: u32, pub data: intptr_t, + #[custom_default(ptr::null_mut())] pub udata: *mut c_void, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 #[repr(packed(4))] pub struct semid_ds { // Note the manpage shows different types than the system header. @@ -1358,6 +1478,7 @@ s! { pub sem_pad3: [i32; 4], } + #[exhaustive] // FIXME(exhaustive): review for 1.0 #[repr(packed(4))] pub struct shmid_ds { pub shm_perm: ipc_perm, @@ -1369,9 +1490,11 @@ s! { pub shm_dtime: crate::time_t, // FIXME(macos): 64-bit wrong align => wrong offset pub shm_ctime: crate::time_t, // FIXME(macos): 64-bit wrong align => wrong offset // FIXME: 64-bit wrong align => wrong offset: + #[custom_default(ptr::null_mut())] pub shm_internal: *mut c_void, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 #[cfg(target_os = "macos")] pub struct proc_threadinfo { pub pth_user_time: u64, @@ -1384,9 +1507,11 @@ s! { pub pth_curpri: i32, pub pth_priority: i32, pub pth_maxpriority: i32, + #[custom_default([0; MAXTHREADNAMESIZE])] pub pth_name: [c_char; MAXTHREADNAMESIZE], } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct statfs { pub f_bsize: u32, pub f_iosize: i32, @@ -1400,19 +1525,24 @@ s! { pub f_type: u32, pub f_flags: u32, pub f_fssubtype: u32, + #[custom_default([0; 16])] pub f_fstypename: [c_char; 16], + #[custom_default([0; 1024])] pub f_mntonname: [c_char; 1024], + #[custom_default([0; 1024])] pub f_mntfromname: [c_char; 1024], pub f_flags_ext: u32, pub f_reserved: [u32; 7], } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct dirent { pub d_ino: u64, pub d_seekoff: u64, pub d_reclen: u16, pub d_namlen: u16, pub d_type: u8, + #[custom_default([0; 1024])] pub d_name: [c_char; 1024], } @@ -1421,16 +1551,19 @@ s! { pub ss_family: crate::sa_family_t, __ss_pad1: Padding<[u8; 6]>, __ss_align: i64, + #[custom_default(Padding::new([0; 112]))] __ss_pad2: Padding<[u8; 112]>, } // netinet/in.h: RFC 3678 multicast group membership requests. + #[exhaustive] // FIXME(exhaustive): review for 1.0 #[repr(packed(4))] pub struct group_req { pub gr_interface: u32, pub gr_group: crate::sockaddr_storage, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 #[repr(packed(4))] pub struct group_source_req { pub gsr_interface: u32, @@ -1439,12 +1572,14 @@ s! { } pub struct utmpx { + #[custom_default([0; _UTX_USERSIZE])] pub ut_user: [c_char; _UTX_USERSIZE], pub ut_id: [c_char; _UTX_IDSIZE], pub ut_line: [c_char; _UTX_LINESIZE], pub ut_pid: crate::pid_t, pub ut_type: c_short, pub ut_tv: crate::timeval, + #[custom_default([0; _UTX_HOSTSIZE])] pub ut_host: [c_char; _UTX_HOSTSIZE], ut_pad: Padding<[u32; 16]>, } @@ -1454,13 +1589,16 @@ s! { pub sigev_signo: c_int, pub sigev_value: crate::sigval, __unused1: Padding<*mut c_void>, //actually a function pointer + #[custom_default(ptr::null_mut())] pub sigev_notify_attributes: *mut crate::pthread_attr_t, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct processor_cpu_load_info { pub cpu_ticks: [c_uint; CPU_STATE_MAX as usize], } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct processor_basic_info { pub cpu_type: cpu_type_t, pub cpu_subtype: cpu_subtype_t, @@ -1469,11 +1607,13 @@ s! { pub is_master: crate::boolean_t, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct processor_set_basic_info { pub processor_count: c_int, pub default_policy: c_int, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct processor_set_load_info { pub task_count: c_int, pub thread_count: c_int, @@ -1481,11 +1621,13 @@ s! { pub mach_factor: integer_t, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct time_value_t { pub seconds: integer_t, pub microseconds: integer_t, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct thread_basic_info { pub user_time: time_value_t, pub system_time: time_value_t, @@ -1497,12 +1639,14 @@ s! { pub sleep_time: crate::integer_t, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct thread_identifier_info { pub thread_id: u64, pub thread_handle: u64, pub dispatch_qaddr: u64, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct thread_extended_info { pub pth_user_time: u64, pub pth_system_time: u64, @@ -1514,9 +1658,11 @@ s! { pub pth_curpri: i32, pub pth_priority: i32, pub pth_maxpriority: i32, + #[custom_default([0; MAXTHREADNAMESIZE])] pub pth_name: [c_char; MAXTHREADNAMESIZE], } + #[exhaustive] // FIXME(exhaustive): review for 1.0 #[repr(packed(4))] pub struct if_data64 { pub ifi_type: c_uchar, @@ -1549,6 +1695,7 @@ s! { pub ifi_lastchange: timeval32, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 #[repr(packed(4))] pub struct if_msghdr2 { pub ifm_msglen: c_ushort, @@ -1564,6 +1711,7 @@ s! { pub ifm_data: if_data64, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 #[repr(packed(8))] pub struct vm_statistics64 { pub free_count: natural_t, @@ -1625,6 +1773,7 @@ s! { pub phantom_ghosts_added: u64, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 #[repr(packed(4))] pub struct mach_task_basic_info { pub virtual_size: mach_vm_size_t, @@ -1636,6 +1785,7 @@ s! { pub suspend_count: integer_t, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 #[repr(packed(4))] pub struct log2phys { pub l2p_flags: c_uint, @@ -1647,6 +1797,7 @@ s! { _os_unfair_lock_opaque: u32, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 #[repr(packed(1))] pub struct sockaddr_vm { pub svm_len: c_uchar, @@ -1656,12 +1807,14 @@ s! { pub svm_cid: c_uint, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct ifdevmtu { pub ifdm_current: c_int, pub ifdm_min: c_int, pub ifdm_max: c_int, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 #[repr(packed(4))] pub struct ifkpi { pub ifk_module_id: c_uint, @@ -1669,11 +1822,13 @@ s! { pub ifk_data: __c_anonymous_ifk_data, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct ifreq { pub ifr_name: [c_char; crate::IFNAMSIZ], pub ifr_ifru: __c_anonymous_ifr_ifru, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 #[cfg(target_os = "macos")] pub struct in6_ifreq { pub ifr_name: [c_char; crate::IFNAMSIZ], @@ -1681,12 +1836,14 @@ s! { } } -s_no_extra_traits! { +s_no_extra_traits2! { + #[exhaustive] // FIXME(exhaustive): review for 1.0 #[repr(packed(4))] pub struct ifconf { pub ifc_len: c_int, pub ifc_ifcu: __c_anonymous_ifc_ifcu, } + pub union __c_anonymous_ifk_data { pub ifk_ptr: *mut c_void, pub ifk_value: c_int, @@ -1717,9 +1874,27 @@ s_no_extra_traits! { } } +impl Default for __c_anonymous_ifk_data { + fn default() -> Self { + unsafe { mem::zeroed() } + } +} + +impl Default for __c_anonymous_ifr_ifru { + fn default() -> Self { + unsafe { mem::zeroed() } + } +} + +impl Default for __c_anonymous_ifc_ifcu { + fn default() -> Self { + unsafe { mem::zeroed() } + } +} + cfg_if! { if #[cfg(target_os = "macos")] { - s_no_extra_traits! { + s_no_extra_traits2! { pub union __c_anonymous_ifr_ifru6 { pub ifru_addr: crate::sockaddr_in6, pub ifru_dstaddr: crate::sockaddr_in6, @@ -1737,6 +1912,13 @@ cfg_if! { } } +#[cfg(target_os = "macos")] +impl Default for __c_anonymous_ifr_ifru6 { + fn default() -> Self { + unsafe { mem::zeroed() } + } +} + impl siginfo_t { pub unsafe fn si_addr(&self) -> *mut c_void { self.si_addr @@ -1771,7 +1953,7 @@ impl siginfo_t { } } -s_no_extra_traits! { +s_no_extra_traits2! { pub union semun { pub val: c_int, pub buf: *mut semid_ds, @@ -3240,6 +3422,7 @@ pub const _CS_DARWIN_USER_CACHE_DIR: c_int = 65538; pub const OS_UNFAIR_LOCK_INIT: os_unfair_lock = os_unfair_lock { _os_unfair_lock_opaque: 0, + __non_exhaustive: (), }; pub const OS_LOG_TYPE_DEFAULT: crate::os_log_type_t = 0x00; diff --git a/src/unix/bsd/mod.rs b/src/unix/bsd/mod.rs index 1b8f58d294d23..ecb49b75e795d 100644 --- a/src/unix/bsd/mod.rs +++ b/src/unix/bsd/mod.rs @@ -12,13 +12,15 @@ pub type regoff_t = c_int; #[cfg(not(target_os = "dragonfly"))] pub type regoff_t = off_t; -s! { +s2! { + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct sockaddr { pub sa_len: u8, pub sa_family: sa_family_t, pub sa_data: [c_char; 14], } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct sockaddr_in6 { pub sin6_len: u8, pub sin6_family: sa_family_t, @@ -28,15 +30,22 @@ s! { pub sin6_scope_id: u32, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct passwd { + #[custom_default(ptr::null_mut())] pub pw_name: *mut c_char, + #[custom_default(ptr::null_mut())] pub pw_passwd: *mut c_char, pub pw_uid: crate::uid_t, pub pw_gid: crate::gid_t, pub pw_change: crate::time_t, + #[custom_default(ptr::null_mut())] pub pw_class: *mut c_char, + #[custom_default(ptr::null_mut())] pub pw_gecos: *mut c_char, + #[custom_default(ptr::null_mut())] pub pw_dir: *mut c_char, + #[custom_default(ptr::null_mut())] pub pw_shell: *mut c_char, pub pw_expire: crate::time_t, @@ -44,13 +53,20 @@ s! { pub pw_fields: c_int, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct ifaddrs { + #[custom_default(ptr::null_mut())] pub ifa_next: *mut ifaddrs, + #[custom_default(ptr::null_mut())] pub ifa_name: *mut c_char, pub ifa_flags: c_uint, + #[custom_default(ptr::null_mut())] pub ifa_addr: *mut crate::sockaddr, + #[custom_default(ptr::null_mut())] pub ifa_netmask: *mut crate::sockaddr, + #[custom_default(ptr::null_mut())] pub ifa_dstaddr: *mut crate::sockaddr, + #[custom_default(ptr::null_mut())] pub ifa_data: *mut c_void, #[cfg(any(target_os = "dragonfly", target_os = "netbsd"))] pub ifa_addrflags: c_uint, @@ -69,16 +85,21 @@ s! { fds_bits: [i32; FD_SETSIZE as usize / 32], } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct msghdr { + #[custom_default(ptr::null_mut())] pub msg_name: *mut c_void, pub msg_namelen: crate::socklen_t, + #[custom_default(ptr::null_mut())] pub msg_iov: *mut crate::iovec, pub msg_iovlen: c_int, + #[custom_default(ptr::null_mut())] pub msg_control: *mut c_void, pub msg_controllen: crate::socklen_t, pub msg_flags: c_int, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct cmsghdr { pub cmsg_len: crate::socklen_t, pub cmsg_level: c_int, @@ -89,52 +110,69 @@ s! { __fsid_val: [i32; 2], } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct if_nameindex { pub if_index: c_uint, + #[custom_default(ptr::null_mut())] pub if_name: *mut c_char, } pub struct regex_t { __re_magic: c_int, __re_nsub: size_t, + #[custom_default(ptr::null_mut())] __re_endp: *const c_char, + #[custom_default(ptr::null_mut())] __re_g: *mut c_void, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct regmatch_t { pub rm_so: regoff_t, pub rm_eo: regoff_t, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct option { + #[custom_default(ptr::null_mut())] pub name: *const c_char, pub has_arg: c_int, + #[custom_default(ptr::null_mut())] pub flag: *mut c_int, pub val: c_int, } + + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct sockaddr_un { pub sun_len: u8, pub sun_family: sa_family_t, + #[custom_default([0; 104])] pub sun_path: [c_char; 104], } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct utsname { + #[custom_default([0; 256])] #[cfg(not(target_os = "dragonfly"))] pub sysname: [c_char; 256], #[cfg(target_os = "dragonfly")] pub sysname: [c_char; 32], + #[custom_default([0; 256])] #[cfg(not(target_os = "dragonfly"))] pub nodename: [c_char; 256], #[cfg(target_os = "dragonfly")] pub nodename: [c_char; 32], + #[custom_default([0; 256])] #[cfg(not(target_os = "dragonfly"))] pub release: [c_char; 256], #[cfg(target_os = "dragonfly")] pub release: [c_char; 32], + #[custom_default([0; 256])] #[cfg(not(target_os = "dragonfly"))] pub version: [c_char; 256], #[cfg(target_os = "dragonfly")] pub version: [c_char; 32], + #[custom_default([0; 256])] #[cfg(not(target_os = "dragonfly"))] pub machine: [c_char; 256], #[cfg(target_os = "dragonfly")] diff --git a/src/unix/mod.rs b/src/unix/mod.rs index d4823d76bc6ad..62d48c9eb8692 100644 --- a/src/unix/mod.rs +++ b/src/unix/mod.rs @@ -49,20 +49,25 @@ unsafe impl Sync for DIR {} #[cfg(not(target_os = "nuttx"))] pub type locale_t = *mut c_void; -s! { +s2! { + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct group { + #[custom_default(ptr::null_mut())] pub gr_name: *mut c_char, + #[custom_default(ptr::null_mut())] pub gr_passwd: *mut c_char, pub gr_gid: crate::gid_t, + #[custom_default(ptr::null_mut())] pub gr_mem: *mut *mut c_char, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct utimbuf { pub actime: time_t, pub modtime: time_t, } - #[derive(Default)] + #[exhaustive] // This one is not likely to ever change pub struct timeval { pub tv_sec: time_t, #[cfg(not(gnu_time_bits64))] @@ -75,7 +80,7 @@ s! { // linux x32 compatibility // See https://sourceware.org/bugzilla/show_bug.cgi?id=16437 - #[derive(Default)] + #[exhaustive] // FIXME(exhaustive): review for 1.0 #[cfg(not(target_env = "gnu"))] pub struct timespec { pub tv_sec: time_t, @@ -89,11 +94,13 @@ s! { __pad0: Padding, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct rlimit { pub rlim_cur: rlim_t, pub rlim_max: rlim_t, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct rusage { pub ru_utime: timeval, pub ru_stime: timeval, @@ -144,6 +151,7 @@ s! { __reserved: Padding<[c_long; 16]>, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 #[cfg(not(target_os = "nuttx"))] pub struct ipv6_mreq { pub ipv6mr_multiaddr: in6_addr, @@ -153,20 +161,27 @@ s! { pub ipv6mr_interface: c_uint, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 #[cfg(all(not(target_os = "cygwin"), not(target_os = "horizon")))] pub struct hostent { + #[custom_default(ptr::null_mut())] pub h_name: *mut c_char, + #[custom_default(ptr::null_mut())] pub h_aliases: *mut *mut c_char, pub h_addrtype: c_int, pub h_length: c_int, + #[custom_default(ptr::null_mut())] pub h_addr_list: *mut *mut c_char, } + #[exhaustive] // Shouldn't ever change pub struct iovec { + #[custom_default(ptr::null_mut())] pub iov_base: *mut c_void, pub iov_len: size_t, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 #[cfg(not(target_os = "horizon"))] pub struct pollfd { pub fd: c_int, @@ -174,6 +189,7 @@ s! { pub revents: c_short, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct winsize { pub ws_row: c_ushort, pub ws_col: c_ushort, @@ -181,24 +197,29 @@ s! { pub ws_ypixel: c_ushort, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 #[cfg(not(target_os = "cygwin"))] pub struct linger { pub l_onoff: c_int, pub l_linger: c_int, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct sigval { // Actually a union of an int and a void* + #[custom_default(ptr::null_mut())] pub sival_ptr: *mut c_void, } // + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct itimerval { pub it_interval: crate::timeval, pub it_value: crate::timeval, } // + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct tms { pub tms_utime: crate::clock_t, pub tms_stime: crate::clock_t, @@ -206,18 +227,25 @@ s! { pub tms_cstime: crate::clock_t, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct servent { + #[custom_default(ptr::null_mut())] pub s_name: *mut c_char, + #[custom_default(ptr::null_mut())] pub s_aliases: *mut *mut c_char, #[cfg(target_os = "cygwin")] pub s_port: c_short, #[cfg(not(target_os = "cygwin"))] pub s_port: c_int, + #[custom_default(ptr::null_mut())] pub s_proto: *mut c_char, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct protoent { + #[custom_default(ptr::null_mut())] pub p_name: *mut c_char, + #[custom_default(ptr::null_mut())] pub p_aliases: *mut *mut c_char, #[cfg(not(target_os = "cygwin"))] pub p_proto: c_int, @@ -225,6 +253,7 @@ s! { pub p_proto: c_short, } + #[exhaustive] // FIXME(exhaustive): review for 1.0 #[repr(align(4))] pub struct in6_addr { pub s6_addr: [u8; 16], From 0c4f7d3dd0f2ea0359e3cdc2536173b3f06320d2 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Wed, 30 Sep 2026 15:42:28 -0500 Subject: [PATCH 29/33] macros: Perform some mild simplification of patterns Add commas to look more like struct syntax and remove `{ }` around literals. (backport ) (cherry picked from commit 8c1d1ec086c9494b03c43a87965c8a8d0c367413) --- src/macros.rs | 320 +++++++++++++++++++++++++------------------------- 1 file changed, 160 insertions(+), 160 deletions(-) diff --git a/src/macros.rs b/src/macros.rs index 72dea31b8a515..82ab40bd299a6 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -370,73 +370,73 @@ macro_rules! union_with_debug { $vis:vis union $name:ident { $($body:tt)* } ) => { union_with_debug! { - @split_attrs - cfg_attrs: { } - other_attrs: { } - remaining_attrs: { $(#$attr)* } - vis: { $vis } - name: { $name } - body: { $($body)* } + @split_attrs, + cfg_attrs: { }, + other_attrs: { }, + remaining_attrs: { $(#$attr)* }, + vis: $vis, + name: $name, + body: { $($body)* }, } }; // a `cfg` also has to gate the impl ( - @split_attrs - cfg_attrs: { $($cfg_attrs:tt)* } - other_attrs: { $($other_attrs:tt)* } + @split_attrs, + cfg_attrs: { $($cfg_attrs:tt)* }, + other_attrs: { $($other_attrs:tt)* }, remaining_attrs: { #[cfg($($cfg:tt)*)] $($tail:tt)* - } - vis: { $vis:vis } - name: { $name:ident } - body: { $($body:tt)* } + }, + vis: $vis:vis, + name: $name:ident, + body: { $($body:tt)* }, ) => { union_with_debug! { - @split_attrs - cfg_attrs: { $($cfg_attrs)* #[cfg($($cfg)*)] } - other_attrs: { $($other_attrs)* } - remaining_attrs: { $($tail)* } - vis: { $vis } - name: { $name } - body: { $($body)* } + @split_attrs, + cfg_attrs: { $($cfg_attrs)* #[cfg($($cfg)*)] }, + other_attrs: { $($other_attrs)* }, + remaining_attrs: { $($tail)* }, + vis: $vis, + name: $name, + body: { $($body)* }, } }; // anything else belongs to the union only ( - @split_attrs - cfg_attrs: { $($cfg_attrs:tt)* } - other_attrs: { $($other_attrs:tt)* } + @split_attrs, + cfg_attrs: { $($cfg_attrs:tt)* }, + other_attrs: { $($other_attrs:tt)* }, remaining_attrs: { #$other:tt $($tail:tt)* - } - vis: { $vis:vis } - name: { $name:ident } - body: { $($body:tt)* } + }, + vis: $vis:vis, + name: $name:ident, + body: { $($body:tt)* }, ) => { union_with_debug! { - @split_attrs - cfg_attrs: { $($cfg_attrs)* } - other_attrs: { $($other_attrs)* #$other } - remaining_attrs: { $($tail)* } - vis: { $vis } - name: { $name } - body: { $($body)* } + @split_attrs, + cfg_attrs: { $($cfg_attrs)* }, + other_attrs: { $($other_attrs)* #$other }, + remaining_attrs: { $($tail)* }, + vis: $vis, + name: $name, + body: { $($body)* }, } }; // done ( - @split_attrs - cfg_attrs: { $($cfg_attrs:tt)* } - other_attrs: { $($other_attrs:tt)* } - remaining_attrs: { } - vis: { $vis:vis } - name: { $name:ident } - body: { $($body:tt)* } + @split_attrs, + cfg_attrs: { $($cfg_attrs:tt)* }, + other_attrs: { $($other_attrs:tt)* }, + remaining_attrs: { }, + vis: $vis:vis, + name: $name:ident, + body: { $($body:tt)* }, ) => { #[repr(C)] #[::core::prelude::v1::derive( @@ -487,196 +487,196 @@ macro_rules! custom_struct { $vis:vis struct $name:ident { $($body:tt)* } ) => { custom_struct! { - @split_attrs - cfg_attrs: { } - other_attrs: { } - remaining_attrs: { $($attrs)* $(#$attr)* } - found_exhaustive_attr: { false } - vis: { $vis } - name: { $name } - body: { $($body)* } + @split_attrs, + cfg_attrs: { }, + other_attrs: { }, + remaining_attrs: { $($attrs)* $(#$attr)* }, + found_exhaustive_attr: false, + vis: $vis, + name: $name, + body: { $($body)* }, } }; // a `cfg` also has to gate the impl ( - @split_attrs - cfg_attrs: { $($cfg_attrs:tt)* } - other_attrs: { $($other_attrs:tt)* } + @split_attrs, + cfg_attrs: { $($cfg_attrs:tt)* }, + other_attrs: { $($other_attrs:tt)* }, remaining_attrs: { #[cfg($($cfg:tt)*)] $($tail:tt)* - } - found_exhaustive_attr: { $found_exhaustive:tt } - vis: { $vis:vis } - name: { $name:ident } - body: { $($body:tt)* } + }, + found_exhaustive_attr: $found_exhaustive:tt, + vis: $vis:vis, + name: $name:ident, + body: { $($body:tt)* }, ) => { custom_struct! { - @split_attrs - cfg_attrs: { $($cfg_attrs)* #[cfg($($cfg)*)] } - other_attrs: { $($other_attrs)* } - remaining_attrs: { $($tail)* } - found_exhaustive_attr: { $found_exhaustive } - vis: { $vis } - name: { $name } - body: { $($body)* } + @split_attrs, + cfg_attrs: { $($cfg_attrs)* #[cfg($($cfg)*)] }, + other_attrs: { $($other_attrs)* }, + remaining_attrs: { $($tail)* }, + found_exhaustive_attr: $found_exhaustive, + vis: $vis, + name: $name, + body: { $($body)* }, } }; // `exhaustive` must be taken into account as many times as it appears, // though the effect is the same with a single annotation. ( - @split_attrs - cfg_attrs: { $($cfg_attrs:tt)* } - other_attrs: { $($other_attrs:tt)* } + @split_attrs, + cfg_attrs: { $($cfg_attrs:tt)* }, + other_attrs: { $($other_attrs:tt)* }, remaining_attrs: { #[exhaustive] $($tail:tt)* - } - found_exhaustive_attr: { $_:tt } - vis: { $vis:vis } - name: { $name:ident } - body: { $($body:tt)* } + }, + found_exhaustive_attr: $_:tt, + vis: $vis:vis, + name: $name:ident, + body: { $($body:tt)* }, ) => { custom_struct! { - @split_attrs - cfg_attrs: { $($cfg_attrs)* } - other_attrs: { $($other_attrs)* } - remaining_attrs: { $($tail)* } - found_exhaustive_attr: { true } - vis: { $vis } - name: { $name } - body: { $($body)* } + @split_attrs, + cfg_attrs: { $($cfg_attrs)* }, + other_attrs: { $($other_attrs)* }, + remaining_attrs: { $($tail)* }, + found_exhaustive_attr: true, + vis: $vis, + name: $name, + body: { $($body)* }, } }; // anything else belongs to the struct only ( - @split_attrs - cfg_attrs: { $($cfg_attrs:tt)* } - other_attrs: { $($other_attrs:tt)* } + @split_attrs, + cfg_attrs: { $($cfg_attrs:tt)* }, + other_attrs: { $($other_attrs:tt)* }, remaining_attrs: { #$other:tt $($tail:tt)* - } - found_exhaustive_attr: { $found_exhaustive:tt } - vis: { $vis:vis } - name: { $name:ident } - body: { $($body:tt)* } + }, + found_exhaustive_attr: $found_exhaustive:tt, + vis: $vis:vis, + name: $name:ident, + body: { $($body:tt)* }, ) => { custom_struct! { - @split_attrs - cfg_attrs: { $($cfg_attrs)* } - other_attrs: { $($other_attrs)* #$other } - remaining_attrs: { $($tail)* } - found_exhaustive_attr: { $found_exhaustive } - vis: { $vis } - name: { $name } - body: { $($body)* } + @split_attrs, + cfg_attrs: { $($cfg_attrs)* }, + other_attrs: { $($other_attrs)* #$other }, + remaining_attrs: { $($tail)* }, + found_exhaustive_attr: $found_exhaustive, + vis: $vis, + name: $name, + body: { $($body)* }, } }; // attributes are split, move on to the fields ( - @split_attrs - cfg_attrs: { $($cfg_attrs:tt)* } - other_attrs: { $($other_attrs:tt)* } - remaining_attrs: { } - found_exhaustive_attr: { $found_exhaustive:tt } - vis: { $vis:vis } - name: { $name:ident } - body: { $($body:tt)* } + @split_attrs, + cfg_attrs: { $($cfg_attrs:tt)* }, + other_attrs: { $($other_attrs:tt)* }, + remaining_attrs: { }, + found_exhaustive_attr: $found_exhaustive:tt, + vis: $vis:vis, + name: $name:ident, + body: { $($body:tt)* }, ) => { custom_struct! { - @struct - cfg_attrs: { $($cfg_attrs)* } - other_attrs: { $($other_attrs)* } - found_exhaustive_attr: { $found_exhaustive } - vis: { $vis } - name: { $name } - processed_fields: { } - processed_field_defaults: { } - remaining_fields: { $($body)* } + @struct, + cfg_attrs: { $($cfg_attrs)* }, + other_attrs: { $($other_attrs)* }, + found_exhaustive_attr: $found_exhaustive, + vis: $vis, + name: $name, + processed_fields: { }, + processed_field_defaults: { }, + remaining_fields: { $($body)* }, } }; // field led by #[custom_default(...)] ( - @struct - cfg_attrs: { $($cfg_attrs:tt)* } - other_attrs: { $($other_attrs:tt)* } - found_exhaustive_attr: { $found_exhaustive:tt } - vis: { $vis:vis } - name: { $name:ident } - processed_fields: { $($processed_fields:tt)* } - processed_field_defaults: { $($processed_field_defaults:tt)* } + @struct, + cfg_attrs: { $($cfg_attrs:tt)* }, + other_attrs: { $($other_attrs:tt)* }, + found_exhaustive_attr: $found_exhaustive:tt, + vis: $vis:vis, + name: $name:ident, + processed_fields: { $($processed_fields:tt)* }, + processed_field_defaults: { $($processed_field_defaults:tt)* }, remaining_fields: { #[custom_default($default:expr)] $(#[$fattr:meta])* $fvis:vis $fname:ident: $fty:ty, $($tail:tt)* - } + }, ) => { custom_struct! { - @struct - cfg_attrs: { $($cfg_attrs)* } - other_attrs: { $($other_attrs)* } - found_exhaustive_attr: { $found_exhaustive } - vis: { $vis } - name: { $name } - processed_fields: { $($processed_fields)* $(#[$fattr])* $fvis $fname: $fty, } + @struct, + cfg_attrs: { $($cfg_attrs)* }, + other_attrs: { $($other_attrs)* }, + found_exhaustive_attr: $found_exhaustive, + vis: $vis, + name: $name, + processed_fields: { $($processed_fields)* $(#[$fattr])* $fvis $fname: $fty, }, processed_field_defaults: { $($processed_field_defaults)* $(#[$fattr])* $fname: $default, - } - remaining_fields: { $($tail)* } + }, + remaining_fields: { $($tail)* }, } }; // plain field ( - @struct - cfg_attrs: { $($cfg_attrs:tt)* } - other_attrs: { $($other_attrs:tt)* } - found_exhaustive_attr: { $found_exhaustive:tt } - vis: { $vis:vis } - name: { $name:ident } - processed_fields: { $($processed_fields:tt)* } - processed_field_defaults: { $($processed_field_defaults:tt)* } + @struct, + cfg_attrs: { $($cfg_attrs:tt)* }, + other_attrs: { $($other_attrs:tt)* }, + found_exhaustive_attr: $found_exhaustive:tt, + vis: $vis:vis, + name: $name:ident, + processed_fields: { $($processed_fields:tt)* }, + processed_field_defaults: { $($processed_field_defaults:tt)* }, remaining_fields: { $(#[$fattr:meta])* $fvis:vis $fname:ident: $fty:ty, $($tail:tt)* - } + }, ) => { custom_struct! { - @struct - cfg_attrs: { $($cfg_attrs)* } - other_attrs: { $($other_attrs)* } - found_exhaustive_attr: { $found_exhaustive } - vis: { $vis } - name: { $name } - processed_fields: { $($processed_fields)* $(#[$fattr])* $fvis $fname: $fty, } + @struct, + cfg_attrs: { $($cfg_attrs)* }, + other_attrs: { $($other_attrs)* }, + found_exhaustive_attr: $found_exhaustive, + vis: $vis, + name: $name, + processed_fields: { $($processed_fields)* $(#[$fattr])* $fvis $fname: $fty, }, processed_field_defaults: { $($processed_field_defaults)* $(#[$fattr])* $fname: ::core::default::Default::default(), - } - remaining_fields: { $($tail)* } + }, + remaining_fields: { $($tail)* }, } }; // done ( - @struct - cfg_attrs: { $($cfg_attrs:tt)* } - other_attrs: { $($other_attrs:tt)* } - found_exhaustive_attr: { $found_exhaustive:tt } - vis: { $vis:vis } - name: { $name:ident } - processed_fields: { $($processed_fields:tt)* } - processed_field_defaults: { $($processed_field_defaults:tt)* } - remaining_fields: { } + @struct, + cfg_attrs: { $($cfg_attrs:tt)* }, + other_attrs: { $($other_attrs:tt)* }, + found_exhaustive_attr: $found_exhaustive:tt, + vis: $vis:vis, + name: $name:ident, + processed_fields: { $($processed_fields:tt)* }, + processed_field_defaults: { $($processed_field_defaults:tt)* }, + remaining_fields: { }, ) => { emit_struct_definition! { found_exhaustive_attr: $found_exhaustive, From 485ef90dbd3b171570fc93d01736a5e20665c7a8 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Wed, 30 Sep 2026 15:55:51 -0500 Subject: [PATCH 30/33] macros: Accept `#[unsafe(union_default_via_zeroed)]` Add a more automatic union `Default` implementation and make use of it. (backport ) (cherry picked from commit 1b75eaab872c08afb2b139e4755754a575aaba48) --- src/macros.rs | 88 +++++++++++++++++++++++++++++++++++++++ src/unix/bsd/apple/mod.rs | 30 ++----------- 2 files changed, 92 insertions(+), 26 deletions(-) diff --git a/src/macros.rs b/src/macros.rs index 82ab40bd299a6..48f1174a5f8a5 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -374,6 +374,7 @@ macro_rules! union_with_debug { cfg_attrs: { }, other_attrs: { }, remaining_attrs: { $(#$attr)* }, + found_default_via_unsafe_zeroed: false, vis: $vis, name: $name, body: { $($body)* }, @@ -389,6 +390,7 @@ macro_rules! union_with_debug { #[cfg($($cfg:tt)*)] $($tail:tt)* }, + found_default_via_unsafe_zeroed: $found_default:tt, vis: $vis:vis, name: $name:ident, body: { $($body:tt)* }, @@ -398,6 +400,33 @@ macro_rules! union_with_debug { cfg_attrs: { $($cfg_attrs)* #[cfg($($cfg)*)] }, other_attrs: { $($other_attrs)* }, remaining_attrs: { $($tail)* }, + found_default_via_unsafe_zeroed: $found_default, + vis: $vis, + name: $name, + body: { $($body)* }, + } + }; + + // a `cfg` also has to gate the impl + ( + @split_attrs, + cfg_attrs: { $($cfg_attrs:tt)* }, + other_attrs: { $($other_attrs:tt)* }, + remaining_attrs: { + #[unsafe(union_default_via_zeroed)] + $($tail:tt)* + }, + found_default_via_unsafe_zeroed: $found_default:tt, + vis: $vis:vis, + name: $name:ident, + body: { $($body:tt)* }, + ) => { + union_with_debug! { + @split_attrs, + cfg_attrs: { $($cfg_attrs)* }, + other_attrs: { $($other_attrs)* }, + remaining_attrs: { $($tail)* }, + found_default_via_unsafe_zeroed: true, vis: $vis, name: $name, body: { $($body)* }, @@ -413,6 +442,7 @@ macro_rules! union_with_debug { #$other:tt $($tail:tt)* }, + found_default_via_unsafe_zeroed: $found_default:tt, vis: $vis:vis, name: $name:ident, body: { $($body:tt)* }, @@ -422,6 +452,7 @@ macro_rules! union_with_debug { cfg_attrs: { $($cfg_attrs)* }, other_attrs: { $($other_attrs)* #$other }, remaining_attrs: { $($tail)* }, + found_default_via_unsafe_zeroed: $found_default, vis: $vis, name: $name, body: { $($body)* }, @@ -434,6 +465,7 @@ macro_rules! union_with_debug { cfg_attrs: { $($cfg_attrs:tt)* }, other_attrs: { $($other_attrs:tt)* }, remaining_attrs: { }, + found_default_via_unsafe_zeroed: $found_default:tt, vis: $vis:vis, name: $name:ident, body: { $($body:tt)* }, @@ -454,6 +486,35 @@ macro_rules! union_with_debug { f.debug_struct(::core::stringify!($name)).finish_non_exhaustive() } } + + emit_union_default_via_unsafe_zeroed! { + found_default_via_unsafe_zeroed: $found_default, + cfg_attrs: { $($cfg_attrs)* }, + name: $name, + } + }; +} + +/// Add a `Default` impl that is just `mem::zeroed`. +macro_rules! emit_union_default_via_unsafe_zeroed { + ( + found_default_via_unsafe_zeroed: false, + cfg_attrs: { $($cfg_attrs:tt)* }, + name: $name:ident, + ) => { + }; + + ( + found_default_via_unsafe_zeroed: true, + cfg_attrs: { $($cfg_attrs:tt)* }, + name: $name:ident, + ) => { + $($cfg_attrs)* + impl ::core::default::Default for $name { + fn default() -> Self { + unsafe { ::core::mem::zeroed() } + } + } }; } @@ -1401,6 +1462,33 @@ mod tests { #[cfg(target_arch = "x86_64")] assert_eq!(s.x86_only, 0); } + + #[test] + fn s2_union_default() { + s_no_extra_traits2! { + #[unsafe(union_default_via_zeroed)] + union Foo { + a: u32, + b: u64 + } + + #[expect(unused)] + union Bar { + a: u32, + b: u64 + } + } + + let f: Foo = Foo::default(); + assert_eq!(unsafe { f.b }, 0); + + // Ensure it isn't always implemented, otherwise we would get a conflict. + impl Default for Bar { + fn default() -> Self { + unimplemented!() + } + } + } } #[cfg(test)] diff --git a/src/unix/bsd/apple/mod.rs b/src/unix/bsd/apple/mod.rs index 8697759222d2f..fa4697bab6898 100644 --- a/src/unix/bsd/apple/mod.rs +++ b/src/unix/bsd/apple/mod.rs @@ -1843,12 +1843,13 @@ s_no_extra_traits2! { pub ifc_len: c_int, pub ifc_ifcu: __c_anonymous_ifc_ifcu, } - + #[unsafe(union_default_via_zeroed)] pub union __c_anonymous_ifk_data { pub ifk_ptr: *mut c_void, pub ifk_value: c_int, } + #[unsafe(union_default_via_zeroed)] pub union __c_anonymous_ifr_ifru { pub ifru_addr: crate::sockaddr, pub ifru_dstaddr: crate::sockaddr, @@ -1868,33 +1869,17 @@ s_no_extra_traits2! { pub ifru_functional_type: u32, } + #[unsafe(union_default_via_zeroed)] pub union __c_anonymous_ifc_ifcu { pub ifcu_buf: *mut c_char, pub ifcu_req: *mut ifreq, } } -impl Default for __c_anonymous_ifk_data { - fn default() -> Self { - unsafe { mem::zeroed() } - } -} - -impl Default for __c_anonymous_ifr_ifru { - fn default() -> Self { - unsafe { mem::zeroed() } - } -} - -impl Default for __c_anonymous_ifc_ifcu { - fn default() -> Self { - unsafe { mem::zeroed() } - } -} - cfg_if! { if #[cfg(target_os = "macos")] { s_no_extra_traits2! { + #[unsafe(union_default_via_zeroed)] pub union __c_anonymous_ifr_ifru6 { pub ifru_addr: crate::sockaddr_in6, pub ifru_dstaddr: crate::sockaddr_in6, @@ -1912,13 +1897,6 @@ cfg_if! { } } -#[cfg(target_os = "macos")] -impl Default for __c_anonymous_ifr_ifru6 { - fn default() -> Self { - unsafe { mem::zeroed() } - } -} - impl siginfo_t { pub unsafe fn si_addr(&self) -> *mut c_void { self.si_addr From c9c05f6b82bcbaf28cda7bc7d159f571c7f8a297 Mon Sep 17 00:00:00 2001 From: Daniel Canencia Garcia Date: Sun, 13 Sep 2026 15:21:41 +0200 Subject: [PATCH 31/33] Improve panic message for out-of-range fds in FD_* functions Passing a file descriptor that is negative or >= FD_SETSIZE to FD_SET, FD_CLR or FD_ISSET is undefined behavior per POSIX, and the previous "index out of bounds" panic gave no hint of the required range. Panic with a message that states the valid 0..FD_SETSIZE range instead. Applies the fix across all platforms: linux_like, bsd, solarish, redox, nto, newlib, fuchsia, haiku, cygwin, hurd, aix (bitmask via get/get_mut + let-else) and wasi (explicit range check). FD_ZERO is unchanged (takes no fd). WASI has no FD_CLR. Also adds panic! and Option::{self, None, Some} to the prelude so the new code resolves under no_core (rustc-dep-of-std) builds. Part of rust-lang#1401 (backport ) (cherry picked from commit 5b6e5a60fe17f2776a3dec5540a6ae5923d6feb0) [ needed to add an extra cast on WASI for the 0.2 branch - Trevor ] --- src/fuchsia/mod.rs | 17 ++++++++++++----- src/macros.rs | 7 ++++++- src/unix/aix/mod.rs | 23 +++++++++++++++-------- src/unix/bsd/mod.rs | 23 +++++++++++++++-------- src/unix/cygwin/mod.rs | 15 ++++++++++++--- src/unix/haiku/mod.rs | 17 ++++++++++++----- src/unix/hurd/mod.rs | 17 ++++++++++++----- src/unix/linux_like/mod.rs | 17 ++++++++++++----- src/unix/newlib/mod.rs | 23 +++++++++++++++-------- src/unix/nto/mod.rs | 17 ++++++++++++----- src/unix/redox/mod.rs | 17 ++++++++++++----- src/unix/solarish/mod.rs | 23 +++++++++++++++-------- src/wasi/mod.rs | 6 ++++++ 13 files changed, 156 insertions(+), 66 deletions(-) diff --git a/src/fuchsia/mod.rs b/src/fuchsia/mod.rs index 6fdaf83c9450d..ff49572667cad 100644 --- a/src/fuchsia/mod.rs +++ b/src/fuchsia/mod.rs @@ -3130,21 +3130,28 @@ f! { pub unsafe fn FD_CLR(fd: c_int, set: *mut fd_set) -> () { let fd = fd as usize; let size = size_of_val(&(*set).fds_bits[0]) * 8; - (*set).fds_bits[fd / size] &= !(1 << (fd % size)); - return; + let Some(slot) = (*set).fds_bits.get_mut(fd / size) else { + panic!("fd {fd} out of range: valid fds are 0..FD_SETSIZE (0..{FD_SETSIZE})"); + }; + *slot &= !(1 << (fd % size)); } pub unsafe fn FD_ISSET(fd: c_int, set: *const fd_set) -> bool { let fd = fd as usize; let size = size_of_val(&(*set).fds_bits[0]) * 8; - return ((*set).fds_bits[fd / size] & (1 << (fd % size))) != 0; + let Some(slot) = (*set).fds_bits.get(fd / size) else { + panic!("fd {fd} out of range: valid fds are 0..FD_SETSIZE (0..{FD_SETSIZE})"); + }; + (*slot & (1 << (fd % size))) != 0 } pub unsafe fn FD_SET(fd: c_int, set: *mut fd_set) -> () { let fd = fd as usize; let size = size_of_val(&(*set).fds_bits[0]) * 8; - (*set).fds_bits[fd / size] |= 1 << (fd % size); - return; + let Some(slot) = (*set).fds_bits.get_mut(fd / size) else { + panic!("fd {fd} out of range: valid fds are 0..FD_SETSIZE (0..{FD_SETSIZE})"); + }; + *slot |= 1 << (fd % size); } pub unsafe fn FD_ZERO(set: *mut fd_set) -> () { diff --git a/src/macros.rs b/src/macros.rs index 48f1174a5f8a5..fb8b0ce65af1e 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -88,7 +88,11 @@ macro_rules! prelude { Sync, }; #[allow(unused_imports)] - pub(crate) use core::option::Option; + pub(crate) use core::option::Option::{ + self, + None, + Some, + }; #[allow(unused_imports)] pub(crate) use core::prelude::v1::derive; #[allow(unused_imports)] @@ -101,6 +105,7 @@ macro_rules! prelude { hash, iter, mem, + panic, ptr, unimplemented, }; diff --git a/src/unix/aix/mod.rs b/src/unix/aix/mod.rs index efd9c486bd0a5..2bdc7c6431fa3 100644 --- a/src/unix/aix/mod.rs +++ b/src/unix/aix/mod.rs @@ -2504,23 +2504,30 @@ f! { } pub unsafe fn FD_SET(fd: c_int, set: *mut fd_set) -> () { - let bits = size_of::() * 8; let fd = fd as usize; - (*set).fds_bits[fd / bits] |= 1 << (fd % bits); - return; + let bits = size_of::() * 8; + let Some(slot) = (*set).fds_bits.get_mut(fd / bits) else { + panic!("fd {fd} out of range: valid fds are 0..FD_SETSIZE (0..{FD_SETSIZE})"); + }; + *slot |= 1 << (fd % bits); } pub unsafe fn FD_CLR(fd: c_int, set: *mut fd_set) -> () { - let bits = size_of::() * 8; let fd = fd as usize; - (*set).fds_bits[fd / bits] &= !(1 << (fd % bits)); - return; + let bits = size_of::() * 8; + let Some(slot) = (*set).fds_bits.get_mut(fd / bits) else { + panic!("fd {fd} out of range: valid fds are 0..FD_SETSIZE (0..{FD_SETSIZE})"); + }; + *slot &= !(1 << (fd % bits)); } pub unsafe fn FD_ISSET(fd: c_int, set: *const fd_set) -> bool { - let bits = size_of::() * 8; let fd = fd as usize; - return ((*set).fds_bits[fd / bits] & (1 << (fd % bits))) != 0; + let bits = size_of::() * 8; + let Some(slot) = (*set).fds_bits.get(fd / bits) else { + panic!("fd {fd} out of range: valid fds are 0..FD_SETSIZE (0..{FD_SETSIZE})"); + }; + (*slot & (1 << (fd % bits))) != 0 } pub const safe fn WIFSTOPPED(status: c_int) -> bool { diff --git a/src/unix/bsd/mod.rs b/src/unix/bsd/mod.rs index ecb49b75e795d..0051b032d94fd 100644 --- a/src/unix/bsd/mod.rs +++ b/src/unix/bsd/mod.rs @@ -527,23 +527,30 @@ f! { } pub unsafe fn FD_CLR(fd: c_int, set: *mut fd_set) -> () { - let bits = size_of_val(&(*set).fds_bits[0]) * 8; let fd = fd as usize; - (*set).fds_bits[fd / bits] &= !(1 << (fd % bits)); - return; + let bits = size_of_val(&(*set).fds_bits[0]) * 8; + let Some(slot) = (*set).fds_bits.get_mut(fd / bits) else { + panic!("fd {fd} out of range: valid fds are 0..FD_SETSIZE (0..{FD_SETSIZE})"); + }; + *slot &= !(1 << (fd % bits)); } pub unsafe fn FD_ISSET(fd: c_int, set: *const fd_set) -> bool { - let bits = size_of_val(&(*set).fds_bits[0]) * 8; let fd = fd as usize; - return ((*set).fds_bits[fd / bits] & (1 << (fd % bits))) != 0; + let bits = size_of_val(&(*set).fds_bits[0]) * 8; + let Some(slot) = (*set).fds_bits.get(fd / bits) else { + panic!("fd {fd} out of range: valid fds are 0..FD_SETSIZE (0..{FD_SETSIZE})"); + }; + (*slot & (1 << (fd % bits))) != 0 } pub unsafe fn FD_SET(fd: c_int, set: *mut fd_set) -> () { - let bits = size_of_val(&(*set).fds_bits[0]) * 8; let fd = fd as usize; - (*set).fds_bits[fd / bits] |= 1 << (fd % bits); - return; + let bits = size_of_val(&(*set).fds_bits[0]) * 8; + let Some(slot) = (*set).fds_bits.get_mut(fd / bits) else { + panic!("fd {fd} out of range: valid fds are 0..FD_SETSIZE (0..{FD_SETSIZE})"); + }; + *slot |= 1 << (fd % bits); } pub unsafe fn FD_ZERO(set: *mut fd_set) -> () { diff --git a/src/unix/cygwin/mod.rs b/src/unix/cygwin/mod.rs index 08a1a81774d34..3b8ea7510ddc3 100644 --- a/src/unix/cygwin/mod.rs +++ b/src/unix/cygwin/mod.rs @@ -1687,19 +1687,28 @@ f! { pub unsafe fn FD_CLR(fd: c_int, set: *mut fd_set) -> () { let fd = fd as usize; let size = size_of_val(&(*set).fds_bits[0]) * 8; - (*set).fds_bits[fd / size] &= !(1 << (fd % size)); + let Some(slot) = (*set).fds_bits.get_mut(fd / size) else { + panic!("fd {fd} out of range: valid fds are 0..FD_SETSIZE (0..{FD_SETSIZE})"); + }; + *slot &= !(1 << (fd % size)); } pub unsafe fn FD_ISSET(fd: c_int, set: *const fd_set) -> bool { let fd = fd as usize; let size = size_of_val(&(*set).fds_bits[0]) * 8; - ((*set).fds_bits[fd / size] & (1 << (fd % size))) != 0 + let Some(slot) = (*set).fds_bits.get(fd / size) else { + panic!("fd {fd} out of range: valid fds are 0..FD_SETSIZE (0..{FD_SETSIZE})"); + }; + (*slot & (1 << (fd % size))) != 0 } pub unsafe fn FD_SET(fd: c_int, set: *mut fd_set) -> () { let fd = fd as usize; let size = size_of_val(&(*set).fds_bits[0]) * 8; - (*set).fds_bits[fd / size] |= 1 << (fd % size); + let Some(slot) = (*set).fds_bits.get_mut(fd / size) else { + panic!("fd {fd} out of range: valid fds are 0..FD_SETSIZE (0..{FD_SETSIZE})"); + }; + *slot |= 1 << (fd % size); } pub unsafe fn FD_ZERO(set: *mut fd_set) -> () { diff --git a/src/unix/haiku/mod.rs b/src/unix/haiku/mod.rs index c1ef35b04de24..1f8609a653f22 100644 --- a/src/unix/haiku/mod.rs +++ b/src/unix/haiku/mod.rs @@ -1436,21 +1436,28 @@ f! { pub unsafe fn FD_CLR(fd: c_int, set: *mut fd_set) -> () { let fd = fd as usize; let size = size_of_val(&(*set).fds_bits[0]) * 8; - (*set).fds_bits[fd / size] &= !(1 << (fd % size)); - return; + let Some(slot) = (*set).fds_bits.get_mut(fd / size) else { + panic!("fd {fd} out of range: valid fds are 0..FD_SETSIZE (0..{FD_SETSIZE})"); + }; + *slot &= !(1 << (fd % size)); } pub unsafe fn FD_ISSET(fd: c_int, set: *const fd_set) -> bool { let fd = fd as usize; let size = size_of_val(&(*set).fds_bits[0]) * 8; - return ((*set).fds_bits[fd / size] & (1 << (fd % size))) != 0; + let Some(slot) = (*set).fds_bits.get(fd / size) else { + panic!("fd {fd} out of range: valid fds are 0..FD_SETSIZE (0..{FD_SETSIZE})"); + }; + (*slot & (1 << (fd % size))) != 0 } pub unsafe fn FD_SET(fd: c_int, set: *mut fd_set) -> () { let fd = fd as usize; let size = size_of_val(&(*set).fds_bits[0]) * 8; - (*set).fds_bits[fd / size] |= 1 << (fd % size); - return; + let Some(slot) = (*set).fds_bits.get_mut(fd / size) else { + panic!("fd {fd} out of range: valid fds are 0..FD_SETSIZE (0..{FD_SETSIZE})"); + }; + *slot |= 1 << (fd % size); } pub unsafe fn FD_ZERO(set: *mut fd_set) -> () { diff --git a/src/unix/hurd/mod.rs b/src/unix/hurd/mod.rs index 2b2eca29b6d12..c2d0eaa55ff1b 100644 --- a/src/unix/hurd/mod.rs +++ b/src/unix/hurd/mod.rs @@ -3609,21 +3609,28 @@ f! { pub unsafe fn FD_CLR(fd: c_int, set: *mut fd_set) -> () { let fd = fd as usize; let size = size_of_val(&(*set).fds_bits[0]) * 8; - (*set).fds_bits[fd / size] &= !(1 << (fd % size)); - return; + let Some(slot) = (*set).fds_bits.get_mut(fd / size) else { + panic!("fd {fd} out of range: valid fds are 0..FD_SETSIZE (0..{FD_SETSIZE})"); + }; + *slot &= !(1 << (fd % size)); } pub unsafe fn FD_ISSET(fd: c_int, set: *const fd_set) -> bool { let fd = fd as usize; let size = size_of_val(&(*set).fds_bits[0]) * 8; - return ((*set).fds_bits[fd / size] & (1 << (fd % size))) != 0; + let Some(slot) = (*set).fds_bits.get(fd / size) else { + panic!("fd {fd} out of range: valid fds are 0..FD_SETSIZE (0..{FD_SETSIZE})"); + }; + (*slot & (1 << (fd % size))) != 0 } pub unsafe fn FD_SET(fd: c_int, set: *mut fd_set) -> () { let fd = fd as usize; let size = size_of_val(&(*set).fds_bits[0]) * 8; - (*set).fds_bits[fd / size] |= 1 << (fd % size); - return; + let Some(slot) = (*set).fds_bits.get_mut(fd / size) else { + panic!("fd {fd} out of range: valid fds are 0..FD_SETSIZE (0..{FD_SETSIZE})"); + }; + *slot |= 1 << (fd % size); } pub unsafe fn FD_ZERO(set: *mut fd_set) -> () { diff --git a/src/unix/linux_like/mod.rs b/src/unix/linux_like/mod.rs index ef18088d0f07e..7fcc9a09aa50f 100644 --- a/src/unix/linux_like/mod.rs +++ b/src/unix/linux_like/mod.rs @@ -1794,21 +1794,28 @@ f! { pub unsafe fn FD_CLR(fd: c_int, set: *mut fd_set) -> () { let fd = fd as usize; let size = size_of_val(&(*set).fds_bits[0]) * 8; - (*set).fds_bits[fd / size] &= !(1 << (fd % size)); - return; + let Some(slot) = (*set).fds_bits.get_mut(fd / size) else { + panic!("fd {fd} out of range: valid fds are 0..FD_SETSIZE (0..{FD_SETSIZE})"); + }; + *slot &= !(1 << (fd % size)); } pub unsafe fn FD_ISSET(fd: c_int, set: *const fd_set) -> bool { let fd = fd as usize; let size = size_of_val(&(*set).fds_bits[0]) * 8; - return ((*set).fds_bits[fd / size] & (1 << (fd % size))) != 0; + let Some(slot) = (*set).fds_bits.get(fd / size) else { + panic!("fd {fd} out of range: valid fds are 0..FD_SETSIZE (0..{FD_SETSIZE})"); + }; + (*slot & (1 << (fd % size))) != 0 } pub unsafe fn FD_SET(fd: c_int, set: *mut fd_set) -> () { let fd = fd as usize; let size = size_of_val(&(*set).fds_bits[0]) * 8; - (*set).fds_bits[fd / size] |= 1 << (fd % size); - return; + let Some(slot) = (*set).fds_bits.get_mut(fd / size) else { + panic!("fd {fd} out of range: valid fds are 0..FD_SETSIZE (0..{FD_SETSIZE})"); + }; + *slot |= 1 << (fd % size); } pub unsafe fn FD_ZERO(set: *mut fd_set) -> () { diff --git a/src/unix/newlib/mod.rs b/src/unix/newlib/mod.rs index 5e5fd11c3590f..e54aed4015872 100644 --- a/src/unix/newlib/mod.rs +++ b/src/unix/newlib/mod.rs @@ -893,23 +893,30 @@ pub const _PATH_BSHELL: *const c_char = cstr(b"/bin/sh\0"); f! { pub unsafe fn FD_CLR(fd: c_int, set: *mut fd_set) -> () { - let bits = size_of_val(&(*set).fds_bits[0]) * 8; let fd = fd as usize; - (*set).fds_bits[fd / bits] &= !(1 << (fd % bits)); - return; + let bits = size_of_val(&(*set).fds_bits[0]) * 8; + let Some(slot) = (*set).fds_bits.get_mut(fd / bits) else { + panic!("fd {fd} out of range: valid fds are 0..FD_SETSIZE (0..{FD_SETSIZE})"); + }; + *slot &= !(1 << (fd % bits)); } pub unsafe fn FD_ISSET(fd: c_int, set: *const fd_set) -> bool { - let bits = size_of_val(&(*set).fds_bits[0]) * 8; let fd = fd as usize; - return ((*set).fds_bits[fd / bits] & (1 << (fd % bits))) != 0; + let bits = size_of_val(&(*set).fds_bits[0]) * 8; + let Some(slot) = (*set).fds_bits.get(fd / bits) else { + panic!("fd {fd} out of range: valid fds are 0..FD_SETSIZE (0..{FD_SETSIZE})"); + }; + (*slot & (1 << (fd % bits))) != 0 } pub unsafe fn FD_SET(fd: c_int, set: *mut fd_set) -> () { - let bits = size_of_val(&(*set).fds_bits[0]) * 8; let fd = fd as usize; - (*set).fds_bits[fd / bits] |= 1 << (fd % bits); - return; + let bits = size_of_val(&(*set).fds_bits[0]) * 8; + let Some(slot) = (*set).fds_bits.get_mut(fd / bits) else { + panic!("fd {fd} out of range: valid fds are 0..FD_SETSIZE (0..{FD_SETSIZE})"); + }; + *slot |= 1 << (fd % bits); } pub unsafe fn FD_ZERO(set: *mut fd_set) -> () { diff --git a/src/unix/nto/mod.rs b/src/unix/nto/mod.rs index 7276aaca09b0c..5854f11ff2865 100644 --- a/src/unix/nto/mod.rs +++ b/src/unix/nto/mod.rs @@ -2363,21 +2363,28 @@ f! { pub unsafe fn FD_CLR(fd: c_int, set: *mut fd_set) -> () { let fd = fd as usize; let size = size_of_val(&(*set).fds_bits[0]) * 8; - (*set).fds_bits[fd / size] &= !(1 << (fd % size)); - return; + let Some(slot) = (*set).fds_bits.get_mut(fd / size) else { + panic!("fd {fd} out of range: valid fds are 0..FD_SETSIZE (0..{FD_SETSIZE})"); + }; + *slot &= !(1 << (fd % size)); } pub unsafe fn FD_ISSET(fd: c_int, set: *const fd_set) -> bool { let fd = fd as usize; let size = size_of_val(&(*set).fds_bits[0]) * 8; - return ((*set).fds_bits[fd / size] & (1 << (fd % size))) != 0; + let Some(slot) = (*set).fds_bits.get(fd / size) else { + panic!("fd {fd} out of range: valid fds are 0..FD_SETSIZE (0..{FD_SETSIZE})"); + }; + (*slot & (1 << (fd % size))) != 0 } pub unsafe fn FD_SET(fd: c_int, set: *mut fd_set) -> () { let fd = fd as usize; let size = size_of_val(&(*set).fds_bits[0]) * 8; - (*set).fds_bits[fd / size] |= 1 << (fd % size); - return; + let Some(slot) = (*set).fds_bits.get_mut(fd / size) else { + panic!("fd {fd} out of range: valid fds are 0..FD_SETSIZE (0..{FD_SETSIZE})"); + }; + *slot |= 1 << (fd % size); } pub unsafe fn FD_ZERO(set: *mut fd_set) -> () { diff --git a/src/unix/redox/mod.rs b/src/unix/redox/mod.rs index 51a49dea24e3e..1625938ff0ce0 100644 --- a/src/unix/redox/mod.rs +++ b/src/unix/redox/mod.rs @@ -1246,21 +1246,28 @@ f! { pub unsafe fn FD_CLR(fd: c_int, set: *mut fd_set) -> () { let fd = fd as usize; let size = size_of_val(&(*set).fds_bits[0]) * 8; - (*set).fds_bits[fd / size] &= !(1 << (fd % size)); - return; + let Some(slot) = (*set).fds_bits.get_mut(fd / size) else { + panic!("fd {fd} out of range: valid fds are 0..FD_SETSIZE (0..{FD_SETSIZE})"); + }; + *slot &= !(1 << (fd % size)); } pub unsafe fn FD_ISSET(fd: c_int, set: *const fd_set) -> bool { let fd = fd as usize; let size = size_of_val(&(*set).fds_bits[0]) * 8; - return ((*set).fds_bits[fd / size] & (1 << (fd % size))) != 0; + let Some(slot) = (*set).fds_bits.get(fd / size) else { + panic!("fd {fd} out of range: valid fds are 0..FD_SETSIZE (0..{FD_SETSIZE})"); + }; + (*slot & (1 << (fd % size))) != 0 } pub unsafe fn FD_SET(fd: c_int, set: *mut fd_set) -> () { let fd = fd as usize; let size = size_of_val(&(*set).fds_bits[0]) * 8; - (*set).fds_bits[fd / size] |= 1 << (fd % size); - return; + let Some(slot) = (*set).fds_bits.get_mut(fd / size) else { + panic!("fd {fd} out of range: valid fds are 0..FD_SETSIZE (0..{FD_SETSIZE})"); + }; + *slot |= 1 << (fd % size); } pub unsafe fn FD_ZERO(set: *mut fd_set) -> () { diff --git a/src/unix/solarish/mod.rs b/src/unix/solarish/mod.rs index 98c61c7636534..93431f3cf71ee 100644 --- a/src/unix/solarish/mod.rs +++ b/src/unix/solarish/mod.rs @@ -2253,23 +2253,30 @@ f! { } pub unsafe fn FD_CLR(fd: c_int, set: *mut fd_set) -> () { - let bits = size_of_val(&(*set).fds_bits[0]) * 8; let fd = fd as usize; - (*set).fds_bits[fd / bits] &= !(1 << (fd % bits)); - return; + let bits = size_of_val(&(*set).fds_bits[0]) * 8; + let Some(slot) = (*set).fds_bits.get_mut(fd / bits) else { + panic!("fd {fd} out of range: valid fds are 0..FD_SETSIZE (0..{FD_SETSIZE})"); + }; + *slot &= !(1 << (fd % bits)); } pub unsafe fn FD_ISSET(fd: c_int, set: *const fd_set) -> bool { - let bits = size_of_val(&(*set).fds_bits[0]) * 8; let fd = fd as usize; - return ((*set).fds_bits[fd / bits] & (1 << (fd % bits))) != 0; + let bits = size_of_val(&(*set).fds_bits[0]) * 8; + let Some(slot) = (*set).fds_bits.get(fd / bits) else { + panic!("fd {fd} out of range: valid fds are 0..FD_SETSIZE (0..{FD_SETSIZE})"); + }; + (*slot & (1 << (fd % bits))) != 0 } pub unsafe fn FD_SET(fd: c_int, set: *mut fd_set) -> () { - let bits = size_of_val(&(*set).fds_bits[0]) * 8; let fd = fd as usize; - (*set).fds_bits[fd / bits] |= 1 << (fd % bits); - return; + let bits = size_of_val(&(*set).fds_bits[0]) * 8; + let Some(slot) = (*set).fds_bits.get_mut(fd / bits) else { + panic!("fd {fd} out of range: valid fds are 0..FD_SETSIZE (0..{FD_SETSIZE})"); + }; + *slot |= 1 << (fd % bits); } pub unsafe fn FD_ZERO(set: *mut fd_set) -> () { diff --git a/src/wasi/mod.rs b/src/wasi/mod.rs index 628ba244a166d..cc8cb122cbca8 100644 --- a/src/wasi/mod.rs +++ b/src/wasi/mod.rs @@ -674,12 +674,18 @@ pub const SO_TYPE: c_int = 3; f! { pub unsafe fn FD_ISSET(fd: c_int, set: *const fd_set) -> bool { + if fd < 0 || (fd as usize) >= FD_SETSIZE { + panic!("fd {fd} out of range: valid fds are 0..FD_SETSIZE (0..{FD_SETSIZE})"); + } let set = &*set; let n = set.__nfds; return set.__fds[..n].iter().any(|p| *p == fd); } pub unsafe fn FD_SET(fd: c_int, set: *mut fd_set) -> () { + if fd < 0 || (fd as usize) >= FD_SETSIZE { + panic!("fd {fd} out of range: valid fds are 0..FD_SETSIZE (0..{FD_SETSIZE})"); + } let set = &mut *set; let n = set.__nfds; if !set.__fds[..n].iter().any(|p| *p == fd) { From cd0490127f4337951746ffc85d6504608b0704dc Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Sun, 20 Sep 2026 18:12:48 -0500 Subject: [PATCH 32/33] build: Make `linux_time_bits64` match the upstream definition `__USE_TIME_BITS64` is set on both 32-bit and 64-bit platforms if `time_t` is 64 bits. Update the usage of `linux_time_bits64` to match. (backport ) (cherry picked from commit b6de484f1e20b146673e8016900731f8056d4371) --- build.rs | 11 ++++++++--- libc-test/build/main.rs | 7 ++++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/build.rs b/build.rs index 52c37fe35b8a9..3d64aad7724a8 100644 --- a/build.rs +++ b/build.rs @@ -37,7 +37,8 @@ enum Cfg { VxworksLt25_09, - /// Corresponds to `__USE_TIME_BITS64` in UAPI. Implies 32-bit Linux target. + /// Corresponds to `__USE_TIME_BITS64` in UAPI. Implies Linux and 64-bit `time_t`, but is set + /// on both 32-bit and 64-bit platforms. LinuxTimeBits64, /// Corresponds to `_FILE_OFFSET_BITS=64` in glibc. Implies 32-bit GNU target. GnuFileOffsetBits64, @@ -265,9 +266,9 @@ fn main() { if musl_v1_2 { cfgs.push(Cfg::MuslV1_2); + cfgs.push(Cfg::LinuxTimeBits64); if target_ptr_width == "32" { cfgs.push(Cfg::Musl32Time64); - cfgs.push(Cfg::LinuxTimeBits64); if !only_v1_2_on_musl { // Older 32-bit arches need the redirects cfgs.push(Cfg::MuslRedirTime64); @@ -332,6 +333,11 @@ fn main() { cfgs.push(Cfg::Uclibc32Time64); } + // `__USE_TIME_BITS64` is set on any platform if `time_t` is 64 bits. + if target_os == "linux" && target_ptr_width == "64" { + cfgs.push(Cfg::LinuxTimeBits64); + } + // On CI: deny all warnings if libc_ci { cfgs.push(Cfg::LibcDenyWarnings); @@ -480,7 +486,6 @@ fn validate_cfg(list: &[Cfg], target_env: &str, target_os: &str, target_ptr_widt } Cfg::LinuxTimeBits64 => { assert_eq!(target_os, "linux", "{cfg:?} set on non-linux platform"); - assert_eq!(target_ptr_width, "32", "{cfg:?} set on non-32-bit platform"); } Cfg::MuslV1_2 => { assert!( diff --git a/libc-test/build/main.rs b/libc-test/build/main.rs index 51493fb3ef963..c2e20fcfa8950 100755 --- a/libc-test/build/main.rs +++ b/libc-test/build/main.rs @@ -4032,6 +4032,7 @@ fn test_linux(t: &Target) { let mips = t.mips(); let mips32 = t.mips32(); let pauthtest = t.pauthtest(); + let p64 = t.p64(); let p32 = t.p32(); let versions = &*VERSIONS; let kernel = match versions.linux { @@ -4059,9 +4060,9 @@ fn test_linux(t: &Target) { if musl && musl_v1_2 { cfg.cfg("musl_v1_2", None); + cfg.cfg("linux_time_bits64", None); if p32 { cfg.cfg("musl32_time64", None); - cfg.cfg("linux_time_bits64", None); } if arm32 || ppc32 || x86_32 || mips32 { cfg.cfg("musl_redir_time64", None); @@ -4076,6 +4077,10 @@ fn test_linux(t: &Target) { cfg.cfg("uclibc32_time64", None); } + if p64 { + cfg.cfg("linux_time_bits64", None); + } + cfg.define("_GNU_SOURCE", None) // This macro re-defines fscanf,scanf,sscanf to link to the symbols that are // deprecated since glibc >= 2.29. This allows Rust binaries to link against From a11b89666d6248204f58a043f737a430449b2fe0 Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Tue, 29 Sep 2026 13:25:37 -0600 Subject: [PATCH 33/33] Fix CI for FreeBSD 15.1 and 16.0-CURRENT * In the CI tests, treat FreeBSD 16 identically to 15. We don't currently need or have separate definitions in the source code for FreeBSD 15 vs 16. So treat them identically during CI. * Remove some more mask constants from FreeBSD. These are bitmasks that are intended to be used within the kernel. New features may widen them, so their values aren't stable. They probably don't have any legitimate uses in userland. And their values have changed in FreeBSD 16. * A few constants got removed in 15.1 and 16.0 . * The in_conninfo struct's internal substructs got renamed in 16.0. * ifi2creq's padding fields got partially used up in 16.0, in the process relaxing its alignment requirement. * max_align_t's size increased in 16.0. But that struct should never be instantiated, so its size doesn't matter. (backport ) (cherry picked from commit d1df215c78c7ee7d96bb2d7f5c046f689079f1fe) --- build.rs | 2 ++ libc-test/build/main.rs | 31 +++++++++++++++++++++++++ libc-test/semver/freebsd.txt | 2 -- src/unix/bsd/freebsdlike/freebsd/mod.rs | 4 ++-- 4 files changed, 35 insertions(+), 4 deletions(-) diff --git a/build.rs b/build.rs index 3d64aad7724a8..bb2e33036c905 100644 --- a/build.rs +++ b/build.rs @@ -544,6 +544,8 @@ fn which_freebsd() -> Option { s if s.starts_with("13") => Some(13), s if s.starts_with("14") => Some(14), s if s.starts_with("15") => Some(15), + // Until we have a need to treat them separately, treat FreeBSD 16 like 15 + s if s.starts_with("16") => Some(15), _ => None, } } diff --git a/libc-test/build/main.rs b/libc-test/build/main.rs index c2e20fcfa8950..387ee5256b0b6 100755 --- a/libc-test/build/main.rs +++ b/libc-test/build/main.rs @@ -2601,6 +2601,8 @@ fn test_freebsd(t: &Target) { (13, _) => cfg.cfg("freebsd13", None), (14, _) => cfg.cfg("freebsd14", None), (15, _) => cfg.cfg("freebsd15", None), + // Until we have a need to treat them separately, treat FreeBSD 16 like 15 + (16, _) => cfg.cfg("freebsd15", None), _ => panic!("unknown FreeBSD version {freebsd:?}"), }; @@ -3038,6 +3040,12 @@ fn test_freebsd(t: &Target) { | "PROC_LOGSIGEXIT_CTL_FORCE_ENABLE" | "PROC_LOGSIGEXIT_CTL_FORCE_DISABLE" => freebsd < (15, 0), + // Removed in FreeBSD 15.1 + "SF_SYNC" => freebsd >= (15, 1), + + // Removed in FreeBSD 16 + "IFF_RENAMING" | "IPPROTO_OLD_DIVERT" | "IPPROTO_DIVERT" => freebsd >= (16, 0), + _ => false, } }); @@ -3095,6 +3103,16 @@ fn test_freebsd(t: &Target) { // Extern types "DIR" | "FILE" | "fpos_t" | "timezone" => true, + // The definition changed in FreeBSD 16. These structs no longer exist, but their + // parent (in_conninfo) still does, and is binary-compatible. + "in_endpoints" | "in_addr_4in6" => freebsd >= (16, 0), + + // FreeBSD 16 relaxed the alignment of this struct, and renamed some fields + "ifi2creq" => freebsd >= (16, 0), + // FreeBSD 16 changed the size of this struct, but its size doesn't matter. Only its + // alignment does. + "max_align_t" => freebsd >= (16, 0), + _ => false, } }); @@ -3223,9 +3241,22 @@ fn test_freebsd(t: &Target) { // mc_spare can change in size between OS releases. It's a spare field, after all. ("__mcontext", "mc_spare") => true, + // The definition changed in FreeBSD 16 but in a binary-compatible way + ("in_conninfo", "inc_ie") => freebsd >= (16, 0), + _ => false, } }); + + cfg.skip_union(move |union_| { + match union_.ident() { + // Removed in FreeBSD 16 + "in_dependaddr" => freebsd >= (16, 0), + + _ => false, + } + }); + if t.arm32() { cfg.skip_roundtrip(move |s| match s { // Can't return an array from a C function. diff --git a/libc-test/semver/freebsd.txt b/libc-test/semver/freebsd.txt index 7d1797320a6f9..1b816a73fae50 100644 --- a/libc-test/semver/freebsd.txt +++ b/libc-test/semver/freebsd.txt @@ -974,7 +974,6 @@ NOTE_LOWAT NOTE_MSECONDS NOTE_NSECONDS NOTE_OPEN -NOTE_PCTRLMASK NOTE_PDATAMASK NOTE_READ NOTE_RENAME @@ -1005,7 +1004,6 @@ O_SHLOCK O_SYNC O_TTY_INIT O_VERIFY -PD_ALLOWED_AT_FORK PD_CLOEXEC PD_DAEMON PENDIN diff --git a/src/unix/bsd/freebsdlike/freebsd/mod.rs b/src/unix/bsd/freebsdlike/freebsd/mod.rs index b1c4305bf4b62..7bd427767f781 100644 --- a/src/unix/bsd/freebsdlike/freebsd/mod.rs +++ b/src/unix/bsd/freebsdlike/freebsd/mod.rs @@ -849,7 +849,9 @@ s! { pub offset: u8, /// read length pub len: u8, + // "page" on FreeBSD 16 pub spare0: u8, + // "bank" plus "spare" on FreeBSD 16 pub spare1: u32, /// read buffer pub data: [u8; 8], @@ -2278,7 +2280,6 @@ pub const NOTE_EXIT: u32 = 0x80000000; pub const NOTE_FORK: u32 = 0x40000000; pub const NOTE_EXEC: u32 = 0x20000000; pub const NOTE_PDATAMASK: u32 = 0x000fffff; -pub const NOTE_PCTRLMASK: u32 = 0xf0000000; pub const NOTE_TRACK: u32 = 0x00000001; pub const NOTE_TRACKERR: u32 = 0x00000002; pub const NOTE_CHILD: u32 = 0x00000004; @@ -3392,7 +3393,6 @@ pub const _UUID_NODE_LEN: usize = 6; // Flags which can be passed to pdfork(2) pub const PD_DAEMON: c_int = 0x00000001; pub const PD_CLOEXEC: c_int = 0x00000002; -pub const PD_ALLOWED_AT_FORK: c_int = PD_DAEMON | PD_CLOEXEC; // Values for struct rtprio (type_ field) pub const RTP_PRIO_REALTIME: c_ushort = 2;