Skip to content

Commit 4d86dfb

Browse files
committed
ARC: kprobes support
Origin port done by Rajeshwar Ranga Signed-off-by: Vineet Gupta <vgupta@synopsys.com> Cc: Rajeshwar Ranga <rajeshwar.ranga@gmail.com>
1 parent e65ab5a commit 4d86dfb

7 files changed

Lines changed: 610 additions & 3 deletions

File tree

arch/arc/Kconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ config ARC
2424
select GENERIC_SMP_IDLE_THREAD
2525
select HAVE_ARCH_TRACEHOOK
2626
select HAVE_GENERIC_HARDIRQS
27+
select HAVE_KPROBES
28+
select HAVE_KRETPROBES
2729
select HAVE_MEMBLOCK
2830
select HAVE_MOD_ARCH_SPECIFIC if ARC_DW2_UNWIND
2931
select HAVE_OPROFILE

arch/arc/include/asm/kprobes.h

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License version 2 as
6+
* published by the Free Software Foundation.
7+
*/
8+
9+
#ifndef _ARC_KPROBES_H
10+
#define _ARC_KPROBES_H
11+
12+
#ifdef CONFIG_KPROBES
13+
14+
typedef u16 kprobe_opcode_t;
15+
16+
#define UNIMP_S_INSTRUCTION 0x79e0
17+
#define TRAP_S_2_INSTRUCTION 0x785e
18+
19+
#define MAX_INSN_SIZE 8
20+
#define MAX_STACK_SIZE 64
21+
22+
struct arch_specific_insn {
23+
int is_short;
24+
kprobe_opcode_t *t1_addr, *t2_addr;
25+
kprobe_opcode_t t1_opcode, t2_opcode;
26+
};
27+
28+
#define flush_insn_slot(p) do { } while (0)
29+
30+
#define kretprobe_blacklist_size 0
31+
32+
struct kprobe;
33+
34+
void arch_remove_kprobe(struct kprobe *p);
35+
36+
int kprobe_exceptions_notify(struct notifier_block *self,
37+
unsigned long val, void *data);
38+
39+
struct prev_kprobe {
40+
struct kprobe *kp;
41+
unsigned long status;
42+
};
43+
44+
struct kprobe_ctlblk {
45+
unsigned int kprobe_status;
46+
struct pt_regs jprobe_saved_regs;
47+
char jprobes_stack[MAX_STACK_SIZE];
48+
struct prev_kprobe prev_kprobe;
49+
};
50+
51+
int kprobe_fault_handler(struct pt_regs *regs, unsigned long cause);
52+
void kretprobe_trampoline(void);
53+
void trap_is_kprobe(unsigned long cause, unsigned long address,
54+
struct pt_regs *regs);
55+
#else
56+
static void trap_is_kprobe(unsigned long cause, unsigned long address,
57+
struct pt_regs *regs)
58+
{
59+
}
60+
#endif
61+
62+
#endif

arch/arc/include/asm/ptrace.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@ struct callee_regs {
111111
(struct pt_regs *)(pg_start + THREAD_SIZE - 4) - 1; \
112112
})
113113

114+
static inline long regs_return_value(struct pt_regs *regs)
115+
{
116+
return regs->r0;
117+
}
118+
114119
#endif /* !__ASSEMBLY__ */
115120

116121
#define orig_r8_IS_SCALL 0x0001

arch/arc/kernel/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ obj-y += devtree.o
1515
obj-$(CONFIG_MODULES) += arcksyms.o module.o
1616
obj-$(CONFIG_SMP) += smp.o
1717
obj-$(CONFIG_ARC_DW2_UNWIND) += unwind.o
18+
obj-$(CONFIG_KPROBES) += kprobes.o
1819

1920
obj-$(CONFIG_ARC_FPU_SAVE_RESTORE) += fpu.o
2021
CFLAGS_fpu.o += -mdpfp

arch/arc/kernel/disasm.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -497,9 +497,8 @@ void __kprobes set_reg(int reg, long val, struct pt_regs *regs,
497497
* @pc +2/4/6 (ARCompact ISA allows free intermixing of 16/32 bit insns).
498498
*
499499
* If @pc is a branch
500-
* -@tgt_if_br is set to branch target.
501-
* -If branch has delay slot, @next_pc updated with actual next PC.
502-
*
500+
* -@tgt_if_br is set to branch target.
501+
* -If branch has delay slot, @next_pc updated with actual next PC.
503502
*/
504503
int __kprobes disasm_next_pc(unsigned long pc, struct pt_regs *regs,
505504
struct callee_regs *cregs,

0 commit comments

Comments
 (0)