Skip to content

Commit

Permalink
Auto merge of #3125 - workingjubilee:joy/unified-auxvec.rs, r=JohnTitor
Browse files Browse the repository at this point in the history
Update auxvec.h for Android and Linux

The NDK automatically generates these constants from Linux kernel headers, and they are available for all architectures. They are also repeated by musl and glibc, though this is mostly just a restatement to make use with getauxval more convenient.

New in this patch: `AT_MINSIGSTKSZ`

This const is needed to handle new extensions to platform arches that add state to save to signal stacks, replacing `MINSIGSTKSZ` with an ELF-loaded equivalent.
  • Loading branch information
bors committed Nov 1, 2023
2 parents a1ad825 + fa3fa1d commit 5856fb7
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 44 deletions.
1 change: 1 addition & 0 deletions libc-test/semver/android.txt
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ ATF_PUBL
ATF_USETRAILERS
AT_EMPTY_PATH
AT_FDCWD
AT_MINSIGSTKSZ
AT_NO_AUTOMOUNT
AT_RECURSIVE
AT_REMOVEDIR
Expand Down
1 change: 1 addition & 0 deletions libc-test/semver/linux.txt
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ AT_GID
AT_HWCAP
AT_HWCAP2
AT_IGNORE
AT_MINSIGSTKSZ
AT_NOTELF
AT_NO_AUTOMOUNT
AT_NULL
Expand Down
25 changes: 0 additions & 25 deletions src/unix/linux_like/android/b64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
40 changes: 40 additions & 0 deletions src/unix/linux_like/android/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1035,6 +1035,46 @@ 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
// `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; // 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; // address of ld.so
pub const AT_FLAGS: ::c_ulong = 8;
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; // 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; // 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; // 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
// 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;
Expand Down
33 changes: 21 additions & 12 deletions src/unix/linux_like/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,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;
Expand Down Expand Up @@ -1670,36 +1672,43 @@ 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
// `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/<arch>/include/uapi/asm/auxvec.h but has the same value
// wherever it is defined.
pub const AT_SYSINFO_EHDR: ::c_ulong = 33;
// wherever it is defined, and explicitly stated by glibc and musl
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
// 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;
Expand Down
15 changes: 8 additions & 7 deletions src/unix/linux_like/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1237,13 +1237,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;
Expand Down

0 comments on commit 5856fb7

Please sign in to comment.