summaryrefslogtreecommitdiff
path: root/us_manager/us_manager.c
blob: 737437f8ea5ee30bba2fdd89781ab43a5c918776 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#include <linux/module.h>
#include <sspt/sspt.h>
#include <sspt/sspt_proc.h>
#include <sspt/sspt_page.h>
#include <helper.h>
#include "pf/proc_filters.h"

struct proc_filter *pf;

void (*ptr_pack_task_event_info)(struct task_struct *task,
				 int probe_id,
				 int record_type,
				 const char *fmt, ...) = NULL;

EXPORT_SYMBOL_GPL(ptr_pack_task_event_info);

struct task_struct *check_task(struct task_struct *task)
{
	if (is_kthread(task))
		return NULL;

	return pf->call(pf, task);
}

int usm_register_probe(struct dentry *dentry, unsigned long offset,
		       void *pre_handler, void *jp_handler, void *rp_handler)
{
/*
	char *file_name;
	struct sspt_file *file;
	struct ip_data ip_d;

	file_name = dentry->d_iname;
	file = sspt_proc_find_file_or_new(proc_base, dentry, file_name);

	ip_d.flag_retprobe = 1;
	ip_d.got_addr = 0;
	ip_d.jp_handler = jp_handler;
	ip_d.offset = offset;
	ip_d.pre_handler = pre_handler;
	ip_d.rp_handler = rp_handler;

	sspt_file_add_ip(file, &ip_d);
*/

	return 0;
}
EXPORT_SYMBOL_GPL(usm_register_probe);

int usm_unregister_probe(struct dentry *dentry, unsigned long offset)
{
/*
	struct sspt_file *file;
	struct sspt_page *page;
	struct us_ip *ip;

	file = sspt_proc_find_file(proc_base, dentry);
	if (file == NULL)
		return -EINVAL;

	page = sspt_get_page(file, offset);
	if (page == NULL)
		return -EINVAL;

	ip = sspt_find_ip(page, offset & ~PAGE_MASK);
	if (ip == NULL) {
		sspt_put_page(page);
		return -EINVAL;
	}

	sspt_del_ip(ip);
	sspt_put_page(page);
*/

	return 0;
}
EXPORT_SYMBOL_GPL(usm_unregister_probe);

int usm_stop(void)
{
	int iRet = 0, found = 0;
	struct task_struct *task = NULL;
	struct sspt_proc *proc;
	int tmp_oops_in_progress;

	unregister_helper();

	if (iRet)
		printk("uninstall_kernel_probe(do_munmap) result=%d!\n", iRet);

/*
	tmp_oops_in_progress = oops_in_progress;
	oops_in_progress = 1;
	rcu_read_lock();
	for_each_process(task) {
		if (is_kthread(task))
			continue;

		proc = sspt_proc_get_by_task(task);
		if (proc) {
			int ret = sspt_proc_uninstall(proc, task, US_UNREGS_PROBE);
			if (ret)
				printk("failed to uninstall IPs (%d)!\n", ret);

			dbi_unregister_all_uprobes(task);
		}
	}
	rcu_read_unlock();
	oops_in_progress = tmp_oops_in_progress;

	free_pf(pf);
*/

	sspt_proc_free_all();

	return iRet;
}
EXPORT_SYMBOL_GPL(usm_stop);

int usm_start(void)
{
	int ret, i;
	struct task_struct *task = NULL, *ts;
	struct sspt_proc *proc;
	int tmp_oops_in_progress;

	ret = register_helper();
	if (ret) {
		return ret;
	}

/*
	tmp_oops_in_progress = oops_in_progress;
	oops_in_progress = 1;
	rcu_read_lock();
	for_each_process(task) {
		if (is_kthread(task))
			continue;

		ts = check_task(task);

		if (ts) {
			proc = sspt_proc_get_by_task_or_new(ts);
			sspt_proc_install(proc);
		}
	}
	rcu_read_unlock();
	oops_in_progress = tmp_oops_in_progress;
*/
	return 0;
}
EXPORT_SYMBOL_GPL(usm_start);

static int __init init_us_manager(void)
{
	int ret;

	ret = init_helper();
	if (ret)
		return ret;

	return 0;
}

static void __exit exit_us_manager(void)
{
	uninit_helper();
}

module_init(init_us_manager);
module_exit(exit_us_manager);

MODULE_LICENSE ("GPL");