526149e6c3b5949ae185d9205399cb68f56b8af2
[kernel/swap-modules.git] / us_manager / us_manager.c
1 #include <linux/module.h>
2 #include <sspt/sspt.h>
3 #include <sspt/sspt_proc.h>
4 #include <sspt/sspt_page.h>
5 #include <helper.h>
6 #include "pf/proc_filters.h"
7
8 struct proc_filter *pf;
9
10 void (*ptr_pack_task_event_info)(struct task_struct *task,
11                                  int probe_id,
12                                  int record_type,
13                                  const char *fmt, ...) = NULL;
14
15 EXPORT_SYMBOL_GPL(ptr_pack_task_event_info);
16
17 struct task_struct *check_task(struct task_struct *task)
18 {
19         if (is_kthread(task))
20                 return NULL;
21
22         return pf->call(pf, task);
23 }
24
25 int usm_register_probe(struct dentry *dentry, unsigned long offset,
26                        void *pre_handler, void *jp_handler, void *rp_handler)
27 {
28 /*
29         char *file_name;
30         struct sspt_file *file;
31         struct ip_data ip_d;
32
33         file_name = dentry->d_iname;
34         file = sspt_proc_find_file_or_new(proc_base, dentry, file_name);
35
36         ip_d.flag_retprobe = 1;
37         ip_d.got_addr = 0;
38         ip_d.jp_handler = jp_handler;
39         ip_d.offset = offset;
40         ip_d.pre_handler = pre_handler;
41         ip_d.rp_handler = rp_handler;
42
43         sspt_file_add_ip(file, &ip_d);
44 */
45
46         return 0;
47 }
48 EXPORT_SYMBOL_GPL(usm_register_probe);
49
50 int usm_unregister_probe(struct dentry *dentry, unsigned long offset)
51 {
52 /*
53         struct sspt_file *file;
54         struct sspt_page *page;
55         struct us_ip *ip;
56
57         file = sspt_proc_find_file(proc_base, dentry);
58         if (file == NULL)
59                 return -EINVAL;
60
61         page = sspt_get_page(file, offset);
62         if (page == NULL)
63                 return -EINVAL;
64
65         ip = sspt_find_ip(page, offset & ~PAGE_MASK);
66         if (ip == NULL) {
67                 sspt_put_page(page);
68                 return -EINVAL;
69         }
70
71         sspt_del_ip(ip);
72         sspt_put_page(page);
73 */
74
75         return 0;
76 }
77 EXPORT_SYMBOL_GPL(usm_unregister_probe);
78
79 int usm_stop(void)
80 {
81         int iRet = 0, found = 0;
82         struct task_struct *task = NULL;
83         struct sspt_proc *proc;
84         int tmp_oops_in_progress;
85
86         unregister_helper();
87
88         if (iRet)
89                 printk("uninstall_kernel_probe(do_munmap) result=%d!\n", iRet);
90
91         uninstall_all();
92
93 /*
94         tmp_oops_in_progress = oops_in_progress;
95         oops_in_progress = 1;
96         rcu_read_lock();
97         for_each_process(task) {
98                 if (is_kthread(task))
99                         continue;
100
101                 proc = sspt_proc_get_by_task(task);
102                 if (proc) {
103                         int ret = sspt_proc_uninstall(proc, task, US_UNREGS_PROBE);
104                         if (ret)
105                                 printk("failed to uninstall IPs (%d)!\n", ret);
106
107                         dbi_unregister_all_uprobes(task);
108                 }
109         }
110         rcu_read_unlock();
111         oops_in_progress = tmp_oops_in_progress;
112
113         free_pf(pf);
114 */
115
116         sspt_proc_free_all();
117
118         return iRet;
119 }
120 EXPORT_SYMBOL_GPL(usm_stop);
121
122 int usm_start(void)
123 {
124         int ret, i;
125         struct task_struct *task = NULL, *ts;
126         struct sspt_proc *proc;
127         int tmp_oops_in_progress;
128
129         ret = register_helper();
130         if (ret) {
131                 return ret;
132         }
133
134         install_all();
135
136 /*
137         tmp_oops_in_progress = oops_in_progress;
138         oops_in_progress = 1;
139         rcu_read_lock();
140         for_each_process(task) {
141                 if (is_kthread(task))
142                         continue;
143
144                 ts = check_task(task);
145
146                 if (ts) {
147                         proc = sspt_proc_get_by_task_or_new(ts);
148                         sspt_proc_install(proc);
149                 }
150         }
151         rcu_read_unlock();
152         oops_in_progress = tmp_oops_in_progress;
153 */
154         return 0;
155 }
156 EXPORT_SYMBOL_GPL(usm_start);
157
158 static int __init init_us_manager(void)
159 {
160         int ret;
161
162         ret = init_helper();
163         if (ret)
164                 return ret;
165
166         return 0;
167 }
168
169 static void __exit exit_us_manager(void)
170 {
171         uninit_helper();
172 }
173
174 module_init(init_us_manager);
175 module_exit(exit_us_manager);
176
177 MODULE_LICENSE ("GPL");
178