Skip to content

Commit

Permalink
Auto merge of #2758 - fkm3:master, r=Amanieu
Browse files Browse the repository at this point in the history
Add misc constants and functions for android

These are the main diffs present in the downstream android opensource
project repo.
  • Loading branch information
bors committed Apr 23, 2022
2 parents 40d529f + 8a64a22 commit 05af8b7
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 12 deletions.
7 changes: 4 additions & 3 deletions ci/android-install-sdk.sh
Expand Up @@ -16,11 +16,12 @@ unzip -q -d sdk/cmdline-tools commandlinetools-linux-${SDK}_latest.zip

case "$1" in
arm | armv7)
api=24
image="system-images;android-${api};default;armeabi-v7a"
api=28
# Using the arm64 image because there is no armeabi-v7a image for api>24.
image="system-images;android-${api};google_apis;arm64-v8a"
;;
aarch64)
api=24
api=28
image="system-images;android-${api};google_apis;arm64-v8a"
;;
i686)
Expand Down
26 changes: 18 additions & 8 deletions ci/android-sysimage.sh
Expand Up @@ -19,20 +19,30 @@ main() {

local system
system="$(find . -name system.img)"

# The ext4 partition of this particular version of "system.img" is offset.
# `e2cp` can't handle the offset, so we use `dd` to trim the start of the
# file.
#
# The offset number might change for future system.img files, look at the
# fdisk output to adjust it when upgrading the system.img.
fdisk -l "$system" # Sector size 512, partition start 2048.
fallocate -c -o 0 -l 1048576 "$system"

mkdir -p ${dest}/{bin,lib,lib64}

# Extract android linker and libraries to /system
# This allows android executables to be run directly (or with qemu)
if [ "${arch}" = "x86_64" ] || [ "${arch}" = "arm64" ]; then
e2cp -p "${system}:/bin/linker64" "${dest}/bin/"
e2cp -p "${system}:/lib64/libdl.so" "${dest}/lib64/"
e2cp -p "${system}:/lib64/libc.so" "${dest}/lib64/"
e2cp -p "${system}:/lib64/libm.so" "${dest}/lib64/"
e2cp -p "${system}:/system/bin/linker64" "${dest}/bin/"
e2cp -p "${system}:/system/lib64/libdl.so" "${dest}/lib64/"
e2cp -p "${system}:/system/lib64/libc.so" "${dest}/lib64/"
e2cp -p "${system}:/system/lib64/libm.so" "${dest}/lib64/"
else
e2cp -p "${system}:/bin/linker" "${dest}/bin/"
e2cp -p "${system}:/lib/libdl.so" "${dest}/lib/"
e2cp -p "${system}:/lib/libc.so" "${dest}/lib/"
e2cp -p "${system}:/lib/libm.so" "${dest}/lib/"
e2cp -p "${system}:/system/bin/linker" "${dest}/bin/"
e2cp -p "${system}:/system/lib/libdl.so" "${dest}/lib/"
e2cp -p "${system}:/system/lib/libc.so" "${dest}/lib/"
e2cp -p "${system}:/system/lib/libm.so" "${dest}/lib/"
fi

# clean up
Expand Down
2 changes: 1 addition & 1 deletion ci/docker/x86_64-linux-android/Dockerfile
Expand Up @@ -18,7 +18,7 @@ RUN sh /android/android-install-ndk.sh $ANDROID_ARCH
# We do not run x86_64-linux-android tests on an android emulator.
# See ci/android-sysimage.sh for information about how tests are run.
COPY android-sysimage.sh /android/
RUN bash /android/android-sysimage.sh x86_64 x86_64-24_r07.zip
RUN bash /android/android-sysimage.sh x86_64 x86_64-28_r04.zip

ENV PATH=$PATH:/rust/bin:/android/ndk-$ANDROID_ARCH/bin \
CARGO_TARGET_X86_64_LINUX_ANDROID_LINKER=x86_64-linux-android-gcc \
Expand Down
2 changes: 2 additions & 0 deletions src/unix/linux_like/android/b32/arm.rs
Expand Up @@ -501,6 +501,8 @@ pub const SYS_pwritev2: ::c_long = 393;
pub const SYS_pkey_mprotect: ::c_long = 394;
pub const SYS_pkey_alloc: ::c_long = 395;
pub const SYS_pkey_free: ::c_long = 396;
pub const SYS_io_uring_setup: ::c_long = 425;
pub const SYS_io_uring_enter: ::c_long = 426;

// offsets in mcontext_t.gregs from sys/ucontext.h
pub const REG_R0: ::c_int = 0;
Expand Down
2 changes: 2 additions & 0 deletions src/unix/linux_like/android/b32/x86/mod.rs
Expand Up @@ -533,6 +533,8 @@ pub const SYS_pwritev2: ::c_long = 379;
pub const SYS_pkey_mprotect: ::c_long = 380;
pub const SYS_pkey_alloc: ::c_long = 381;
pub const SYS_pkey_free: ::c_long = 382;
pub const SYS_io_uring_setup: ::c_long = 425;
pub const SYS_io_uring_enter: ::c_long = 426;

// offsets in user_regs_structs, from sys/reg.h
pub const EBX: ::c_int = 0;
Expand Down
2 changes: 2 additions & 0 deletions src/unix/linux_like/android/b64/aarch64/mod.rs
Expand Up @@ -374,6 +374,8 @@ 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_io_uring_setup: ::c_long = 425;
pub const SYS_io_uring_enter: ::c_long = 426;
pub const SYS_syscalls: ::c_long = 436;

cfg_if! {
Expand Down
2 changes: 2 additions & 0 deletions src/unix/linux_like/android/b64/x86_64/mod.rs
Expand Up @@ -603,6 +603,8 @@ pub const SYS_pwritev2: ::c_long = 328;
pub const SYS_pkey_mprotect: ::c_long = 329;
pub const SYS_pkey_alloc: ::c_long = 330;
pub const SYS_pkey_free: ::c_long = 331;
pub const SYS_io_uring_setup: ::c_long = 425;
pub const SYS_io_uring_enter: ::c_long = 426;

// offsets in user_regs_structs, from sys/reg.h
pub const R15: ::c_int = 0;
Expand Down
21 changes: 21 additions & 0 deletions src/unix/linux_like/android/mod.rs
Expand Up @@ -2170,9 +2170,20 @@ pub const NFT_TRACETYPE_RULE: ::c_int = 3;
pub const NFT_NG_INCREMENTAL: ::c_int = 0;
pub const NFT_NG_RANDOM: ::c_int = 1;

// bionic/libc/kernel/uapi/linux/if_tun.h
pub const IFF_TUN: ::c_int = 0x0001;
pub const IFF_TAP: ::c_int = 0x0002;
pub const IFF_NAPI: ::c_int = 0x0010;
pub const IFF_NAPI_FRAGS: ::c_int = 0x0020;
pub const IFF_NO_PI: ::c_int = 0x1000;
pub const IFF_ONE_QUEUE: ::c_int = 0x2000;
pub const IFF_VNET_HDR: ::c_int = 0x4000;
pub const IFF_TUN_EXCL: ::c_int = 0x8000;
pub const IFF_MULTI_QUEUE: ::c_int = 0x0100;
pub const IFF_ATTACH_QUEUE: ::c_int = 0x0200;
pub const IFF_DETACH_QUEUE: ::c_int = 0x0400;
pub const IFF_PERSIST: ::c_int = 0x0800;
pub const IFF_NOFILTER: ::c_int = 0x1000;

// start android/platform/bionic/libc/kernel/uapi/linux/if_ether.h
// from https://android.googlesource.com/
Expand Down Expand Up @@ -2486,6 +2497,12 @@ pub const AF_VSOCK: ::c_int = 40;
pub const PF_NFC: ::c_int = AF_NFC;
pub const PF_VSOCK: ::c_int = AF_VSOCK;

// sys/prctl.h
pub const PR_SET_PDEATHSIG: ::c_int = 1;
pub const PR_GET_PDEATHSIG: ::c_int = 2;
pub const PR_GET_SECUREBITS: ::c_int = 27;
pub const PR_SET_SECUREBITS: ::c_int = 28;

// sys/system_properties.h
pub const PROP_VALUE_MAX: ::c_int = 92;
pub const PROP_NAME_MAX: ::c_int = 32;
Expand Down Expand Up @@ -2969,6 +2986,10 @@ extern "C" {

pub fn gettid() -> ::pid_t;

pub fn getrandom(buf: *mut ::c_void, buflen: ::size_t, flags: ::c_uint) -> ::ssize_t;

pub fn pthread_setname_np(thread: ::pthread_t, name: *const ::c_char) -> ::c_int;

pub fn __system_property_set(__name: *const ::c_char, __value: *const ::c_char) -> ::c_int;
pub fn __system_property_get(__name: *const ::c_char, __value: *mut ::c_char) -> ::c_int;
pub fn __system_property_find(__name: *const ::c_char) -> *const prop_info;
Expand Down

0 comments on commit 05af8b7

Please sign in to comment.