Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access/print the auxiliary vector entry in main?

Tags:

c

stack

linux

enter image description here

According to the image,the stack is populated with the auxiliary vector entry on start up.

I don't know of it before.

How can I access/print them?

int main(int argc, char *argv[], char *envp[]);

Does it mean main has a hidden fourth parameter?

like image 403
lexer Avatar asked Oct 11 '22 03:10

lexer


1 Answers

The aux vector is located immediately past the end of the environment vector, which is accessible (per POSIX) as extern char **environ;. environ points to a NULL-pointer terminated array of char * pointers to environment variables. Iterate through the environment until you reach NULL, then advance one element further and cast the result to whatever type you want to use to access the aux vector. Personally, I treat it as an array of size_t or uintptr_t values that come in pairs, since this is easier and more portable than the elf.h Elf32_auxv_t and Elf64_auxv_t types (which require that you special-case whether you're building for a 32-bit or 64-bit target).

Note that the existence and location of the aux vector are not specified by POSIX, but this is where they will be located on any ELF-ABI-based implementation that use an aux vector.

like image 95
R.. GitHub STOP HELPING ICE Avatar answered Oct 14 '22 01:10

R.. GitHub STOP HELPING ICE