arch/x86/um/os-Linux/registers.c
Source file repositories/reference/linux-study-clean/arch/x86/um/os-Linux/registers.c
File Facts
- System
- Linux kernel
- Corpus path
arch/x86/um/os-Linux/registers.c- Extension
.c- Size
- 2198 bytes
- Lines
- 110
- Domain
- Architecture Layer
- Bucket
- arch/x86
- Inferred role
- Architecture Layer: implementation source
- Status
- source 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 uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
errno.hstdlib.hsys/ptrace.hsys/user.hlongjmp.hsysdep/ptrace_user.hsys/uio.hasm/sigcontext.hlinux/elf.hregisters.hsys/mman.h
Detected Declarations
function get_fp_registersfunction put_fp_registersfunction arch_init_registersfunction get_thread_reg
Annotated Snippet
#include <errno.h>
#include <stdlib.h>
#include <sys/ptrace.h>
#ifdef __i386__
#include <sys/user.h>
#endif
#include <longjmp.h>
#include <sysdep/ptrace_user.h>
#include <sys/uio.h>
#include <asm/sigcontext.h>
#include <linux/elf.h>
#include <registers.h>
#include <sys/mman.h>
static unsigned long ptrace_regset;
unsigned long host_fp_size;
int get_fp_registers(int pid, unsigned long *regs)
{
struct iovec iov = {
.iov_base = regs,
.iov_len = host_fp_size,
};
if (ptrace(PTRACE_GETREGSET, pid, ptrace_regset, &iov) < 0)
return -errno;
return 0;
}
int put_fp_registers(int pid, unsigned long *regs)
{
struct iovec iov = {
.iov_base = regs,
.iov_len = host_fp_size,
};
if (ptrace(PTRACE_SETREGSET, pid, ptrace_regset, &iov) < 0)
return -errno;
return 0;
}
int arch_init_registers(int pid)
{
struct iovec iov = {
/* Just use plenty of space, it does not cost us anything */
.iov_len = 2 * 1024 * 1024,
};
int ret;
iov.iov_base = mmap(NULL, iov.iov_len, PROT_WRITE | PROT_READ,
MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
if (iov.iov_base == MAP_FAILED)
return -ENOMEM;
/* GDB has x86_xsave_length, which uses x86_cpuid_count */
ptrace_regset = NT_X86_XSTATE;
ret = ptrace(PTRACE_GETREGSET, pid, ptrace_regset, &iov);
if (ret)
ret = -errno;
if (ret == -ENODEV) {
#ifdef CONFIG_X86_32
ptrace_regset = NT_PRXFPREG;
#else
ptrace_regset = NT_PRFPREG;
#endif
iov.iov_len = 2 * 1024 * 1024;
ret = ptrace(PTRACE_GETREGSET, pid, ptrace_regset, &iov);
if (ret)
ret = -errno;
}
munmap(iov.iov_base, 2 * 1024 * 1024);
host_fp_size = iov.iov_len;
return ret;
}
unsigned long get_thread_reg(int reg, jmp_buf *buf)
{
switch (reg) {
#ifdef __i386__
case HOST_IP:
return buf[0]->__eip;
case HOST_SP:
return buf[0]->__esp;
case HOST_BP:
return buf[0]->__ebp;
#else
Annotation
- Immediate include surface: `errno.h`, `stdlib.h`, `sys/ptrace.h`, `sys/user.h`, `longjmp.h`, `sysdep/ptrace_user.h`, `sys/uio.h`, `asm/sigcontext.h`.
- Detected declarations: `function get_fp_registers`, `function put_fp_registers`, `function arch_init_registers`, `function get_thread_reg`.
- Atlas domain: Architecture Layer / arch/x86.
- Implementation status: source implementation candidate.
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.