From bdfe8759d7f2c40e4a40518d7bb5ded614ad3b65 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Sun, 17 Nov 2024 02:52:22 -0500 Subject: [PATCH 1/9] Apply small fixes to sync `main` and `libc-0.2` build and test Just check out a few hunks of these files from `main` now that we aren't limited by the old MSRV. --- build.rs | 30 ++++++++---------------------- ci/README.md | 2 +- libc-test/build.rs | 3 ++- libc-test/semver/android.txt | 3 --- 4 files changed, 11 insertions(+), 27 deletions(-) diff --git a/build.rs b/build.rs index c8ffb7bf92ad2..e1c9b23c4617f 100644 --- a/build.rs +++ b/build.rs @@ -132,7 +132,7 @@ fn rustc_version_cmd(is_clippy_driver: bool) -> Output { cmd.arg("--version"); - let output = cmd.output().ok().expect("Failed to get rustc version"); + let output = cmd.output().expect("Failed to get rustc version"); if !output.status.success() { panic!( @@ -187,20 +187,14 @@ fn rustc_minor_nightly() -> (u32, bool) { } fn which_freebsd() -> Option { - let output = std::process::Command::new("freebsd-version").output().ok(); - if output.is_none() { - return None; - } - let output = output.unwrap(); + let output = std::process::Command::new("freebsd-version") + .output() + .ok()?; if !output.status.success() { return None; } - let stdout = String::from_utf8(output.stdout).ok(); - if stdout.is_none() { - return None; - } - let stdout = stdout.unwrap(); + let stdout = String::from_utf8(output.stdout).ok()?; match &stdout { s if s.starts_with("10") => Some(10), @@ -217,24 +211,16 @@ fn emcc_version_code() -> Option { let output = std::process::Command::new("emcc") .arg("-dumpversion") .output() - .ok(); - if output.is_none() { - return None; - } - let output = output.unwrap(); + .ok()?; if !output.status.success() { return None; } - let stdout = String::from_utf8(output.stdout).ok(); - if stdout.is_none() { - return None; - } - let version = stdout.unwrap(); + let version = String::from_utf8(output.stdout).ok()?; // Some Emscripten versions come with `-git` attached, so split the // version string also on the `-` char. - let mut pieces = version.trim().split(|c| c == '.' || c == '-'); + let mut pieces = version.trim().split(['.', '-']); let major = pieces.next().and_then(|x| x.parse().ok()).unwrap_or(0); let minor = pieces.next().and_then(|x| x.parse().ok()).unwrap_or(0); diff --git a/ci/README.md b/ci/README.md index b810cd4ac59c0..d97b98acfcd08 100644 --- a/ci/README.md +++ b/ci/README.md @@ -161,7 +161,7 @@ about above), and then shut down. poweroff 1. Exit the post install shell: `exit` - 1. Back in in the installer choose Reboot + 1. Back in the installer choose Reboot 1. If all went well the machine should reboot and show a login prompt. If you switch to the serial console by choosing View > serial0 in the qemu menu, you should be logged in as root. diff --git a/libc-test/build.rs b/libc-test/build.rs index ce2f75eb312aa..8a06298741c52 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -1858,6 +1858,7 @@ fn test_android(target: &str) { // These are tested in the `linux_elf.rs` file. "Elf64_Phdr" | "Elf32_Phdr" => true, + // These are intended to be opaque "posix_spawn_file_actions_t" => true, "posix_spawnattr_t" => true, @@ -2463,7 +2464,7 @@ fn test_freebsd(target: &str) { true } - // Added in in FreeBSD 13.0 (r367776 and r367287) + // Added in FreeBSD 13.0 (r367776 and r367287) "SCM_CREDS2" | "LOCAL_CREDS_PERSISTENT" if Some(13) > freebsd_ver => true, // Added in FreeBSD 14 diff --git a/libc-test/semver/android.txt b/libc-test/semver/android.txt index b679acdcf28ed..b863ef50906b6 100644 --- a/libc-test/semver/android.txt +++ b/libc-test/semver/android.txt @@ -1,6 +1,3 @@ - - - ABS_CNT ABS_MAX ADDR_COMPAT_LAYOUT From 77de375891285e18a81616f7dceda6d52732eed6 Mon Sep 17 00:00:00 2001 From: shandongbinzhou Date: Fri, 29 Mar 2024 16:09:25 +0800 Subject: [PATCH 2/9] chore: remove repetitive words Signed-off-by: shandongbinzhou (cherry picked from commit 7735f68280809a9b7b9a12d75b77efb69c93a831) --- libc-test/semver/TODO-linux.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libc-test/semver/TODO-linux.txt b/libc-test/semver/TODO-linux.txt index 7855498efafcf..8427cf1ea12c8 100644 --- a/libc-test/semver/TODO-linux.txt +++ b/libc-test/semver/TODO-linux.txt @@ -1,4 +1,4 @@ -# The following symbols are not not available in some combinations of +# The following symbols are not available in some combinations of # musl/gnu/android and/or architecture. KEYCTL_CAPABILITIES KEYCTL_CAPS0_BIG_KEY From deaa2c1fd6a96024f1006391b43c4b1b116c9add Mon Sep 17 00:00:00 2001 From: Michael Yang Date: Wed, 5 Jun 2024 17:14:58 +1000 Subject: [PATCH 3/9] feat: add missing netfilter consts (backport ) (cherry picked from commit 70004713b855d4fe1328d4faa33bca037cd17be3) --- libc-test/build.rs | 14 +++++++++-- libc-test/semver/android.txt | 24 +++++++++++++++++++ libc-test/semver/linux.txt | 24 +++++++++++++++++++ src/unix/linux_like/android/mod.rs | 31 ++++++++++++++++++++++++- src/unix/linux_like/linux/mod.rs | 37 ++++++++++++++++++++++++++---- 5 files changed, 123 insertions(+), 7 deletions(-) diff --git a/libc-test/build.rs b/libc-test/build.rs index 8a06298741c52..ea3d8e8ceafc7 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -1789,6 +1789,8 @@ fn test_android(target: &str) { "linux/netfilter/nfnetlink_log.h", "linux/netfilter/nfnetlink_queue.h", "linux/netfilter/nf_tables.h", + "linux/netfilter_arp.h", + "linux/netfilter_bridge.h", "linux/netfilter_ipv4.h", "linux/netfilter_ipv6.h", "linux/netfilter_ipv6/ip6_tables.h", @@ -3592,6 +3594,8 @@ fn test_linux(target: &str) { "linux/netfilter/nfnetlink_log.h", "linux/netfilter/nfnetlink_queue.h", "linux/netfilter/nf_tables.h", + "linux/netfilter_arp.h", + "linux/netfilter_bridge.h", "linux/netfilter_ipv4.h", "linux/netfilter_ipv6.h", "linux/netfilter_ipv6/ip6_tables.h", @@ -4113,9 +4117,15 @@ fn test_linux(target: &str) { | "MINSIGSTKSZ" if gnu => true, - // FIXME: Linux >= 5.16 changed its value: + // FIXME: Linux >= 5.10: + // https://github.com/torvalds/linux/commit/d25e2e9388eda61b6e298585024ee3355f50c493 + "NF_INET_INGRESS" if musl => true, + + // FIXME: Linux >= 5.16: // https://github.com/torvalds/linux/commit/42df6e1d221dddc0f2acf2be37e68d553ad65f96 - "NF_NETDEV_NUMHOOKS" => true, + "NF_NETDEV_EGRESS" if musl || sparc64 => true, + // value changed + "NF_NETDEV_NUMHOOKS" if musl || sparc64 => true, // FIXME: requires Linux >= 5.6: | "RESOLVE_BENEATH" diff --git a/libc-test/semver/android.txt b/libc-test/semver/android.txt index b863ef50906b6..2c49d75c4466f 100644 --- a/libc-test/semver/android.txt +++ b/libc-test/semver/android.txt @@ -1689,8 +1689,29 @@ NFULNL_COPY_PACKET NFULNL_MSG_CONFIG NFULNL_MSG_PACKET NF_ACCEPT +NF_ARP +NF_ARP_FORWARD +NF_ARP_IN +NF_ARP_NUMHOOKS +NF_ARP_OUT +NF_BR_BROUTING +NF_BR_FORWARD +NF_BR_LOCAL_IN +NF_BR_LOCAL_OUT +NF_BR_NUMHOOKS +NF_BR_POST_ROUTING +NF_BR_PRE_ROUTING +NF_BR_PRI_BRNF +NF_BR_PRI_FILTER_BRIDGED +NF_BR_PRI_FILTER_OTHER +NF_BR_PRI_FIRST +NF_BR_PRI_LAST +NF_BR_PRI_NAT_DST_BRIDGED +NF_BR_PRI_NAT_DST_OTHER +NF_BR_PRI_NAT_SRC NF_DROP NF_INET_FORWARD +NF_INET_INGRESS NF_INET_LOCAL_IN NF_INET_LOCAL_OUT NF_INET_NUMHOOKS @@ -1712,6 +1733,7 @@ NF_IP6_PRI_MANGLE NF_IP6_PRI_NAT_DST NF_IP6_PRI_NAT_SRC NF_IP6_PRI_RAW +NF_IP6_PRI_RAW_BEFORE_DEFRAG NF_IP6_PRI_SECURITY NF_IP6_PRI_SELINUX_FIRST NF_IP6_PRI_SELINUX_LAST @@ -1732,10 +1754,12 @@ NF_IP_PRI_MANGLE NF_IP_PRI_NAT_DST NF_IP_PRI_NAT_SRC NF_IP_PRI_RAW +NF_IP_PRI_RAW_BEFORE_DEFRAG NF_IP_PRI_SECURITY NF_IP_PRI_SELINUX_FIRST NF_IP_PRI_SELINUX_LAST NF_MAX_VERDICT +NF_NETDEV_EGRESS NF_NETDEV_INGRESS NF_NETDEV_NUMHOOKS NF_QUEUE diff --git a/libc-test/semver/linux.txt b/libc-test/semver/linux.txt index 5b0fca57b3e11..fff447de3c8fc 100644 --- a/libc-test/semver/linux.txt +++ b/libc-test/semver/linux.txt @@ -1852,8 +1852,29 @@ NFULNL_COPY_PACKET NFULNL_MSG_CONFIG NFULNL_MSG_PACKET NF_ACCEPT +NF_ARP +NF_ARP_FORWARD +NF_ARP_IN +NF_ARP_NUMHOOKS +NF_ARP_OUT +NF_BR_BROUTING +NF_BR_FORWARD +NF_BR_LOCAL_IN +NF_BR_LOCAL_OUT +NF_BR_NUMHOOKS +NF_BR_POST_ROUTING +NF_BR_PRE_ROUTING +NF_BR_PRI_BRNF +NF_BR_PRI_FILTER_BRIDGED +NF_BR_PRI_FILTER_OTHER +NF_BR_PRI_FIRST +NF_BR_PRI_LAST +NF_BR_PRI_NAT_DST_BRIDGED +NF_BR_PRI_NAT_DST_OTHER +NF_BR_PRI_NAT_SRC NF_DROP NF_INET_FORWARD +NF_INET_INGRESS NF_INET_LOCAL_IN NF_INET_LOCAL_OUT NF_INET_NUMHOOKS @@ -1875,6 +1896,7 @@ NF_IP6_PRI_MANGLE NF_IP6_PRI_NAT_DST NF_IP6_PRI_NAT_SRC NF_IP6_PRI_RAW +NF_IP6_PRI_RAW_BEFORE_DEFRAG NF_IP6_PRI_SECURITY NF_IP6_PRI_SELINUX_FIRST NF_IP6_PRI_SELINUX_LAST @@ -1895,10 +1917,12 @@ NF_IP_PRI_MANGLE NF_IP_PRI_NAT_DST NF_IP_PRI_NAT_SRC NF_IP_PRI_RAW +NF_IP_PRI_RAW_BEFORE_DEFRAG NF_IP_PRI_SECURITY NF_IP_PRI_SELINUX_FIRST NF_IP_PRI_SELINUX_LAST NF_MAX_VERDICT +NF_NETDEV_EGRESS NF_QUEUE NF_REPEAT NF_STOLEN diff --git a/src/unix/linux_like/android/mod.rs b/src/unix/linux_like/android/mod.rs index 2829b249dd0b6..75f8a7877b617 100644 --- a/src/unix/linux_like/android/mod.rs +++ b/src/unix/linux_like/android/mod.rs @@ -2349,9 +2349,11 @@ pub const NF_INET_FORWARD: ::c_int = 2; pub const NF_INET_LOCAL_OUT: ::c_int = 3; pub const NF_INET_POST_ROUTING: ::c_int = 4; pub const NF_INET_NUMHOOKS: ::c_int = 5; +pub const NF_INET_INGRESS: ::c_int = NF_INET_NUMHOOKS; pub const NF_NETDEV_INGRESS: ::c_int = 0; -pub const NF_NETDEV_NUMHOOKS: ::c_int = 1; +pub const NF_NETDEV_EGRESS: ::c_int = 1; +pub const NF_NETDEV_NUMHOOKS: ::c_int = 2; pub const NFPROTO_UNSPEC: ::c_int = 0; pub const NFPROTO_INET: ::c_int = 1; @@ -2363,6 +2365,31 @@ pub const NFPROTO_IPV6: ::c_int = 10; pub const NFPROTO_DECNET: ::c_int = 12; pub const NFPROTO_NUMPROTO: ::c_int = 13; +// linux/netfilter_arp.h +pub const NF_ARP: ::c_int = 0; +pub const NF_ARP_IN: ::c_int = 0; +pub const NF_ARP_OUT: ::c_int = 1; +pub const NF_ARP_FORWARD: ::c_int = 2; +pub const NF_ARP_NUMHOOKS: ::c_int = 3; + +// linux/netfilter_bridge.h +pub const NF_BR_PRE_ROUTING: ::c_int = 0; +pub const NF_BR_LOCAL_IN: ::c_int = 1; +pub const NF_BR_FORWARD: ::c_int = 2; +pub const NF_BR_LOCAL_OUT: ::c_int = 3; +pub const NF_BR_POST_ROUTING: ::c_int = 4; +pub const NF_BR_BROUTING: ::c_int = 5; +pub const NF_BR_NUMHOOKS: ::c_int = 6; + +pub const NF_BR_PRI_FIRST: ::c_int = ::INT_MIN; +pub const NF_BR_PRI_NAT_DST_BRIDGED: ::c_int = -300; +pub const NF_BR_PRI_FILTER_BRIDGED: ::c_int = -200; +pub const NF_BR_PRI_BRNF: ::c_int = 0; +pub const NF_BR_PRI_NAT_DST_OTHER: ::c_int = 100; +pub const NF_BR_PRI_FILTER_OTHER: ::c_int = 200; +pub const NF_BR_PRI_NAT_SRC: ::c_int = 300; +pub const NF_BR_PRI_LAST: ::c_int = ::INT_MAX; + // linux/netfilter_ipv4.h pub const NF_IP_PRE_ROUTING: ::c_int = 0; pub const NF_IP_LOCAL_IN: ::c_int = 1; @@ -2372,6 +2399,7 @@ pub const NF_IP_POST_ROUTING: ::c_int = 4; pub const NF_IP_NUMHOOKS: ::c_int = 5; pub const NF_IP_PRI_FIRST: ::c_int = ::INT_MIN; +pub const NF_IP_PRI_RAW_BEFORE_DEFRAG: ::c_int = -450; pub const NF_IP_PRI_CONNTRACK_DEFRAG: ::c_int = -400; pub const NF_IP_PRI_RAW: ::c_int = -300; pub const NF_IP_PRI_SELINUX_FIRST: ::c_int = -225; @@ -2395,6 +2423,7 @@ pub const NF_IP6_POST_ROUTING: ::c_int = 4; pub const NF_IP6_NUMHOOKS: ::c_int = 5; pub const NF_IP6_PRI_FIRST: ::c_int = ::INT_MIN; +pub const NF_IP6_PRI_RAW_BEFORE_DEFRAG: ::c_int = -450; pub const NF_IP6_PRI_CONNTRACK_DEFRAG: ::c_int = -400; pub const NF_IP6_PRI_RAW: ::c_int = -300; pub const NF_IP6_PRI_SELINUX_FIRST: ::c_int = -225; diff --git a/src/unix/linux_like/linux/mod.rs b/src/unix/linux_like/linux/mod.rs index aa7213f77ee70..495db499b9a29 100644 --- a/src/unix/linux_like/linux/mod.rs +++ b/src/unix/linux_like/linux/mod.rs @@ -3336,20 +3336,47 @@ pub const NF_INET_FORWARD: ::c_int = 2; pub const NF_INET_LOCAL_OUT: ::c_int = 3; pub const NF_INET_POST_ROUTING: ::c_int = 4; pub const NF_INET_NUMHOOKS: ::c_int = 5; +pub const NF_INET_INGRESS: ::c_int = NF_INET_NUMHOOKS; + +pub const NF_NETDEV_INGRESS: ::c_int = 0; +pub const NF_NETDEV_EGRESS: ::c_int = 1; +pub const NF_NETDEV_NUMHOOKS: ::c_int = 2; // Some NFPROTO are not compatible with musl and are defined in submodules. pub const NFPROTO_UNSPEC: ::c_int = 0; +pub const NFPROTO_INET: ::c_int = 1; pub const NFPROTO_IPV4: ::c_int = 2; pub const NFPROTO_ARP: ::c_int = 3; +pub const NFPROTO_NETDEV: ::c_int = 5; pub const NFPROTO_BRIDGE: ::c_int = 7; pub const NFPROTO_IPV6: ::c_int = 10; pub const NFPROTO_DECNET: ::c_int = 12; pub const NFPROTO_NUMPROTO: ::c_int = 13; -pub const NFPROTO_INET: ::c_int = 1; -pub const NFPROTO_NETDEV: ::c_int = 5; -pub const NF_NETDEV_INGRESS: ::c_int = 0; -pub const NF_NETDEV_NUMHOOKS: ::c_int = 1; +// linux/netfilter_arp.h +pub const NF_ARP: ::c_int = 0; +pub const NF_ARP_IN: ::c_int = 0; +pub const NF_ARP_OUT: ::c_int = 1; +pub const NF_ARP_FORWARD: ::c_int = 2; +pub const NF_ARP_NUMHOOKS: ::c_int = 3; + +// linux/netfilter_bridge.h +pub const NF_BR_PRE_ROUTING: ::c_int = 0; +pub const NF_BR_LOCAL_IN: ::c_int = 1; +pub const NF_BR_FORWARD: ::c_int = 2; +pub const NF_BR_LOCAL_OUT: ::c_int = 3; +pub const NF_BR_POST_ROUTING: ::c_int = 4; +pub const NF_BR_BROUTING: ::c_int = 5; +pub const NF_BR_NUMHOOKS: ::c_int = 6; + +pub const NF_BR_PRI_FIRST: ::c_int = ::INT_MIN; +pub const NF_BR_PRI_NAT_DST_BRIDGED: ::c_int = -300; +pub const NF_BR_PRI_FILTER_BRIDGED: ::c_int = -200; +pub const NF_BR_PRI_BRNF: ::c_int = 0; +pub const NF_BR_PRI_NAT_DST_OTHER: ::c_int = 100; +pub const NF_BR_PRI_FILTER_OTHER: ::c_int = 200; +pub const NF_BR_PRI_NAT_SRC: ::c_int = 300; +pub const NF_BR_PRI_LAST: ::c_int = ::INT_MAX; // linux/netfilter_ipv4.h pub const NF_IP_PRE_ROUTING: ::c_int = 0; @@ -3360,6 +3387,7 @@ pub const NF_IP_POST_ROUTING: ::c_int = 4; pub const NF_IP_NUMHOOKS: ::c_int = 5; pub const NF_IP_PRI_FIRST: ::c_int = ::INT_MIN; +pub const NF_IP_PRI_RAW_BEFORE_DEFRAG: ::c_int = -450; pub const NF_IP_PRI_CONNTRACK_DEFRAG: ::c_int = -400; pub const NF_IP_PRI_RAW: ::c_int = -300; pub const NF_IP_PRI_SELINUX_FIRST: ::c_int = -225; @@ -3383,6 +3411,7 @@ pub const NF_IP6_POST_ROUTING: ::c_int = 4; pub const NF_IP6_NUMHOOKS: ::c_int = 5; pub const NF_IP6_PRI_FIRST: ::c_int = ::INT_MIN; +pub const NF_IP6_PRI_RAW_BEFORE_DEFRAG: ::c_int = -450; pub const NF_IP6_PRI_CONNTRACK_DEFRAG: ::c_int = -400; pub const NF_IP6_PRI_RAW: ::c_int = -300; pub const NF_IP6_PRI_SELINUX_FIRST: ::c_int = -225; From f1dd493821c8034cacd1c53a2a7683d956cba508 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Sun, 9 Jun 2024 12:56:27 +0100 Subject: [PATCH 4/9] freebsd kcmp call support. (backport ) (cherry picked from commit 68ebe1d187d0b40e7ba2012c5d36162a57528a2e) --- libc-test/build.rs | 10 ++++++++++ libc-test/semver/freebsd.txt | 6 ++++++ src/unix/bsd/freebsdlike/freebsd/mod.rs | 14 ++++++++++++++ 3 files changed, 30 insertions(+) diff --git a/libc-test/build.rs b/libc-test/build.rs index ea3d8e8ceafc7..8e8a71d2bb4e1 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -2596,6 +2596,13 @@ fn test_freebsd(target: &str) { true } + // Added in FreeBSD 14.1 + "KCMP_FILE" | "KCMP_FILEOBJ" | "KCMP_FILES" | "KCMP_SIGHAND" | "KCMP_VM" + if Some(14) > freebsd_ver => + { + true + } + // FIXME: Removed in FreeBSD 15: "LOCAL_CONNWAIT" if freebsd_ver >= Some(15) => true, @@ -2716,6 +2723,9 @@ fn test_freebsd(target: &str) { true } + // Those are introduced in FreeBSD 14.1. + "kcmp" => true, + _ => false, } }); diff --git a/libc-test/semver/freebsd.txt b/libc-test/semver/freebsd.txt index ba4902ee780a2..853e4c0043ddc 100644 --- a/libc-test/semver/freebsd.txt +++ b/libc-test/semver/freebsd.txt @@ -689,6 +689,11 @@ JAIL_SYS_DISABLE JAIL_SYS_INHERIT JAIL_SYS_NEW JAIL_UPDATE +KCMP_FILE +KCMP_FILEOBJ +KCMP_FILES +KCMP_SIGHAND +KCMP_VM KENV_DUMP KENV_DUMP_LOADER KENV_DUMP_STATIC @@ -2007,6 +2012,7 @@ jail_get jail_remove jail_set jrand48 +kcmp kevent key_t killpg diff --git a/src/unix/bsd/freebsdlike/freebsd/mod.rs b/src/unix/bsd/freebsdlike/freebsd/mod.rs index 1cb8ab4c34845..9b69ccbbb74de 100644 --- a/src/unix/bsd/freebsdlike/freebsd/mod.rs +++ b/src/unix/bsd/freebsdlike/freebsd/mod.rs @@ -4902,6 +4902,12 @@ pub const TFD_TIMER_CANCEL_ON_SET: ::c_int = 0x02; pub const CLOSE_RANGE_CLOEXEC: ::c_uint = 1 << 2; +pub const KCMP_FILE: ::c_int = 100; +pub const KCMP_FILEOBJ: ::c_int = 101; +pub const KCMP_FILES: ::c_int = 102; +pub const KCMP_SIGHAND: ::c_int = 103; +pub const KCMP_VM: ::c_int = 104; + pub const fn MAP_ALIGNED(a: ::c_int) -> ::c_int { a << 24 } @@ -5625,6 +5631,14 @@ extern "C" { argv: *const *const ::c_char, envp: *const *const ::c_char, ) -> ::c_int; + + pub fn kcmp( + pid1: ::pid_t, + pid2: ::pid_t, + type_: ::c_int, + idx1: ::c_ulong, + idx2: ::c_ulong, + ) -> ::c_int; } #[link(name = "memstat")] From ddf5f93bb1987e0851bd775ff09029fbb86a98b6 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Sun, 10 Mar 2024 23:13:33 +0000 Subject: [PATCH 5/9] adding in6_ifreq to apple. close #3611 (backport ) (cherry picked from commit 01955aef9721b2791d4a2fe917d88842a33e1a48) --- libc-test/build.rs | 2 + libc-test/semver/apple.txt | 5 ++ src/unix/bsd/apple/mod.rs | 163 +++++++++++++++++++++++++++++++++++++ 3 files changed, 170 insertions(+) diff --git a/libc-test/build.rs b/libc-test/build.rs index 8e8a71d2bb4e1..c9ecc4b0376dd 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -232,6 +232,7 @@ fn test_apple(target: &str) { "netinet/ip.h", "netinet/tcp.h", "netinet/udp.h", + "netinet6/in6_var.h", "os/clock.h", "os/lock.h", "os/signpost.h", @@ -401,6 +402,7 @@ fn test_apple(target: &str) { ("__darwin_arm_neon_state64", "__v") => true, ("ifreq", "ifr_ifru") => true, + ("in6_ifreq", "ifr_ifru") => true, ("ifkpi", "ifk_data") => true, ("ifconf", "ifc_ifcu") => true, // FIXME: this field has been incorporated into a resized `rmx_filler` array. diff --git a/libc-test/semver/apple.txt b/libc-test/semver/apple.txt index 36faea40179a5..1b278d66a15b5 100644 --- a/libc-test/semver/apple.txt +++ b/libc-test/semver/apple.txt @@ -2003,6 +2003,7 @@ globfree host_cpu_load_info host_cpu_load_info_data_t host_cpu_load_info_t +icmp6_ifstat iconv iconv_close iconv_open @@ -2018,6 +2019,9 @@ ifconf ifkpi ifreq image_offset +in6_addrlifetime +in6_ifreq +in6_ifstat in6_pktinfo in_pktinfo initgroups @@ -2338,6 +2342,7 @@ timeval32 timex truncate ttyname_r +u_quad_t ucontext_t unmount useconds_t diff --git a/src/unix/bsd/apple/mod.rs b/src/unix/bsd/apple/mod.rs index cd8a67a1b9ec2..74eb9b45d5d2e 100644 --- a/src/unix/bsd/apple/mod.rs +++ b/src/unix/bsd/apple/mod.rs @@ -37,6 +37,8 @@ pub type rusage_info_t = *mut ::c_void; pub type vm_offset_t = ::uintptr_t; pub type vm_size_t = ::uintptr_t; pub type vm_address_t = vm_offset_t; +pub type quad_t = i64; +pub type u_quad_t = u64; pub type posix_spawnattr_t = *mut ::c_void; pub type posix_spawn_file_actions_t = *mut ::c_void; @@ -1233,6 +1235,78 @@ s! { pub iffmid_id: u32, pub iffmid_str: [::c_char; 1], } + + pub struct in6_addrlifetime { + pub ia6t_expire: time_t, + pub ia6t_preferred: time_t, + pub ia6t_vltime: u32, + pub ia6t_pltime: u32, + } + + pub struct in6_ifstat { + pub ifs6_in_receive: ::u_quad_t, + pub ifs6_in_hdrerr: ::u_quad_t, + pub ifs6_in_toobig: ::u_quad_t, + pub ifs6_in_noroute: ::u_quad_t, + pub ifs6_in_addrerr: ::u_quad_t, + pub ifs6_in_protounknown: ::u_quad_t, + pub ifs6_in_truncated: ::u_quad_t, + pub ifs6_in_discard: ::u_quad_t, + pub ifs6_in_deliver: ::u_quad_t, + pub ifs6_out_forward: ::u_quad_t, + pub ifs6_out_request: ::u_quad_t, + pub ifs6_out_discard: ::u_quad_t, + pub ifs6_out_fragok: ::u_quad_t, + pub ifs6_out_fragfail: ::u_quad_t, + pub ifs6_out_fragcreat: ::u_quad_t, + pub ifs6_reass_reqd: ::u_quad_t, + pub ifs6_reass_ok: ::u_quad_t, + pub ifs6_atmfrag_rcvd: ::u_quad_t, + pub ifs6_reass_fail: ::u_quad_t, + pub ifs6_in_mcast: ::u_quad_t, + pub ifs6_out_mcast: ::u_quad_t, + pub ifs6_cantfoward_icmp6: ::u_quad_t, + pub ifs6_addr_expiry_cnt: ::u_quad_t, + pub ifs6_pfx_expiry_cnt: ::u_quad_t, + pub ifs6_defrtr_expiry_cnt: ::u_quad_t, + } + + pub struct icmp6_ifstat { + pub ifs6_in_msg: ::u_quad_t, + pub ifs6_in_error: ::u_quad_t, + pub ifs6_in_dstunreach: ::u_quad_t, + pub ifs6_in_adminprohib: ::u_quad_t, + pub ifs6_in_timeexceed: ::u_quad_t, + pub ifs6_in_paramprob: ::u_quad_t, + pub ifs6_in_pkttoobig: ::u_quad_t, + pub ifs6_in_echo: ::u_quad_t, + pub ifs6_in_echoreply: ::u_quad_t, + pub ifs6_in_routersolicit: ::u_quad_t, + pub ifs6_in_routeradvert: ::u_quad_t, + pub ifs6_in_neighborsolicit: ::u_quad_t, + pub ifs6_in_neighboradvert: ::u_quad_t, + pub ifs6_in_redirect: ::u_quad_t, + pub ifs6_in_mldquery: ::u_quad_t, + pub ifs6_in_mldreport: ::u_quad_t, + pub ifs6_in_mlddone: ::u_quad_t, + pub ifs6_out_msg: ::u_quad_t, + pub ifs6_out_error: ::u_quad_t, + pub ifs6_out_dstunreach: ::u_quad_t, + pub ifs6_out_adminprohib: ::u_quad_t, + pub ifs6_out_timeexceed: ::u_quad_t, + pub ifs6_out_paramprob: ::u_quad_t, + pub ifs6_out_pkttoobig: ::u_quad_t, + pub ifs6_out_echo: ::u_quad_t, + pub ifs6_out_echoreply: ::u_quad_t, + pub ifs6_out_routersolicit: ::u_quad_t, + pub ifs6_out_routeradvert: ::u_quad_t, + pub ifs6_out_neighborsolicit: ::u_quad_t, + pub ifs6_out_neighboradvert: ::u_quad_t, + pub ifs6_out_redirect: ::u_quad_t, + pub ifs6_out_mldquery: ::u_quad_t, + pub ifs6_out_mldreport: ::u_quad_t, + pub ifs6_out_mlddone: ::u_quad_t, + } } s_no_extra_traits! { @@ -1576,6 +1650,25 @@ s_no_extra_traits! { pub ifcu_buf: *mut ::c_char, pub ifcu_req: *mut ifreq, } + + pub union __c_anonymous_ifr_ifru6 { + pub ifru_addr: ::sockaddr_in6, + pub ifru_dstaddr: ::sockaddr_in6, + pub ifru_flags: ::c_int, + pub ifru_flags6: ::c_int, + pub ifru_metrics: ::c_int, + pub ifru_intval: ::c_int, + pub ifru_data: *mut ::c_char, + pub ifru_lifetime: in6_addrlifetime, + pub ifru_stat: in6_ifstat, + pub ifru_icmp6stat: icmp6_ifstat, + pub ifru_scope_id: [u32; SCOPE6_ID_MAX], + } + + pub struct in6_ifreq { + pub ifr_name: [::c_char; ::IFNAMSIZ], + pub ifr_ifru: __c_anonymous_ifr_ifru6, + } } impl siginfo_t { @@ -3151,6 +3244,74 @@ cfg_if! { unsafe { self.ifcu_req.hash(state) }; } } + + impl PartialEq for __c_anonymous_ifr_ifru6 { + fn eq(&self, other: &__c_anonymous_ifr_ifru6) -> bool { + unsafe { + self.ifru_addr == other.ifru_addr + && self.ifru_dstaddr == other.ifru_dstaddr + && self.ifru_flags == other.ifru_flags + && self.ifru_flags6 == other.ifru_flags6 + && self.ifru_metrics == other.ifru_metrics + && self.ifru_intval == other.ifru_intval + && self.ifru_data == other.ifru_data + && self.ifru_scope_id + .iter() + .zip(other.ifru_scope_id.iter()) + .all(|(a,b)| a == b) + } + } + } + + impl Eq for __c_anonymous_ifr_ifru6 {} + + impl ::fmt::Debug for __c_anonymous_ifr_ifru6 { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("__c_anonymous_ifr_ifru6") + .field("ifru_addr", unsafe { &self.ifru_addr }) + .field("ifru_dstaddr", unsafe { &self.ifru_dstaddr }) + .field("ifru_flags", unsafe { &self.ifru_flags }) + .field("ifru_flags6", unsafe { &self.ifru_flags6 }) + .field("ifru_metrics", unsafe { &self.ifru_metrics }) + .field("ifru_intval", unsafe { &self.ifru_intval }) + .field("ifru_data", unsafe { &self.ifru_data }) + .field("ifru_scope_id", unsafe { &self.ifru_scope_id }) + .finish() + } + } + + impl ::hash::Hash for __c_anonymous_ifr_ifru6 { + fn hash(&self, state: &mut H) { + unsafe { + self.ifru_addr.hash(state); + self.ifru_dstaddr.hash(state); + self.ifru_flags.hash(state); + self.ifru_flags6.hash(state); + self.ifru_metrics.hash(state); + self.ifru_intval.hash(state); + self.ifru_data.hash(state); + self.ifru_scope_id.hash(state); + } + } + } + + impl PartialEq for in6_ifreq { + fn eq(&self, other: &in6_ifreq) -> bool { + self.ifr_name == other.ifr_name + && self.ifr_ifru == other.ifr_ifru + } + } + + impl Eq for in6_ifreq {} + + impl ::fmt::Debug for in6_ifreq { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("in6_ifreq") + .field("ifr_name", &self.ifr_name) + .field("ifr_ifru", &self.ifr_ifru) + .finish() + } + } } } @@ -4340,6 +4501,8 @@ pub const IFF_LINK2: ::c_int = 0x4000; // per link layer defined bit pub const IFF_ALTPHYS: ::c_int = IFF_LINK2; // use alternate physical connection pub const IFF_MULTICAST: ::c_int = 0x8000; // supports multicast +pub const SCOPE6_ID_MAX: ::size_t = 16; + pub const SHUT_RD: ::c_int = 0; pub const SHUT_WR: ::c_int = 1; pub const SHUT_RDWR: ::c_int = 2; From 8e55d586e823898aa0e440b74611b2c7caf23aac Mon Sep 17 00:00:00 2001 From: David Carlier Date: Tue, 13 Feb 2024 19:52:29 +0000 Subject: [PATCH 6/9] linux elf relocation related structs addition. close #3577 (backport ) (cherry picked from commit 7763956f21d4dc663f4949583ac20eeb11d28b9f) --- libc-test/build.rs | 7 ++++ libc-test/semver/linux-aarch64.txt | 2 + libc-test/semver/linux-i686.txt | 2 + libc-test/semver/linux-powerpc64.txt | 2 + libc-test/semver/linux-riscv64gc.txt | 2 + libc-test/semver/linux-x86_64.txt | 2 + libc-test/semver/linux.txt | 13 +++++++ src/unix/linux_like/linux/mod.rs | 57 ++++++++++++++++++++++++++++ 8 files changed, 87 insertions(+) diff --git a/libc-test/build.rs b/libc-test/build.rs index c9ecc4b0376dd..7ea6a5b819381 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -3695,6 +3695,13 @@ fn test_linux(target: &str) { }); cfg.skip_type(move |ty| { + // FIXME: very recent additions to musl, not yet released. + if musl && (ty == "Elf32_Relr" || ty == "Elf64_Relr") { + return true; + } + if sparc64 && (ty == "Elf32_Rela" || ty == "Elf64_Rela") { + return true; + } match ty { // FIXME: `sighandler_t` type is incorrect, see: // https://github.com/rust-lang/libc/issues/1359 diff --git a/libc-test/semver/linux-aarch64.txt b/libc-test/semver/linux-aarch64.txt index 7e2566b6f0b1a..9dceaeccb819b 100644 --- a/libc-test/semver/linux-aarch64.txt +++ b/libc-test/semver/linux-aarch64.txt @@ -38,6 +38,8 @@ BPF_W BPF_X BPF_XOR CIBAUD +Elf32_Rela +Elf64_Rela FICLONE FICLONERANGE MADV_SOFT_OFFLINE diff --git a/libc-test/semver/linux-i686.txt b/libc-test/semver/linux-i686.txt index 73d4ca3554321..d914ca7f9285d 100644 --- a/libc-test/semver/linux-i686.txt +++ b/libc-test/semver/linux-i686.txt @@ -15,6 +15,8 @@ EFL EIP ES ESI +Elf32_Rela +Elf64_Rela FS GS KEYCTL_CAPABILITIES diff --git a/libc-test/semver/linux-powerpc64.txt b/libc-test/semver/linux-powerpc64.txt index 99be508e6bd59..77718d9ce47f0 100644 --- a/libc-test/semver/linux-powerpc64.txt +++ b/libc-test/semver/linux-powerpc64.txt @@ -2,6 +2,8 @@ B2500000 B3000000 B3500000 B4000000 +Elf32_Rela +Elf64_Rela KEYCTL_CAPABILITIES KEYCTL_CAPS0_BIG_KEY KEYCTL_CAPS0_CAPABILITIES diff --git a/libc-test/semver/linux-riscv64gc.txt b/libc-test/semver/linux-riscv64gc.txt index 28a115b234638..13f5b85196790 100644 --- a/libc-test/semver/linux-riscv64gc.txt +++ b/libc-test/semver/linux-riscv64gc.txt @@ -10,6 +10,8 @@ COMPAT_HWCAP_ISA_F COMPAT_HWCAP_ISA_I COMPAT_HWCAP_ISA_M COMPAT_HWCAP_ISA_V +Elf32_Rela +Elf64_Rela KEYCTL_CAPABILITIES KEYCTL_CAPS0_BIG_KEY KEYCTL_CAPS0_CAPABILITIES diff --git a/libc-test/semver/linux-x86_64.txt b/libc-test/semver/linux-x86_64.txt index a26f63d6d5a6c..f1ed29b8f299d 100644 --- a/libc-test/semver/linux-x86_64.txt +++ b/libc-test/semver/linux-x86_64.txt @@ -41,6 +41,8 @@ CIBAUD CS DS ES +Elf32_Rela +Elf64_Rela FS GS MADV_SOFT_OFFLINE diff --git a/libc-test/semver/linux.txt b/libc-test/semver/linux.txt index fff447de3c8fc..f549c977a60ba 100644 --- a/libc-test/semver/linux.txt +++ b/libc-test/semver/linux.txt @@ -418,6 +418,12 @@ EL2HLT EL2NSYNC EL3HLT EL3RST +ELF32_R_INFO +ELF32_R_SYM +ELF32_R_TYPE +ELF64_R_INFO +ELF64_R_SYM +ELF64_R_TYPE ELFCLASS32 ELFCLASS64 ELFCLASSNONE @@ -697,17 +703,24 @@ Elf32_Ehdr Elf32_Half Elf32_Off Elf32_Phdr +Elf32_Rel +Elf32_Relr Elf32_Section Elf32_Shdr +Elf32_Sword Elf32_Sym Elf32_Word +Elf32_Xword Elf64_Addr Elf64_Ehdr Elf64_Half Elf64_Off Elf64_Phdr +Elf64_Rel +Elf64_Relr Elf64_Section Elf64_Shdr +Elf64_Sword Elf64_Sxword Elf64_Sym Elf64_Word diff --git a/src/unix/linux_like/linux/mod.rs b/src/unix/linux_like/linux/mod.rs index 495db499b9a29..9cc2425fc6b6f 100644 --- a/src/unix/linux_like/linux/mod.rs +++ b/src/unix/linux_like/linux/mod.rs @@ -28,6 +28,8 @@ pub type Elf32_Half = u16; pub type Elf32_Word = u32; pub type Elf32_Off = u32; pub type Elf32_Addr = u32; +pub type Elf32_Xword = u64; +pub type Elf32_Sword = i32; pub type Elf64_Half = u16; pub type Elf64_Word = u32; @@ -35,10 +37,23 @@ pub type Elf64_Off = u64; pub type Elf64_Addr = u64; pub type Elf64_Xword = u64; pub type Elf64_Sxword = i64; +pub type Elf64_Sword = i32; pub type Elf32_Section = u16; pub type Elf64_Section = u16; +pub type Elf32_Relr = Elf32_Word; +pub type Elf64_Relr = Elf32_Xword; +pub type Elf32_Rel = __c_anonymous_elf32_rel; +pub type Elf64_Rel = __c_anonymous_elf64_rel; + +cfg_if! { + if #[cfg(not(target_arch = "sparc64"))] { + pub type Elf32_Rela = __c_anonymous_elf32_rela; + pub type Elf64_Rela = __c_anonymous_elf64_rela; + } +} + // linux/can.h pub type canid_t = u32; @@ -980,6 +995,24 @@ s! { } } +cfg_if! { + if #[cfg(not(target_arch = "sparc64"))] { + s!{ + pub struct __c_anonymous_elf32_rela { + pub r_offset: Elf32_Addr, + pub r_info: Elf32_Word, + pub r_addend: Elf32_Sword, + } + + pub struct __c_anonymous_elf64_rela { + pub r_offset: Elf64_Addr, + pub r_info: Elf64_Xword, + pub r_addend: Elf64_Sxword, + } + } + } +} + s_no_extra_traits! { pub struct sockaddr_nl { pub nl_family: ::sa_family_t, @@ -5353,6 +5386,30 @@ f! { pub fn BPF_JUMP(code: ::__u16, k: ::__u32, jt: ::__u8, jf: ::__u8) -> sock_filter { sock_filter{code: code, jt: jt, jf: jf, k: k} } + + pub fn ELF32_R_SYM(val: Elf32_Word) -> Elf32_Word { + val >> 8 + } + + pub fn ELF32_R_TYPE(val: Elf32_Word) -> Elf32_Word { + val & 0xff + } + + pub fn ELF32_R_INFO(sym: Elf32_Word, t: Elf32_Word) -> Elf32_Word { + sym << 8 + t & 0xff + } + + pub fn ELF64_R_SYM(val: Elf64_Xword) -> Elf64_Xword { + val >> 32 + } + + pub fn ELF64_R_TYPE(val: Elf64_Xword) -> Elf64_Xword { + val & 0xffffffff + } + + pub fn ELF64_R_INFO(sym: Elf64_Xword, t: Elf64_Xword) -> Elf64_Xword { + sym << 32 + t + } } safe_f! { From 870f096739f8e826b127ee9515422d253d91302c Mon Sep 17 00:00:00 2001 From: David Carlier Date: Fri, 21 Apr 2023 20:25:58 +0100 Subject: [PATCH 7/9] utmpx api for linux musl. close #3190 (backport ) (cherry picked from commit e3caaf6b0ea08ae294e25a861022c256a7535ec4) --- libc-test/semver/linux-musl.txt | 6 ++++++ src/unix/linux_like/linux/musl/mod.rs | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/libc-test/semver/linux-musl.txt b/libc-test/semver/linux-musl.txt index b307f90353ef0..62b188dac8288 100644 --- a/libc-test/semver/linux-musl.txt +++ b/libc-test/semver/linux-musl.txt @@ -78,11 +78,15 @@ copy_file_range ctermid dirname eaccess +endutxent euidaccess explicit_bzero futimes getauxval getloadavg +getutxent +getutxid +getutxline lio_listio ntptimeval open_wmemstream @@ -94,8 +98,10 @@ prlimit prlimit64 process_vm_readv process_vm_writev +pututxline pwritev2 pwritev64 reallocarray +setutxent tcp_info timex diff --git a/src/unix/linux_like/linux/musl/mod.rs b/src/unix/linux_like/linux/musl/mod.rs index 978423b0f2a0d..bfdbb0f0bad59 100644 --- a/src/unix/linux_like/linux/musl/mod.rs +++ b/src/unix/linux_like/linux/musl/mod.rs @@ -993,6 +993,13 @@ extern "C" { actions: *mut ::posix_spawn_file_actions_t, fd: ::c_int, ) -> ::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(); } // Alias to 64 to mimic glibc's LFS64 support From c00cc3b3acd8ae2853b23f53b6d1e6dddd5b769f Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Sun, 17 Nov 2024 04:02:02 -0500 Subject: [PATCH 8/9] Add a check that semver files don't contain duplicate entries Also make shellcheck failures actually cause an exit, `find ... -exec` apparently does not propagate errors. (backport ) (cherry picked from commit 1568789860258f9fbb41160c77e17ea6d5b711f8) --- ci/style.sh | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/ci/style.sh b/ci/style.sh index 131632ff21dd4..0684caafaad7d 100755 --- a/ci/style.sh +++ b/ci/style.sh @@ -11,7 +11,7 @@ rustfmt -V cargo fmt --all -- --check if shellcheck --version ; then - find . -name '*.sh' -exec shellcheck {} ';' + find . -name '*.sh' -print0 | xargs -0 shellcheck else echo "shellcheck not found" exit 1 @@ -29,4 +29,12 @@ for file in libc-test/semver/*.txt; do echo "Unsorted semver file $file" exit 1 fi + + duplicates=$(uniq -d "$file") + if [ -n "$duplicates" ]; then + echo "Semver file $file contains duplicates:" + echo "$duplicates" + + exit 1 + fi done From a00d7e6d1da5a656b3516eba217a208edd497320 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Tue, 2 Apr 2024 12:57:57 +0100 Subject: [PATCH 9/9] attempt to fix #3641 (backport ) (cherry picked from commit 2e94ad3524c1b0c4b33c971f11be9fca30c4e24c) --- libc-test/build.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libc-test/build.rs b/libc-test/build.rs index 7ea6a5b819381..511e166d364ce 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -3696,7 +3696,8 @@ fn test_linux(target: &str) { cfg.skip_type(move |ty| { // FIXME: very recent additions to musl, not yet released. - if musl && (ty == "Elf32_Relr" || ty == "Elf64_Relr") { + // also apparently some glibc versions + if ty == "Elf32_Relr" || ty == "Elf64_Relr" { return true; } if sparc64 && (ty == "Elf32_Rela" || ty == "Elf64_Rela") {