Skip to content

Commit 878bbb5

Browse files
committed
Auto merge of #3125 - workingjubilee:joy/unified-auxvec.rs, r=JohnTitor
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.
2 parents a1ad825 + fa3fa1d commit 878bbb5

File tree

6 files changed

+71
-44
lines changed

6 files changed

+71
-44
lines changed

libc-test/semver/android.txt

+1
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ ATF_PUBL
138138
ATF_USETRAILERS
139139
AT_EMPTY_PATH
140140
AT_FDCWD
141+
AT_MINSIGSTKSZ
141142
AT_NO_AUTOMOUNT
142143
AT_RECURSIVE
143144
AT_REMOVEDIR

libc-test/semver/linux.txt

+1
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ AT_GID
169169
AT_HWCAP
170170
AT_HWCAP2
171171
AT_IGNORE
172+
AT_MINSIGSTKSZ
172173
AT_NOTELF
173174
AT_NO_AUTOMOUNT
174175
AT_NULL

src/unix/linux_like/android/b64/mod.rs

-25
Original file line numberDiff line numberDiff line change
@@ -264,31 +264,6 @@ pub const RTLD_GLOBAL: ::c_int = 0x00100;
264264
pub const RTLD_NOW: ::c_int = 2;
265265
pub const RTLD_DEFAULT: *mut ::c_void = 0i64 as *mut ::c_void;
266266

267-
// From NDK's linux/auxvec.h
268-
pub const AT_NULL: ::c_ulong = 0;
269-
pub const AT_IGNORE: ::c_ulong = 1;
270-
pub const AT_EXECFD: ::c_ulong = 2;
271-
pub const AT_PHDR: ::c_ulong = 3;
272-
pub const AT_PHENT: ::c_ulong = 4;
273-
pub const AT_PHNUM: ::c_ulong = 5;
274-
pub const AT_PAGESZ: ::c_ulong = 6;
275-
pub const AT_BASE: ::c_ulong = 7;
276-
pub const AT_FLAGS: ::c_ulong = 8;
277-
pub const AT_ENTRY: ::c_ulong = 9;
278-
pub const AT_NOTELF: ::c_ulong = 10;
279-
pub const AT_UID: ::c_ulong = 11;
280-
pub const AT_EUID: ::c_ulong = 12;
281-
pub const AT_GID: ::c_ulong = 13;
282-
pub const AT_EGID: ::c_ulong = 14;
283-
pub const AT_PLATFORM: ::c_ulong = 15;
284-
pub const AT_HWCAP: ::c_ulong = 16;
285-
pub const AT_CLKTCK: ::c_ulong = 17;
286-
pub const AT_SECURE: ::c_ulong = 23;
287-
pub const AT_BASE_PLATFORM: ::c_ulong = 24;
288-
pub const AT_RANDOM: ::c_ulong = 25;
289-
pub const AT_HWCAP2: ::c_ulong = 26;
290-
pub const AT_EXECFN: ::c_ulong = 31;
291-
292267
pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t {
293268
value: 0,
294269
__reserved: [0; 36],

src/unix/linux_like/android/mod.rs

+40
Original file line numberDiff line numberDiff line change
@@ -1035,6 +1035,46 @@ pub const USER_PROCESS: ::c_short = 7;
10351035

10361036
pub const _POSIX_VDISABLE: ::cc_t = 0;
10371037

1038+
// keys to the values in the ELF auxiliary vector, usable with getauxval
1039+
// found at uapi/linux/auxvec.h in the kernel
1040+
// `man getauxval` for docs. briefly: returns a c_ulong but some are meant as addresses
1041+
// a return of 0 can mean "no entry", in which case bionic sets errno = ENOENT
1042+
pub const AT_NULL: ::c_ulong = 0;
1043+
pub const AT_IGNORE: ::c_ulong = 1;
1044+
pub const AT_EXECFD: ::c_ulong = 2;
1045+
pub const AT_PHDR: ::c_ulong = 3; // address of ELF's program headers
1046+
pub const AT_PHENT: ::c_ulong = 4;
1047+
pub const AT_PHNUM: ::c_ulong = 5;
1048+
pub const AT_PAGESZ: ::c_ulong = 6;
1049+
pub const AT_BASE: ::c_ulong = 7; // address of ld.so
1050+
pub const AT_FLAGS: ::c_ulong = 8;
1051+
pub const AT_ENTRY: ::c_ulong = 9; // address of _start
1052+
pub const AT_NOTELF: ::c_ulong = 10;
1053+
pub const AT_UID: ::c_ulong = 11;
1054+
pub const AT_EUID: ::c_ulong = 12;
1055+
pub const AT_GID: ::c_ulong = 13;
1056+
pub const AT_EGID: ::c_ulong = 14;
1057+
pub const AT_PLATFORM: ::c_ulong = 15; // address of a cstr naming the hardware
1058+
pub const AT_HWCAP: ::c_ulong = 16; // arch/ABI-specific bitmask
1059+
pub const AT_CLKTCK: ::c_ulong = 17;
1060+
1061+
pub const AT_SECURE: ::c_ulong = 23;
1062+
pub const AT_BASE_PLATFORM: ::c_ulong = 24; // address of a cstr, arch-specific meaning
1063+
pub const AT_RANDOM: ::c_ulong = 25; // address of [u8; 16]
1064+
pub const AT_HWCAP2: ::c_ulong = 26; // AT_HWCAP ran out of bits
1065+
1066+
pub const AT_EXECFN: ::c_ulong = 31; // address of executable path name
1067+
1068+
// You may be expecting this here:
1069+
// pub const AT_SYSINFO_EHDR: ::c_ulong = 33;
1070+
// Currently it's not defined for Android, as it is defined explicitly by musl and glibc
1071+
// whereas bionic just references kernel headers, which do not for all architectures
1072+
1073+
pub const AT_MINSIGSTKSZ: ::c_ulong = 51;
1074+
// getauxval AT_* values should be current for all "architecture-neutral" ones as of
1075+
// Linux headers: include/uapi/linux/auxvec.h kernel 6.1
1076+
// Android NDK: libc/kernel/uapi/linux/auxvec.h NDK 25 (updated ~5.14)
1077+
10381078
// linux/falloc.h
10391079
pub const FALLOC_FL_KEEP_SIZE: ::c_int = 0x01;
10401080
pub const FALLOC_FL_PUNCH_HOLE: ::c_int = 0x02;

src/unix/linux_like/linux/mod.rs

+21-12
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ pub type __s16 = ::c_short;
2323
pub type __u32 = ::c_uint;
2424
pub type __s32 = ::c_int;
2525

26+
// elf.h
27+
2628
pub type Elf32_Half = u16;
2729
pub type Elf32_Word = u32;
2830
pub type Elf32_Off = u32;
@@ -1670,36 +1672,43 @@ pub const PF_R: u32 = 1 << 2;
16701672
pub const PF_MASKOS: u32 = 0x0ff00000;
16711673
pub const PF_MASKPROC: u32 = 0xf0000000;
16721674

1673-
// elf.h - Legal values for a_type (entry type).
1675+
// keys to the values in the ELF auxiliary vector, usable with getauxval
1676+
// found at uapi/linux/auxvec.h in the kernel and elf/elf.h in musl and glibc
1677+
// `man getauxval` for docs. briefly: returns a c_ulong but some are meant as addresses
1678+
// a return of 0 can mean "no entry", in which case musl and glibc set errno = ENOENT
16741679
pub const AT_NULL: ::c_ulong = 0;
16751680
pub const AT_IGNORE: ::c_ulong = 1;
16761681
pub const AT_EXECFD: ::c_ulong = 2;
1677-
pub const AT_PHDR: ::c_ulong = 3;
1682+
pub const AT_PHDR: ::c_ulong = 3; // address of ELF's program headers
16781683
pub const AT_PHENT: ::c_ulong = 4;
16791684
pub const AT_PHNUM: ::c_ulong = 5;
16801685
pub const AT_PAGESZ: ::c_ulong = 6;
1681-
pub const AT_BASE: ::c_ulong = 7;
1686+
pub const AT_BASE: ::c_ulong = 7; // address of ld.so
16821687
pub const AT_FLAGS: ::c_ulong = 8;
1683-
pub const AT_ENTRY: ::c_ulong = 9;
1688+
pub const AT_ENTRY: ::c_ulong = 9; // address of _start
16841689
pub const AT_NOTELF: ::c_ulong = 10;
16851690
pub const AT_UID: ::c_ulong = 11;
16861691
pub const AT_EUID: ::c_ulong = 12;
16871692
pub const AT_GID: ::c_ulong = 13;
16881693
pub const AT_EGID: ::c_ulong = 14;
1689-
pub const AT_PLATFORM: ::c_ulong = 15;
1690-
pub const AT_HWCAP: ::c_ulong = 16;
1694+
pub const AT_PLATFORM: ::c_ulong = 15; // address of a cstr naming the hardware
1695+
pub const AT_HWCAP: ::c_ulong = 16; // arch/ABI-specific bitmask
16911696
pub const AT_CLKTCK: ::c_ulong = 17;
16921697

16931698
pub const AT_SECURE: ::c_ulong = 23;
1694-
pub const AT_BASE_PLATFORM: ::c_ulong = 24;
1695-
pub const AT_RANDOM: ::c_ulong = 25;
1696-
pub const AT_HWCAP2: ::c_ulong = 26;
1699+
pub const AT_BASE_PLATFORM: ::c_ulong = 24; // address of a cstr, arch-specific meaning
1700+
pub const AT_RANDOM: ::c_ulong = 25; // address of [u8; 16]
1701+
pub const AT_HWCAP2: ::c_ulong = 26; // AT_HWCAP ran out of bits
16971702

1698-
pub const AT_EXECFN: ::c_ulong = 31;
1703+
pub const AT_EXECFN: ::c_ulong = 31; // address of executable path name
16991704

17001705
// defined in arch/<arch>/include/uapi/asm/auxvec.h but has the same value
1701-
// wherever it is defined.
1702-
pub const AT_SYSINFO_EHDR: ::c_ulong = 33;
1706+
// wherever it is defined, and explicitly stated by glibc and musl
1707+
pub const AT_SYSINFO_EHDR: ::c_ulong = 33; // address of vDSO page
1708+
1709+
pub const AT_MINSIGSTKSZ: ::c_ulong = 51;
1710+
// getauxval AT_* values should be current for all "architecture-neutral" ones as of
1711+
// Linux headers: include/uapi/linux/auxvec.h kernel 6.1
17031712

17041713
pub const GLOB_ERR: ::c_int = 1 << 0;
17051714
pub const GLOB_MARK: ::c_int = 1 << 1;

src/unix/linux_like/mod.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -1237,13 +1237,14 @@ pub const POSIX_FADV_RANDOM: ::c_int = 1;
12371237
pub const POSIX_FADV_SEQUENTIAL: ::c_int = 2;
12381238
pub const POSIX_FADV_WILLNEED: ::c_int = 3;
12391239

1240-
pub const AT_FDCWD: ::c_int = -100;
1241-
pub const AT_SYMLINK_NOFOLLOW: ::c_int = 0x100;
1242-
pub const AT_REMOVEDIR: ::c_int = 0x200;
1243-
pub const AT_SYMLINK_FOLLOW: ::c_int = 0x400;
1244-
pub const AT_NO_AUTOMOUNT: ::c_int = 0x800;
1245-
pub const AT_EMPTY_PATH: ::c_int = 0x1000;
1246-
pub const AT_RECURSIVE: ::c_int = 0x8000;
1240+
// flags for "at"-suffixed file operations, e.g. execveat, openat
1241+
pub const AT_FDCWD: ::c_int = -100; // used instead of dirfd
1242+
pub const AT_REMOVEDIR: ::c_int = 0x200; // unlinkat
1243+
pub const AT_SYMLINK_NOFOLLOW: ::c_int = 0x100; // fstatat
1244+
pub const AT_NO_AUTOMOUNT: ::c_int = 0x800; // fstatat
1245+
pub const AT_SYMLINK_FOLLOW: ::c_int = 0x400; // linkat
1246+
pub const AT_EMPTY_PATH: ::c_int = 0x1000; // linkat
1247+
pub const AT_RECURSIVE: ::c_int = 0x8000; // mount_setattr
12471248

12481249
pub const LOG_CRON: ::c_int = 9 << 3;
12491250
pub const LOG_AUTHPRIV: ::c_int = 10 << 3;

0 commit comments

Comments
 (0)