AuxVar

Enum AuxVar 

Source
pub enum AuxVar<'a> {
Show 34 variants Null, Ignore, ExecFd(usize), Phdr(*const u8), Phent(usize), Phnum(usize), Pagesz(usize), Base(*const u8), Flags(AuxVarFlags), Entry(*const u8), NotElf(bool), Uid(usize), EUid(usize), Gid(usize), EGid(usize), Platform(AuxVarString<'a>), HwCap(usize), Clktck(usize), Secure(bool), BasePlatform(AuxVarString<'a>), Random([u8; 16]), HwCap2(usize), ExecFn(AuxVarString<'a>), Sysinfo(*const u8), SysinfoEhdr(*const u8), L1iCacheSize(usize), L1iCacheGeometry(usize), L1dCacheSize(usize), L1dCacheGeometry(usize), L2CacheSize(usize), L2CacheGeometry(usize), L3CacheSize(usize), L3CacheGeometry(usize), MinSigStkSz(usize),
}
Expand description

High-level version of an auxiliary vector (auxv) entry. Also called Auxiliary Variable or AT Variable.

The data/payload is either an immediate value embedded into the enum variant or a pointer into the auxv data area. The enum variant’s payload does not necessarily correspond to the ABI.

§More Info

Variants§

§

Null

Entry with payload for type AuxVarType::Null.

§

Ignore

Entry with payload for type AuxVarType::Ignore.

§

ExecFd(usize)

Entry with payload for type AuxVarType::ExecFd.

§

Phdr(*const u8)

Entry with payload for type AuxVarType::Phdr.

§

Phent(usize)

Entry with payload for type AuxVarType::Phent.

§

Phnum(usize)

Entry with payload for type AuxVarType::Phnum.

§

Pagesz(usize)

Entry with payload for type AuxVarType::Pagesz.

§

Base(*const u8)

Entry with payload for type AuxVarType::Base.

§

Flags(AuxVarFlags)

Entry with payload for type AuxVarType::Flags.

§

Entry(*const u8)

Entry with payload for type AuxVarType::Entry.

§

NotElf(bool)

Entry with payload for type AuxVarType::NotElf.

§

Uid(usize)

Entry with payload for type AuxVarType::Uid.

§

EUid(usize)

Entry with payload for type AuxVarType::EUid.

§

Gid(usize)

Entry with payload for type AuxVarType::Gid.

§

EGid(usize)

Entry with payload for type AuxVarType::EGid.

§

Platform(AuxVarString<'a>)

Entry with payload for type AuxVarType::Platform.

§

HwCap(usize)

Entry with payload for type AuxVarType::HwCap.

§

Clktck(usize)

Entry with payload for type AuxVarType::Clktck.

§

Secure(bool)

Entry with payload for type AuxVarType::Secure.

§

BasePlatform(AuxVarString<'a>)

Entry with payload for type AuxVarType::BasePlatform.

§

Random([u8; 16])

Entry with payload for type AuxVarType::Random.

§

HwCap2(usize)

Entry with payload for type AuxVarType::HwCap2.

§

ExecFn(AuxVarString<'a>)

Entry with payload for type AuxVarType::ExecFn.

§

Sysinfo(*const u8)

Entry with payload for type AuxVarType::Sysinfo.

§

SysinfoEhdr(*const u8)

Entry with payload for type AuxVarType::SysinfoEhdr.

§

L1iCacheSize(usize)

Entry with payload for type AuxVarType::L1iCacheSize.

§

L1iCacheGeometry(usize)

Entry with payload for type AuxVarType::L1iCacheGeometry.

§

L1dCacheSize(usize)

Entry with payload for type AuxVarType::L1dCacheSize.

§

L1dCacheGeometry(usize)

Entry with payload for type AuxVarType::L1dCacheGeometry.

§

L2CacheSize(usize)

Entry with payload for type AuxVarType::L2CacheSize.

§

L2CacheGeometry(usize)

Entry with payload for type AuxVarType::L2CacheGeometry.

§

L3CacheSize(usize)

Entry with payload for type AuxVarType::L3CacheSize.

§

L3CacheGeometry(usize)

Entry with payload for type AuxVarType::L3CacheGeometry.

§

MinSigStkSz(usize)

Entry with payload for type AuxVarType::MinSigStkSz.

Implementations§

Source§

impl<'a> AuxVar<'a>

Source

pub const fn key(&self) -> AuxVarType

Returns the AuxVarType this aux var corresponds to.

Examples found in repository?
examples/linux_print_layout.rs (line 69)
31fn main(argc: isize, argv: *const *const u8) -> isize {
32    let buffer = unsafe {
33        // 100 KiB, reasonably big.
34        // On my Linux machine, the structure needs 23 KiB
35        slice::from_raw_parts(argv.cast::<u8>(), 0x19000)
36    };
37
38    let parsed = StackLayoutRef::new(buffer, Some(argc as usize));
39
40    println!("There are {} arguments.", parsed.argc());
41    println!("  argv (raw)");
42    for (i, arg) in parsed.argv_raw_iter().enumerate() {
43        println!("    [{i}] @ {arg:?}");
44    }
45    println!("  argv");
46    // SAFETY: The pointers are valid in the address space of this process.
47    for (i, arg) in unsafe { parsed.argv_iter() }.enumerate() {
48        println!("    [{i}] {arg:?}");
49    }
50
51    println!("There are {} environment variables.", parsed.envc());
52    println!("  envv (raw)");
53    for (i, env) in parsed.envv_raw_iter().enumerate() {
54        println!("    [{i}] {env:?}");
55    }
56    println!("  envv");
57    // SAFETY: The pointers are valid in the address space of this process.
58    for (i, env) in unsafe { parsed.envv_iter() }.enumerate() {
59        println!("    [{i}] {env:?}");
60    }
61
62    println!(
63        "There are {} auxiliary vector entries/AT variables.",
64        parsed.auxv_raw_iter().count()
65    );
66    println!("  aux");
67    // ptr iter is safe for other address spaces; the other only because here user_addr == write_addr
68    for aux in unsafe { parsed.auxv_iter() } {
69        if aux.key().value_in_data_area() {
70            println!("    {:?} => @ {:?}", aux.key(), aux);
71        } else {
72            println!("    {:?} => {:?}", aux.key(), aux);
73        }
74    }
75
76    0
77}
Source

pub fn value_raw(&self) -> usize

Transforms any inner value into it’s corresponding serialized usize value.

This only works for variants that do not reference data exceeding the size of an usize.

Source

pub const fn value_integer(&self) -> Option<usize>

Returns a value if the corresponding entry corresponds to a basic value/integer, and not a pointer, flags, or a boolean.

Source

pub const fn value_flags(&self) -> Option<AuxVarFlags>

Returns the AuxVarFlags if the corresponding entry is of type AuxVarType::Flags.

Source

pub const fn value_boolean(&self) -> Option<bool>

Returns a value if the corresponding entry corresponds to a boolean, and not a pointer, flags, or a basic value/integer.

Source

pub const fn value_ptr(&self) -> Option<*const u8>

Returns a value if the corresponding entry corresponds to a pointer, and not a boolean, flags, or a basic value/integer.

This only affects entries that point to memory outside the stack layout, i.e., the aux vector data area.

Source

pub fn value_payload_bytes(&'a self) -> Option<&'a [u8]>

Returns a value, if the corresponding auxiliary vector entry references data in the auxiliary vector data area of the data structure. This returns only something for AuxVarType::Random.

This function is safe, because the creation during parsing already guarantee memory safety (the addresses are accessed).

Source

pub const fn value_payload_str(&'a self) -> Option<&'a AuxVarString<'a>>

Returns a value, if the corresponding auxiliary vector entry references data in the auxiliary vector data area of the data structure. This returns only something for AuxVarType::Random.

This function is safe, because the creation during parsing already guarantee memory safety (the addresses are accessed).

Trait Implementations§

Source§

impl<'a> Clone for AuxVar<'a>

Source§

fn clone(&self) -> AuxVar<'a>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for AuxVar<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> Ord for AuxVar<'a>

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<'a> PartialEq for AuxVar<'a>

Source§

fn eq(&self, other: &AuxVar<'a>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a> PartialOrd for AuxVar<'a>

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<'a> Eq for AuxVar<'a>

Source§

impl<'a> StructuralPartialEq for AuxVar<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for AuxVar<'a>

§

impl<'a> RefUnwindSafe for AuxVar<'a>

§

impl<'a> !Send for AuxVar<'a>

§

impl<'a> !Sync for AuxVar<'a>

§

impl<'a> Unpin for AuxVar<'a>

§

impl<'a> UnwindSafe for AuxVar<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.