arch/nios2/kernel/ptrace.c
Source file repositories/reference/linux-study-clean/arch/nios2/kernel/ptrace.c
File Facts
- System
- Linux kernel
- Corpus path
arch/nios2/kernel/ptrace.c- Extension
.c- Size
- 3893 bytes
- Lines
- 146
- Domain
- Architecture Layer
- Bucket
- arch/nios2
- 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
linux/elf.hlinux/errno.hlinux/kernel.hlinux/mm.hlinux/ptrace.hlinux/regset.hlinux/sched.hlinux/sched/task_stack.hlinux/uaccess.hlinux/user.h
Detected Declarations
enum nios2_regsetfunction Copyrightfunction genregs_setfunction ptrace_disablefunction do_syscall_trace_enterfunction do_syscall_trace_exit
Annotated Snippet
#include <linux/elf.h>
#include <linux/errno.h>
#include <linux/kernel.h>
#include <linux/mm.h>
#include <linux/ptrace.h>
#include <linux/regset.h>
#include <linux/sched.h>
#include <linux/sched/task_stack.h>
#include <linux/uaccess.h>
#include <linux/user.h>
static int genregs_get(struct task_struct *target,
const struct user_regset *regset,
struct membuf to)
{
const struct pt_regs *regs = task_pt_regs(target);
const struct switch_stack *sw = (struct switch_stack *)regs - 1;
membuf_zero(&to, 4); // R0
membuf_write(&to, ®s->r1, 7 * 4); // R1..R7
membuf_write(&to, ®s->r8, 8 * 4); // R8..R15
membuf_write(&to, sw, 8 * 4); // R16..R23
membuf_zero(&to, 2 * 4); /* et and bt */
membuf_store(&to, regs->gp);
membuf_store(&to, regs->sp);
membuf_store(&to, regs->fp);
membuf_store(&to, regs->ea);
membuf_zero(&to, 4); // PTR_BA
membuf_store(&to, regs->ra);
membuf_store(&to, regs->ea); /* use ea for PC */
return membuf_zero(&to, (NUM_PTRACE_REG - PTR_PC) * 4);
}
/*
* Set the thread state from a regset passed in via ptrace
*/
static int genregs_set(struct task_struct *target,
const struct user_regset *regset,
unsigned int pos, unsigned int count,
const void *kbuf, const void __user *ubuf)
{
struct pt_regs *regs = task_pt_regs(target);
const struct switch_stack *sw = (struct switch_stack *)regs - 1;
int ret = 0;
#define REG_IGNORE_RANGE(START, END) \
if (!ret) \
user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf, \
START * 4, (END * 4) + 4);
#define REG_IN_ONE(PTR, LOC) \
if (!ret) \
ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, \
(void *)(PTR), LOC * 4, (LOC * 4) + 4);
#define REG_IN_RANGE(PTR, START, END) \
if (!ret) \
ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, \
(void *)(PTR), START * 4, (END * 4) + 4);
REG_IGNORE_RANGE(PTR_R0, PTR_R0);
REG_IN_RANGE(®s->r1, PTR_R1, PTR_R7);
REG_IN_RANGE(®s->r8, PTR_R8, PTR_R15);
REG_IN_RANGE(sw, PTR_R16, PTR_R23);
REG_IGNORE_RANGE(PTR_R24, PTR_R25); /* et and bt */
REG_IN_ONE(®s->gp, PTR_GP);
REG_IN_ONE(®s->sp, PTR_SP);
REG_IN_ONE(®s->fp, PTR_FP);
REG_IN_ONE(®s->ea, PTR_EA);
REG_IGNORE_RANGE(PTR_BA, PTR_BA);
REG_IN_ONE(®s->ra, PTR_RA);
REG_IN_ONE(®s->ea, PTR_PC); /* use ea for PC */
if (!ret)
user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
PTR_STATUS * 4, -1);
return ret;
}
/*
* Define the register sets available on Nios2 under Linux
*/
enum nios2_regset {
REGSET_GENERAL,
};
static const struct user_regset nios2_regsets[] = {
[REGSET_GENERAL] = {
USER_REGSET_NOTE_TYPE(PRSTATUS),
.n = NUM_PTRACE_REG,
Annotation
- Immediate include surface: `linux/elf.h`, `linux/errno.h`, `linux/kernel.h`, `linux/mm.h`, `linux/ptrace.h`, `linux/regset.h`, `linux/sched.h`, `linux/sched/task_stack.h`.
- Detected declarations: `enum nios2_regset`, `function Copyright`, `function genregs_set`, `function ptrace_disable`, `function do_syscall_trace_enter`, `function do_syscall_trace_exit`.
- Atlas domain: Architecture Layer / arch/nios2.
- 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.