-
Notifications
You must be signed in to change notification settings - Fork 0
/
record.c
238 lines (210 loc) · 4.84 KB
/
record.c
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
#include "record.h"
//恶意pid list头部
Malicious malicious_header = NULL;
/* 2021-5-11 */
Suspect suspect_header = NULL;
/* 背包问题中用于存储中间值的数组 */
int **V;
struct mutex global_mutex_lock;
struct mutex process_mutex_lock;
struct mutex detect_prepare_lock;
BWC global_blk_write_count = NULL;
void init_malicious_list_lock()
{
mutex_init(&global_mutex_lock);
mutex_init(&process_mutex_lock);
mutex_init(&detect_prepare_lock);
}
/* 记录恶意pid相关 */
void insert_into_malicious_process(int pid)
{
Malicious p_node,p_curr;
p_node = (Malicious)kmalloc(sizeof(MaliciousProcess),GFP_KERNEL);
p_node->pid = pid;
p_node->next = NULL;
if(malicious_header == NULL)
{
malicious_header = p_node;
return;
}
p_curr = malicious_header;
while(p_curr->next != NULL)
{
p_curr = p_curr->next;
}
p_curr->next = p_node;
}
void delete_from_malicious_process(int pid)
{
Malicious p_prev,p_curr;
if(malicious_header == NULL)
{
return;
}
p_curr = malicious_header;
p_prev = malicious_header;
if(malicious_header->pid == pid)
{
malicious_header = malicious_header->next;
kfree(p_curr);
return;
}
while(p_curr != NULL)
{
if(p_curr->pid == pid)
{
p_prev->next = p_curr->next;
kfree(p_curr);
return;
}
p_prev = p_curr;
p_curr = p_curr->next;
}
}
void print_malicious_process_info(void)
{
Malicious p_curr = malicious_header;
if(p_curr == NULL)
printk("There is no malicious process \n");
while(p_curr != NULL)
{
printk("malicious pid is %d\n",p_curr->pid);
p_curr = p_curr->next;
}
}
char is_in_malicious_process_list(int pid)
{
Malicious p_curr = malicious_header;
while(p_curr != NULL)
{
if(p_curr->pid == pid)
return 1;
p_curr = p_curr->next;
}
return 0;
}
void free_all_malicious_process_list(void)
{
Malicious p_curr,p_next;
p_curr = malicious_header;
while(p_curr != NULL)
{
p_next = p_curr->next;
kfree(p_curr);
p_curr = p_next;
}
malicious_header = NULL;
}
/* suspect 2021-5-11 */
/* 添加可疑进程的代码 */
insert_into_suspect_process(int pid, unsigned long ac, unsigned long dev, unsigned long pc)
{
Suspect p_node,p_curr;
p_node = (Suspect)kmalloc(sizeof(SuspectProcess),GFP_KERNEL);
p_node->pid = pid;
p_node->averageCount = ac;
p_node->deviation = dev;
p_node->pageCount = pc;
p_node->next = NULL;
p_node->prev = NULL;
if(suspect_header == NULL)
{
suspect_header = p_node;
return;
}
p_curr = suspect_header;
while(p_curr->next != NULL)
{
p_curr = p_curr->next;
}
p_curr->next = p_node;
p_node->prev = p_curr;
}
void delete_from_suspect_process(int pid)
{
Suspect p_prev,p_curr;
if(suspect_header == NULL)
{
return;
}
p_curr = suspect_header;
p_prev = suspect_header;
if(suspect_header->pid == pid)
{
suspect_header = suspect_header->next;
kfree(p_curr);
return;
}
while(p_curr != NULL)
{
if(p_curr->pid == pid)
{
p_prev->next = p_curr->next;
kfree(p_curr);
return;
}
p_prev = p_curr;
p_curr = p_curr->next;
}
}
void print_suspect_process_info(void)
{
Suspect p_curr = suspect_header;
if(p_curr == NULL)
printk("There is no Suspect process \n");
while(p_curr != NULL)
{
printk("Suspect: pid is %d, average is %llu, deviation is %llu, pageCount is %llu\n",
p_curr->pid, p_curr->averageCount, p_curr->deviation, p_curr->pageCount);
p_curr = p_curr->next;
}
}
char is_in_suspect_process_list(int pid)
{
Suspect p_curr = suspect_header;
while(p_curr != NULL)
{
if(p_curr->pid == pid)
return 1;
p_curr = p_curr->next;
}
return 0;
}
void free_all_suspect_process_list(void)
{
Suspect p_curr,p_next;
p_curr = suspect_header;
while(p_curr != NULL)
{
p_next = p_curr->next;
kfree(p_curr);
p_curr = p_next;
}
suspect_header = NULL;
}
/* 保存动态规划0-1背包的中间解 */
void zeroV(void)
{
int i,j;
for(i = 0; i < sizeV; i++)
for(j = 0; j < sizeV; j++)
V[i][j] = 0;
}
void initV(void)
{
int i;
V = (int **)vmalloc(sizeof(int *) * sizeV);
for(i = 0; i < sizeV; i++)
V[i] = (int *)vmalloc(sizeof(int) * sizeV);
zeroV();
}
void printV(void)
{
int i, j;
for(i = 0; i < sizeV; i++)
{
for(j = 0; j < sizeV; j++)
printk("%d ", V[i][j]);
printk("\n");
}
}