1 #include <linux/kernel.h>
2 #include <linux/errno.h>
3 #include <linux/sched.h>
4 #include <linux/user.h>
6 #include <asm/uaccess.h>
8 #include <asm/system.h>
10 #include <asm/processor.h>
11 #include <asm/proto.h>
14 * sys_alloc_thread_area: get a yet unused TLS descriptor index.
16 static int get_free_idx(void)
18 struct thread_struct *t = ¤t->thread;
21 for (idx = 0; idx < GDT_ENTRY_TLS_ENTRIES; idx++)
22 if (desc_empty((struct n_desc_struct *)(t->tls_array) + idx))
23 return idx + GDT_ENTRY_TLS_MIN;
28 * Set a given TLS descriptor:
29 * When you want addresses > 32bit use arch_prctl()
31 int do_set_thread_area(struct thread_struct *t, struct user_desc __user *u_info)
33 struct user_desc info;
34 struct n_desc_struct *desc;
37 if (copy_from_user(&info, u_info, sizeof(info)))
40 idx = info.entry_number;
43 * index -1 means the kernel should try to find and
44 * allocate an empty descriptor:
50 if (put_user(idx, &u_info->entry_number))
54 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
57 desc = ((struct n_desc_struct *)t->tls_array) + idx - GDT_ENTRY_TLS_MIN;
60 * We must not get preempted while modifying the TLS.
64 if (LDT_empty(&info)) {
68 desc->a = LDT_entry_a(&info);
69 desc->b = LDT_entry_b(&info);
71 if (t == ¤t->thread)
78 asmlinkage long sys32_set_thread_area(struct user_desc __user *u_info)
80 return do_set_thread_area(¤t->thread, u_info);
85 * Get the current Thread-Local Storage area:
88 #define GET_LIMIT(desc) ( \
89 ((desc)->a & 0x0ffff) | \
90 ((desc)->b & 0xf0000) )
92 #define GET_32BIT(desc) (((desc)->b >> 22) & 1)
93 #define GET_CONTENTS(desc) (((desc)->b >> 10) & 3)
94 #define GET_WRITABLE(desc) (((desc)->b >> 9) & 1)
95 #define GET_LIMIT_PAGES(desc) (((desc)->b >> 23) & 1)
96 #define GET_PRESENT(desc) (((desc)->b >> 15) & 1)
97 #define GET_USEABLE(desc) (((desc)->b >> 20) & 1)
98 #define GET_LONGMODE(desc) (((desc)->b >> 21) & 1)
100 int do_get_thread_area(struct thread_struct *t, struct user_desc __user *u_info)
102 struct user_desc info;
103 struct n_desc_struct *desc;
106 if (get_user(idx, &u_info->entry_number))
108 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
111 desc = ((struct n_desc_struct *)t->tls_array) + idx - GDT_ENTRY_TLS_MIN;
113 memset(&info, 0, sizeof(struct user_desc));
114 info.entry_number = idx;
115 info.base_addr = get_desc_base(desc);
116 info.limit = GET_LIMIT(desc);
117 info.seg_32bit = GET_32BIT(desc);
118 info.contents = GET_CONTENTS(desc);
119 info.read_exec_only = !GET_WRITABLE(desc);
120 info.limit_in_pages = GET_LIMIT_PAGES(desc);
121 info.seg_not_present = !GET_PRESENT(desc);
122 info.useable = GET_USEABLE(desc);
123 info.lm = GET_LONGMODE(desc);
125 if (copy_to_user(u_info, &info, sizeof(info)))
130 asmlinkage long sys32_get_thread_area(struct user_desc __user *u_info)
132 return do_get_thread_area(¤t->thread, u_info);
136 int ia32_child_tls(struct task_struct *p, struct pt_regs *childregs)
138 struct n_desc_struct *desc;
139 struct user_desc info;
140 struct user_desc __user *cp;
143 cp = (void __user *)childregs->rsi;
144 if (copy_from_user(&info, cp, sizeof(info)))
146 if (LDT_empty(&info))
149 idx = info.entry_number;
150 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
153 desc = (struct n_desc_struct *)(p->thread.tls_array) + idx - GDT_ENTRY_TLS_MIN;
154 desc->a = LDT_entry_a(&info);
155 desc->b = LDT_entry_b(&info);