arch/x86/kernel/ptrace.c
Source file repositories/reference/linux-study-clean/arch/x86/kernel/ptrace.c
File Facts
- System
- Linux kernel
- Corpus path
arch/x86/kernel/ptrace.c- Extension
.c- Size
- 35873 bytes
- Lines
- 1424
- 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.
- 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/kernel.hlinux/sched.hlinux/sched/task_stack.hlinux/mm.hlinux/smp.hlinux/errno.hlinux/slab.hlinux/ptrace.hlinux/user.hlinux/elf.hlinux/security.hlinux/audit.hlinux/seccomp.hlinux/signal.hlinux/perf_event.hlinux/hw_breakpoint.hlinux/rcupdate.hlinux/export.hlinux/context_tracking.hlinux/nospec.hlinux/uaccess.hasm/processor.hasm/fpu/signal.hasm/fpu/regset.hasm/fpu/xstate.hasm/debugreg.hasm/ldt.hasm/desc.hasm/prctl.hasm/proto.hasm/hw_breakpoint.hasm/traps.h
Detected Declarations
struct pt_regs_offsetenum x86_regset_32enum x86_regset_64function regs_query_register_offsetfunction invalid_selectorfunction get_segment_regfunction set_segment_regfunction user_modefunction get_segment_regfunction offsetoffunction offsetoffunction offsetoffunction set_segment_regfunction get_flagsfunction set_flagsfunction putregfunction getregfunction genregs_getfunction genregs_setfunction ptrace_triggeredfunction ptrace_get_dr7function ptrace_fill_bp_fieldsfunction ptrace_register_breakpointfunction ptrace_modify_breakpointfunction ptrace_write_dr7function ptrace_get_debugregfunction ptrace_set_breakpoint_addrfunction ptrace_set_debugregfunction anotherfunction ioperm_getfunction ptrace_disablefunction arch_ptracefunction putreg32function getreg32function genregs32_getfunction genregs32_setfunction ia32_arch_ptracefunction x32_arch_ptracefunction compat_arch_ptracefunction update_regset_xstate_infofunction fieldfunction send_sigtrapfunction user_single_step_report
Annotated Snippet
struct pt_regs_offset {
const char *name;
int offset;
};
#define REG_OFFSET_NAME(r) {.name = #r, .offset = offsetof(struct pt_regs, r)}
#define REG_OFFSET_END {.name = NULL, .offset = 0}
static const struct pt_regs_offset regoffset_table[] = {
#ifdef CONFIG_X86_64
REG_OFFSET_NAME(r15),
REG_OFFSET_NAME(r14),
REG_OFFSET_NAME(r13),
REG_OFFSET_NAME(r12),
REG_OFFSET_NAME(r11),
REG_OFFSET_NAME(r10),
REG_OFFSET_NAME(r9),
REG_OFFSET_NAME(r8),
#endif
REG_OFFSET_NAME(bx),
REG_OFFSET_NAME(cx),
REG_OFFSET_NAME(dx),
REG_OFFSET_NAME(si),
REG_OFFSET_NAME(di),
REG_OFFSET_NAME(bp),
REG_OFFSET_NAME(ax),
#ifdef CONFIG_X86_32
REG_OFFSET_NAME(ds),
REG_OFFSET_NAME(es),
REG_OFFSET_NAME(fs),
REG_OFFSET_NAME(gs),
#endif
REG_OFFSET_NAME(orig_ax),
REG_OFFSET_NAME(ip),
REG_OFFSET_NAME(cs),
REG_OFFSET_NAME(flags),
REG_OFFSET_NAME(sp),
REG_OFFSET_NAME(ss),
REG_OFFSET_END,
};
/**
* regs_query_register_offset() - query register offset from its name
* @name: the name of a register
*
* regs_query_register_offset() returns the offset of a register in struct
* pt_regs from its name. If the name is invalid, this returns -EINVAL;
*/
int regs_query_register_offset(const char *name)
{
const struct pt_regs_offset *roff;
for (roff = regoffset_table; roff->name != NULL; roff++)
if (!strcmp(roff->name, name))
return roff->offset;
return -EINVAL;
}
/**
* regs_query_register_name() - query register name from its offset
* @offset: the offset of a register in struct pt_regs.
*
* regs_query_register_name() returns the name of a register from its
* offset in struct pt_regs. If the @offset is invalid, this returns NULL;
*/
const char *regs_query_register_name(unsigned int offset)
{
const struct pt_regs_offset *roff;
for (roff = regoffset_table; roff->name != NULL; roff++)
if (roff->offset == offset)
return roff->name;
return NULL;
}
/*
* does not yet catch signals sent when the child dies.
* in exit.c or in signal.c.
*/
/*
* Determines which flags the user has access to [1 = access, 0 = no access].
*/
#define FLAG_MASK_32 ((unsigned long) \
(X86_EFLAGS_CF | X86_EFLAGS_PF | \
X86_EFLAGS_AF | X86_EFLAGS_ZF | \
X86_EFLAGS_SF | X86_EFLAGS_TF | \
X86_EFLAGS_DF | X86_EFLAGS_OF | \
X86_EFLAGS_RF | X86_EFLAGS_AC))
/*
* Determines whether a value may be installed in a segment register.
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/sched.h`, `linux/sched/task_stack.h`, `linux/mm.h`, `linux/smp.h`, `linux/errno.h`, `linux/slab.h`, `linux/ptrace.h`.
- Detected declarations: `struct pt_regs_offset`, `enum x86_regset_32`, `enum x86_regset_64`, `function regs_query_register_offset`, `function invalid_selector`, `function get_segment_reg`, `function set_segment_reg`, `function user_mode`, `function get_segment_reg`, `function offsetof`.
- Atlas domain: Architecture Layer / arch/x86.
- Implementation status: source 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.