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