arch/um/kernel/ptrace.c
Source file repositories/reference/linux-study-clean/arch/um/kernel/ptrace.c
File Facts
- System
- Linux kernel
- Corpus path
arch/um/kernel/ptrace.c- Extension
.c- Size
- 3628 bytes
- Lines
- 162
- Domain
- Architecture Layer
- Bucket
- arch/um
- 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/audit.hlinux/ptrace.hlinux/sched.hlinux/uaccess.hasm/ptrace-abi.htrace/events/syscalls.h
Detected Declarations
function Copyrightfunction user_disable_single_stepfunction ptrace_disablefunction arch_ptracefunction send_sigtrapfunction syscall_trace_enterfunction syscall_trace_leave
Annotated Snippet
if (!access_ok(p, MAX_REG_OFFSET)) {
ret = -EIO;
break;
}
for ( i = 0; i < MAX_REG_OFFSET; i += sizeof(long) ) {
__put_user(getreg(child, i), p);
p++;
}
ret = 0;
break;
}
#endif
#ifdef PTRACE_SETREGS
case PTRACE_SETREGS: { /* Set all gp regs in the child. */
unsigned long tmp = 0;
if (!access_ok(p, MAX_REG_OFFSET)) {
ret = -EIO;
break;
}
for ( i = 0; i < MAX_REG_OFFSET; i += sizeof(long) ) {
__get_user(tmp, p);
putreg(child, i, tmp);
p++;
}
ret = 0;
break;
}
#endif
case PTRACE_GET_THREAD_AREA:
ret = ptrace_get_thread_area(child, addr, vp);
break;
case PTRACE_SET_THREAD_AREA:
ret = ptrace_set_thread_area(child, addr, vp);
break;
default:
ret = ptrace_request(child, request, addr, data);
if (ret == -EIO)
ret = subarch_ptrace(child, request, addr, data);
break;
}
return ret;
}
static void send_sigtrap(struct uml_pt_regs *regs, int error_code)
{
/* Send us the fake SIGTRAP */
force_sig_fault(SIGTRAP, TRAP_BRKPT,
/* User-mode eip? */
UPT_IS_USER(regs) ? (void __user *) UPT_IP(regs) : NULL);
}
/*
* XXX Check TIF_SINGLESTEP for singlestepping check and
* PT_PTRACED vs TIF_SYSCALL_TRACE for syscall tracing check
*/
int syscall_trace_enter(struct pt_regs *regs)
{
audit_syscall_entry(UPT_SYSCALL_NR(®s->regs),
UPT_SYSCALL_ARG1(®s->regs),
UPT_SYSCALL_ARG2(®s->regs),
UPT_SYSCALL_ARG3(®s->regs),
UPT_SYSCALL_ARG4(®s->regs));
if (test_thread_flag(TIF_SYSCALL_TRACEPOINT))
trace_sys_enter(regs, UPT_SYSCALL_NR(®s->regs));
if (!test_thread_flag(TIF_SYSCALL_TRACE))
return 0;
return ptrace_report_syscall_entry(regs);
}
void syscall_trace_leave(struct pt_regs *regs)
{
int ptraced = current->ptrace;
audit_syscall_exit(regs);
/* Fake a debug trap */
if (test_thread_flag(TIF_SINGLESTEP))
send_sigtrap(®s->regs, 0);
if (test_thread_flag(TIF_SYSCALL_TRACEPOINT))
trace_sys_exit(regs, PT_REGS_SYSCALL_RET(regs));
if (!test_thread_flag(TIF_SYSCALL_TRACE))
return;
Annotation
- Immediate include surface: `linux/audit.h`, `linux/ptrace.h`, `linux/sched.h`, `linux/uaccess.h`, `asm/ptrace-abi.h`, `trace/events/syscalls.h`.
- Detected declarations: `function Copyright`, `function user_disable_single_step`, `function ptrace_disable`, `function arch_ptrace`, `function send_sigtrap`, `function syscall_trace_enter`, `function syscall_trace_leave`.
- Atlas domain: Architecture Layer / arch/um.
- 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.