summaryrefslogtreecommitdiffstats
path: root/runtime/probes.c
diff options
context:
space:
mode:
authorhunt <hunt>2005-03-21 21:06:50 +0000
committerhunt <hunt>2005-03-21 21:06:50 +0000
commite10ae0b0a445c70eafed2e6a7e8991191f023445 (patch)
treefc3bc70c38db5597aeff27caaa09407364fe138f /runtime/probes.c
parentc4ee89e1258ecce0abf46e5f57687106d727254c (diff)
downloadsystemtap-steved-e10ae0b0a445c70eafed2e6a7e8991191f023445.tar.gz
systemtap-steved-e10ae0b0a445c70eafed2e6a7e8991191f023445.tar.xz
systemtap-steved-e10ae0b0a445c70eafed2e6a7e8991191f023445.zip
Initial checkin. Code to load/unload jprobes and kprobes.
Diffstat (limited to 'runtime/probes.c')
-rw-r--r--runtime/probes.c81
1 files changed, 81 insertions, 0 deletions
diff --git a/runtime/probes.c b/runtime/probes.c
new file mode 100644
index 00000000..cb268e93
--- /dev/null
+++ b/runtime/probes.c
@@ -0,0 +1,81 @@
+/* -*- linux-c -*- */
+
+/** Create a new map.
+ * Maps must be created at module initialization time.
+ * @param max_entries The maximum number of entries allowed. Currently that
+ * will be allocated dynamically.
+ * @param type Type of values stored in this map.
+ * @return A MAP on success or NULL on failure.
+ */
+
+
+static unsigned long (*_stp_lookup_name)(char *name)=(void *)KALLSYMS_LOOKUP_NAME;
+
+void _stp_unregister_jprobes (struct jprobe *probes, int num_probes)
+{
+ int i;
+ for (i = 0; i < num_probes; i++)
+ unregister_jprobe(&probes[i]);
+ dlog ("All jprobes removed\n");
+}
+
+int _stp_register_jprobes (struct jprobe *probes, int num_probes)
+{
+ int i, ret ;
+ unsigned long addr;
+
+ for (i = 0; i < num_probes; i++) {
+ addr =_stp_lookup_name((char *)probes[i].kp.addr);
+ if (addr == 0) {
+ dlog ("ERROR: function %s not found!\n",
+ (char *)probes[i].kp.addr);
+ ret = -1; /* FIXME */
+ goto out;
+ }
+ dlog("inserting jprobe at %s (%p)\n", probes[i].kp.addr, addr);
+ probes[i].kp.addr = (kprobe_opcode_t *)addr;
+ ret = register_jprobe(&probes[i]);
+ if (ret)
+ goto out;
+ }
+ return 0;
+out:
+ dlog ("probe module initialization failed. Exiting...\n");
+ _stp_unregister_jprobes(probes, i);
+ return ret;
+}
+
+void _stp_unregister_kprobes (struct kprobe *probes, int num_probes)
+{
+ int i;
+ for (i = 0; i < num_probes; i++)
+ unregister_kprobe(&probes[i]);
+ dlog ("All kprobes removed\n");
+}
+
+int _stp_register_kprobes (struct kprobe *probes, int num_probes)
+{
+ int i, ret ;
+ unsigned long addr;
+
+ for (i = 0; i < num_probes; i++) {
+ addr =_stp_lookup_name((char *)probes[i].addr);
+ if (addr == 0) {
+ dlog ("ERROR: function %s not found!\n",
+ (char *)probes[i].addr);
+ ret = -1; /* FIXME */
+ goto out;
+ }
+ dlog("inserting kprobe at %s (%p)\n", probes[i].addr, addr);
+ probes[i].addr = (kprobe_opcode_t *)addr;
+ ret = register_kprobe(&probes[i]);
+ if (ret)
+ goto out;
+ }
+ return 0;
+out:
+ dlog ("probe module initialization failed. Exiting...\n");
+ _stp_unregister_kprobes(probes, i);
+ return ret;
+}
+