diff options
Diffstat (limited to 'arch/x86/um/os-Linux/tls.c')
-rw-r--r-- | arch/x86/um/os-Linux/tls.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/arch/x86/um/os-Linux/tls.c b/arch/x86/um/os-Linux/tls.c new file mode 100644 index 000000000000..281e83ecce3d --- /dev/null +++ b/arch/x86/um/os-Linux/tls.c | |||
@@ -0,0 +1,35 @@ | |||
1 | #include <errno.h> | ||
2 | #include <linux/unistd.h> | ||
3 | |||
4 | #include <sys/syscall.h> | ||
5 | #include <unistd.h> | ||
6 | |||
7 | #include "sysdep/tls.h" | ||
8 | |||
9 | /* Checks whether host supports TLS, and sets *tls_min according to the value | ||
10 | * valid on the host. | ||
11 | * i386 host have it == 6; x86_64 host have it == 12, for i386 emulation. */ | ||
12 | void check_host_supports_tls(int *supports_tls, int *tls_min) { | ||
13 | /* Values for x86 and x86_64.*/ | ||
14 | int val[] = {GDT_ENTRY_TLS_MIN_I386, GDT_ENTRY_TLS_MIN_X86_64}; | ||
15 | int i; | ||
16 | |||
17 | for (i = 0; i < ARRAY_SIZE(val); i++) { | ||
18 | user_desc_t info; | ||
19 | info.entry_number = val[i]; | ||
20 | |||
21 | if (syscall(__NR_get_thread_area, &info) == 0) { | ||
22 | *tls_min = val[i]; | ||
23 | *supports_tls = 1; | ||
24 | return; | ||
25 | } else { | ||
26 | if (errno == EINVAL) | ||
27 | continue; | ||
28 | else if (errno == ENOSYS) | ||
29 | *supports_tls = 0; | ||
30 | return; | ||
31 | } | ||
32 | } | ||
33 | |||
34 | *supports_tls = 0; | ||
35 | } | ||