Merge branch 'misc' of master.kernel.org:/pub/scm/linux/kernel/git/galak/powerpc...
[pandora-kernel.git] / arch / um / os-Linux / sys-i386 / tls.c
1 #include <errno.h>
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 }