tls.c 832 B

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