blob: 120abbe4e3ce2916d7d20eb7680dcdfd2a8c0baa [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>
3#include "sysdep/tls.h"
4#include "user_util.h"
5
6static _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. */
11void 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}