1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2014-2016 Pratyush Anand <panand@redhat.com>
5 #include <linux/highmem.h>
6 #include <linux/ptrace.h>
7 #include <linux/uprobes.h>
8 #include <asm/cacheflush.h>
10 #include "decode-insn.h"
12 #define UPROBE_TRAP_NR UINT_MAX
14 unsigned long uprobe_get_swbp_addr(struct pt_regs *regs)
16 return instruction_pointer(regs);
19 int arch_uprobe_analyze_insn(struct arch_uprobe *auprobe, struct mm_struct *mm,
24 insn = *(probe_opcode_t *)(&auprobe->insn[0]);
26 auprobe->insn_size = is_insn32(insn) ? 4 : 2;
28 switch (csky_probe_decode_insn(&insn, &auprobe->api)) {
32 case INSN_GOOD_NO_SLOT:
33 auprobe->simulate = true;
43 int arch_uprobe_pre_xol(struct arch_uprobe *auprobe, struct pt_regs *regs)
45 struct uprobe_task *utask = current->utask;
47 utask->autask.saved_trap_no = current->thread.trap_no;
48 current->thread.trap_no = UPROBE_TRAP_NR;
50 instruction_pointer_set(regs, utask->xol_vaddr);
52 user_enable_single_step(current);
57 int arch_uprobe_post_xol(struct arch_uprobe *auprobe, struct pt_regs *regs)
59 struct uprobe_task *utask = current->utask;
61 WARN_ON_ONCE(current->thread.trap_no != UPROBE_TRAP_NR);
63 instruction_pointer_set(regs, utask->vaddr + auprobe->insn_size);
65 user_disable_single_step(current);
70 bool arch_uprobe_xol_was_trapped(struct task_struct *t)
72 if (t->thread.trap_no != UPROBE_TRAP_NR)
78 bool arch_uprobe_skip_sstep(struct arch_uprobe *auprobe, struct pt_regs *regs)
83 if (!auprobe->simulate)
86 insn = *(probe_opcode_t *)(&auprobe->insn[0]);
87 addr = instruction_pointer(regs);
89 if (auprobe->api.handler)
90 auprobe->api.handler(insn, addr, regs);
95 void arch_uprobe_abort_xol(struct arch_uprobe *auprobe, struct pt_regs *regs)
97 struct uprobe_task *utask = current->utask;
100 * Task has received a fatal signal, so reset back to probbed
103 instruction_pointer_set(regs, utask->vaddr);
105 user_disable_single_step(current);
108 bool arch_uretprobe_is_alive(struct return_instance *ret, enum rp_check ctx,
109 struct pt_regs *regs)
111 if (ctx == RP_CHECK_CHAIN_CALL)
112 return regs->usp <= ret->stack;
114 return regs->usp < ret->stack;
118 arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr,
119 struct pt_regs *regs)
125 regs->lr = trampoline_vaddr;
130 int arch_uprobe_exception_notify(struct notifier_block *self,
131 unsigned long val, void *data)
136 int uprobe_breakpoint_handler(struct pt_regs *regs)
138 if (uprobe_pre_sstep_notifier(regs))
144 int uprobe_single_step_handler(struct pt_regs *regs)
146 if (uprobe_post_sstep_notifier(regs))