Remove the `AT_NULL` variant

This commit is contained in:
Ruihan Li 2026-01-14 00:39:45 +08:00 committed by Jianfeng Jiang
parent 48ccafd7f9
commit fdcf5fd0fe
3 changed files with 16 additions and 18 deletions

View File

@ -17,7 +17,6 @@ use crate::prelude::*;
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[repr(u8)]
pub enum AuxKey {
AT_NULL = 0, /* end of vector */
AT_IGNORE = 1, /* entry should be ignored */
AT_EXECFD = 2, /* file descriptor of program */
AT_PHDR = 3, /* program headers for program */
@ -49,6 +48,11 @@ pub enum AuxKey {
AT_SYSINFO_EHDR = 33, /* the start address of the page containing the VDSO */
}
impl AuxKey {
/// A special auxiliary key that denotes the end of the auxiliary vector.
pub(super) const AT_NULL: u8 = 0;
}
#[derive(Clone, Default, Debug)]
pub struct AuxVec {
table: BTreeMap<AuxKey, u64>,
@ -61,18 +65,14 @@ impl AuxVec {
}
}
pub fn set(&mut self, key: AuxKey, val: u64) -> Result<()> {
if key == AuxKey::AT_NULL || key == AuxKey::AT_IGNORE {
return_errno_with_message!(Errno::EINVAL, "Illegal key");
}
pub fn set(&mut self, key: AuxKey, val: u64) {
self.table
.entry(key)
.and_modify(|val_mut| *val_mut = val)
.or_insert(val);
Ok(())
}
pub fn table(&self) -> &BTreeMap<AuxKey, u64> {
pub(super) fn table(&self) -> &BTreeMap<AuxKey, u64> {
&self.table
}
}

View File

@ -259,7 +259,7 @@ impl InitStackWriter<'_> {
let random_value = generate_random_for_aux_vec();
self.write_bytes(&random_value)?
};
self.auxvec.set(AuxKey::AT_RANDOM, random_value_pointer)?;
self.auxvec.set(AuxKey::AT_RANDOM, random_value_pointer);
self.adjust_stack_alignment(&envp_pointers, &argv_pointers)?;
self.write_aux_vec()?;

View File

@ -74,9 +74,7 @@ pub fn load_elf_to_vmar(
if let Some(vdso_text_base) = map_vdso_to_vmar(vmar) {
#[cfg(target_arch = "riscv64")]
vmar.process_vm().set_vdso_base(vdso_text_base);
aux_vec
.set(AuxKey::AT_SYSINFO_EHDR, vdso_text_base as u64)
.unwrap();
aux_vec.set(AuxKey::AT_SYSINFO_EHDR, vdso_text_base as u64);
}
vmar.process_vm()
@ -166,7 +164,7 @@ fn map_vmos_and_build_aux_vec(
} else {
0
};
aux_vec.set(AuxKey::AT_SECURE, secure)?;
aux_vec.set(AuxKey::AT_SECURE, secure);
let entry_point = if let Some(ldso_load_info) = ldso_load_info {
ldso_load_info.entry_point
@ -431,7 +429,7 @@ fn init_aux_vec(
) -> Result<AuxVec> {
let mut aux_vec = AuxVec::new();
aux_vec.set(AuxKey::AT_PAGESZ, PAGE_SIZE as _)?;
aux_vec.set(AuxKey::AT_PAGESZ, PAGE_SIZE as _);
let Some(ph_vaddr) = elf_map_range.relocated_addr_of(elf.find_vaddr_of_phdrs()?) else {
return_errno_with_message!(
@ -439,9 +437,9 @@ fn init_aux_vec(
"the ELF program headers are not located in any segments"
);
};
aux_vec.set(AuxKey::AT_PHDR, ph_vaddr as u64)?;
aux_vec.set(AuxKey::AT_PHNUM, elf.ph_count() as u64)?;
aux_vec.set(AuxKey::AT_PHENT, elf.ph_ent() as u64)?;
aux_vec.set(AuxKey::AT_PHDR, ph_vaddr as u64);
aux_vec.set(AuxKey::AT_PHNUM, elf.ph_count() as u64);
aux_vec.set(AuxKey::AT_PHENT, elf.ph_ent() as u64);
let Some(entry_vaddr) = elf_map_range.relocated_addr_of(elf.entry_point()) else {
return_errno_with_message!(
@ -449,10 +447,10 @@ fn init_aux_vec(
"the entry point is not located in any segments"
);
};
aux_vec.set(AuxKey::AT_ENTRY, entry_vaddr as u64)?;
aux_vec.set(AuxKey::AT_ENTRY, entry_vaddr as u64);
if let Some(ldso_base) = ldso_base {
aux_vec.set(AuxKey::AT_BASE, ldso_base as u64)?;
aux_vec.set(AuxKey::AT_BASE, ldso_base as u64);
}
Ok(aux_vec)