diff --git a/.travis.yml b/.travis.yml index 3172a6fd69f9e..93236a8d0c6a2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -51,6 +51,12 @@ matrix: - os: linux env: TARGET=arm-linux-androideabi rust: stable + - os: linux + env: TARGET=aarch64-linux-android + rust: stable + - os: linux + env: TARGET=i686-linux-android + rust: stable - os: linux env: TARGET=x86_64-unknown-linux-musl rust: stable diff --git a/ci/docker/arm-linux-androideabi/accept-licenses.sh b/ci/android-accept-licenses.sh similarity index 100% rename from ci/docker/arm-linux-androideabi/accept-licenses.sh rename to ci/android-accept-licenses.sh diff --git a/ci/docker/arm-linux-androideabi/install-ndk.sh b/ci/android-install-ndk.sh similarity index 81% rename from ci/docker/arm-linux-androideabi/install-ndk.sh rename to ci/android-install-ndk.sh index 566a3191848a3..75bcd20f2f77d 100644 --- a/ci/docker/arm-linux-androideabi/install-ndk.sh +++ b/ci/android-install-ndk.sh @@ -13,9 +13,24 @@ set -ex curl -O https://dl.google.com/android/repository/android-ndk-r13b-linux-x86_64.zip unzip -q android-ndk-r13b-linux-x86_64.zip + +case "$1" in + aarch64) + arch=arm64 + ;; + + i686) + arch=x86 + ;; + + *) + arch=$1 + ;; +esac; + android-ndk-r13b/build/tools/make_standalone_toolchain.py \ - --install-dir /android/ndk-arm \ - --arch arm \ + --install-dir /android/ndk-$1 \ + --arch $arch \ --api 24 rm -rf ./android-ndk-r13b-linux-x86_64.zip ./android-ndk-r13b diff --git a/ci/docker/arm-linux-androideabi/install-sdk.sh b/ci/android-install-sdk.sh similarity index 61% rename from ci/docker/arm-linux-androideabi/install-sdk.sh rename to ci/android-install-sdk.sh index 3f20837fe061a..0762dcb45d0b7 100644 --- a/ci/docker/arm-linux-androideabi/install-sdk.sh +++ b/ci/android-install-sdk.sh @@ -19,15 +19,35 @@ set -ex # which apparently magically accepts the licenses. mkdir sdk -curl https://dl.google.com/android/android-sdk_r24.4.1-linux.tgz | \ - tar xzf - -C sdk --strip-components=1 +curl https://dl.google.com/android/repository/tools_r25.2.5-linux.zip -O +unzip -d sdk tools_r25.2.5-linux.zip -filter="platform-tools,android-21" -filter="$filter,sys-img-armeabi-v7a-android-21" +filter="platform-tools,android-24" -./accept-licenses.sh "android - update sdk -a --no-ui --filter $filter" +case "$1" in + arm | armv7) + abi=armeabi-v7a + ;; + + aarch64) + abi=arm64-v8a + ;; + + i686) + abi=x86 + ;; + + *) + echo "invalid arch: $1" + exit 1 + ;; +esac; + +filter="$filter,sys-img-$abi-android-24" + +./android-accept-licenses.sh "android - update sdk -a --no-ui --filter $filter" echo "no" | android create avd \ - --name arm-21 \ - --target android-21 \ - --abi armeabi-v7a + --name $1 \ + --target android-24 \ + --abi $abi diff --git a/ci/docker/aarch64-linux-android/Dockerfile b/ci/docker/aarch64-linux-android/Dockerfile new file mode 100644 index 0000000000000..7ad84926bf82b --- /dev/null +++ b/ci/docker/aarch64-linux-android/Dockerfile @@ -0,0 +1,32 @@ +FROM ubuntu:16.04 + +RUN dpkg --add-architecture i386 && \ + apt-get update && \ + apt-get install -y --no-install-recommends \ + file \ + curl \ + ca-certificates \ + python \ + unzip \ + expect \ + openjdk-9-jre \ + libstdc++6:i386 \ + libpulse0 \ + gcc \ + libc6-dev + +WORKDIR /android/ +COPY android* /android/ + +ENV ANDROID_ARCH=aarch64 +ENV PATH=$PATH:/android/ndk-$ANDROID_ARCH/bin:/android/sdk/tools:/android/sdk/platform-tools + +RUN sh /android/android-install-ndk.sh $ANDROID_ARCH +RUN sh /android/android-install-sdk.sh $ANDROID_ARCH +RUN mv /root/.android /tmp +RUN chmod 777 -R /tmp/.android +RUN chmod 755 /android/sdk/tools/* /android/sdk/tools/qemu/linux-x86_64/* + +ENV PATH=$PATH:/rust/bin \ + CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER=aarch64-linux-android-gcc \ + HOME=/tmp diff --git a/ci/docker/arm-linux-androideabi/Dockerfile b/ci/docker/arm-linux-androideabi/Dockerfile index 1911fbd87970e..054941416dfb5 100644 --- a/ci/docker/arm-linux-androideabi/Dockerfile +++ b/ci/docker/arm-linux-androideabi/Dockerfile @@ -11,24 +11,22 @@ RUN dpkg --add-architecture i386 && \ expect \ openjdk-9-jre \ libstdc++6:i386 \ + libpulse0 \ gcc \ libc6-dev WORKDIR /android/ +COPY android* /android/ -COPY install-ndk.sh /android/ -RUN sh /android/install-ndk.sh +ENV ANDROID_ARCH=arm +ENV PATH=$PATH:/android/ndk-$ANDROID_ARCH/bin:/android/sdk/tools:/android/sdk/platform-tools -ENV PATH=$PATH:/android/ndk-arm/bin:/android/sdk/tools:/android/sdk/platform-tools - -COPY install-sdk.sh accept-licenses.sh /android/ -RUN sh /android/install-sdk.sh +RUN sh /android/android-install-ndk.sh $ANDROID_ARCH +RUN sh /android/android-install-sdk.sh $ANDROID_ARCH +RUN mv /root/.android /tmp +RUN chmod 777 -R /tmp/.android +RUN chmod 755 /android/sdk/tools/* /android/sdk/tools/qemu/linux-x86_64/* ENV PATH=$PATH:/rust/bin \ CARGO_TARGET_ARM_LINUX_ANDROIDEABI_LINKER=arm-linux-androideabi-gcc \ - ANDROID_EMULATOR_FORCE_32BIT=1 \ HOME=/tmp -RUN chmod 755 /android/sdk/tools/* - -RUN cp -r /root/.android /tmp -RUN chmod 777 -R /tmp/.android diff --git a/ci/docker/i686-linux-android/Dockerfile b/ci/docker/i686-linux-android/Dockerfile new file mode 100644 index 0000000000000..bee904379645f --- /dev/null +++ b/ci/docker/i686-linux-android/Dockerfile @@ -0,0 +1,32 @@ +FROM ubuntu:16.04 + +RUN dpkg --add-architecture i386 && \ + apt-get update && \ + apt-get install -y --no-install-recommends \ + file \ + curl \ + ca-certificates \ + python \ + unzip \ + expect \ + openjdk-9-jre \ + libstdc++6:i386 \ + libpulse0 \ + gcc \ + libc6-dev + +WORKDIR /android/ +COPY android* /android/ + +ENV ANDROID_ARCH=i686 +ENV PATH=$PATH:/android/ndk-$ANDROID_ARCH/bin:/android/sdk/tools:/android/sdk/platform-tools + +RUN sh /android/android-install-ndk.sh $ANDROID_ARCH +RUN sh /android/android-install-sdk.sh $ANDROID_ARCH +RUN mv /root/.android /tmp +RUN chmod 777 -R /tmp/.android +RUN chmod 755 /android/sdk/tools/* /android/sdk/tools/qemu/linux-x86_64/* + +ENV PATH=$PATH:/rust/bin \ + CARGO_TARGET_I686_LINUX_ANDROID_LINKER=i686-linux-android-gcc \ + HOME=/tmp diff --git a/ci/run-docker.sh b/ci/run-docker.sh index a7702ae1dc512..1ac419a349c08 100644 --- a/ci/run-docker.sh +++ b/ci/run-docker.sh @@ -5,7 +5,8 @@ set -ex run() { echo $1 - docker build -t libc ci/docker/$1 + # use -f so we can use ci/ as build context + docker build -t libc -f ci/docker/$1/Dockerfile ci/ mkdir -p target docker run \ --user `id -u`:`id -g` \ diff --git a/ci/run.sh b/ci/run.sh index d33af30fd91c7..1b6e0fb1d4549 100755 --- a/ci/run.sh +++ b/ci/run.sh @@ -105,11 +105,16 @@ case "$TARGET" in esac case "$TARGET" in - arm-linux-androideabi) - emulator @arm-21 -no-window & + arm-linux-androideabi | aarch64-linux-android | i686-linux-android) + # set SHELL so android can detect a 64bits system, see + # http://stackoverflow.com/a/41789144 + # https://issues.jenkins-ci.org/browse/JENKINS-26930?focusedCommentId=230791&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-230791 + export SHELL=/bin/dash + arch=$(echo $TARGET | cut -d- -f1) + emulator @$arch -no-window -no-accel & adb wait-for-device - adb push $CARGO_TARGET_DIR/$TARGET/debug/libc-test /data/libc-test - adb shell /data/libc-test 2>&1 | tee /tmp/out + adb push $CARGO_TARGET_DIR/$TARGET/debug/libc-test /data/local/tmp/libc-test + adb shell /data/local/tmp/libc-test 2>&1 | tee /tmp/out grep "^PASSED .* tests" /tmp/out ;; diff --git a/libc-test/build.rs b/libc-test/build.rs index a0390522574e9..4ebba509e19b0 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -6,6 +6,7 @@ use std::env; fn main() { let target = env::var("TARGET").unwrap(); + let aarch64 = target.contains("aarch64"); let x86_64 = target.contains("x86_64"); let windows = target.contains("windows"); let mingw = target.contains("windows-gnu"); @@ -105,8 +106,12 @@ fn main() { } if android { + if !aarch64 { + // time64_t is not define for aarch64 + // If included it will generate the error 'Your time_t is already 64-bit' + cfg.header("time64.h"); + } cfg.header("arpa/inet.h"); - cfg.header("time64.h"); cfg.header("xlocale.h"); cfg.header("utmp.h"); } else if !windows { diff --git a/src/unix/bsd/mod.rs b/src/unix/bsd/mod.rs index 2f7024f8276a0..826bd9288bd53 100644 --- a/src/unix/bsd/mod.rs +++ b/src/unix/bsd/mod.rs @@ -1,4 +1,4 @@ -use dox::mem; +use dox::{mem, Option}; pub type c_char = i8; pub type wchar_t = i32; @@ -359,6 +359,75 @@ extern { pub fn getpeereid(socket: ::c_int, euid: *mut ::uid_t, egid: *mut ::gid_t) -> ::c_int; + + #[cfg_attr(target_os = "macos", link_name = "glob$INODE64")] + #[cfg_attr(target_os = "netbsd", link_name = "__glob30")] + pub fn glob(pattern: *const ::c_char, + flags: ::c_int, + errfunc: Option ::c_int>, + pglob: *mut ::glob_t) -> ::c_int; + #[cfg_attr(target_os = "netbsd", link_name = "__globfree30")] + pub fn globfree(pglob: *mut ::glob_t); + + pub fn posix_madvise(addr: *mut ::c_void, len: ::size_t, advice: ::c_int) + -> ::c_int; + + pub fn shm_unlink(name: *const ::c_char) -> ::c_int; + + #[cfg_attr(all(target_os = "macos", target_arch = "x86_64"), + link_name = "seekdir$INODE64")] + #[cfg_attr(all(target_os = "macos", target_arch = "x86"), + link_name = "seekdir$INODE64$UNIX2003")] + pub fn seekdir(dirp: *mut ::DIR, loc: ::c_long); + + #[cfg_attr(all(target_os = "macos", target_arch = "x86_64"), + link_name = "telldir$INODE64")] + #[cfg_attr(all(target_os = "macos", target_arch = "x86"), + link_name = "telldir$INODE64$UNIX2003")] + pub fn telldir(dirp: *mut ::DIR) -> ::c_long; + pub fn madvise(addr: *mut ::c_void, len: ::size_t, advice: ::c_int) + -> ::c_int; + + #[cfg_attr(all(target_os = "macos", target_arch = "x86"), + link_name = "msync$UNIX2003")] + #[cfg_attr(target_os = "netbsd", link_name = "__msync13")] + pub fn msync(addr: *mut ::c_void, len: ::size_t, flags: ::c_int) -> ::c_int; + + #[cfg_attr(all(target_os = "macos", target_arch = "x86"), + link_name = "recvfrom$UNIX2003")] + pub fn recvfrom(socket: ::c_int, buf: *mut ::c_void, len: ::size_t, + flags: ::c_int, addr: *mut ::sockaddr, + addrlen: *mut ::socklen_t) -> ::ssize_t; + pub fn mkstemps(template: *mut ::c_char, suffixlen: ::c_int) -> ::c_int; + pub fn futimes(fd: ::c_int, times: *const ::timeval) -> ::c_int; + pub fn nl_langinfo(item: ::nl_item) -> *mut ::c_char; + + #[cfg_attr(all(target_os = "macos", target_arch = "x86"), + link_name = "bind$UNIX2003")] + pub fn bind(socket: ::c_int, address: *const ::sockaddr, + address_len: ::socklen_t) -> ::c_int; + + #[cfg_attr(all(target_os = "macos", target_arch = "x86"), + link_name = "writev$UNIX2003")] + pub fn writev(fd: ::c_int, + iov: *const ::iovec, + iovcnt: ::c_int) -> ::ssize_t; + #[cfg_attr(all(target_os = "macos", target_arch = "x86"), + link_name = "readv$UNIX2003")] + pub fn readv(fd: ::c_int, + iov: *const ::iovec, + iovcnt: ::c_int) -> ::ssize_t; + + #[cfg_attr(all(target_os = "macos", target_arch = "x86"), + link_name = "sendmsg$UNIX2003")] + pub fn sendmsg(fd: ::c_int, + msg: *const ::msghdr, + flags: ::c_int) -> ::ssize_t; + #[cfg_attr(all(target_os = "macos", target_arch = "x86"), + link_name = "recvmsg$UNIX2003")] + pub fn recvmsg(fd: ::c_int, msg: *mut ::msghdr, flags: ::c_int) + -> ::ssize_t; } cfg_if! { diff --git a/src/unix/haiku/mod.rs b/src/unix/haiku/mod.rs index 634805ca2ee70..c4b446769bf61 100644 --- a/src/unix/haiku/mod.rs +++ b/src/unix/haiku/mod.rs @@ -1,4 +1,4 @@ -use dox::mem; +use dox::{mem, Option}; pub type rlim_t = ::uintptr_t; pub type sa_family_t = u8; @@ -760,6 +760,49 @@ extern { abstime: *const ::timespec) -> ::c_int; pub fn waitid(idtype: idtype_t, id: id_t, infop: *mut ::siginfo_t, options: ::c_int) -> ::c_int; + + pub fn glob(pattern: *const ::c_char, + flags: ::c_int, + errfunc: Option ::c_int>, + pglob: *mut ::glob_t) -> ::c_int; + pub fn globfree(pglob: *mut ::glob_t); + + pub fn posix_madvise(addr: *mut ::c_void, len: ::size_t, advice: ::c_int) + -> ::c_int; + + pub fn shm_unlink(name: *const ::c_char) -> ::c_int; + + pub fn seekdir(dirp: *mut ::DIR, loc: ::c_long); + + pub fn telldir(dirp: *mut ::DIR) -> ::c_long; + pub fn madvise(addr: *mut ::c_void, len: ::size_t, advice: ::c_int) + -> ::c_int; + + pub fn msync(addr: *mut ::c_void, len: ::size_t, flags: ::c_int) -> ::c_int; + + pub fn recvfrom(socket: ::c_int, buf: *mut ::c_void, len: ::size_t, + flags: ::c_int, addr: *mut ::sockaddr, + addrlen: *mut ::socklen_t) -> ::ssize_t; + pub fn mkstemps(template: *mut ::c_char, suffixlen: ::c_int) -> ::c_int; + pub fn futimes(fd: ::c_int, times: *const ::timeval) -> ::c_int; + pub fn nl_langinfo(item: ::nl_item) -> *mut ::c_char; + + pub fn bind(socket: ::c_int, address: *const ::sockaddr, + address_len: ::socklen_t) -> ::c_int; + + pub fn writev(fd: ::c_int, + iov: *const ::iovec, + iovcnt: ::c_int) -> ::ssize_t; + pub fn readv(fd: ::c_int, + iov: *const ::iovec, + iovcnt: ::c_int) -> ::ssize_t; + + pub fn sendmsg(fd: ::c_int, + msg: *const ::msghdr, + flags: ::c_int) -> ::ssize_t; + pub fn recvmsg(fd: ::c_int, msg: *mut ::msghdr, flags: ::c_int) + -> ::ssize_t; } cfg_if! { diff --git a/src/unix/mod.rs b/src/unix/mod.rs index 3030f80e095c7..9b39050e6cc17 100644 --- a/src/unix/mod.rs +++ b/src/unix/mod.rs @@ -274,10 +274,6 @@ extern { link_name = "connect$UNIX2003")] pub fn connect(socket: ::c_int, address: *const sockaddr, len: socklen_t) -> ::c_int; - #[cfg_attr(all(target_os = "macos", target_arch = "x86"), - link_name = "bind$UNIX2003")] - pub fn bind(socket: ::c_int, address: *const sockaddr, - address_len: socklen_t) -> ::c_int; #[cfg_attr(all(target_os = "macos", target_arch = "x86"), link_name = "listen$UNIX2003")] pub fn listen(socket: ::c_int, backlog: ::c_int) -> ::c_int; @@ -681,16 +677,6 @@ extern { #[cfg_attr(target_os = "netbsd", link_name = "__mknod50")] pub fn mknod(pathname: *const ::c_char, mode: ::mode_t, dev: ::dev_t) -> ::c_int; - #[cfg_attr(all(target_os = "macos", target_arch = "x86"), - link_name = "writev$UNIX2003")] - pub fn writev(fd: ::c_int, - iov: *const ::iovec, - iovcnt: ::c_int) -> ::ssize_t; - #[cfg_attr(all(target_os = "macos", target_arch = "x86"), - link_name = "readv$UNIX2003")] - pub fn readv(fd: ::c_int, - iov: *const ::iovec, - iovcnt: ::c_int) -> ::ssize_t; pub fn uname(buf: *mut ::utsname) -> ::c_int; pub fn daemon(nochdir: ::c_int, noclose: ::c_int) -> ::c_int; pub fn gethostname(name: *mut ::c_char, len: ::size_t) -> ::c_int; @@ -710,14 +696,6 @@ extern { link_name = "putenv$UNIX2003")] #[cfg_attr(target_os = "netbsd", link_name = "__putenv50")] pub fn putenv(string: *mut c_char) -> ::c_int; - #[cfg_attr(all(target_os = "macos", target_arch = "x86"), - link_name = "sendmsg$UNIX2003")] - pub fn sendmsg(fd: ::c_int, - msg: *const msghdr, - flags: ::c_int) -> ::ssize_t; - #[cfg_attr(all(target_os = "macos", target_arch = "x86"), - link_name = "recvmsg$UNIX2003")] - pub fn recvmsg(fd: ::c_int, msg: *mut msghdr, flags: ::c_int) -> ::ssize_t; #[cfg_attr(all(target_os = "macos", target_arch = "x86"), link_name = "poll$UNIX2003")] pub fn poll(fds: *mut pollfd, nfds: nfds_t, timeout: ::c_int) -> ::c_int; @@ -751,58 +729,12 @@ extern { -> ::c_int; pub fn statvfs(path: *const c_char, buf: *mut statvfs) -> ::c_int; pub fn fstatvfs(fd: ::c_int, buf: *mut statvfs) -> ::c_int; -} - -// TODO: get rid of this cfg(not(...)) -#[cfg(not(target_os = "android"))] // " if " -- appease style checker -extern { - #[cfg_attr(target_os = "macos", link_name = "glob$INODE64")] - #[cfg_attr(target_os = "netbsd", link_name = "__glob30")] - pub fn glob(pattern: *const c_char, - flags: ::c_int, - errfunc: Option ::c_int>, - pglob: *mut glob_t) -> ::c_int; - #[cfg_attr(target_os = "netbsd", link_name = "__globfree30")] - pub fn globfree(pglob: *mut glob_t); - - pub fn posix_madvise(addr: *mut ::c_void, len: ::size_t, advice: ::c_int) - -> ::c_int; - - pub fn shm_unlink(name: *const c_char) -> ::c_int; - - #[cfg_attr(all(target_os = "macos", target_arch = "x86_64"), - link_name = "seekdir$INODE64")] - #[cfg_attr(all(target_os = "macos", target_arch = "x86"), - link_name = "seekdir$INODE64$UNIX2003")] - pub fn seekdir(dirp: *mut ::DIR, loc: c_long); - - #[cfg_attr(all(target_os = "macos", target_arch = "x86_64"), - link_name = "telldir$INODE64")] - #[cfg_attr(all(target_os = "macos", target_arch = "x86"), - link_name = "telldir$INODE64$UNIX2003")] - pub fn telldir(dirp: *mut ::DIR) -> c_long; - pub fn getsid(pid: pid_t) -> pid_t; - pub fn madvise(addr: *mut ::c_void, len: ::size_t, advice: ::c_int) - -> ::c_int; pub fn readlink(path: *const c_char, buf: *mut c_char, bufsz: ::size_t) -> ::ssize_t; - #[cfg_attr(all(target_os = "macos", target_arch = "x86"), - link_name = "msync$UNIX2003")] - #[cfg_attr(target_os = "netbsd", link_name = "__msync13")] - pub fn msync(addr: *mut ::c_void, len: ::size_t, flags: ::c_int) -> ::c_int; - pub fn sysconf(name: ::c_int) -> c_long; - #[cfg_attr(all(target_os = "macos", target_arch = "x86"), - link_name = "recvfrom$UNIX2003")] - pub fn recvfrom(socket: ::c_int, buf: *mut ::c_void, len: ::size_t, - flags: ::c_int, addr: *mut sockaddr, - addrlen: *mut socklen_t) -> ::ssize_t; - pub fn mkfifo(path: *const c_char, mode: mode_t) -> ::c_int; - #[cfg_attr(target_os = "netbsd", link_name = "__sigemptyset14")] pub fn sigemptyset(set: *mut sigset_t) -> ::c_int; #[cfg_attr(target_os = "netbsd", link_name = "__sigaddset14")] @@ -813,6 +745,16 @@ extern { pub fn sigdelset(set: *mut sigset_t, signum: ::c_int) -> ::c_int; #[cfg_attr(target_os = "netbsd", link_name = "__sigismember14")] pub fn sigismember(set: *const sigset_t, signum: ::c_int) -> ::c_int; + + #[cfg_attr(target_os = "netbsd", link_name = "__timegm50")] + pub fn timegm(tm: *mut ::tm) -> time_t; + + pub fn getsid(pid: pid_t) -> pid_t; + + pub fn sysconf(name: ::c_int) -> ::c_long; + + pub fn mkfifo(path: *const c_char, mode: mode_t) -> ::c_int; + #[cfg_attr(all(target_os = "macos", target_arch = "x86_64"), link_name = "pselect$1050")] #[cfg_attr(all(target_os = "macos", target_arch = "x86"), @@ -828,8 +770,6 @@ extern { offset: ::off_t, whence: ::c_int) -> ::c_int; pub fn ftello(stream: *mut ::FILE) -> ::off_t; - #[cfg_attr(target_os = "netbsd", link_name = "__timegm50")] - pub fn timegm(tm: *mut ::tm) -> time_t; #[cfg_attr(all(target_os = "macos", target_arch = "x86"), link_name = "tcdrain$UNIX2003")] pub fn tcdrain(fd: ::c_int) -> ::c_int; @@ -847,11 +787,9 @@ extern { pub fn tcflush(fd: ::c_int, action: ::c_int) -> ::c_int; pub fn tcsendbreak(fd: ::c_int, duration: ::c_int) -> ::c_int; pub fn mkstemp(template: *mut ::c_char) -> ::c_int; - pub fn mkstemps(template: *mut ::c_char, suffixlen: ::c_int) -> ::c_int; pub fn mkdtemp(template: *mut ::c_char) -> *mut ::c_char; + pub fn tmpnam(ptr: *mut ::c_char) -> *mut ::c_char; - pub fn futimes(fd: ::c_int, times: *const ::timeval) -> ::c_int; - pub fn nl_langinfo(item: ::nl_item) -> *mut ::c_char; pub fn openlog(ident: *const ::c_char, logopt: ::c_int, facility: ::c_int); pub fn closelog(); diff --git a/src/unix/notbsd/android/b32/arm.rs b/src/unix/notbsd/android/b32/arm.rs new file mode 100644 index 0000000000000..1c9d033d17dba --- /dev/null +++ b/src/unix/notbsd/android/b32/arm.rs @@ -0,0 +1,6 @@ +pub type c_char = u8; +pub type wchar_t = u32; + +pub const O_DIRECT: ::c_int = 0x10000; +pub const O_DIRECTORY: ::c_int = 0x4000; +pub const O_NOFOLLOW: ::c_int = 0x8000; diff --git a/src/unix/notbsd/android/b32.rs b/src/unix/notbsd/android/b32/mod.rs similarity index 76% rename from src/unix/notbsd/android/b32.rs rename to src/unix/notbsd/android/b32/mod.rs index bd69ccf37d571..9efcd61c726ec 100644 --- a/src/unix/notbsd/android/b32.rs +++ b/src/unix/notbsd/android/b32/mod.rs @@ -2,6 +2,9 @@ pub type c_long = i32; pub type c_ulong = u32; pub type mode_t = u16; pub type off64_t = ::c_longlong; +pub type sigset_t = ::c_ulong; +pub type socklen_t = i32; +pub type time64_t = i64; s! { pub struct sigaction { @@ -11,6 +14,11 @@ s! { pub sa_restorer: ::dox::Option, } + pub struct rlimit64 { + pub rlim_cur: u64, + pub rlim_max: u64, + } + pub struct stat { pub st_dev: ::c_ulonglong, __pad0: [::c_uchar; 4], @@ -121,6 +129,15 @@ s! { } } +pub const RTLD_GLOBAL: ::c_int = 2; +pub const RTLD_NOW: ::c_int = 0; +pub const RTLD_DEFAULT: *mut ::c_void = -1isize as *mut ::c_void; + +pub const PTRACE_GETFPREGS: ::c_int = 14; +pub const PTRACE_SETFPREGS: ::c_int = 15; +pub const PTRACE_GETREGS: ::c_int = 12; +pub const PTRACE_SETREGS: ::c_int = 13; + pub const SYS_gettid: ::c_long = 224; pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t { value: 0, @@ -147,5 +164,33 @@ pub const UT_NAMESIZE: usize = 8; pub const UT_HOSTSIZE: usize = 16; extern { + pub fn bind(socket: ::c_int, address: *const ::sockaddr, + address_len: socklen_t) -> ::c_int; + + pub fn writev(fd: ::c_int, + iov: *const ::iovec, + iovcnt: ::c_int) -> ::ssize_t; + pub fn readv(fd: ::c_int, + iov: *const ::iovec, + iovcnt: ::c_int) -> ::ssize_t; + + pub fn sendmsg(fd: ::c_int, + msg: *const ::msghdr, + flags: ::c_int) -> ::ssize_t; + pub fn recvmsg(fd: ::c_int, msg: *mut ::msghdr, flags: ::c_int) + -> ::ssize_t; + pub fn timegm64(tm: *const ::tm) -> ::time64_t; } + +cfg_if! { + if #[cfg(target_arch = "x86")] { + mod x86; + pub use self::x86::*; + } else if #[cfg(target_arch = "arm")] { + mod arm; + pub use self::arm::*; + } else { + // Unknown target_arch + } +} diff --git a/src/unix/notbsd/android/b32/x86.rs b/src/unix/notbsd/android/b32/x86.rs new file mode 100644 index 0000000000000..c4b8197de55bc --- /dev/null +++ b/src/unix/notbsd/android/b32/x86.rs @@ -0,0 +1,6 @@ +pub type c_char = i8; +pub type wchar_t = i32; + +pub const O_DIRECT: ::c_int = 0x4000; +pub const O_DIRECTORY: ::c_int = 0x10000; +pub const O_NOFOLLOW: ::c_int = 0x20000; diff --git a/src/unix/notbsd/android/b64.rs b/src/unix/notbsd/android/b64/mod.rs similarity index 75% rename from src/unix/notbsd/android/b64.rs rename to src/unix/notbsd/android/b64/mod.rs index b35dde4216059..31a05d657c55e 100644 --- a/src/unix/notbsd/android/b64.rs +++ b/src/unix/notbsd/android/b64/mod.rs @@ -1,11 +1,18 @@ // The following definitions are correct for aarch64 and may be wrong for x86_64 +pub type c_char = u8; pub type c_long = i64; pub type c_ulong = u64; pub type mode_t = u32; pub type off64_t = i64; +pub type socklen_t = u32; +pub type wchar_t = u32; s! { + pub struct sigset_t { + __val: [::c_ulong; 1], + } + pub struct sigaction { pub sa_flags: ::c_uint, pub sa_sigaction: ::sighandler_t, @@ -13,6 +20,11 @@ s! { _restorer: *mut ::c_void, } + pub struct rlimit64 { + pub rlim_cur: ::c_ulonglong, + pub rlim_max: ::c_ulonglong, + } + pub struct stat { pub st_dev: ::dev_t, pub st_ino: ::ino_t, @@ -131,6 +143,14 @@ s! { } } +pub const O_DIRECT: ::c_int = 0x10000; +pub const O_DIRECTORY: ::c_int = 0x4000; +pub const O_NOFOLLOW: ::c_int = 0x8000; + +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; + pub const SYS_gettid: ::c_long = 178; pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t { value: 0, @@ -156,6 +176,27 @@ pub const UT_LINESIZE: usize = 32; pub const UT_NAMESIZE: usize = 32; pub const UT_HOSTSIZE: usize = 256; +// Some weirdness in Android extern { - pub fn timegm(tm: *const ::tm) -> ::time64_t; + // address_len should be socklen_t, but it is c_int! + pub fn bind(socket: ::c_int, address: *const ::sockaddr, + address_len: ::c_int) -> ::c_int; + + // the return type should be ::ssize_t, but it is c_int! + pub fn writev(fd: ::c_int, + iov: *const ::iovec, + iovcnt: ::c_int) -> ::c_int; + + // the return type should be ::ssize_t, but it is c_int! + pub fn readv(fd: ::c_int, + iov: *const ::iovec, + iovcnt: ::c_int) -> ::c_int; + + // the return type should be ::ssize_t, but it is c_int! + pub fn sendmsg(fd: ::c_int, + msg: *const ::msghdr, + flags: ::c_int) -> ::c_int; + + // the return type should be ::ssize_t, but it is c_int! + pub fn recvmsg(fd: ::c_int, msg: *mut ::msghdr, flags: ::c_int) -> ::c_int; } diff --git a/src/unix/notbsd/android/mod.rs b/src/unix/notbsd/android/mod.rs index 3884a770786e1..57eda11e7e46b 100644 --- a/src/unix/notbsd/android/mod.rs +++ b/src/unix/notbsd/android/mod.rs @@ -2,22 +2,17 @@ use dox::mem; -pub type c_char = u8; pub type clock_t = ::c_long; pub type time_t = ::c_long; pub type suseconds_t = ::c_long; -pub type wchar_t = u32; pub type off_t = ::c_long; pub type blkcnt_t = ::c_ulong; pub type blksize_t = ::c_ulong; pub type nlink_t = u32; pub type useconds_t = u32; -pub type socklen_t = i32; pub type pthread_t = ::c_long; pub type pthread_mutexattr_t = ::c_long; pub type pthread_condattr_t = ::c_long; -pub type sigset_t = ::c_ulong; -pub type time64_t = i64; // N/A on android pub type fsfilcnt_t = ::c_ulong; pub type fsblkcnt_t = ::c_ulong; pub type nfds_t = ::c_uint; @@ -44,11 +39,6 @@ s! { pub d_name: [::c_char; 256], } - pub struct rlimit64 { - pub rlim_cur: u64, - pub rlim_max: u64, - } - pub struct stack_t { pub ss_sp: *mut ::c_void, pub ss_flags: ::c_int, @@ -60,6 +50,7 @@ s! { pub si_errno: ::c_int, pub si_code: ::c_int, pub _pad: [::c_int; 29], + _align: [usize; 0], } pub struct __fsid_t { @@ -68,7 +59,7 @@ s! { pub struct msghdr { pub msg_name: *mut ::c_void, - pub msg_namelen: ::c_int, + pub msg_namelen: ::socklen_t, pub msg_iov: *mut ::iovec, pub msg_iovlen: ::size_t, pub msg_control: *mut ::c_void, @@ -108,6 +99,8 @@ s! { pub struct sem_t { count: ::c_uint, + #[cfg(target_pointer_width = "64")] + __reserved: [::c_int; 3], } pub struct lastlog { @@ -149,6 +142,8 @@ s! { pub f_fsid: ::c_ulong, pub f_flag: ::c_ulong, pub f_namemax: ::c_ulong, + #[cfg(target_pointer_width = "64")] + __f_reserved: [u32; 6], } } @@ -447,9 +442,6 @@ pub const O_EXCL: ::c_int = 128; pub const O_NOCTTY: ::c_int = 256; pub const O_NONBLOCK: ::c_int = 2048; pub const O_SYNC: ::c_int = 0x101000; -pub const O_DIRECT: ::c_int = 0x10000; -pub const O_DIRECTORY: ::c_int = 0x4000; -pub const O_NOFOLLOW: ::c_int = 0x8000; pub const O_ASYNC: ::c_int = 0x2000; pub const O_NDELAY: ::c_int = 0x800; @@ -517,10 +509,6 @@ pub const PTRACE_SETOPTIONS: ::c_int = 0x4200; pub const PTRACE_GETEVENTMSG: ::c_int = 0x4201; pub const PTRACE_GETSIGINFO: ::c_int = 0x4202; pub const PTRACE_SETSIGINFO: ::c_int = 0x4203; -pub const PTRACE_GETFPREGS: ::c_int = 14; -pub const PTRACE_SETFPREGS: ::c_int = 15; -pub const PTRACE_GETREGS: ::c_int = 12; -pub const PTRACE_SETREGS: ::c_int = 13; pub const EFD_NONBLOCK: ::c_int = 0x800; @@ -562,10 +550,7 @@ pub const TIOCMSET: ::c_int = 0x5418; pub const FIONREAD: ::c_int = 0x541B; pub const TIOCCONS: ::c_int = 0x541D; -pub const RTLD_GLOBAL: ::c_int = 0x2; pub const RTLD_NOLOAD: ::c_int = 0x4; -pub const RTLD_NOW: ::c_int = 0; -pub const RTLD_DEFAULT: *mut ::c_void = -1isize as *mut ::c_void; pub const SEM_FAILED: *mut sem_t = 0 as *mut sem_t; @@ -727,74 +712,6 @@ pub const NLA_TYPE_MASK: ::c_int = !(NLA_F_NESTED | NLA_F_NET_BYTEORDER); pub const SIGEV_THREAD_ID: ::c_int = 4; f! { - pub fn sigemptyset(set: *mut sigset_t) -> ::c_int { - *set = 0; - return 0 - } - pub fn sigaddset(set: *mut sigset_t, signum: ::c_int) -> ::c_int { - *set |= signum as sigset_t; - return 0 - } - pub fn sigfillset(set: *mut sigset_t) -> ::c_int { - *set = !0; - return 0 - } - pub fn sigdelset(set: *mut sigset_t, signum: ::c_int) -> ::c_int { - *set &= !(signum as sigset_t); - return 0 - } - pub fn sigismember(set: *const sigset_t, signum: ::c_int) -> ::c_int { - (*set & (signum as sigset_t)) as ::c_int - } - pub fn cfgetispeed(termios: *const ::termios) -> ::speed_t { - (*termios).c_cflag & ::CBAUD - } - pub fn cfgetospeed(termios: *const ::termios) -> ::speed_t { - (*termios).c_cflag & ::CBAUD - } - pub fn cfmakeraw(termios: *mut ::termios) -> () { - (*termios).c_iflag &= !(::IGNBRK | ::BRKINT | ::PARMRK | ::ISTRIP | - ::INLCR | ::IGNCR | ::ICRNL | ::IXON); - (*termios).c_oflag &= !::OPOST; - (*termios).c_lflag &= !(::ECHO | ::ECHONL | ::ICANON | ::ISIG | - ::IEXTEN); - (*termios).c_cflag &= !(::CSIZE | ::PARENB); - (*termios).c_cflag |= ::CS8; - () - } - pub fn cfsetispeed(termios: *mut ::termios, speed: ::speed_t) -> ::c_int { - let cbaud = ::CBAUD; - (*termios).c_cflag = ((*termios).c_cflag & !cbaud) | (speed & cbaud); - return 0 - } - pub fn cfsetospeed(termios: *mut ::termios, speed: ::speed_t) -> ::c_int { - let cbaud = ::CBAUD; - (*termios).c_cflag = ((*termios).c_cflag & !cbaud) | (speed & cbaud); - return 0 - } - pub fn cfsetspeed(termios: *mut ::termios, speed: ::speed_t) -> ::c_int { - let cbaud = ::CBAUD; - (*termios).c_cflag = ((*termios).c_cflag & !cbaud) | (speed & cbaud); - return 0 - } - pub fn tcgetattr(fd: ::c_int, termios: *mut ::termios) -> ::c_int { - ioctl(fd, ::TCGETS, termios) - } - pub fn tcsetattr(fd: ::c_int, - optional_actions: ::c_int, - termios: *const ::termios) -> ::c_int { - ioctl(fd, optional_actions, termios) - } - pub fn tcflow(fd: ::c_int, action: ::c_int) -> ::c_int { - ioctl(fd, ::TCXONC, action as *mut ::c_void) - } - pub fn tcflush(fd: ::c_int, action: ::c_int) -> ::c_int { - ioctl(fd, ::TCFLSH, action as *mut ::c_void) - } - pub fn tcsendbreak(fd: ::c_int, duration: ::c_int) -> ::c_int { - ioctl(fd, TCSBRKP, duration as *mut ::c_void) - } - pub fn CPU_ZERO(cpuset: &mut cpu_set_t) -> () { for slot in cpuset.__bits.iter_mut() { *slot = 0; @@ -834,15 +751,10 @@ extern { pub fn madvise(addr: *const ::c_void, len: ::size_t, advice: ::c_int) -> ::c_int; pub fn ioctl(fd: ::c_int, request: ::c_int, ...) -> ::c_int; - pub fn readlink(path: *const ::c_char, - buf: *mut ::c_char, - bufsz: ::size_t) - -> ::c_int; pub fn msync(addr: *const ::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; - pub fn sysconf(name: ::c_int) -> ::c_long; pub fn recvfrom(socket: ::c_int, buf: *mut ::c_void, len: ::size_t, flags: ::c_int, addr: *const ::sockaddr, addrlen: *mut ::socklen_t) -> ::ssize_t; diff --git a/src/unix/notbsd/linux/mod.rs b/src/unix/notbsd/linux/mod.rs index fd8fffe77c319..248ea50b411fc 100644 --- a/src/unix/notbsd/linux/mod.rs +++ b/src/unix/notbsd/linux/mod.rs @@ -1,6 +1,6 @@ //! Linux-specific definitions for linux-like values -use dox::mem; +use dox::{mem, Option}; pub type useconds_t = u32; pub type dev_t = u64; @@ -900,6 +900,49 @@ extern { new_len: ::size_t, flags: ::c_int, ...) -> *mut ::c_void; + + pub fn glob(pattern: *const c_char, + flags: ::c_int, + errfunc: Option ::c_int>, + pglob: *mut ::glob_t) -> ::c_int; + pub fn globfree(pglob: *mut ::glob_t); + + pub fn posix_madvise(addr: *mut ::c_void, len: ::size_t, advice: ::c_int) + -> ::c_int; + + pub fn shm_unlink(name: *const ::c_char) -> ::c_int; + + pub fn seekdir(dirp: *mut ::DIR, loc: ::c_long); + + pub fn telldir(dirp: *mut ::DIR) -> ::c_long; + pub fn madvise(addr: *mut ::c_void, len: ::size_t, advice: ::c_int) + -> ::c_int; + + pub fn msync(addr: *mut ::c_void, len: ::size_t, flags: ::c_int) -> ::c_int; + + pub fn recvfrom(socket: ::c_int, buf: *mut ::c_void, len: ::size_t, + flags: ::c_int, addr: *mut ::sockaddr, + addrlen: *mut ::socklen_t) -> ::ssize_t; + pub fn mkstemps(template: *mut ::c_char, suffixlen: ::c_int) -> ::c_int; + pub fn futimes(fd: ::c_int, times: *const ::timeval) -> ::c_int; + pub fn nl_langinfo(item: ::nl_item) -> *mut ::c_char; + + pub fn bind(socket: ::c_int, address: *const ::sockaddr, + address_len: ::socklen_t) -> ::c_int; + + pub fn writev(fd: ::c_int, + iov: *const ::iovec, + iovcnt: ::c_int) -> ::ssize_t; + pub fn readv(fd: ::c_int, + iov: *const ::iovec, + iovcnt: ::c_int) -> ::ssize_t; + + pub fn sendmsg(fd: ::c_int, + msg: *const ::msghdr, + flags: ::c_int) -> ::ssize_t; + pub fn recvmsg(fd: ::c_int, msg: *mut ::msghdr, flags: ::c_int) + -> ::ssize_t; } cfg_if! { diff --git a/src/unix/notbsd/mod.rs b/src/unix/notbsd/mod.rs index 9f8d8e56f57f3..9f9e8cd08231d 100644 --- a/src/unix/notbsd/mod.rs +++ b/src/unix/notbsd/mod.rs @@ -120,7 +120,9 @@ s! { pub dli_saddr: *mut ::c_void, } - #[cfg_attr(any(all(target_arch = "x86", not(target_env = "musl")), + #[cfg_attr(any(all(target_arch = "x86", + not(target_env = "musl"), + not(target_os = "android")), target_arch = "x86_64"), repr(packed))] pub struct epoll_event { diff --git a/src/unix/solaris/mod.rs b/src/unix/solaris/mod.rs index 1800a4cb433c6..55ac0a276dbe9 100644 --- a/src/unix/solaris/mod.rs +++ b/src/unix/solaris/mod.rs @@ -1,4 +1,4 @@ -use dox::mem; +use dox::{mem, Option}; pub type c_char = i8; pub type c_long = i64; @@ -1094,4 +1094,48 @@ extern { abstime: *const ::timespec) -> ::c_int; pub fn waitid(idtype: idtype_t, id: id_t, infop: *mut ::siginfo_t, options: ::c_int) -> ::c_int; + + pub fn glob(pattern: *const ::c_char, + flags: ::c_int, + errfunc: Option ::c_int>, + pglob: *mut ::glob_t) -> ::c_int; + + pub fn globfree(pglob: *mut ::glob_t); + + pub fn posix_madvise(addr: *mut ::c_void, len: ::size_t, advice: ::c_int) + -> ::c_int; + + pub fn shm_unlink(name: *const ::c_char) -> ::c_int; + + pub fn seekdir(dirp: *mut ::DIR, loc: ::c_long); + + pub fn telldir(dirp: *mut ::DIR) -> ::c_long; + pub fn madvise(addr: *mut ::c_void, len: ::size_t, advice: ::c_int) + -> ::c_int; + + pub fn msync(addr: *mut ::c_void, len: ::size_t, flags: ::c_int) -> ::c_int; + + pub fn recvfrom(socket: ::c_int, buf: *mut ::c_void, len: ::size_t, + flags: ::c_int, addr: *mut ::sockaddr, + addrlen: *mut ::socklen_t) -> ::ssize_t; + pub fn mkstemps(template: *mut ::c_char, suffixlen: ::c_int) -> ::c_int; + pub fn futimes(fd: ::c_int, times: *const ::timeval) -> ::c_int; + pub fn nl_langinfo(item: ::nl_item) -> *mut ::c_char; + + pub fn bind(socket: ::c_int, address: *const ::sockaddr, + address_len: ::socklen_t) -> ::c_int; + + pub fn writev(fd: ::c_int, + iov: *const ::iovec, + iovcnt: ::c_int) -> ::ssize_t; + pub fn readv(fd: ::c_int, + iov: *const ::iovec, + iovcnt: ::c_int) -> ::ssize_t; + + pub fn sendmsg(fd: ::c_int, + msg: *const ::msghdr, + flags: ::c_int) -> ::ssize_t; + pub fn recvmsg(fd: ::c_int, msg: *mut ::msghdr, flags: ::c_int) + -> ::ssize_t; }