Marat Dukhan | f3a71e6 | 2017-11-29 15:15:36 -0800 | [diff] [blame] | 1 | #include <stdlib.h> |
| 2 | #include <stdio.h> |
| 3 | |
| 4 | #include <sys/auxv.h> |
| 5 | #include <errno.h> |
| 6 | #include <dlfcn.h> |
| 7 | |
Marat Dukhan | f3a71e6 | 2017-11-29 15:15:36 -0800 | [diff] [blame] | 8 | |
| 9 | typedef unsigned long (*getauxval_function_t)(unsigned long); |
| 10 | |
| 11 | int 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 | } |