Crates.io | auxvec |
lib.rs | auxvec |
version | 0.0.4 |
created_at | 2025-07-02 23:57:56.838698+00 |
updated_at | 2025-07-03 00:19:35.576363+00 |
description | Auxiliary vector (auxv) reader and modifier. |
homepage | |
repository | https://github.com/cull-os/carcass/tree/master/auxvec |
max_upload_size | |
id | 1735683 |
size | 29,409 |
Auxiliary vector (auxv) reader and modifier.
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:
fs/binfmt_elf.c
).include/uapi/linux/auxvec.h
in the Linux source (or man 3 getauxval
)
for defined keys, as well as other header files for architecture-specific
types.AT_
in your OS of choice (it's open source, right?) will also
yield some good results on how it's handled.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
.