blob: 6e945ab4584324b6b6df71a7c32688c7cde95538 [file] [log] [blame]
Jeff Dikea5d2f462006-04-10 22:53:26 -07001#include <errno.h>
Paolo 'Blaisorblade' Giarrusso3feb8852006-03-31 02:30:25 -08002#include <linux/unistd.h>
Arnd Bergmann5f4c6bc2006-10-02 02:18:37 -07003#include <sys/syscall.h>
Paolo 'Blaisorblade' Giarrusso3feb8852006-03-31 02:30:25 -08004#include "sysdep/tls.h"
5#include "user_util.h"
6
Paolo 'Blaisorblade' Giarrusso3feb8852006-03-31 02:30:25 -08007/* Checks whether host supports TLS, and sets *tls_min according to the value
8 * valid on the host.
9 * i386 host have it == 6; x86_64 host have it == 12, for i386 emulation. */
10void check_host_supports_tls(int *supports_tls, int *tls_min) {
11 /* Values for x86 and x86_64.*/
12 int val[] = {GDT_ENTRY_TLS_MIN_I386, GDT_ENTRY_TLS_MIN_X86_64};
13 int i;
14
15 for (i = 0; i < ARRAY_SIZE(val); i++) {
16 user_desc_t info;
17 info.entry_number = val[i];
18
Arnd Bergmann5f4c6bc2006-10-02 02:18:37 -070019 if (syscall(__NR_get_thread_area, &info) == 0) {
Paolo 'Blaisorblade' Giarrusso3feb8852006-03-31 02:30:25 -080020 *tls_min = val[i];
21 *supports_tls = 1;
22 return;
23 } else {
24 if (errno == EINVAL)
25 continue;
26 else if (errno == ENOSYS)
27 *supports_tls = 0;
28 return;
29 }
30 }
31
32 *supports_tls = 0;
33}