auxvec

Crates.ioauxvec
lib.rsauxvec
version0.0.4
created_at2025-07-02 23:57:56.838698+00
updated_at2025-07-03 00:19:35.576363+00
descriptionAuxiliary vector (auxv) reader and modifier.
homepage
repositoryhttps://github.com/cull-os/carcass/tree/master/auxvec
max_upload_size
id1735683
size29,409
RGBCube (RGBCube)

documentation

README

auxvec

Auxiliary vector (auxv) reader and modifier.

What is an "auxiliary vector"?

The auxiliary vector (auxv) is a sequence of key value pairs near the start of a running ELF program's stack. They do not exist within the ELF file, and are instantiated by the kernel before the program is handed off to the interpreter (or directly executed, if it does not specify one).

These key/value pairs give the interpreter (and dynamic linker, they are different concepts but usually implemented by the same program) information on what to do with the ELF file & how to transform its dynamic, relocatable code into something that the CPU can execute.

The way this library actually find this vector is by following the address in the global environ variable, which points to the start of the environment variables (which is actually a C-style null terminated list of pointers to C-style null terminated strings: &CSlice<&CStr>), and setting the start of the vector to the element right after the environment null sentinel:

++++++++++++++-----------------------------------------+
+ WORD SIZED * <pointer> -> "FOO=bar\0"                 |
++++++++++++++------------------------------------------+
+ WORD SIZED * <pointer> -> "BAR=baz\0"                 |
++++++++++++++------------------------------------------+
+ WORD SIZED * NULL (end of the environment)            |
++++++++++++++------------------------------------------+
+ WORD SIZED * <key>   (start of auxiliary vector)      |
++++++++++++++------------------------------------------+
+ WORD SIZED * <value> (the value for the first entry)  |
++++++++++++++-----------------------------------------+

And it is guaranteed that the vector ends with a (key, value) pair where the key is 0. This is how we figure out to stop iterating.

You can see some of the common auxiliary vector keys set by the Linux kernel in this document.

These keys are widely defined using macros in C and are prefixed using AT_. However, this crate uses auxvec::VectorKey::<type-here> instead and doesn't define the enumerations using the C naming style. AT_PAGESZ vs auxvec::VectorKey::PageSize, for example.

TODO: write rest of the README and finish documenting mod.rs.

More reading on the auxiliary vector:

Credits

  • The well documented auxv crate, which was a good starting point for the documentation.
  • nix-ld, which inspired me to write a better and well-designed version of auxv.rs.
  • And all the other people around the world that documented some of the odd keys.
Commit count: 807

cargo fmt