arch/arm/kernel/ptrace.c
Source file repositories/reference/linux-study-clean/arch/arm/kernel/ptrace.c
File Facts
- System
- Linux kernel
- Corpus path
arch/arm/kernel/ptrace.c- Extension
.c- Size
- 21481 bytes
- Lines
- 897
- Domain
- Architecture Layer
- Bucket
- arch/arm
- Inferred role
- Architecture Layer: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- 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/signal.hlinux/sched/task_stack.hlinux/mm.hlinux/elf.hlinux/smp.hlinux/ptrace.hlinux/user.hlinux/security.hlinux/init.hlinux/signal.hlinux/uaccess.hlinux/perf_event.hlinux/hw_breakpoint.hlinux/regset.hlinux/audit.hlinux/unistd.hasm/syscall.hasm/traps.htrace/events/syscalls.h
Detected Declarations
struct pt_regs_offsetenum arm_regsetenum ptrace_syscall_dirfunction regs_query_register_offsetfunction regs_within_kernel_stackfunction regs_get_kernel_stack_nthfunction get_user_regfunction put_user_regfunction ptrace_disablefunction break_trapfunction ptrace_break_initfunction ptrace_read_userfunction ptrace_write_userfunction ptrace_getwmmxregsfunction ptrace_setwmmxregsfunction offunction ptrace_hbp_idx_to_numfunction ptrace_hbptriggeredfunction clear_ptrace_hw_breakpointfunction flush_ptrace_hw_breakpointfunction ptrace_get_hbp_resource_infofunction ptrace_gethbpregsfunction ptrace_sethbpregsfunction gpr_getfunction gpr_setfunction fpa_getfunction fpa_setfunction registersfunction vfp_setfunction arch_ptracefunction report_syscallfunction syscall_trace_enterfunction syscall_trace_exitmodule init ptrace_break_init
Annotated Snippet
core_initcall(ptrace_break_init);
/*
* Read the word at offset "off" into the "struct user". We
* actually access the pt_regs stored on the kernel stack.
*/
static int ptrace_read_user(struct task_struct *tsk, unsigned long off,
unsigned long __user *ret)
{
unsigned long tmp;
if (off & 3)
return -EIO;
tmp = 0;
if (off == PT_TEXT_ADDR)
tmp = tsk->mm->start_code;
else if (off == PT_DATA_ADDR)
tmp = tsk->mm->start_data;
else if (off == PT_TEXT_END_ADDR)
tmp = tsk->mm->end_code;
else if (off < sizeof(struct pt_regs))
tmp = get_user_reg(tsk, off >> 2);
else if (off >= sizeof(struct user))
return -EIO;
return put_user(tmp, ret);
}
/*
* Write the word at offset "off" into "struct user". We
* actually access the pt_regs stored on the kernel stack.
*/
static int ptrace_write_user(struct task_struct *tsk, unsigned long off,
unsigned long val)
{
if (off & 3 || off >= sizeof(struct user))
return -EIO;
if (off >= sizeof(struct pt_regs))
return 0;
return put_user_reg(tsk, off >> 2, val);
}
#ifdef CONFIG_IWMMXT
/*
* Get the child iWMMXt state.
*/
static int ptrace_getwmmxregs(struct task_struct *tsk, void __user *ufp)
{
struct thread_info *thread = task_thread_info(tsk);
if (!test_ti_thread_flag(thread, TIF_USING_IWMMXT))
return -ENODATA;
iwmmxt_task_disable(thread); /* force it to ram */
return copy_to_user(ufp, &thread->fpstate.iwmmxt, IWMMXT_SIZE)
? -EFAULT : 0;
}
/*
* Set the child iWMMXt state.
*/
static int ptrace_setwmmxregs(struct task_struct *tsk, void __user *ufp)
{
struct thread_info *thread = task_thread_info(tsk);
if (!test_ti_thread_flag(thread, TIF_USING_IWMMXT))
return -EACCES;
iwmmxt_task_release(thread); /* force a reload */
return copy_from_user(&thread->fpstate.iwmmxt, ufp, IWMMXT_SIZE)
? -EFAULT : 0;
}
#endif
#ifdef CONFIG_HAVE_HW_BREAKPOINT
/*
* Convert a virtual register number into an index for a thread_info
* breakpoint array. Breakpoints are identified using positive numbers
* whilst watchpoints are negative. The registers are laid out as pairs
* of (address, control), each pair mapping to a unique hw_breakpoint struct.
* Register 0 is reserved for describing resource information.
*/
static int ptrace_hbp_num_to_idx(long num)
{
if (num < 0)
num = (ARM_MAX_BRP << 1) - num;
return (num - 1) >> 1;
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/sched/signal.h`, `linux/sched/task_stack.h`, `linux/mm.h`, `linux/elf.h`, `linux/smp.h`, `linux/ptrace.h`, `linux/user.h`.
- Detected declarations: `struct pt_regs_offset`, `enum arm_regset`, `enum ptrace_syscall_dir`, `function regs_query_register_offset`, `function regs_within_kernel_stack`, `function regs_get_kernel_stack_nth`, `function get_user_reg`, `function put_user_reg`, `function ptrace_disable`, `function break_trap`.
- Atlas domain: Architecture Layer / arch/arm.
- Implementation status: integration 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.