From 7319e5ae236996be43cc3d8dae81cec262ef21b6 Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Sun, 2 Jul 2023 23:58:09 -0700 Subject: [PATCH 1/4] Clarify purpose of some `AT_` consts They have to deal with "openat", etc. --- src/unix/linux_like/mod.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/unix/linux_like/mod.rs b/src/unix/linux_like/mod.rs index 20d0006bd4d75..e00cfdeafd172 100644 --- a/src/unix/linux_like/mod.rs +++ b/src/unix/linux_like/mod.rs @@ -1196,13 +1196,14 @@ pub const POSIX_FADV_RANDOM: ::c_int = 1; pub const POSIX_FADV_SEQUENTIAL: ::c_int = 2; pub const POSIX_FADV_WILLNEED: ::c_int = 3; -pub const AT_FDCWD: ::c_int = -100; -pub const AT_SYMLINK_NOFOLLOW: ::c_int = 0x100; -pub const AT_REMOVEDIR: ::c_int = 0x200; -pub const AT_SYMLINK_FOLLOW: ::c_int = 0x400; -pub const AT_NO_AUTOMOUNT: ::c_int = 0x800; -pub const AT_EMPTY_PATH: ::c_int = 0x1000; -pub const AT_RECURSIVE: ::c_int = 0x8000; +// flags for "at"-suffixed file operations, e.g. execveat, openat +pub const AT_FDCWD: ::c_int = -100; // used instead of dirfd +pub const AT_REMOVEDIR: ::c_int = 0x200; // unlinkat +pub const AT_SYMLINK_NOFOLLOW: ::c_int = 0x100; // fstatat +pub const AT_NO_AUTOMOUNT: ::c_int = 0x800; // fstatat +pub const AT_SYMLINK_FOLLOW: ::c_int = 0x400; // linkat +pub const AT_EMPTY_PATH: ::c_int = 0x1000; // linkat +pub const AT_RECURSIVE: ::c_int = 0x8000; // mount_setattr pub const LOG_CRON: ::c_int = 9 << 3; pub const LOG_AUTHPRIV: ::c_int = 10 << 3; From 506493d0097edea3d2ca49e9c9430f3f9e8a458d Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Sun, 2 Jul 2023 23:59:57 -0700 Subject: [PATCH 2/4] Add auxvec.h to all Androids These values are universal across architectures, as they are defined primarily by the Linux UAPI. Thus adding them to only 64-bit was in error. --- libc-test/semver/android.txt | 1 + src/unix/linux_like/android/b64/mod.rs | 25 ------------------- src/unix/linux_like/android/mod.rs | 33 ++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 25 deletions(-) diff --git a/libc-test/semver/android.txt b/libc-test/semver/android.txt index 3bee01ca18385..e1bb449723b5a 100644 --- a/libc-test/semver/android.txt +++ b/libc-test/semver/android.txt @@ -137,6 +137,7 @@ ATF_PUBL ATF_USETRAILERS AT_EMPTY_PATH AT_FDCWD +AT_MINSIGSTKSZ AT_NO_AUTOMOUNT AT_RECURSIVE AT_REMOVEDIR diff --git a/src/unix/linux_like/android/b64/mod.rs b/src/unix/linux_like/android/b64/mod.rs index 67d0dacf17e93..97cf137b7fc79 100644 --- a/src/unix/linux_like/android/b64/mod.rs +++ b/src/unix/linux_like/android/b64/mod.rs @@ -264,31 +264,6 @@ pub const RTLD_GLOBAL: ::c_int = 0x00100; pub const RTLD_NOW: ::c_int = 2; pub const RTLD_DEFAULT: *mut ::c_void = 0i64 as *mut ::c_void; -// From NDK's linux/auxvec.h -pub const AT_NULL: ::c_ulong = 0; -pub const AT_IGNORE: ::c_ulong = 1; -pub const AT_EXECFD: ::c_ulong = 2; -pub const AT_PHDR: ::c_ulong = 3; -pub const AT_PHENT: ::c_ulong = 4; -pub const AT_PHNUM: ::c_ulong = 5; -pub const AT_PAGESZ: ::c_ulong = 6; -pub const AT_BASE: ::c_ulong = 7; -pub const AT_FLAGS: ::c_ulong = 8; -pub const AT_ENTRY: ::c_ulong = 9; -pub const AT_NOTELF: ::c_ulong = 10; -pub const AT_UID: ::c_ulong = 11; -pub const AT_EUID: ::c_ulong = 12; -pub const AT_GID: ::c_ulong = 13; -pub const AT_EGID: ::c_ulong = 14; -pub const AT_PLATFORM: ::c_ulong = 15; -pub const AT_HWCAP: ::c_ulong = 16; -pub const AT_CLKTCK: ::c_ulong = 17; -pub const AT_SECURE: ::c_ulong = 23; -pub const AT_BASE_PLATFORM: ::c_ulong = 24; -pub const AT_RANDOM: ::c_ulong = 25; -pub const AT_HWCAP2: ::c_ulong = 26; -pub const AT_EXECFN: ::c_ulong = 31; - pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t { value: 0, __reserved: [0; 36], diff --git a/src/unix/linux_like/android/mod.rs b/src/unix/linux_like/android/mod.rs index 2bc748ac4c303..6d67ac0174c79 100644 --- a/src/unix/linux_like/android/mod.rs +++ b/src/unix/linux_like/android/mod.rs @@ -1030,6 +1030,39 @@ pub const USER_PROCESS: ::c_short = 7; pub const _POSIX_VDISABLE: ::cc_t = 0; +// keys to the values in the ELF auxiliary vector, usable with getauxval +// found at uapi/linux/auxvec.h in the kernel +pub const AT_NULL: ::c_ulong = 0; +pub const AT_IGNORE: ::c_ulong = 1; +pub const AT_EXECFD: ::c_ulong = 2; +pub const AT_PHDR: ::c_ulong = 3; +pub const AT_PHENT: ::c_ulong = 4; +pub const AT_PHNUM: ::c_ulong = 5; +pub const AT_PAGESZ: ::c_ulong = 6; +pub const AT_BASE: ::c_ulong = 7; +pub const AT_FLAGS: ::c_ulong = 8; +pub const AT_ENTRY: ::c_ulong = 9; +pub const AT_NOTELF: ::c_ulong = 10; +pub const AT_UID: ::c_ulong = 11; +pub const AT_EUID: ::c_ulong = 12; +pub const AT_GID: ::c_ulong = 13; +pub const AT_EGID: ::c_ulong = 14; +pub const AT_PLATFORM: ::c_ulong = 15; +pub const AT_HWCAP: ::c_ulong = 16; +pub const AT_CLKTCK: ::c_ulong = 17; + +pub const AT_SECURE: ::c_ulong = 23; +pub const AT_BASE_PLATFORM: ::c_ulong = 24; +pub const AT_RANDOM: ::c_ulong = 25; +pub const AT_HWCAP2: ::c_ulong = 26; + +pub const AT_EXECFN: ::c_ulong = 31; + +pub const AT_MINSIGSTKSZ: ::c_ulong = 51; +// getauxval AT_* values should be current for all "architecture-neutral" ones as of +// Linux headers: include/uapi/linux/auxvec.h kernel 6.1 +// Android NDK: libc/kernel/uapi/linux/auxvec.h NDK 25 (updated ~5.14) + // linux/falloc.h pub const FALLOC_FL_KEEP_SIZE: ::c_int = 0x01; pub const FALLOC_FL_PUNCH_HOLE: ::c_int = 0x02; From bca14be24b0b03edc0b27777ce3357840d4527ce Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Mon, 3 Jul 2023 00:00:54 -0700 Subject: [PATCH 3/4] Add auxvec.h values to Linux These values are universal across architectures, as they are defined primarily by the Linux UAPI. They are also echoed exactly by musl and glibc. --- libc-test/semver/linux.txt | 1 + src/unix/linux_like/linux/mod.rs | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/libc-test/semver/linux.txt b/libc-test/semver/linux.txt index daccc3c38ddb4..279b0e6ca9f20 100644 --- a/libc-test/semver/linux.txt +++ b/libc-test/semver/linux.txt @@ -167,6 +167,7 @@ AT_GID AT_HWCAP AT_HWCAP2 AT_IGNORE +AT_MINSIGSTKSZ AT_NOTELF AT_NO_AUTOMOUNT AT_NULL diff --git a/src/unix/linux_like/linux/mod.rs b/src/unix/linux_like/linux/mod.rs index be12190b45dfc..ccfdbab6be149 100644 --- a/src/unix/linux_like/linux/mod.rs +++ b/src/unix/linux_like/linux/mod.rs @@ -22,6 +22,8 @@ pub type __s16 = ::c_short; pub type __u32 = ::c_uint; pub type __s32 = ::c_int; +// elf.h + pub type Elf32_Half = u16; pub type Elf32_Word = u32; pub type Elf32_Off = u32; @@ -1638,7 +1640,8 @@ pub const PF_R: u32 = 1 << 2; pub const PF_MASKOS: u32 = 0x0ff00000; pub const PF_MASKPROC: u32 = 0xf0000000; -// elf.h - Legal values for a_type (entry type). +// keys to the values in the ELF auxiliary vector, usable with getauxval +// found at uapi/linux/auxvec.h in the kernel and elf/elf.h in musl and glibc pub const AT_NULL: ::c_ulong = 0; pub const AT_IGNORE: ::c_ulong = 1; pub const AT_EXECFD: ::c_ulong = 2; @@ -1666,9 +1669,13 @@ pub const AT_HWCAP2: ::c_ulong = 26; pub const AT_EXECFN: ::c_ulong = 31; // defined in arch//include/uapi/asm/auxvec.h but has the same value -// wherever it is defined. +// wherever it is defined, and explicitly stated by glibc and musl pub const AT_SYSINFO_EHDR: ::c_ulong = 33; +pub const AT_MINSIGSTKSZ: ::c_ulong = 51; +// getauxval AT_* values should be current for all "architecture-neutral" ones as of +// Linux headers: include/uapi/linux/auxvec.h kernel 6.1 + pub const GLOB_ERR: ::c_int = 1 << 0; pub const GLOB_MARK: ::c_int = 1 << 1; pub const GLOB_NOSORT: ::c_int = 1 << 2; From fa3fa1d4bb894e97ba289a488dcd1b13cb35bd62 Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Mon, 10 Jul 2023 13:37:03 -0700 Subject: [PATCH 4/4] Add more comments to AT_* values Some return values require special thought in Rust, e.g. addresses that may violate "strict provenance", or ones with special, hardware-specific meaning. So note when the return value is meant to be an address or has platform-specific interpretation. --- src/unix/linux_like/android/mod.rs | 25 ++++++++++++++++--------- src/unix/linux_like/linux/mod.rs | 22 ++++++++++++---------- 2 files changed, 28 insertions(+), 19 deletions(-) diff --git a/src/unix/linux_like/android/mod.rs b/src/unix/linux_like/android/mod.rs index 6d67ac0174c79..3a942c681562e 100644 --- a/src/unix/linux_like/android/mod.rs +++ b/src/unix/linux_like/android/mod.rs @@ -1032,31 +1032,38 @@ pub const _POSIX_VDISABLE: ::cc_t = 0; // keys to the values in the ELF auxiliary vector, usable with getauxval // found at uapi/linux/auxvec.h in the kernel +// `man getauxval` for docs. briefly: returns a c_ulong but some are meant as addresses +// a return of 0 can mean "no entry", in which case bionic sets errno = ENOENT pub const AT_NULL: ::c_ulong = 0; pub const AT_IGNORE: ::c_ulong = 1; pub const AT_EXECFD: ::c_ulong = 2; -pub const AT_PHDR: ::c_ulong = 3; +pub const AT_PHDR: ::c_ulong = 3; // address of ELF's program headers pub const AT_PHENT: ::c_ulong = 4; pub const AT_PHNUM: ::c_ulong = 5; pub const AT_PAGESZ: ::c_ulong = 6; -pub const AT_BASE: ::c_ulong = 7; +pub const AT_BASE: ::c_ulong = 7; // address of ld.so pub const AT_FLAGS: ::c_ulong = 8; -pub const AT_ENTRY: ::c_ulong = 9; +pub const AT_ENTRY: ::c_ulong = 9; // address of _start pub const AT_NOTELF: ::c_ulong = 10; pub const AT_UID: ::c_ulong = 11; pub const AT_EUID: ::c_ulong = 12; pub const AT_GID: ::c_ulong = 13; pub const AT_EGID: ::c_ulong = 14; -pub const AT_PLATFORM: ::c_ulong = 15; -pub const AT_HWCAP: ::c_ulong = 16; +pub const AT_PLATFORM: ::c_ulong = 15; // address of a cstr naming the hardware +pub const AT_HWCAP: ::c_ulong = 16; // arch/ABI-specific bitmask pub const AT_CLKTCK: ::c_ulong = 17; pub const AT_SECURE: ::c_ulong = 23; -pub const AT_BASE_PLATFORM: ::c_ulong = 24; -pub const AT_RANDOM: ::c_ulong = 25; -pub const AT_HWCAP2: ::c_ulong = 26; +pub const AT_BASE_PLATFORM: ::c_ulong = 24; // address of a cstr, arch-specific meaning +pub const AT_RANDOM: ::c_ulong = 25; // address of [u8; 16] +pub const AT_HWCAP2: ::c_ulong = 26; // AT_HWCAP ran out of bits -pub const AT_EXECFN: ::c_ulong = 31; +pub const AT_EXECFN: ::c_ulong = 31; // address of executable path name + +// You may be expecting this here: +// pub const AT_SYSINFO_EHDR: ::c_ulong = 33; +// Currently it's not defined for Android, as it is defined explicitly by musl and glibc +// whereas bionic just references kernel headers, which do not for all architectures pub const AT_MINSIGSTKSZ: ::c_ulong = 51; // getauxval AT_* values should be current for all "architecture-neutral" ones as of diff --git a/src/unix/linux_like/linux/mod.rs b/src/unix/linux_like/linux/mod.rs index ccfdbab6be149..90c6e42281d02 100644 --- a/src/unix/linux_like/linux/mod.rs +++ b/src/unix/linux_like/linux/mod.rs @@ -1642,35 +1642,37 @@ pub const PF_MASKPROC: u32 = 0xf0000000; // keys to the values in the ELF auxiliary vector, usable with getauxval // found at uapi/linux/auxvec.h in the kernel and elf/elf.h in musl and glibc +// `man getauxval` for docs. briefly: returns a c_ulong but some are meant as addresses +// a return of 0 can mean "no entry", in which case musl and glibc set errno = ENOENT pub const AT_NULL: ::c_ulong = 0; pub const AT_IGNORE: ::c_ulong = 1; pub const AT_EXECFD: ::c_ulong = 2; -pub const AT_PHDR: ::c_ulong = 3; +pub const AT_PHDR: ::c_ulong = 3; // address of ELF's program headers pub const AT_PHENT: ::c_ulong = 4; pub const AT_PHNUM: ::c_ulong = 5; pub const AT_PAGESZ: ::c_ulong = 6; -pub const AT_BASE: ::c_ulong = 7; +pub const AT_BASE: ::c_ulong = 7; // address of ld.so pub const AT_FLAGS: ::c_ulong = 8; -pub const AT_ENTRY: ::c_ulong = 9; +pub const AT_ENTRY: ::c_ulong = 9; // address of _start pub const AT_NOTELF: ::c_ulong = 10; pub const AT_UID: ::c_ulong = 11; pub const AT_EUID: ::c_ulong = 12; pub const AT_GID: ::c_ulong = 13; pub const AT_EGID: ::c_ulong = 14; -pub const AT_PLATFORM: ::c_ulong = 15; -pub const AT_HWCAP: ::c_ulong = 16; +pub const AT_PLATFORM: ::c_ulong = 15; // address of a cstr naming the hardware +pub const AT_HWCAP: ::c_ulong = 16; // arch/ABI-specific bitmask pub const AT_CLKTCK: ::c_ulong = 17; pub const AT_SECURE: ::c_ulong = 23; -pub const AT_BASE_PLATFORM: ::c_ulong = 24; -pub const AT_RANDOM: ::c_ulong = 25; -pub const AT_HWCAP2: ::c_ulong = 26; +pub const AT_BASE_PLATFORM: ::c_ulong = 24; // address of a cstr, arch-specific meaning +pub const AT_RANDOM: ::c_ulong = 25; // address of [u8; 16] +pub const AT_HWCAP2: ::c_ulong = 26; // AT_HWCAP ran out of bits -pub const AT_EXECFN: ::c_ulong = 31; +pub const AT_EXECFN: ::c_ulong = 31; // address of executable path name // defined in arch//include/uapi/asm/auxvec.h but has the same value // wherever it is defined, and explicitly stated by glibc and musl -pub const AT_SYSINFO_EHDR: ::c_ulong = 33; +pub const AT_SYSINFO_EHDR: ::c_ulong = 33; // address of vDSO page pub const AT_MINSIGSTKSZ: ::c_ulong = 51; // getauxval AT_* values should be current for all "architecture-neutral" ones as of