arch/x86/um/tls_32.c
Source file repositories/reference/linux-study-clean/arch/x86/um/tls_32.c
File Facts
- System
- Linux kernel
- Corpus path
arch/x86/um/tls_32.c- Extension
.c- Size
- 9104 bytes
- Lines
- 387
- Domain
- Architecture Layer
- Bucket
- arch/x86
- Inferred role
- Architecture Layer: syscall or user/kernel boundary
- Status
- core implementation candidate
Why This File Exists
CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- Defines or participates in a user/kernel boundary; inspect argument validation, copy_from_user/copy_to_user, credentials, and dispatch target.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/percpu.hlinux/sched.hlinux/syscalls.hlinux/uaccess.hasm/ptrace-abi.hos.hskas.hsysdep/tls.hasm/desc.hstub-data.h
Detected Declarations
syscall set_thread_areasyscall get_thread_areafunction do_set_thread_areafunction herefunction clear_user_descfunction load_TLSfunction needs_TLS_updatefunction clear_flushed_tlsfunction whenfunction set_tls_entryfunction arch_set_tlsfunction get_tls_entryfunction ptrace_set_thread_areafunction ptrace_get_thread_areafunction __setup_host_supports_tls
Annotated Snippet
SYSCALL_DEFINE1(set_thread_area, struct user_desc __user *, user_desc)
{
struct user_desc info;
int idx, ret;
if (!host_supports_tls)
return -ENOSYS;
if (copy_from_user(&info, user_desc, sizeof(info)))
return -EFAULT;
idx = info.entry_number;
if (idx == -1) {
idx = get_free_idx(current);
if (idx < 0)
return idx;
info.entry_number = idx;
/* Tell the user which slot we chose for him.*/
if (put_user(idx, &user_desc->entry_number))
return -EFAULT;
}
ret = do_set_thread_area(current, &info);
if (ret)
return ret;
return set_tls_entry(current, &info, idx, 1);
}
/*
* Perform set_thread_area on behalf of the traced child.
* Note: error handling is not done on the deferred load, and this differ from
* i386. However the only possible error are caused by bugs.
*/
int ptrace_set_thread_area(struct task_struct *child, int idx,
struct user_desc __user *user_desc)
{
struct user_desc info;
if (!host_supports_tls)
return -EIO;
if (copy_from_user(&info, user_desc, sizeof(info)))
return -EFAULT;
return set_tls_entry(child, &info, idx, 0);
}
SYSCALL_DEFINE1(get_thread_area, struct user_desc __user *, user_desc)
{
struct user_desc info;
int idx, ret;
if (!host_supports_tls)
return -ENOSYS;
if (get_user(idx, &user_desc->entry_number))
return -EFAULT;
ret = get_tls_entry(current, &info, idx);
if (ret < 0)
goto out;
if (copy_to_user(user_desc, &info, sizeof(info)))
ret = -EFAULT;
out:
return ret;
}
/*
* Perform get_thread_area on behalf of the traced child.
*/
int ptrace_get_thread_area(struct task_struct *child, int idx,
struct user_desc __user *user_desc)
{
struct user_desc info;
int ret;
if (!host_supports_tls)
return -EIO;
ret = get_tls_entry(child, &info, idx);
if (ret < 0)
goto out;
if (copy_to_user(user_desc, &info, sizeof(info)))
ret = -EFAULT;
out:
return ret;
Annotation
- Immediate include surface: `linux/percpu.h`, `linux/sched.h`, `linux/syscalls.h`, `linux/uaccess.h`, `asm/ptrace-abi.h`, `os.h`, `skas.h`, `sysdep/tls.h`.
- Detected declarations: `syscall set_thread_area`, `syscall get_thread_area`, `function do_set_thread_area`, `function here`, `function clear_user_desc`, `function load_TLS`, `function needs_TLS_update`, `function clear_flushed_tls`, `function when`, `function set_tls_entry`.
- Atlas domain: Architecture Layer / arch/x86.
- Implementation status: core implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.