8ba1324829707c3cda2725180c268ef6d45232d2
[safe/jmp/linux-2.6] / arch / um / os-Linux / sys-i386 / tls.c
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 #include "user.h"
9 #include "user_util.h"
10
11 /* Checks whether host supports TLS, and sets *tls_min according to the value
12  * valid on the host.
13  * i386 host have it == 6; x86_64 host have it == 12, for i386 emulation. */
14 void check_host_supports_tls(int *supports_tls, int *tls_min) {
15         /* Values for x86 and x86_64.*/
16         int val[] = {GDT_ENTRY_TLS_MIN_I386, GDT_ENTRY_TLS_MIN_X86_64};
17         int i;
18
19         for (i = 0; i < ARRAY_SIZE(val); i++) {
20                 user_desc_t info;
21                 info.entry_number = val[i];
22
23                 if (syscall(__NR_get_thread_area, &info) == 0) {
24                         *tls_min = val[i];
25                         *supports_tls = 1;
26                         return;
27                 } else {
28                         if (errno == EINVAL)
29                                 continue;
30                         else if (errno == ENOSYS)
31                                 *supports_tls = 0;
32                                 return;
33                 }
34         }
35
36         *supports_tls = 0;
37 }