Skip to content

Commit fa3fa1d

Browse files
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.
1 parent bca14be commit fa3fa1d

File tree

2 files changed

+28
-19
lines changed

2 files changed

+28
-19
lines changed

src/unix/linux_like/android/mod.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,31 +1032,38 @@ pub const _POSIX_VDISABLE: ::cc_t = 0;
10321032

10331033
// keys to the values in the ELF auxiliary vector, usable with getauxval
10341034
// found at uapi/linux/auxvec.h in the kernel
1035+
// `man getauxval` for docs. briefly: returns a c_ulong but some are meant as addresses
1036+
// a return of 0 can mean "no entry", in which case bionic sets errno = ENOENT
10351037
pub const AT_NULL: ::c_ulong = 0;
10361038
pub const AT_IGNORE: ::c_ulong = 1;
10371039
pub const AT_EXECFD: ::c_ulong = 2;
1038-
pub const AT_PHDR: ::c_ulong = 3;
1040+
pub const AT_PHDR: ::c_ulong = 3; // address of ELF's program headers
10391041
pub const AT_PHENT: ::c_ulong = 4;
10401042
pub const AT_PHNUM: ::c_ulong = 5;
10411043
pub const AT_PAGESZ: ::c_ulong = 6;
1042-
pub const AT_BASE: ::c_ulong = 7;
1044+
pub const AT_BASE: ::c_ulong = 7; // address of ld.so
10431045
pub const AT_FLAGS: ::c_ulong = 8;
1044-
pub const AT_ENTRY: ::c_ulong = 9;
1046+
pub const AT_ENTRY: ::c_ulong = 9; // address of _start
10451047
pub const AT_NOTELF: ::c_ulong = 10;
10461048
pub const AT_UID: ::c_ulong = 11;
10471049
pub const AT_EUID: ::c_ulong = 12;
10481050
pub const AT_GID: ::c_ulong = 13;
10491051
pub const AT_EGID: ::c_ulong = 14;
1050-
pub const AT_PLATFORM: ::c_ulong = 15;
1051-
pub const AT_HWCAP: ::c_ulong = 16;
1052+
pub const AT_PLATFORM: ::c_ulong = 15; // address of a cstr naming the hardware
1053+
pub const AT_HWCAP: ::c_ulong = 16; // arch/ABI-specific bitmask
10521054
pub const AT_CLKTCK: ::c_ulong = 17;
10531055

10541056
pub const AT_SECURE: ::c_ulong = 23;
1055-
pub const AT_BASE_PLATFORM: ::c_ulong = 24;
1056-
pub const AT_RANDOM: ::c_ulong = 25;
1057-
pub const AT_HWCAP2: ::c_ulong = 26;
1057+
pub const AT_BASE_PLATFORM: ::c_ulong = 24; // address of a cstr, arch-specific meaning
1058+
pub const AT_RANDOM: ::c_ulong = 25; // address of [u8; 16]
1059+
pub const AT_HWCAP2: ::c_ulong = 26; // AT_HWCAP ran out of bits
10581060

1059-
pub const AT_EXECFN: ::c_ulong = 31;
1061+
pub const AT_EXECFN: ::c_ulong = 31; // address of executable path name
1062+
1063+
// You may be expecting this here:
1064+
// pub const AT_SYSINFO_EHDR: ::c_ulong = 33;
1065+
// Currently it's not defined for Android, as it is defined explicitly by musl and glibc
1066+
// whereas bionic just references kernel headers, which do not for all architectures
10601067

10611068
pub const AT_MINSIGSTKSZ: ::c_ulong = 51;
10621069
// getauxval AT_* values should be current for all "architecture-neutral" ones as of

src/unix/linux_like/linux/mod.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1642,35 +1642,37 @@ pub const PF_MASKPROC: u32 = 0xf0000000;
16421642

16431643
// keys to the values in the ELF auxiliary vector, usable with getauxval
16441644
// found at uapi/linux/auxvec.h in the kernel and elf/elf.h in musl and glibc
1645+
// `man getauxval` for docs. briefly: returns a c_ulong but some are meant as addresses
1646+
// a return of 0 can mean "no entry", in which case musl and glibc set errno = ENOENT
16451647
pub const AT_NULL: ::c_ulong = 0;
16461648
pub const AT_IGNORE: ::c_ulong = 1;
16471649
pub const AT_EXECFD: ::c_ulong = 2;
1648-
pub const AT_PHDR: ::c_ulong = 3;
1650+
pub const AT_PHDR: ::c_ulong = 3; // address of ELF's program headers
16491651
pub const AT_PHENT: ::c_ulong = 4;
16501652
pub const AT_PHNUM: ::c_ulong = 5;
16511653
pub const AT_PAGESZ: ::c_ulong = 6;
1652-
pub const AT_BASE: ::c_ulong = 7;
1654+
pub const AT_BASE: ::c_ulong = 7; // address of ld.so
16531655
pub const AT_FLAGS: ::c_ulong = 8;
1654-
pub const AT_ENTRY: ::c_ulong = 9;
1656+
pub const AT_ENTRY: ::c_ulong = 9; // address of _start
16551657
pub const AT_NOTELF: ::c_ulong = 10;
16561658
pub const AT_UID: ::c_ulong = 11;
16571659
pub const AT_EUID: ::c_ulong = 12;
16581660
pub const AT_GID: ::c_ulong = 13;
16591661
pub const AT_EGID: ::c_ulong = 14;
1660-
pub const AT_PLATFORM: ::c_ulong = 15;
1661-
pub const AT_HWCAP: ::c_ulong = 16;
1662+
pub const AT_PLATFORM: ::c_ulong = 15; // address of a cstr naming the hardware
1663+
pub const AT_HWCAP: ::c_ulong = 16; // arch/ABI-specific bitmask
16621664
pub const AT_CLKTCK: ::c_ulong = 17;
16631665

16641666
pub const AT_SECURE: ::c_ulong = 23;
1665-
pub const AT_BASE_PLATFORM: ::c_ulong = 24;
1666-
pub const AT_RANDOM: ::c_ulong = 25;
1667-
pub const AT_HWCAP2: ::c_ulong = 26;
1667+
pub const AT_BASE_PLATFORM: ::c_ulong = 24; // address of a cstr, arch-specific meaning
1668+
pub const AT_RANDOM: ::c_ulong = 25; // address of [u8; 16]
1669+
pub const AT_HWCAP2: ::c_ulong = 26; // AT_HWCAP ran out of bits
16681670

1669-
pub const AT_EXECFN: ::c_ulong = 31;
1671+
pub const AT_EXECFN: ::c_ulong = 31; // address of executable path name
16701672

16711673
// defined in arch/<arch>/include/uapi/asm/auxvec.h but has the same value
16721674
// wherever it is defined, and explicitly stated by glibc and musl
1673-
pub const AT_SYSINFO_EHDR: ::c_ulong = 33;
1675+
pub const AT_SYSINFO_EHDR: ::c_ulong = 33; // address of vDSO page
16741676

16751677
pub const AT_MINSIGSTKSZ: ::c_ulong = 51;
16761678
// getauxval AT_* values should be current for all "architecture-neutral" ones as of

0 commit comments

Comments
 (0)