开发者

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

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

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?


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.


The answer to your question is system specific. The C ISO defines only two arguments to the main function. Additional arguments are not standard and should be considered an extension. Quoting Main function from Wikipedia:

The parameters argc, argument count, and argv, argument vector, [1] respectively give the number and value of the program's command-line arguments. The names of argc and argv may be any valid identifier in C, but it is common convention to use these names. In C++, the names are to be taken literally, and the "void" in the parameter list is to be omitted, if strict conformance is desired. [2] Other platform-dependent formats are also allowed by the C and C++ standards, except that in C++ the return type must stay int; for example, Unix (though not POSIX.1) and Microsoft Windows have a third argument giving the program's environment, otherwise accessible through getenv in stdlib.h:

int main(int argc, char **argv, char **envp)

Mac OS X and Darwin have a fourth parameter containing arbitrary OS-supplied information, such as the path to the executing binary: [3]

int main(int argc, char **argv, char **envp, char **apple)

The AMD64 ABI

According to the System V ABI for AMD64, Draft 0.99.5, the auxiliary vector entries are of type auxv_t, as shown below:

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜