cpusupport_arm_aes.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #include "cpusupport.h"
  2. #ifdef CPUSUPPORT_HWCAP_GETAUXVAL
  3. #include <sys/auxv.h>
  4. #if defined(__arm__)
  5. /**
  6. * Workaround for a glibc bug: <bits/hwcap.h> contains a comment saying:
  7. * The following must match the kernel's <asm/hwcap.h>.
  8. * However, it does not contain any of the HWCAP2_* entries from <asm/hwcap.h>.
  9. */
  10. #ifndef HWCAP2_AES
  11. #include <asm/hwcap.h>
  12. #endif
  13. #endif /* __arm__ */
  14. #endif /* CPUSUPPORT_HWCAP_GETAUXVAL */
  15. #if defined(CPUSUPPORT_HWCAP_ELF_AUX_INFO)
  16. #include <sys/auxv.h>
  17. #endif /* CPUSUPPORT_HWCAP_ELF_AUX_INFO */
  18. CPUSUPPORT_FEATURE_DECL(arm, aes)
  19. {
  20. int supported = 0;
  21. #if defined(CPUSUPPORT_ARM_AES)
  22. #if defined(CPUSUPPORT_HWCAP_GETAUXVAL)
  23. unsigned long capabilities;
  24. #if defined(__aarch64__)
  25. capabilities = getauxval(AT_HWCAP);
  26. supported = (capabilities & HWCAP_AES) ? 1 : 0;
  27. #elif defined(__arm__)
  28. capabilities = getauxval(AT_HWCAP2);
  29. supported = (capabilities & HWCAP2_AES) ? 1 : 0;
  30. #endif
  31. #endif /* CPUSUPPORT_HWCAP_GETAUXVAL */
  32. #if defined(CPUSUPPORT_HWCAP_ELF_AUX_INFO)
  33. unsigned long capabilities;
  34. #if defined(__aarch64__)
  35. if (elf_aux_info(AT_HWCAP, &capabilities, sizeof(unsigned long)))
  36. return (0);
  37. supported = (capabilities & HWCAP_AES) ? 1 : 0;
  38. #else
  39. if (elf_aux_info(AT_HWCAP2, &capabilities, sizeof(unsigned long)))
  40. return (0);
  41. supported = (capabilities & HWCAP2_AES) ? 1 : 0;
  42. #endif
  43. #endif /* CPUSUPPORT_HWCAP_ELF_AUX_INFO */
  44. #endif /* CPUSUPPORT_ARM_AES */
  45. /* Return the supported status. */
  46. return (supported);
  47. }