Skip to content

Instantly share code, notes, and snippets.

@savanovich
Last active August 29, 2015 14:02
Show Gist options
  • Save savanovich/c8ecb12fc97e83a78538 to your computer and use it in GitHub Desktop.
Save savanovich/c8ecb12fc97e83a78538 to your computer and use it in GitHub Desktop.
/*
Original here https://www.technovelty.org/linux/poking-around-in-auxv-part-2.html
Changed for x64
gcc read-auxv.c -o read-auxv
./read-auxv <PID>
*/
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <assert.h>
#include <elf.h>
char *aux_to_str(int n) {
switch (n) {
case AT_NULL:
return "AT_NULL";
case AT_IGNORE:
return "AT_IGNORE";
case AT_EXECFD:
return "AT_EXECFD";
case AT_PHDR:
return "AT_PHDR";
case AT_PHENT:
return "AT_PHENT";
case AT_PHNUM:
return "AT_PHNUM";
case AT_PAGESZ:
return "AT_PAGESZ";
case AT_BASE:
return "AT_BASE";
case AT_FLAGS:
return "AT_FLAGS";
case AT_ENTRY:
return "AT_ENTRY";
case AT_NOTELF:
return "AT_NOTELF";
case AT_UID:
return "AT_UID";
case AT_EUID:
return "AT_EUID";
case AT_GID:
return "AT_GID";
case AT_EGID:
return "AT_EGID";
case AT_CLKTCK:
return "AT_CLKTCK";
case AT_PLATFORM:
return "AT_PLATFORM";
case AT_HWCAP:
return "AT_HWCAP";
case AT_FPUCW:
return "AT_FPUCW";
case AT_DCACHEBSIZE:
return "AT_DCACHEBSIZE";
case AT_ICACHEBSIZE:
return "AT_ICACHEBSIZE";
case AT_UCACHEBSIZE:
return "AT_UCACHEBSIZE";
case AT_IGNOREPPC:
return "AT_IGNOREPPC";
case AT_SECURE:
return "AT_SECURE";
case AT_SYSINFO:
return "AT_SYSINFO";
case AT_SYSINFO_EHDR:
return "AT_SYSINFO_EHDR";
case AT_L1I_CACHESHAPE:
return "AT_L1I_CACHESHAPE";
case AT_L1D_CACHESHAPE:
return "AT_L1D_CACHESHAPE";
case AT_L2_CACHESHAPE:
return "AT_L2_CACHESHAPE";
case AT_L3_CACHESHAPE:
return "AT_L3_CACHESHAPE";
default:
return "UNKNOWN";
}
}
int main(int argc, char *argv[]) {
int fd;
char *file;
struct stat sb;
Elf64_auxv_t aux;
int count;
asprintf(&file, "/proc/%s/auxv", argv[1]);
assert(file);
fd = open(file, O_RDONLY);
assert(fd);
while (read(fd, &aux, sizeof(Elf64_auxv_t))) {
printf("%s : %lx\n", aux_to_str(aux.a_type), aux.a_un.a_val);
}
}
@savanovich
Copy link
Author

The same info produces LD_SHOW_AUXV environment variable:

$ LD_SHOW_AUXV=1 ./ptr5
AT_SYSINFO_EHDR: 0x7fff113fe000
AT_HWCAP: bfebfbff
AT_PAGESZ: 4096
AT_CLKTCK: 100
AT_PHDR: 0x400040
AT_PHENT: 56
AT_PHNUM: 9
AT_BASE: 0x7faff183a000
AT_FLAGS: 0x0
AT_ENTRY: 0x400440
AT_UID: 1000
AT_EUID: 1000
AT_GID: 1000
AT_EGID: 1000
AT_SECURE: 0
AT_RANDOM: 0x7fff11366c99
AT_EXECFN: ./ptr5
AT_PLATFORM: x86_64

@savanovich
Copy link
Author

(gdb) info auxv

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment