Lines Matching +full:if +full:- +full:idx
10 #include <asm/ptrace-abi.h>
15 #include <stub-data.h>
18 * If needed we can detect when it's uninitialized.
22 static int host_supports_tls = -1;
29 if (info->entry_number < host_gdt_entry_tls_min || in do_set_thread_area()
30 info->entry_number >= host_gdt_entry_tls_min + GDT_ENTRY_TLS_ENTRIES) in do_set_thread_area()
31 return -EINVAL; in do_set_thread_area()
33 if (using_seccomp) { in do_set_thread_area()
34 int idx = info->entry_number - host_gdt_entry_tls_min; in do_set_thread_area() local
35 struct stub_data *data = (void *)task->mm->context.id.stack; in do_set_thread_area()
37 data->arch_data.tls[idx] = *info; in do_set_thread_area()
38 data->arch_data.sync |= BIT(idx); in do_set_thread_area()
43 ret = os_set_thread_area(info, task->mm->context.id.pid); in do_set_thread_area()
45 if (ret) in do_set_thread_area()
47 "index = %d\n", ret, info->entry_number); in do_set_thread_area()
62 struct thread_struct *t = &task->thread; in get_free_idx()
63 int idx; in get_free_idx() local
65 for (idx = 0; idx < GDT_ENTRY_TLS_ENTRIES; idx++) in get_free_idx()
66 if (!t->arch.tls_array[idx].present) in get_free_idx()
67 return idx + GDT_ENTRY_TLS_MIN; in get_free_idx()
68 return -ESRCH; in get_free_idx()
77 * Check the LDT_empty or the i386 sys_get_thread_area code - we obtain in clear_user_desc()
80 info->read_exec_only = 1; in clear_user_desc()
81 info->seg_not_present = 1; in clear_user_desc()
89 int idx; in load_TLS() local
91 for (idx = GDT_ENTRY_TLS_MIN; idx < GDT_ENTRY_TLS_MAX; idx++) { in load_TLS()
93 &to->thread.arch.tls_array[idx - GDT_ENTRY_TLS_MIN]; in load_TLS()
96 * Actually, now if it wasn't flushed it gets cleared and in load_TLS()
99 if (!curr->present) { in load_TLS()
100 if (!curr->flushed) { in load_TLS()
101 clear_user_desc(&curr->tls); in load_TLS()
102 curr->tls.entry_number = idx; in load_TLS()
104 WARN_ON(!LDT_empty(&curr->tls)); in load_TLS()
109 if (!(flags & O_FORCE) && curr->flushed) in load_TLS()
112 ret = do_set_thread_area(current, &curr->tls); in load_TLS()
113 if (ret) in load_TLS()
116 curr->flushed = 1; in load_TLS()
123 * Verify if we need to do a flush for the new process, i.e. if there are any
124 * present desc's, only if they haven't been flushed.
133 &task->thread.arch.tls_array[i - GDT_ENTRY_TLS_MIN]; in needs_TLS_update()
136 * Can't test curr->present, we may need to clear a descriptor in needs_TLS_update()
139 if (curr->flushed) in needs_TLS_update()
157 &task->thread.arch.tls_array[i - GDT_ENTRY_TLS_MIN]; in clear_flushed_tls()
160 * Still correct to do this, if it wasn't present on the host it in clear_flushed_tls()
163 if (!curr->present) in clear_flushed_tls()
166 curr->flushed = 0; in clear_flushed_tls()
171 * In SKAS0 mode, currently, multiple guest threads sharing the same ->mm have a
174 * However, if each thread had a different host process (and this was discussed
177 * And this will not need be used when (and if) we'll add support to the host
183 if (!host_supports_tls) in arch_switch_tls()
189 * task->mm == NULL, which would cause a crash. in arch_switch_tls()
191 if (likely(to->mm)) in arch_switch_tls()
198 int idx, int flushed) in set_tls_entry() argument
200 struct thread_struct *t = &task->thread; in set_tls_entry()
202 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX) in set_tls_entry()
203 return -EINVAL; in set_tls_entry()
205 t->arch.tls_array[idx - GDT_ENTRY_TLS_MIN].tls = *info; in set_tls_entry()
206 t->arch.tls_array[idx - GDT_ENTRY_TLS_MIN].present = 1; in set_tls_entry()
207 t->arch.tls_array[idx - GDT_ENTRY_TLS_MIN].flushed = flushed; in set_tls_entry()
215 int idx, ret = -EFAULT; in arch_set_tls() local
217 if (copy_from_user(&info, (void __user *) tls, sizeof(info))) in arch_set_tls()
220 ret = -EINVAL; in arch_set_tls()
221 if (LDT_empty(&info)) in arch_set_tls()
224 idx = info.entry_number; in arch_set_tls()
226 ret = set_tls_entry(new, &info, idx, 0); in arch_set_tls()
232 int idx) in get_tls_entry() argument
234 struct thread_struct *t = &task->thread; in get_tls_entry()
236 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX) in get_tls_entry()
237 return -EINVAL; in get_tls_entry()
239 if (!t->arch.tls_array[idx - GDT_ENTRY_TLS_MIN].present) in get_tls_entry()
242 *info = t->arch.tls_array[idx - GDT_ENTRY_TLS_MIN].tls; in get_tls_entry()
247 * flushed. This could be triggered if load_TLS() failed. in get_tls_entry()
249 if (unlikely(task == current && in get_tls_entry()
250 !t->arch.tls_array[idx - GDT_ENTRY_TLS_MIN].flushed)) { in get_tls_entry()
252 "without flushed TLS.", current->pid); in get_tls_entry()
263 info->entry_number = idx; in get_tls_entry()
270 int idx, ret; in SYSCALL_DEFINE1() local
272 if (!host_supports_tls) in SYSCALL_DEFINE1()
273 return -ENOSYS; in SYSCALL_DEFINE1()
275 if (copy_from_user(&info, user_desc, sizeof(info))) in SYSCALL_DEFINE1()
276 return -EFAULT; in SYSCALL_DEFINE1()
278 idx = info.entry_number; in SYSCALL_DEFINE1()
280 if (idx == -1) { in SYSCALL_DEFINE1()
281 idx = get_free_idx(current); in SYSCALL_DEFINE1()
282 if (idx < 0) in SYSCALL_DEFINE1()
283 return idx; in SYSCALL_DEFINE1()
284 info.entry_number = idx; in SYSCALL_DEFINE1()
286 if (put_user(idx, &user_desc->entry_number)) in SYSCALL_DEFINE1()
287 return -EFAULT; in SYSCALL_DEFINE1()
291 if (ret) in SYSCALL_DEFINE1()
293 return set_tls_entry(current, &info, idx, 1); in SYSCALL_DEFINE1()
301 int ptrace_set_thread_area(struct task_struct *child, int idx, in ptrace_set_thread_area() argument
306 if (!host_supports_tls) in ptrace_set_thread_area()
307 return -EIO; in ptrace_set_thread_area()
309 if (copy_from_user(&info, user_desc, sizeof(info))) in ptrace_set_thread_area()
310 return -EFAULT; in ptrace_set_thread_area()
312 return set_tls_entry(child, &info, idx, 0); in ptrace_set_thread_area()
318 int idx, ret; in SYSCALL_DEFINE1() local
320 if (!host_supports_tls) in SYSCALL_DEFINE1()
321 return -ENOSYS; in SYSCALL_DEFINE1()
323 if (get_user(idx, &user_desc->entry_number)) in SYSCALL_DEFINE1()
324 return -EFAULT; in SYSCALL_DEFINE1()
326 ret = get_tls_entry(current, &info, idx); in SYSCALL_DEFINE1()
327 if (ret < 0) in SYSCALL_DEFINE1()
330 if (copy_to_user(user_desc, &info, sizeof(info))) in SYSCALL_DEFINE1()
331 ret = -EFAULT; in SYSCALL_DEFINE1()
340 int ptrace_get_thread_area(struct task_struct *child, int idx, in ptrace_get_thread_area() argument
346 if (!host_supports_tls) in ptrace_get_thread_area()
347 return -EIO; in ptrace_get_thread_area()
349 ret = get_tls_entry(child, &info, idx); in ptrace_get_thread_area()
350 if (ret < 0) in ptrace_get_thread_area()
353 if (copy_to_user(user_desc, &info, sizeof(info))) in ptrace_get_thread_area()
354 ret = -EFAULT; in ptrace_get_thread_area()
360 * This code is really i386-only, but it detects and logs x86_64 GDT indexes
361 * if a 32-bit UML is running on a 64-bit host.
366 if (host_supports_tls) { in __setup_host_supports_tls()