Skip to contentSkip to conversation

samples/kprobes: add a new module parameter

PATCH New [email protected] 1 participant 1 message May 21, 2016 kprobes

lore
Share & tools
lore
#0 lore raw

PATCH 161/162 samples/kprobes: add a new module parameter

From: Huang Shijie <[email protected]>
Subject: samples/kprobes: add a new module parameter

Add a new module parameter which can be used as the symbol name. Without this patch, we can only test the "_do_fork" function with this kernel module. With this patch, the module becomes more flexible; we can test any functions with this module with

	# insmod kprobe_example.ko symbol="xxx"

---

 samples/kprobes/kprobe_example.c |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
samples/kprobes/kprobe_example.c renamed from samples/kprobes/kprobe_example.c~kprobes-add-a-new-module-parameter +5 -1
diff -puN samples/kprobes/kprobe_example.c~kprobes-add-a-new-module-parameter samples/kprobes/kprobe_example.c
@@ -14,9 +14,13 @@
 #include <linux/module.h>
 #include <linux/kprobes.h>
 
+#define MAX_SYMBOL_LEN	64
+static char symbol[MAX_SYMBOL_LEN] = "_do_fork";
+module_param_string(symbol, symbol, sizeof(symbol), 0644);
+
 /* For each probe you need to allocate a kprobe structure */
 static struct kprobe kp = {
-	.symbol_name	= "_do_fork",
+	.symbol_name	= symbol,
 };
 
 /* kprobe pre_handler: called just before the probed instruction is executed */

_