Skip to content

Commit d85eaa9

Browse files
mhiramatKAGA-KOKO
authored andcommitted
samples/kprobes: Add __kprobes and NOKPROBE_SYMBOL() for handlers.
Add __kprobes and NOKPROBE_SYMBOL() for sample kprobe handlers. Signed-off-by: Masami Hiramatsu <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Reviewed-by: Alexandre Chartre <[email protected]> Acked-by: Peter Zijlstra <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 16db626 commit d85eaa9

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

samples/kprobes/kprobe_example.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ static struct kprobe kp = {
2525
};
2626

2727
/* kprobe pre_handler: called just before the probed instruction is executed */
28-
static int handler_pre(struct kprobe *p, struct pt_regs *regs)
28+
static int __kprobes handler_pre(struct kprobe *p, struct pt_regs *regs)
2929
{
3030
#ifdef CONFIG_X86
3131
pr_info("<%s> pre_handler: p->addr = 0x%p, ip = %lx, flags = 0x%lx\n",
@@ -54,7 +54,7 @@ static int handler_pre(struct kprobe *p, struct pt_regs *regs)
5454
}
5555

5656
/* kprobe post_handler: called after the probed instruction is executed */
57-
static void handler_post(struct kprobe *p, struct pt_regs *regs,
57+
static void __kprobes handler_post(struct kprobe *p, struct pt_regs *regs,
5858
unsigned long flags)
5959
{
6060
#ifdef CONFIG_X86
@@ -90,6 +90,8 @@ static int handler_fault(struct kprobe *p, struct pt_regs *regs, int trapnr)
9090
/* Return 0 because we don't handle the fault. */
9191
return 0;
9292
}
93+
/* NOKPROBE_SYMBOL() is also available */
94+
NOKPROBE_SYMBOL(handler_fault);
9395

9496
static int __init kprobe_init(void)
9597
{

samples/kprobes/kretprobe_example.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ static int entry_handler(struct kretprobe_instance *ri, struct pt_regs *regs)
4848
data->entry_stamp = ktime_get();
4949
return 0;
5050
}
51+
NOKPROBE_SYMBOL(entry_handler);
5152

5253
/*
5354
* Return-probe handler: Log the return value and duration. Duration may turn
@@ -67,6 +68,7 @@ static int ret_handler(struct kretprobe_instance *ri, struct pt_regs *regs)
6768
func_name, retval, (long long)delta);
6869
return 0;
6970
}
71+
NOKPROBE_SYMBOL(ret_handler);
7072

7173
static struct kretprobe my_kretprobe = {
7274
.handler = ret_handler,

0 commit comments

Comments
 (0)