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 diff --git a/libc-test/build.rs b/libc-test/build.rs index 8bd7f80558b10..7e7d28c1d19a0 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,14 @@ 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, + // deprecated, obsolete upstream + "ptrace_lwpinfo" => true, + // ABI change in NetBSD10, with symbol versioning. + "statvfs" if !netbsd9 => true, _ => false, } }); @@ -1321,12 +1348,19 @@ 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 "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,13 +1368,18 @@ 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, + // FIXME(netbsd): Look into setting `_POSIX_C_SOURCE` to enable this + "qsort_r" => true, - "getrlimit" | "getrlimit64" | // non-int in 1st arg - "setrlimit" | "setrlimit64" | // non-int in 1st arg - "prlimit" | "prlimit64" | // non-int in 2nd arg + _ => false, + } + }); + 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, } }); @@ -1361,10 +1400,65 @@ 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, + ("ifreq", "ifr_ifru") => 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() { + "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, + _ => 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(); } @@ -2179,7 +2273,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 +4852,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 +5476,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) +} diff --git a/libc-test/semver/netbsd.txt b/libc-test/semver/netbsd.txt index bcd25eca15b93..982f610a4f3aa 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 @@ -104,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 @@ -180,7 +162,6 @@ CTL_HW CTL_IPPROTO_IPSEC CTL_KERN CTL_MACHDEP -CTL_MAXID CTL_MAXNAME CTL_MMAP CTL_NET @@ -417,7 +398,6 @@ IFF_LINK2 IFF_LOOPBACK IFF_MULTICAST IFF_NOARP -IFF_NOTRAILERS IFF_OACTIVE IFF_POINTOPOINT IFF_PROMISC @@ -534,7 +514,6 @@ KERN_LOGSIGEXIT KERN_LWP KERN_MAPPED_FILES KERN_MAXFILES -KERN_MAXID KERN_MAXPARTITIONS KERN_MAXPHYS KERN_MAXPROC @@ -728,13 +707,11 @@ NANOSECOND NET_RT_DUMP NET_RT_FLAGS NET_RT_IFLIST -NET_RT_MAXID NET_RT_OIFLIST NET_RT_OOIFLIST NET_RT_OOOIFLIST NEW_TIME NI_DGRAM -NI_MAXHOST NI_MAXSERV NI_NAMEREQD NI_NOFQDN @@ -845,7 +822,6 @@ POSIX_SPAWN_RETURNERROR POSIX_SPAWN_SETPGROUP POSIX_SPAWN_SETSCHEDPARAM POSIX_SPAWN_SETSCHEDULER -POSIX_SPAWN_SETSIGDEP POSIX_SPAWN_SETSIGMASK PROT_MPROTECT PTHREAD_CREATE_DETACHED @@ -908,7 +884,6 @@ REG_ECOLLATE REG_ECTYPE REG_EESCAPE REG_EMPTY -REG_ENOSYS REG_EPAREN REG_ERANGE REG_ESPACE @@ -997,7 +972,6 @@ SIGINFO SIGIO SIGNATURE SIGSTKSZ -SIOCGIFADDR SOCKCREDSIZE SOCK_CLOEXEC SOCK_CONN_DGRAM @@ -1342,7 +1316,6 @@ futimes getbootfile getbyteorder getdiskrawname -getdistcookedname getdomainname getdtablesize getentropy @@ -1422,7 +1395,6 @@ lcong48 lgetxattr lio_listio listxattr -llistxaatr localeconv_l lockf login @@ -1651,11 +1623,10 @@ updwtmpx useconds_t utimensat utmp +utmpname utmpx utmpxname -utpname utrace uucred -vm_size_t wait4 waitid 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, diff --git a/src/new/mod.rs b/src/new/mod.rs index 1846ada479fba..38a0759afb65d 100644 --- a/src/new/mod.rs +++ b/src/new/mod.rs @@ -182,6 +182,17 @@ cfg_if! { pub use net::route::*; } 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::*; + pub use sys::timex::*; + pub use sys::types::*; + 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 b43e7aeb088d2..5db71760c4de9 100644 --- a/src/new/netbsd/mod.rs +++ b/src/new/netbsd/mod.rs @@ -1,5 +1,14 @@ //! NetBSD libc. //! +//! * Headers: +//! * Sys headers: //! * Manual pages: +pub(crate) mod net { + pub(crate) mod if_; +} + +pub(crate) mod sys; pub(crate) mod unistd; +pub(crate) mod utmp_; +pub(crate) mod utmpx_; 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/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 new file mode 100644 index 0000000000000..185c1f1c2cba1 --- /dev/null +++ b/src/new/netbsd/sys/mod.rs @@ -0,0 +1,9 @@ +//! Directory: `sys/` +//! +//! https://github.com/NetBSD/src/tree/trunk/sys/sys + +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/statvfs.rs b/src/new/netbsd/sys/statvfs.rs new file mode 100644 index 0000000000000..eee3766300ce6 --- /dev/null +++ b/src/new/netbsd/sys/statvfs.rs @@ -0,0 +1,47 @@ +//! 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, + + // 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], + } +} 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/new/netbsd/sys/timex.rs b/src/new/netbsd/sys/timex.rs new file mode 100644 index 0000000000000..82844bf0e732d --- /dev/null +++ b/src/new/netbsd/sys/timex.rs @@ -0,0 +1,95 @@ +//! 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" { + #[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/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/new/netbsd/utmp_.rs b/src/new/netbsd/utmp_.rs new file mode 100644 index 0000000000000..2047449053ce8 --- /dev/null +++ b/src/new/netbsd/utmp_.rs @@ -0,0 +1,33 @@ +//! 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(); + #[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 new file mode 100644 index 0000000000000..813c8fb69712e --- /dev/null +++ b/src/new/netbsd/utmpx_.rs @@ -0,0 +1,92 @@ +//! 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(); + + #[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/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/mod.rs b/src/unix/bsd/mod.rs index 420ff3b1bab1f..754272a852c48 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; @@ -724,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; @@ -798,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, @@ -808,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, @@ -873,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 150eca5aea3f4..557199dc75a87 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, @@ -718,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; @@ -762,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 e7f0d08aca0ac..7e3afa030fa64 100644 --- a/src/unix/bsd/netbsdlike/netbsd/mod.rs +++ b/src/unix/bsd/netbsdlike/netbsd/mod.rs @@ -1,25 +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 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; pub type cpuset_t = _cpuset; pub type pthread_spin_t = c_uchar; -pub type timer_t = c_int; // elf.h @@ -49,6 +43,10 @@ c_enum! { } } +extern_ty! { + pub enum _cpuset {} +} + cfg_if! { if #[cfg(target_pointer_width = "64")] { type Elf_Addr = Elf64_Addr; @@ -168,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], } @@ -300,8 +293,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 { @@ -349,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, @@ -395,7 +355,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], } @@ -413,12 +373,7 @@ s! { pub sdl_nlen: u8, pub sdl_alen: u8, pub sdl_slen: u8, - pub sdl_data: [c_char; 12], - } - - pub struct __exit_status { - pub e_termination: u16, - pub e_exit: u16, + pub sdl_data: [c_char; 24], } pub struct shmid_ds { @@ -433,47 +388,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, - 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 { @@ -521,10 +435,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], @@ -712,6 +622,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, @@ -741,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, @@ -793,27 +695,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, @@ -852,40 +733,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, @@ -908,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! { @@ -931,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); - } - } - } } } @@ -976,7 +803,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; @@ -1112,22 +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_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 -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) @@ -1219,7 +1029,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; @@ -1406,12 +1215,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; @@ -1455,65 +1258,16 @@ 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; +#[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! { @@ -1701,7 +1455,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; @@ -1786,7 +1539,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; @@ -1854,31 +1606,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 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; -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; @@ -1893,9 +1620,10 @@ 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; +#[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; @@ -1905,7 +1633,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; @@ -2111,8 +1839,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, @@ -2397,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, @@ -2423,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; @@ -2465,18 +2194,17 @@ 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 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; - 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( @@ -2512,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, @@ -2528,26 +2256,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 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 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; @@ -2609,9 +2317,9 @@ 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 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); 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; 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 { diff --git a/src/unix/mod.rs b/src/unix/mod.rs index dbf84dc8d977f..c3c65d0864838 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)] @@ -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")] { @@ -1550,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; @@ -1653,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; }