From c980c64a1c1dec7a491a25da494ae786e3237645 Mon Sep 17 00:00:00 2001 From: LoveSy Date: Sat, 20 Jul 2024 16:56:34 +0800 Subject: [PATCH 01/25] Add missing constant for Android (backport ) [resolve conflicts - Trevor] (cherry picked from commit 93e531e09522134923981bab39757479809f8cf4) --- libc-test/semver/android-aarch64.txt | 2 ++ libc-test/semver/android-arm.txt | 1 + libc-test/semver/android-i686.txt | 4 +++ libc-test/semver/android-x86_64.txt | 2 ++ libc-test/semver/android.txt | 26 +++++++++++++++++ src/unix/linux_like/android/b32/arm.rs | 3 ++ src/unix/linux_like/android/b32/x86/mod.rs | 5 ++++ .../linux_like/android/b64/aarch64/mod.rs | 4 +++ src/unix/linux_like/android/b64/mod.rs | 26 ----------------- .../linux_like/android/b64/riscv64/mod.rs | 12 ++++++++ src/unix/linux_like/android/b64/x86_64/mod.rs | 4 +++ src/unix/linux_like/android/mod.rs | 28 +++++++++++++++++++ 12 files changed, 91 insertions(+), 26 deletions(-) diff --git a/libc-test/semver/android-aarch64.txt b/libc-test/semver/android-aarch64.txt index 8a38e32dd5022..d634779743526 100644 --- a/libc-test/semver/android-aarch64.txt +++ b/libc-test/semver/android-aarch64.txt @@ -1,3 +1,5 @@ +AT_SYSINFO_EHDR +AT_VECTOR_SIZE_ARCH HWCAP2_DCPODP HWCAP2_FLAGM2 HWCAP2_FRINT diff --git a/libc-test/semver/android-arm.txt b/libc-test/semver/android-arm.txt index fe1ce5bba1c5d..15578095c5c5f 100644 --- a/libc-test/semver/android-arm.txt +++ b/libc-test/semver/android-arm.txt @@ -1,3 +1,4 @@ +AT_SYSINFO_EHDR NGREG PTRACE_GETFPREGS PTRACE_GETREGS diff --git a/libc-test/semver/android-i686.txt b/libc-test/semver/android-i686.txt index eb6ecadba60b5..5ffb45ebc32c6 100644 --- a/libc-test/semver/android-i686.txt +++ b/libc-test/semver/android-i686.txt @@ -1,3 +1,7 @@ +AT_SYSINFO +AT_SYSINFO_EHDR +AT_VECTOR_SIZE_ARCH +SYS_memfd_secret __c_anonymous_uc_sigmask __c_anonymous_uc_sigmask_with_padding time64_t diff --git a/libc-test/semver/android-x86_64.txt b/libc-test/semver/android-x86_64.txt index c4bb87bccb66d..05919bb6f40e5 100644 --- a/libc-test/semver/android-x86_64.txt +++ b/libc-test/semver/android-x86_64.txt @@ -1,3 +1,5 @@ +AT_SYSINFO_EHDR +AT_VECTOR_SIZE_ARCH EFLAGS FS_BASE GS_BASE diff --git a/libc-test/semver/android.txt b/libc-test/semver/android.txt index 28b3286bfc339..945c53e7e0651 100644 --- a/libc-test/semver/android.txt +++ b/libc-test/semver/android.txt @@ -136,13 +136,39 @@ ATF_NETMASK ATF_PERM ATF_PUBL ATF_USETRAILERS +AT_BASE +AT_BASE_PLATFORM +AT_CLKTCK +AT_EGID AT_EMPTY_PATH +AT_ENTRY +AT_EUID +AT_EXECFD +AT_EXECFN AT_FDCWD +AT_FLAGS +AT_GID +AT_HWCAP +AT_HWCAP2 +AT_IGNORE +AT_MINSIGSTKSZ +AT_NOTELF AT_NO_AUTOMOUNT +AT_NULL +AT_PAGESZ +AT_PHDR +AT_PHENT +AT_PHNUM +AT_PLATFORM +AT_RANDOM AT_RECURSIVE AT_REMOVEDIR +AT_RSEQ_ALIGN +AT_RSEQ_FEATURE_SIZE +AT_SECURE AT_SYMLINK_FOLLOW AT_SYMLINK_NOFOLLOW +AT_UID B0 B1000000 B110 diff --git a/src/unix/linux_like/android/b32/arm.rs b/src/unix/linux_like/android/b32/arm.rs index a062175eef746..c4c78939cba48 100644 --- a/src/unix/linux_like/android/b32/arm.rs +++ b/src/unix/linux_like/android/b32/arm.rs @@ -533,6 +533,9 @@ pub const REG_R15: ::c_int = 15; pub const NGREG: ::c_int = 18; +// From NDK's asm/auxvec.h +pub const AT_SYSINFO_EHDR: ::c_ulong = 33; + f! { // Sadly, Android before 5.0 (API level 21), the accept4 syscall is not // exposed by the libc. As work-around, we implement it through `syscall` diff --git a/src/unix/linux_like/android/b32/x86/mod.rs b/src/unix/linux_like/android/b32/x86/mod.rs index e549f3b5168e6..64ce93dd22916 100644 --- a/src/unix/linux_like/android/b32/x86/mod.rs +++ b/src/unix/linux_like/android/b32/x86/mod.rs @@ -585,6 +585,11 @@ pub const REG_EFL: ::c_int = 16; pub const REG_UESP: ::c_int = 17; pub const REG_SS: ::c_int = 18; +// From NDK's asm/auxvec.h +pub const AT_SYSINFO: ::c_ulong = 32; +pub const AT_SYSINFO_EHDR: ::c_ulong = 33; +pub const AT_VECTOR_SIZE_ARCH: ::c_ulong = 3; + // socketcall values from linux/net.h (only the needed ones, and not public) const SYS_ACCEPT4: ::c_int = 18; diff --git a/src/unix/linux_like/android/b64/aarch64/mod.rs b/src/unix/linux_like/android/b64/aarch64/mod.rs index 7b87a1d49dc3e..bd3146deb7f9f 100644 --- a/src/unix/linux_like/android/b64/aarch64/mod.rs +++ b/src/unix/linux_like/android/b64/aarch64/mod.rs @@ -417,6 +417,10 @@ pub const SYS_syscalls: ::c_long = 436; pub const PROT_BTI: ::c_int = 0x10; pub const PROT_MTE: ::c_int = 0x20; +// From NDK's asm/auxvec.h +pub const AT_SYSINFO_EHDR: ::c_ulong = 33; +pub const AT_VECTOR_SIZE_ARCH: ::c_ulong = 2; + cfg_if! { if #[cfg(libc_align)] { mod align; diff --git a/src/unix/linux_like/android/b64/mod.rs b/src/unix/linux_like/android/b64/mod.rs index 9639e1b4fa589..97cf137b7fc79 100644 --- a/src/unix/linux_like/android/b64/mod.rs +++ b/src/unix/linux_like/android/b64/mod.rs @@ -264,32 +264,6 @@ pub const RTLD_GLOBAL: ::c_int = 0x00100; pub const RTLD_NOW: ::c_int = 2; pub const RTLD_DEFAULT: *mut ::c_void = 0i64 as *mut ::c_void; -// From NDK's linux/auxvec.h -pub const AT_NULL: ::c_ulong = 0; -pub const AT_IGNORE: ::c_ulong = 1; -pub const AT_EXECFD: ::c_ulong = 2; -pub const AT_PHDR: ::c_ulong = 3; -pub const AT_PHENT: ::c_ulong = 4; -pub const AT_PHNUM: ::c_ulong = 5; -pub const AT_PAGESZ: ::c_ulong = 6; -pub const AT_BASE: ::c_ulong = 7; -pub const AT_FLAGS: ::c_ulong = 8; -pub const AT_ENTRY: ::c_ulong = 9; -pub const AT_NOTELF: ::c_ulong = 10; -pub const AT_UID: ::c_ulong = 11; -pub const AT_EUID: ::c_ulong = 12; -pub const AT_GID: ::c_ulong = 13; -pub const AT_EGID: ::c_ulong = 14; -pub const AT_PLATFORM: ::c_ulong = 15; -pub const AT_HWCAP: ::c_ulong = 16; -pub const AT_CLKTCK: ::c_ulong = 17; -pub const AT_SECURE: ::c_ulong = 23; -pub const AT_BASE_PLATFORM: ::c_ulong = 24; -pub const AT_RANDOM: ::c_ulong = 25; -pub const AT_HWCAP2: ::c_ulong = 26; -pub const AT_EXECFN: ::c_ulong = 31; -pub const AT_MINSIGSTKSZ: ::c_ulong = 51; - pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t { value: 0, __reserved: [0; 36], diff --git a/src/unix/linux_like/android/b64/riscv64/mod.rs b/src/unix/linux_like/android/b64/riscv64/mod.rs index 9d414dc15fb39..209f050f25ce5 100644 --- a/src/unix/linux_like/android/b64/riscv64/mod.rs +++ b/src/unix/linux_like/android/b64/riscv64/mod.rs @@ -345,6 +345,18 @@ pub const SYS_fsmount: ::c_long = 432; pub const SYS_fspick: ::c_long = 433; pub const SYS_syscalls: ::c_long = 436; +// From NDK's asm/auxvec.h +pub const AT_SYSINFO_EHDR: ::c_ulong = 33; +pub const AT_L1I_CACHESIZE: ::c_ulong = 40; +pub const AT_L1I_CACHEGEOMETRY: ::c_ulong = 41; +pub const AT_L1D_CACHESIZE: ::c_ulong = 42; +pub const AT_L1D_CACHEGEOMETRY: ::c_ulong = 43; +pub const AT_L2_CACHESIZE: ::c_ulong = 44; +pub const AT_L2_CACHEGEOMETRY: ::c_ulong = 45; +pub const AT_L3_CACHESIZE: ::c_ulong = 46; +pub const AT_L3_CACHEGEOMETRY: ::c_ulong = 47; +pub const AT_VECTOR_SIZE_ARCH: ::c_ulong = 9; + cfg_if! { if #[cfg(libc_align)] { mod align; diff --git a/src/unix/linux_like/android/b64/x86_64/mod.rs b/src/unix/linux_like/android/b64/x86_64/mod.rs index be6b5011c21cc..a7363304c65ce 100644 --- a/src/unix/linux_like/android/b64/x86_64/mod.rs +++ b/src/unix/linux_like/android/b64/x86_64/mod.rs @@ -794,6 +794,10 @@ pub const REG_TRAPNO: ::c_int = 20; pub const REG_OLDMASK: ::c_int = 21; pub const REG_CR2: ::c_int = 22; +// From NDK's asm/auxvec.h +pub const AT_SYSINFO_EHDR: ::c_ulong = 33; +pub const AT_VECTOR_SIZE_ARCH: ::c_ulong = 3; + cfg_if! { if #[cfg(libc_align)] { mod align; diff --git a/src/unix/linux_like/android/mod.rs b/src/unix/linux_like/android/mod.rs index a9cc5943bb469..2e2d25903e539 100644 --- a/src/unix/linux_like/android/mod.rs +++ b/src/unix/linux_like/android/mod.rs @@ -3535,6 +3535,34 @@ pub const KLOG_CONSOLE_LEVEL: ::c_int = 8; pub const KLOG_SIZE_UNREAD: ::c_int = 9; pub const KLOG_SIZE_BUFFER: ::c_int = 10; +// From NDK's linux/auxvec.h +pub const AT_NULL: ::c_ulong = 0; +pub const AT_IGNORE: ::c_ulong = 1; +pub const AT_EXECFD: ::c_ulong = 2; +pub const AT_PHDR: ::c_ulong = 3; +pub const AT_PHENT: ::c_ulong = 4; +pub const AT_PHNUM: ::c_ulong = 5; +pub const AT_PAGESZ: ::c_ulong = 6; +pub const AT_BASE: ::c_ulong = 7; +pub const AT_FLAGS: ::c_ulong = 8; +pub const AT_ENTRY: ::c_ulong = 9; +pub const AT_NOTELF: ::c_ulong = 10; +pub const AT_UID: ::c_ulong = 11; +pub const AT_EUID: ::c_ulong = 12; +pub const AT_GID: ::c_ulong = 13; +pub const AT_EGID: ::c_ulong = 14; +pub const AT_PLATFORM: ::c_ulong = 15; +pub const AT_HWCAP: ::c_ulong = 16; +pub const AT_CLKTCK: ::c_ulong = 17; +pub const AT_SECURE: ::c_ulong = 23; +pub const AT_BASE_PLATFORM: ::c_ulong = 24; +pub const AT_RANDOM: ::c_ulong = 25; +pub const AT_HWCAP2: ::c_ulong = 26; +pub const AT_RSEQ_FEATURE_SIZE: ::c_ulong = 27; +pub const AT_RSEQ_ALIGN: ::c_ulong = 28; +pub const AT_EXECFN: ::c_ulong = 31; +pub const AT_MINSIGSTKSZ: ::c_ulong = 51; + // Most `*_SUPER_MAGIC` constants are defined at the `linux_like` level; the // following are only available on newer Linux versions than the versions // currently used in CI in some configurations, so we define them here. From 6be814de90eae29ef2f2c4ff8bea857d910c5ad4 Mon Sep 17 00:00:00 2001 From: LoveSy Date: Fri, 16 Aug 2024 22:21:51 +0800 Subject: [PATCH 02/25] Add android-riscv64 API check (backport ) (cherry picked from commit d22cc1952341280989a7eaf7ec103f08bab36c45) --- libc-test/semver/android-riscv64.txt | 90 ++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 libc-test/semver/android-riscv64.txt diff --git a/libc-test/semver/android-riscv64.txt b/libc-test/semver/android-riscv64.txt new file mode 100644 index 0000000000000..723278a289464 --- /dev/null +++ b/libc-test/semver/android-riscv64.txt @@ -0,0 +1,90 @@ +AT_SYSINFO_EHDR +AT_VECTOR_SIZE_ARCH +HWCAP2_AFP +HWCAP2_BF16 +HWCAP2_BTI +HWCAP2_DCPODP +HWCAP2_DGH +HWCAP2_EBF16 +HWCAP2_ECV +HWCAP2_FLAGM2 +HWCAP2_FRINT +HWCAP2_I8MM +HWCAP2_MTE +HWCAP2_MTE3 +HWCAP2_RNG +HWCAP2_RPRES +HWCAP2_SME +HWCAP2_SME_B16F32 +HWCAP2_SME_F16F32 +HWCAP2_SME_F32F32 +HWCAP2_SME_F64F64 +HWCAP2_SME_FA64 +HWCAP2_SME_I16I64 +HWCAP2_SME_I8I32 +HWCAP2_SVE2 +HWCAP2_SVEAES +HWCAP2_SVEBF16 +HWCAP2_SVEBITPERM +HWCAP2_SVEF32MM +HWCAP2_SVEF64MM +HWCAP2_SVEI8MM +HWCAP2_SVEPMULL +HWCAP2_SVESHA3 +HWCAP2_SVESM4 +HWCAP2_SVE_EBF16 +HWCAP2_WFXT +HWCAP_AES +HWCAP_ASIMD +HWCAP_ASIMDDP +HWCAP_ASIMDFHM +HWCAP_ASIMDHP +HWCAP_ASIMDRDM +HWCAP_ATOMICS +HWCAP_CPUID +HWCAP_CRC32 +HWCAP_DCPOP +HWCAP_DIT +HWCAP_EVTSTRM +HWCAP_FCMA +HWCAP_FLAGM +HWCAP_FP +HWCAP_FPHP +HWCAP_ILRCPC +HWCAP_JSCVT +HWCAP_LRCPC +HWCAP_PACA +HWCAP_PACG +HWCAP_PMULL +HWCAP_SB +HWCAP_SHA1 +HWCAP_SHA2 +HWCAP_SHA3 +HWCAP_SHA512 +HWCAP_SM3 +HWCAP_SM4 +HWCAP_SSBS +HWCAP_SVE +HWCAP_USCAT +PROT_BTI +PROT_MTE +SYS_accept +SYS_arch_specific_syscall +SYS_fcntl +SYS_getrlimit +SYS_memfd_secret +SYS_migrate_pages +SYS_msgctl +SYS_msgget +SYS_msgrcv +SYS_msgsnd +SYS_semctl +SYS_semget +SYS_semop +SYS_semtimedop +SYS_shmat +SYS_shmctl +SYS_shmdt +SYS_shmget +SYS_sync_file_range +SYS_syscalls From 1c77f80a94ddfa72b539102be95f4543d1306a19 Mon Sep 17 00:00:00 2001 From: Askar Safin Date: Sat, 11 May 2024 01:51:07 +0300 Subject: [PATCH 03/25] Add IN6ADDR_ANY_INIT, IN6ADDR_LOOPBACK_INIT, in6addr_any, in6addr_loopback (backport ) [ move constants to the align module to support old rustc - Trevor ] (cherry picked from commit 8db9bc7059af69dcde2f6c99892df11a06bfc0e8) --- libc-test/semver/unix.txt | 4 ++++ src/unix/align.rs | 8 ++++++++ src/unix/mod.rs | 5 +++++ src/unix/no_align.rs | 10 ++++++++++ 4 files changed, 27 insertions(+) diff --git a/libc-test/semver/unix.txt b/libc-test/semver/unix.txt index 03248dfec58c7..bb8e319def299 100644 --- a/libc-test/semver/unix.txt +++ b/libc-test/semver/unix.txt @@ -152,6 +152,8 @@ IF_NAMESIZE IGNBRK IGNCR IGNPAR +IN6ADDR_ANY_INIT +IN6ADDR_LOOPBACK_INIT INADDR_ANY INADDR_BROADCAST INADDR_LOOPBACK @@ -586,6 +588,8 @@ hstrerror if_indextoname if_nametoindex in6_addr +in6addr_any +in6addr_loopback in_addr in_addr_t in_port_t diff --git a/src/unix/align.rs b/src/unix/align.rs index 4fdba9a6aba69..2e7c954ccff7a 100644 --- a/src/unix/align.rs +++ b/src/unix/align.rs @@ -4,3 +4,11 @@ s! { pub s6_addr: [u8; 16], } } + +pub const IN6ADDR_LOOPBACK_INIT: in6_addr = in6_addr { + s6_addr: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], +}; + +pub const IN6ADDR_ANY_INIT: in6_addr = in6_addr { + s6_addr: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], +}; diff --git a/src/unix/mod.rs b/src/unix/mod.rs index 8b3d988ae38ae..6bab825b0449b 100644 --- a/src/unix/mod.rs +++ b/src/unix/mod.rs @@ -313,6 +313,11 @@ pub const ATF_PERM: ::c_int = 0x04; pub const ATF_PUBL: ::c_int = 0x08; pub const ATF_USETRAILERS: ::c_int = 0x10; +extern "C" { + pub static in6addr_loopback: in6_addr; + pub static in6addr_any: in6_addr; +} + cfg_if! { if #[cfg(any(target_os = "l4re", target_os = "espidf"))] { // required libraries for L4Re and the ESP-IDF framework are linked externally, ATM diff --git a/src/unix/no_align.rs b/src/unix/no_align.rs index f6b9f4c12d4ba..b435d72aa7db0 100644 --- a/src/unix/no_align.rs +++ b/src/unix/no_align.rs @@ -4,3 +4,13 @@ s! { __align: [u32; 0], } } + +pub const IN6ADDR_LOOPBACK_INIT: in6_addr = in6_addr { + s6_addr: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], + __align: [0u32; 0], +}; + +pub const IN6ADDR_ANY_INIT: in6_addr = in6_addr { + s6_addr: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + __align: [0u32; 0], +}; From 33ff229a6760cb529d479684912e7be240e9d0e1 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Fri, 26 Jul 2024 11:49:17 +0200 Subject: [PATCH 04/25] hurd: Add missing struct __timeval for 64bit support This is the same as linux_like/linux/gnu's __timeval for ut_tv for 64bit architectures. (backport ) (cherry picked from commit c8f2b3c9599affd8d571c244d6f61304a3fded0c) --- src/unix/hurd/mod.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/unix/hurd/mod.rs b/src/unix/hurd/mod.rs index 71f1ac8d98c22..ad422fe718349 100644 --- a/src/unix/hurd/mod.rs +++ b/src/unix/hurd/mod.rs @@ -450,6 +450,11 @@ s! { pub tv_nsec: __syscall_slong_t, } + pub struct __timeval { + pub tv_sec: i32, + pub tv_usec: i32, + } + pub struct __locale_data { pub _address: u8, } From 244f752c2bbff0fd7417cfc028191903bab55da3 Mon Sep 17 00:00:00 2001 From: Nathaniel Date: Fri, 16 Aug 2024 17:33:51 -0400 Subject: [PATCH 05/25] Add missing `NFT_CT_*` constants (backport ) (cherry picked from commit cd63e38273565554d6d4628e13c30851bdc9b7ad) --- libc-test/semver/android.txt | 8 ++++++++ libc-test/semver/linux-gnu.txt | 7 +++++++ src/unix/linux_like/android/mod.rs | 8 ++++++++ src/unix/linux_like/linux/mod.rs | 7 +++++++ 4 files changed, 30 insertions(+) diff --git a/libc-test/semver/android.txt b/libc-test/semver/android.txt index 945c53e7e0651..ddd651da0d6df 100644 --- a/libc-test/semver/android.txt +++ b/libc-test/semver/android.txt @@ -1503,11 +1503,16 @@ NFT_CMP_LT NFT_CMP_LTE NFT_CMP_NEQ NFT_CONTINUE +NFT_CT_AVGPKT NFT_CT_BYTES NFT_CT_DIRECTION NFT_CT_DST +NFT_CT_DST_IP +NFT_CT_DST_IP6 +NFT_CT_EVENTMASK NFT_CT_EXPIRATION NFT_CT_HELPER +NFT_CT_ID NFT_CT_L3PROTOCOL NFT_CT_LABELS NFT_CT_MARK @@ -1517,8 +1522,11 @@ NFT_CT_PROTO_DST NFT_CT_PROTO_SRC NFT_CT_SECMARK NFT_CT_SRC +NFT_CT_SRC_IP +NFT_CT_SRC_IP6 NFT_CT_STATE NFT_CT_STATUS +NFT_CT_ZONE NFT_DATA_RESERVED_MASK NFT_DATA_VALUE NFT_DATA_VALUE_MAXLEN diff --git a/libc-test/semver/linux-gnu.txt b/libc-test/semver/linux-gnu.txt index 6fa88e6c77927..60ba5f62673f7 100644 --- a/libc-test/semver/linux-gnu.txt +++ b/libc-test/semver/linux-gnu.txt @@ -191,9 +191,13 @@ NFT_CMP_LT NFT_CMP_LTE NFT_CMP_NEQ NFT_CONTINUE +NFT_CT_AVGPKT NFT_CT_BYTES NFT_CT_DIRECTION NFT_CT_DST +NFT_CT_DST_IP +NFT_CT_DST_IP6 +NFT_CT_EVENTMASK NFT_CT_EXPIRATION NFT_CT_HELPER NFT_CT_L3PROTOCOL @@ -205,8 +209,11 @@ NFT_CT_PROTO_DST NFT_CT_PROTO_SRC NFT_CT_SECMARK NFT_CT_SRC +NFT_CT_SRC_IP +NFT_CT_SRC_IP6 NFT_CT_STATE NFT_CT_STATUS +NFT_CT_ZONE NFT_DATA_RESERVED_MASK NFT_DATA_VALUE NFT_DATA_VALUE_MAXLEN diff --git a/src/unix/linux_like/android/mod.rs b/src/unix/linux_like/android/mod.rs index 2e2d25903e539..a8e935967c132 100644 --- a/src/unix/linux_like/android/mod.rs +++ b/src/unix/linux_like/android/mod.rs @@ -2572,6 +2572,14 @@ pub const NFT_CT_PROTO_DST: ::c_int = 12; pub const NFT_CT_LABELS: ::c_int = 13; pub const NFT_CT_PKTS: ::c_int = 14; pub const NFT_CT_BYTES: ::c_int = 15; +pub const NFT_CT_AVGPKT: ::c_int = 16; +pub const NFT_CT_ZONE: ::c_int = 17; +pub const NFT_CT_EVENTMASK: ::c_int = 18; +pub const NFT_CT_SRC_IP: ::c_int = 19; +pub const NFT_CT_DST_IP: ::c_int = 20; +pub const NFT_CT_SRC_IP6: ::c_int = 21; +pub const NFT_CT_DST_IP6: ::c_int = 22; +pub const NFT_CT_ID: ::c_int = 23; pub const NFT_LIMIT_PKTS: ::c_int = 0; pub const NFT_LIMIT_PKT_BYTES: ::c_int = 1; diff --git a/src/unix/linux_like/linux/mod.rs b/src/unix/linux_like/linux/mod.rs index 779faa81ff16e..5d2505a1b2f26 100644 --- a/src/unix/linux_like/linux/mod.rs +++ b/src/unix/linux_like/linux/mod.rs @@ -3980,6 +3980,13 @@ pub const NFT_CT_PROTO_DST: ::c_int = 12; pub const NFT_CT_LABELS: ::c_int = 13; pub const NFT_CT_PKTS: ::c_int = 14; pub const NFT_CT_BYTES: ::c_int = 15; +pub const NFT_CT_AVGPKT: ::c_int = 16; +pub const NFT_CT_ZONE: ::c_int = 17; +pub const NFT_CT_EVENTMASK: ::c_int = 18; +pub const NFT_CT_SRC_IP: ::c_int = 19; +pub const NFT_CT_DST_IP: ::c_int = 20; +pub const NFT_CT_SRC_IP6: ::c_int = 21; +pub const NFT_CT_DST_IP6: ::c_int = 22; pub const NFT_LIMIT_PKTS: ::c_int = 0; pub const NFT_LIMIT_PKT_BYTES: ::c_int = 1; From f90afeff6329792c2578ba174e50e876c925598e Mon Sep 17 00:00:00 2001 From: David Carlier Date: Sat, 17 Aug 2024 20:43:41 +0100 Subject: [PATCH 06/25] adding mq_notify glibc wrapper for SYS_mq_notify syscall. (backport ) (cherry picked from commit 99fb76f8e327a028f087fec55a787e8361a349e0) --- libc-test/semver/linux-gnu.txt | 1 + src/unix/linux_like/linux/gnu/mod.rs | 2 ++ 2 files changed, 3 insertions(+) diff --git a/libc-test/semver/linux-gnu.txt b/libc-test/semver/linux-gnu.txt index 60ba5f62673f7..821443c6c385d 100644 --- a/libc-test/semver/linux-gnu.txt +++ b/libc-test/semver/linux-gnu.txt @@ -657,6 +657,7 @@ malloc_info malloc_trim malloc_usable_size mallopt +mq_notify nl_mmap_hdr nl_mmap_req nl_pktinfo diff --git a/src/unix/linux_like/linux/gnu/mod.rs b/src/unix/linux_like/linux/gnu/mod.rs index d6e5eb69c7fbb..f206693d4af71 100644 --- a/src/unix/linux_like/linux/gnu/mod.rs +++ b/src/unix/linux_like/linux/gnu/mod.rs @@ -1541,6 +1541,8 @@ extern "C" { // Added in `glibc` 2.34 pub fn close_range(first: ::c_uint, last: ::c_uint, flags: ::c_int) -> ::c_int; + + pub fn mq_notify(mqdes: ::mqd_t, sevp: *const ::sigevent) -> ::c_int; } cfg_if! { From ea08dd5e5339015ef9f4151a96d914df92e32118 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Sat, 13 Jul 2024 08:46:38 +0200 Subject: [PATCH 07/25] add missing error numbers for HermitOS (backport ) (cherry picked from commit d448050fde7b5ca687615af201460eff0f77fc0d) --- src/hermit.rs | 134 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) diff --git a/src/hermit.rs b/src/hermit.rs index 145d1241b190b..77df54ae12d8d 100644 --- a/src/hermit.rs +++ b/src/hermit.rs @@ -267,6 +267,140 @@ pub const STDERR_FILENO: c_int = 2; pub const TCP_NODELAY: i32 = 1; +pub const EPERM: i32 = 1; +pub const ENOENT: i32 = 2; +pub const ESRCH: i32 = 3; +pub const EINTR: i32 = 4; +pub const EIO: i32 = 5; +pub const ENXIO: i32 = 6; +pub const E2BIG: i32 = 7; +pub const ENOEXEC: i32 = 8; +pub const EBADF: i32 = 9; +pub const ECHILD: i32 = 10; +pub const EAGAIN: i32 = 11; +pub const ENOMEM: i32 = 12; +pub const EACCES: i32 = 13; +pub const EFAULT: i32 = 14; +pub const ENOTBLK: i32 = 15; +pub const EBUSY: i32 = 16; +pub const EEXIST: i32 = 17; +pub const EXDEV: i32 = 18; +pub const ENODEV: i32 = 19; +pub const ENOTDIR: i32 = 20; +pub const EISDIR: i32 = 21; +pub const EINVAL: i32 = 22; +pub const ENFILE: i32 = 23; +pub const EMFILE: i32 = 24; +pub const ENOTTY: i32 = 25; +pub const ETXTBSY: i32 = 26; +pub const EFBIG: i32 = 27; +pub const ENOSPC: i32 = 28; +pub const ESPIPE: i32 = 29; +pub const EROFS: i32 = 30; +pub const EMLINK: i32 = 31; +pub const EPIPE: i32 = 32; +pub const EDOM: i32 = 33; +pub const ERANGE: i32 = 34; +pub const EDEADLK: i32 = 35; +pub const ENAMETOOLONG: i32 = 36; +pub const ENOLCK: i32 = 37; +pub const ENOSYS: i32 = 38; +pub const ENOTEMPTY: i32 = 39; +pub const ELOOP: i32 = 40; +pub const EWOULDBLOCK: i32 = EAGAIN; +pub const ENOMSG: i32 = 42; +pub const EIDRM: i32 = 43; +pub const ECHRNG: i32 = 44; +pub const EL2NSYNC: i32 = 45; +pub const EL3HLT: i32 = 46; +pub const EL3RST: i32 = 47; +pub const ELNRNG: i32 = 48; +pub const EUNATCH: i32 = 49; +pub const ENOCSI: i32 = 50; +pub const EL2HLT: i32 = 51; +pub const EBADE: i32 = 52; +pub const EBADR: i32 = 53; +pub const EXFULL: i32 = 54; +pub const ENOANO: i32 = 55; +pub const EBADRQC: i32 = 56; +pub const EBADSLT: i32 = 57; +pub const EDEADLOCK: i32 = EDEADLK; +pub const EBFONT: i32 = 59; +pub const ENOSTR: i32 = 60; +pub const ENODATA: i32 = 61; +pub const ETIME: i32 = 62; +pub const ENOSR: i32 = 63; +pub const ENONET: i32 = 64; +pub const ENOPKG: i32 = 65; +pub const EREMOTE: i32 = 66; +pub const ENOLINK: i32 = 67; +pub const EADV: i32 = 68; +pub const ESRMNT: i32 = 69; +pub const ECOMM: i32 = 70; +pub const EPROTO: i32 = 71; +pub const EMULTIHOP: i32 = 72; +pub const EDOTDOT: i32 = 73; +pub const EBADMSG: i32 = 74; +pub const EOVERFLOW: i32 = 75; +pub const ENOTUNIQ: i32 = 76; +pub const EBADFD: i32 = 77; +pub const EREMCHG: i32 = 78; +pub const ELIBACC: i32 = 79; +pub const ELIBBAD: i32 = 80; +pub const ELIBSCN: i32 = 81; +pub const ELIBMAX: i32 = 82; +pub const ELIBEXEC: i32 = 83; +pub const EILSEQ: i32 = 84; +pub const ERESTART: i32 = 85; +pub const ESTRPIPE: i32 = 86; +pub const EUSERS: i32 = 87; +pub const ENOTSOCK: i32 = 88; +pub const EDESTADDRREQ: i32 = 89; +pub const EMSGSIZE: i32 = 90; +pub const EPROTOTYPE: i32 = 91; +pub const ENOPROTOOPT: i32 = 92; +pub const EPROTONOSUPPORT: i32 = 93; +pub const ESOCKTNOSUPPORT: i32 = 94; +pub const EOPNOTSUPP: i32 = 95; +pub const EPFNOSUPPORT: i32 = 96; +pub const EAFNOSUPPORT: i32 = 97; +pub const EADDRINUSE: i32 = 98; +pub const EADDRNOTAVAIL: i32 = 99; +pub const ENETDOWN: i32 = 100; +pub const ENETUNREACH: i32 = 101; +pub const ENETRESET: i32 = 102; +pub const ECONNABORTED: i32 = 103; +pub const ECONNRESET: i32 = 104; +pub const ENOBUFS: i32 = 105; +pub const EISCONN: i32 = 106; +pub const ENOTCONN: i32 = 107; +pub const ESHUTDOWN: i32 = 108; +pub const ETOOMANYREFS: i32 = 109; +pub const ETIMEDOUT: i32 = 110; +pub const ECONNREFUSED: i32 = 111; +pub const EHOSTDOWN: i32 = 112; +pub const EHOSTUNREACH: i32 = 113; +pub const EALREADY: i32 = 114; +pub const EINPROGRESS: i32 = 115; +pub const ESTALE: i32 = 116; +pub const EUCLEAN: i32 = 117; +pub const ENOTNAM: i32 = 118; +pub const ENAVAIL: i32 = 119; +pub const EISNAM: i32 = 120; +pub const EREMOTEIO: i32 = 121; +pub const EDQUOT: i32 = 122; +pub const ENOMEDIUM: i32 = 123; +pub const EMEDIUMTYPE: i32 = 124; +pub const ECANCELED: i32 = 125; +pub const ENOKEY: i32 = 126; +pub const EKEYEXPIRED: i32 = 127; +pub const EKEYREVOKED: i32 = 128; +pub const EKEYREJECTED: i32 = 129; +pub const EOWNERDEAD: i32 = 130; +pub const ENOTRECOVERABLE: i32 = 131; +pub const ERFKILL: i32 = 132; +pub const EHWPOISON: i32 = 133; + extern "C" { #[link_name = "sys_alloc"] pub fn alloc(size: usize, align: usize) -> *mut u8; From d5403b0bfe762cfd3e9fe2750dc263b55e1f5ee1 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Tue, 20 Aug 2024 22:45:58 +0200 Subject: [PATCH 08/25] add missing symbols for HermitOS (backport ) (cherry picked from commit 982e041afb82254785fd2c3cca57792d5b47d97e) --- libc-test/semver/hermit.txt | 302 ++++++++++++++++++++++++++++++++++++ 1 file changed, 302 insertions(+) create mode 100644 libc-test/semver/hermit.txt diff --git a/libc-test/semver/hermit.txt b/libc-test/semver/hermit.txt new file mode 100644 index 0000000000000..ef3f1894fbb89 --- /dev/null +++ b/libc-test/semver/hermit.txt @@ -0,0 +1,302 @@ +AF_INET +AF_INET6 +CLOCK_REALTIME +CLOCK_MONOTONIC +DT_UNKNOWN +DT_FIFO +DT_CHR +DT_DIR +DT_BLK +DT_REG +DT_LNK +DT_SOCK +DT_WHT +EAI_AGAIN +EAI_BADFLAGS +EAI_FAIL +EAI_FAMILY +EAI_MEMORY +EAI_NODATA +EAI_NONAME +EAI_SERVICE +EAI_SOCKTYPE +EAI_SYSTEM +EAI_OVERFLOW +EFD_SEMAPHORE +EFD_NONBLOCK +EFD_CLOEXEC +F_DUPFD +F_GETFD +F_SETFD +F_GETFL +F_SETFL +FD_CLOEXEC +FIONBIO +FUTEX_RELATIVE_TIMEOUT +IP_TOS +IP_TTL +IP_ADD_MEMBERSHIP +IP_DROP_MEMBERSHIP +IP_MULTICAST_TTL +IP_MULTICAST_LOOP +IPPROTO_IP +IPPROTO_TCP +IPPROTO_UDP +IPPROTO_IPV6 +IPV6_ADD_MEMBERSHIP +IPV6_DROP_MEMBERSHIP +IPV6_MULTICAST_LOOP +IPV6_V6ONLY +MSG_PEEK +O_RDONLY +O_WRONLY +O_RDWR +O_CREAT +O_EXCL +O_TRUNC +O_APPEND +O_NONBLOCK +O_DIRECTORY +POLLIN +POLLPRI +POLLOUT +POLLERR +POLLHUP +POLLNVAL +POLLRDNORM +POLLRDBAND +POLLWRNORM +POLLWRBAND +POLLRDHUP +S_IRWXU +S_IRUSR +S_IWUSR +S_IXUSR +S_IRWXG +S_IRGRP +S_IWGRP +S_IXGRP +S_IRWXO +S_IROTH +S_IWOTH +S_IXOTH +S_IFMT +S_IFSOCK +S_IFLNK +S_IFREG +S_IFBLK +S_IFDIR +S_IFCHR +S_IFIFO +SHUT_RD +SHUT_WR +SHUT_RDWR +SO_REUSEADDR +SO_KEEPALIVE +SO_BROADCAST +SO_LINGER +SO_SNDBUF +SO_RCVBUF +SO_SNDTIMEO +SO_RCVTIMEO +SO_ERROR +SOCK_STREAM +SOCK_DGRAM +SOCK_NONBLOCK +SOCK_CLOEXEC +SOL_SOCKET +STDIN_FILENO +STDOUT_FILENO +STDERR_FILENO +TCP_NODELAY +EPERM +ENOENT +ESRCH +EINTR +EIO +ENXIO +E2BIG +ENOEXEC +EBADF +ECHILD +EAGAIN +ENOMEM +EACCES +EFAULT +ENOTBLK +EBUSY +EEXIST +EXDEV +ENODEV +ENOTDIR +EISDIR +EINVAL +ENFILE +EMFILE +ENOTTY +ETXTBSY +EFBIG +ENOSPC +ESPIPE +EROFS +EMLINK +EPIPE +EDOM +ERANGE +EDEADLK +ENAMETOOLONG +ENOLCK +ENOSYS +ENOTEMPTY +ELOOP +EWOULDBLOCK +ENOMSG +EIDRM +ECHRNG +EL2NSYNC +EL3HLT +EL3RST +ELNRNG +EUNATCH +ENOCSI +EL2HLT +EBADE +EBADR +EXFULL +ENOANO +EBADRQC +EBADSLT +EDEADLOCK +EBFONT +ENOSTR +ENODATA +ETIME +ENOSR +ENONET +ENOPKG +EREMOTE +ENOLINK +EADV +ESRMNT +ECOMM +EPROTO +EMULTIHOP +EDOTDOT +EBADMSG +EOVERFLOW +ENOTUNIQ +EBADFD +EREMCHG +ELIBACC +ELIBBAD +ELIBSCN +ELIBMAX +ELIBEXEC +EILSEQ +ERESTART +ESTRPIPE +EUSERS +ENOTSOCK +EDESTADDRREQ +EMSGSIZE +EPROTOTYPE +ENOPROTOOPT +EPROTONOSUPPORT +ESOCKTNOSUPPORT +EOPNOTSUPP +EPFNOSUPPORT +EAFNOSUPPORT +EADDRINUSE +EADDRNOTAVAIL +ENETDOWN +ENETUNREACH +ENETRESET +ECONNABORTED +ECONNRESET +ENOBUFS +EISCONN +ENOTCONN +ESHUTDOWN +ETOOMANYREFS +ETIMEDOUT +ECONNREFUSED +EHOSTDOWN +EHOSTUNREACH +EALREADY +EINPROGRESS +ESTALE +EUCLEAN +ENOTNAM +ENAVAIL +EISNAM +EREMOTEIO +EDQUOT +ENOMEDIUM +EMEDIUMTYPE +ECANCELED +ENOKEY +EKEYEXPIRED +EKEYREVOKED +EKEYREJECTED +EOWNERDEAD +ENOTRECOVERABLE +ERFKIL +EHWPOISON +addrinfo +dirent64 +in6_addr +in_addr +iovec +pollfd +sockaddr +sockaddr_in +sockaddr_in6 +sockaddr_storage +stat +timespec +sys_abort +sys_accept +sys_alloc +sys_alloc_zeroed +sys_available_parallelism +sys_bind +sys_clock_gettime +sys_close +sys_connect +sys_dealloc +sys_dup +sys_errno +sys_eventfd +sys_exit +sys_fcntl +sys_freeaddrinfo +sys_fstat +sys_futex_wait +sys_futex_wake +sys_getaddrinfo +sys_getdents64 +sys_getpeername +sys_getsockname +sys_getsockopt +sys_ioctl +sys_listen +sys_lstat +sys_mkdir +sys_nanosleep +sys_open +sys_poll +sys_read +sys_readv +sys_realloc +sys_recv +sys_recvfrom +sys_rmdir +sys_send +sys_sendto +sys_setsockopt +sys_shutdown +sys_socket +sys_stat +sys_unlink +sys_write +sys_writev From 63973924e21f0caa309c8a77869c4e4d47cd70e0 Mon Sep 17 00:00:00 2001 From: B I Mohammed Abbas Date: Wed, 21 Aug 2024 12:39:37 +0530 Subject: [PATCH 09/25] VxWorks: Add functions from vxCpuLib.h and taskLib.h (backport ) (cherry picked from commit 7cf499d51afaa639644e9ed2f0a64ef5c54649fc) --- src/vxworks/mod.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/vxworks/mod.rs b/src/vxworks/mod.rs index 4f0274241394e..8a6dabb39fd95 100644 --- a/src/vxworks/mod.rs +++ b/src/vxworks/mod.rs @@ -1812,6 +1812,10 @@ extern "C" { pub fn taskIdSelf() -> ::TASK_ID; pub fn taskDelay(ticks: ::_Vx_ticks_t) -> ::c_int; + // taskLib.h + pub fn taskNameSet(task_id: ::TASK_ID, task_name: *mut ::c_char) -> ::c_int; + pub fn taskNameGet(task_id: ::TASK_ID, buf_name: *mut ::c_char, bufsize: ::size_t) -> ::c_int; + // rtpLibCommon.h pub fn rtpInfoGet(rtpId: ::RTP_ID, rtpStruct: *mut ::RTP_DESC) -> ::c_int; pub fn rtpSpawn( @@ -1871,6 +1875,10 @@ extern "C" { ) -> ::c_int; pub fn mq_getattr(mqd: ::mqd_t, attr: *mut ::mq_attr) -> ::c_int; pub fn mq_setattr(mqd: ::mqd_t, newattr: *const ::mq_attr, oldattr: *mut ::mq_attr) -> ::c_int; + + // vxCpuLib.h + fn vxCpuEnabledGet() -> ::cpuset_t; // Get set of running CPU's in the system + fn vxCpuConfiguredGet() -> ::cpuset_t; // Get set of Configured CPU's in the system } //Dummy functions, these don't really exist in VxWorks. From 4c0eaac7629d6d88823315ef3406f7ac51cc97d4 Mon Sep 17 00:00:00 2001 From: B I Mohammed Abbas Date: Mon, 8 Jul 2024 17:21:43 +0530 Subject: [PATCH 10/25] Add missing constant S_ISVTX for vxworks (backport ) [ Change to `c_int` rather than `mode_t`. We should make everything consistent at some point, just not a partial change here. - Trevor ] (cherry picked from commit e9b1b9c78c0230174b1885971e08ebf2cb9f020d) --- src/vxworks/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/vxworks/mod.rs b/src/vxworks/mod.rs index 8a6dabb39fd95..314283410aed6 100644 --- a/src/vxworks/mod.rs +++ b/src/vxworks/mod.rs @@ -782,6 +782,7 @@ pub const S_IFSOCK: ::c_int = 0xc000; pub const S_ISUID: ::c_int = 0x0800; pub const S_ISGID: ::c_int = 0x0400; pub const S_ISTXT: ::c_int = 0x0200; +pub const S_ISVTX: ::c_int = 0o1000; pub const S_IRUSR: ::c_int = 0x0100; pub const S_IWUSR: ::c_int = 0x0080; pub const S_IXUSR: ::c_int = 0x0040; From 9b88c55790cba155204f3ecaec2be3072287d3fa Mon Sep 17 00:00:00 2001 From: David Carlier Date: Thu, 15 Aug 2024 22:28:30 +0100 Subject: [PATCH 11/25] OpenBSD: add sendmmsg and recvmmsg support. (backport ) (cherry picked from commit c36918572d2b91382753ec8b9516a5e8bebdeff2) --- libc-test/semver/openbsd.txt | 3 +++ src/unix/bsd/netbsdlike/mod.rs | 19 +++++++++++++++++++ src/unix/bsd/netbsdlike/netbsd/mod.rs | 19 ------------------- 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/libc-test/semver/openbsd.txt b/libc-test/semver/openbsd.txt index 6f07fec590ff5..197df09e1c2c6 100644 --- a/libc-test/semver/openbsd.txt +++ b/libc-test/semver/openbsd.txt @@ -1137,6 +1137,7 @@ mknodat mkostemp mkostemps mkstemps +mmsghdr mount_info mrand48 msdosfs_args @@ -1216,6 +1217,7 @@ readlinkat reallocarray reboot recvmsg +recvmmsg regcomp regerror regex_t @@ -1237,6 +1239,7 @@ sem_init sem_open sem_timedwait sem_unlink +sendmmsg sendmsg setdomainname setgrent diff --git a/src/unix/bsd/netbsdlike/mod.rs b/src/unix/bsd/netbsdlike/mod.rs index e92cf65940141..dcd3582fd7bf8 100644 --- a/src/unix/bsd/netbsdlike/mod.rs +++ b/src/unix/bsd/netbsdlike/mod.rs @@ -92,6 +92,11 @@ s! { pub piod_addr: *mut ::c_void, pub piod_len: ::size_t, } + + pub struct mmsghdr { + pub msg_hdr: ::msghdr, + pub msg_len: ::c_uint, + } } pub const D_T_FMT: ::nl_item = 0; @@ -848,6 +853,20 @@ extern "C" { pub fn dirname(path: *mut ::c_char) -> *mut ::c_char; pub fn basename(path: *mut ::c_char) -> *mut ::c_char; pub fn getentropy(buf: *mut ::c_void, buflen: ::size_t) -> ::c_int; + + pub fn sendmmsg( + sockfd: ::c_int, + mmsg: *mut ::mmsghdr, + vlen: ::c_uint, + flags: ::c_int, + ) -> ::c_int; + pub fn recvmmsg( + sockfd: ::c_int, + mmsg: *mut ::mmsghdr, + vlen: ::c_uint, + flags: ::c_int, + timeout: *mut ::timespec, + ) -> ::c_int; } cfg_if! { diff --git a/src/unix/bsd/netbsdlike/netbsd/mod.rs b/src/unix/bsd/netbsdlike/netbsd/mod.rs index 0ad2473138080..0517a47b69c30 100644 --- a/src/unix/bsd/netbsdlike/netbsd/mod.rs +++ b/src/unix/bsd/netbsdlike/netbsd/mod.rs @@ -401,11 +401,6 @@ s! { pub sdl_data: [::c_char; 12], } - pub struct mmsghdr { - pub msg_hdr: ::msghdr, - pub msg_len: ::c_uint, - } - pub struct __exit_status { pub e_termination: u16, pub e_exit: u16, @@ -2781,20 +2776,6 @@ extern "C" { pub fn kqueue1(flags: ::c_int) -> ::c_int; - pub fn sendmmsg( - sockfd: ::c_int, - msgvec: *mut ::mmsghdr, - vlen: ::c_uint, - flags: ::c_int, - ) -> ::c_int; - pub fn recvmmsg( - sockfd: ::c_int, - msgvec: *mut ::mmsghdr, - vlen: ::c_uint, - flags: ::c_int, - timeout: *mut ::timespec, - ) -> ::c_int; - pub fn _lwp_self() -> lwpid_t; pub fn memmem( haystack: *const ::c_void, From adafc287d63978c484aeb0a21962200cf71b4d85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20=C3=81vila=20de=20Esp=C3=ADndola?= Date: Fri, 24 May 2024 19:56:35 +0000 Subject: [PATCH 12/25] Unify the ioctl declarations on linux This uses the existing Ioctl type to reduce the duplication. (backport ) (cherry picked from commit 01a36171f2aa7e523dca7c632293f2c95f892eeb) --- src/unix/linux_like/linux/gnu/mod.rs | 1 - src/unix/linux_like/linux/mod.rs | 2 ++ src/unix/linux_like/linux/musl/mod.rs | 1 - src/unix/linux_like/linux/uclibc/mod.rs | 1 - 4 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/unix/linux_like/linux/gnu/mod.rs b/src/unix/linux_like/linux/gnu/mod.rs index f206693d4af71..3c22d845f1008 100644 --- a/src/unix/linux_like/linux/gnu/mod.rs +++ b/src/unix/linux_like/linux/gnu/mod.rs @@ -1405,7 +1405,6 @@ extern "C" { pub fn reallocarray(ptr: *mut ::c_void, nmemb: ::size_t, size: ::size_t) -> *mut ::c_void; pub fn ctermid(s: *mut ::c_char) -> *mut ::c_char; - pub fn ioctl(fd: ::c_int, request: ::c_ulong, ...) -> ::c_int; pub fn backtrace(buf: *mut *mut ::c_void, sz: ::c_int) -> ::c_int; pub fn glob64( pattern: *const ::c_char, diff --git a/src/unix/linux_like/linux/mod.rs b/src/unix/linux_like/linux/mod.rs index 5d2505a1b2f26..1973b3f574efa 100644 --- a/src/unix/linux_like/linux/mod.rs +++ b/src/unix/linux_like/linux/mod.rs @@ -5635,6 +5635,8 @@ extern "C" { ) -> ::ssize_t; pub fn klogctl(syslog_type: ::c_int, bufp: *mut ::c_char, len: ::c_int) -> ::c_int; + + pub fn ioctl(fd: ::c_int, request: ::Ioctl, ...) -> ::c_int; } // LFS64 extensions diff --git a/src/unix/linux_like/linux/musl/mod.rs b/src/unix/linux_like/linux/musl/mod.rs index 699c8181f8466..a4c8f79c35cad 100644 --- a/src/unix/linux_like/linux/musl/mod.rs +++ b/src/unix/linux_like/linux/musl/mod.rs @@ -853,7 +853,6 @@ extern "C" { new_limit: *const ::rlimit, old_limit: *mut ::rlimit, ) -> ::c_int; - pub fn ioctl(fd: ::c_int, request: ::c_int, ...) -> ::c_int; pub fn gettimeofday(tp: *mut ::timeval, tz: *mut ::c_void) -> ::c_int; pub fn ptrace(request: ::c_int, ...) -> ::c_long; pub fn getpriority(which: ::c_int, who: ::id_t) -> ::c_int; diff --git a/src/unix/linux_like/linux/uclibc/mod.rs b/src/unix/linux_like/linux/uclibc/mod.rs index b8d10cb94595f..32c65545a8905 100644 --- a/src/unix/linux_like/linux/uclibc/mod.rs +++ b/src/unix/linux_like/linux/uclibc/mod.rs @@ -353,7 +353,6 @@ pub const UDP_SEGMENT: ::c_int = 103; pub const YESEXPR: ::c_int = ((5) << 8) | (0); extern "C" { - pub fn ioctl(fd: ::c_int, request: ::c_ulong, ...) -> ::c_int; pub fn gettimeofday(tp: *mut ::timeval, tz: *mut ::timezone) -> ::c_int; pub fn pthread_rwlockattr_getkind_np( From ac6739c557ddf4ee4f47a4809d0781d12951a293 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 27 Aug 2024 08:04:41 -0700 Subject: [PATCH 13/25] Re-enable testing of WASI on CI This commit updates CI to resume testing WASI. This updates the container and testing scripts from historical processes to more modern ones, e.g. downloading wasi-sdk instead of compiling a custom toolchain. This should make it easier to update in the future and keep it in sync with rust-lang/rust as well. This also required a few minor fixes such as: * The `S_IFIFO` and `S_IFMT` constants had incorrect values. * The `CLOCK_*` definitions cause `ctest2`'s parsing to panic to they're skipped with a new `#[cfg]`. * A new `langinfo.h` header was added to the list to include. * Some historically skipped checks were removed since they're no longer necessary. * Checks for `__errno_location` are disabled since that doesn't actually exist in headers. * Checks for `select` are disabled because the Rust definition got the `const`-ness swapped for the final `timeval` argument. (backport ) [ resolve conflicts - Trevor ] (cherry picked from commit 7c10562845682f605d361d1c7d0fbfa38180bc87) --- .github/workflows/full_ci.yml | 6 +---- build.rs | 1 + ci/docker/wasm32-wasi/Dockerfile | 40 ------------------------------ ci/docker/wasm32-wasi/clang.sh | 2 -- ci/docker/wasm32-wasip1/Dockerfile | 32 ++++++++++++++++++++++++ libc-test/build.rs | 35 ++++++++++++++++++-------- src/wasi.rs | 34 ++++++++++++++++--------- 7 files changed, 80 insertions(+), 70 deletions(-) delete mode 100644 ci/docker/wasm32-wasi/Dockerfile delete mode 100755 ci/docker/wasm32-wasi/clang.sh create mode 100644 ci/docker/wasm32-wasip1/Dockerfile diff --git a/.github/workflows/full_ci.yml b/.github/workflows/full_ci.yml index 6a4fbc7f4d332..3fb7616203b8a 100644 --- a/.github/workflows/full_ci.yml +++ b/.github/workflows/full_ci.yml @@ -118,11 +118,7 @@ jobs: powerpc64le-unknown-linux-gnu, s390x-unknown-linux-gnu, riscv64gc-unknown-linux-gnu, - # FIXME: A recent nightly causes a linker failure: - # https://github.com/rust-lang/rust/issues/76679 - # See this comment for more details: - # https://github.com/rust-lang/libc/pull/2225#issuecomment-880696737 - #wasm32-wasi, + wasm32-wasip1, sparc64-unknown-linux-gnu, wasm32-unknown-emscripten, x86_64-linux-android, diff --git a/build.rs b/build.rs index 076bbc0114f86..098ee0fd6d7bc 100644 --- a/build.rs +++ b/build.rs @@ -30,6 +30,7 @@ const ALLOWED_CFGS: &'static [&'static str] = &[ "libc_thread_local", "libc_underscore_const_names", "libc_union", + "libc_ctest", ]; // Extra values to allow for check-cfg. diff --git a/ci/docker/wasm32-wasi/Dockerfile b/ci/docker/wasm32-wasi/Dockerfile deleted file mode 100644 index 80ae09f75038b..0000000000000 --- a/ci/docker/wasm32-wasi/Dockerfile +++ /dev/null @@ -1,40 +0,0 @@ -FROM ubuntu:23.10 - -RUN apt-get update && \ - apt-get install -y --no-install-recommends \ - ca-certificates \ - clang \ - curl \ - git \ - libc6-dev \ - make \ - xz-utils - -# Note that we're using `git reset --hard` to pin to a specific commit for -# verification for now. The sysroot is currently in somewhat of a state of flux -# and is expected to have breaking changes, so this is an attempt to mitigate -# those breaking changes on `libc`'s own CI -RUN git clone https://github.com/WebAssembly/wasi-libc && \ - cd wasi-libc && \ - git reset --hard ad5133410f66b93a2381db5b542aad5e0964db96 -RUN apt-get install -y --no-install-recommends llvm -RUN make -C wasi-libc install -j $(nproc) INSTALL_DIR=/wasi-libc - -RUN curl -L https://github.com/bytecodealliance/wasmtime/releases/download/dev/wasmtime-dev-x86_64-linux.tar.xz | \ - tar xJf - -ENV PATH=$PATH:/wasmtime-dev-x86_64-linux -COPY docker/wasm32-wasi/clang.sh /wasi-libc/bin/clang - -RUN apt-get install -y --no-install-recommends lld -RUN ln -s /usr/bin/wasm-ld-10 /usr/bin/wasm-ld -ENV PATH=$PATH:/usr/lib/llvm-10/bin - -# Of note here is our clang wrapper which just executes a normal clang -# executable with the right sysroot, and then we're sure to turn off the -# crt-static feature to ensure that the CRT that we're specifying with `clang` -# is used. -ENV CARGO_TARGET_WASM32_WASI_RUNNER=wasmtime \ - CARGO_TARGET_WASM32_WASI_LINKER=/wasi-libc/bin/clang \ - CC_wasm32_wasi=/wasi-libc/bin/clang \ - PATH=$PATH:/rust/bin \ - RUSTFLAGS=-Ctarget-feature=-crt-static diff --git a/ci/docker/wasm32-wasi/clang.sh b/ci/docker/wasm32-wasi/clang.sh deleted file mode 100755 index 83f5da5ad6d81..0000000000000 --- a/ci/docker/wasm32-wasi/clang.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/usr/bin/env sh -exec /usr/bin/clang --target=wasm32-wasi --sysroot /wasi-libc/sysroot "$@" diff --git a/ci/docker/wasm32-wasip1/Dockerfile b/ci/docker/wasm32-wasip1/Dockerfile new file mode 100644 index 0000000000000..9ffb85671e3d3 --- /dev/null +++ b/ci/docker/wasm32-wasip1/Dockerfile @@ -0,0 +1,32 @@ +FROM ubuntu:24.04 + +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + ca-certificates \ + curl \ + clang \ + xz-utils + +# Wasmtime is used to execute tests and wasi-sdk is used to compile tests. +# Download appropriate versions here and configure various flags below. +ENV WASMTIME 24.0.0 +ENV WASI_SDK 24 + +RUN curl -L https://github.com/bytecodealliance/wasmtime/releases/download/v$WASMTIME/wasmtime-v$WASMTIME-x86_64-linux.tar.xz | \ + tar xJf - +ENV PATH=$PATH:/wasmtime-v$WASMTIME-x86_64-linux + +RUN curl -LO https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-$WASI_SDK/wasi-sdk-$WASI_SDK.0-x86_64-linux.deb +RUN dpkg -i ./wasi-sdk-*.deb + +# Note that `-D_WASI_EMULATED_PROCESS_CLOCKS` is used to enable access to +# clock-related defines even though they're emulated. Also note that the usage +# of `-Ctarget-feature=-crt-static` here forces usage of the external wasi-libc +# installed via `wasi-sdk` instead of the version that comes with the standard +# library. +ENV CARGO_TARGET_WASM32_WASIP1_RUNNER=wasmtime \ + CARGO_TARGET_WASM32_WASIP1_LINKER=/opt/wasi-sdk/bin/clang \ + CARGO_TARGET_WASM32_WASIP1_RUSTFLAGS="-lwasi-emulated-process-clocks -Ctarget-feature=-crt-static" \ + CC_wasm32_wasip1=/opt/wasi-sdk/bin/clang \ + CFLAGS_wasm32_wasip1=-D_WASI_EMULATED_PROCESS_CLOCKS \ + PATH=$PATH:/rust/bin diff --git a/libc-test/build.rs b/libc-test/build.rs index 30ab41202e945..8e0a9cf4ad94d 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -1530,6 +1530,7 @@ fn test_wasi(target: &str) { "dirent.h", "errno.h", "fcntl.h", + "langinfo.h", "limits.h", "locale.h", "malloc.h", @@ -1541,6 +1542,7 @@ fn test_wasi(target: &str) { "stdio.h", "stdlib.h", "string.h", + "sys/ioctl.h", "sys/resource.h", "sys/select.h", "sys/socket.h", @@ -1549,16 +1551,20 @@ fn test_wasi(target: &str) { "sys/types.h", "sys/uio.h", "sys/utsname.h", - "sys/ioctl.h", "time.h", "unistd.h", "wasi/api.h", - "wasi/libc.h", "wasi/libc-find-relpath.h", "wasi/libc-nocwd.h", + "wasi/libc.h", "wchar.h", } + // Currently `ctest2` doesn't support macros-in-static-expressions and will + // panic on them. That affects `CLOCK_*` defines in wasi to set this here + // to omit them. + cfg.cfg("libc_ctest", None); + cfg.type_name(move |ty, is_struct, is_union| match ty { "FILE" | "fd_set" | "DIR" => ty.to_string(), t if is_union => format!("union {}", t), @@ -1577,20 +1583,27 @@ fn test_wasi(target: &str) { } }); - // Looks like LLD doesn't merge duplicate imports, so if the Rust - // code imports from a module and the C code also imports from a - // module we end up with two imports of function pointers which - // import the same thing but have different function pointers - cfg.skip_fn_ptrcheck(|f| f.starts_with("__wasi")); + // These have a different and internal type in header files and are only + // used here to generate a pointer to them in bindings so skip these tests. + cfg.skip_static(|c| c.starts_with("_CLOCK_")); + + cfg.skip_fn(|f| match f { + // This function doesn't actually exist in libc's header files + "__errno_location" => true, + + // The `timeout` argument to this function is `*const` in Rust but + // mutable in C which causes a mismatch. Avoiding breakage by changing + // this in wasi-libc and instead accepting that this is slightly + // different. + "select" => true, + + _ => false, + }); // d_name is declared as a flexible array in WASI libc, so it // doesn't support sizeof. cfg.skip_field(|s, field| s == "dirent" && field == "d_name"); - // Currently Rust/clang disagree on function argument ABI, so skip these - // tests. For more info see WebAssembly/tool-conventions#88 - cfg.skip_roundtrip(|_| true); - cfg.generate("../src/lib.rs", "main.rs"); } diff --git a/src/wasi.rs b/src/wasi.rs index 36047cbaed87d..ea8d4af29aa3b 100644 --- a/src/wasi.rs +++ b/src/wasi.rs @@ -245,14 +245,14 @@ pub const AT_SYMLINK_FOLLOW: c_int = 0x2; pub const AT_REMOVEDIR: c_int = 0x4; pub const UTIME_OMIT: c_long = 0xfffffffe; pub const UTIME_NOW: c_long = 0xffffffff; -pub const S_IFIFO: mode_t = 49152; +pub const S_IFIFO: mode_t = 0o1_0000; pub const S_IFCHR: mode_t = 8192; pub const S_IFBLK: mode_t = 24576; pub const S_IFDIR: mode_t = 16384; pub const S_IFREG: mode_t = 32768; pub const S_IFLNK: mode_t = 40960; pub const S_IFSOCK: mode_t = 49152; -pub const S_IFMT: mode_t = 57344; +pub const S_IFMT: mode_t = 0o17_0000; pub const S_IRWXO: mode_t = 0x7; pub const S_IXOTH: mode_t = 0x1; pub const S_IWOTH: mode_t = 0x2; @@ -372,16 +372,26 @@ pub const _SC_PAGE_SIZE: ::c_int = _SC_PAGESIZE; pub const _SC_IOV_MAX: c_int = 60; pub const _SC_SYMLOOP_MAX: c_int = 173; -#[allow(unused_unsafe)] // `addr_of!(EXTERN_STATIC)` is now safe; remove `unsafe` when MSRV >= 1.82 -pub static CLOCK_MONOTONIC: clockid_t = unsafe { clockid_t(ptr_addr_of!(_CLOCK_MONOTONIC)) }; -#[allow(unused_unsafe)] -pub static CLOCK_PROCESS_CPUTIME_ID: clockid_t = - unsafe { clockid_t(ptr_addr_of!(_CLOCK_PROCESS_CPUTIME_ID)) }; -#[allow(unused_unsafe)] -pub static CLOCK_REALTIME: clockid_t = unsafe { clockid_t(ptr_addr_of!(_CLOCK_REALTIME)) }; -#[allow(unused_unsafe)] -pub static CLOCK_THREAD_CPUTIME_ID: clockid_t = - unsafe { clockid_t(ptr_addr_of!(_CLOCK_THREAD_CPUTIME_ID)) }; +cfg_if! { + if #[cfg(libc_ctest)] { + // skip these constants when this is active because `ctest` currently + // panics on parsing the constants below + } else { + // `addr_of!(EXTERN_STATIC)` is now safe; remove `unsafe` when MSRV >= 1.82 + #[allow(unused_unsafe)] + pub static CLOCK_MONOTONIC: clockid_t = + unsafe { clockid_t(ptr_addr_of!(_CLOCK_MONOTONIC)) }; + #[allow(unused_unsafe)] + pub static CLOCK_PROCESS_CPUTIME_ID: clockid_t = + unsafe { clockid_t(ptr_addr_of!(_CLOCK_PROCESS_CPUTIME_ID)) }; + #[allow(unused_unsafe)] + pub static CLOCK_REALTIME: clockid_t = + unsafe { clockid_t(ptr_addr_of!(_CLOCK_REALTIME)) }; + #[allow(unused_unsafe)] + pub static CLOCK_THREAD_CPUTIME_ID: clockid_t = + unsafe { clockid_t(ptr_addr_of!(_CLOCK_THREAD_CPUTIME_ID)) }; + } +} pub const ABDAY_1: ::nl_item = 0x20000; pub const ABDAY_2: ::nl_item = 0x20001; From 4d990a598bd074e0dd745fc47986f26aefd8fd1d Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 28 Aug 2024 08:18:00 -0700 Subject: [PATCH 14/25] Add `wasm32-wasip2` to the test matrix on CI This is similar to #3869 except that it adds tests for `wasm32-wasip2` in addition to `wasm32-wasip1`. This is intended to eventually empower definitions from rust-lang/rust#129638 to move into this repository. (backport ) (cherry picked from commit 15f8c4445680c88def0695ecff088dfa35874301) --- .github/workflows/full_ci.yml | 1 + ci/docker/wasm32-wasip1/Dockerfile | 22 +++------------------- ci/docker/wasm32-wasip2/Dockerfile | 15 +++++++++++++++ ci/wasi.sh | 27 +++++++++++++++++++++++++++ 4 files changed, 46 insertions(+), 19 deletions(-) create mode 100644 ci/docker/wasm32-wasip2/Dockerfile create mode 100644 ci/wasi.sh diff --git a/.github/workflows/full_ci.yml b/.github/workflows/full_ci.yml index 3fb7616203b8a..b36f4f9d2ba57 100644 --- a/.github/workflows/full_ci.yml +++ b/.github/workflows/full_ci.yml @@ -119,6 +119,7 @@ jobs: s390x-unknown-linux-gnu, riscv64gc-unknown-linux-gnu, wasm32-wasip1, + wasm32-wasip2, sparc64-unknown-linux-gnu, wasm32-unknown-emscripten, x86_64-linux-android, diff --git a/ci/docker/wasm32-wasip1/Dockerfile b/ci/docker/wasm32-wasip1/Dockerfile index 9ffb85671e3d3..e1318151d2e62 100644 --- a/ci/docker/wasm32-wasip1/Dockerfile +++ b/ci/docker/wasm32-wasip1/Dockerfile @@ -1,23 +1,7 @@ FROM ubuntu:24.04 -RUN apt-get update && \ - apt-get install -y --no-install-recommends \ - ca-certificates \ - curl \ - clang \ - xz-utils - -# Wasmtime is used to execute tests and wasi-sdk is used to compile tests. -# Download appropriate versions here and configure various flags below. -ENV WASMTIME 24.0.0 -ENV WASI_SDK 24 - -RUN curl -L https://github.com/bytecodealliance/wasmtime/releases/download/v$WASMTIME/wasmtime-v$WASMTIME-x86_64-linux.tar.xz | \ - tar xJf - -ENV PATH=$PATH:/wasmtime-v$WASMTIME-x86_64-linux - -RUN curl -LO https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-$WASI_SDK/wasi-sdk-$WASI_SDK.0-x86_64-linux.deb -RUN dpkg -i ./wasi-sdk-*.deb +COPY wasi.sh / +RUN bash /wasi.sh # Note that `-D_WASI_EMULATED_PROCESS_CLOCKS` is used to enable access to # clock-related defines even though they're emulated. Also note that the usage @@ -29,4 +13,4 @@ ENV CARGO_TARGET_WASM32_WASIP1_RUNNER=wasmtime \ CARGO_TARGET_WASM32_WASIP1_RUSTFLAGS="-lwasi-emulated-process-clocks -Ctarget-feature=-crt-static" \ CC_wasm32_wasip1=/opt/wasi-sdk/bin/clang \ CFLAGS_wasm32_wasip1=-D_WASI_EMULATED_PROCESS_CLOCKS \ - PATH=$PATH:/rust/bin + PATH=$PATH:/rust/bin:/wasmtime diff --git a/ci/docker/wasm32-wasip2/Dockerfile b/ci/docker/wasm32-wasip2/Dockerfile new file mode 100644 index 0000000000000..c433c491353f9 --- /dev/null +++ b/ci/docker/wasm32-wasip2/Dockerfile @@ -0,0 +1,15 @@ +FROM ubuntu:24.04 + +COPY wasi.sh / +RUN bash /wasi.sh + +# Note that most of these are copied from `wasm32-wasip1/Dockerfile` +# +# FIXME: the `-Clink-arg` to export `cabi_realloc` is a bug in the target +# itself, this should be fixed upstream. +ENV CARGO_TARGET_WASM32_WASIP2_RUNNER=wasmtime \ + CARGO_TARGET_WASM32_WASIP2_LINKER=/opt/wasi-sdk/bin/clang \ + CARGO_TARGET_WASM32_WASIP2_RUSTFLAGS="-lwasi-emulated-process-clocks -Ctarget-feature=-crt-static -Clink-arg=-Wl,--export,cabi_realloc" \ + CC_wasm32_wasip2=/opt/wasi-sdk/bin/clang \ + CFLAGS_wasm32_wasip2=-D_WASI_EMULATED_PROCESS_CLOCKS \ + PATH=$PATH:/rust/bin:/wasmtime diff --git a/ci/wasi.sh b/ci/wasi.sh new file mode 100644 index 0000000000000..a06c1f45af11a --- /dev/null +++ b/ci/wasi.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash + +set -ex + +apt-get update +apt-get install -y --no-install-recommends \ + ca-certificates \ + curl \ + clang \ + xz-utils + +# Wasmtime is used to execute tests and wasi-sdk is used to compile tests. +# Download appropriate versions here and configure various flags below. +# +# At the time of this writing wasmtime 24.0.0 is the latest release and +# wasi-sdk-24 is the latest release, that these numbers match is just +# coincidence. +wasmtime=24.0.0 +wasi_sdk=24 + +curl -L https://github.com/bytecodealliance/wasmtime/releases/download/v$wasmtime/wasmtime-v$wasmtime-x86_64-linux.tar.xz | \ + tar xJf - +mv wasmtime-v$wasmtime-x86_64-linux wasmtime + +# The pre-built `*.deb` files for wasi-sdk install to `/opt/wasi-sdk` +curl -LO https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-$wasi_sdk/wasi-sdk-$wasi_sdk.0-x86_64-linux.deb +dpkg -i ./wasi-sdk-*.deb From 839bfc2d53aab9f36af0fbf8fff66ea863fc757b Mon Sep 17 00:00:00 2001 From: David Carlier Date: Sat, 17 Feb 2024 16:52:40 +0000 Subject: [PATCH 15/25] adding new syscall id fchmodat2 for glibc/musl x86 (kernel >= 6.6). (backport ) (cherry picked from commit 14bc9fb8089ed3d8d91938b65cc5cd5a1ad7a013) --- libc-test/build.rs | 3 +++ src/unix/linux_like/linux/gnu/b32/x86/mod.rs | 1 + src/unix/linux_like/linux/gnu/b64/x86_64/not_x32.rs | 1 + src/unix/linux_like/linux/gnu/b64/x86_64/x32.rs | 1 + src/unix/linux_like/linux/musl/b32/x86/mod.rs | 1 + src/unix/linux_like/linux/musl/b64/x86_64/mod.rs | 1 + 6 files changed, 8 insertions(+) diff --git a/libc-test/build.rs b/libc-test/build.rs index 8e0a9cf4ad94d..6252d8523c2d5 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -4210,6 +4210,9 @@ fn test_linux(target: &str) { true } + // FIXME: Requires >= 6.6 kernel headers. + "SYS_fchmodat2" => true, + // FIXME: seems to not be available all the time (from : "PF_VCPU" | "PF_IDLE" diff --git a/src/unix/linux_like/linux/gnu/b32/x86/mod.rs b/src/unix/linux_like/linux/gnu/b32/x86/mod.rs index 27f477bb48f85..161e54d13df9d 100644 --- a/src/unix/linux_like/linux/gnu/b32/x86/mod.rs +++ b/src/unix/linux_like/linux/gnu/b32/x86/mod.rs @@ -1044,6 +1044,7 @@ pub const SYS_memfd_secret: ::c_long = 447; pub const SYS_process_mrelease: ::c_long = 448; pub const SYS_futex_waitv: ::c_long = 449; pub const SYS_set_mempolicy_home_node: ::c_long = 450; +pub const SYS_fchmodat2: ::c_long = 452; // offsets in user_regs_structs, from sys/reg.h pub const EBX: ::c_int = 0; diff --git a/src/unix/linux_like/linux/gnu/b64/x86_64/not_x32.rs b/src/unix/linux_like/linux/gnu/b64/x86_64/not_x32.rs index 3831dfad9d414..e8750ec0cd8ee 100644 --- a/src/unix/linux_like/linux/gnu/b64/x86_64/not_x32.rs +++ b/src/unix/linux_like/linux/gnu/b64/x86_64/not_x32.rs @@ -438,6 +438,7 @@ pub const SYS_memfd_secret: ::c_long = 447; pub const SYS_process_mrelease: ::c_long = 448; pub const SYS_futex_waitv: ::c_long = 449; pub const SYS_set_mempolicy_home_node: ::c_long = 450; +pub const SYS_fchmodat2: ::c_long = 452; extern "C" { pub fn sysctl( diff --git a/src/unix/linux_like/linux/gnu/b64/x86_64/x32.rs b/src/unix/linux_like/linux/gnu/b64/x86_64/x32.rs index 06aa0da2d74aa..90745b1762335 100644 --- a/src/unix/linux_like/linux/gnu/b64/x86_64/x32.rs +++ b/src/unix/linux_like/linux/gnu/b64/x86_64/x32.rs @@ -366,6 +366,7 @@ pub const SYS_memfd_secret: ::c_long = __X32_SYSCALL_BIT + 447; pub const SYS_process_mrelease: ::c_long = __X32_SYSCALL_BIT + 448; pub const SYS_futex_waitv: ::c_long = __X32_SYSCALL_BIT + 449; pub const SYS_set_mempolicy_home_node: ::c_long = __X32_SYSCALL_BIT + 450; +pub const SYS_fchmodat2: ::c_long = __X32_SYSCALL_BIT + 452; pub const SYS_rt_sigaction: ::c_long = __X32_SYSCALL_BIT + 512; pub const SYS_rt_sigreturn: ::c_long = __X32_SYSCALL_BIT + 513; pub const SYS_ioctl: ::c_long = __X32_SYSCALL_BIT + 514; diff --git a/src/unix/linux_like/linux/musl/b32/x86/mod.rs b/src/unix/linux_like/linux/musl/b32/x86/mod.rs index 12280851e7471..7fad04677f8a4 100644 --- a/src/unix/linux_like/linux/musl/b32/x86/mod.rs +++ b/src/unix/linux_like/linux/musl/b32/x86/mod.rs @@ -936,6 +936,7 @@ pub const SYS_memfd_secret: ::c_long = 447; pub const SYS_process_mrelease: ::c_long = 448; pub const SYS_futex_waitv: ::c_long = 449; pub const SYS_set_mempolicy_home_node: ::c_long = 450; +pub const SYS_fchmodat2: ::c_long = 452; // offsets in user_regs_structs, from sys/reg.h pub const EBX: ::c_int = 0; diff --git a/src/unix/linux_like/linux/musl/b64/x86_64/mod.rs b/src/unix/linux_like/linux/musl/b64/x86_64/mod.rs index 4d17868000ebd..677e2e4953e75 100644 --- a/src/unix/linux_like/linux/musl/b64/x86_64/mod.rs +++ b/src/unix/linux_like/linux/musl/b64/x86_64/mod.rs @@ -608,6 +608,7 @@ pub const SYS_memfd_secret: ::c_long = 447; pub const SYS_process_mrelease: ::c_long = 448; pub const SYS_futex_waitv: ::c_long = 449; pub const SYS_set_mempolicy_home_node: ::c_long = 450; +pub const SYS_fchmodat2: ::c_long = 452; // offsets in user_regs_structs, from sys/reg.h pub const R15: ::c_int = 0; From 255a51524a191c18dbd1ebdda38cb26d07b324be Mon Sep 17 00:00:00 2001 From: David Carlier Date: Sat, 10 Aug 2024 15:28:19 +0100 Subject: [PATCH 16/25] linux adding new syscall SYS_mseal for x86_64 glibc/musl. (backport ) (cherry picked from commit 396c63c594915655bbd5aa8e6ea4aaab4f35a548) --- libc-test/build.rs | 3 +++ libc-test/semver/linux-i686.txt | 1 + libc-test/semver/linux-powerpc.txt | 1 + libc-test/semver/linux-s390x.txt | 1 + libc-test/semver/linux-x86_64.txt | 1 + src/unix/linux_like/linux/gnu/b32/arm/mod.rs | 1 + src/unix/linux_like/linux/gnu/b32/powerpc.rs | 1 + src/unix/linux_like/linux/gnu/b32/x86/mod.rs | 1 + src/unix/linux_like/linux/gnu/b64/aarch64/mod.rs | 1 + src/unix/linux_like/linux/gnu/b64/s390x.rs | 1 + src/unix/linux_like/linux/gnu/b64/x86_64/not_x32.rs | 1 + src/unix/linux_like/linux/musl/b32/arm/mod.rs | 1 + src/unix/linux_like/linux/musl/b32/powerpc.rs | 1 + src/unix/linux_like/linux/musl/b64/aarch64/mod.rs | 1 + src/unix/linux_like/linux/musl/b64/s390x.rs | 1 + src/unix/linux_like/linux/musl/b64/x86_64/mod.rs | 1 + 16 files changed, 18 insertions(+) diff --git a/libc-test/build.rs b/libc-test/build.rs index 6252d8523c2d5..6a7f7efce2b39 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -4213,6 +4213,9 @@ fn test_linux(target: &str) { // FIXME: Requires >= 6.6 kernel headers. "SYS_fchmodat2" => true, + // FIXME: Requires >= 6.10 kernel headers. + "SYS_mseal" => true, + // FIXME: seems to not be available all the time (from : "PF_VCPU" | "PF_IDLE" diff --git a/libc-test/semver/linux-i686.txt b/libc-test/semver/linux-i686.txt index a14498adc8396..2f40472dcfaeb 100644 --- a/libc-test/semver/linux-i686.txt +++ b/libc-test/semver/linux-i686.txt @@ -132,6 +132,7 @@ SYS_mknod SYS_mmap2 SYS_modify_ldt SYS_mpx +SYS_mseal SYS_nice SYS_oldfstat SYS_oldlstat diff --git a/libc-test/semver/linux-powerpc.txt b/libc-test/semver/linux-powerpc.txt index d9aacc973d972..2826bb98d20e3 100644 --- a/libc-test/semver/linux-powerpc.txt +++ b/libc-test/semver/linux-powerpc.txt @@ -82,6 +82,7 @@ SYS_mknod SYS_mmap2 SYS_modify_ldt SYS_mpx +SYS_mseal SYS_multiplexer SYS_nice SYS_oldfstat diff --git a/libc-test/semver/linux-s390x.txt b/libc-test/semver/linux-s390x.txt index f5d089e3d5e50..96be9c25e4f3c 100644 --- a/libc-test/semver/linux-s390x.txt +++ b/libc-test/semver/linux-s390x.txt @@ -59,6 +59,7 @@ SYS_link SYS_lstat SYS_mkdir SYS_mknod +SYS_mseal SYS_newfstatat SYS_nice SYS_open diff --git a/libc-test/semver/linux-x86_64.txt b/libc-test/semver/linux-x86_64.txt index 6ad111e7308cc..c8a509c215085 100644 --- a/libc-test/semver/linux-x86_64.txt +++ b/libc-test/semver/linux-x86_64.txt @@ -107,6 +107,7 @@ SYS_lstat SYS_mkdir SYS_mknod SYS_modify_ldt +SYS_mseal SYS_open SYS_pause SYS_pipe diff --git a/src/unix/linux_like/linux/gnu/b32/arm/mod.rs b/src/unix/linux_like/linux/gnu/b32/arm/mod.rs index 89c93aba8818e..4a14d692c8652 100644 --- a/src/unix/linux_like/linux/gnu/b32/arm/mod.rs +++ b/src/unix/linux_like/linux/gnu/b32/arm/mod.rs @@ -855,6 +855,7 @@ pub const SYS_memfd_secret: ::c_long = 447; pub const SYS_process_mrelease: ::c_long = 448; pub const SYS_futex_waitv: ::c_long = 449; pub const SYS_set_mempolicy_home_node: ::c_long = 450; +pub const SYS_mseal: ::c_long = 462; cfg_if! { if #[cfg(libc_align)] { diff --git a/src/unix/linux_like/linux/gnu/b32/powerpc.rs b/src/unix/linux_like/linux/gnu/b32/powerpc.rs index dd5732e0dcc14..cb7fdf7661472 100644 --- a/src/unix/linux_like/linux/gnu/b32/powerpc.rs +++ b/src/unix/linux_like/linux/gnu/b32/powerpc.rs @@ -823,3 +823,4 @@ pub const SYS_memfd_secret: ::c_long = 447; pub const SYS_process_mrelease: ::c_long = 448; pub const SYS_futex_waitv: ::c_long = 449; pub const SYS_set_mempolicy_home_node: ::c_long = 450; +pub const SYS_mseal: ::c_long = 462; diff --git a/src/unix/linux_like/linux/gnu/b32/x86/mod.rs b/src/unix/linux_like/linux/gnu/b32/x86/mod.rs index 161e54d13df9d..4391eb3fa7968 100644 --- a/src/unix/linux_like/linux/gnu/b32/x86/mod.rs +++ b/src/unix/linux_like/linux/gnu/b32/x86/mod.rs @@ -1045,6 +1045,7 @@ pub const SYS_process_mrelease: ::c_long = 448; pub const SYS_futex_waitv: ::c_long = 449; pub const SYS_set_mempolicy_home_node: ::c_long = 450; pub const SYS_fchmodat2: ::c_long = 452; +pub const SYS_mseal: ::c_long = 462; // offsets in user_regs_structs, from sys/reg.h pub const EBX: ::c_int = 0; diff --git a/src/unix/linux_like/linux/gnu/b64/aarch64/mod.rs b/src/unix/linux_like/linux/gnu/b64/aarch64/mod.rs index 284a1788f4409..c8a805cdd36cb 100644 --- a/src/unix/linux_like/linux/gnu/b64/aarch64/mod.rs +++ b/src/unix/linux_like/linux/gnu/b64/aarch64/mod.rs @@ -892,6 +892,7 @@ pub const SYS_memfd_secret: ::c_long = 447; pub const SYS_process_mrelease: ::c_long = 448; pub const SYS_futex_waitv: ::c_long = 449; pub const SYS_set_mempolicy_home_node: ::c_long = 450; +pub const SYS_mseal: ::c_long = 462; pub const PROT_BTI: ::c_int = 0x10; pub const PROT_MTE: ::c_int = 0x20; diff --git a/src/unix/linux_like/linux/gnu/b64/s390x.rs b/src/unix/linux_like/linux/gnu/b64/s390x.rs index 61ee2dcc9b50a..e85429ef97bf6 100644 --- a/src/unix/linux_like/linux/gnu/b64/s390x.rs +++ b/src/unix/linux_like/linux/gnu/b64/s390x.rs @@ -946,6 +946,7 @@ pub const SYS_memfd_secret: ::c_long = 447; pub const SYS_process_mrelease: ::c_long = 448; pub const SYS_futex_waitv: ::c_long = 449; pub const SYS_set_mempolicy_home_node: ::c_long = 450; +pub const SYS_mseal: ::c_long = 462; extern "C" { diff --git a/src/unix/linux_like/linux/gnu/b64/x86_64/not_x32.rs b/src/unix/linux_like/linux/gnu/b64/x86_64/not_x32.rs index e8750ec0cd8ee..9b37907bbb28a 100644 --- a/src/unix/linux_like/linux/gnu/b64/x86_64/not_x32.rs +++ b/src/unix/linux_like/linux/gnu/b64/x86_64/not_x32.rs @@ -439,6 +439,7 @@ pub const SYS_process_mrelease: ::c_long = 448; pub const SYS_futex_waitv: ::c_long = 449; pub const SYS_set_mempolicy_home_node: ::c_long = 450; pub const SYS_fchmodat2: ::c_long = 452; +pub const SYS_mseal: ::c_long = 462; extern "C" { pub fn sysctl( diff --git a/src/unix/linux_like/linux/musl/b32/arm/mod.rs b/src/unix/linux_like/linux/musl/b32/arm/mod.rs index 8225f26adb474..4ac3e60d43079 100644 --- a/src/unix/linux_like/linux/musl/b32/arm/mod.rs +++ b/src/unix/linux_like/linux/musl/b32/arm/mod.rs @@ -840,6 +840,7 @@ pub const SYS_memfd_secret: ::c_long = 447; pub const SYS_process_mrelease: ::c_long = 448; pub const SYS_futex_waitv: ::c_long = 449; pub const SYS_set_mempolicy_home_node: ::c_long = 450; +pub const SYS_mseal: ::c_long = 462; extern "C" { pub fn getrandom(buf: *mut ::c_void, buflen: ::size_t, flags: ::c_uint) -> ::ssize_t; diff --git a/src/unix/linux_like/linux/musl/b32/powerpc.rs b/src/unix/linux_like/linux/musl/b32/powerpc.rs index bdf25455fd8cc..834a442802b27 100644 --- a/src/unix/linux_like/linux/musl/b32/powerpc.rs +++ b/src/unix/linux_like/linux/musl/b32/powerpc.rs @@ -796,6 +796,7 @@ pub const SYS_memfd_secret: ::c_long = 447; pub const SYS_process_mrelease: ::c_long = 448; pub const SYS_futex_waitv: ::c_long = 449; pub const SYS_set_mempolicy_home_node: ::c_long = 450; +pub const SYS_mseal: ::c_long = 462; extern "C" { pub fn getrandom(buf: *mut ::c_void, buflen: ::size_t, flags: ::c_uint) -> ::ssize_t; diff --git a/src/unix/linux_like/linux/musl/b64/aarch64/mod.rs b/src/unix/linux_like/linux/musl/b64/aarch64/mod.rs index 54e072b314a84..24e6b8419253a 100644 --- a/src/unix/linux_like/linux/musl/b64/aarch64/mod.rs +++ b/src/unix/linux_like/linux/musl/b64/aarch64/mod.rs @@ -561,6 +561,7 @@ pub const SYS_memfd_secret: ::c_long = 447; pub const SYS_process_mrelease: ::c_long = 448; pub const SYS_futex_waitv: ::c_long = 449; pub const SYS_set_mempolicy_home_node: ::c_long = 450; +pub const SYS_mseal: ::c_long = 462; pub const MCL_CURRENT: ::c_int = 0x0001; pub const MCL_FUTURE: ::c_int = 0x0002; diff --git a/src/unix/linux_like/linux/musl/b64/s390x.rs b/src/unix/linux_like/linux/musl/b64/s390x.rs index aa4cbf87f8a22..567914f7b8cd5 100644 --- a/src/unix/linux_like/linux/musl/b64/s390x.rs +++ b/src/unix/linux_like/linux/musl/b64/s390x.rs @@ -722,3 +722,4 @@ pub const SYS_memfd_secret: ::c_long = 447; pub const SYS_process_mrelease: ::c_long = 448; pub const SYS_futex_waitv: ::c_long = 449; pub const SYS_set_mempolicy_home_node: ::c_long = 450; +pub const SYS_mseal: ::c_long = 462; diff --git a/src/unix/linux_like/linux/musl/b64/x86_64/mod.rs b/src/unix/linux_like/linux/musl/b64/x86_64/mod.rs index 677e2e4953e75..dc617d42fe0cc 100644 --- a/src/unix/linux_like/linux/musl/b64/x86_64/mod.rs +++ b/src/unix/linux_like/linux/musl/b64/x86_64/mod.rs @@ -609,6 +609,7 @@ pub const SYS_process_mrelease: ::c_long = 448; pub const SYS_futex_waitv: ::c_long = 449; pub const SYS_set_mempolicy_home_node: ::c_long = 450; pub const SYS_fchmodat2: ::c_long = 452; +pub const SYS_mseal: ::c_long = 462; // offsets in user_regs_structs, from sys/reg.h pub const R15: ::c_int = 0; From ff9b2109a6e42be54e419374178dcb52d51b119f Mon Sep 17 00:00:00 2001 From: byteallen Date: Thu, 29 Aug 2024 18:07:14 +0800 Subject: [PATCH 17/25] Add missing NOTE_MACHTIME and NOTE_MACH_CONTINUOUS_TIME constants to apple. (backport ) (cherry picked from commit b6938543a91241ed3d46433334ca74534005e392) --- libc-test/semver/apple.txt | 2 ++ src/unix/bsd/apple/mod.rs | 2 ++ 2 files changed, 4 insertions(+) diff --git a/libc-test/semver/apple.txt b/libc-test/semver/apple.txt index 4d280dc731dfd..89b5cca443395 100644 --- a/libc-test/semver/apple.txt +++ b/libc-test/semver/apple.txt @@ -1004,6 +1004,8 @@ NOTE_FORK NOTE_LEEWAY NOTE_LINK NOTE_LOWAT +NOTE_MACHTIME +NOTE_MACH_CONTINUOUS_TIME NOTE_NONE NOTE_NSECONDS NOTE_PCTRLMASK diff --git a/src/unix/bsd/apple/mod.rs b/src/unix/bsd/apple/mod.rs index 06b6c62a63f35..92d724071a3d4 100644 --- a/src/unix/bsd/apple/mod.rs +++ b/src/unix/bsd/apple/mod.rs @@ -4522,6 +4522,8 @@ pub const NOTE_ABSOLUTE: u32 = 0x00000008; pub const NOTE_LEEWAY: u32 = 0x00000010; pub const NOTE_CRITICAL: u32 = 0x00000020; pub const NOTE_BACKGROUND: u32 = 0x00000040; +pub const NOTE_MACH_CONTINUOUS_TIME: u32 = 0x00000080; +pub const NOTE_MACHTIME: u32 = 0x00000100; pub const NOTE_TRACK: u32 = 0x00000001; pub const NOTE_TRACKERR: u32 = 0x00000002; pub const NOTE_CHILD: u32 = 0x00000004; From 3ff9276095bd189842e25d69a87f6b612b0e4626 Mon Sep 17 00:00:00 2001 From: Nicola Krumschmidt Date: Fri, 30 Aug 2024 00:05:55 +0200 Subject: [PATCH 18/25] Add wasm32-wasip2 definitions necessary for std::net support (backport ) (cherry picked from commit 78e7b89791b41342841eadb6785f48423fa420d2) --- libc-test/build.rs | 18 ++++ libc-test/semver/wasi-p2.txt | 59 +++++++++++++ src/{wasi.rs => wasi/mod.rs} | 7 ++ src/wasi/p2.rs | 161 +++++++++++++++++++++++++++++++++++ 4 files changed, 245 insertions(+) create mode 100644 libc-test/semver/wasi-p2.txt rename src/{wasi.rs => wasi/mod.rs} (99%) create mode 100644 src/wasi/p2.rs diff --git a/libc-test/build.rs b/libc-test/build.rs index 6a7f7efce2b39..75dcd14fc83be 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -1521,6 +1521,7 @@ fn test_dragonflybsd(target: &str) { fn test_wasi(target: &str) { assert!(target.contains("wasi")); + let p2 = target.contains("wasip2"); let mut cfg = ctest_cfg(); cfg.define("_GNU_SOURCE", None); @@ -1534,6 +1535,9 @@ fn test_wasi(target: &str) { "limits.h", "locale.h", "malloc.h", + [p2]: "netdb.h", + [p2]: "netinet/in.h", + [p2]: "netinet/tcp.h", "poll.h", "sched.h", "stdbool.h", @@ -1565,6 +1569,12 @@ fn test_wasi(target: &str) { // to omit them. cfg.cfg("libc_ctest", None); + // `ctest2` has a hard-coded list of default cfgs which doesn't include + // wasip2, which is why it has to be set here manually. + if p2 { + cfg.cfg("target_env", Some("p2")); + } + cfg.type_name(move |ty, is_struct, is_union| match ty { "FILE" | "fd_set" | "DIR" => ty.to_string(), t if is_union => format!("union {}", t), @@ -1587,6 +1597,14 @@ fn test_wasi(target: &str) { // used here to generate a pointer to them in bindings so skip these tests. cfg.skip_static(|c| c.starts_with("_CLOCK_")); + cfg.skip_const(|c| match c { + // These constants aren't yet defined in wasi-libc. + // Exposing them is being tracked by https://github.com/WebAssembly/wasi-libc/issues/531. + "SO_BROADCAST" | "SO_LINGER" => true, + + _ => false, + }); + cfg.skip_fn(|f| match f { // This function doesn't actually exist in libc's header files "__errno_location" => true, diff --git a/libc-test/semver/wasi-p2.txt b/libc-test/semver/wasi-p2.txt new file mode 100644 index 0000000000000..bb79dfd0dc1e8 --- /dev/null +++ b/libc-test/semver/wasi-p2.txt @@ -0,0 +1,59 @@ +sa_family_t +in_port_t +in_addr_t +socklen_t +sockaddr +in_addr +sockaddr_in +in6_addr +sockaddr_in6 +sockaddr_storage +addrinfo +ip_mreq +ipv6_mreq +SHUT_RD +SHUT_WR +SHUT_RDWR +MSG_NOSIGNAL +MSG_PEEK +SO_REUSEADDR +SO_ERROR +SO_BROADCAST +SO_LINGER +SO_RCVTIMEO +SO_SNDTIMEO +SOCK_DGRAM +SOCK_STREAM +SOL_SOCKET +AF_INET +AF_INET6 +IPPROTO_IP +IPPROTO_TCP +IPPROTO_IPV6 +IP_TTL +IP_MULTICAST_TTL +IP_MULTICAST_LOOP +IP_ADD_MEMBERSHIP +IP_DROP_MEMBERSHIP +IPV6_MULTICAST_LOOP +IPV6_JOIN_GROUP +IPV6_LEAVE_GROUP +IPV6_V6ONLY +IPV6_ADD_MEMBERSHIP +IPV6_DROP_MEMBERSHIP +TCP_NODELAY +EAI_SYSTEM +socket +connect +bind +listen +accept +getsockname +getpeername +sendto +recvfrom +getsockopt +setsockopt +getaddrinfo +freeaddrinfo +gai_strerror diff --git a/src/wasi.rs b/src/wasi/mod.rs similarity index 99% rename from src/wasi.rs rename to src/wasi/mod.rs index ea8d4af29aa3b..d47d4076cc720 100644 --- a/src/wasi.rs +++ b/src/wasi/mod.rs @@ -879,3 +879,10 @@ extern "C" { pub fn __errno_location() -> *mut ::c_int; } + +cfg_if! { + if #[cfg(target_env = "p2")] { + mod p2; + pub use self::p2::*; + } +} diff --git a/src/wasi/p2.rs b/src/wasi/p2.rs new file mode 100644 index 0000000000000..3e8eb95fcd1a5 --- /dev/null +++ b/src/wasi/p2.rs @@ -0,0 +1,161 @@ +pub type sa_family_t = ::c_ushort; +pub type in_port_t = ::c_ushort; +pub type in_addr_t = ::c_uint; + +pub type socklen_t = ::c_uint; + +s! { + #[repr(align(16))] + pub struct sockaddr { + pub sa_family: sa_family_t, + pub sa_data: [::c_char; 0], + } + + pub struct in_addr { + pub s_addr: in_addr_t, + } + + #[repr(align(16))] + pub struct sockaddr_in { + pub sin_family: sa_family_t, + pub sin_port: in_port_t, + pub sin_addr: in_addr, + } + + #[repr(align(4))] + pub struct in6_addr { + pub s6_addr: [::c_uchar; 16], + } + + #[repr(align(16))] + pub struct sockaddr_in6 { + pub sin6_family: sa_family_t, + pub sin6_port: in_port_t, + pub sin6_flowinfo: ::c_uint, + pub sin6_addr: in6_addr, + pub sin6_scope_id: ::c_uint, + } + + #[repr(align(16))] + pub struct sockaddr_storage { + pub ss_family: sa_family_t, + pub __ss_data: [::c_char; 32], + } + + pub struct addrinfo { + pub ai_flags: ::c_int, + pub ai_family: ::c_int, + pub ai_socktype: ::c_int, + pub ai_protocol: ::c_int, + pub ai_addrlen: socklen_t, + pub ai_addr: *mut sockaddr, + pub ai_canonname: *mut ::c_char, + pub ai_next: *mut addrinfo, + } + + pub struct ip_mreq { + pub imr_multiaddr: in_addr, + pub imr_interface: in_addr, + } + + pub struct ipv6_mreq { + pub ipv6mr_multiaddr: in6_addr, + pub ipv6mr_interface: ::c_uint, + } +} + +pub const SHUT_RD: ::c_int = 1 << 0; +pub const SHUT_WR: ::c_int = 1 << 1; +pub const SHUT_RDWR: ::c_int = SHUT_RD | SHUT_WR; + +pub const MSG_NOSIGNAL: ::c_int = 0x4000; +pub const MSG_PEEK: ::c_int = 0x0002; + +pub const SO_REUSEADDR: ::c_int = 2; +pub const SO_ERROR: ::c_int = 4; +pub const SO_BROADCAST: ::c_int = 6; +pub const SO_LINGER: ::c_int = 13; +pub const SO_RCVTIMEO: ::c_int = 66; +pub const SO_SNDTIMEO: ::c_int = 67; + +pub const SOCK_DGRAM: ::c_int = 5; +pub const SOCK_STREAM: ::c_int = 6; + +pub const SOL_SOCKET: ::c_int = 0x7fffffff; + +pub const AF_INET: ::c_int = 1; +pub const AF_INET6: ::c_int = 2; + +pub const IPPROTO_IP: ::c_int = 0; +pub const IPPROTO_TCP: ::c_int = 6; +pub const IPPROTO_IPV6: ::c_int = 41; + +pub const IP_TTL: ::c_int = 2; +pub const IP_MULTICAST_TTL: ::c_int = 33; +pub const IP_MULTICAST_LOOP: ::c_int = 34; +pub const IP_ADD_MEMBERSHIP: ::c_int = 35; +pub const IP_DROP_MEMBERSHIP: ::c_int = 36; + +pub const IPV6_MULTICAST_LOOP: ::c_int = 19; +pub const IPV6_JOIN_GROUP: ::c_int = 20; +pub const IPV6_LEAVE_GROUP: ::c_int = 21; +pub const IPV6_V6ONLY: ::c_int = 26; + +pub const IPV6_ADD_MEMBERSHIP: ::c_int = IPV6_JOIN_GROUP; +pub const IPV6_DROP_MEMBERSHIP: ::c_int = IPV6_LEAVE_GROUP; + +pub const TCP_NODELAY: ::c_int = 1; + +pub const EAI_SYSTEM: ::c_int = -11; + +extern "C" { + pub fn socket(domain: ::c_int, type_: ::c_int, protocol: ::c_int) -> ::c_int; + pub fn connect(fd: ::c_int, name: *const sockaddr, addrlen: socklen_t) -> ::c_int; + pub fn bind(socket: ::c_int, addr: *const sockaddr, addrlen: socklen_t) -> ::c_int; + pub fn listen(socket: ::c_int, backlog: ::c_int) -> ::c_int; + pub fn accept(socket: ::c_int, addr: *mut sockaddr, addrlen: *mut socklen_t) -> ::c_int; + + pub fn getsockname(socket: ::c_int, addr: *mut sockaddr, addrlen: *mut socklen_t) -> ::c_int; + pub fn getpeername(socket: ::c_int, addr: *mut sockaddr, addrlen: *mut socklen_t) -> ::c_int; + + pub fn sendto( + socket: ::c_int, + buffer: *const ::c_void, + length: ::size_t, + flags: ::c_int, + addr: *const sockaddr, + addrlen: socklen_t, + ) -> ::ssize_t; + pub fn recvfrom( + socket: ::c_int, + buffer: *mut ::c_void, + length: ::size_t, + flags: ::c_int, + addr: *mut sockaddr, + addrlen: *mut socklen_t, + ) -> ::ssize_t; + + pub fn getsockopt( + sockfd: ::c_int, + level: ::c_int, + optname: ::c_int, + optval: *mut ::c_void, + optlen: *mut socklen_t, + ) -> ::c_int; + pub fn setsockopt( + sockfd: ::c_int, + level: ::c_int, + optname: ::c_int, + optval: *const ::c_void, + optlen: socklen_t, + ) -> ::c_int; + + pub fn getaddrinfo( + host: *const ::c_char, + serv: *const ::c_char, + hint: *const addrinfo, + res: *mut *mut addrinfo, + ) -> ::c_int; + pub fn freeaddrinfo(p: *mut addrinfo); + pub fn gai_strerror(ecode: ::c_int) -> *const ::c_char; +} From e6e4bccd5bd330d7ea5f1cb62a6ede654aa45381 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=B7=D0=B0=D0=BB=D0=B8=D1=8F=20=D0=A1=D0=BC=D0=B0?= =?UTF-8?q?=D1=80=D0=B0=D0=B3=D0=B4=D0=BE=D0=B2=D0=B0?= Date: Sat, 24 Aug 2024 12:11:13 +0500 Subject: [PATCH 19/25] Expose the "epoll_pwait2()" function The ```epoll_pwait2()``` function has been moved to linux/gnu (backport ) (cherry picked from commit f3756b90e8605ec07d49fc041ef685be8582bf5d) --- libc-test/semver/linux-gnu.txt | 1 + src/unix/linux_like/linux/gnu/mod.rs | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/libc-test/semver/linux-gnu.txt b/libc-test/semver/linux-gnu.txt index 821443c6c385d..ce4f85484eee0 100644 --- a/libc-test/semver/linux-gnu.txt +++ b/libc-test/semver/linux-gnu.txt @@ -711,3 +711,4 @@ putpwent putgrent execveat close_range +epoll_pwait2 diff --git a/src/unix/linux_like/linux/gnu/mod.rs b/src/unix/linux_like/linux/gnu/mod.rs index 3c22d845f1008..75d150c90d58a 100644 --- a/src/unix/linux_like/linux/gnu/mod.rs +++ b/src/unix/linux_like/linux/gnu/mod.rs @@ -1542,6 +1542,14 @@ extern "C" { pub fn close_range(first: ::c_uint, last: ::c_uint, flags: ::c_int) -> ::c_int; pub fn mq_notify(mqdes: ::mqd_t, sevp: *const ::sigevent) -> ::c_int; + + pub fn epoll_pwait2( + epfd: ::c_int, + events: *mut ::epoll_event, + maxevents: ::c_int, + timeout: *const ::timespec, + sigmask: *const ::sigset_t, + ) -> ::c_int; } cfg_if! { From 70feded4192065ec4734b6a91eb7c80410471a0f Mon Sep 17 00:00:00 2001 From: Ben Kimock Date: Mon, 2 Sep 2024 15:25:13 -0400 Subject: [PATCH 20/25] Change signal constants to c_int on espidf (backport ) (cherry picked from commit a6f4694237042e0fc5616782c2f8bbb516c27e4d) --- src/unix/newlib/espidf/mod.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/unix/newlib/espidf/mod.rs b/src/unix/newlib/espidf/mod.rs index e2e98ee9c394a..1a2a907d83191 100644 --- a/src/unix/newlib/espidf/mod.rs +++ b/src/unix/newlib/espidf/mod.rs @@ -89,14 +89,14 @@ pub const MSG_EOR: ::c_int = 0x08; pub const PTHREAD_STACK_MIN: ::size_t = 768; -pub const SIGABRT: ::size_t = 1; -pub const SIGFPE: ::size_t = 1; -pub const SIGILL: ::size_t = 1; -pub const SIGINT: ::size_t = 1; -pub const SIGSEGV: ::size_t = 1; -pub const SIGTERM: ::size_t = 1; -pub const SIGHUP: ::size_t = 1; -pub const SIGQUIT: ::size_t = 1; +pub const SIGABRT: ::c_int = 1; +pub const SIGFPE: ::c_int = 1; +pub const SIGILL: ::c_int = 1; +pub const SIGINT: ::c_int = 1; +pub const SIGSEGV: ::c_int = 1; +pub const SIGTERM: ::c_int = 1; +pub const SIGHUP: ::c_int = 1; +pub const SIGQUIT: ::c_int = 1; pub const NSIG: ::size_t = 2; extern "C" { From a3e88691a9a1a41867b0692b67cc50f5b1d39eb2 Mon Sep 17 00:00:00 2001 From: Andrea Ciliberti Date: Wed, 21 Aug 2024 12:38:49 +0200 Subject: [PATCH 21/25] Revise network definitions for HorizonOS (backport ) (cherry picked from commit 82ebf14f8fcb70be0e0b290115b0fe879bfa6f0a) --- src/unix/newlib/horizon/mod.rs | 9 +++++++++ src/unix/newlib/mod.rs | 26 ++++++++++++++++---------- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/src/unix/newlib/horizon/mod.rs b/src/unix/newlib/horizon/mod.rs index 9c70f7b031b63..97e0b18f6fb71 100644 --- a/src/unix/newlib/horizon/mod.rs +++ b/src/unix/newlib/horizon/mod.rs @@ -21,6 +21,14 @@ pub type sbintime_t = ::c_longlong; pub type sigset_t = ::c_ulong; s! { + pub struct hostent { + pub h_name: *mut ::c_char, + pub h_aliases: *mut *mut ::c_char, + pub h_addrtype: u16, + pub h_length: u16, + pub h_addr_list: *mut *mut ::c_char, + } + pub struct sockaddr { pub sa_family: ::sa_family_t, pub sa_data: [::c_char; 26usize], @@ -35,6 +43,7 @@ s! { pub sin_family: ::sa_family_t, pub sin_port: ::in_port_t, pub sin_addr: ::in_addr, + pub sin_zero: [::c_char; 8], } pub struct sockaddr_in6 { diff --git a/src/unix/newlib/mod.rs b/src/unix/newlib/mod.rs index a572cc38bfda9..29693f6ec2402 100644 --- a/src/unix/newlib/mod.rs +++ b/src/unix/newlib/mod.rs @@ -53,6 +53,21 @@ cfg_if! { } } +cfg_if! { + if #[cfg(not(target_os = "horizon"))] { + s!{ + pub struct hostent { + pub h_name: *mut ::c_char, + pub h_aliases: *mut *mut ::c_char, + pub h_addrtype: ::c_int, + pub h_length: ::c_int, + pub h_addr_list: *mut *mut ::c_char, + pub h_addr: *mut ::c_char, + } + } + } +} + s! { // The order of the `ai_addr` field in this struct is crucial // for converting between the Rust and C types. @@ -87,16 +102,7 @@ s! { } pub struct in_addr { - pub s_addr: ::in_addr_t, - } - - pub struct hostent { - pub h_name: *mut ::c_char, - pub h_aliases: *mut *mut ::c_char, - pub h_addrtype: ::c_int, - pub h_length: ::c_int, - pub h_addr_list: *mut *mut ::c_char, - pub h_addr: *mut ::c_char, + pub s_addr: ::in_addr_t, } pub struct pollfd { From 507833559bd0bfe04b5139c1607c3dc3208174f5 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Sat, 31 Aug 2024 11:01:53 -0400 Subject: [PATCH 22/25] Fix rustc version when `clippy-driver` is used This is a combined cherry-pick of the following two commits: - 18b8da96 ("Handle rustc version output correctly...") - cdf12d2a ("Update `rustc_version_cmd`") These two commits are squashed for the backport to slightly reduce the amount of conflict resolution needed going forward (some small tweaks were still needed). This backports the following: - - Commit 1 original message: Handle rustc version output correctly when `clippy-driver` used Commit 2 original message: Update `rustc_version_cmd` Change `if let` to a `match` because it is about the same complexity but also works with our MSRV for 0.2. This should allow backporting [1] easier, as well as future backports that touch this code. Additionally, add some new documentation comments. [1]: https://github.com/rust-lang/libc/pull/3893 Co-authored-by: Nathaniel Bennett Co-authored-by: Trevor Gross --- build.rs | 58 +++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 39 insertions(+), 19 deletions(-) diff --git a/build.rs b/build.rs index 098ee0fd6d7bc..bfc1f63e6ff9e 100644 --- a/build.rs +++ b/build.rs @@ -1,5 +1,5 @@ use std::env; -use std::process::Command; +use std::process::{Command, Output}; use std::str; // List of cfgs this build script is allowed to set. The list is needed to support check-cfg, as we @@ -194,31 +194,29 @@ fn main() { } } -fn rustc_minor_nightly() -> (u32, bool) { - macro_rules! otry { - ($e:expr) => { - match $e { - Some(e) => e, - None => panic!("Failed to get rustc version"), - } - }; - } - +/// Run `rustc --version` and capture the output, adjusting arguments as needed if `clippy-driver` +/// is used instead. +fn rustc_version_cmd(is_clippy_driver: bool) -> Output { + let rustc_wrapper = env::var_os("RUSTC_WRAPPER").filter(|w| !w.is_empty()); let rustc = env::var_os("RUSTC").expect("Failed to get rustc version: missing RUSTC env"); - let mut cmd = match env::var_os("RUSTC_WRAPPER").as_ref() { - Some(wrapper) if !wrapper.is_empty() => { + + let mut cmd = match rustc_wrapper { + Some(wrapper) => { let mut cmd = Command::new(wrapper); cmd.arg(rustc); + if is_clippy_driver { + cmd.arg("--rustc"); + } + cmd } - _ => Command::new(rustc), + None => Command::new(rustc), }; - let output = cmd - .arg("--version") - .output() - .ok() - .expect("Failed to get rustc version"); + cmd.arg("--version"); + + let output = cmd.output().ok().expect("Failed to get rustc version"); + if !output.status.success() { panic!( "failed to run rustc: {}", @@ -226,7 +224,29 @@ fn rustc_minor_nightly() -> (u32, bool) { ); } + output +} + +/// Return the minor version of `rustc`, as well as a bool indicating whether or not the version +/// is a nightly. +fn rustc_minor_nightly() -> (u32, bool) { + macro_rules! otry { + ($e:expr) => { + match $e { + Some(e) => e, + None => panic!("Failed to get rustc version"), + } + }; + } + + let mut output = rustc_version_cmd(false); + + if otry!(str::from_utf8(&output.stdout).ok()).starts_with("clippy") { + output = rustc_version_cmd(true); + } + let version = otry!(str::from_utf8(&output.stdout).ok()); + let mut pieces = version.split('.'); if pieces.next() != Some("rustc 1") { From abcb8f87986c8f57a28c4f67d7939272f4f8cbad Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Tue, 10 Sep 2024 15:16:06 +0200 Subject: [PATCH 23/25] Simplify the RUSTC_WRAPPER check This should be compatible with older versions of rustc, to get the branches more in sync. (backport ) (cherry picked from commit bdce2b2ff52832e86061aa204581e034bcb78e8d) --- build-tmp.rs | 374 +++++++++++++++++++++++++++++++++++++++++++++++++++ build.rs | 4 +- 2 files changed, 376 insertions(+), 2 deletions(-) create mode 100644 build-tmp.rs diff --git a/build-tmp.rs b/build-tmp.rs new file mode 100644 index 0000000000000..101f45ac262e9 --- /dev/null +++ b/build-tmp.rs @@ -0,0 +1,374 @@ +use std::env; +use std::ffi::{OsStr, OsString}; +use std::process::{Command, Output}; +use std::str; + +// List of cfgs this build script is allowed to set. The list is needed to support check-cfg, as we +// need to know all the possible cfgs that this script will set. If you need to set another cfg +// make sure to add it to this list as well. +const ALLOWED_CFGS: &'static [&'static str] = &[ + "emscripten_new_stat_abi", + "espidf_time64", + "freebsd10", + "freebsd11", + "freebsd12", + "freebsd13", + "freebsd14", + "freebsd15", + "libc_align", + "libc_cfg_target_vendor", + "libc_const_extern_fn", + "libc_const_extern_fn_unstable", + "libc_const_size_of", + "libc_core_cvoid", + "libc_deny_warnings", + "libc_int128", + "libc_long_array", + "libc_non_exhaustive", + "libc_packedN", + "libc_priv_mod_use", + "libc_ptr_addr_of", + "libc_thread_local", + "libc_underscore_const_names", + "libc_union", + "libc_ctest", +]; + +// Extra values to allow for check-cfg. +const CHECK_CFG_EXTRA: &'static [(&'static str, &'static [&'static str])] = &[ + ("target_os", &["switch", "aix", "ohos", "hurd", "visionos"]), + ("target_env", &["illumos", "wasi", "aix", "ohos"]), + ( + "target_arch", + &["loongarch64", "mips32r6", "mips64r6", "csky"], + ), +]; + +fn main() { + // Avoid unnecessary re-building. + println!("cargo:rerun-if-changed=build.rs"); + + let (rustc_minor_ver, is_nightly) = rustc_minor_nightly(); + let rustc_dep_of_std = env::var("CARGO_FEATURE_RUSTC_DEP_OF_STD").is_ok(); + let align_cargo_feature = env::var("CARGO_FEATURE_ALIGN").is_ok(); + let const_extern_fn_cargo_feature = env::var("CARGO_FEATURE_CONST_EXTERN_FN").is_ok(); + let libc_ci = env::var("LIBC_CI").is_ok(); + let libc_check_cfg = env::var("LIBC_CHECK_CFG").is_ok() || rustc_minor_ver >= 80; + + if env::var("CARGO_FEATURE_USE_STD").is_ok() { + println!( + "cargo:warning=\"libc's use_std cargo feature is deprecated since libc 0.2.55; \ + please consider using the `std` cargo feature instead\"" + ); + } + + // The ABI of libc used by std is backward compatible with FreeBSD 12. + // The ABI of libc from crates.io is backward compatible with FreeBSD 11. + // + // On CI, we detect the actual FreeBSD version and match its ABI exactly, + // running tests to ensure that the ABI is correct. + let which_freebsd = if libc_ci { + which_freebsd().unwrap_or(11) + } else if rustc_dep_of_std { + 12 + } else { + 11 + }; + match which_freebsd { + x if x < 10 => panic!("FreeBSD older than 10 is not supported"), + 10 => set_cfg("freebsd10"), + 11 => set_cfg("freebsd11"), + 12 => set_cfg("freebsd12"), + 13 => set_cfg("freebsd13"), + 14 => set_cfg("freebsd14"), + _ => set_cfg("freebsd15"), + } + + match emcc_version_code() { + Some(v) if (v >= 30142) => set_cfg("emscripten_new_stat_abi"), + // Non-Emscripten or version < 3.1.42. + Some(_) | None => (), + } + + // On CI: deny all warnings + if libc_ci { + set_cfg("libc_deny_warnings"); + } + + // Rust >= 1.15 supports private module use: + if rustc_minor_ver >= 15 || rustc_dep_of_std { + set_cfg("libc_priv_mod_use"); + } + + // Rust >= 1.19 supports unions: + if rustc_minor_ver >= 19 || rustc_dep_of_std { + set_cfg("libc_union"); + } + + // Rust >= 1.24 supports const mem::size_of: + if rustc_minor_ver >= 24 || rustc_dep_of_std { + set_cfg("libc_const_size_of"); + } + + // Rust >= 1.25 supports repr(align): + if rustc_minor_ver >= 25 || rustc_dep_of_std || align_cargo_feature { + set_cfg("libc_align"); + } + + // Rust >= 1.26 supports i128 and u128: + if rustc_minor_ver >= 26 || rustc_dep_of_std { + set_cfg("libc_int128"); + } + + // Rust >= 1.30 supports `core::ffi::c_void`, so libc can just re-export it. + // Otherwise, it defines an incompatible type to retaining + // backwards-compatibility. + if rustc_minor_ver >= 30 || rustc_dep_of_std { + set_cfg("libc_core_cvoid"); + } + + // Rust >= 1.33 supports repr(packed(N)) and cfg(target_vendor). + if rustc_minor_ver >= 33 || rustc_dep_of_std { + set_cfg("libc_packedN"); + set_cfg("libc_cfg_target_vendor"); + } + + // Rust >= 1.40 supports #[non_exhaustive]. + if rustc_minor_ver >= 40 || rustc_dep_of_std { + set_cfg("libc_non_exhaustive"); + } + + // Rust >= 1.47 supports long array: + if rustc_minor_ver >= 47 || rustc_dep_of_std { + set_cfg("libc_long_array"); + } + + if rustc_minor_ver >= 51 || rustc_dep_of_std { + set_cfg("libc_ptr_addr_of"); + } + + // Rust >= 1.37.0 allows underscores as anonymous constant names. + if rustc_minor_ver >= 37 || rustc_dep_of_std { + set_cfg("libc_underscore_const_names"); + } + + // #[thread_local] is currently unstable + if rustc_dep_of_std { + set_cfg("libc_thread_local"); + } + + // Rust >= 1.62.0 allows to use `const_extern_fn` for "Rust" and "C". + if rustc_minor_ver >= 62 { + set_cfg("libc_const_extern_fn"); + } else { + // Rust < 1.62.0 requires a crate feature and feature gate. + if const_extern_fn_cargo_feature { + if !is_nightly || rustc_minor_ver < 40 { + panic!("const-extern-fn requires a nightly compiler >= 1.40"); + } + set_cfg("libc_const_extern_fn_unstable"); + set_cfg("libc_const_extern_fn"); + } + } + + // check-cfg is a nightly cargo/rustc feature to warn when unknown cfgs are used across the + // codebase. libc can configure it if the appropriate environment variable is passed. Since + // rust-lang/rust enforces it, this is useful when using a custom libc fork there. + // + // https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#check-cfg + if libc_check_cfg { + for cfg in ALLOWED_CFGS { + if rustc_minor_ver >= 75 { + println!("cargo:rustc-check-cfg=cfg({})", cfg); + } else { + println!("cargo:rustc-check-cfg=values({})", cfg); + } + } + for &(name, values) in CHECK_CFG_EXTRA { + let values = values.join("\",\""); + if rustc_minor_ver >= 75 { + println!("cargo:rustc-check-cfg=cfg({},values(\"{}\"))", name, values); + } else { + println!("cargo:rustc-check-cfg=values({},\"{}\")", name, values); + } + } + } +} + +fn rustc_version_cmd(is_clippy_driver: bool) -> Output { + let rustc_wrapper = env::var_os("RUSTC_WRAPPER").filter(|w| !w.is_empty()); + let rustc = env::var_os("RUSTC").expect("Failed to get rustc version: missing RUSTC env"); + + let mut cmd = if let Some(wrapper) = rustc_wrapper { + let mut cmd = Command::new(wrapper); + cmd.arg(rustc); + if is_clippy_driver { + cmd.arg("--rustc"); + } + + cmd + } else { + Command::new(rustc) + }; + + cmd.arg("--version"); + + let output = cmd.output().expect("Failed to get rustc version"); + + if !output.status.success() { + panic!( + "failed to run rustc: {}", + String::from_utf8_lossy(output.stderr.as_slice()) + ); + } + + output +} + +fn rustc_minor_nightly() -> (u32, bool) { + macro_rules! otry { + ($e:expr) => { + match $e { + Some(e) => e, + None => panic!("Failed to get rustc version"), + } + }; + } + +<<<<<<< HEAD + let rustc = env::var_os("RUSTC").expect("Failed to get rustc version: missing RUSTC env"); + let mut cmd = match env::var_os("RUSTC_WRAPPER").as_ref() { + Some(wrapper) if !wrapper.is_empty() => { + let mut cmd = Command::new(wrapper); + cmd.arg(rustc); + cmd + } + _ => Command::new(rustc), + }; +||||||| parent of 18b8da967 (Handle rustc version output correctly when `clippy-driver` used) + let rustc = env::var_os("RUSTC").expect("Failed to get rustc version: missing RUSTC env"); + let mut cmd = if let Some(wrapper) = env::var_os("RUSTC_WRAPPER").filter(|w| !w.is_empty()) { + let mut cmd = Command::new(wrapper); + cmd.arg(rustc); + cmd + } else { + Command::new(rustc) + }; +======= + let mut output = rustc_version_cmd(false); +>>>>>>> 18b8da967 (Handle rustc version output correctly when `clippy-driver` used) + +<<<<<<< HEAD + let output = cmd + .arg("--version") + .output() + .ok() + .expect("Failed to get rustc version"); + if !output.status.success() { + panic!( + "failed to run rustc: {}", + String::from_utf8_lossy(output.stderr.as_slice()) + ); +||||||| parent of 18b8da967 (Handle rustc version output correctly when `clippy-driver` used) + let output = cmd + .arg("--version") + .output() + .expect("Failed to get rustc version"); + if !output.status.success() { + panic!( + "failed to run rustc: {}", + String::from_utf8_lossy(output.stderr.as_slice()) + ); +======= + if otry!(str::from_utf8(&output.stdout).ok()).starts_with("clippy") { + output = rustc_version_cmd(true); +>>>>>>> 18b8da967 (Handle rustc version output correctly when `clippy-driver` used) + } + + let version = otry!(str::from_utf8(&output.stdout).ok()); + + let mut pieces = version.split('.'); + + if pieces.next() != Some("rustc 1") { + panic!("Failed to get rustc version"); + } + + let minor = pieces.next(); + + // If `rustc` was built from a tarball, its version string + // will have neither a git hash nor a commit date + // (e.g. "rustc 1.39.0"). Treat this case as non-nightly, + // since a nightly build should either come from CI + // or a git checkout + let nightly_raw = otry!(pieces.next()).split('-').nth(1); + let nightly = nightly_raw + .map(|raw| raw.starts_with("dev") || raw.starts_with("nightly")) + .unwrap_or(false); + let minor = otry!(otry!(minor).parse().ok()); + + (minor, nightly) +} + +fn which_freebsd() -> Option { + let output = std::process::Command::new("freebsd-version").output().ok(); + if output.is_none() { + return None; + } + let output = output.unwrap(); + if !output.status.success() { + return None; + } + + let stdout = String::from_utf8(output.stdout).ok(); + if stdout.is_none() { + return None; + } + let stdout = stdout.unwrap(); + + 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 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(); + if !output.status.success() { + return None; + } + + let stdout = String::from_utf8(output.stdout).ok(); + if stdout.is_none() { + return None; + } + let version = stdout.unwrap(); + + // 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 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); + let patch = pieces.next().and_then(|x| x.parse().ok()).unwrap_or(0); + + Some(major * 10000 + minor * 100 + patch) +} + +fn set_cfg(cfg: &str) { + if !ALLOWED_CFGS.contains(&cfg) { + panic!("trying to set cfg {}, but it is not in ALLOWED_CFGS", cfg); + } + println!("cargo:rustc-cfg={}", cfg); +} diff --git a/build.rs b/build.rs index bfc1f63e6ff9e..ce4541e62955c 100644 --- a/build.rs +++ b/build.rs @@ -197,10 +197,10 @@ fn main() { /// Run `rustc --version` and capture the output, adjusting arguments as needed if `clippy-driver` /// is used instead. fn rustc_version_cmd(is_clippy_driver: bool) -> Output { - let rustc_wrapper = env::var_os("RUSTC_WRAPPER").filter(|w| !w.is_empty()); let rustc = env::var_os("RUSTC").expect("Failed to get rustc version: missing RUSTC env"); - let mut cmd = match rustc_wrapper { + let mut cmd = match env::var_os("RUSTC_WRAPPER") { + Some(ref wrapper) if wrapper.is_empty() => Command::new(rustc), Some(wrapper) => { let mut cmd = Command::new(wrapper); cmd.arg(rustc); From 28bb64b1fe678ca090f9af08d786949d53285940 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Tue, 17 Sep 2024 18:04:07 +0200 Subject: [PATCH 24/25] Remove temporary file that was added by accident (backport ) (cherry picked from commit ea9548ae341631a38b6486b4f6991350400176aa) --- build-tmp.rs | 374 --------------------------------------------------- 1 file changed, 374 deletions(-) delete mode 100644 build-tmp.rs diff --git a/build-tmp.rs b/build-tmp.rs deleted file mode 100644 index 101f45ac262e9..0000000000000 --- a/build-tmp.rs +++ /dev/null @@ -1,374 +0,0 @@ -use std::env; -use std::ffi::{OsStr, OsString}; -use std::process::{Command, Output}; -use std::str; - -// List of cfgs this build script is allowed to set. The list is needed to support check-cfg, as we -// need to know all the possible cfgs that this script will set. If you need to set another cfg -// make sure to add it to this list as well. -const ALLOWED_CFGS: &'static [&'static str] = &[ - "emscripten_new_stat_abi", - "espidf_time64", - "freebsd10", - "freebsd11", - "freebsd12", - "freebsd13", - "freebsd14", - "freebsd15", - "libc_align", - "libc_cfg_target_vendor", - "libc_const_extern_fn", - "libc_const_extern_fn_unstable", - "libc_const_size_of", - "libc_core_cvoid", - "libc_deny_warnings", - "libc_int128", - "libc_long_array", - "libc_non_exhaustive", - "libc_packedN", - "libc_priv_mod_use", - "libc_ptr_addr_of", - "libc_thread_local", - "libc_underscore_const_names", - "libc_union", - "libc_ctest", -]; - -// Extra values to allow for check-cfg. -const CHECK_CFG_EXTRA: &'static [(&'static str, &'static [&'static str])] = &[ - ("target_os", &["switch", "aix", "ohos", "hurd", "visionos"]), - ("target_env", &["illumos", "wasi", "aix", "ohos"]), - ( - "target_arch", - &["loongarch64", "mips32r6", "mips64r6", "csky"], - ), -]; - -fn main() { - // Avoid unnecessary re-building. - println!("cargo:rerun-if-changed=build.rs"); - - let (rustc_minor_ver, is_nightly) = rustc_minor_nightly(); - let rustc_dep_of_std = env::var("CARGO_FEATURE_RUSTC_DEP_OF_STD").is_ok(); - let align_cargo_feature = env::var("CARGO_FEATURE_ALIGN").is_ok(); - let const_extern_fn_cargo_feature = env::var("CARGO_FEATURE_CONST_EXTERN_FN").is_ok(); - let libc_ci = env::var("LIBC_CI").is_ok(); - let libc_check_cfg = env::var("LIBC_CHECK_CFG").is_ok() || rustc_minor_ver >= 80; - - if env::var("CARGO_FEATURE_USE_STD").is_ok() { - println!( - "cargo:warning=\"libc's use_std cargo feature is deprecated since libc 0.2.55; \ - please consider using the `std` cargo feature instead\"" - ); - } - - // The ABI of libc used by std is backward compatible with FreeBSD 12. - // The ABI of libc from crates.io is backward compatible with FreeBSD 11. - // - // On CI, we detect the actual FreeBSD version and match its ABI exactly, - // running tests to ensure that the ABI is correct. - let which_freebsd = if libc_ci { - which_freebsd().unwrap_or(11) - } else if rustc_dep_of_std { - 12 - } else { - 11 - }; - match which_freebsd { - x if x < 10 => panic!("FreeBSD older than 10 is not supported"), - 10 => set_cfg("freebsd10"), - 11 => set_cfg("freebsd11"), - 12 => set_cfg("freebsd12"), - 13 => set_cfg("freebsd13"), - 14 => set_cfg("freebsd14"), - _ => set_cfg("freebsd15"), - } - - match emcc_version_code() { - Some(v) if (v >= 30142) => set_cfg("emscripten_new_stat_abi"), - // Non-Emscripten or version < 3.1.42. - Some(_) | None => (), - } - - // On CI: deny all warnings - if libc_ci { - set_cfg("libc_deny_warnings"); - } - - // Rust >= 1.15 supports private module use: - if rustc_minor_ver >= 15 || rustc_dep_of_std { - set_cfg("libc_priv_mod_use"); - } - - // Rust >= 1.19 supports unions: - if rustc_minor_ver >= 19 || rustc_dep_of_std { - set_cfg("libc_union"); - } - - // Rust >= 1.24 supports const mem::size_of: - if rustc_minor_ver >= 24 || rustc_dep_of_std { - set_cfg("libc_const_size_of"); - } - - // Rust >= 1.25 supports repr(align): - if rustc_minor_ver >= 25 || rustc_dep_of_std || align_cargo_feature { - set_cfg("libc_align"); - } - - // Rust >= 1.26 supports i128 and u128: - if rustc_minor_ver >= 26 || rustc_dep_of_std { - set_cfg("libc_int128"); - } - - // Rust >= 1.30 supports `core::ffi::c_void`, so libc can just re-export it. - // Otherwise, it defines an incompatible type to retaining - // backwards-compatibility. - if rustc_minor_ver >= 30 || rustc_dep_of_std { - set_cfg("libc_core_cvoid"); - } - - // Rust >= 1.33 supports repr(packed(N)) and cfg(target_vendor). - if rustc_minor_ver >= 33 || rustc_dep_of_std { - set_cfg("libc_packedN"); - set_cfg("libc_cfg_target_vendor"); - } - - // Rust >= 1.40 supports #[non_exhaustive]. - if rustc_minor_ver >= 40 || rustc_dep_of_std { - set_cfg("libc_non_exhaustive"); - } - - // Rust >= 1.47 supports long array: - if rustc_minor_ver >= 47 || rustc_dep_of_std { - set_cfg("libc_long_array"); - } - - if rustc_minor_ver >= 51 || rustc_dep_of_std { - set_cfg("libc_ptr_addr_of"); - } - - // Rust >= 1.37.0 allows underscores as anonymous constant names. - if rustc_minor_ver >= 37 || rustc_dep_of_std { - set_cfg("libc_underscore_const_names"); - } - - // #[thread_local] is currently unstable - if rustc_dep_of_std { - set_cfg("libc_thread_local"); - } - - // Rust >= 1.62.0 allows to use `const_extern_fn` for "Rust" and "C". - if rustc_minor_ver >= 62 { - set_cfg("libc_const_extern_fn"); - } else { - // Rust < 1.62.0 requires a crate feature and feature gate. - if const_extern_fn_cargo_feature { - if !is_nightly || rustc_minor_ver < 40 { - panic!("const-extern-fn requires a nightly compiler >= 1.40"); - } - set_cfg("libc_const_extern_fn_unstable"); - set_cfg("libc_const_extern_fn"); - } - } - - // check-cfg is a nightly cargo/rustc feature to warn when unknown cfgs are used across the - // codebase. libc can configure it if the appropriate environment variable is passed. Since - // rust-lang/rust enforces it, this is useful when using a custom libc fork there. - // - // https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#check-cfg - if libc_check_cfg { - for cfg in ALLOWED_CFGS { - if rustc_minor_ver >= 75 { - println!("cargo:rustc-check-cfg=cfg({})", cfg); - } else { - println!("cargo:rustc-check-cfg=values({})", cfg); - } - } - for &(name, values) in CHECK_CFG_EXTRA { - let values = values.join("\",\""); - if rustc_minor_ver >= 75 { - println!("cargo:rustc-check-cfg=cfg({},values(\"{}\"))", name, values); - } else { - println!("cargo:rustc-check-cfg=values({},\"{}\")", name, values); - } - } - } -} - -fn rustc_version_cmd(is_clippy_driver: bool) -> Output { - let rustc_wrapper = env::var_os("RUSTC_WRAPPER").filter(|w| !w.is_empty()); - let rustc = env::var_os("RUSTC").expect("Failed to get rustc version: missing RUSTC env"); - - let mut cmd = if let Some(wrapper) = rustc_wrapper { - let mut cmd = Command::new(wrapper); - cmd.arg(rustc); - if is_clippy_driver { - cmd.arg("--rustc"); - } - - cmd - } else { - Command::new(rustc) - }; - - cmd.arg("--version"); - - let output = cmd.output().expect("Failed to get rustc version"); - - if !output.status.success() { - panic!( - "failed to run rustc: {}", - String::from_utf8_lossy(output.stderr.as_slice()) - ); - } - - output -} - -fn rustc_minor_nightly() -> (u32, bool) { - macro_rules! otry { - ($e:expr) => { - match $e { - Some(e) => e, - None => panic!("Failed to get rustc version"), - } - }; - } - -<<<<<<< HEAD - let rustc = env::var_os("RUSTC").expect("Failed to get rustc version: missing RUSTC env"); - let mut cmd = match env::var_os("RUSTC_WRAPPER").as_ref() { - Some(wrapper) if !wrapper.is_empty() => { - let mut cmd = Command::new(wrapper); - cmd.arg(rustc); - cmd - } - _ => Command::new(rustc), - }; -||||||| parent of 18b8da967 (Handle rustc version output correctly when `clippy-driver` used) - let rustc = env::var_os("RUSTC").expect("Failed to get rustc version: missing RUSTC env"); - let mut cmd = if let Some(wrapper) = env::var_os("RUSTC_WRAPPER").filter(|w| !w.is_empty()) { - let mut cmd = Command::new(wrapper); - cmd.arg(rustc); - cmd - } else { - Command::new(rustc) - }; -======= - let mut output = rustc_version_cmd(false); ->>>>>>> 18b8da967 (Handle rustc version output correctly when `clippy-driver` used) - -<<<<<<< HEAD - let output = cmd - .arg("--version") - .output() - .ok() - .expect("Failed to get rustc version"); - if !output.status.success() { - panic!( - "failed to run rustc: {}", - String::from_utf8_lossy(output.stderr.as_slice()) - ); -||||||| parent of 18b8da967 (Handle rustc version output correctly when `clippy-driver` used) - let output = cmd - .arg("--version") - .output() - .expect("Failed to get rustc version"); - if !output.status.success() { - panic!( - "failed to run rustc: {}", - String::from_utf8_lossy(output.stderr.as_slice()) - ); -======= - if otry!(str::from_utf8(&output.stdout).ok()).starts_with("clippy") { - output = rustc_version_cmd(true); ->>>>>>> 18b8da967 (Handle rustc version output correctly when `clippy-driver` used) - } - - let version = otry!(str::from_utf8(&output.stdout).ok()); - - let mut pieces = version.split('.'); - - if pieces.next() != Some("rustc 1") { - panic!("Failed to get rustc version"); - } - - let minor = pieces.next(); - - // If `rustc` was built from a tarball, its version string - // will have neither a git hash nor a commit date - // (e.g. "rustc 1.39.0"). Treat this case as non-nightly, - // since a nightly build should either come from CI - // or a git checkout - let nightly_raw = otry!(pieces.next()).split('-').nth(1); - let nightly = nightly_raw - .map(|raw| raw.starts_with("dev") || raw.starts_with("nightly")) - .unwrap_or(false); - let minor = otry!(otry!(minor).parse().ok()); - - (minor, nightly) -} - -fn which_freebsd() -> Option { - let output = std::process::Command::new("freebsd-version").output().ok(); - if output.is_none() { - return None; - } - let output = output.unwrap(); - if !output.status.success() { - return None; - } - - let stdout = String::from_utf8(output.stdout).ok(); - if stdout.is_none() { - return None; - } - let stdout = stdout.unwrap(); - - 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 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(); - if !output.status.success() { - return None; - } - - let stdout = String::from_utf8(output.stdout).ok(); - if stdout.is_none() { - return None; - } - let version = stdout.unwrap(); - - // 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 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); - let patch = pieces.next().and_then(|x| x.parse().ok()).unwrap_or(0); - - Some(major * 10000 + minor * 100 + patch) -} - -fn set_cfg(cfg: &str) { - if !ALLOWED_CFGS.contains(&cfg) { - panic!("trying to set cfg {}, but it is not in ALLOWED_CFGS", cfg); - } - println!("cargo:rustc-cfg={}", cfg); -} From 7373a1abe57da20efae9fd2ca891d7b905c19e03 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 24 Sep 2024 14:19:24 +0000 Subject: [PATCH 25/25] chore: release (#3862) Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Trevor Gross --- CHANGELOG.md | 31 +++++++++++++++++++++++++++++++ Cargo.toml | 2 +- libc-test/Cargo.toml | 2 +- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a5ac00205b010..01c340acaa11f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,37 @@ ## [Unreleased] +## [0.2.159](https://github.com/rust-lang/libc/compare/0.2.158...0.2.159) - 2024-09-24 + +### Added + +- Android: add more `AT_*` constants in +- Apple: add missing `NOTE_*` constants in +- Hermit: add missing error numbers in +- Hurd: add `__timeval` for 64-bit support in +- Linux: add `epoll_pwait2` in +- Linux: add `mq_notify` in +- Linux: add missing `NFT_CT_*` constants in +- Linux: add the `fchmodat2` syscall in +- Linux: add the `mseal` syscall in +- OpenBSD: add `sendmmsg` and `recvmmsg` in +- Unix: add `IN6ADDR_ANY_INIT` and `IN6ADDR_LOOPBACK_INIT` in +- VxWorks: add `S_ISVTX` in +- VxWorks: add `vxCpuLib` and `taskLib` functions +- WASIp2: add definitions for `std::net` support in + +### Fixed + +- Correctly handle version checks when `clippy-driver` is used + +### Changed + +- EspIdf: change signal constants to c_int in +- HorizonOS: update network definitions in +- Linux: combine `ioctl` APIs in +- WASI: enable CI testing in +- WASIp2: enable CI testing in + ## [0.2.158](https://github.com/rust-lang/libc/compare/0.2.157...0.2.158) - 2024-08-19 ### Other diff --git a/Cargo.toml b/Cargo.toml index 8fe2ad6badabf..3ca0827a37aed 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "libc" -version = "0.2.158" +version = "0.2.159" authors = ["The Rust Project Developers"] license = "MIT OR Apache-2.0" readme = "README.md" diff --git a/libc-test/Cargo.toml b/libc-test/Cargo.toml index 033458e8bd5de..8f25c7f2ca9d9 100644 --- a/libc-test/Cargo.toml +++ b/libc-test/Cargo.toml @@ -14,7 +14,7 @@ A test crate for the libc crate. [dependencies.libc] path = ".." -version = "0.2.158" +version = "0.2.159" default-features = false [build-dependencies]