| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * kretprobe_example.c |
|---|
| 3 | 4 | * |
|---|
| .. | .. |
|---|
| 7 | 8 | * |
|---|
| 8 | 9 | * usage: insmod kretprobe_example.ko func=<func_name> |
|---|
| 9 | 10 | * |
|---|
| 10 | | - * If no func_name is specified, _do_fork is instrumented |
|---|
| 11 | + * If no func_name is specified, kernel_clone is instrumented |
|---|
| 11 | 12 | * |
|---|
| 12 | 13 | * For more information on theory of operation of kretprobes, see |
|---|
| 13 | | - * Documentation/kprobes.txt |
|---|
| 14 | + * Documentation/trace/kprobes.rst |
|---|
| 14 | 15 | * |
|---|
| 15 | 16 | * Build and insert the kernel module as done in the kprobe example. |
|---|
| 16 | 17 | * You will see the trace data in /var/log/messages and on the console |
|---|
| .. | .. |
|---|
| 25 | 26 | #include <linux/limits.h> |
|---|
| 26 | 27 | #include <linux/sched.h> |
|---|
| 27 | 28 | |
|---|
| 28 | | -static char func_name[NAME_MAX] = "_do_fork"; |
|---|
| 29 | +static char func_name[NAME_MAX] = "kernel_clone"; |
|---|
| 29 | 30 | module_param_string(func, func_name, NAME_MAX, S_IRUGO); |
|---|
| 30 | 31 | MODULE_PARM_DESC(func, "Function to kretprobe; this module will report the" |
|---|
| 31 | 32 | " function's execution time"); |
|---|
| .. | .. |
|---|
| 47 | 48 | data->entry_stamp = ktime_get(); |
|---|
| 48 | 49 | return 0; |
|---|
| 49 | 50 | } |
|---|
| 51 | +NOKPROBE_SYMBOL(entry_handler); |
|---|
| 50 | 52 | |
|---|
| 51 | 53 | /* |
|---|
| 52 | 54 | * Return-probe handler: Log the return value and duration. Duration may turn |
|---|
| .. | .. |
|---|
| 66 | 68 | func_name, retval, (long long)delta); |
|---|
| 67 | 69 | return 0; |
|---|
| 68 | 70 | } |
|---|
| 71 | +NOKPROBE_SYMBOL(ret_handler); |
|---|
| 69 | 72 | |
|---|
| 70 | 73 | static struct kretprobe my_kretprobe = { |
|---|
| 71 | 74 | .handler = ret_handler, |
|---|