1 #include <stdlib.h>
2 #include <stdio.h>
3
4 #include <sys/auxv.h>
5 #include <errno.h>
6 #include <dlfcn.h>
7
8 #include <cpuinfo.h>
9
10
11 typedef unsigned long (*getauxval_function_t)(unsigned long);
12
main(int argc,char ** argv)13 int main(int argc, char** argv) {
14 void* libc = dlopen("libc.so", RTLD_NOW);
15 if (libc == NULL) {
16 fprintf(stderr, "Error: failed to load libc.so: %s\n", dlerror());
17 exit(EXIT_FAILURE);
18 }
19
20 getauxval_function_t getauxval = (getauxval_function_t) dlsym(libc, "getauxval");
21 if (getauxval == NULL) {
22 fprintf(stderr, "Error: failed to locate getauxval in libc.so: %s", dlerror());
23 exit(EXIT_FAILURE);
24 }
25
26 printf("AT_HWCAP = 0x%08lX\n", getauxval(AT_HWCAP));
27 #if CPUINFO_ARCH_ARM
28 printf("AT_HWCAP2 = 0x%08lX\n", getauxval(AT_HWCAP2));
29 #endif
30
31 return 0;
32 }
33