arch/riscv/kernel/ptrace.c
Source file repositories/reference/linux-study-clean/arch/riscv/kernel/ptrace.c
File Facts
- System
- Linux kernel
- Corpus path
arch/riscv/kernel/ptrace.c- Extension
.c- Size
- 16745 bytes
- Lines
- 638
- Domain
- Architecture Layer
- Bucket
- arch/riscv
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
asm/vector.hasm/ptrace.hasm/syscall.hasm/thread_info.hasm/switch_to.hlinux/audit.hlinux/compat.hlinux/ptrace.hlinux/elf.hlinux/regset.hlinux/sched.hlinux/sched/task_stack.hasm/usercfi.h
Detected Declarations
struct pt_regs_offsetenum riscv_regsetfunction riscv_gpr_getfunction riscv_gpr_setfunction riscv_fpr_getfunction riscv_fpr_setfunction riscv_vr_getfunction invalid_ptrace_v_csrfunction riscv_vr_setfunction riscv_vr_activefunction tagged_addr_ctrl_getfunction tagged_addr_ctrl_setfunction riscv_cfi_getfunction riscv_cfi_setfunction update_regset_vector_infofunction regs_query_register_offsetfunction regs_within_kernel_stackfunction regs_get_kernel_stack_nthfunction ptrace_disablefunction compat_riscv_gpr_getfunction compat_riscv_gpr_setfunction compat_arch_ptrace
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[] = {
REG_OFFSET_NAME(epc),
REG_OFFSET_NAME(ra),
REG_OFFSET_NAME(sp),
REG_OFFSET_NAME(gp),
REG_OFFSET_NAME(tp),
REG_OFFSET_NAME(t0),
REG_OFFSET_NAME(t1),
REG_OFFSET_NAME(t2),
REG_OFFSET_NAME(s0),
REG_OFFSET_NAME(s1),
REG_OFFSET_NAME(a0),
REG_OFFSET_NAME(a1),
REG_OFFSET_NAME(a2),
REG_OFFSET_NAME(a3),
REG_OFFSET_NAME(a4),
REG_OFFSET_NAME(a5),
REG_OFFSET_NAME(a6),
REG_OFFSET_NAME(a7),
REG_OFFSET_NAME(s2),
REG_OFFSET_NAME(s3),
REG_OFFSET_NAME(s4),
REG_OFFSET_NAME(s5),
REG_OFFSET_NAME(s6),
REG_OFFSET_NAME(s7),
REG_OFFSET_NAME(s8),
REG_OFFSET_NAME(s9),
REG_OFFSET_NAME(s10),
REG_OFFSET_NAME(s11),
REG_OFFSET_NAME(t3),
REG_OFFSET_NAME(t4),
REG_OFFSET_NAME(t5),
REG_OFFSET_NAME(t6),
REG_OFFSET_NAME(status),
REG_OFFSET_NAME(badaddr),
REG_OFFSET_NAME(cause),
REG_OFFSET_NAME(orig_a0),
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));
}
/**
* 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.
*/
unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs, unsigned int n)
{
Annotation
- Immediate include surface: `asm/vector.h`, `asm/ptrace.h`, `asm/syscall.h`, `asm/thread_info.h`, `asm/switch_to.h`, `linux/audit.h`, `linux/compat.h`, `linux/ptrace.h`.
- Detected declarations: `struct pt_regs_offset`, `enum riscv_regset`, `function riscv_gpr_get`, `function riscv_gpr_set`, `function riscv_fpr_get`, `function riscv_fpr_set`, `function riscv_vr_get`, `function invalid_ptrace_v_csr`, `function riscv_vr_set`, `function riscv_vr_active`.
- Atlas domain: Architecture Layer / arch/riscv.
- Implementation status: source implementation candidate.
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.