blob: 8ba1324829707c3cda2725180c268ef6d45232d2 [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#include "user_util.h"
10
Paolo 'Blaisorblade' Giarrusso3feb8852006-03-31 02:30:25 -080011/* 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. */
14void 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
Arnd Bergmann5f4c6bc2006-10-02 02:18:37 -070023 if (syscall(__NR_get_thread_area, &info) == 0) {
Paolo 'Blaisorblade' Giarrusso3feb8852006-03-31 02:30:25 -080024 *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}