arch/xtensa/kernel/ptrace.c
Source file repositories/reference/linux-study-clean/arch/xtensa/kernel/ptrace.c
File Facts
- System
- Linux kernel
- Corpus path
arch/xtensa/kernel/ptrace.c- Extension
.c- Size
- 13979 bytes
- Lines
- 585
- Domain
- Architecture Layer
- Bucket
- arch/xtensa
- 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.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/audit.hlinux/errno.hlinux/hw_breakpoint.hlinux/kernel.hlinux/mm.hlinux/perf_event.hlinux/ptrace.hlinux/regset.hlinux/sched.hlinux/sched/task_stack.hlinux/seccomp.hlinux/security.hlinux/signal.hlinux/smp.hlinux/uaccess.htrace/events/syscalls.hasm/coprocessor.hasm/elf.hasm/page.hasm/ptrace.h
Detected Declarations
enum xtensa_regsetfunction Copyrightfunction gpr_setfunction tie_getfunction tie_setfunction user_enable_single_stepfunction user_disable_single_stepfunction ptrace_disablefunction ptrace_setregsfunction ptrace_getxregsfunction ptrace_setxregsfunction ptrace_peekusrfunction ptrace_pokeusrfunction ptrace_hbptriggeredfunction instructionfunction ptrace_sethbpregsfunction arch_ptracefunction do_syscall_trace_enterfunction do_syscall_trace_leave
Annotated Snippet
if (dbreak) {
if (bp->attr.bp_type & HW_BREAKPOINT_R)
user_data[1] |= DBREAKC_LOAD_MASK;
if (bp->attr.bp_type & HW_BREAKPOINT_W)
user_data[1] |= DBREAKC_STOR_MASK;
}
}
if (copy_to_user(datap, user_data, sizeof(user_data)))
return -EFAULT;
return 0;
}
static long ptrace_sethbpregs(struct task_struct *child, long addr,
long __user *datap)
{
struct perf_event *bp;
struct perf_event_attr attr;
u32 user_data[2];
bool dbreak = addr & 1;
unsigned idx = addr >> 1;
int bp_type = 0;
if ((!dbreak && idx >= XCHAL_NUM_IBREAK) ||
(dbreak && idx >= XCHAL_NUM_DBREAK))
return -EINVAL;
if (copy_from_user(user_data, datap, sizeof(user_data)))
return -EFAULT;
if (dbreak) {
bp = child->thread.ptrace_wp[idx];
if (user_data[1] & DBREAKC_LOAD_MASK)
bp_type |= HW_BREAKPOINT_R;
if (user_data[1] & DBREAKC_STOR_MASK)
bp_type |= HW_BREAKPOINT_W;
} else {
bp = child->thread.ptrace_bp[idx];
bp_type = HW_BREAKPOINT_X;
}
if (!bp) {
bp = ptrace_hbp_create(child,
bp_type ? bp_type : HW_BREAKPOINT_RW);
if (IS_ERR(bp))
return PTR_ERR(bp);
if (dbreak)
child->thread.ptrace_wp[idx] = bp;
else
child->thread.ptrace_bp[idx] = bp;
}
attr = bp->attr;
attr.bp_addr = user_data[0];
attr.bp_len = user_data[1] & ~(DBREAKC_LOAD_MASK | DBREAKC_STOR_MASK);
attr.bp_type = bp_type;
attr.disabled = !attr.bp_len;
return modify_user_hw_breakpoint(bp, &attr);
}
#endif
long arch_ptrace(struct task_struct *child, long request,
unsigned long addr, unsigned long data)
{
int ret = -EPERM;
void __user *datap = (void __user *) data;
switch (request) {
case PTRACE_PEEKUSR: /* read register specified by addr. */
ret = ptrace_peekusr(child, addr, datap);
break;
case PTRACE_POKEUSR: /* write register specified by addr. */
ret = ptrace_pokeusr(child, addr, data);
break;
case PTRACE_GETREGS:
ret = ptrace_getregs(child, datap);
break;
case PTRACE_SETREGS:
ret = ptrace_setregs(child, datap);
break;
case PTRACE_GETXTREGS:
ret = ptrace_getxregs(child, datap);
break;
Annotation
- Immediate include surface: `linux/audit.h`, `linux/errno.h`, `linux/hw_breakpoint.h`, `linux/kernel.h`, `linux/mm.h`, `linux/perf_event.h`, `linux/ptrace.h`, `linux/regset.h`.
- Detected declarations: `enum xtensa_regset`, `function Copyright`, `function gpr_set`, `function tie_get`, `function tie_set`, `function user_enable_single_step`, `function user_disable_single_step`, `function ptrace_disable`, `function ptrace_setregs`, `function ptrace_getxregs`.
- Atlas domain: Architecture Layer / arch/xtensa.
- 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.