sysconf.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /* Copyright (C) 2017-2019 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library. If not, see
  13. <http://www.gnu.org/licenses/>. */
  14. #include <assert.h>
  15. #include <stdbool.h>
  16. #include <stdlib.h>
  17. #include <unistd.h>
  18. static long int linux_sysconf (int name);
  19. /* Get the value of the system variable NAME. */
  20. long int
  21. __sysconf (int name)
  22. {
  23. unsigned ctr;
  24. /* Unfortunately, the registers that contain the actual cache info
  25. (CCSIDR_EL1, CLIDR_EL1, and CSSELR_EL1) are protected by the Linux
  26. kernel (though they need not have been). However, CTR_EL0 contains
  27. the *minimum* linesize in the entire cache hierarchy, and is
  28. accessible to userland, for use in __aarch64_sync_cache_range,
  29. and it is a reasonable assumption that the L1 cache will have that
  30. minimum line size. */
  31. switch (name)
  32. {
  33. case _SC_LEVEL1_ICACHE_LINESIZE:
  34. asm("mrs\t%0, ctr_el0" : "=r"(ctr));
  35. return 4 << (ctr & 0xf);
  36. case _SC_LEVEL1_DCACHE_LINESIZE:
  37. asm("mrs\t%0, ctr_el0" : "=r"(ctr));
  38. return 4 << ((ctr >> 16) & 0xf);
  39. }
  40. return linux_sysconf (name);
  41. }
  42. /* Now the generic Linux version. */
  43. #undef __sysconf
  44. #define __sysconf static linux_sysconf
  45. #include <sysdeps/unix/sysv/linux/sysconf.c>