From eb0794a5d8af5b7b370b01c5ae4f7f5f0c14bc0d Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Thu, 16 May 2019 12:17:37 +0200 Subject: [PATCH 01/25] Update Android SDK, NDK (r19c), and API versions (arm:24,x86:28) * Update Android NDK to version r19c * Update Android API versions to: * API 24 on arm and aarch64 targets * API 28 on x86 and x86_64 targets * Unified headers were removed in NDK 16 * Refactor the NDK and SDK installation scripts * OpenJDK version 8 must be kept: it appears that the Android tools do not work with more modern OpenJDK versions. --- ci/android-install-ndk.sh | 31 ++++++++++----- ci/android-install-sdk.sh | 44 +++++++++++++--------- ci/docker/aarch64-linux-android/Dockerfile | 2 +- ci/docker/arm-linux-androideabi/Dockerfile | 2 +- ci/docker/i686-linux-android/Dockerfile | 2 +- 5 files changed, 52 insertions(+), 29 deletions(-) diff --git a/ci/android-install-ndk.sh b/ci/android-install-ndk.sh index 54f7b2efd9674..90c9747c3363b 100644 --- a/ci/android-install-ndk.sh +++ b/ci/android-install-ndk.sh @@ -11,27 +11,40 @@ set -ex -curl --retry 10 -O https://dl.google.com/android/repository/android-ndk-r15b-linux-x86_64.zip -unzip -q android-ndk-r15b-linux-x86_64.zip +NDK=android-ndk-r19c +curl --retry 10 -O https://dl.google.com/android/repository/${NDK}-linux-x86_64.zip +unzip -q ${NDK}-linux-x86_64.zip case "$1" in + arm) + arch=arm + api=24 + ;; + armv7) + arch=arm + api=24 + ;; aarch64) arch=arm64 + api=24 ;; - i686) arch=x86 + api=28 + ;; + x86_64) + arch=x86_64 + api=28 ;; - *) - arch=$1 + echo "invalid arch: $1" + exit 1 ;; esac; -android-ndk-r15b/build/tools/make_standalone_toolchain.py \ - --unified-headers \ +${NDK}/build/tools/make_standalone_toolchain.py \ --install-dir "/android/ndk-${1}" \ --arch "${arch}" \ - --api 24 + --api ${api} -rm -rf ./android-ndk-r15b-linux-x86_64.zip ./android-ndk-r15b +rm -rf ./${NDK}-linux-x86_64.zip ./${NDK} diff --git a/ci/android-install-sdk.sh b/ci/android-install-sdk.sh index e011cfc34bb4c..fe28d43417b11 100644 --- a/ci/android-install-sdk.sh +++ b/ci/android-install-sdk.sh @@ -18,46 +18,56 @@ set -ex # located in https://github.com/appunite/docker by just wrapping it in a script # which apparently magically accepts the licenses. +SDK=4333796 mkdir sdk -curl --retry 10 https://dl.google.com/android/repository/sdk-tools-linux-3859397.zip -O -unzip -d sdk sdk-tools-linux-3859397.zip +curl --retry 10 https://dl.google.com/android/repository/sdk-tools-linux-${SDK}.zip -O +unzip -q -d sdk sdk-tools-linux-${SDK}.zip case "$1" in arm | armv7) - abi=armeabi-v7a + api=24 + image="system-images;android-${api};google_apis;armeabi-v7a" ;; - aarch64) - abi=arm64-v8a + api=24 + image="system-images;android-${api};google_apis;arm64-v8a" ;; - i686) - abi=x86 + api=28 + image="system-images;android-${api};default;x86" ;; - x86_64) - abi=x86_64 + api=28 + image="system-images;android-${api};default;x86_64" ;; - *) echo "invalid arch: $1" exit 1 ;; esac; -# See: https://stackoverflow.com/a/51644855/1422197 -export JAVA_OPTS='-XX:+IgnoreUnrecognizedVMOptions --add-modules java.se.ee' +# Try to fix warning about missing file. +# See https://askubuntu.com/a/1078784 +mkdir -p /root/.android/ +echo '### User Sources for Android SDK Manager' >> /root/.android/repositories.cfg +echo '#Fri Nov 03 10:11:27 CET 2017 count=0' >> /root/.android/repositories.cfg + +# Print all available packages +# yes | ./sdk/tools/bin/sdkmanager --list --verbose # --no_https avoids - # javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: No trusted certificate found -yes | ./sdk/tools/bin/sdkmanager --licenses --no_https +# javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: No trusted certificate found +# +# | grep -v = || true removes the progress bar output from the sdkmanager +# which produces an insane amount of output. +yes | ./sdk/tools/bin/sdkmanager --licenses --no_https | grep -v = || true yes | ./sdk/tools/bin/sdkmanager --no_https \ "emulator" \ "platform-tools" \ - "platforms;android-24" \ - "system-images;android-24;default;$abi" + "platforms;android-${api}" \ + "${image}" | grep -v = || true echo "no" | ./sdk/tools/bin/avdmanager create avd \ --name "${1}" \ - --package "system-images;android-24;default;$abi" + --package "${image}" | grep -v = || true diff --git a/ci/docker/aarch64-linux-android/Dockerfile b/ci/docker/aarch64-linux-android/Dockerfile index 1458423756759..6751dd93762d0 100644 --- a/ci/docker/aarch64-linux-android/Dockerfile +++ b/ci/docker/aarch64-linux-android/Dockerfile @@ -9,7 +9,7 @@ RUN dpkg --add-architecture i386 && \ python \ unzip \ expect \ - openjdk-11-jre \ + openjdk-8-jre \ libstdc++6:i386 \ libpulse0 \ gcc \ diff --git a/ci/docker/arm-linux-androideabi/Dockerfile b/ci/docker/arm-linux-androideabi/Dockerfile index acc784e7d595f..544d1676e1b08 100644 --- a/ci/docker/arm-linux-androideabi/Dockerfile +++ b/ci/docker/arm-linux-androideabi/Dockerfile @@ -9,7 +9,7 @@ RUN dpkg --add-architecture i386 && \ python \ unzip \ expect \ - openjdk-11-jre \ + openjdk-8-jre \ libstdc++6:i386 \ libpulse0 \ gcc \ diff --git a/ci/docker/i686-linux-android/Dockerfile b/ci/docker/i686-linux-android/Dockerfile index 59ea2d79fc31b..540322055e449 100644 --- a/ci/docker/i686-linux-android/Dockerfile +++ b/ci/docker/i686-linux-android/Dockerfile @@ -9,7 +9,7 @@ RUN dpkg --add-architecture i386 && \ python \ unzip \ expect \ - openjdk-11-jre \ + openjdk-8-jre \ libstdc++6:i386 \ libpulse0 \ gcc \ From e42b1edbdd5a2ae0f67e78dfa3ada12d99122e41 Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Thu, 16 May 2019 13:29:09 +0200 Subject: [PATCH 02/25] Update FILENAME_MAX, L_tmpnam, MS_*, SYS_ and NFT* Android constants Non-existent constants like SYS_syscalls have been removed --- src/unix/notbsd/android/b64/aarch64.rs | 2 +- src/unix/notbsd/android/mod.rs | 17 ++++++++++------- src/unix/notbsd/emscripten/mod.rs | 3 +++ src/unix/notbsd/linux/mod.rs | 3 +++ src/unix/notbsd/mod.rs | 2 -- 5 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/unix/notbsd/android/b64/aarch64.rs b/src/unix/notbsd/android/b64/aarch64.rs index 44dfee6404da7..94b7959b3bd45 100644 --- a/src/unix/notbsd/android/b64/aarch64.rs +++ b/src/unix/notbsd/android/b64/aarch64.rs @@ -322,4 +322,4 @@ pub const SYS_pwritev2: ::c_long = 287; pub const SYS_pkey_mprotect: ::c_long = 288; pub const SYS_pkey_alloc: ::c_long = 289; pub const SYS_pkey_free: ::c_long = 290; -pub const SYS_syscalls: ::c_long = 291; +pub const SYS_syscalls: ::c_long = 292; diff --git a/src/unix/notbsd/android/mod.rs b/src/unix/notbsd/android/mod.rs index 46dd6092402a1..ed5c44163a56f 100644 --- a/src/unix/notbsd/android/mod.rs +++ b/src/unix/notbsd/android/mod.rs @@ -547,6 +547,9 @@ cfg_if! { } } +pub const MS_NOUSER: ::c_ulong = 0xffffffff80000000; +pub const MS_RMT_MASK: ::c_ulong = 0x02800051; + pub const O_TRUNC: ::c_int = 512; pub const O_CLOEXEC: ::c_int = 0x80000; pub const O_PATH: ::c_int = 0o10000000; @@ -582,11 +585,11 @@ pub const EFD_CLOEXEC: ::c_int = 0x80000; pub const USER_PROCESS: ::c_short = 7; pub const BUFSIZ: ::c_uint = 1024; -pub const FILENAME_MAX: ::c_uint = 1024; +pub const FILENAME_MAX: ::c_uint = 4096; pub const FOPEN_MAX: ::c_uint = 20; pub const POSIX_FADV_DONTNEED: ::c_int = 4; pub const POSIX_FADV_NOREUSE: ::c_int = 5; -pub const L_tmpnam: ::c_uint = 1024; +pub const L_tmpnam: ::c_uint = 4096; pub const TMP_MAX: ::c_uint = 308915776; pub const _PC_LINK_MAX: ::c_int = 1; pub const _PC_MAX_CANON: ::c_int = 2; @@ -1459,10 +1462,10 @@ pub const NF_IP6_PRI_CONNTRACK_HELPER: ::c_int = 300; pub const NF_IP6_PRI_LAST: ::c_int = ::INT_MAX; // linux/netfilter/nf_tables.h -pub const NFT_TABLE_MAXNAMELEN: ::c_int = 32; -pub const NFT_CHAIN_MAXNAMELEN: ::c_int = 32; -pub const NFT_SET_MAXNAMELEN: ::c_int = 32; -pub const NFT_OBJ_MAXNAMELEN: ::c_int = 32; +pub const NFT_TABLE_MAXNAMELEN: ::c_int = 256; +pub const NFT_CHAIN_MAXNAMELEN: ::c_int = 256; +pub const NFT_SET_MAXNAMELEN: ::c_int = 256; +pub const NFT_OBJ_MAXNAMELEN: ::c_int = 256; pub const NFT_USERDATA_MAXLEN: ::c_int = 256; pub const NFT_REG_VERDICT: ::c_int = 0; @@ -1519,7 +1522,7 @@ pub const NFT_MSG_NEWOBJ: ::c_int = 18; pub const NFT_MSG_GETOBJ: ::c_int = 19; pub const NFT_MSG_DELOBJ: ::c_int = 20; pub const NFT_MSG_GETOBJ_RESET: ::c_int = 21; -pub const NFT_MSG_MAX: ::c_int = 22; +pub const NFT_MSG_MAX: ::c_int = 25; pub const NFT_SET_ANONYMOUS: ::c_int = 0x1; pub const NFT_SET_CONSTANT: ::c_int = 0x2; diff --git a/src/unix/notbsd/emscripten/mod.rs b/src/unix/notbsd/emscripten/mod.rs index 8521d5dc4cb84..32c9583e133eb 100644 --- a/src/unix/notbsd/emscripten/mod.rs +++ b/src/unix/notbsd/emscripten/mod.rs @@ -573,6 +573,9 @@ cfg_if! { } } +pub const MS_NOUSER: ::c_ulong = 0x80000000; +pub const MS_RMT_MASK: ::c_ulong = 0x800051; + pub const ABDAY_1: ::nl_item = 0x20000; pub const ABDAY_2: ::nl_item = 0x20001; pub const ABDAY_3: ::nl_item = 0x20002; diff --git a/src/unix/notbsd/linux/mod.rs b/src/unix/notbsd/linux/mod.rs index 2419a41d4c4c4..71e2c37629ae9 100644 --- a/src/unix/notbsd/linux/mod.rs +++ b/src/unix/notbsd/linux/mod.rs @@ -849,6 +849,9 @@ pub const _PC_ALLOC_SIZE_MIN: ::c_int = 18; pub const _PC_SYMLINK_MAX: ::c_int = 19; pub const _PC_2_SYMLINKS: ::c_int = 20; +pub const MS_NOUSER: ::c_ulong = 0x80000000; +pub const MS_RMT_MASK: ::c_ulong = 0x800051; + pub const _SC_ARG_MAX: ::c_int = 0; pub const _SC_CHILD_MAX: ::c_int = 1; pub const _SC_CLK_TCK: ::c_int = 2; diff --git a/src/unix/notbsd/mod.rs b/src/unix/notbsd/mod.rs index 6b8adba4e74ea..8919eff91f637 100644 --- a/src/unix/notbsd/mod.rs +++ b/src/unix/notbsd/mod.rs @@ -580,10 +580,8 @@ pub const MS_KERNMOUNT: ::c_ulong = 0x400000; pub const MS_I_VERSION: ::c_ulong = 0x800000; pub const MS_STRICTATIME: ::c_ulong = 0x1000000; pub const MS_ACTIVE: ::c_ulong = 0x40000000; -pub const MS_NOUSER: ::c_ulong = 0x80000000; pub const MS_MGC_VAL: ::c_ulong = 0xc0ed0000; pub const MS_MGC_MSK: ::c_ulong = 0xffff0000; -pub const MS_RMT_MASK: ::c_ulong = 0x800051; pub const EPERM: ::c_int = 1; pub const ENOENT: ::c_int = 2; From a59ea44cebafc7113a4d5d0790eb92de2325fb23 Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Thu, 16 May 2019 12:48:21 +0200 Subject: [PATCH 03/25] [breaking change] __sched_cpucount changed pointer mutability on x86_64-android --- src/unix/notbsd/android/mod.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/unix/notbsd/android/mod.rs b/src/unix/notbsd/android/mod.rs index ed5c44163a56f..51a2cafd9f99a 100644 --- a/src/unix/notbsd/android/mod.rs +++ b/src/unix/notbsd/android/mod.rs @@ -1951,7 +1951,8 @@ extern { pub fn setpriority(which: ::c_int, who: ::c_int, prio: ::c_int) -> ::c_int; pub fn __sched_cpualloc(count: ::size_t) -> *mut ::cpu_set_t; pub fn __sched_cpufree(set: *mut ::cpu_set_t); - pub fn __sched_cpucount(setsize: ::size_t, set: *mut cpu_set_t) -> ::c_int; + pub fn __sched_cpucount(setsize: ::size_t, + set: *const cpu_set_t) -> ::c_int; pub fn sched_getcpu() -> ::c_int; pub fn utmpname(name: *const ::c_char) -> ::c_int; From 841b3eb01644283c3c41ac1d1a2ddcec141f15f2 Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Thu, 16 May 2019 12:49:40 +0200 Subject: [PATCH 04/25] [breaking change] sigaction.sa_flags changed signedness on x86_64-android --- src/unix/notbsd/android/b64/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/unix/notbsd/android/b64/mod.rs b/src/unix/notbsd/android/b64/mod.rs index 46becc53d4d38..eb10c6384e503 100644 --- a/src/unix/notbsd/android/b64/mod.rs +++ b/src/unix/notbsd/android/b64/mod.rs @@ -13,7 +13,7 @@ s! { } pub struct sigaction { - pub sa_flags: ::c_uint, + pub sa_flags: ::c_int, pub sa_sigaction: ::sighandler_t, pub sa_mask: ::sigset_t, pub sa_restorer: ::Option, From 91ea0b21a374d1feecb36f41e6a1372040e6c8d4 Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Thu, 16 May 2019 15:36:14 +0200 Subject: [PATCH 05/25] [breaking change] sigaction.sa_flags changed from c_ulong to c_int on 32-bit Android --- src/unix/notbsd/android/b32/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/unix/notbsd/android/b32/mod.rs b/src/unix/notbsd/android/b32/mod.rs index a8cc51b2215c8..f2ff9492ddd9e 100644 --- a/src/unix/notbsd/android/b32/mod.rs +++ b/src/unix/notbsd/android/b32/mod.rs @@ -13,7 +13,7 @@ s! { pub struct sigaction { pub sa_sigaction: ::sighandler_t, pub sa_mask: ::sigset_t, - pub sa_flags: ::c_ulong, + pub sa_flags: ::c_int, pub sa_restorer: ::Option, } From eea0102308d5676919e8b3b4381eab69498d5fe5 Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Wed, 22 May 2019 10:46:57 +0200 Subject: [PATCH 06/25] Enable more tests on Android --- libc-test/build.rs | 182 +++++++++------------------------------------ 1 file changed, 37 insertions(+), 145 deletions(-) diff --git a/libc-test/build.rs b/libc-test/build.rs index 526c8a82b25ca..af19881210efc 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -1222,14 +1222,6 @@ fn test_android(target: &str) { let mut cfg = ctest::TestGenerator::new(); cfg.define("_GNU_SOURCE", None); - // FIXME: still necessary? - cfg.flag("-Wno-deprecated-declarations"); - - // Android doesn't actually have in_port_t but it's much easier if we - // provide one for us to test against - // FIXME: still necessary? - cfg.define("in_port_t", Some("uint16_t")); - headers! { cfg: "arpa/inet.h", "asm/mman.h", @@ -1296,6 +1288,7 @@ fn test_android(target: &str) { "sys/personality.h", "sys/prctl.h", "sys/ptrace.h", + "sys/random.h", "sys/reboot.h", "sys/resource.h", "sys/sendfile.h", @@ -1313,6 +1306,7 @@ fn test_android(target: &str) { "sys/un.h", "sys/utsname.h", "sys/vfs.h", + "sys/xattr.h", "sys/wait.h", "syslog.h", "termios.h", @@ -1329,6 +1323,7 @@ fn test_android(target: &str) { // generate the error 'Your time_t is already 64-bit' cfg.header("time64.h"); } + if x86 { cfg.header("sys/reg.h"); } @@ -1336,11 +1331,7 @@ fn test_android(target: &str) { cfg.type_name(move |ty, is_struct, is_union| { match ty { // Just pass all these through, no need for a "struct" prefix - // FIXME: still required ? - "FILE" | "fd_set" | "Dl_info" | "DIR" | "Elf32_Phdr" - | "Elf64_Phdr" | "Elf32_Shdr" | "Elf64_Shdr" | "Elf32_Sym" - | "Elf64_Sym" | "Elf32_Ehdr" | "Elf64_Ehdr" | "Elf32_Chdr" - | "Elf64_Chdr" => ty.to_string(), + "FILE" | "fd_set" | "Dl_info" => ty.to_string(), t if is_union => format!("union {}", t), @@ -1360,8 +1351,6 @@ fn test_android(target: &str) { s if s.ends_with("_nsec") && struct_.starts_with("stat") => { s.to_string() } - // FIXME: still necessary? - "u64" if struct_ == "epoll_event" => "data.u64".to_string(), s => s.to_string(), } }); @@ -1377,72 +1366,19 @@ fn test_android(target: &str) { cfg.skip_struct(move |ty| { match ty { - // This is actually a union, not a struct - // FIXME: still necessary - "sigval" => true, - - // These structs have changed since unified headers in NDK r14b. - // `st_atime` and `st_atime_nsec` have changed sign. - // FIXME: unskip it for next major release - "stat" | "stat64" => true, - // These are tested as part of the linux_fcntl tests since there are // header conflicts when including them with all the other structs. - // FIXME: still necessary "termios2" => true, _ => false, } }); - cfg.skip_signededness(move |c| { - match c { - // FIXME: still necessary? - "LARGE_INTEGER" | "float" | "double" => true, - // FIXME: still necessary? - n if n.starts_with("pthread") => true, - _ => false, - } - }); - cfg.skip_const(move |name| { match name { - // FIXME: still necessary? - "SIG_DFL" | "SIG_ERR" | "SIG_IGN" => true, // sighandler_t weirdness - // FIXME: still necessary? - "SIGUNUSED" => true, // removed in glibc 2.26 - - // weird signed extension or something like that? - // FIXME: still necessary? - "MS_NOUSER" => true, - // FIXME: still necessary? - "MS_RMT_MASK" => true, // updated in glibc 2.22 and musl 1.1.13 - - // Android uses old kernel headers - // These are constants used in getrandom syscall - // FIXME: still necessary? - "GRND_NONBLOCK" | "GRND_RANDOM" => true, - - // Defined by libattr not libc on linux (hard to test). - // See constant definition for more details. - // FIXME: still necessary? + // FIXME: deprecated: not available in any header + // See: https://github.com/rust-lang/libc/issues/1356 "ENOATTR" => true, - - // FIXME: still necessary? - "BOTHER" => true, - - // MFD_HUGETLB is not available in some older libc versions on the CI builders. On the - // x86_64 and i686 builders it seems to be available for all targets, so at least test - // it there. - // FIXME: still necessary? - "MFD_HUGETLB" => true, - - // These change all the time from release to release of linux - // distros, let's just not bother trying to verify them. They - // shouldn't be used in code anyway... - // FIXME: still necessary? - "AF_MAX" | "PF_MAX" => true, - _ => false, } }); @@ -1461,9 +1397,6 @@ fn test_android(target: &str) { // FIXME: still necessary? "getdtablesize" => true, - // FIXME: still necessary? - "dlerror" => true, // const-ness is added - // Apparently the NDK doesn't have this defined on android, but // it's in a header file? // FIXME: still necessary? @@ -1474,17 +1407,6 @@ fn test_android(target: &str) { // FIXME: still necessary? "res_init" => true, - // Definition of those functions as changed since unified headers from NDK r14b - // These changes imply some API breaking changes but are still ABI compatible. - // We can wait for the next major release to be compliant with the new API. - // FIXME: unskip these for next major release - "strerror_r" | "madvise" | "msync" | "mprotect" | "recvfrom" | "getpriority" | - "setpriority" | "personality" => true, - // In Android 64 bits, these functions have been fixed since unified headers. - // Ignore these until next major version. - "bind" | "writev" | "readv" | "sendmsg" | "recvmsg" - if target_pointer_width == 64 => true, - _ => false, } }); @@ -1525,40 +1447,12 @@ fn test_android(target: &str) { field == "ssi_arch")) }); - // FIXME: remove - cfg.fn_cname(move |name, _cname| name.to_string()); - cfg.generate("../src/lib.rs", "main.rs"); // On Android also generate another script for testing linux/fcntl // declarations. These cannot be tested normally because including both // `linux/fcntl.h` and `fcntl.h` fails. - // - // FIXME: is still necessary? - let mut cfg = ctest::TestGenerator::new(); - cfg.skip_type(|_| true) - .skip_fn(|_| true) - .skip_static(|_| true); - cfg.header("linux/fcntl.h"); - cfg.header("net/if.h"); - cfg.header("linux/if.h"); - cfg.header("linux/quota.h"); - cfg.header("asm/termbits.h"); - cfg.skip_const(move |name| match name { - "F_CANCELLK" | "F_ADD_SEALS" | "F_GET_SEALS" => false, - "F_SEAL_SEAL" | "F_SEAL_SHRINK" | "F_SEAL_GROW" | "F_SEAL_WRITE" => { - false - } - "BOTHER" => false, - _ => true, - }); - cfg.skip_struct(|s| s != "termios2"); - cfg.type_name(move |ty, is_struct, is_union| match ty { - t if is_struct => format!("struct {}", t), - t if is_union => format!("union {}", t), - t => t.to_string(), - }); - cfg.generate("../src/lib.rs", "linux_fcntl.rs"); + test_linux_termios2(); } fn test_freebsd(target: &str) { @@ -2774,38 +2668,7 @@ fn test_linux(target: &str) { // On Linux also generate another script for testing linux/fcntl declarations. // These cannot be tested normally because including both `linux/fcntl.h` and `fcntl.h` // fails on a lot of platforms. - let mut cfg = ctest::TestGenerator::new(); - cfg.skip_type(|_| true) - .skip_fn(|_| true) - .skip_static(|_| true); - // musl defines these directly in `fcntl.h` - if musl { - cfg.header("fcntl.h"); - } else { - cfg.header("linux/fcntl.h"); - } - if !musl { - cfg.header("net/if.h"); - cfg.header("linux/if.h"); - } - cfg.header("linux/quota.h"); - cfg.header("asm/termbits.h"); - cfg.skip_const(move |name| match name { - "F_CANCELLK" | "F_ADD_SEALS" | "F_GET_SEALS" => false, - "F_SEAL_SEAL" | "F_SEAL_SHRINK" | "F_SEAL_GROW" | "F_SEAL_WRITE" => { - false - } - "QFMT_VFS_OLD" | "QFMT_VFS_V0" | "QFMT_VFS_V1" if mips => false, - "BOTHER" => false, - _ => true, - }); - cfg.skip_struct(|s| s != "termios2"); - cfg.type_name(move |ty, is_struct, is_union| match ty { - t if is_struct => format!("struct {}", t), - t if is_union => format!("union {}", t), - t => t.to_string(), - }); - cfg.generate("../src/lib.rs", "linux_fcntl.rs"); + test_linux_termios2(); // Test Elf64_Phdr and Elf32_Phdr // These types have a field called `p_type`, but including @@ -2827,3 +2690,32 @@ fn test_linux(target: &str) { cfg.header("elf.h"); cfg.generate("../src/lib.rs", "linux_elf.rs"); } + +fn test_linux_termios2() { + let mut cfg = ctest::TestGenerator::new(); + cfg.skip_type(|_| true) + .skip_fn(|_| true) + .skip_static(|_| true); + headers! { + cfg: + "linux/fcntl.h", + "net/if.h", + "linux/if.h", + "linux/quota.h", + "asm/termbits.h" + } + cfg.skip_const(move |name| match name { + "F_CANCELLK" | "F_ADD_SEALS" | "F_GET_SEALS" => false, + "F_SEAL_SEAL" | "F_SEAL_SHRINK" | "F_SEAL_GROW" | "F_SEAL_WRITE" => { + false + } + _ => true, + }); + cfg.skip_struct(|s| s != "termios2"); + cfg.type_name(move |ty, is_struct, is_union| match ty { + t if is_struct => format!("struct {}", t), + t if is_union => format!("union {}", t), + t => t.to_string(), + }); + cfg.generate("../src/lib.rs", "linux_fcntl.rs"); +} From 4774fc1c9fec44d49ebe763eadc87f00d3425d9d Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Wed, 22 May 2019 13:34:02 +0200 Subject: [PATCH 07/25] Deprecate ENOATTR on Linux and Android --- libc-test/build.rs | 6 ++++++ src/unix/notbsd/android/mod.rs | 5 ++++- src/unix/notbsd/linux/mod.rs | 7 ++++--- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/libc-test/build.rs b/libc-test/build.rs index af19881210efc..5d915e13412fd 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -1379,6 +1379,12 @@ fn test_android(target: &str) { // FIXME: deprecated: not available in any header // See: https://github.com/rust-lang/libc/issues/1356 "ENOATTR" => true, + + // FIXME: still necessary? + "SIG_DFL" | "SIG_ERR" | "SIG_IGN" => true, // sighandler_t weirdness + // FIXME: still necessary? + "SIGUNUSED" => true, // removed in glibc 2.26 + _ => false, } }); diff --git a/src/unix/notbsd/android/mod.rs b/src/unix/notbsd/android/mod.rs index 51a2cafd9f99a..b6b67842905cc 100644 --- a/src/unix/notbsd/android/mod.rs +++ b/src/unix/notbsd/android/mod.rs @@ -1792,7 +1792,10 @@ pub const SIOCSIFMAP: ::c_ulong = 0x00008971; pub const MODULE_INIT_IGNORE_MODVERSIONS: ::c_uint = 0x0001; pub const MODULE_INIT_IGNORE_VERMAGIC: ::c_uint = 0x0002; -// Similarity to Linux it's not used but defined for compatibility. +#[deprecated( + since = "0.2.55", + note = "ENOATTR is not available on Android; use ENODATA instead" +)] pub const ENOATTR: ::c_int = ::ENODATA; // linux/if_alg.h diff --git a/src/unix/notbsd/linux/mod.rs b/src/unix/notbsd/linux/mod.rs index 71e2c37629ae9..a76f7a0283cbb 100644 --- a/src/unix/notbsd/linux/mod.rs +++ b/src/unix/notbsd/linux/mod.rs @@ -1409,9 +1409,10 @@ pub const FALLOC_FL_ZERO_RANGE: ::c_int = 0x10; pub const FALLOC_FL_INSERT_RANGE: ::c_int = 0x20; pub const FALLOC_FL_UNSHARE_RANGE: ::c_int = 0x40; -// On Linux, libc doesn't define this constant, libattr does instead. -// We still define it for Linux as it's defined by libc on other platforms, -// and it's mentioned in the man pages for getxattr and setxattr. +#[deprecated( + since = "0.2.55", + note = "ENOATTR is not available on Linux; use ENODATA instead" +)] pub const ENOATTR: ::c_int = ::ENODATA; pub const SO_ORIGINAL_DST: ::c_int = 80; From 003c04d95281582aa8cf7b69554448cc9380c112 Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Wed, 22 May 2019 18:11:21 +0200 Subject: [PATCH 08/25] [breaking change] fix types of stat/stat64 structs, atime/mtime/ctime fields on Android --- libc-test/build.rs | 1 + src/unix/notbsd/android/b32/mod.rs | 24 ++++++++++++------------ src/unix/notbsd/android/b64/aarch64.rs | 12 ++++++------ src/unix/notbsd/android/b64/x86_64.rs | 24 ++++++++++++------------ 4 files changed, 31 insertions(+), 30 deletions(-) diff --git a/libc-test/build.rs b/libc-test/build.rs index 5d915e13412fd..4fd21721b97a4 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -1351,6 +1351,7 @@ fn test_android(target: &str) { s if s.ends_with("_nsec") && struct_.starts_with("stat") => { s.to_string() } + "u64" if struct_ == "epoll_event" => "data.u64".to_string(), s => s.to_string(), } }); diff --git a/src/unix/notbsd/android/b32/mod.rs b/src/unix/notbsd/android/b32/mod.rs index f2ff9492ddd9e..e0a0d7e67cf42 100644 --- a/src/unix/notbsd/android/b32/mod.rs +++ b/src/unix/notbsd/android/b32/mod.rs @@ -35,12 +35,12 @@ s! { pub st_size: ::c_longlong, pub st_blksize: ::blksize_t, pub st_blocks: ::c_ulonglong, - pub st_atime: ::c_ulong, - pub st_atime_nsec: ::c_ulong, - pub st_mtime: ::c_ulong, - pub st_mtime_nsec: ::c_ulong, - pub st_ctime: ::c_ulong, - pub st_ctime_nsec: ::c_ulong, + pub st_atime: ::c_long, + pub st_atime_nsec: ::c_long, + pub st_mtime: ::c_long, + pub st_mtime_nsec: ::c_long, + pub st_ctime: ::c_long, + pub st_ctime_nsec: ::c_long, pub st_ino: ::c_ulonglong, } @@ -57,12 +57,12 @@ s! { pub st_size: ::c_longlong, pub st_blksize: ::blksize_t, pub st_blocks: ::c_ulonglong, - pub st_atime: ::c_ulong, - pub st_atime_nsec: ::c_ulong, - pub st_mtime: ::c_ulong, - pub st_mtime_nsec: ::c_ulong, - pub st_ctime: ::c_ulong, - pub st_ctime_nsec: ::c_ulong, + pub st_atime: ::c_long, + pub st_atime_nsec: ::c_long, + pub st_mtime: ::c_long, + pub st_mtime_nsec: ::c_long, + pub st_ctime: ::c_long, + pub st_ctime_nsec: ::c_long, pub st_ino: ::c_ulonglong, } diff --git a/src/unix/notbsd/android/b64/aarch64.rs b/src/unix/notbsd/android/b64/aarch64.rs index 94b7959b3bd45..cb1c81b260579 100644 --- a/src/unix/notbsd/android/b64/aarch64.rs +++ b/src/unix/notbsd/android/b64/aarch64.rs @@ -16,11 +16,11 @@ s! { __pad2: ::c_int, pub st_blocks: ::c_long, pub st_atime: ::time_t, - pub st_atime_nsec: ::c_ulong, + pub st_atime_nsec: ::c_long, pub st_mtime: ::time_t, - pub st_mtime_nsec: ::c_ulong, + pub st_mtime_nsec: ::c_long, pub st_ctime: ::time_t, - pub st_ctime_nsec: ::c_ulong, + pub st_ctime_nsec: ::c_long, __unused4: ::c_uint, __unused5: ::c_uint, } @@ -39,11 +39,11 @@ s! { __pad2: ::c_int, pub st_blocks: ::c_long, pub st_atime: ::time_t, - pub st_atime_nsec: ::c_ulong, + pub st_atime_nsec: ::c_long, pub st_mtime: ::time_t, - pub st_mtime_nsec: ::c_ulong, + pub st_mtime_nsec: ::c_long, pub st_ctime: ::time_t, - pub st_ctime_nsec: ::c_ulong, + pub st_ctime_nsec: ::c_long, __unused4: ::c_uint, __unused5: ::c_uint, } diff --git a/src/unix/notbsd/android/b64/x86_64.rs b/src/unix/notbsd/android/b64/x86_64.rs index c813e7da32077..2ab6080a6d63f 100644 --- a/src/unix/notbsd/android/b64/x86_64.rs +++ b/src/unix/notbsd/android/b64/x86_64.rs @@ -13,12 +13,12 @@ s! { pub st_size: ::off64_t, pub st_blksize: ::c_long, pub st_blocks: ::c_long, - pub st_atime: ::c_ulong, - pub st_atime_nsec: ::c_ulong, - pub st_mtime: ::c_ulong, - pub st_mtime_nsec: ::c_ulong, - pub st_ctime: ::c_ulong, - pub st_ctime_nsec: ::c_ulong, + pub st_atime: ::c_long, + pub st_atime_nsec: ::c_long, + pub st_mtime: ::c_long, + pub st_mtime_nsec: ::c_long, + pub st_ctime: ::c_long, + pub st_ctime_nsec: ::c_long, __unused: [::c_long; 3], } @@ -33,12 +33,12 @@ s! { pub st_size: ::off64_t, pub st_blksize: ::c_long, pub st_blocks: ::c_long, - pub st_atime: ::c_ulong, - pub st_atime_nsec: ::c_ulong, - pub st_mtime: ::c_ulong, - pub st_mtime_nsec: ::c_ulong, - pub st_ctime: ::c_ulong, - pub st_ctime_nsec: ::c_ulong, + pub st_atime: ::c_long, + pub st_atime_nsec: ::c_long, + pub st_mtime: ::c_long, + pub st_mtime_nsec: ::c_long, + pub st_ctime: ::c_long, + pub st_ctime_nsec: ::c_long, __unused: [::c_long; 3], } } From 61c9de80b4fe75c53fc8a84b2c3030da267767f1 Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Wed, 22 May 2019 18:51:50 +0200 Subject: [PATCH 09/25] [breaking change] pthread_key_t is signed on Android --- src/unix/notbsd/android/mod.rs | 1 + src/unix/notbsd/emscripten/mod.rs | 1 + src/unix/notbsd/linux/mod.rs | 1 + src/unix/notbsd/mod.rs | 1 - 4 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/unix/notbsd/android/mod.rs b/src/unix/notbsd/android/mod.rs index b6b67842905cc..9305377065acd 100644 --- a/src/unix/notbsd/android/mod.rs +++ b/src/unix/notbsd/android/mod.rs @@ -12,6 +12,7 @@ pub type pthread_t = ::c_long; pub type pthread_mutexattr_t = ::c_long; pub type pthread_rwlockattr_t = ::c_long; pub type pthread_condattr_t = ::c_long; +pub type pthread_key_t = ::c_int; pub type fsfilcnt_t = ::c_ulong; pub type fsblkcnt_t = ::c_ulong; pub type nfds_t = ::c_uint; diff --git a/src/unix/notbsd/emscripten/mod.rs b/src/unix/notbsd/emscripten/mod.rs index 32c9583e133eb..8db46795df4e4 100644 --- a/src/unix/notbsd/emscripten/mod.rs +++ b/src/unix/notbsd/emscripten/mod.rs @@ -17,6 +17,7 @@ pub type nfds_t = ::c_ulong; pub type nl_item = ::c_int; pub type idtype_t = ::c_uint; pub type loff_t = i32; +pub type pthread_key_t = ::c_uint; pub type clock_t = c_long; pub type time_t = c_long; diff --git a/src/unix/notbsd/linux/mod.rs b/src/unix/notbsd/linux/mod.rs index a76f7a0283cbb..6813a85457737 100644 --- a/src/unix/notbsd/linux/mod.rs +++ b/src/unix/notbsd/linux/mod.rs @@ -14,6 +14,7 @@ pub type nfds_t = ::c_ulong; pub type nl_item = ::c_int; pub type idtype_t = ::c_uint; pub type loff_t = ::c_longlong; +pub type pthread_key_t = ::c_uint; pub type __u8 = ::c_uchar; pub type __u16 = ::c_ushort; diff --git a/src/unix/notbsd/mod.rs b/src/unix/notbsd/mod.rs index 8919eff91f637..ea1e7c69bb919 100644 --- a/src/unix/notbsd/mod.rs +++ b/src/unix/notbsd/mod.rs @@ -1,5 +1,4 @@ pub type sa_family_t = u16; -pub type pthread_key_t = ::c_uint; pub type speed_t = ::c_uint; pub type tcflag_t = ::c_uint; pub type clockid_t = ::c_int; From 8b02725e340e580acc472bfa6cbcbc9c6cdbbf2f Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Thu, 23 May 2019 11:29:53 +0200 Subject: [PATCH 10/25] [breaking change] madvise takes a mut pointer on Android --- src/unix/notbsd/android/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/unix/notbsd/android/mod.rs b/src/unix/notbsd/android/mod.rs index 9305377065acd..1f4b171cfbf3e 100644 --- a/src/unix/notbsd/android/mod.rs +++ b/src/unix/notbsd/android/mod.rs @@ -1933,7 +1933,7 @@ extern { extern { pub fn gettimeofday(tp: *mut ::timeval, tz: *mut ::timezone) -> ::c_int; - pub fn madvise(addr: *const ::c_void, len: ::size_t, advice: ::c_int) + pub fn madvise(addr: *mut ::c_void, len: ::size_t, advice: ::c_int) -> ::c_int; pub fn ioctl(fd: ::c_int, request: ::c_int, ...) -> ::c_int; pub fn msync(addr: *const ::c_void, len: ::size_t, From 5016f87a1816e24b96920d8846689b99f4e7546a Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Thu, 23 May 2019 11:30:29 +0200 Subject: [PATCH 11/25] [breaking change] msync takes a mut pointer on Android --- src/unix/notbsd/android/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/unix/notbsd/android/mod.rs b/src/unix/notbsd/android/mod.rs index 1f4b171cfbf3e..2dc1e386b872b 100644 --- a/src/unix/notbsd/android/mod.rs +++ b/src/unix/notbsd/android/mod.rs @@ -1936,7 +1936,7 @@ extern { pub fn madvise(addr: *mut ::c_void, len: ::size_t, advice: ::c_int) -> ::c_int; pub fn ioctl(fd: ::c_int, request: ::c_int, ...) -> ::c_int; - pub fn msync(addr: *const ::c_void, len: ::size_t, + pub fn msync(addr: *mut ::c_void, len: ::size_t, flags: ::c_int) -> ::c_int; pub fn mprotect(addr: *const ::c_void, len: ::size_t, prot: ::c_int) -> ::c_int; From 918d371af0001070037e60a5c4f463fc6a19cf72 Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Thu, 23 May 2019 11:31:01 +0200 Subject: [PATCH 12/25] [breaking change] mprotect takes a mut pointer on Android --- src/unix/notbsd/android/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/unix/notbsd/android/mod.rs b/src/unix/notbsd/android/mod.rs index 2dc1e386b872b..e614427080d73 100644 --- a/src/unix/notbsd/android/mod.rs +++ b/src/unix/notbsd/android/mod.rs @@ -1938,7 +1938,7 @@ extern { pub fn ioctl(fd: ::c_int, request: ::c_int, ...) -> ::c_int; pub fn msync(addr: *mut ::c_void, len: ::size_t, flags: ::c_int) -> ::c_int; - pub fn mprotect(addr: *const ::c_void, len: ::size_t, prot: ::c_int) + pub fn mprotect(addr: *mut ::c_void, len: ::size_t, prot: ::c_int) -> ::c_int; pub fn recvfrom(socket: ::c_int, buf: *mut ::c_void, len: ::size_t, flags: ::c_int, addr: *const ::sockaddr, From ebe64f1e25c811b6adb64f8c7ba212bdf826374f Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Thu, 23 May 2019 11:32:07 +0200 Subject: [PATCH 13/25] [breaking change] recvfrom takes a mut pointer on Android --- src/unix/notbsd/android/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/unix/notbsd/android/mod.rs b/src/unix/notbsd/android/mod.rs index e614427080d73..ac58604a91a05 100644 --- a/src/unix/notbsd/android/mod.rs +++ b/src/unix/notbsd/android/mod.rs @@ -1941,7 +1941,7 @@ extern { pub fn mprotect(addr: *mut ::c_void, len: ::size_t, prot: ::c_int) -> ::c_int; pub fn recvfrom(socket: ::c_int, buf: *mut ::c_void, len: ::size_t, - flags: ::c_int, addr: *const ::sockaddr, + flags: ::c_int, addr: *mut ::sockaddr, addrlen: *mut ::socklen_t) -> ::ssize_t; pub fn getnameinfo(sa: *const ::sockaddr, salen: ::socklen_t, From 7d5e632d36fea980a7fadaafd279c4604978cad7 Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Thu, 23 May 2019 11:34:16 +0200 Subject: [PATCH 14/25] [breaking change] set/getpriority who argument is of type id_t on Android --- src/unix/notbsd/android/mod.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/unix/notbsd/android/mod.rs b/src/unix/notbsd/android/mod.rs index ac58604a91a05..b3885aba3d244 100644 --- a/src/unix/notbsd/android/mod.rs +++ b/src/unix/notbsd/android/mod.rs @@ -19,6 +19,7 @@ pub type nfds_t = ::c_uint; pub type rlim_t = ::c_ulong; pub type dev_t = ::c_ulong; pub type ino_t = ::c_ulong; +pub type id_t = ::c_uint; pub type __CPU_BITTYPE = ::c_ulong; pub type idtype_t = ::c_int; pub type loff_t = ::c_longlong; @@ -1951,8 +1952,8 @@ extern { sevlen: ::size_t, flags: ::c_int) -> ::c_int; pub fn ptrace(request: ::c_int, ...) -> ::c_long; - pub fn getpriority(which: ::c_int, who: ::c_int) -> ::c_int; - pub fn setpriority(which: ::c_int, who: ::c_int, prio: ::c_int) -> ::c_int; + pub fn getpriority(which: ::c_int, who: ::id_t) -> ::c_int; + pub fn setpriority(which: ::c_int, who: ::id_t, prio: ::c_int) -> ::c_int; pub fn __sched_cpualloc(count: ::size_t) -> *mut ::cpu_set_t; pub fn __sched_cpufree(set: *mut ::cpu_set_t); pub fn __sched_cpucount(setsize: ::size_t, From 46c60fb726d7beba247ba1d4b531fdcf15c2f2f2 Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Thu, 23 May 2019 11:35:24 +0200 Subject: [PATCH 15/25] [breaking change] personality takes a c_uint instead of c_ulong on Android --- src/unix/notbsd/android/mod.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/unix/notbsd/android/mod.rs b/src/unix/notbsd/android/mod.rs index b3885aba3d244..16fd717b9bdc9 100644 --- a/src/unix/notbsd/android/mod.rs +++ b/src/unix/notbsd/android/mod.rs @@ -19,7 +19,6 @@ pub type nfds_t = ::c_uint; pub type rlim_t = ::c_ulong; pub type dev_t = ::c_ulong; pub type ino_t = ::c_ulong; -pub type id_t = ::c_uint; pub type __CPU_BITTYPE = ::c_ulong; pub type idtype_t = ::c_int; pub type loff_t = ::c_longlong; @@ -2020,7 +2019,7 @@ extern { fstype: *const ::c_char, flags: ::c_ulong, data: *const ::c_void) -> ::c_int; - pub fn personality(persona: ::c_ulong) -> ::c_int; + pub fn personality(persona: ::c_uint) -> ::c_int; pub fn prctl(option: ::c_int, ...) -> ::c_int; pub fn sched_getparam(pid: ::pid_t, param: *mut ::sched_param) -> ::c_int; pub fn ppoll(fds: *mut ::pollfd, From d52732581a69752475665f497395985333585110 Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Thu, 23 May 2019 11:28:15 +0200 Subject: [PATCH 16/25] Test strerror_r on Android and Linux --- libc-test/build.rs | 30 ++++++++++++++++++++++++++++-- src/unix/bsd/mod.rs | 2 ++ src/unix/haiku/mod.rs | 3 +++ src/unix/hermit/mod.rs | 3 +++ src/unix/mod.rs | 4 ---- src/unix/newlib/mod.rs | 5 +++++ src/unix/notbsd/android/mod.rs | 3 +++ src/unix/notbsd/emscripten/mod.rs | 3 +++ src/unix/notbsd/linux/mod.rs | 5 +++++ src/unix/redox/mod.rs | 3 +++ src/unix/solarish/mod.rs | 3 +++ src/unix/uclibc/mod.rs | 5 +++++ 12 files changed, 63 insertions(+), 6 deletions(-) diff --git a/libc-test/build.rs b/libc-test/build.rs index 4fd21721b97a4..b20e67a9cf7f0 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -1337,6 +1337,9 @@ fn test_android(target: &str) { t if t.ends_with("_t") => t.to_string(), + // sigval is a struct in Rust, but a union in C: + "sigval" => format!("union sigval"), + // put `struct` in front of all structs:. t if is_struct => format!("struct {}", t), @@ -1400,6 +1403,23 @@ fn test_android(target: &str) { "execvpe" | "fexecve" => true, + // There are two versions of the sterror_r function, see + // + // https://linux.die.net/man/3/strerror_r + // + // An XSI-compliant version provided if: + // + // (_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && ! _GNU_SOURCE + // + // and a GNU specific version provided if _GNU_SOURCE is defined. + // + // libc provides bindings for the XSI-compliant version, which is + // preferred for portable applications. + // + // We skip the test here since here _GNU_SOURCE is defined, and + // test the XSI version below. + "strerror_r" => true, + // not declared in newer android toolchains // FIXME: still necessary? "getdtablesize" => true, @@ -1459,6 +1479,8 @@ fn test_android(target: &str) { // On Android also generate another script for testing linux/fcntl // declarations. These cannot be tested normally because including both // `linux/fcntl.h` and `fcntl.h` fails. + // + // This also tests strerror_r. test_linux_termios2(); } @@ -2701,7 +2723,10 @@ fn test_linux(target: &str) { fn test_linux_termios2() { let mut cfg = ctest::TestGenerator::new(); cfg.skip_type(|_| true) - .skip_fn(|_| true) + .skip_fn(|f| match f { + "strerror_r" => false, + _ => true, + }) .skip_static(|_| true); headers! { cfg: @@ -2709,7 +2734,8 @@ fn test_linux_termios2() { "net/if.h", "linux/if.h", "linux/quota.h", - "asm/termbits.h" + "asm/termbits.h", + "string.h" } cfg.skip_const(move |name| match name { "F_CANCELLK" | "F_ADD_SEALS" | "F_GET_SEALS" => false, diff --git a/src/unix/bsd/mod.rs b/src/unix/bsd/mod.rs index 03c987dd33741..ef92bd5cd4bac 100644 --- a/src/unix/bsd/mod.rs +++ b/src/unix/bsd/mod.rs @@ -488,6 +488,8 @@ f! { } extern { + pub fn strerror_r(errnum: ::c_int, buf: *mut c_char, + buflen: ::size_t) -> ::c_int; pub fn abs(i: ::c_int) -> ::c_int; pub fn atof(s: *const ::c_char) -> ::c_double; pub fn labs(i: ::c_long) -> ::c_long; diff --git a/src/unix/haiku/mod.rs b/src/unix/haiku/mod.rs index 8eb8bffc3da5f..885c83991fce9 100644 --- a/src/unix/haiku/mod.rs +++ b/src/unix/haiku/mod.rs @@ -1209,6 +1209,9 @@ f! { } extern { + pub fn strerror_r(errnum: ::c_int, buf: *mut c_char, + buflen: ::size_t) -> ::c_int; + pub fn abs(i: ::c_int) -> ::c_int; pub fn atof(s: *const ::c_char) -> ::c_double; pub fn labs(i: ::c_long) -> ::c_long; diff --git a/src/unix/hermit/mod.rs b/src/unix/hermit/mod.rs index 583056bac4bda..4c5781163037c 100644 --- a/src/unix/hermit/mod.rs +++ b/src/unix/hermit/mod.rs @@ -964,6 +964,9 @@ f! { } extern { + pub fn strerror_r(errnum: ::c_int, buf: *mut c_char, + buflen: ::size_t) -> ::c_int; + pub fn sem_destroy(sem: *mut sem_t) -> ::c_int; pub fn sem_init(sem: *mut sem_t, pshared: ::c_int, diff --git a/src/unix/mod.rs b/src/unix/mod.rs index b85a27108926f..6240964dd5463 100644 --- a/src/unix/mod.rs +++ b/src/unix/mod.rs @@ -931,10 +931,6 @@ extern { pub fn pthread_rwlockattr_init(attr: *mut pthread_rwlockattr_t) -> ::c_int; pub fn pthread_rwlockattr_destroy(attr: *mut pthread_rwlockattr_t) -> ::c_int; - #[cfg_attr(all(target_os = "linux", not(target_env = "musl")), - link_name = "__xpg_strerror_r")] - pub fn strerror_r(errnum: ::c_int, buf: *mut c_char, - buflen: ::size_t) -> ::c_int; #[cfg_attr(target_os = "illumos", link_name = "__xnet_getsockopt")] pub fn getsockopt(sockfd: ::c_int, diff --git a/src/unix/newlib/mod.rs b/src/unix/newlib/mod.rs index ea52ff560ad93..93798e58b5059 100644 --- a/src/unix/newlib/mod.rs +++ b/src/unix/newlib/mod.rs @@ -598,6 +598,11 @@ f! { } extern { + #[cfg_attr(target_os = "linux", + link_name = "__xpg_strerror_r")] + pub fn strerror_r(errnum: ::c_int, buf: *mut c_char, + buflen: ::size_t) -> ::c_int; + pub fn sem_destroy(sem: *mut sem_t) -> ::c_int; pub fn sem_init(sem: *mut sem_t, pshared: ::c_int, diff --git a/src/unix/notbsd/android/mod.rs b/src/unix/notbsd/android/mod.rs index 16fd717b9bdc9..dda1903657d4f 100644 --- a/src/unix/notbsd/android/mod.rs +++ b/src/unix/notbsd/android/mod.rs @@ -1931,6 +1931,9 @@ extern { } extern { + pub fn strerror_r(errnum: ::c_int, buf: *mut c_char, + buflen: ::size_t) -> ::c_int; + pub fn gettimeofday(tp: *mut ::timeval, tz: *mut ::timezone) -> ::c_int; pub fn madvise(addr: *mut ::c_void, len: ::size_t, advice: ::c_int) diff --git a/src/unix/notbsd/emscripten/mod.rs b/src/unix/notbsd/emscripten/mod.rs index 8db46795df4e4..0a98eafb61e5c 100644 --- a/src/unix/notbsd/emscripten/mod.rs +++ b/src/unix/notbsd/emscripten/mod.rs @@ -1687,6 +1687,9 @@ f! { } extern { + pub fn strerror_r(errnum: ::c_int, buf: *mut c_char, + buflen: ::size_t) -> ::c_int; + pub fn abs(i: ::c_int) -> ::c_int; pub fn atof(s: *const ::c_char) -> ::c_double; pub fn labs(i: ::c_long) -> ::c_long; diff --git a/src/unix/notbsd/linux/mod.rs b/src/unix/notbsd/linux/mod.rs index 6813a85457737..bc39c88b009e7 100644 --- a/src/unix/notbsd/linux/mod.rs +++ b/src/unix/notbsd/linux/mod.rs @@ -1972,6 +1972,11 @@ f! { } extern { + #[cfg_attr(not(target_env = "musl"), + link_name = "__xpg_strerror_r")] + pub fn strerror_r(errnum: ::c_int, buf: *mut c_char, + buflen: ::size_t) -> ::c_int; + pub fn abs(i: ::c_int) -> ::c_int; pub fn atof(s: *const ::c_char) -> ::c_double; pub fn labs(i: ::c_long) -> ::c_long; diff --git a/src/unix/redox/mod.rs b/src/unix/redox/mod.rs index 9f22ca2022345..4131bb9cf32b5 100644 --- a/src/unix/redox/mod.rs +++ b/src/unix/redox/mod.rs @@ -534,6 +534,9 @@ cfg_if! { } extern { + pub fn strerror_r(errnum: ::c_int, buf: *mut c_char, + buflen: ::size_t) -> ::c_int; + // malloc.h pub fn memalign(align: ::size_t, size: ::size_t) -> *mut ::c_void; diff --git a/src/unix/solarish/mod.rs b/src/unix/solarish/mod.rs index 887cfc347bc54..062b2837dbd70 100644 --- a/src/unix/solarish/mod.rs +++ b/src/unix/solarish/mod.rs @@ -1786,6 +1786,9 @@ f! { } extern { + pub fn strerror_r(errnum: ::c_int, buf: *mut c_char, + buflen: ::size_t) -> ::c_int; + pub fn sem_destroy(sem: *mut sem_t) -> ::c_int; pub fn sem_init(sem: *mut sem_t, pshared: ::c_int, diff --git a/src/unix/uclibc/mod.rs b/src/unix/uclibc/mod.rs index 4cb430b15f9c3..9a430a9fa9b99 100644 --- a/src/unix/uclibc/mod.rs +++ b/src/unix/uclibc/mod.rs @@ -1487,6 +1487,11 @@ f! { } extern { + #[cfg_attr(target_os = "linux", + link_name = "__xpg_strerror_r")] + pub fn strerror_r(errnum: ::c_int, buf: *mut c_char, + buflen: ::size_t) -> ::c_int; + pub fn sem_destroy(sem: *mut sem_t) -> ::c_int; pub fn sem_init(sem: *mut sem_t, pshared: ::c_int, From 8c70f498f230c38095f0910a06c7d3e2e3f4432b Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Thu, 23 May 2019 15:09:57 +0200 Subject: [PATCH 17/25] Enable more tests (some related to issue 1272) on Android --- libc-test/build.rs | 40 ++++++++-------------------------------- 1 file changed, 8 insertions(+), 32 deletions(-) diff --git a/libc-test/build.rs b/libc-test/build.rs index b20e67a9cf7f0..616f1dde12303 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -313,6 +313,7 @@ fn test_openbsd(target: &str) { cfg.skip_fn(move |name| { match name { + // FIXME: https://github.com/rust-lang/libc/issues/1272 "execv" | "execve" | "execvp" | "execvpe" => true, // Removed in OpenBSD 6.5 @@ -458,7 +459,7 @@ fn test_windows(target: &str) { cfg.skip_fn(move |name| { match name { - // FIXME: API error: + // FIXME: https://github.com/rust-lang/libc/issues/1272 "execv" | "execve" | "execvp" | "execvpe" => true, _ => false, @@ -873,12 +874,8 @@ fn test_netbsd(target: &str) { cfg.skip_fn(move |name| { match name { - // FIXME: incorrect API - "execv" | - "execve" | - "execvp" | - "execvpe" | - "fexecve" => true, + // FIXME: https://github.com/rust-lang/libc/issues/1272 + "execv" | "execve" | "execvp" => true, "getrlimit" | "getrlimit64" | // non-int in 1st arg "setrlimit" | "setrlimit64" | // non-int in 1st arg @@ -1102,11 +1099,8 @@ fn test_dragonflybsd(target: &str) { cfg.skip_fn(move |name| { // skip those that are manually verified match name { - "execv" | // crazy stuff with const/mut - "execve" | - "execvp" | - "execvpe" | - "fexecve" => true, + // FIXME: https://github.com/rust-lang/libc/issues/1272 + "execv" | "execve" | "execvp" => true, "getrlimit" | "getrlimit64" | // non-int in 1st arg "setrlimit" | "setrlimit64" | // non-int in 1st arg @@ -1396,12 +1390,8 @@ fn test_android(target: &str) { cfg.skip_fn(move |name| { // skip those that are manually verified match name { - // FIXME: still necessary? - "execv" | // crazy stuff with const/mut - "execve" | - "execvp" | - "execvpe" | - "fexecve" => true, + // FIXME: https://github.com/rust-lang/libc/issues/1272 + "execv" | "execve" | "execvp" | "execvpe" | "fexecve" => true, // There are two versions of the sterror_r function, see // @@ -1420,20 +1410,6 @@ fn test_android(target: &str) { // test the XSI version below. "strerror_r" => true, - // not declared in newer android toolchains - // FIXME: still necessary? - "getdtablesize" => true, - - // Apparently the NDK doesn't have this defined on android, but - // it's in a header file? - // FIXME: still necessary? - "endpwent" => true, - - // Apparently res_init exists on Android, but isn't defined in a header: - // https://mail.gnome.org/archives/commits-list/2013-May/msg01329.html - // FIXME: still necessary? - "res_init" => true, - _ => false, } }); From 30c853f59fea8b6660480c2fa3fc7ce40429e99c Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Thu, 23 May 2019 15:13:17 +0200 Subject: [PATCH 18/25] [breaking change] remove __progname --- libc-test/build.rs | 9 --------- src/unix/notbsd/android/mod.rs | 4 ---- 2 files changed, 13 deletions(-) diff --git a/libc-test/build.rs b/libc-test/build.rs index 616f1dde12303..d899810494707 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -1414,15 +1414,6 @@ fn test_android(target: &str) { } }); - cfg.skip_static(move |name| { - match name { - // Internal constant, not declared in any headers. - // FIXME: still necessary - "__progname" => true, - _ => false, - } - }); - // FIXME: still necessary? cfg.skip_field_type(move |struct_, field| { // This is a weird union, don't check the type. diff --git a/src/unix/notbsd/android/mod.rs b/src/unix/notbsd/android/mod.rs index dda1903657d4f..9fda9d6da7ae5 100644 --- a/src/unix/notbsd/android/mod.rs +++ b/src/unix/notbsd/android/mod.rs @@ -1926,10 +1926,6 @@ f! { } } -extern { - static mut __progname: *mut ::c_char; -} - extern { pub fn strerror_r(errnum: ::c_int, buf: *mut c_char, buflen: ::size_t) -> ::c_int; From 1c5a36c488e495dba388903f3e6bfddf34398b6a Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Thu, 23 May 2019 15:33:06 +0200 Subject: [PATCH 19/25] [breaking change] remove getdtablesize - removed in Android API 21 --- src/unix/notbsd/android/mod.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/unix/notbsd/android/mod.rs b/src/unix/notbsd/android/mod.rs index 9fda9d6da7ae5..6fb61ae352c70 100644 --- a/src/unix/notbsd/android/mod.rs +++ b/src/unix/notbsd/android/mod.rs @@ -2070,7 +2070,6 @@ extern { pub fn sigaltstack(ss: *const stack_t, oss: *mut stack_t) -> ::c_int; pub fn sem_close(sem: *mut sem_t) -> ::c_int; - pub fn getdtablesize() -> ::c_int; #[cfg_attr(target_os = "solaris", link_name = "__posix_getgrnam_r")] pub fn getgrnam_r(name: *const ::c_char, grp: *mut ::group, From 3efe23b1c01b8a5d8b26724214da6d36a1ff08da Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Thu, 23 May 2019 15:42:38 +0200 Subject: [PATCH 20/25] Enable more tests on Android --- libc-test/build.rs | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/libc-test/build.rs b/libc-test/build.rs index d899810494707..19cba89ad496a 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -1414,31 +1414,19 @@ fn test_android(target: &str) { } }); - // FIXME: still necessary? cfg.skip_field_type(move |struct_, field| { // This is a weird union, don't check the type. (struct_ == "ifaddrs" && field == "ifa_ifu") || - // sighandler_t type is super weird - (struct_ == "sigaction" && field == "sa_sigaction") || // sigval is actually a union, but we pretend it's a struct - (struct_ == "sigevent" && field == "sigev_value") || - // aio_buf is "volatile void*" and Rust doesn't understand volatile - (struct_ == "aiocb" && field == "aio_buf") + (struct_ == "sigevent" && field == "sigev_value") }); - // FIXME: still necessary? cfg.skip_field(move |struct_, field| { // this is actually a union on linux, so we can't represent it well and // just insert some padding. (struct_ == "siginfo_t" && field == "_pad") || // sigev_notify_thread_id is actually part of a sigev_un union - (struct_ == "sigevent" && field == "sigev_notify_thread_id") || - // signalfd had SIGSYS fields added in Linux 4.18, but no libc release has them yet. - (struct_ == "signalfd_siginfo" && (field == "ssi_addr_lsb" || - field == "_pad2" || - field == "ssi_syscall" || - field == "ssi_call_addr" || - field == "ssi_arch")) + (struct_ == "sigevent" && field == "sigev_notify_thread_id") }); cfg.generate("../src/lib.rs", "main.rs"); From 7f8b946cc2795673ab7ece9e6a2da3233ee1e307 Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Thu, 23 May 2019 16:06:37 +0200 Subject: [PATCH 21/25] Document what is wrong with sighandler_t --- libc-test/build.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/libc-test/build.rs b/libc-test/build.rs index 19cba89ad496a..f5e30bdcd7ab6 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -1348,6 +1348,7 @@ fn test_android(target: &str) { s if s.ends_with("_nsec") && struct_.starts_with("stat") => { s.to_string() } + // FIXME: appears that `epoll_event.data` is an union "u64" if struct_ == "epoll_event" => "data.u64".to_string(), s => s.to_string(), } @@ -1355,8 +1356,8 @@ fn test_android(target: &str) { cfg.skip_type(move |ty| { match ty { - // sighandler_t is crazy across platforms - // FIXME: still necessary? + // FIXME: `sighandler_t` type is incorrect, see: + // https://github.com/rust-lang/libc/issues/1359 "sighandler_t" => true, _ => false, } @@ -1425,8 +1426,15 @@ fn test_android(target: &str) { // this is actually a union on linux, so we can't represent it well and // just insert some padding. (struct_ == "siginfo_t" && field == "_pad") || + // FIXME: `sa_sigaction` has type `sighandler_t` but that type is + // incorrect, see: https://github.com/rust-lang/libc/issues/1359 + (struct_ == "sigaction" && field == "sa_sigaction") || // sigev_notify_thread_id is actually part of a sigev_un union - (struct_ == "sigevent" && field == "sigev_notify_thread_id") + (struct_ == "sigevent" && field == "sigev_notify_thread_id") || + // signalfd had SIGSYS fields added in Android 4.19, but CI does not have that version yet. + (struct_ == "signalfd_siginfo" && (field == "ssi_syscall" || + field == "ssi_call_addr" || + field == "ssi_arch")) }); cfg.generate("../src/lib.rs", "main.rs"); From c37623116d2223a77e82c21edc8ee5c597f86bea Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Thu, 16 May 2019 12:53:44 +0200 Subject: [PATCH 22/25] Add i686-linux-android build job --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 1fa0a8d368699..07530eb55e4d5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -174,6 +174,8 @@ matrix: stage: tier2 - env: TARGET=asmjs-unknown-emscripten stage: tier2 + - env: TARGET=i686-linux-android + stage: tier2 - env: TARGET=i686-unknown-linux-musl stage: tier2 - env: TARGET=mips-unknown-linux-gnu From cc13d7506e9675e8af1466e7074cfe97be1386a6 Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Thu, 23 May 2019 16:33:41 +0200 Subject: [PATCH 23/25] Fix Android build jobs: not allowed to fail anymore --- .travis.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 07530eb55e4d5..3c6cc9429eaf4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -232,9 +232,6 @@ matrix: allow_failures: - # FIXME: android build bots time out irregularly - - env: TARGET=aarch64-linux-android - - env: TARGET=arm-linux-androideabi # FIXME: https://github.com/rust-lang/libc/issues/1226 - env: TARGET=asmjs-unknown-emscripten - env: TARGET=wasm32-unknown-emscripten From ccad8b426cb6c9811f725ea6174152b5b642c06a Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Thu, 23 May 2019 19:09:39 +0200 Subject: [PATCH 24/25] Fix musl build jobs --- libc-test/build.rs | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/libc-test/build.rs b/libc-test/build.rs index f5e30bdcd7ab6..56c62d4274f52 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -1444,7 +1444,7 @@ fn test_android(target: &str) { // `linux/fcntl.h` and `fcntl.h` fails. // // This also tests strerror_r. - test_linux_termios2(); + test_linux_termios2(target); } fn test_freebsd(target: &str) { @@ -2660,7 +2660,7 @@ fn test_linux(target: &str) { // On Linux also generate another script for testing linux/fcntl declarations. // These cannot be tested normally because including both `linux/fcntl.h` and `fcntl.h` // fails on a lot of platforms. - test_linux_termios2(); + test_linux_termios2(target); // Test Elf64_Phdr and Elf32_Phdr // These types have a field called `p_type`, but including @@ -2683,7 +2683,9 @@ fn test_linux(target: &str) { cfg.generate("../src/lib.rs", "linux_elf.rs"); } -fn test_linux_termios2() { +fn test_linux_termios2(target: &str) { + assert!(target.contains("linux") || target.contains("android")); + let musl = target.contains("musl"); let mut cfg = ctest::TestGenerator::new(); cfg.skip_type(|_| true) .skip_fn(|f| match f { @@ -2693,13 +2695,20 @@ fn test_linux_termios2() { .skip_static(|_| true); headers! { cfg: - "linux/fcntl.h", - "net/if.h", - "linux/if.h", - "linux/quota.h", + "linux/quota.h", "asm/termbits.h", "string.h" } + if musl { + cfg.header("fcntl.h"); + } else { + cfg.header("linux/fcntl.h"); + } + if !musl { + cfg.header("net/if.h"); + cfg.header("linux/if.h"); + } + cfg.skip_const(move |name| match name { "F_CANCELLK" | "F_ADD_SEALS" | "F_GET_SEALS" => false, "F_SEAL_SEAL" | "F_SEAL_SHRINK" | "F_SEAL_GROW" | "F_SEAL_WRITE" => { From ea31f5aeb5a616402bd75146fee847d5417319cc Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Thu, 23 May 2019 19:10:58 +0200 Subject: [PATCH 25/25] Increase retries of Android downloads --- ci/android-install-ndk.sh | 2 +- ci/android-install-sdk.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ci/android-install-ndk.sh b/ci/android-install-ndk.sh index 90c9747c3363b..723e719054a14 100644 --- a/ci/android-install-ndk.sh +++ b/ci/android-install-ndk.sh @@ -12,7 +12,7 @@ set -ex NDK=android-ndk-r19c -curl --retry 10 -O https://dl.google.com/android/repository/${NDK}-linux-x86_64.zip +curl --retry 20 -O https://dl.google.com/android/repository/${NDK}-linux-x86_64.zip unzip -q ${NDK}-linux-x86_64.zip case "$1" in diff --git a/ci/android-install-sdk.sh b/ci/android-install-sdk.sh index fe28d43417b11..7f2104000fdef 100644 --- a/ci/android-install-sdk.sh +++ b/ci/android-install-sdk.sh @@ -20,7 +20,7 @@ set -ex SDK=4333796 mkdir sdk -curl --retry 10 https://dl.google.com/android/repository/sdk-tools-linux-${SDK}.zip -O +curl --retry 20 https://dl.google.com/android/repository/sdk-tools-linux-${SDK}.zip -O unzip -q -d sdk sdk-tools-linux-${SDK}.zip case "$1" in