Jeff Dike | a5d2f46 | 2006-04-10 22:53:26 -0700 | [diff] [blame] | 1 | #include <errno.h> |
Paolo 'Blaisorblade' Giarrusso | 3feb885 | 2006-03-31 02:30:25 -0800 | [diff] [blame] | 2 | #include <linux/unistd.h> |
| 3 | #include "sysdep/tls.h" |
| 4 | #include "user_util.h" |
| 5 | |
| 6 | static _syscall1(int, get_thread_area, user_desc_t *, u_info); |
| 7 | |
| 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 | |
| 16 | for (i = 0; i < ARRAY_SIZE(val); i++) { |
| 17 | user_desc_t info; |
| 18 | info.entry_number = val[i]; |
| 19 | |
| 20 | if (get_thread_area(&info) == 0) { |
| 21 | *tls_min = val[i]; |
| 22 | *supports_tls = 1; |
| 23 | return; |
| 24 | } else { |
| 25 | if (errno == EINVAL) |
| 26 | continue; |
| 27 | else if (errno == ENOSYS) |
| 28 | *supports_tls = 0; |
| 29 | return; |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | *supports_tls = 0; |
| 34 | } |