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