Enum AuxVarType

Source
#[repr(usize)]
pub enum AuxVarType {
Show 34 variants Null = 0, Ignore = 1, ExecFd = 2, Phdr = 3, Phent = 4, Phnum = 5, Pagesz = 6, Base = 7, Flags = 8, Entry = 9, NotElf = 10, Uid = 11, EUid = 12, Gid = 13, EGid = 14, Platform = 15, HwCap = 16, Clktck = 17, Secure = 23, BasePlatform = 24, Random = 25, HwCap2 = 26, ExecFn = 31, Sysinfo = 32, SysinfoEhdr = 33, L1iCacheSize = 40, L1iCacheGeometry = 41, L1dCacheSize = 42, L1dCacheGeometry = 43, L2CacheSize = 44, L2CacheGeometry = 45, L3CacheSize = 46, L3CacheGeometry = 47, MinSigStkSz = 51,
}
Expand description

All types of auxiliary variables that Linux supports for the initial stack. Also called “AT”-variables in Linux source code.

According to some Linux code comments, 0-17 are architecture independent The ones above and including 32 are for x86_64. Values above 40 are for power PC.

More info:

Variants§

§

Null = 0

end of vector

§

Ignore = 1

entry should be ignored

§

ExecFd = 2

file descriptor of program

§

Phdr = 3

program headers for program

§

Phent = 4

size of program header entry

§

Phnum = 5

number of program headers

§

Pagesz = 6

system page size

§

Base = 7

The base address of the program interpreter (usually, the dynamic linker).

§

Flags = 8

Flags that apply on the whole auxiliary vector. See crate::AuxVarFlags.

§

Entry = 9

entry point of program

§

NotElf = 10

program is not ELF

§

Uid = 11

real uid

§

EUid = 12

effective uid

§

Gid = 13

real gid

§

EGid = 14

effective gid

§

Platform = 15

string identifying CPU for optimizations

§

HwCap = 16

Arch dependent hints at CPU capabilities. On x86_64 these are the CPUID features.

§

Clktck = 17

frequency at which times() increments

§

Secure = 23

secure mode boolean

§

BasePlatform = 24

string identifying real platform, may differ from AtPlatform.

§

Random = 25

address of 16 random bytes

§

HwCap2 = 26

extension of AtHwcap

§

ExecFn = 31

filename of program, for example “./my_executable\0”

§

Sysinfo = 32

The entry point to the system call function in the vDSO. Not present/needed on all architectures (e.g., absent on x86-64).

§

SysinfoEhdr = 33

The address of a page containing the virtual Dynamic Shared Object (vDSO) that the kernel creates in order to provide fast implementations of certain system calls.

§

L1iCacheSize = 40

§

L1iCacheGeometry = 41

§

L1dCacheSize = 42

§

L1dCacheGeometry = 43

§

L2CacheSize = 44

§

L2CacheGeometry = 45

§

L3CacheSize = 46

§

L3CacheGeometry = 47

§

MinSigStkSz = 51

Minimal stack size for signal delivery.

Implementations§

Source§

impl AuxVarType

Source

pub const fn val(self) -> usize

Source

pub const fn value_in_data_area(self) -> bool

If this is true, the value of the key should be interpreted as pointer into the aux vector data area. Otherwise, the value of the key is an immediate value/integer.

Examples found in repository?
examples/minimal.rs (line 79)
27fn main() {
28    let builder = InitialLinuxLibcStackLayoutBuilder::new()
29        // can contain terminating zero; not mandatory in the builder
30        .add_arg_v("./first_arg\0")
31        .add_arg_v("./second_arg")
32        .add_env_v("FOO=BAR\0")
33        .add_env_v("PATH=/bin")
34        .add_aux_v(AuxVar::Clktck(100))
35        .add_aux_v(AuxVar::Random([
36            1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
37        ]))
38        .add_aux_v(AuxVar::ExecFn("/usr/bin/foo"))
39        .add_aux_v(AuxVar::Platform("x86_64"));
40
41    // memory where we serialize the data structure into
42    let mut buf = vec![0; builder.total_size()];
43
44    // assume user stack is at 0x7fff0000
45    let user_base_addr = 0x7fff0000;
46    unsafe {
47        builder.serialize_into_buf(buf.as_mut_slice(), user_base_addr);
48    }
49
50    // So far, this is memory safe, as long as the slice is valid memory. No pointers are
51    // dereferenced yet.
52    let parsed = InitialLinuxLibcStackLayout::from(buf.as_slice());
53
54    println!("There are {} arguments.", parsed.argc());
55    println!(
56        "There are {} environment variables.",
57        parsed.envv_ptr_iter().count()
58    );
59    println!(
60        "There are {} auxiliary vector entries/AT variables.",
61        parsed.aux_serialized_iter().count()
62    );
63
64    println!("  argv");
65    // ptr iter is safe for other address spaces; the other only because here user_addr == write_addr
66    for (i, arg) in parsed.argv_ptr_iter().enumerate() {
67        println!("    [{}] @ {:?}", i, arg);
68    }
69
70    println!("  envp");
71    // ptr iter is safe for other address spaces; the other only because here user_addr == write_addr
72    for (i, env) in parsed.envv_ptr_iter().enumerate() {
73        println!("    [{}] @ {:?}", i, env);
74    }
75
76    println!("  aux");
77    // ptr iter is safe for other address spaces; the other only because here user_addr == write_addr
78    for aux in parsed.aux_serialized_iter() {
79        if aux.key().value_in_data_area() {
80            println!("    {:?} => @ {:?}", aux.key(), aux.val() as *const u8);
81        } else {
82            println!("    {:?} => {:?}", aux.key(), aux.val() as *const u8);
83        }
84    }
85}
Source

pub fn value_is_cstr(self) -> bool

Most of the auxiliary vector entries where Self::value_is_cstr is true, represent a null-terminated C-string.

Source

pub const fn data_area_val_size_hint(self) -> Option<usize>

The payload of some AuxVarType is stored in the aux var data area. Some of these data is null-terminated. Some has a fixed size. This helps to find out if there is a fixed size.

Trait Implementations§

Source§

impl Clone for AuxVarType

Source§

fn clone(&self) -> AuxVarType

Returns a copy 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 Debug for AuxVarType

Source§

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

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

impl From<usize> for AuxVarType

Source§

fn from(val: usize) -> Self

Converts to this type from the input type.
Source§

impl IntoEnumIterator for AuxVarType

Source§

const VARIANT_COUNT: usize = 34usize

Number of variants.
Source§

type Iterator = AuxVarTypeEnumIterator

Type of the iterator over the variants.
Source§

fn into_enum_iter() -> Self::Iterator

Returns an iterator over the variants. Read more
Source§

impl Ord for AuxVarType

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 PartialEq for AuxVarType

Source§

fn eq(&self, other: &AuxVarType) -> 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 PartialOrd for AuxVarType

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 Copy for AuxVarType

Source§

impl Eq for AuxVarType

Source§

impl StructuralPartialEq for AuxVarType

Auto Trait Implementations§

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.