.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * NOTE: This example is works on x86 and powerpc. |
---|
3 | 4 | * Here's a sample kernel module showing the use of kprobes to dump a |
---|
4 | | - * stack trace and selected registers when _do_fork() is called. |
---|
| 5 | + * stack trace and selected registers when kernel_clone() is called. |
---|
5 | 6 | * |
---|
6 | 7 | * For more information on theory of operation of kprobes, see |
---|
7 | | - * Documentation/kprobes.txt |
---|
| 8 | + * Documentation/trace/kprobes.rst |
---|
8 | 9 | * |
---|
9 | 10 | * You will see the trace data in /var/log/messages and on the console |
---|
10 | | - * whenever _do_fork() is invoked to create a new process. |
---|
| 11 | + * whenever kernel_clone() is invoked to create a new process. |
---|
11 | 12 | */ |
---|
12 | 13 | |
---|
13 | 14 | #include <linux/kernel.h> |
---|
.. | .. |
---|
15 | 16 | #include <linux/kprobes.h> |
---|
16 | 17 | |
---|
17 | 18 | #define MAX_SYMBOL_LEN 64 |
---|
18 | | -static char symbol[MAX_SYMBOL_LEN] = "_do_fork"; |
---|
| 19 | +static char symbol[MAX_SYMBOL_LEN] = "kernel_clone"; |
---|
19 | 20 | module_param_string(symbol, symbol, sizeof(symbol), 0644); |
---|
20 | 21 | |
---|
21 | 22 | /* For each probe you need to allocate a kprobe structure */ |
---|
.. | .. |
---|
24 | 25 | }; |
---|
25 | 26 | |
---|
26 | 27 | /* kprobe pre_handler: called just before the probed instruction is executed */ |
---|
27 | | -static int handler_pre(struct kprobe *p, struct pt_regs *regs) |
---|
| 28 | +static int __kprobes handler_pre(struct kprobe *p, struct pt_regs *regs) |
---|
28 | 29 | { |
---|
29 | 30 | #ifdef CONFIG_X86 |
---|
30 | 31 | pr_info("<%s> pre_handler: p->addr = 0x%p, ip = %lx, flags = 0x%lx\n", |
---|
.. | .. |
---|
53 | 54 | } |
---|
54 | 55 | |
---|
55 | 56 | /* kprobe post_handler: called after the probed instruction is executed */ |
---|
56 | | -static void handler_post(struct kprobe *p, struct pt_regs *regs, |
---|
| 57 | +static void __kprobes handler_post(struct kprobe *p, struct pt_regs *regs, |
---|
57 | 58 | unsigned long flags) |
---|
58 | 59 | { |
---|
59 | 60 | #ifdef CONFIG_X86 |
---|
.. | .. |
---|
89 | 90 | /* Return 0 because we don't handle the fault. */ |
---|
90 | 91 | return 0; |
---|
91 | 92 | } |
---|
| 93 | +/* NOKPROBE_SYMBOL() is also available */ |
---|
| 94 | +NOKPROBE_SYMBOL(handler_fault); |
---|
92 | 95 | |
---|
93 | 96 | static int __init kprobe_init(void) |
---|
94 | 97 | { |
---|