tls.c 847 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #include <errno.h>
  2. #include <linux/unistd.h>
  3. #include <sys/syscall.h>
  4. #include <unistd.h>
  5. #include "sysdep/tls.h"
  6. #include "user.h"
  7. #include "user_util.h"
  8. /* Checks whether host supports TLS, and sets *tls_min according to the value
  9. * valid on the host.
  10. * i386 host have it == 6; x86_64 host have it == 12, for i386 emulation. */
  11. void check_host_supports_tls(int *supports_tls, int *tls_min) {
  12. /* Values for x86 and x86_64.*/
  13. int val[] = {GDT_ENTRY_TLS_MIN_I386, GDT_ENTRY_TLS_MIN_X86_64};
  14. int i;
  15. for (i = 0; i < ARRAY_SIZE(val); i++) {
  16. user_desc_t info;
  17. info.entry_number = val[i];
  18. if (syscall(__NR_get_thread_area, &info) == 0) {
  19. *tls_min = val[i];
  20. *supports_tls = 1;
  21. return;
  22. } else {
  23. if (errno == EINVAL)
  24. continue;
  25. else if (errno == ENOSYS)
  26. *supports_tls = 0;
  27. return;
  28. }
  29. }
  30. *supports_tls = 0;
  31. }