hwcap.cc 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /* Copyright (C) 2011-2015 Free Software Foundation, Inc.
  2. Contributed by Richard Henderson <rth@redhat.com>.
  3. This file is part of the GNU Transactional Memory Library (libitm).
  4. Libitm is free software; you can redistribute it and/or modify it
  5. under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. Libitm is distributed in the hope that it will be useful, but WITHOUT ANY
  9. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  10. FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. more details.
  12. Under Section 7 of GPL version 3, you are granted additional
  13. permissions described in the GCC Runtime Library Exception, version
  14. 3.1, as published by the Free Software Foundation.
  15. You should have received a copy of the GNU General Public License and
  16. a copy of the GCC Runtime Library Exception along with this program;
  17. see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  18. <http://www.gnu.org/licenses/>. */
  19. /* This file initializes GTM_hwcap in some os-specific way to indicate
  20. what ISA extensions are present for ARM. */
  21. #include "libitm_i.h"
  22. #include "hwcap.h"
  23. /* Begin by defaulting to whatever options were given to the compiler. */
  24. int GTM_hwcap HIDDEN = 0
  25. #ifdef __VFP_FP__
  26. | HWCAP_ARM_VFP
  27. #endif
  28. #ifdef __IWMMXT__
  29. | HWCAP_ARM_IWMMXT
  30. #endif
  31. ;
  32. #ifdef __linux__
  33. #include <unistd.h>
  34. #include <sys/fcntl.h>
  35. #include <elf.h>
  36. static void __attribute__((constructor))
  37. init_gtm_hwcap(void)
  38. {
  39. int fd = open ("/proc/self/auxv", O_RDONLY);
  40. if (fd < 0)
  41. return;
  42. Elf32_auxv_t pairs[512];
  43. ssize_t rlen = read (fd, pairs, sizeof(pairs));
  44. close (fd);
  45. if (rlen < 0)
  46. return;
  47. size_t n = (size_t)rlen / sizeof(pairs[0]);
  48. for (size_t i = 0; i < n; ++i)
  49. if (pairs[i].a_type == AT_HWCAP)
  50. {
  51. GTM_hwcap = pairs[i].a_un.a_val;
  52. return;
  53. }
  54. }
  55. #endif