From 44c84be302d7719d96d754ac787b2de59d40e643 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Mon, 27 Oct 2025 00:13:15 -0400 Subject: [PATCH 01/31] ci: Add testing for NetBSD The x86-64 NetBSD target is tier 2, so we can start testing it. --- .github/workflows/ci.yaml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index c0fc1aaff51ab..439910893c728 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -270,6 +270,7 @@ jobs: matrix: include: - target: x86_64-pc-solaris + - target: x86_64-unknown-netbsd timeout-minutes: 25 steps: - uses: actions/checkout@v5 @@ -290,6 +291,26 @@ jobs: export PATH=$HOME/.rust_solaris/bin:$PATH ./ci/run.sh ${{ matrix.target }} + - name: Test on NetBSD + uses: vmactions/netbsd-vm@v1 + if: contains(matrix.target, 'netbsd') + with: + release: "10.1" + usesh: true + mem: 4096 + copyback: false + prepare: | + set -x + /usr/sbin/pkg_add curl + curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- \ + --profile minimal --default-toolchain nightly -y + run: | + set -x + . "$HOME/.cargo/env" + which rustc + rustc -Vv + ./ci/run.sh ${{ matrix.target }} + ctest_msrv: name: Check ctest MSRV runs-on: ubuntu-24.04 From 8fd353bd063eb73666c47a3ed3ced9de931f5bb3 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Sun, 2 Nov 2025 21:55:36 -0600 Subject: [PATCH 02/31] Add `core::cfg` to the prelude This is not always present when we are building as `rustc-dep-of-std`. --- src/macros.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/macros.rs b/src/macros.rs index 0d6d84f362eaa..4d116e08fc6ae 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -87,6 +87,7 @@ macro_rules! prelude { pub(crate) use core::prelude::v1::derive; #[allow(unused_imports)] pub(crate) use core::{ + cfg, fmt, hash, iter, From 23cc63d94f38f06090d9986b174edbf27f4453cd Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Sun, 2 Nov 2025 16:21:17 -0600 Subject: [PATCH 03/31] test: Factor out a fallible command runner This pattern is currently used by the `freebsd-version` check but will be used by more in the future. --- libc-test/build.rs | 58 +++++++++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/libc-test/build.rs b/libc-test/build.rs index 8bd7f80558b10..bc88f41225bbb 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -2179,7 +2179,21 @@ fn test_freebsd(target: &str) { assert!(target.contains("freebsd")); let mut cfg = ctest_cfg(); - let freebsd_ver = which_freebsd(); + let freebsd_ver = if let Ok(version) = env::var("RUST_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), @@ -4744,34 +4758,6 @@ fn test_linux_like_apis(target: &str) { } } -fn which_freebsd() -> Option { - if let Ok(version) = env::var("RUST_LIBC_UNSTABLE_FREEBSD_VERSION") { - let vers = version.parse().unwrap(); - println!("cargo:warning=setting FreeBSD version to {vers}"); - return Some(vers); - } - - let output = std::process::Command::new("freebsd-version") - .output() - .ok()?; - - if !output.status.success() { - return None; - } - - let stdout = String::from_utf8(output.stdout).ok()?; - - match &stdout { - s if s.starts_with("10") => Some(10), - s if s.starts_with("11") => Some(11), - s if s.starts_with("12") => Some(12), - s if s.starts_with("13") => Some(13), - s if s.starts_with("14") => Some(14), - s if s.starts_with("15") => Some(15), - _ => None, - } -} - fn test_haiku(target: &str) { assert!(target.contains("haiku")); @@ -5396,3 +5382,17 @@ fn test_aix(target: &str) { ctest::generate_test(&mut cfg, "../src/lib.rs", "ctest_output.rs").unwrap(); } + +/// Attempt to execute a command and collect its output, If the command fails for whatever +/// reason, return `None`. +fn try_command_output(cmd: &str, args: &[&str]) -> Option { + let output = std::process::Command::new(cmd).args(args).output().ok()?; + + if !output.status.success() { + return None; + } + + let res = String::from_utf8(output.stdout) + .unwrap_or_else(|e| panic!("command {cmd} returned non-UTF-8 output: {e}")); + Some(res) +} From 8f67a0f1fbeabdcd6a58a2edb1510ce0aea58d4f Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Tue, 28 Oct 2025 04:18:59 -0400 Subject: [PATCH 04/31] NetBSD: Delete items from the semver file that don't exist Some of these may have been removed. `NI_MAXHOST` is already specified in the unix semver file. --- libc-test/semver/netbsd.txt | 5 ----- 1 file changed, 5 deletions(-) diff --git a/libc-test/semver/netbsd.txt b/libc-test/semver/netbsd.txt index bcd25eca15b93..58d581b7cb4fd 100644 --- a/libc-test/semver/netbsd.txt +++ b/libc-test/semver/netbsd.txt @@ -93,7 +93,6 @@ AT_SUN_IFLUSH AT_SUN_LDELF AT_SUN_LDNAME AT_SUN_LDSHDR -AT_SUN_LPGSIZE AT_SUN_PLATFORM AT_SYMLINK_FOLLOW AT_SYMLINK_NOFOLLOW @@ -734,7 +733,6 @@ NET_RT_OOIFLIST NET_RT_OOOIFLIST NEW_TIME NI_DGRAM -NI_MAXHOST NI_MAXSERV NI_NAMEREQD NI_NOFQDN @@ -845,7 +843,6 @@ POSIX_SPAWN_RETURNERROR POSIX_SPAWN_SETPGROUP POSIX_SPAWN_SETSCHEDPARAM POSIX_SPAWN_SETSCHEDULER -POSIX_SPAWN_SETSIGDEP POSIX_SPAWN_SETSIGMASK PROT_MPROTECT PTHREAD_CREATE_DETACHED @@ -1342,7 +1339,6 @@ futimes getbootfile getbyteorder getdiskrawname -getdistcookedname getdomainname getdtablesize getentropy @@ -1422,7 +1418,6 @@ lcong48 lgetxattr lio_listio listxattr -llistxaatr localeconv_l lockf login From 7f354aa4a0856f2c1e91ac136f84ee2ee99b6ae5 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Sun, 2 Nov 2025 17:20:33 -0600 Subject: [PATCH 05/31] NetBSD: riscv64: Fix the mcontext types Currently this target fails to build. --- src/unix/bsd/netbsdlike/netbsd/riscv64.rs | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/unix/bsd/netbsdlike/netbsd/riscv64.rs b/src/unix/bsd/netbsdlike/netbsd/riscv64.rs index 47240cb2818c0..8cacb7250eddc 100644 --- a/src/unix/bsd/netbsdlike/netbsd/riscv64.rs +++ b/src/unix/bsd/netbsdlike/netbsd/riscv64.rs @@ -1,16 +1,15 @@ -use PT_FIRSTMACH; - use crate::prelude::*; +use crate::PT_FIRSTMACH; pub type __greg_t = u64; pub type __cpu_simple_lock_nv_t = c_int; pub type __gregset = [__greg_t; _NGREG]; -pub type __fregset = [__freg; _NFREG]; +pub type __fregset = [__fpreg; _NFREG]; s! { pub struct mcontext_t { pub __gregs: __gregset, - pub __fregs: __fpregset, + pub __fregs: __fregset, __spare: [crate::__greg_t; 7], } } @@ -22,6 +21,22 @@ s_no_extra_traits! { } } +cfg_if! { + if #[cfg(feature = "extra_traits")] { + impl PartialEq for __fpreg { + fn eq(&self, other: &Self) -> bool { + unsafe { self.u_u64 == other.u_u64 } + } + } + impl Eq for __fpreg {} + impl hash::Hash for __fpreg { + fn hash(&self, state: &mut H) { + unsafe { self.u_u64.hash(state) }; + } + } + } +} + pub(crate) const _ALIGNBYTES: usize = size_of::() - 1; pub const PT_GETREGS: c_int = PT_FIRSTMACH + 0; From 99c9f2d60d50de34249941f7bbb9425f41f20dc9 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Mon, 27 Oct 2025 20:01:26 -0400 Subject: [PATCH 06/31] NetBSD: Update test headers and skips Add headers required for the new constants we have, add skips for things we can't easily fix, and remove skips for things that now work. Additionally, check the NetBSD version via `uname` for configuring skips based on the tested version. --- libc-test/build.rs | 86 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 80 insertions(+), 6 deletions(-) diff --git a/libc-test/build.rs b/libc-test/build.rs index bc88f41225bbb..615be01fb138e 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -1169,6 +1169,12 @@ fn test_netbsd(target: &str) { assert!(target.contains("netbsd")); let mut cfg = ctest_cfg(); + // Assume netbsd10 but check for netbsd9 for test config. + let netbsd9 = match try_command_output("uname", &["-sr"]) { + Some(s) if s.starts_with("NetBSD 9.") => true, + _ => false, + }; + cfg.flag("-Wno-deprecated-declarations"); cfg.define("_NETBSD_SOURCE", Some("1")); @@ -1195,10 +1201,12 @@ fn test_netbsd(target: &str) { "ctype.h", "dirent.h", "dlfcn.h", + "execinfo.h", "glob.h", "grp.h", "ifaddrs.h", "langinfo.h", + "lwp.h", "net/bpf.h", "net/if.h", "net/if_arp.h", @@ -1217,12 +1225,14 @@ fn test_netbsd(target: &str) { "sched.h", "semaphore.h", "signal.h", + "spawn.h", "string.h", "sys/endian.h", "sys/exec_elf.h", "sys/xattr.h", "sys/extattr.h", "sys/file.h", + (!netbsd9, "sys/futex.h"), "sys/ioctl.h", "sys/ioctl_compat.h", "sys/ipc.h", @@ -1230,12 +1240,15 @@ fn test_netbsd(target: &str) { "sys/mman.h", "sys/mount.h", "sys/ptrace.h", + (!netbsd9, "sys/random.h"), "sys/resource.h", + "sys/sched.h", "sys/shm.h", "sys/socket.h", "sys/statvfs.h", "sys/sysctl.h", "sys/time.h", + (!netbsd9, "sys/timerfd.h"), "sys/times.h", "sys/timex.h", "sys/ucontext.h", @@ -1258,6 +1271,8 @@ fn test_netbsd(target: &str) { "sys/reboot.h", "sys/shm.h", "iconv.h", + "utmp.h", + "utmpx.h", ); cfg.rename_type(move |ty| { @@ -1289,10 +1304,14 @@ fn test_netbsd(target: &str) { } }); + cfg.alias_is_c_enum(|ty| ty == "fae_action"); + cfg.skip_alias(move |ty| { match ty.ident() { // FIXME(netbsd): sighandler_t is crazy across platforms "sighandler_t" => true, + // Incomplete type in C + "cpuset_t" => true, _ => false, } }); @@ -1302,6 +1321,10 @@ fn test_netbsd(target: &str) { // These are tested as part of the linux_fcntl tests since there are // header conflicts when including them with all the other structs. "termios2" => true, + // Anon struct + "__exit_status" => true, + // FIXME(netbsd): Should be importable but aren't for some reason. + "Aux32Info" | "Aux64Info" => true, _ => false, } }); @@ -1327,6 +1350,10 @@ fn test_netbsd(target: &str) { "BOTHER" => true, "GRND_RANDOM" | "GRND_INSECURE" | "GRND_NONBLOCK" => true, // netbsd 10 minimum + // Due to the NetBSD `__BIT` macro this turns out to be an `unsigned long`, but + // the futex syscall takes `int` ops. + "FUTEX_CMD_MASK" => true, + _ => false, } }); @@ -1334,12 +1361,8 @@ fn test_netbsd(target: &str) { cfg.skip_fn(move |func| { #[expect(clippy::wildcard_in_or_patterns)] match func.ident() { - // FIXME(netbsd): netbsd 10 minimum - "getentropy" | "getrandom" => true, - - "getrlimit" | "getrlimit64" | // non-int in 1st arg - "setrlimit" | "setrlimit64" | // non-int in 1st arg - "prlimit" | "prlimit64" | // non-int in 2nd arg + // FIXME(netbsd): Look into setting `_POSIX_C_SOURCE` to enable this + "qsort_r" => true, _ => false, } @@ -1361,10 +1384,61 @@ fn test_netbsd(target: &str) { ("Elf64_Phdr", "p_type") => true, // pthread_spin_t is a volatile uchar ("pthread_spinlock_t", "pts_spin") => true, + + // `tcp_snd_wscale` and `tcp_rcv_wscale` are bitfields + ("tcp_info", "tcp_snd_wscale") => true, + ("tcp_info", "tcp_rcv_wscale") => true, + + // Anonymous unions + ("ifconf", "ifc_ifcu") => true, + ("utmpx", "ut_exit") => true, + ("posix_spawn_file_actions_entry_t", "fae_data") => true, + _ => false, } }); + // Unless otherwise noted, everything in this block was an addition in NetBS 10. + if netbsd9 { + cfg.skip_const(move |constant| match constant.ident() { + "EOWNERDEAD" + | "ENOTRECOVERABLE" + | "F_GETPATH" + | "MNT_NFS4ACLS" + | "MNT_POSIX1EACLS" + | "MNT_ACLS" + | "EVFILT_USER" + | "EVFILT_EMPTY" + | "REG_ILLSEQ" + | "PT_SET_SIGPASS" + | "PT_GET_SIGPASS" + | "EXTATTR_NAMESPACE_EMPTY" => true, + x if x.starts_with("FUTEX") => true, + x if x.starts_with("NOTE_") => true, + x if x.starts_with("PT_LWP") => true, + x if x.starts_with("TFD_") => true, + "ELAST" => true, // not version-stable + _ => false, + }); + + cfg.skip_struct(move |struct_| match struct_.ident() { + x if x.starts_with("ptrace_lwp") => true, + _ => false, + }); + + cfg.skip_fn(move |func| match func.ident() { + "reallocarray" | "getentropy" | "ppoll" | "getrandom" => true, + x if x.starts_with("timerfd_") => true, + _ => false, + }); + + cfg.skip_struct_field(|struct_, field| match (struct_.ident(), field.ident()) { + ("statvfs", "f_mntfromlabel") => true, // added field + ("kevent", "udata") => true, // changed type (ABI-compatible) + _ => false, + }); + } + ctest::generate_test(&mut cfg, "../src/lib.rs", "ctest_output.rs").unwrap(); } From 3707e007a86c4be27fb14ad8634008d4c0f09d01 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Sun, 2 Nov 2025 19:27:16 -0600 Subject: [PATCH 07/31] NetBSD: Skip tests on 9.x for network structs with alignment mismatches These were previously packed, but this was changed in NetBSD10. Link: https://github.com/NetBSD/src/commit/1ca39e872702d4539e8844aff15593cf4c18a1cb --- libc-test/build.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libc-test/build.rs b/libc-test/build.rs index 615be01fb138e..133200aa9c315 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -1423,6 +1423,8 @@ fn test_netbsd(target: &str) { cfg.skip_struct(move |struct_| match struct_.ident() { x if x.starts_with("ptrace_lwp") => true, + // These were packed before NetBSD 10 + "arphdr" | "in_addr" | "ip_mreq" | "sockaddr_in" => true, _ => false, }); From a16d14311355974ca36574fe280903d8d98ca85b Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Mon, 27 Oct 2025 20:25:22 -0400 Subject: [PATCH 08/31] NetBSD: Remove IFF_NOTRAILERS Upstream commit: https://github.com/NetBSD/src/commit/091e15265dbe2bb314cd3f15830a81f296d03f40 --- libc-test/semver/netbsd.txt | 1 - src/unix/bsd/netbsdlike/netbsd/mod.rs | 1 - 2 files changed, 2 deletions(-) diff --git a/libc-test/semver/netbsd.txt b/libc-test/semver/netbsd.txt index 58d581b7cb4fd..af57ee5ea4d81 100644 --- a/libc-test/semver/netbsd.txt +++ b/libc-test/semver/netbsd.txt @@ -416,7 +416,6 @@ IFF_LINK2 IFF_LOOPBACK IFF_MULTICAST IFF_NOARP -IFF_NOTRAILERS IFF_OACTIVE IFF_POINTOPOINT IFF_PROMISC diff --git a/src/unix/bsd/netbsdlike/netbsd/mod.rs b/src/unix/bsd/netbsdlike/netbsd/mod.rs index e7f0d08aca0ac..1f0aa34f2b931 100644 --- a/src/unix/bsd/netbsdlike/netbsd/mod.rs +++ b/src/unix/bsd/netbsdlike/netbsd/mod.rs @@ -1117,7 +1117,6 @@ pub const IFF_BROADCAST: c_int = 0x0002; // broadcast address valid pub const IFF_DEBUG: c_int = 0x0004; // turn on debugging pub const IFF_LOOPBACK: c_int = 0x0008; // is a loopback net pub const IFF_POINTOPOINT: c_int = 0x0010; // interface is point-to-point link -pub const IFF_NOTRAILERS: c_int = 0x0020; // avoid use of trailers pub const IFF_RUNNING: c_int = 0x0040; // resources allocated pub const IFF_NOARP: c_int = 0x0080; // no address resolution protocol pub const IFF_PROMISC: c_int = 0x0100; // receive all packets From e59edd0d7e6fec9e99dcf65dc2e3d6b21a0d0941 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Tue, 28 Oct 2025 22:50:55 -0400 Subject: [PATCH 09/31] NetBSD: Remove `*_MAXID` constants and `AT_SUN_LDPGSIZE` These assorted constants may have existed at some point but I can't find any reference to them in the source repo. Remove them now. --- libc-test/semver/netbsd.txt | 3 --- src/unix/bsd/netbsdlike/netbsd/mod.rs | 4 ---- 2 files changed, 7 deletions(-) diff --git a/libc-test/semver/netbsd.txt b/libc-test/semver/netbsd.txt index af57ee5ea4d81..ab4a8b1dbda10 100644 --- a/libc-test/semver/netbsd.txt +++ b/libc-test/semver/netbsd.txt @@ -179,7 +179,6 @@ CTL_HW CTL_IPPROTO_IPSEC CTL_KERN CTL_MACHDEP -CTL_MAXID CTL_MAXNAME CTL_MMAP CTL_NET @@ -532,7 +531,6 @@ KERN_LOGSIGEXIT KERN_LWP KERN_MAPPED_FILES KERN_MAXFILES -KERN_MAXID KERN_MAXPARTITIONS KERN_MAXPHYS KERN_MAXPROC @@ -726,7 +724,6 @@ NANOSECOND NET_RT_DUMP NET_RT_FLAGS NET_RT_IFLIST -NET_RT_MAXID NET_RT_OIFLIST NET_RT_OOIFLIST NET_RT_OOOIFLIST diff --git a/src/unix/bsd/netbsdlike/netbsd/mod.rs b/src/unix/bsd/netbsdlike/netbsd/mod.rs index 1f0aa34f2b931..b378b7c68cdeb 100644 --- a/src/unix/bsd/netbsdlike/netbsd/mod.rs +++ b/src/unix/bsd/netbsdlike/netbsd/mod.rs @@ -976,7 +976,6 @@ pub const AT_RGID: c_int = 2003; pub const AT_SUN_LDELF: c_int = 2004; pub const AT_SUN_LDSHDR: c_int = 2005; pub const AT_SUN_LDNAME: c_int = 2006; -pub const AT_SUN_LDPGSIZE: c_int = 2007; pub const AT_SUN_PLATFORM: c_int = 2008; pub const AT_SUN_HWCAP: c_int = 2009; pub const AT_SUN_IFLUSH: c_int = 2010; @@ -1218,7 +1217,6 @@ pub const NET_RT_OOOIFLIST: c_int = 3; pub const NET_RT_OOIFLIST: c_int = 4; pub const NET_RT_OIFLIST: c_int = 5; pub const NET_RT_IFLIST: c_int = 6; -pub const NET_RT_MAXID: c_int = 7; pub const PF_OROUTE: c_int = AF_OROUTE; pub const PF_ARP: c_int = AF_ARP; @@ -1700,7 +1698,6 @@ pub const CTL_PROC: c_int = 10; pub const CTL_VENDOR: c_int = 11; pub const CTL_EMUL: c_int = 12; pub const CTL_SECURITY: c_int = 13; -pub const CTL_MAXID: c_int = 14; pub const KERN_OSTYPE: c_int = 1; pub const KERN_OSRELEASE: c_int = 2; pub const KERN_OSREV: c_int = 3; @@ -1785,7 +1782,6 @@ pub const KERN_ARND: c_int = 81; pub const KERN_SYSVIPC: c_int = 82; pub const KERN_BOOTTIME: c_int = 83; pub const KERN_EVCNT: c_int = 84; -pub const KERN_MAXID: c_int = 85; pub const KERN_PROC_ALL: c_int = 0; pub const KERN_PROC_PID: c_int = 1; pub const KERN_PROC_PGRP: c_int = 2; From c0258a17f784083bababe71f46ea50e801db087f Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Mon, 27 Oct 2025 22:40:25 -0400 Subject: [PATCH 10/31] NetBSD: Remove `vm_size_t` As noted, this has been deprecated a long time and is no longer present on x86_64. Remove the typedef. --- libc-test/semver/netbsd.txt | 1 - src/unix/bsd/netbsdlike/netbsd/mod.rs | 1 - 2 files changed, 2 deletions(-) diff --git a/libc-test/semver/netbsd.txt b/libc-test/semver/netbsd.txt index ab4a8b1dbda10..c02af7ccf5e21 100644 --- a/libc-test/semver/netbsd.txt +++ b/libc-test/semver/netbsd.txt @@ -1647,6 +1647,5 @@ utmpxname utpname utrace uucred -vm_size_t wait4 waitid diff --git a/src/unix/bsd/netbsdlike/netbsd/mod.rs b/src/unix/bsd/netbsdlike/netbsd/mod.rs index b378b7c68cdeb..3c26aa552ad6f 100644 --- a/src/unix/bsd/netbsdlike/netbsd/mod.rs +++ b/src/unix/bsd/netbsdlike/netbsd/mod.rs @@ -13,7 +13,6 @@ pub type fsfilcnt_t = u64; pub type idtype_t = c_int; pub type mqd_t = c_int; type __pthread_spin_t = __cpu_simple_lock_nv_t; -pub type vm_size_t = crate::uintptr_t; // FIXME(deprecated): deprecated since long time pub type lwpid_t = c_uint; pub type shmatt_t = c_uint; pub type cpuid_t = c_ulong; From 185a5657e8cac3c13741fbcae13a96b5d94e0aba Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Tue, 28 Oct 2025 21:29:36 -0400 Subject: [PATCH 11/31] NetBSD: Remove BPF constants These are currently incorrect, so remove them for now. If desired, they can be added back in the future using the `_IO*` functions. --- libc-test/semver/netbsd.txt | 18 ---------------- src/unix/bsd/mod.rs | 31 ++++++++++++++++----------- src/unix/bsd/netbsdlike/netbsd/mod.rs | 6 ------ 3 files changed, 18 insertions(+), 37 deletions(-) diff --git a/libc-test/semver/netbsd.txt b/libc-test/semver/netbsd.txt index c02af7ccf5e21..97c39c24f8ccc 100644 --- a/libc-test/semver/netbsd.txt +++ b/libc-test/semver/netbsd.txt @@ -103,23 +103,6 @@ B460800 B7200 B76800 B921600 -BIOCFLUSH -BIOCGBLEN -BIOCGDLT -BIOCGETIF -BIOCGHDRCMPLT -BIOCGRSIG -BIOCGSEESENT -BIOCGSTATS -BIOCIMMEDIATE -BIOCPROMISC -BIOCSBLEN -BIOCSDLT -BIOCSETIF -BIOCSHDRCMPLT -BIOCSRSIG -BIOCSSEESENT -BIOCVERSION BOOT_TIME BUFSIZ BUS_ADRALN @@ -990,7 +973,6 @@ SIGINFO SIGIO SIGNATURE SIGSTKSZ -SIOCGIFADDR SOCKCREDSIZE SOCK_CLOEXEC SOCK_CONN_DGRAM diff --git a/src/unix/bsd/mod.rs b/src/unix/bsd/mod.rs index 420ff3b1bab1f..18f513719e3d1 100644 --- a/src/unix/bsd/mod.rs +++ b/src/unix/bsd/mod.rs @@ -398,19 +398,24 @@ pub const POLLWRNORM: c_short = 0x004; pub const POLLRDBAND: c_short = 0x080; pub const POLLWRBAND: c_short = 0x100; -pub const BIOCGBLEN: c_ulong = 0x40044266; -pub const BIOCSBLEN: c_ulong = 0xc0044266; -pub const BIOCFLUSH: c_uint = 0x20004268; -pub const BIOCPROMISC: c_uint = 0x20004269; -pub const BIOCGDLT: c_ulong = 0x4004426a; -pub const BIOCGETIF: c_ulong = 0x4020426b; -pub const BIOCSETIF: c_ulong = 0x8020426c; -pub const BIOCGSTATS: c_ulong = 0x4008426f; -pub const BIOCIMMEDIATE: c_ulong = 0x80044270; -pub const BIOCVERSION: c_ulong = 0x40044271; -pub const BIOCGHDRCMPLT: c_ulong = 0x40044274; -pub const BIOCSHDRCMPLT: c_ulong = 0x80044275; -pub const SIOCGIFADDR: c_ulong = 0xc0206921; +cfg_if! { + // Not yet implemented on NetBSD + if #[cfg(not(any(target_os = "netbsd")))] { + pub const BIOCGBLEN: c_ulong = 0x40044266; + pub const BIOCSBLEN: c_ulong = 0xc0044266; + pub const BIOCFLUSH: c_uint = 0x20004268; + pub const BIOCPROMISC: c_uint = 0x20004269; + pub const BIOCGDLT: c_ulong = 0x4004426a; + pub const BIOCGETIF: c_ulong = 0x4020426b; + pub const BIOCSETIF: c_ulong = 0x8020426c; + pub const BIOCGSTATS: c_ulong = 0x4008426f; + pub const BIOCIMMEDIATE: c_ulong = 0x80044270; + pub const BIOCVERSION: c_ulong = 0x40044271; + pub const BIOCGHDRCMPLT: c_ulong = 0x40044274; + pub const BIOCSHDRCMPLT: c_ulong = 0x80044275; + pub const SIOCGIFADDR: c_ulong = 0xc0206921; + } +} pub const REG_BASIC: c_int = 0o0000; pub const REG_EXTENDED: c_int = 0o0001; diff --git a/src/unix/bsd/netbsdlike/netbsd/mod.rs b/src/unix/bsd/netbsdlike/netbsd/mod.rs index 3c26aa552ad6f..3fbf0148f3377 100644 --- a/src/unix/bsd/netbsdlike/netbsd/mod.rs +++ b/src/unix/bsd/netbsdlike/netbsd/mod.rs @@ -1402,12 +1402,6 @@ pub const FD_SETSIZE: c_int = 0x100; pub const ST_NOSUID: c_ulong = 8; -pub const BIOCGRSIG: c_ulong = 0x40044272; -pub const BIOCSRSIG: c_ulong = 0x80044273; -pub const BIOCSDLT: c_ulong = 0x80044278; -pub const BIOCGSEESENT: c_ulong = 0x40044276; -pub const BIOCSSEESENT: c_ulong = 0x80044277; - // pub const MNT_UNION: c_int = 0x00000020; pub const MNT_NOCOREDUMP: c_int = 0x00008000; From e65f8f1a54565bc15d674b997cb37a961d01b582 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Mon, 27 Oct 2025 20:31:28 -0400 Subject: [PATCH 12/31] NetBSD: Replace REG_ENOSYS with REG_ILLSEQ Upstream commit: https://github.com/NetBSD/src/commit/cc8bab3745d49df3be13e903212f10c5fbee6c75 --- libc-test/semver/netbsd.txt | 1 - src/unix/bsd/netbsdlike/netbsd/mod.rs | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/libc-test/semver/netbsd.txt b/libc-test/semver/netbsd.txt index 97c39c24f8ccc..1f2a04c678632 100644 --- a/libc-test/semver/netbsd.txt +++ b/libc-test/semver/netbsd.txt @@ -884,7 +884,6 @@ REG_ECOLLATE REG_ECTYPE REG_EESCAPE REG_EMPTY -REG_ENOSYS REG_EPAREN REG_ERANGE REG_ESPACE diff --git a/src/unix/bsd/netbsdlike/netbsd/mod.rs b/src/unix/bsd/netbsdlike/netbsd/mod.rs index 3fbf0148f3377..8048a6c0f517c 100644 --- a/src/unix/bsd/netbsdlike/netbsd/mod.rs +++ b/src/unix/bsd/netbsdlike/netbsd/mod.rs @@ -1881,7 +1881,7 @@ pub const FIBMAP: c_ulong = 0xc008667a; pub const SIGSTKSZ: size_t = 40960; -pub const REG_ENOSYS: c_int = 17; +pub const REG_ILLSEQ: c_int = 17; pub const PT_DUMPCORE: c_int = 12; pub const PT_LWPINFO: c_int = 13; From cc2d05d7d81aa14445e70555fa2d24f11eed333c Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Mon, 27 Oct 2025 22:05:52 -0400 Subject: [PATCH 13/31] NetBSD: Fix `uucred.cr_ngroups` from `int` to `short` Link: https://github.com/NetBSD/src/blob/6017cb90fd7d83ed6e45d93129b12d525978c2fa/sys/sys/ucred.h#L52 --- src/unix/bsd/netbsdlike/netbsd/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/unix/bsd/netbsdlike/netbsd/mod.rs b/src/unix/bsd/netbsdlike/netbsd/mod.rs index 8048a6c0f517c..c39389b1355ce 100644 --- a/src/unix/bsd/netbsdlike/netbsd/mod.rs +++ b/src/unix/bsd/netbsdlike/netbsd/mod.rs @@ -394,7 +394,7 @@ s! { pub cr_unused: c_ushort, pub cr_uid: crate::uid_t, pub cr_gid: crate::gid_t, - pub cr_ngroups: c_int, + pub cr_ngroups: c_short, pub cr_groups: [crate::gid_t; NGROUPS_MAX as usize], } From 63f40376430e3f86b895d2b73621c2e25e802858 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Mon, 27 Oct 2025 22:28:15 -0400 Subject: [PATCH 14/31] NetBSD: Fix the type of `kevent.udata` This changed in 10.0. The change is ABI-compatible so we can make it now. This is a minor break, but should allow users to remove some special casing on NetBSD since this brings it in line with other BSDs. Link: https://github.com/NetBSD/src/blob/6017cb90fd7d83ed6e45d93129b12d525978c2fa/sys/sys/event.h#L72 --- src/unix/bsd/netbsdlike/netbsd/mod.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/unix/bsd/netbsdlike/netbsd/mod.rs b/src/unix/bsd/netbsdlike/netbsd/mod.rs index c39389b1355ce..19935c1bd0f33 100644 --- a/src/unix/bsd/netbsdlike/netbsd/mod.rs +++ b/src/unix/bsd/netbsdlike/netbsd/mod.rs @@ -299,8 +299,7 @@ s! { pub flags: u32, pub fflags: u32, pub data: i64, - // FIXME(netbsd): NetBSD 10.0 will finally have same layout as other BSD - pub udata: intptr_t, + pub udata: *mut c_void, } pub struct dqblk { From a1426ae5cdc0428f69687d89f4257dddc1b688ce Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Tue, 28 Oct 2025 22:21:00 -0400 Subject: [PATCH 15/31] NetBSD: Fix the value of `PT_SUSPEND` Link: https://github.com/NetBSD/src/blob/6ace5fed3bd010695a1b88ca6c1f8a5af7793ffb/sys/sys/ptrace.h#L62 --- src/unix/bsd/netbsdlike/netbsd/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/unix/bsd/netbsdlike/netbsd/mod.rs b/src/unix/bsd/netbsdlike/netbsd/mod.rs index 19935c1bd0f33..4a68315422f66 100644 --- a/src/unix/bsd/netbsdlike/netbsd/mod.rs +++ b/src/unix/bsd/netbsdlike/netbsd/mod.rs @@ -1892,7 +1892,7 @@ pub const PT_GET_PROCESS_STATE: c_int = 18; pub const PT_SET_SIGINFO: c_int = 19; pub const PT_GET_SIGINFO: c_int = 20; pub const PT_RESUME: c_int = 21; -pub const PT_SUSPEND: c_int = 23; +pub const PT_SUSPEND: c_int = 22; pub const PT_STOP: c_int = 23; pub const PT_LWPSTATUS: c_int = 24; pub const PT_LWPNEXT: c_int = 25; From 03761f1b16138b4c7024d6362fee2a8429e69303 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Tue, 28 Oct 2025 16:44:16 -0400 Subject: [PATCH 16/31] NetBSD: Fix the values of FNM_* constants Link: https://github.com/NetBSD/src/blob/908770859a5d5141adc63c7844190d01db8a18a4/include/fnmatch.h#L43-L48 --- src/unix/mod.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/unix/mod.rs b/src/unix/mod.rs index dbf84dc8d977f..6b811ce92ef48 100644 --- a/src/unix/mod.rs +++ b/src/unix/mod.rs @@ -369,7 +369,11 @@ cfg_if! { pub const FNM_NOMATCH: c_int = 1; cfg_if! { - if #[cfg(any(target_os = "illumos", target_os = "solaris",))] { + if #[cfg(any( + target_os = "illumos", + target_os = "solaris", + target_os = "netbsd" + ))] { pub const FNM_CASEFOLD: c_int = 1 << 3; } else if #[cfg(not(target_os = "aix"))] { pub const FNM_CASEFOLD: c_int = 1 << 4; @@ -383,6 +387,7 @@ cfg_if! { target_os = "android", target_os = "openbsd", target_os = "cygwin", + target_os = "netbsd", ))] { pub const FNM_PATHNAME: c_int = 1 << 1; } else { @@ -396,6 +401,7 @@ cfg_if! { target_os = "freebsd", target_os = "android", target_os = "openbsd", + target_os = "netbsd", ))] { pub const FNM_NOESCAPE: c_int = 1 << 0; } else if #[cfg(target_os = "nto")] { From 3aa704476977ede6763f02db49320b76c4f730cb Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Mon, 27 Oct 2025 22:23:29 -0400 Subject: [PATCH 17/31] NetBSD: Fix the type of `mcontext_t.__fpregs` Link: https://github.com/NetBSD/src/blob/6017cb90fd7d83ed6e45d93129b12d525978c2fa/sys/arch/amd64/include/mcontext.h#L59-L65 --- src/unix/bsd/netbsdlike/netbsd/x86_64.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/unix/bsd/netbsdlike/netbsd/x86_64.rs b/src/unix/bsd/netbsdlike/netbsd/x86_64.rs index 77daa4b1e9eb2..801b326b70fa5 100644 --- a/src/unix/bsd/netbsdlike/netbsd/x86_64.rs +++ b/src/unix/bsd/netbsdlike/netbsd/x86_64.rs @@ -4,11 +4,14 @@ use crate::PT_FIRSTMACH; pub type c___greg_t = u64; pub type __cpu_simple_lock_nv_t = c_uchar; +// FIXME(alignment): Type is `__aligned(8)` +type __fpregset_t = [c_char; 512]; + s! { pub struct mcontext_t { pub __gregs: [c___greg_t; 26], pub _mc_tlsbase: c___greg_t, - pub __fpregs: [[c_char; 32]; 16], + pub __fpregs: __fpregset_t, } pub struct ucontext_t { From 75fff514cc7c2a7a7bda55131dd2092578951ad8 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Mon, 27 Oct 2025 22:09:54 -0400 Subject: [PATCH 18/31] NetBSD: Increase the size of `sockaddr_dl.sdl_data` from 12 to 24 Upstream commit: https://github.com/NetBSD/src/commit/a3d9e0f54ed964e4da9d6ef05c15f769c7bc2bc9 --- libc-test/build.rs | 1 + src/unix/bsd/netbsdlike/netbsd/mod.rs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/libc-test/build.rs b/libc-test/build.rs index 133200aa9c315..af1744831d86d 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -1422,6 +1422,7 @@ fn test_netbsd(target: &str) { }); cfg.skip_struct(move |struct_| match struct_.ident() { + "sockaddr_dl" => true, // Last field increased size in 10 x if x.starts_with("ptrace_lwp") => true, // These were packed before NetBSD 10 "arphdr" | "in_addr" | "ip_mreq" | "sockaddr_in" => true, diff --git a/src/unix/bsd/netbsdlike/netbsd/mod.rs b/src/unix/bsd/netbsdlike/netbsd/mod.rs index 4a68315422f66..584ed485ffbb9 100644 --- a/src/unix/bsd/netbsdlike/netbsd/mod.rs +++ b/src/unix/bsd/netbsdlike/netbsd/mod.rs @@ -411,7 +411,7 @@ s! { pub sdl_nlen: u8, pub sdl_alen: u8, pub sdl_slen: u8, - pub sdl_data: [c_char; 12], + pub sdl_data: [c_char; 24], } pub struct __exit_status { From 9b0dedb5261b74099b4e6fd77ed5384c6d81b330 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Mon, 27 Oct 2025 22:35:46 -0400 Subject: [PATCH 19/31] NetBSD: Make `_cpuset` an extern type Our definition was correct for how it is defined internally, but in the header where it is included it is an incomplete definition. Link: https://github.com/NetBSD/src/blob/6017cb90fd7d83ed6e45d93129b12d525978c2fa/sys/sys/sched.h#L99 --- src/unix/bsd/netbsdlike/netbsd/mod.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/unix/bsd/netbsdlike/netbsd/mod.rs b/src/unix/bsd/netbsdlike/netbsd/mod.rs index 584ed485ffbb9..8e12a837197e0 100644 --- a/src/unix/bsd/netbsdlike/netbsd/mod.rs +++ b/src/unix/bsd/netbsdlike/netbsd/mod.rs @@ -48,6 +48,10 @@ c_enum! { } } +extern_ty! { + pub enum _cpuset {} +} + cfg_if! { if #[cfg(target_pointer_width = "64")] { type Elf_Addr = Elf64_Addr; @@ -519,10 +523,6 @@ s! { pub dlpi_tls_data: *mut c_void, } - pub struct _cpuset { - bits: [u32; 0], - } - pub struct accept_filter_arg { pub af_name: [c_char; 16], pub af_arg: [c_char; 256 - 16], From b2606341ec5f247f590f3623f2112e5e3f2c48f3 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Mon, 27 Oct 2025 20:46:56 -0400 Subject: [PATCH 20/31] NetBSD: Account for upstream changes to ptrace with LWP Deprecate the PT_LWPINFO and PL_EVENT* constants, as well as `ptrace_lwpinfo`. Upstream commit: https://github.com/NetBSD/src/commit/4f79a484704c25ba5c21ab92911b2c71cf56a9dd --- libc-test/build.rs | 5 +++++ src/unix/bsd/netbsdlike/netbsd/mod.rs | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/libc-test/build.rs b/libc-test/build.rs index af1744831d86d..00c8efe7488bd 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -1325,6 +1325,8 @@ fn test_netbsd(target: &str) { "__exit_status" => true, // FIXME(netbsd): Should be importable but aren't for some reason. "Aux32Info" | "Aux64Info" => true, + // deprecated, obsolete upstream + "ptrace_lwpinfo" => true, _ => false, } }); @@ -1344,6 +1346,9 @@ fn test_netbsd(target: &str) { "SIG_DFL" | "SIG_ERR" | "SIG_IGN" => true, // sighandler_t weirdness "SIGUNUSED" => true, // removed in glibc 2.26 + // deprecated, obsolete upstream + "PT_LWPINFO" | "PL_EVENT_NONE" | "PL_EVENT_SIGNAL" | "PL_EVENT_SUSPENDED" => true, + // weird signed extension or something like that? "MS_NOUSER" => true, "MS_RMT_MASK" => true, // updated in glibc 2.22 and musl 1.1.13 diff --git a/src/unix/bsd/netbsdlike/netbsd/mod.rs b/src/unix/bsd/netbsdlike/netbsd/mod.rs index 8e12a837197e0..7ef23714fc460 100644 --- a/src/unix/bsd/netbsdlike/netbsd/mod.rs +++ b/src/unix/bsd/netbsdlike/netbsd/mod.rs @@ -710,6 +710,7 @@ s! { pub fae: *mut posix_spawn_file_actions_entry_t, } + #[deprecated(since = "0.2.178", note = "obsolete upstream")] pub struct ptrace_lwpinfo { pub pl_lwpid: lwpid_t, pub pl_event: c_int, @@ -1501,8 +1502,11 @@ pub const TIME_ERROR: c_int = 5; pub const LITTLE_ENDIAN: c_int = 1234; pub const BIG_ENDIAN: c_int = 4321; +#[deprecated(since = "0.2.178", note = "obsolete upstream")] pub const PL_EVENT_NONE: c_int = 0; +#[deprecated(since = "0.2.178", note = "obsolete upstream")] pub const PL_EVENT_SIGNAL: c_int = 1; +#[deprecated(since = "0.2.178", note = "obsolete upstream")] pub const PL_EVENT_SUSPENDED: c_int = 2; cfg_if! { @@ -1883,6 +1887,7 @@ pub const SIGSTKSZ: size_t = 40960; pub const REG_ILLSEQ: c_int = 17; pub const PT_DUMPCORE: c_int = 12; +#[deprecated(note = "obsolete operation")] pub const PT_LWPINFO: c_int = 13; pub const PT_SYSCALL: c_int = 14; pub const PT_SYSCALLEMU: c_int = 15; From 579a14567dc2b04f18cf8f5c19df109c5c99d699 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Tue, 28 Oct 2025 20:03:10 -0400 Subject: [PATCH 21/31] NetBSD: Introduce `statvfs.rs` Move statvfs types to the `new` module. Link: https://github.com/NetBSD/src/blob/6ace5fed3bd010695a1b88ca6c1f8a5af7793ffb/sys/sys/statvfs.h#L66-L101 --- src/new/mod.rs | 2 ++ src/new/netbsd/mod.rs | 3 ++ src/new/netbsd/sys/mod.rs | 5 +++ src/new/netbsd/sys/statvfs.rs | 44 +++++++++++++++++++++++++++ src/unix/bsd/netbsdlike/netbsd/mod.rs | 36 +--------------------- src/unix/mod.rs | 4 +-- 6 files changed, 57 insertions(+), 37 deletions(-) create mode 100644 src/new/netbsd/sys/mod.rs create mode 100644 src/new/netbsd/sys/statvfs.rs diff --git a/src/new/mod.rs b/src/new/mod.rs index 1846ada479fba..dded532dc8004 100644 --- a/src/new/mod.rs +++ b/src/new/mod.rs @@ -182,6 +182,8 @@ cfg_if! { pub use net::route::*; } else if #[cfg(target_vendor = "apple")] { pub use signal::*; + } else if #[cfg(target_os = "netbsd")] { + pub use sys::statvfs::*; } } diff --git a/src/new/netbsd/mod.rs b/src/new/netbsd/mod.rs index b43e7aeb088d2..73bdb8292d6ef 100644 --- a/src/new/netbsd/mod.rs +++ b/src/new/netbsd/mod.rs @@ -1,5 +1,8 @@ //! NetBSD libc. //! +//! * Headers: +//! * Sys headers: //! * Manual pages: +pub(crate) mod sys; pub(crate) mod unistd; diff --git a/src/new/netbsd/sys/mod.rs b/src/new/netbsd/sys/mod.rs new file mode 100644 index 0000000000000..0ac2d2e2d876c --- /dev/null +++ b/src/new/netbsd/sys/mod.rs @@ -0,0 +1,5 @@ +//! Directory: `sys/` +//! +//! https://github.com/NetBSD/src/tree/trunk/sys/sys + +pub(crate) mod statvfs; diff --git a/src/new/netbsd/sys/statvfs.rs b/src/new/netbsd/sys/statvfs.rs new file mode 100644 index 0000000000000..640f42a33b21f --- /dev/null +++ b/src/new/netbsd/sys/statvfs.rs @@ -0,0 +1,44 @@ +//! Header: `sys/statvfs.h` +//! +//! + +use crate::prelude::*; + +const _VFS_NAMELEN: usize = 32; +const _VFS_MNAMELEN: usize = 1024; + +s! { + pub struct statvfs { + pub f_flag: c_ulong, + pub f_bsize: c_ulong, + pub f_frsize: c_ulong, + pub f_iosize: c_ulong, + + pub f_blocks: crate::fsblkcnt_t, + pub f_bfree: crate::fsblkcnt_t, + pub f_bavail: crate::fsblkcnt_t, + pub f_bresvd: crate::fsblkcnt_t, + + pub f_files: crate::fsfilcnt_t, + pub f_ffree: crate::fsfilcnt_t, + pub f_favail: crate::fsfilcnt_t, + pub f_fresvd: crate::fsfilcnt_t, + + pub f_syncreads: u64, + pub f_syncwrites: u64, + + pub f_asyncreads: u64, + pub f_asyncwrites: u64, + + pub f_fsidx: crate::fsid_t, + pub f_fsid: c_ulong, + pub f_namemax: c_ulong, + pub f_owner: crate::uid_t, + + pub f_spare: [u32; 4], + + pub f_fstypename: [c_char; _VFS_NAMELEN], + pub f_mntonname: [c_char; _VFS_MNAMELEN], + pub f_mntfromname: [c_char; _VFS_MNAMELEN], + } +} diff --git a/src/unix/bsd/netbsdlike/netbsd/mod.rs b/src/unix/bsd/netbsdlike/netbsd/mod.rs index 7ef23714fc460..406b21a3794c9 100644 --- a/src/unix/bsd/netbsdlike/netbsd/mod.rs +++ b/src/unix/bsd/netbsdlike/netbsd/mod.rs @@ -851,40 +851,6 @@ s! { pub d_name: [c_char; 512], } - pub struct statvfs { - pub f_flag: c_ulong, - pub f_bsize: c_ulong, - pub f_frsize: c_ulong, - pub f_iosize: c_ulong, - - pub f_blocks: crate::fsblkcnt_t, - pub f_bfree: crate::fsblkcnt_t, - pub f_bavail: crate::fsblkcnt_t, - pub f_bresvd: crate::fsblkcnt_t, - - pub f_files: crate::fsfilcnt_t, - pub f_ffree: crate::fsfilcnt_t, - pub f_favail: crate::fsfilcnt_t, - pub f_fresvd: crate::fsfilcnt_t, - - pub f_syncreads: u64, - pub f_syncwrites: u64, - - pub f_asyncreads: u64, - pub f_asyncwrites: u64, - - pub f_fsidx: crate::fsid_t, - pub f_fsid: c_ulong, - pub f_namemax: c_ulong, - pub f_owner: crate::uid_t, - - pub f_spare: [u32; 4], - - pub f_fstypename: [c_char; 32], - pub f_mntonname: [c_char; 1024], - pub f_mntfromname: [c_char; 1024], - } - pub struct sockaddr_storage { pub ss_len: u8, pub ss_family: crate::sa_family_t, @@ -2459,7 +2425,7 @@ extern "C" { ) -> c_int; #[link_name = "__getmntinfo13"] pub fn getmntinfo(mntbufp: *mut *mut crate::statvfs, flags: c_int) -> c_int; - pub fn getvfsstat(buf: *mut statvfs, bufsize: size_t, flags: c_int) -> c_int; + pub fn getvfsstat(buf: *mut crate::statvfs, bufsize: size_t, flags: c_int) -> c_int; // Added in `NetBSD` 10.0 pub fn timerfd_create(clockid: crate::clockid_t, flags: c_int) -> c_int; diff --git a/src/unix/mod.rs b/src/unix/mod.rs index 6b811ce92ef48..a070b697b905c 100644 --- a/src/unix/mod.rs +++ b/src/unix/mod.rs @@ -1556,9 +1556,9 @@ extern "C" { pub fn sem_trywait(sem: *mut sem_t) -> c_int; pub fn sem_post(sem: *mut sem_t) -> c_int; #[cfg_attr(gnu_file_offset_bits64, link_name = "statvfs64")] - pub fn statvfs(path: *const c_char, buf: *mut statvfs) -> c_int; + pub fn statvfs(path: *const c_char, buf: *mut crate::statvfs) -> c_int; #[cfg_attr(gnu_file_offset_bits64, link_name = "fstatvfs64")] - pub fn fstatvfs(fd: c_int, buf: *mut statvfs) -> c_int; + pub fn fstatvfs(fd: c_int, buf: *mut crate::statvfs) -> c_int; #[cfg_attr(target_os = "netbsd", link_name = "__sigemptyset14")] pub fn sigemptyset(set: *mut sigset_t) -> c_int; From 18e83154d5aa96a6b99684f450822655c62e1cf1 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Mon, 27 Oct 2025 22:14:20 -0400 Subject: [PATCH 22/31] NetBSD: Make `statvfs.f_spare` non-public With NetBSD10 the type changes and fields get adjusted. Make the field nonpublic now to prepare for this change in the future. This is a minor breaking change but means that the NetBSD10 updates will not be breaking. Link: https://github.com/NetBSD/src/blob/6017cb90fd7d83ed6e45d93129b12d525978c2fa/sys/sys/statvfs.h#L94 --- src/new/netbsd/sys/statvfs.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/new/netbsd/sys/statvfs.rs b/src/new/netbsd/sys/statvfs.rs index 640f42a33b21f..eee3766300ce6 100644 --- a/src/new/netbsd/sys/statvfs.rs +++ b/src/new/netbsd/sys/statvfs.rs @@ -35,10 +35,13 @@ s! { pub f_namemax: c_ulong, pub f_owner: crate::uid_t, - pub f_spare: [u32; 4], + // This type is updated in a future version + f_spare: [u32; 4], pub f_fstypename: [c_char; _VFS_NAMELEN], pub f_mntonname: [c_char; _VFS_MNAMELEN], pub f_mntfromname: [c_char; _VFS_MNAMELEN], + // Added in NetBSD10 + // pub f_mntfromlabel: [c_char; _VFS_MNAMELEN], } } From 50ddd7bfd11b7036a623d141b3bedc45756b20ec Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Sun, 2 Nov 2025 19:02:28 -0600 Subject: [PATCH 23/31] NetBSD: Skip tests for structvfs on NetBSD10 This went through an ABI change with a symbol version in NetBSD10. Our version still works but tests don't pass. Link: https://github.com/NetBSD/src/commit/02cdd248ec8b17634bab40aa4f2e161a756d7fce --- libc-test/build.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libc-test/build.rs b/libc-test/build.rs index 00c8efe7488bd..c74e4c811de8c 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -1327,6 +1327,8 @@ fn test_netbsd(target: &str) { "Aux32Info" | "Aux64Info" => true, // deprecated, obsolete upstream "ptrace_lwpinfo" => true, + // ABI change in NetBSD10, with symbol versioning. + "statvfs" if !netbsd9 => true, _ => false, } }); From 0255bbd7801527ddfbaf266448e01e73ddc1a6b7 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Tue, 28 Oct 2025 20:24:30 -0400 Subject: [PATCH 24/31] NetBSD: Correct `ipc_perm`, split from OpenBSD as `ipc.rs` The field ordering is incorrect on NetBSD. Move it to the `new` module for NetBSD and OpenBSD and fix the mismatch on NetBSD. Link: https://github.com/NetBSD/src/blob/6ace5fed3bd010695a1b88ca6c1f8a5af7793ffb/sys/sys/ipc.h#L54-L68 Link: https://github.com/openbsd/src/blob/9abc5df53d8ad6b65dbd35b89ed94f73e2fc58da/sys/sys/ipc.h#L53-L61 --- src/new/mod.rs | 3 +++ src/new/netbsd/sys/ipc.rs | 17 +++++++++++++++++ src/new/netbsd/sys/mod.rs | 1 + src/new/openbsd/mod.rs | 1 + src/new/openbsd/sys/ipc.rs | 17 +++++++++++++++++ src/new/openbsd/sys/mod.rs | 5 +++++ src/unix/bsd/netbsdlike/mod.rs | 16 ---------------- 7 files changed, 44 insertions(+), 16 deletions(-) create mode 100644 src/new/netbsd/sys/ipc.rs create mode 100644 src/new/openbsd/sys/ipc.rs create mode 100644 src/new/openbsd/sys/mod.rs diff --git a/src/new/mod.rs b/src/new/mod.rs index dded532dc8004..9cb6e5b969fe1 100644 --- a/src/new/mod.rs +++ b/src/new/mod.rs @@ -183,7 +183,10 @@ cfg_if! { } else if #[cfg(target_vendor = "apple")] { pub use signal::*; } else if #[cfg(target_os = "netbsd")] { + pub use sys::ipc::*; pub use sys::statvfs::*; + } else if #[cfg(target_os = "openbsd")] { + pub use sys::ipc::*; } } diff --git a/src/new/netbsd/sys/ipc.rs b/src/new/netbsd/sys/ipc.rs new file mode 100644 index 0000000000000..49a1c84d74296 --- /dev/null +++ b/src/new/netbsd/sys/ipc.rs @@ -0,0 +1,17 @@ +//! Header: `sys/ipc.h` +//! +//! + +use crate::prelude::*; + +s! { + pub struct ipc_perm { + pub uid: crate::uid_t, + pub gid: crate::gid_t, + pub cuid: crate::uid_t, + pub cgid: crate::gid_t, + pub mode: crate::mode_t, + pub _seq: c_ushort, + pub _key: crate::key_t, + } +} diff --git a/src/new/netbsd/sys/mod.rs b/src/new/netbsd/sys/mod.rs index 0ac2d2e2d876c..7fab417362739 100644 --- a/src/new/netbsd/sys/mod.rs +++ b/src/new/netbsd/sys/mod.rs @@ -2,4 +2,5 @@ //! //! https://github.com/NetBSD/src/tree/trunk/sys/sys +pub(crate) mod ipc; pub(crate) mod statvfs; diff --git a/src/new/openbsd/mod.rs b/src/new/openbsd/mod.rs index d5debb80f3928..25fa784b2b004 100644 --- a/src/new/openbsd/mod.rs +++ b/src/new/openbsd/mod.rs @@ -3,4 +3,5 @@ //! * Headers: //! * Manual pages: +pub(crate) mod sys; pub(crate) mod unistd; diff --git a/src/new/openbsd/sys/ipc.rs b/src/new/openbsd/sys/ipc.rs new file mode 100644 index 0000000000000..59774405bcdd0 --- /dev/null +++ b/src/new/openbsd/sys/ipc.rs @@ -0,0 +1,17 @@ +//! Header: `sys/ipc.h` +//! +//! + +use crate::prelude::*; + +s! { + pub struct ipc_perm { + pub cuid: crate::uid_t, + pub cgid: crate::gid_t, + pub uid: crate::uid_t, + pub gid: crate::gid_t, + pub mode: crate::mode_t, + pub seq: c_ushort, + pub key: crate::key_t, + } +} diff --git a/src/new/openbsd/sys/mod.rs b/src/new/openbsd/sys/mod.rs new file mode 100644 index 0000000000000..7ba77c537356e --- /dev/null +++ b/src/new/openbsd/sys/mod.rs @@ -0,0 +1,5 @@ +//! Directory: `sys/` +//! +//! https://github.com/openbsd/src/tree/trunk/sys/sys + +pub(crate) mod ipc; diff --git a/src/unix/bsd/netbsdlike/mod.rs b/src/unix/bsd/netbsdlike/mod.rs index 150eca5aea3f4..88ce63d52ec19 100644 --- a/src/unix/bsd/netbsdlike/mod.rs +++ b/src/unix/bsd/netbsdlike/mod.rs @@ -61,22 +61,6 @@ s! { pub l_whence: c_short, } - pub struct ipc_perm { - pub cuid: crate::uid_t, - pub cgid: crate::gid_t, - pub uid: crate::uid_t, - pub gid: crate::gid_t, - pub mode: mode_t, - #[cfg(target_os = "openbsd")] - pub seq: c_ushort, - #[cfg(target_os = "netbsd")] - pub _seq: c_ushort, - #[cfg(target_os = "openbsd")] - pub key: crate::key_t, - #[cfg(target_os = "netbsd")] - pub _key: crate::key_t, - } - pub struct ptrace_io_desc { pub piod_op: c_int, pub piod_offs: *mut c_void, From ef16a023dda4726d15e5c49b6fd830976cf6a3f1 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Tue, 28 Oct 2025 20:43:58 -0400 Subject: [PATCH 25/31] NetBSD: Introduce `utmp_.rs`, correct the definition of `lastlog` The field order was incorrect. Update this and move it to `new`, along with the rest of `utmp`. As part of this, correct an incorrectly spelled `utpname` to `utmpname`. Fixes: 42289eb64f63 "Implement utmp for NetBSD" --- libc-test/semver/netbsd.txt | 2 +- src/new/mod.rs | 1 + src/new/netbsd/mod.rs | 1 + src/new/netbsd/utmp_.rs | 32 +++++++++++++++++++++++++++ src/unix/bsd/netbsdlike/netbsd/mod.rs | 27 +++------------------- 5 files changed, 38 insertions(+), 25 deletions(-) create mode 100644 src/new/netbsd/utmp_.rs diff --git a/libc-test/semver/netbsd.txt b/libc-test/semver/netbsd.txt index 1f2a04c678632..982f610a4f3aa 100644 --- a/libc-test/semver/netbsd.txt +++ b/libc-test/semver/netbsd.txt @@ -1623,9 +1623,9 @@ updwtmpx useconds_t utimensat utmp +utmpname utmpx utmpxname -utpname utrace uucred wait4 diff --git a/src/new/mod.rs b/src/new/mod.rs index 9cb6e5b969fe1..e68f32724253a 100644 --- a/src/new/mod.rs +++ b/src/new/mod.rs @@ -185,6 +185,7 @@ cfg_if! { } else if #[cfg(target_os = "netbsd")] { pub use sys::ipc::*; pub use sys::statvfs::*; + pub use utmp_::*; } else if #[cfg(target_os = "openbsd")] { pub use sys::ipc::*; } diff --git a/src/new/netbsd/mod.rs b/src/new/netbsd/mod.rs index 73bdb8292d6ef..337f9018c848c 100644 --- a/src/new/netbsd/mod.rs +++ b/src/new/netbsd/mod.rs @@ -6,3 +6,4 @@ pub(crate) mod sys; pub(crate) mod unistd; +pub(crate) mod utmp_; diff --git a/src/new/netbsd/utmp_.rs b/src/new/netbsd/utmp_.rs new file mode 100644 index 0000000000000..6179a7924f42e --- /dev/null +++ b/src/new/netbsd/utmp_.rs @@ -0,0 +1,32 @@ +//! Header: `utmp.h` +//! +//! + +use crate::prelude::*; + +pub const UT_NAMESIZE: usize = 8; +pub const UT_LINESIZE: usize = 8; +pub const UT_HOSTSIZE: usize = 16; + +s! { + pub struct lastlog { + pub ll_time: crate::time_t, + pub ll_line: [c_char; UT_LINESIZE], + pub ll_host: [c_char; UT_HOSTSIZE], + } + + pub struct utmp { + pub ut_line: [c_char; UT_LINESIZE], + pub ut_name: [c_char; UT_NAMESIZE], + pub ut_host: [c_char; UT_HOSTSIZE], + pub ut_time: crate::time_t, + } +} + +#[link(name = "util")] +extern "C" { + pub fn utmpname(file: *const c_char) -> c_int; + pub fn setutent(); + pub fn getutent() -> *mut utmp; + pub fn endutent(); +} diff --git a/src/unix/bsd/netbsdlike/netbsd/mod.rs b/src/unix/bsd/netbsdlike/netbsd/mod.rs index 406b21a3794c9..afe3bdfb668fb 100644 --- a/src/unix/bsd/netbsdlike/netbsd/mod.rs +++ b/src/unix/bsd/netbsdlike/netbsd/mod.rs @@ -435,19 +435,6 @@ s! { _shm_internal: *mut c_void, } - pub struct utmp { - pub ut_line: [c_char; UT_LINESIZE], - pub ut_name: [c_char; UT_NAMESIZE], - pub ut_host: [c_char; UT_HOSTSIZE], - pub ut_time: crate::time_t, - } - - pub struct lastlog { - pub ll_line: [c_char; UT_LINESIZE], - pub ll_host: [c_char; UT_HOSTSIZE], - pub ll_time: crate::time_t, - } - pub struct timex { pub modes: c_uint, pub offset: c_long, @@ -1815,9 +1802,6 @@ pub const CHWFLOW: crate::tcflag_t = crate::MDMBUF | crate::CRTSCTS | crate::CDT // pub const _PATH_WTMPX: &[c_char; 14] = b"/var/log/wtmpx"; // pub const _PATH_LASTLOGX: &[c_char; 17] = b"/var/log/lastlogx"; // pub const _PATH_UTMP_UPDATE: &[c_char; 24] = b"/usr/libexec/utmp_update"; -pub const UT_NAMESIZE: usize = 8; -pub const UT_LINESIZE: usize = 8; -pub const UT_HOSTSIZE: usize = 16; pub const _UTX_USERSIZE: usize = 32; pub const _UTX_LINESIZE: usize = 32; pub const _UTX_PADSIZE: usize = 40; @@ -2498,13 +2482,8 @@ extern "C" { pub fn setutxent(); pub fn endutxent(); - pub fn getutmp(ux: *const utmpx, u: *mut utmp); - pub fn getutmpx(u: *const utmp, ux: *mut utmpx); - - pub fn utpname(file: *const c_char) -> c_int; - pub fn setutent(); - pub fn endutent(); - pub fn getutent() -> *mut utmp; + pub fn getutmp(ux: *const utmpx, u: *mut crate::utmp); + pub fn getutmpx(u: *const crate::utmp, ux: *mut utmpx); pub fn efopen(p: *const c_char, m: *const c_char) -> crate::FILE; pub fn emalloc(n: size_t) -> *mut c_void; @@ -2567,7 +2546,7 @@ extern "C" { precision: size_t, ) -> *mut c_char; #[link_name = "__login50"] - pub fn login(ut: *const utmp); + pub fn login(ut: *const crate::utmp); #[link_name = "__loginx50"] pub fn loginx(ut: *const utmpx); pub fn logout(line: *const c_char); From 5eebe27ae3ddc34580d71e28301b77e6b444050c Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Tue, 28 Oct 2025 22:17:32 -0400 Subject: [PATCH 26/31] NetBSD: Introduce `utmpx_.rs`, correct utmpx definitions Create a new module for `utmpx` and move definitions there, then correct `_UTX_PADSIZE`. We can also just use `s!`, there is no need to manually implement the traits. NetBSD defines `_UTX_PADSIZE` manually but includes this comment in their source: /* * This should be: * 40 - (sizeof(struct timeval) - sizeof(struct { long s; long u; }))) * but g++ does not like it, to retain size compatibility with v1.00, * so we do it manually. */ #ifdef _LP64 #define _UTX_PADSIZE 36 #else #define _UTX_PADSIZE 40 #endif I tried using the expression here: 40 - (size_of::() - size_of::<(c_long, c_long)>()); But this returns a value of 8 which doesn't match the expected 36. So, keep with their source and hardcode the values. Link: https://github.com/NetBSD/src/blob/6ace5fed3bd010695a1b88ca6c1f8a5af7793ffb/include/utmpx.h#L91-L101 --- src/new/mod.rs | 1 + src/new/netbsd/mod.rs | 1 + src/new/netbsd/utmpx_.rs | 82 +++++++++++++++++++++++++++ src/unix/bsd/netbsdlike/netbsd/mod.rs | 65 +-------------------- 4 files changed, 85 insertions(+), 64 deletions(-) create mode 100644 src/new/netbsd/utmpx_.rs diff --git a/src/new/mod.rs b/src/new/mod.rs index e68f32724253a..8bbcaba4f5899 100644 --- a/src/new/mod.rs +++ b/src/new/mod.rs @@ -186,6 +186,7 @@ cfg_if! { pub use sys::ipc::*; pub use sys::statvfs::*; pub use utmp_::*; + pub use utmpx_::*; } else if #[cfg(target_os = "openbsd")] { pub use sys::ipc::*; } diff --git a/src/new/netbsd/mod.rs b/src/new/netbsd/mod.rs index 337f9018c848c..070a544dae81d 100644 --- a/src/new/netbsd/mod.rs +++ b/src/new/netbsd/mod.rs @@ -7,3 +7,4 @@ pub(crate) mod sys; pub(crate) mod unistd; pub(crate) mod utmp_; +pub(crate) mod utmpx_; diff --git a/src/new/netbsd/utmpx_.rs b/src/new/netbsd/utmpx_.rs new file mode 100644 index 0000000000000..6b0762056de5f --- /dev/null +++ b/src/new/netbsd/utmpx_.rs @@ -0,0 +1,82 @@ +//! Header: `utmpx.h` +//! +//! + +use crate::prelude::*; + +// pub const _PATH_UTMPX: &[c_char; 14] = b"/var/run/utmpx"; +// pub const _PATH_WTMPX: &[c_char; 14] = b"/var/log/wtmpx"; +// pub const _PATH_LASTLOGX: &[c_char; 17] = b"/var/log/lastlogx"; +// pub const _PATH_UTMP_UPDATE: &[c_char; 24] = b"/usr/libexec/utmp_update"; + +pub const _UTX_USERSIZE: usize = 32; +pub const _UTX_LINESIZE: usize = 32; +pub const _UTX_IDSIZE: usize = 4; +pub const _UTX_HOSTSIZE: usize = 256; + +pub const EMPTY: u16 = 0; +pub const RUN_LVL: u16 = 1; +pub const BOOT_TIME: u16 = 2; +pub const OLD_TIME: u16 = 3; +pub const NEW_TIME: u16 = 4; +pub const INIT_PROCESS: u16 = 5; +pub const LOGIN_PROCESS: u16 = 6; +pub const USER_PROCESS: u16 = 7; +pub const DEAD_PROCESS: u16 = 8; +pub const ACCOUNTING: u16 = 9; +pub const SIGNATURE: u16 = 10; +pub const DOWN_TIME: u16 = 11; + +// Expression based on the comment in NetBSD source. +pub const _UTX_PADSIZE: usize = if cfg!(target_pointer_width = "64") { + 36 +} else { + 40 +}; + +s! { + pub struct utmpx { + pub ut_name: [c_char; _UTX_USERSIZE], + pub ut_id: [c_char; _UTX_IDSIZE], + pub ut_line: [c_char; _UTX_LINESIZE], + pub ut_host: [c_char; _UTX_HOSTSIZE], + pub ut_session: u16, + pub ut_type: u16, + pub ut_pid: crate::pid_t, + pub ut_exit: __exit_status, // FIXME(netbsd): when anonymous struct are supported + pub ut_ss: crate::sockaddr_storage, + pub ut_tv: crate::timeval, + ut_pad: [u8; _UTX_PADSIZE], + } + + pub struct __exit_status { + pub e_termination: u16, + pub e_exit: u16, + } + + pub struct lastlogx { + pub ll_tv: crate::timeval, + pub ll_line: [c_char; _UTX_LINESIZE], + pub ll_host: [c_char; _UTX_HOSTSIZE], + pub ll_ss: crate::sockaddr_storage, + } +} + +#[link(name = "util")] +extern "C" { + pub fn setutxent(); + pub fn endutxent(); + + pub fn getutxent() -> *mut utmpx; + pub fn getutxid(ut: *const utmpx) -> *mut utmpx; + pub fn getutxline(ut: *const utmpx) -> *mut utmpx; + pub fn pututxline(ut: *const utmpx) -> *mut utmpx; + + pub fn updwtmpx(file: *const c_char, ut: *const utmpx) -> c_int; + pub fn getlastlogx(fname: *const c_char, uid: crate::uid_t, ll: *mut lastlogx) + -> *mut lastlogx; + pub fn updlastlogx(fname: *const c_char, uid: crate::uid_t, ll: *mut lastlogx) -> c_int; + pub fn getutmp(ux: *const utmpx, u: *mut crate::utmp); + pub fn getutmpx(u: *const crate::utmp, ux: *mut utmpx); + pub fn utmpxname(file: *const c_char) -> c_int; +} diff --git a/src/unix/bsd/netbsdlike/netbsd/mod.rs b/src/unix/bsd/netbsdlike/netbsd/mod.rs index afe3bdfb668fb..4c0bab96a761b 100644 --- a/src/unix/bsd/netbsdlike/netbsd/mod.rs +++ b/src/unix/bsd/netbsdlike/netbsd/mod.rs @@ -418,11 +418,6 @@ s! { pub sdl_data: [c_char; 24], } - pub struct __exit_status { - pub e_termination: u16, - pub e_exit: u16, - } - pub struct shmid_ds { pub shm_perm: crate::ipc_perm, pub shm_segsz: size_t, @@ -779,27 +774,6 @@ s! { pub __tcpi_pad: [u32; 26], } - pub struct utmpx { - pub ut_name: [c_char; _UTX_USERSIZE], - pub ut_id: [c_char; _UTX_IDSIZE], - pub ut_line: [c_char; _UTX_LINESIZE], - pub ut_host: [c_char; _UTX_HOSTSIZE], - pub ut_session: u16, - pub ut_type: u16, - pub ut_pid: crate::pid_t, - pub ut_exit: __exit_status, // FIXME(netbsd): when anonymous struct are supported - pub ut_ss: sockaddr_storage, - pub ut_tv: crate::timeval, - pub ut_pad: [u8; _UTX_PADSIZE], - } - - pub struct lastlogx { - pub ll_tv: crate::timeval, - pub ll_line: [c_char; _UTX_LINESIZE], - pub ll_host: [c_char; _UTX_HOSTSIZE], - pub ll_ss: sockaddr_storage, - } - pub struct in_pktinfo { pub ipi_addr: crate::in_addr, pub ipi_ifindex: c_uint, @@ -1798,28 +1772,6 @@ pub const ONLRET: crate::tcflag_t = 0x40; pub const CDTRCTS: crate::tcflag_t = 0x00020000; pub const CHWFLOW: crate::tcflag_t = crate::MDMBUF | crate::CRTSCTS | crate::CDTRCTS; -// pub const _PATH_UTMPX: &[c_char; 14] = b"/var/run/utmpx"; -// pub const _PATH_WTMPX: &[c_char; 14] = b"/var/log/wtmpx"; -// pub const _PATH_LASTLOGX: &[c_char; 17] = b"/var/log/lastlogx"; -// pub const _PATH_UTMP_UPDATE: &[c_char; 24] = b"/usr/libexec/utmp_update"; -pub const _UTX_USERSIZE: usize = 32; -pub const _UTX_LINESIZE: usize = 32; -pub const _UTX_PADSIZE: usize = 40; -pub const _UTX_IDSIZE: usize = 4; -pub const _UTX_HOSTSIZE: usize = 256; -pub const EMPTY: u16 = 0; -pub const RUN_LVL: u16 = 1; -pub const BOOT_TIME: u16 = 2; -pub const OLD_TIME: u16 = 3; -pub const NEW_TIME: u16 = 4; -pub const INIT_PROCESS: u16 = 5; -pub const LOGIN_PROCESS: u16 = 6; -pub const USER_PROCESS: u16 = 7; -pub const DEAD_PROCESS: u16 = 8; -pub const ACCOUNTING: u16 = 9; -pub const SIGNATURE: u16 = 10; -pub const DOWN_TIME: u16 = 11; - pub const SOCK_CLOEXEC: c_int = 0x10000000; pub const SOCK_NONBLOCK: c_int = 0x20000000; @@ -2470,21 +2422,6 @@ extern "C" { pub fn mincore(addr: *mut c_void, len: size_t, vec: *mut c_char) -> c_int; - pub fn updwtmpx(file: *const c_char, ut: *const utmpx) -> c_int; - pub fn getlastlogx(fname: *const c_char, uid: crate::uid_t, ll: *mut lastlogx) - -> *mut lastlogx; - pub fn updlastlogx(fname: *const c_char, uid: crate::uid_t, ll: *mut lastlogx) -> c_int; - pub fn utmpxname(file: *const c_char) -> c_int; - pub fn getutxent() -> *mut utmpx; - pub fn getutxid(ut: *const utmpx) -> *mut utmpx; - pub fn getutxline(ut: *const utmpx) -> *mut utmpx; - pub fn pututxline(ut: *const utmpx) -> *mut utmpx; - pub fn setutxent(); - pub fn endutxent(); - - pub fn getutmp(ux: *const utmpx, u: *mut crate::utmp); - pub fn getutmpx(u: *const crate::utmp, ux: *mut utmpx); - pub fn efopen(p: *const c_char, m: *const c_char) -> crate::FILE; pub fn emalloc(n: size_t) -> *mut c_void; pub fn ecalloc(n: size_t, c: size_t) -> *mut c_void; @@ -2548,7 +2485,7 @@ extern "C" { #[link_name = "__login50"] pub fn login(ut: *const crate::utmp); #[link_name = "__loginx50"] - pub fn loginx(ut: *const utmpx); + pub fn loginx(ut: *const crate::utmpx); pub fn logout(line: *const c_char); pub fn logoutx(line: *const c_char, status: c_int, tpe: c_int); pub fn logwtmp(line: *const c_char, name: *const c_char, host: *const c_char); From 9dff509d8ccf8f1ccab4f53acf7069cbd5955b85 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Tue, 28 Oct 2025 20:57:44 -0400 Subject: [PATCH 27/31] NetBSD: Introduce `types.rs`, correct the definition of `lwpid_t` This is currently defined as an `unsigned int` but should be `int32_t`. Also move some related definitions `new`. Link: https://github.com/NetBSD/src/blob/6ace5fed3bd010695a1b88ca6c1f8a5af7793ffb/sys/sys/types.h#L200 --- src/new/mod.rs | 1 + src/new/netbsd/sys/mod.rs | 1 + src/new/netbsd/sys/types.rs | 16 ++++++++++++++++ src/unix/bsd/netbsdlike/mod.rs | 3 ++- src/unix/bsd/netbsdlike/netbsd/mod.rs | 9 ++------- src/unix/mod.rs | 2 +- 6 files changed, 23 insertions(+), 9 deletions(-) create mode 100644 src/new/netbsd/sys/types.rs diff --git a/src/new/mod.rs b/src/new/mod.rs index 8bbcaba4f5899..41dcdea56bdcb 100644 --- a/src/new/mod.rs +++ b/src/new/mod.rs @@ -185,6 +185,7 @@ cfg_if! { } else if #[cfg(target_os = "netbsd")] { pub use sys::ipc::*; pub use sys::statvfs::*; + pub use sys::types::*; pub use utmp_::*; pub use utmpx_::*; } else if #[cfg(target_os = "openbsd")] { diff --git a/src/new/netbsd/sys/mod.rs b/src/new/netbsd/sys/mod.rs index 7fab417362739..46031de9eb4cf 100644 --- a/src/new/netbsd/sys/mod.rs +++ b/src/new/netbsd/sys/mod.rs @@ -4,3 +4,4 @@ pub(crate) mod ipc; pub(crate) mod statvfs; +pub(crate) mod types; diff --git a/src/new/netbsd/sys/types.rs b/src/new/netbsd/sys/types.rs new file mode 100644 index 0000000000000..8dfc049426170 --- /dev/null +++ b/src/new/netbsd/sys/types.rs @@ -0,0 +1,16 @@ +//! Header: `sys/types.h` +//! +//! + +use crate::prelude::*; + +pub type dev_t = u64; + +pub type lwpid_t = i32; + +pub type mqd_t = c_int; +pub type cpuid_t = c_ulong; + +pub type clock_t = c_uint; +pub type timer_t = c_int; +pub type suseconds_t = c_int; diff --git a/src/unix/bsd/netbsdlike/mod.rs b/src/unix/bsd/netbsdlike/mod.rs index 88ce63d52ec19..ff267bffae0cc 100644 --- a/src/unix/bsd/netbsdlike/mod.rs +++ b/src/unix/bsd/netbsdlike/mod.rs @@ -702,7 +702,8 @@ extern "C" { pub fn getpriority(which: c_int, who: crate::id_t) -> c_int; pub fn setpriority(which: c_int, who: crate::id_t, prio: c_int) -> c_int; - pub fn mknodat(dirfd: c_int, pathname: *const c_char, mode: mode_t, dev: dev_t) -> c_int; + pub fn mknodat(dirfd: c_int, pathname: *const c_char, mode: mode_t, dev: crate::dev_t) + -> c_int; pub fn mkfifoat(dirfd: c_int, pathname: *const c_char, mode: mode_t) -> c_int; pub fn sem_timedwait(sem: *mut sem_t, abstime: *const crate::timespec) -> c_int; pub fn sem_getvalue(sem: *mut sem_t, sval: *mut c_int) -> c_int; diff --git a/src/unix/bsd/netbsdlike/netbsd/mod.rs b/src/unix/bsd/netbsdlike/netbsd/mod.rs index 4c0bab96a761b..17d204fc65082 100644 --- a/src/unix/bsd/netbsdlike/netbsd/mod.rs +++ b/src/unix/bsd/netbsdlike/netbsd/mod.rs @@ -1,24 +1,19 @@ use crate::prelude::*; use crate::{ cmsghdr, + cpuid_t, + lwpid_t, off_t, }; -pub type clock_t = c_uint; -pub type suseconds_t = c_int; -pub type dev_t = u64; pub type blksize_t = i32; pub type fsblkcnt_t = u64; pub type fsfilcnt_t = u64; pub type idtype_t = c_int; -pub type mqd_t = c_int; type __pthread_spin_t = __cpu_simple_lock_nv_t; -pub type lwpid_t = c_uint; pub type shmatt_t = c_uint; -pub type cpuid_t = c_ulong; pub type cpuset_t = _cpuset; pub type pthread_spin_t = c_uchar; -pub type timer_t = c_int; // elf.h diff --git a/src/unix/mod.rs b/src/unix/mod.rs index a070b697b905c..04b4cedeeac76 100644 --- a/src/unix/mod.rs +++ b/src/unix/mod.rs @@ -60,7 +60,7 @@ s! { pub struct timeval { pub tv_sec: time_t, #[cfg(not(gnu_time_bits64))] - pub tv_usec: suseconds_t, + pub tv_usec: crate::suseconds_t, // For 64 bit time on 32 bit linux glibc, suseconds_t is still // a 32 bit type. Use __suseconds64_t instead #[cfg(gnu_time_bits64)] From 60500e68faa5ae5593f8faa97526a9eb81bb3802 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Tue, 28 Oct 2025 21:44:59 -0400 Subject: [PATCH 28/31] NetBSD: Introduce `timex.rs` Move `timex.h` types to the `new/` module. --- src/new/mod.rs | 1 + src/new/netbsd/sys/mod.rs | 1 + src/new/netbsd/sys/timex.rs | 94 +++++++++++++++++++++++++++ src/unix/bsd/netbsdlike/netbsd/mod.rs | 80 ----------------------- 4 files changed, 96 insertions(+), 80 deletions(-) create mode 100644 src/new/netbsd/sys/timex.rs diff --git a/src/new/mod.rs b/src/new/mod.rs index 41dcdea56bdcb..31a224cb67bf8 100644 --- a/src/new/mod.rs +++ b/src/new/mod.rs @@ -185,6 +185,7 @@ cfg_if! { } else if #[cfg(target_os = "netbsd")] { pub use sys::ipc::*; pub use sys::statvfs::*; + pub use sys::timex::*; pub use sys::types::*; pub use utmp_::*; pub use utmpx_::*; diff --git a/src/new/netbsd/sys/mod.rs b/src/new/netbsd/sys/mod.rs index 46031de9eb4cf..395b82ebd6809 100644 --- a/src/new/netbsd/sys/mod.rs +++ b/src/new/netbsd/sys/mod.rs @@ -4,4 +4,5 @@ pub(crate) mod ipc; pub(crate) mod statvfs; +pub(crate) mod timex; pub(crate) mod types; diff --git a/src/new/netbsd/sys/timex.rs b/src/new/netbsd/sys/timex.rs new file mode 100644 index 0000000000000..d3c279726c396 --- /dev/null +++ b/src/new/netbsd/sys/timex.rs @@ -0,0 +1,94 @@ +//! Header: `sys/timex.h` +//! +//! + +use crate::prelude::*; + +pub const MAXPHASE: c_long = 500000000; +pub const MAXFREQ: c_long = 500000; +pub const MINSEC: c_int = 256; +pub const MAXSEC: c_int = 2048; +pub const NANOSECOND: c_long = 1000000000; +pub const SCALE_PPM: c_int = 65; +pub const MAXTC: c_int = 10; + +pub const MOD_OFFSET: c_uint = 0x0001; +pub const MOD_FREQUENCY: c_uint = 0x0002; +pub const MOD_MAXERROR: c_uint = 0x0004; +pub const MOD_ESTERROR: c_uint = 0x0008; +pub const MOD_STATUS: c_uint = 0x0010; +pub const MOD_TIMECONST: c_uint = 0x0020; +pub const MOD_PPSMAX: c_uint = 0x0040; +pub const MOD_TAI: c_uint = 0x0080; +pub const MOD_MICRO: c_uint = 0x1000; +pub const MOD_NANO: c_uint = 0x2000; +pub const MOD_CLKB: c_uint = 0x4000; +pub const MOD_CLKA: c_uint = 0x8000; + +pub const STA_PLL: c_int = 0x0001; +pub const STA_PPSFREQ: c_int = 0x0002; +pub const STA_PPSTIME: c_int = 0x0004; +pub const STA_FLL: c_int = 0x0008; +pub const STA_INS: c_int = 0x0010; +pub const STA_DEL: c_int = 0x0020; +pub const STA_UNSYNC: c_int = 0x0040; +pub const STA_FREQHOLD: c_int = 0x0080; +pub const STA_PPSSIGNAL: c_int = 0x0100; +pub const STA_PPSJITTER: c_int = 0x0200; +pub const STA_PPSWANDER: c_int = 0x0400; +pub const STA_PPSERROR: c_int = 0x0800; +pub const STA_CLOCKERR: c_int = 0x1000; +pub const STA_NANO: c_int = 0x2000; +pub const STA_MODE: c_int = 0x4000; +pub const STA_CLK: c_int = 0x8000; + +pub const STA_RONLY: c_int = STA_PPSSIGNAL + | STA_PPSJITTER + | STA_PPSWANDER + | STA_PPSERROR + | STA_CLOCKERR + | STA_NANO + | STA_MODE + | STA_CLK; + +pub const TIME_OK: c_int = 0; +pub const TIME_INS: c_int = 1; +pub const TIME_DEL: c_int = 2; +pub const TIME_OOP: c_int = 3; +pub const TIME_WAIT: c_int = 4; +pub const TIME_ERROR: c_int = 5; + +s! { + pub struct ntptimeval { + pub time: crate::timespec, + pub maxerror: c_long, + pub esterror: c_long, + pub tai: c_long, + pub time_state: c_int, + } + + pub struct timex { + pub modes: c_uint, + pub offset: c_long, + pub freq: c_long, + pub maxerror: c_long, + pub esterror: c_long, + pub status: c_int, + pub constant: c_long, + pub precision: c_long, + pub tolerance: c_long, + pub ppsfreq: c_long, + pub jitter: c_long, + pub shift: c_int, + pub stabil: c_long, + pub jitcnt: c_long, + pub calcnt: c_long, + pub errcnt: c_long, + pub stbcnt: c_long, + } +} + +extern "C" { + pub fn ntp_gettime(buf: *mut ntptimeval) -> c_int; + pub fn ntp_adjtime(buf: *mut timex) -> c_int; +} diff --git a/src/unix/bsd/netbsdlike/netbsd/mod.rs b/src/unix/bsd/netbsdlike/netbsd/mod.rs index 17d204fc65082..3c5fb6af8c8af 100644 --- a/src/unix/bsd/netbsdlike/netbsd/mod.rs +++ b/src/unix/bsd/netbsdlike/netbsd/mod.rs @@ -425,34 +425,6 @@ s! { _shm_internal: *mut c_void, } - pub struct timex { - pub modes: c_uint, - pub offset: c_long, - pub freq: c_long, - pub maxerror: c_long, - pub esterror: c_long, - pub status: c_int, - pub constant: c_long, - pub precision: c_long, - pub tolerance: c_long, - pub ppsfreq: c_long, - pub jitter: c_long, - pub shift: c_int, - pub stabil: c_long, - pub jitcnt: c_long, - pub calcnt: c_long, - pub errcnt: c_long, - pub stbcnt: c_long, - } - - pub struct ntptimeval { - pub time: crate::timespec, - pub maxerror: c_long, - pub esterror: c_long, - pub tai: c_long, - pub time_state: c_int, - } - // elf.h pub struct Elf32_Phdr { @@ -1367,59 +1339,9 @@ pub const fn _IOC(inout: c_ulong, group: c_ulong, num: c_ulong, len: c_ulong) -> | (num) } -// pub const CLOCK_PROCESS_CPUTIME_ID: crate::clockid_t = 2; pub const CLOCK_THREAD_CPUTIME_ID: crate::clockid_t = 4; pub const NTP_API: c_int = 4; -pub const MAXPHASE: c_long = 500000000; -pub const MAXFREQ: c_long = 500000; -pub const MINSEC: c_int = 256; -pub const MAXSEC: c_int = 2048; -pub const NANOSECOND: c_long = 1000000000; -pub const SCALE_PPM: c_int = 65; -pub const MAXTC: c_int = 10; -pub const MOD_OFFSET: c_uint = 0x0001; -pub const MOD_FREQUENCY: c_uint = 0x0002; -pub const MOD_MAXERROR: c_uint = 0x0004; -pub const MOD_ESTERROR: c_uint = 0x0008; -pub const MOD_STATUS: c_uint = 0x0010; -pub const MOD_TIMECONST: c_uint = 0x0020; -pub const MOD_PPSMAX: c_uint = 0x0040; -pub const MOD_TAI: c_uint = 0x0080; -pub const MOD_MICRO: c_uint = 0x1000; -pub const MOD_NANO: c_uint = 0x2000; -pub const MOD_CLKB: c_uint = 0x4000; -pub const MOD_CLKA: c_uint = 0x8000; -pub const STA_PLL: c_int = 0x0001; -pub const STA_PPSFREQ: c_int = 0x0002; -pub const STA_PPSTIME: c_int = 0x0004; -pub const STA_FLL: c_int = 0x0008; -pub const STA_INS: c_int = 0x0010; -pub const STA_DEL: c_int = 0x0020; -pub const STA_UNSYNC: c_int = 0x0040; -pub const STA_FREQHOLD: c_int = 0x0080; -pub const STA_PPSSIGNAL: c_int = 0x0100; -pub const STA_PPSJITTER: c_int = 0x0200; -pub const STA_PPSWANDER: c_int = 0x0400; -pub const STA_PPSERROR: c_int = 0x0800; -pub const STA_CLOCKERR: c_int = 0x1000; -pub const STA_NANO: c_int = 0x2000; -pub const STA_MODE: c_int = 0x4000; -pub const STA_CLK: c_int = 0x8000; -pub const STA_RONLY: c_int = STA_PPSSIGNAL - | STA_PPSJITTER - | STA_PPSWANDER - | STA_PPSERROR - | STA_CLOCKERR - | STA_NANO - | STA_MODE - | STA_CLK; -pub const TIME_OK: c_int = 0; -pub const TIME_INS: c_int = 1; -pub const TIME_DEL: c_int = 2; -pub const TIME_OOP: c_int = 3; -pub const TIME_WAIT: c_int = 4; -pub const TIME_ERROR: c_int = 5; pub const LITTLE_ENDIAN: c_int = 1234; pub const BIG_ENDIAN: c_int = 4321; @@ -2000,8 +1922,6 @@ safe_f! { } extern "C" { - pub fn ntp_adjtime(buf: *mut timex) -> c_int; - pub fn ntp_gettime(buf: *mut ntptimeval) -> c_int; pub fn clock_nanosleep( clk_id: crate::clockid_t, flags: c_int, From 438b06c94279e86ef7c14f05c7e646767209ba6c Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Tue, 28 Oct 2025 21:57:11 -0400 Subject: [PATCH 29/31] NetBSD: Introduce `time.rs`, fix the values of `CLOCK_*_CPUTIME_ID` Link: https://github.com/NetBSD/src/blob/6ace5fed3bd010695a1b88ca6c1f8a5af7793ffb/sys/sys/time.h#L305-L306 --- src/new/mod.rs | 1 + src/new/netbsd/sys/mod.rs | 1 + src/new/netbsd/sys/time.rs | 13 +++++++++++++ src/unix/bsd/netbsdlike/netbsd/mod.rs | 13 +++---------- 4 files changed, 18 insertions(+), 10 deletions(-) create mode 100644 src/new/netbsd/sys/time.rs diff --git a/src/new/mod.rs b/src/new/mod.rs index 31a224cb67bf8..8d8644a7dae94 100644 --- a/src/new/mod.rs +++ b/src/new/mod.rs @@ -185,6 +185,7 @@ cfg_if! { } else if #[cfg(target_os = "netbsd")] { pub use sys::ipc::*; pub use sys::statvfs::*; + pub use sys::time::*; pub use sys::timex::*; pub use sys::types::*; pub use utmp_::*; diff --git a/src/new/netbsd/sys/mod.rs b/src/new/netbsd/sys/mod.rs index 395b82ebd6809..185c1f1c2cba1 100644 --- a/src/new/netbsd/sys/mod.rs +++ b/src/new/netbsd/sys/mod.rs @@ -4,5 +4,6 @@ pub(crate) mod ipc; pub(crate) mod statvfs; +pub(crate) mod time; pub(crate) mod timex; pub(crate) mod types; diff --git a/src/new/netbsd/sys/time.rs b/src/new/netbsd/sys/time.rs new file mode 100644 index 0000000000000..5f2d39d347e69 --- /dev/null +++ b/src/new/netbsd/sys/time.rs @@ -0,0 +1,13 @@ +//! Header: `sys/time.h` +//! +//! + +s! { + pub struct itimerspec { + pub it_interval: crate::timespec, + pub it_value: crate::timespec, + } +} + +pub const CLOCK_THREAD_CPUTIME_ID: crate::clockid_t = 0x20000000; +pub const CLOCK_PROCESS_CPUTIME_ID: crate::clockid_t = 0x40000000; diff --git a/src/unix/bsd/netbsdlike/netbsd/mod.rs b/src/unix/bsd/netbsdlike/netbsd/mod.rs index 3c5fb6af8c8af..c1e8380c51093 100644 --- a/src/unix/bsd/netbsdlike/netbsd/mod.rs +++ b/src/unix/bsd/netbsdlike/netbsd/mod.rs @@ -166,11 +166,6 @@ s! { pub mq_curmsgs: c_long, } - pub struct itimerspec { - pub it_interval: crate::timespec, - pub it_value: crate::timespec, - } - pub struct sigset_t { __bits: [u32; 4], } @@ -1339,8 +1334,6 @@ pub const fn _IOC(inout: c_ulong, group: c_ulong, num: c_ulong, len: c_ulong) -> | (num) } -pub const CLOCK_PROCESS_CPUTIME_ID: crate::clockid_t = 2; -pub const CLOCK_THREAD_CPUTIME_ID: crate::clockid_t = 4; pub const NTP_API: c_int = 4; pub const LITTLE_ENDIAN: c_int = 1234; @@ -2280,12 +2273,12 @@ extern "C" { // Added in `NetBSD` 10.0 pub fn timerfd_create(clockid: crate::clockid_t, flags: c_int) -> c_int; - pub fn timerfd_gettime(fd: c_int, curr_value: *mut itimerspec) -> c_int; + pub fn timerfd_gettime(fd: c_int, curr_value: *mut crate::itimerspec) -> c_int; pub fn timerfd_settime( fd: c_int, flags: c_int, - new_value: *const itimerspec, - old_value: *mut itimerspec, + new_value: *const crate::itimerspec, + old_value: *mut crate::itimerspec, ) -> c_int; pub fn qsort_r( From c1dc9ea7449e80f18d48be10f2cd3952e7a216de Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Wed, 29 Oct 2025 00:23:36 -0500 Subject: [PATCH 30/31] NetBSD: Introduce `if_.rs`, fix the definition of `ifreq` The definition of `struct ifreq` didn't match up. Make a new module for `net/if.h` and fix it there. Note that this drops some trait implementations since the correct API involves unions. --- libc-test/build.rs | 1 + src/new/mod.rs | 1 + src/new/netbsd/mod.rs | 4 ++ src/new/netbsd/net/if_.rs | 96 +++++++++++++++++++++++++++ src/unix/bsd/netbsdlike/netbsd/mod.rs | 76 --------------------- 5 files changed, 102 insertions(+), 76 deletions(-) create mode 100644 src/new/netbsd/net/if_.rs diff --git a/libc-test/build.rs b/libc-test/build.rs index c74e4c811de8c..e8a5534299b5d 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -1398,6 +1398,7 @@ fn test_netbsd(target: &str) { // Anonymous unions ("ifconf", "ifc_ifcu") => true, + ("ifreq", "ifr_ifru") => true, ("utmpx", "ut_exit") => true, ("posix_spawn_file_actions_entry_t", "fae_data") => true, diff --git a/src/new/mod.rs b/src/new/mod.rs index 8d8644a7dae94..38a0759afb65d 100644 --- a/src/new/mod.rs +++ b/src/new/mod.rs @@ -183,6 +183,7 @@ cfg_if! { } else if #[cfg(target_vendor = "apple")] { pub use signal::*; } else if #[cfg(target_os = "netbsd")] { + pub use net::if_::*; pub use sys::ipc::*; pub use sys::statvfs::*; pub use sys::time::*; diff --git a/src/new/netbsd/mod.rs b/src/new/netbsd/mod.rs index 070a544dae81d..5db71760c4de9 100644 --- a/src/new/netbsd/mod.rs +++ b/src/new/netbsd/mod.rs @@ -4,6 +4,10 @@ //! * Sys headers: //! * Manual pages: +pub(crate) mod net { + pub(crate) mod if_; +} + pub(crate) mod sys; pub(crate) mod unistd; pub(crate) mod utmp_; diff --git a/src/new/netbsd/net/if_.rs b/src/new/netbsd/net/if_.rs new file mode 100644 index 0000000000000..7cceadfc2b3d6 --- /dev/null +++ b/src/new/netbsd/net/if_.rs @@ -0,0 +1,96 @@ +//! Header: `net/if.h` +//! +//! + +use crate::prelude::*; +use crate::IFNAMSIZ; + +s! { + pub struct if_data { + pub ifi_type: c_uchar, + pub ifi_addrlen: c_uchar, + pub ifi_hdrlen: c_uchar, + pub ifi_link_state: c_int, + pub ifi_mtu: u64, + pub ifi_metric: u64, + pub ifi_baudrate: u64, + pub ifi_ipackets: u64, + pub ifi_ierrors: u64, + pub ifi_opackets: u64, + pub ifi_oerrors: u64, + pub ifi_collisions: u64, + pub ifi_ibytes: u64, + pub ifi_obytes: u64, + pub ifi_imcasts: u64, + pub ifi_omcasts: u64, + pub ifi_iqdrops: u64, + pub ifi_noproto: u64, + pub ifi_lastchange: crate::timespec, + } +} + +pub const IFF_UP: c_int = 0x0001; // interface is up +pub const IFF_BROADCAST: c_int = 0x0002; // broadcast address valid +pub const IFF_DEBUG: c_int = 0x0004; // turn on debugging +pub const IFF_LOOPBACK: c_int = 0x0008; // is a loopback net +pub const IFF_POINTOPOINT: c_int = 0x0010; // interface is point-to-point link +pub const IFF_RUNNING: c_int = 0x0040; // resources allocated +pub const IFF_NOARP: c_int = 0x0080; // no address resolution protocol +pub const IFF_PROMISC: c_int = 0x0100; // receive all packets +pub const IFF_ALLMULTI: c_int = 0x0200; // receive all multicast packets +pub const IFF_OACTIVE: c_int = 0x0400; // transmission in progress +pub const IFF_SIMPLEX: c_int = 0x0800; // can't hear own transmissions +pub const IFF_LINK0: c_int = 0x1000; // per link layer defined bit +pub const IFF_LINK1: c_int = 0x2000; // per link layer defined bit +pub const IFF_LINK2: c_int = 0x4000; // per link layer defined bit +pub const IFF_MULTICAST: c_int = 0x8000; // supports multicast + +s! { + pub struct if_msghdr { + pub ifm_msglen: c_ushort, + pub ifm_version: c_uchar, + pub ifm_type: c_uchar, + pub ifm_addrs: c_int, + pub ifm_flags: c_int, + pub ifm_index: c_ushort, + pub ifm_data: if_data, + } +} + +s_no_extra_traits! { + pub struct ifreq { + pub ifr_name: [c_char; IFNAMSIZ], + pub ifr_ifru: __c_anonymous_ifr_ifru, + } + + pub union __c_anonymous_ifr_ifru { + pub ifru_addr: crate::sockaddr, + pub ifru_dstaddr: crate::sockaddr, + pub ifru_broadaddr: crate::sockaddr, + pub space: crate::sockaddr_storage, + pub ifru_flags: c_short, + pub ifru_addrflags: c_int, + pub ifru_metrics: c_int, + pub ifru_mtu: c_int, + pub ifru_dlt: c_int, + pub ifru_value: c_uint, + pub ifru_data: *mut c_void, + // buf and buflen are deprecated but they contribute to union size + ifru_b: __c_anonymous_ifr_ifru_ifru_b, + } + + struct __c_anonymous_ifr_ifru_ifru_b { + b_buflen: u32, + b_buf: *mut c_void, + } + + pub struct ifconf { + pub ifc_len: c_int, + pub ifc_ifcu: __c_anonymous_ifc_ifcu, + } + + pub union __c_anonymous_ifc_ifcu { + pub ifcu_buf: *mut c_void, + pub ifcu_req: *mut ifreq, + } +} diff --git a/src/unix/bsd/netbsdlike/netbsd/mod.rs b/src/unix/bsd/netbsdlike/netbsd/mod.rs index c1e8380c51093..ea5ec9880f950 100644 --- a/src/unix/bsd/netbsdlike/netbsd/mod.rs +++ b/src/unix/bsd/netbsdlike/netbsd/mod.rs @@ -341,38 +341,6 @@ s! { pub int_n_sign_posn: c_char, } - pub struct if_data { - pub ifi_type: c_uchar, - pub ifi_addrlen: c_uchar, - pub ifi_hdrlen: c_uchar, - pub ifi_link_state: c_int, - pub ifi_mtu: u64, - pub ifi_metric: u64, - pub ifi_baudrate: u64, - pub ifi_ipackets: u64, - pub ifi_ierrors: u64, - pub ifi_opackets: u64, - pub ifi_oerrors: u64, - pub ifi_collisions: u64, - pub ifi_ibytes: u64, - pub ifi_obytes: u64, - pub ifi_imcasts: u64, - pub ifi_omcasts: u64, - pub ifi_iqdrops: u64, - pub ifi_noproto: u64, - pub ifi_lastchange: crate::timespec, - } - - pub struct if_msghdr { - pub ifm_msglen: c_ushort, - pub ifm_version: c_uchar, - pub ifm_type: c_uchar, - pub ifm_addrs: c_int, - pub ifm_flags: c_int, - pub ifm_index: c_ushort, - pub ifm_data: if_data, - } - pub struct sockcred { pub sc_pid: crate::pid_t, pub sc_uid: crate::uid_t, @@ -684,15 +652,6 @@ s! { pub descr_str: [c_char; 1], } - pub struct ifreq { - pub _priv: [[c_char; 6]; 24], - } - - pub struct ifconf { - pub ifc_len: c_int, - pub ifc_ifcu: __c_anonymous_ifc_ifcu, - } - pub struct tcp_info { pub tcpi_state: u8, pub __tcpi_ca_state: u8, @@ -796,11 +755,6 @@ s_no_extra_traits! { pub open: __c_anonymous_posix_spawn_fae_open, pub dup2: __c_anonymous_posix_spawn_fae_dup2, } - - pub union __c_anonymous_ifc_ifcu { - pub ifcu_buf: *mut c_void, - pub ifcu_req: *mut ifreq, - } } cfg_if! { @@ -819,21 +773,6 @@ cfg_if! { } } } - - impl Eq for __c_anonymous_ifc_ifcu {} - impl PartialEq for __c_anonymous_ifc_ifcu { - fn eq(&self, other: &__c_anonymous_ifc_ifcu) -> bool { - unsafe { self.ifcu_buf == other.ifcu_buf || self.ifcu_req == other.ifcu_req } - } - } - impl hash::Hash for __c_anonymous_ifc_ifcu { - fn hash(&self, state: &mut H) { - unsafe { - self.ifcu_buf.hash(state); - self.ifcu_req.hash(state); - } - } - } } } @@ -999,21 +938,6 @@ pub const LOCAL_PEEREID: c_int = 0x0003; // get peer identification pub const LOCAL_CREDS: c_int = 0x0004; // pass credentials to receiver // https://github.com/NetBSD/src/blob/trunk/sys/net/if.h#L373 -pub const IFF_UP: c_int = 0x0001; // interface is up -pub const IFF_BROADCAST: c_int = 0x0002; // broadcast address valid -pub const IFF_DEBUG: c_int = 0x0004; // turn on debugging -pub const IFF_LOOPBACK: c_int = 0x0008; // is a loopback net -pub const IFF_POINTOPOINT: c_int = 0x0010; // interface is point-to-point link -pub const IFF_RUNNING: c_int = 0x0040; // resources allocated -pub const IFF_NOARP: c_int = 0x0080; // no address resolution protocol -pub const IFF_PROMISC: c_int = 0x0100; // receive all packets -pub const IFF_ALLMULTI: c_int = 0x0200; // receive all multicast packets -pub const IFF_OACTIVE: c_int = 0x0400; // transmission in progress -pub const IFF_SIMPLEX: c_int = 0x0800; // can't hear own transmissions -pub const IFF_LINK0: c_int = 0x1000; // per link layer defined bit -pub const IFF_LINK1: c_int = 0x2000; // per link layer defined bit -pub const IFF_LINK2: c_int = 0x4000; // per link layer defined bit -pub const IFF_MULTICAST: c_int = 0x8000; // supports multicast // sys/netinet/in.h // Protocols (RFC 1700) From e08f2e022d2f9cce46a24129c3fc0f148f2577a1 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Wed, 29 Oct 2025 01:44:02 -0500 Subject: [PATCH 31/31] NetBSD: Correct a number of symbol link names Relevant source: * `devname`: https://github.com/NetBSD/src/blob/908770859a5d5141adc63c7844190d01db8a18a4/include/stdlib.h#L296 * `getutent`: https://github.com/NetBSD/src/blob/908770859a5d5141adc63c7844190d01db8a18a4/include/utmp.h#L70 * `ntp_gettime`: https://github.com/NetBSD/src/blob/908770859a5d5141adc63c7844190d01db8a18a4/sys/sys/timex.h#L257 * `sched_rr_get_interval`: https://github.com/NetBSD/src/blob/908770859a5d5141adc63c7844190d01db8a18a4/include/sched.h#L50-L51 * `shmctl`: https://github.com/NetBSD/src/blob/908770859a5d5141adc63c7844190d01db8a18a4/sys/sys/shm.h#L2011 * `sig{action,suspend}`: https://github.com/NetBSD/src/blob/908770859a5d5141adc63c7844190d01db8a18a4/include/signal.h#L85-L95 * `{get,set}itimer`: https://github.com/NetBSD/src/blob/908770859a5d5141adc63c7844190d01db8a18a4/sys/sys/time.h#L331-L335 * `timer_{get,set}time`: https://github.com/NetBSD/src/blob/908770859a5d5141adc63c7844190d01db8a18a4/include/time.h#L158-L160 * `utmpx` symbols: https://github.com/NetBSD/src/blob/908770859a5d5141adc63c7844190d01db8a18a4/include/utmpx.h#L135-L150 * `wait4`: https://github.com/NetBSD/src/blob/908770859a5d5141adc63c7844190d01db8a18a4/sys/sys/wait.h#L209 Excluded are `__statvfs90`, `__fstatvfs90`, `__sigaction_siginfo`, `__getmntinfo90`, `__getvfsstat90`which are only present in 10.0+ (the symbol version seems to be N-1). Source: * https://github.com/NetBSD/src/blob/908770859a5d5141adc63c7844190d01db8a18a4/sys/sys/statvfs.h#L160-L168 There is also a deprecated aliases that used to be needed and is removed here. * `__getmntinfo13`: https://github.com/NetBSD/src/blob/62c785e59d064070166dab5d2a4492055effba89/lib/libc/compat/gen/compat___getmntinfo13.c#L49-L50 --- libc-test/build.rs | 9 +++++++++ src/new/netbsd/sys/timex.rs | 1 + src/new/netbsd/utmp_.rs | 1 + src/new/netbsd/utmpx_.rs | 10 ++++++++++ src/unix/bsd/mod.rs | 5 +++++ src/unix/bsd/netbsdlike/mod.rs | 1 + src/unix/bsd/netbsdlike/netbsd/mod.rs | 6 ++++-- src/unix/mod.rs | 1 + 8 files changed, 32 insertions(+), 2 deletions(-) diff --git a/libc-test/build.rs b/libc-test/build.rs index e8a5534299b5d..7e7d28c1d19a0 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -1375,6 +1375,15 @@ fn test_netbsd(target: &str) { } }); + cfg.skip_fn_ptrcheck(move |func| { + match func { + // New symbol version present in NetBSD10, but we keep the old versions for NetBSD9 + // compatibility. + "getmntinfo" | "statvfs" | "fstatvfs" | "getvfsstat" | "sigaction" => true, + _ => false, + } + }); + cfg.skip_struct_field_type(move |struct_, field| { // This is a weird union, don't check the type. (struct_.ident() == "ifaddrs" && field.ident() == "ifa_ifu") || diff --git a/src/new/netbsd/sys/timex.rs b/src/new/netbsd/sys/timex.rs index d3c279726c396..82844bf0e732d 100644 --- a/src/new/netbsd/sys/timex.rs +++ b/src/new/netbsd/sys/timex.rs @@ -89,6 +89,7 @@ s! { } extern "C" { + #[link_name = "__ntp_gettime50"] pub fn ntp_gettime(buf: *mut ntptimeval) -> c_int; pub fn ntp_adjtime(buf: *mut timex) -> c_int; } diff --git a/src/new/netbsd/utmp_.rs b/src/new/netbsd/utmp_.rs index 6179a7924f42e..2047449053ce8 100644 --- a/src/new/netbsd/utmp_.rs +++ b/src/new/netbsd/utmp_.rs @@ -27,6 +27,7 @@ s! { extern "C" { pub fn utmpname(file: *const c_char) -> c_int; pub fn setutent(); + #[link_name = "__getutent50"] pub fn getutent() -> *mut utmp; pub fn endutent(); } diff --git a/src/new/netbsd/utmpx_.rs b/src/new/netbsd/utmpx_.rs index 6b0762056de5f..813c8fb69712e 100644 --- a/src/new/netbsd/utmpx_.rs +++ b/src/new/netbsd/utmpx_.rs @@ -67,16 +67,26 @@ extern "C" { pub fn setutxent(); pub fn endutxent(); + #[link_name = "__getutxent50"] pub fn getutxent() -> *mut utmpx; + #[link_name = "__getutxid50"] pub fn getutxid(ut: *const utmpx) -> *mut utmpx; + #[link_name = "__getutxline50"] pub fn getutxline(ut: *const utmpx) -> *mut utmpx; + #[link_name = "__pututxline50"] pub fn pututxline(ut: *const utmpx) -> *mut utmpx; + #[link_name = "__updwtmpx50"] pub fn updwtmpx(file: *const c_char, ut: *const utmpx) -> c_int; + #[link_name = "__getlastlogx50"] pub fn getlastlogx(fname: *const c_char, uid: crate::uid_t, ll: *mut lastlogx) -> *mut lastlogx; + + #[link_name = "__updlastlogx50"] pub fn updlastlogx(fname: *const c_char, uid: crate::uid_t, ll: *mut lastlogx) -> c_int; + #[link_name = "__getutmp50"] pub fn getutmp(ux: *const utmpx, u: *mut crate::utmp); + #[link_name = "__getutmpx50"] pub fn getutmpx(u: *const crate::utmp, ux: *mut utmpx); pub fn utmpxname(file: *const c_char) -> c_int; } diff --git a/src/unix/bsd/mod.rs b/src/unix/bsd/mod.rs index 18f513719e3d1..754272a852c48 100644 --- a/src/unix/bsd/mod.rs +++ b/src/unix/bsd/mod.rs @@ -729,6 +729,7 @@ extern "C" { )] #[cfg_attr(target_os = "netbsd", link_name = "__sigaltstack14")] pub fn sigaltstack(ss: *const stack_t, oss: *mut stack_t) -> c_int; + #[cfg_attr(target_os = "netbsd", link_name = "__sigsuspend14")] pub fn sigsuspend(mask: *const crate::sigset_t) -> c_int; pub fn sem_close(sem: *mut sem_t) -> c_int; pub fn getdtablesize() -> c_int; @@ -803,6 +804,7 @@ extern "C" { all(target_os = "freebsd", any(freebsd12, freebsd11, freebsd10)), link_name = "wait4@FBSD_1.0" )] + #[cfg_attr(target_os = "netbsd", link_name = "__wait450")] pub fn wait4( pid: crate::pid_t, status: *mut c_int, @@ -813,11 +815,13 @@ extern "C" { all(target_os = "macos", target_arch = "x86"), link_name = "getitimer$UNIX2003" )] + #[cfg_attr(target_os = "netbsd", link_name = "__getitimer50")] pub fn getitimer(which: c_int, curr_value: *mut crate::itimerval) -> c_int; #[cfg_attr( all(target_os = "macos", target_arch = "x86"), link_name = "setitimer$UNIX2003" )] + #[cfg_attr(target_os = "netbsd", link_name = "__setitimer50")] pub fn setitimer( which: c_int, new_value: *const crate::itimerval, @@ -878,6 +882,7 @@ extern "C" { locale: crate::locale_t, ) -> size_t; + #[cfg_attr(target_os = "netbsd", link_name = "__devname50")] pub fn devname(dev: crate::dev_t, mode_t: crate::mode_t) -> *mut c_char; pub fn issetugid() -> c_int; diff --git a/src/unix/bsd/netbsdlike/mod.rs b/src/unix/bsd/netbsdlike/mod.rs index ff267bffae0cc..557199dc75a87 100644 --- a/src/unix/bsd/netbsdlike/mod.rs +++ b/src/unix/bsd/netbsdlike/mod.rs @@ -747,6 +747,7 @@ extern "C" { pub fn shmget(key: crate::key_t, size: size_t, shmflg: c_int) -> c_int; pub fn shmat(shmid: c_int, shmaddr: *const c_void, shmflg: c_int) -> *mut c_void; pub fn shmdt(shmaddr: *const c_void) -> c_int; + #[cfg_attr(target_os = "netbsd", link_name = "__shmctl50")] pub fn shmctl(shmid: c_int, cmd: c_int, buf: *mut crate::shmid_ds) -> c_int; pub fn execvpe( file: *const c_char, diff --git a/src/unix/bsd/netbsdlike/netbsd/mod.rs b/src/unix/bsd/netbsdlike/netbsd/mod.rs index ea5ec9880f950..7e3afa030fa64 100644 --- a/src/unix/bsd/netbsdlike/netbsd/mod.rs +++ b/src/unix/bsd/netbsdlike/netbsd/mod.rs @@ -2123,7 +2123,9 @@ extern "C" { ) -> c_int; pub fn timer_delete(timerid: crate::timer_t) -> c_int; pub fn timer_getoverrun(timerid: crate::timer_t) -> c_int; + #[link_name = "__timer_gettime50"] pub fn timer_gettime(timerid: crate::timer_t, curr_value: *mut crate::itimerspec) -> c_int; + #[link_name = "__timer_settime50"] pub fn timer_settime( timerid: crate::timer_t, flags: c_int, @@ -2149,6 +2151,7 @@ extern "C" { flags: c_int, ) -> *mut c_void; + #[link_name = "__sched_rr_get_interval50"] pub fn sched_rr_get_interval(pid: crate::pid_t, t: *mut crate::timespec) -> c_int; pub fn sched_setparam(pid: crate::pid_t, param: *const crate::sched_param) -> c_int; pub fn sched_getparam(pid: crate::pid_t, param: *mut crate::sched_param) -> c_int; @@ -2191,7 +2194,6 @@ extern "C" { ntargets: size_t, hint: *const c_void, ) -> c_int; - #[link_name = "__getmntinfo13"] pub fn getmntinfo(mntbufp: *mut *mut crate::statvfs, flags: c_int) -> c_int; pub fn getvfsstat(buf: *mut crate::statvfs, bufsize: size_t, flags: c_int) -> c_int; @@ -2238,7 +2240,7 @@ extern "C" { #[link(name = "util")] extern "C" { - #[cfg_attr(target_os = "netbsd", link_name = "__getpwent_r50")] + #[link_name = "__getpwent_r50"] pub fn getpwent_r( pwd: *mut crate::passwd, buf: *mut c_char, diff --git a/src/unix/mod.rs b/src/unix/mod.rs index 04b4cedeeac76..c3c65d0864838 100644 --- a/src/unix/mod.rs +++ b/src/unix/mod.rs @@ -1659,6 +1659,7 @@ cfg_if! { target_os = "aix", )))] { extern "C" { + #[cfg_attr(target_os = "netbsd", link_name = "__adjtime50")] #[cfg_attr(gnu_time_bits64, link_name = "__adjtime64")] pub fn adjtime(delta: *const timeval, olddelta: *mut timeval) -> c_int; }