arch/csky/kernel/probes/kprobes.c
Source file repositories/reference/linux-study-clean/arch/csky/kernel/probes/kprobes.c
File Facts
- System
- Linux kernel
- Corpus path
arch/csky/kernel/probes/kprobes.c- Extension
.c- Size
- 9910 bytes
- Lines
- 413
- Domain
- Architecture Layer
- Bucket
- arch/csky
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kprobes.hlinux/extable.hlinux/slab.hlinux/stop_machine.hasm/ptrace.hlinux/uaccess.hasm/sections.hasm/cacheflush.hdecode-insn.h
Detected Declarations
struct csky_insn_patchfunction patch_text_cbfunction patch_textfunction arch_prepare_ss_slotfunction arch_prepare_simulatefunction arch_simulate_insnfunction arch_prepare_kprobefunction arch_arm_kprobefunction arch_disarm_kprobefunction arch_remove_kprobefunction save_previous_kprobefunction restore_previous_kprobefunction set_current_kprobefunction kprobes_save_local_irqflagfunction kprobes_restore_local_irqflagfunction set_ss_contextfunction clear_ss_contextfunction setup_singlestepfunction reenter_kprobefunction post_kprobe_handlerfunction kprobe_fault_handlerfunction kprobe_breakpoint_handlerfunction kprobe_single_step_handlerfunction debugfsfunction arch_prepare_kretprobefunction arch_trampoline_kprobefunction arch_init_kprobes
Annotated Snippet
struct csky_insn_patch {
kprobe_opcode_t *addr;
u32 opcode;
atomic_t cpu_count;
};
static int __kprobes patch_text_cb(void *priv)
{
struct csky_insn_patch *param = priv;
unsigned int addr = (unsigned int)param->addr;
if (atomic_inc_return(¶m->cpu_count) == num_online_cpus()) {
*(u16 *) addr = cpu_to_le16(param->opcode);
dcache_wb_range(addr, addr + 2);
atomic_inc(¶m->cpu_count);
} else {
while (atomic_read(¶m->cpu_count) <= num_online_cpus())
cpu_relax();
}
icache_inv_range(addr, addr + 2);
return 0;
}
static int __kprobes patch_text(kprobe_opcode_t *addr, u32 opcode)
{
struct csky_insn_patch param = { addr, opcode, ATOMIC_INIT(0) };
return stop_machine_cpuslocked(patch_text_cb, ¶m, cpu_online_mask);
}
static void __kprobes arch_prepare_ss_slot(struct kprobe *p)
{
unsigned long offset = is_insn32(p->opcode) ? 4 : 2;
p->ainsn.api.restore = (unsigned long)p->addr + offset;
patch_text(p->ainsn.api.insn, p->opcode);
}
static void __kprobes arch_prepare_simulate(struct kprobe *p)
{
p->ainsn.api.restore = 0;
}
static void __kprobes arch_simulate_insn(struct kprobe *p, struct pt_regs *regs)
{
struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
if (p->ainsn.api.handler)
p->ainsn.api.handler((u32)p->opcode, (long)p->addr, regs);
post_kprobe_handler(kcb, regs);
}
int __kprobes arch_prepare_kprobe(struct kprobe *p)
{
unsigned long probe_addr = (unsigned long)p->addr;
if (probe_addr & 0x1)
return -EILSEQ;
/* copy instruction */
p->opcode = le32_to_cpu(*p->addr);
/* decode instruction */
switch (csky_probe_decode_insn(p->addr, &p->ainsn.api)) {
case INSN_REJECTED: /* insn not supported */
return -EINVAL;
case INSN_GOOD_NO_SLOT: /* insn need simulation */
p->ainsn.api.insn = NULL;
break;
case INSN_GOOD: /* instruction uses slot */
p->ainsn.api.insn = get_insn_slot();
if (!p->ainsn.api.insn)
return -ENOMEM;
break;
}
/* prepare the instruction */
if (p->ainsn.api.insn)
arch_prepare_ss_slot(p);
else
arch_prepare_simulate(p);
return 0;
}
Annotation
- Immediate include surface: `linux/kprobes.h`, `linux/extable.h`, `linux/slab.h`, `linux/stop_machine.h`, `asm/ptrace.h`, `linux/uaccess.h`, `asm/sections.h`, `asm/cacheflush.h`.
- Detected declarations: `struct csky_insn_patch`, `function patch_text_cb`, `function patch_text`, `function arch_prepare_ss_slot`, `function arch_prepare_simulate`, `function arch_simulate_insn`, `function arch_prepare_kprobe`, `function arch_arm_kprobe`, `function arch_disarm_kprobe`, `function arch_remove_kprobe`.
- Atlas domain: Architecture Layer / arch/csky.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.