blob: 32ed41ec1a3d8790d97471f7cae706168f68bb20 [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>
Paolo 'Blaisorblade' Giarrussob428b512006-10-29 22:46:41 -08003
Arnd Bergmann5f4c6bc2006-10-02 02:18:37 -07004#include <sys/syscall.h>
Paolo 'Blaisorblade' Giarrussob428b512006-10-29 22:46:41 -08005#include <unistd.h>
6
Paolo 'Blaisorblade' Giarrusso3feb8852006-03-31 02:30:25 -08007#include "sysdep/tls.h"
Jeff Dike24fa6c02007-05-06 14:51:09 -07008#include "user.h"
Paolo 'Blaisorblade' Giarrusso3feb8852006-03-31 02:30:25 -08009
Paolo 'Blaisorblade' Giarrusso3feb8852006-03-31 02:30:25 -080010/* Checks whether host supports TLS, and sets *tls_min according to the value
11 * valid on the host.
12 * i386 host have it == 6; x86_64 host have it == 12, for i386 emulation. */
13void check_host_supports_tls(int *supports_tls, int *tls_min) {
14 /* Values for x86 and x86_64.*/
15 int val[] = {GDT_ENTRY_TLS_MIN_I386, GDT_ENTRY_TLS_MIN_X86_64};
16 int i;
17
18 for (i = 0; i < ARRAY_SIZE(val); i++) {
19 user_desc_t info;
20 info.entry_number = val[i];
21
Arnd Bergmann5f4c6bc2006-10-02 02:18:37 -070022 if (syscall(__NR_get_thread_area, &info) == 0) {
Paolo 'Blaisorblade' Giarrusso3feb8852006-03-31 02:30:25 -080023 *tls_min = val[i];
24 *supports_tls = 1;
25 return;
26 } else {
27 if (errno == EINVAL)
28 continue;
29 else if (errno == ENOSYS)
30 *supports_tls = 0;
31 return;
32 }
33 }
34
35 *supports_tls = 0;
36}