292f312a |
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 PROBE_NAME subsys_mark1 |
25 | |
26 | #define CALL __mark_subsys_mark1_call |
27 | #define JUMP_OVER __mark_subsys_mark1_jump_over |
28 | #define JUMP_CALL __mark_subsys_mark1_jump_call |
29 | #define JUMP_INLINE __mark_subsys_mark1_jump_inline |
30 | |
31 | static void *saved_over; |
32 | |
33 | static void **target_mark_call; |
34 | static void **target_mark_jump_over; |
35 | static void **target_mark_jump_call; |
36 | static void **target_mark_jump_inline; |
37 | |
38 | void show_symbol_pointers(void) |
39 | { |
40 | printk("Marker loader : Loading symbols...\n"); |
41 | printk(" %s %p %p\n", __stringify(CALL), target_mark_call, |
42 | target_mark_call?*target_mark_call:0x0); |
43 | printk(" %s %p %p\n", __stringify(JUMP_OVER), target_mark_jump_over, |
44 | target_mark_jump_over?*target_mark_jump_over:0x0); |
45 | printk(" %s %p %p\n", __stringify(JUMP_CALL), target_mark_jump_call, |
46 | target_mark_jump_call?*target_mark_jump_call:0x0); |
47 | printk(" %s %p %p\n", __stringify(JUMP_INLINE), target_mark_jump_inline, |
48 | target_mark_jump_inline?*target_mark_jump_inline:0x0); |
49 | } |
50 | |
51 | int mark_install_hook(void) |
52 | { |
53 | target_mark_call = (void**)kallsyms_lookup_name(__stringify(CALL)); |
54 | target_mark_jump_over = (void**)kallsyms_lookup_name(__stringify(JUMP_OVER)); |
55 | target_mark_jump_call = (void**)kallsyms_lookup_name(__stringify(JUMP_CALL)); |
56 | target_mark_jump_inline = (void**)kallsyms_lookup_name(__stringify(JUMP_INLINE)); |
57 | |
58 | show_symbol_pointers(); |
59 | |
60 | if(!(target_mark_call && target_mark_jump_over && target_mark_jump_call && |
61 | target_mark_jump_inline)) { |
62 | printk("Target symbols missing in kallsyms.\n"); |
63 | return -EPERM; |
64 | } |
65 | |
66 | printk("Installing hook\n"); |
67 | *target_mark_call = (void*)do_mark1; |
68 | saved_over = *target_mark_jump_over; |
69 | *target_mark_jump_over = *target_mark_jump_call; |
70 | |
71 | return 0; |
72 | } |
73 | |
74 | int init_module(void) |
75 | { |
76 | return mark_install_hook(); |
77 | } |
78 | |
79 | void cleanup_module(void) |
80 | { |
81 | printk("Removing hook\n"); |
82 | *target_mark_jump_over = saved_over; |
83 | *target_mark_call = __mark_empty_function; |
84 | |
85 | /* Wait for instrumentation functions to return before quitting */ |
86 | synchronize_sched(); |
87 | } |
88 | |
89 | MODULE_LICENSE("GPL"); |
90 | MODULE_AUTHOR("Mathieu Desnoyers"); |
91 | MODULE_DESCRIPTION("Marker Loader"); |
92 | |