arch/arm64/kernel/ptrace.c
Source file repositories/reference/linux-study-clean/arch/arm64/kernel/ptrace.c
File Facts
- System
- Linux kernel
- Corpus path
arch/arm64/kernel/ptrace.c- Extension
.c- Size
- 61115 bytes
- Lines
- 2530
- Domain
- Architecture Layer
- Bucket
- arch/arm64
- 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/compat.hlinux/kernel.hlinux/sched/signal.hlinux/sched/task_stack.hlinux/mm.hlinux/nospec.hlinux/smp.hlinux/ptrace.hlinux/user.hlinux/seccomp.hlinux/security.hlinux/init.hlinux/signal.hlinux/string.hlinux/uaccess.hlinux/perf_event.hlinux/hw_breakpoint.hlinux/regset.hlinux/elf.hlinux/rseq.hasm/compat.hasm/cpufeature.hasm/debug-monitors.hasm/fpsimd.hasm/gcs.hasm/mte.hasm/pointer_auth.hasm/stacktrace.hasm/syscall.hasm/traps.hasm/system_misc.h
Detected Declarations
struct pt_regs_offsetenum aarch64_regsetenum compat_regsetenum ptrace_syscall_dirfunction regs_query_register_offsetfunction regs_within_kernel_stackfunction regs_get_kernel_stack_nthfunction ptrace_disablefunction ptrace_hbptriggeredfunction flush_ptrace_hw_breakpointfunction ptrace_hw_copy_threadfunction ptrace_hbp_set_eventfunction ptrace_hbp_fill_attr_ctrlfunction ptrace_hbp_get_resource_infofunction ptrace_hbp_get_ctrlfunction ptrace_hbp_get_addrfunction ptrace_hbp_set_ctrlfunction ptrace_hbp_set_addrfunction hw_break_getfunction hw_break_setfunction gpr_getfunction gpr_setfunction fpr_activefunction __fpr_getfunction fpr_getfunction __fpr_setfunction fpr_setfunction tls_getfunction tls_setfunction fpmr_getfunction fpmr_setfunction system_call_getfunction system_call_setfunction sve_init_header_from_taskfunction sve_size_from_headerfunction sve_get_commonfunction sve_getfunction sve_set_commonfunction sve_setfunction ssve_getfunction ssve_setfunction za_getfunction za_setfunction zt_getfunction zt_setfunction pac_mask_getfunction pac_enabled_keys_getfunction pac_enabled_keys_set
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}
#define GPR_OFFSET_NAME(r) \
{.name = "x" #r, .offset = offsetof(struct pt_regs, regs[r])}
static const struct pt_regs_offset regoffset_table[] = {
GPR_OFFSET_NAME(0),
GPR_OFFSET_NAME(1),
GPR_OFFSET_NAME(2),
GPR_OFFSET_NAME(3),
GPR_OFFSET_NAME(4),
GPR_OFFSET_NAME(5),
GPR_OFFSET_NAME(6),
GPR_OFFSET_NAME(7),
GPR_OFFSET_NAME(8),
GPR_OFFSET_NAME(9),
GPR_OFFSET_NAME(10),
GPR_OFFSET_NAME(11),
GPR_OFFSET_NAME(12),
GPR_OFFSET_NAME(13),
GPR_OFFSET_NAME(14),
GPR_OFFSET_NAME(15),
GPR_OFFSET_NAME(16),
GPR_OFFSET_NAME(17),
GPR_OFFSET_NAME(18),
GPR_OFFSET_NAME(19),
GPR_OFFSET_NAME(20),
GPR_OFFSET_NAME(21),
GPR_OFFSET_NAME(22),
GPR_OFFSET_NAME(23),
GPR_OFFSET_NAME(24),
GPR_OFFSET_NAME(25),
GPR_OFFSET_NAME(26),
GPR_OFFSET_NAME(27),
GPR_OFFSET_NAME(28),
GPR_OFFSET_NAME(29),
GPR_OFFSET_NAME(30),
{.name = "lr", .offset = offsetof(struct pt_regs, regs[30])},
REG_OFFSET_NAME(sp),
REG_OFFSET_NAME(pc),
REG_OFFSET_NAME(pstate),
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_within_kernel_stack() - check the address in the stack
* @regs: pt_regs which contains kernel stack pointer.
* @addr: address which is checked.
*
* regs_within_kernel_stack() checks @addr is within the kernel stack page(s).
* If @addr is within the kernel stack, it returns true. If not, returns false.
*/
static bool regs_within_kernel_stack(struct pt_regs *regs, unsigned long addr)
{
return ((addr & ~(THREAD_SIZE - 1)) ==
(kernel_stack_pointer(regs) & ~(THREAD_SIZE - 1))) ||
on_irq_stack(addr, sizeof(unsigned long));
}
/**
* regs_get_kernel_stack_nth() - get Nth entry of the stack
* @regs: pt_regs which contains kernel stack pointer.
* @n: stack entry number.
*
* regs_get_kernel_stack_nth() returns @n th entry of the kernel stack which
* is specified by @regs. If the @n th entry is NOT in the kernel stack,
* this returns 0.
*/
Annotation
- Immediate include surface: `linux/audit.h`, `linux/compat.h`, `linux/kernel.h`, `linux/sched/signal.h`, `linux/sched/task_stack.h`, `linux/mm.h`, `linux/nospec.h`, `linux/smp.h`.
- Detected declarations: `struct pt_regs_offset`, `enum aarch64_regset`, `enum compat_regset`, `enum ptrace_syscall_dir`, `function regs_query_register_offset`, `function regs_within_kernel_stack`, `function regs_get_kernel_stack_nth`, `function ptrace_disable`, `function ptrace_hbptriggered`, `function flush_ptrace_hw_breakpoint`.
- Atlas domain: Architecture Layer / arch/arm64.
- 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.