update
[lttv.git] / marker-loader / marker-loader.c
1 /* marker-loader.c
2 *
3 * Marker Loader
4 *
5 * Loads a function at a marker call site.
6 *
7 * (C) Copyright 2006 Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
8 *
9 * This file is released under the GPLv2.
10 * See the file COPYING for more details.
11 */
12
13 #include <linux/marker.h>
14 #include <linux/module.h>
15 #include <linux/kallsyms.h>
16
17 /* function to install */
18 void do_mark1(const char *format, int value)
19 {
20 printk("value is %d\n", value);
21 }
22
23
24 //#define CALL __mark_subsys_mark1_call
25 //#define JUMP_OVER __mark_subsys_mark1_jump_over
26 //#define JUMP_CALL __mark_subsys_mark1_jump_call
27 //#define JUMP_INLINE __mark_subsys_mark1_jump_inline
28
29 static void *saved_over;
30
31 static void **target_mark_call;
32 static void **target_mark_jump_over;
33 static void **target_mark_jump_call;
34 static void **target_mark_jump_inline;
35
36 void show_symbol_pointers(void)
37 {
38 printk("Marker loader : Loading symbols...\n");
39 printk(" %s %p %p\n", __stringify(CALL), target_mark_call,
40 target_mark_call?*target_mark_call:0x0);
41 printk(" %s %p %p\n", __stringify(JUMP_OVER), target_mark_jump_over,
42 target_mark_jump_over?*target_mark_jump_over:0x0);
43 printk(" %s %p %p\n", __stringify(JUMP_CALL), target_mark_jump_call,
44 target_mark_jump_call?*target_mark_jump_call:0x0);
45 printk(" %s %p %p\n", __stringify(JUMP_INLINE), target_mark_jump_inline,
46 target_mark_jump_inline?*target_mark_jump_inline:0x0);
47 }
48
49 int mark_install_hook(void)
50 {
51 target_mark_call = (void**)kallsyms_lookup_name(__stringify(CALL));
52 target_mark_jump_over = (void**)kallsyms_lookup_name(__stringify(JUMP_OVER));
53 target_mark_jump_call = (void**)kallsyms_lookup_name(__stringify(JUMP_CALL));
54 target_mark_jump_inline = (void**)kallsyms_lookup_name(__stringify(JUMP_INLINE));
55
56 show_symbol_pointers();
57
58 if(!(target_mark_call && target_mark_jump_over && target_mark_jump_call &&
59 target_mark_jump_inline)) {
60 printk("Target symbols missing in kallsyms.\n");
61 return -EPERM;
62 }
63
64 printk("Installing hook\n");
65 *target_mark_call = (void*)do_mark1;
66 saved_over = *target_mark_jump_over;
67 *target_mark_jump_over = *target_mark_jump_call;
68
69 return 0;
70 }
71
72 int init_module(void)
73 {
74 return mark_install_hook();
75 }
76
77 void cleanup_module(void)
78 {
79 printk("Removing hook\n");
80 *target_mark_jump_over = saved_over;
81 *target_mark_call = __mark_empty_function;
82
83 /* Wait for instrumentation functions to return before quitting */
84 synchronize_sched();
85 }
86
87 MODULE_LICENSE("GPL");
88 MODULE_AUTHOR("Mathieu Desnoyers");
89 MODULE_DESCRIPTION("Marker Loader");
90
This page took 0.0318349999999999 seconds and 5 git commands to generate.