Skip to content

Instantly share code, notes, and snippets.

@drizzt
Created March 21, 2018 18:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drizzt/76bea31268da8a449323120bcfff0360 to your computer and use it in GitHub Desktop.
Save drizzt/76bea31268da8a449323120bcfff0360 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <elf.h>
#include <fcntl.h>
#include <assert.h>
#include <unistd.h>
#if defined(__GLIBC__) && defined(__GLIBC_PREREQ)
#if __GLIBC_PREREQ(2, 16)
#include <sys/auxv.h>
#endif
#endif
int main() {
int auxv_fd;
Elf64_auxv_t auxv;
#if defined(__GLIBC__) && defined(__GLIBC_PREREQ)
#if __GLIBC_PREREQ(2, 16)
puts("Reading using getauxval");
printf("REG_HWCAP: %lx\n", getauxval(AT_HWCAP));
printf("REG_HWCAP2: %lx\n", getauxval(AT_HWCAP2));
printf("PLATFORM_STR: %s\n", (char *)getauxval(AT_PLATFORM));
puts("---");
#endif
#endif
puts("Reading from /proc/self/auxv");
auxv_fd = open("/proc/self/auxv", O_RDONLY);
assert(auxv_fd != -1);
while (read(auxv_fd, &auxv, sizeof(auxv)) == sizeof(auxv)) {
if (auxv.a_type == AT_HWCAP) {
printf("REG_HWCAP: %lx\n", auxv.a_un.a_val);
} else if (auxv.a_type == AT_HWCAP2) {
printf("REG_HWCAP2: %lx\n", auxv.a_un.a_val);
} else if (auxv.a_type == AT_PLATFORM) {
printf("PLATFORM_STR: %s\n", (char *)auxv.a_un.a_val);
}
}
close(auxv_fd);
puts("---");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment