#[derive(Debug)]
pub struct AuxValues {
pub at_base: usize,
pub at_gid: usize,
pub at_uid: usize,
pub at_phdr: usize,
pub at_phent: usize,
pub at_phnum: usize,
pub at_random: usize,
pub at_secure: usize,
pub at_sysinfo_ehdr: usize,
pub at_execfn: usize,
}
impl AuxValues {
#[inline(always)]
#[must_use]
pub const fn zeroed() -> Self {
Self {
at_base: 0,
at_gid: 0,
at_uid: 0,
at_phdr: 0,
at_phent: 0,
at_phnum: 0,
at_random: 0,
at_secure: 0,
at_sysinfo_ehdr: 0,
at_execfn: 0,
}
}
#[must_use]
#[inline(always)]
#[expect(clippy::cast_possible_wrap, clippy::cast_possible_truncation)]
pub(crate) unsafe fn from_auxv(auxv: *const usize) -> Self {
let mut collected = Self::zeroed();
let mut i = 0;
let mut key = *auxv;
while key != 0 {
if key <= 51 {
match key as i32 {
rusl::platform::AT_PHDR => collected.at_phdr = *(auxv.add(i + 1)),
rusl::platform::AT_PHENT => collected.at_phent = *(auxv.add(i + 1)),
rusl::platform::AT_PHNUM => collected.at_phnum = *(auxv.add(i + 1)),
rusl::platform::AT_BASE => collected.at_base = *(auxv.add(i + 1)),
rusl::platform::AT_UID => collected.at_uid = *(auxv.add(i + 1)),
rusl::platform::AT_GID => collected.at_gid = *(auxv.add(i + 1)),
rusl::platform::AT_SECURE => collected.at_secure = *(auxv.add(i + 1)),
rusl::platform::AT_RANDOM => collected.at_random = *(auxv.add(i + 1)),
rusl::platform::AT_SYSINFO_EHDR => {
collected.at_sysinfo_ehdr = *(auxv.add(i + 1));
}
rusl::platform::AT_EXECFN => collected.at_execfn = *(auxv.add(i + 1)),
_ => {}
}
}
i += 2;
key = *(auxv.add(i));
}
collected
}
}