arm_arch_queries.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Header included only by arm_arch_queries.c.
  3. *
  4. * The only reason this is a header file instead of a source file is
  5. * so that I can define 'static inline' functions which may or may not
  6. * be used, without provoking a compiler warning when I turn out not
  7. * to use them in the subsequent source file.
  8. */
  9. #ifndef PUTTY_ARM_ARCH_QUERIES_H
  10. #define PUTTY_ARM_ARCH_QUERIES_H
  11. #if defined __APPLE__
  12. #if HAVE_SYS_SYSCTL_H
  13. #include <sys/sysctl.h>
  14. #endif
  15. #endif /* defined __APPLE__ */
  16. #if defined __arm__ || defined __aarch64__
  17. #if HAVE_SYS_TYPES_H
  18. #include <sys/types.h>
  19. #endif
  20. #if HAVE_SYS_AUXV_H
  21. #include <sys/auxv.h>
  22. #endif
  23. #if HAVE_ASM_HWCAP_H
  24. #include <asm/hwcap.h>
  25. #endif
  26. #if HAVE_GETAUXVAL
  27. /* No code needed: getauxval has just the API we want already */
  28. #elif HAVE_ELF_AUX_INFO
  29. /* Implement the simple getauxval API in terms of FreeBSD elf_aux_info */
  30. static inline u_long getauxval(int which)
  31. {
  32. u_long toret;
  33. if (elf_aux_info(which, &toret, sizeof(toret)) != 0)
  34. return 0; /* elf_aux_info didn't work */
  35. return toret;
  36. }
  37. #else
  38. /* Implement a stub getauxval which returns no capabilities */
  39. static inline u_long getauxval(int which) { return 0; }
  40. #endif
  41. #endif /* defined __arm__ || defined __aarch64__ */
  42. #if defined __APPLE__
  43. typedef enum { SYSCTL_MISSING, SYSCTL_OFF, SYSCTL_ON } SysctlResult;
  44. static inline SysctlResult test_sysctl_flag(const char *flagname)
  45. {
  46. #if HAVE_SYSCTLBYNAME
  47. int value;
  48. size_t size = sizeof(value);
  49. if (sysctlbyname(flagname, &value, &size, NULL, 0) == 0 &&
  50. size == sizeof(value)) {
  51. return value != 0 ? SYSCTL_ON : SYSCTL_OFF;
  52. }
  53. #else /* HAVE_SYSCTLBYNAME */
  54. return SYSCTL_MISSING;
  55. #endif /* HAVE_SYSCTLBYNAME */
  56. }
  57. #endif /* defined __APPLE__ */
  58. #endif /* PUTTY_ARM_ARCH_QUERIES_H */