forked from NJUST-FishTeam/OnlineJudgeCore
-
Notifications
You must be signed in to change notification settings - Fork 2
/
rf_table.h
288 lines (276 loc) · 6.92 KB
/
rf_table.h
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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
#ifndef __RF_TABLE__
#define __RF_TABLE__
#include <string.h>
#include <sys/syscall.h>
#include "core.h"
#include "logger.h"
/*
* RF_table 每个值对应的是该syscall可被调用的次数
* 取值有3种:
* 正值: 表示可被调用的次数, 每次调用后会减一(比如fork)
* 零值: 表示禁止调用(比如open)
* 负值: 表示不限制该syscall(比如write)
*
* RF_table的初始化由init_RF_table函数完成
*/
short RF_table[1024] = {0};
/*
* RF_* 数组对是用于初始化RF_table的数据来源,
* 每两个数字为一组k/v: syscall_id:次数
* 次数 < 0 表示不限制
* 次数 > 0 表示可调用次数, 运行时每调用一次减一
* 次数 = 0 (运行时达到) 不再允许调用该syscall
* 最后一个syscall_id存放的是非正值,表示结束
* 未指定的syscall_id的次数将被自动初始化为0
*/
#if __WORDSIZE == 32 //x86_32
//c or c++
int RF_C[512] =
{
SYS_access, -1,
SYS_brk, -1,
SYS_close, -1,
SYS_execve, 1,
SYS_exit_group, -1,
SYS_fstat64, -1,
SYS_futex, -1,
SYS_gettimeofday, -1,
SYS_mmap2, -1,
SYS_mremap, -1,
SYS_mprotect, -1,
SYS_munmap, -1,
SYS_lseek, -1,
SYS_read, -1,
SYS_set_thread_area,-1,
SYS_uname, -1,
SYS_write, -1,
SYS_writev, -1,
201, -1,
-1
};
int RF_CPP[512] =
{
SYS_access, -1,
SYS_brk, -1,
SYS_close, -1,
SYS_execve, 1,
SYS_exit_group, -1,
SYS_fstat64, -1,
SYS_futex, -1,
SYS_gettimeofday, -1,
SYS_mmap2, -1,
SYS_mremap, -1,
SYS_mprotect, -1,
SYS_munmap, -1,
SYS_lseek, -1,
SYS_read, -1,
SYS_set_thread_area,-1,
SYS_uname, -1,
SYS_write, -1,
SYS_writev, -1,
201, -1,
-1
};
//Pascal
int RF_PASCAL[512] =
{
SYS_close, -1,
SYS_execve, 1,
SYS_exit_group, -1,
SYS_futex, -1,
SYS_gettimeofday, -1,
SYS_ioctl, -1,
SYS_mmap, -1,
SYS_mremap, -1,
SYS_munmap, -1,
SYS_lseek, -1,
SYS_read, -1,
SYS_readlink, -1,
SYS_rt_sigaction, -1,
SYS_ugetrlimit, -1,
SYS_uname, -1,
SYS_write, -1,
SYS_writev, -1,
-1
};
//Java (TODO暂未测试)
int RF_JAVA[512] =
{
SYS_access, -1,
SYS_brk, -1,
SYS_clone, -1,
SYS_close, -1,
SYS_execve, -1,
SYS_exit, -1,
SYS_exit_group, -1,
SYS_fcntl64, -1,
SYS_fstat64, -1,
SYS_futex, -1,
SYS_getdents64, -1,
SYS_getegid32, -1,
SYS_geteuid32, -1,
SYS_getgid32, -1,
SYS_getrlimit, -1,
SYS_gettimeofday, -1,
SYS_getuid32, -1,
SYS_mmap, -1,
SYS_mmap2, -1,
SYS_mremap, -1,
SYS_mprotect, -1,
SYS_munmap, -1,
SYS_lseek, -1,
SYS_open, -1,
SYS_read, -1,
SYS_readlink, -1,
SYS_rt_sigaction, -1,
SYS_rt_sigprocmask, -1,
SYS_set_robust_list,-1,
SYS_set_thread_area,-1,
SYS_set_tid_address,-1,
SYS_sigprocmask, -1,
SYS_stat64, -1,
SYS_ugetrlimit, -1,
SYS_uname, -1,
-1
};
#elif defined __x86_64__
int RF_C[512] =
{
SYS_access, -1,
SYS_arch_prctl, -1,
SYS_brk, -1,
SYS_close, -1,
SYS_execve, 1,
SYS_exit_group, -1,
SYS_fstat, -1,
SYS_futex, -1,
SYS_gettimeofday, -1,
SYS_mmap, -1,
SYS_mremap, -1,
SYS_mprotect, -1,
SYS_munmap, -1,
SYS_lseek, -1,
SYS_read, -1,
SYS_set_thread_area,-1,
SYS_uname, -1,
SYS_write, -1,
SYS_writev, -1,
SYS_time, -1,
SYS_readlink, -1,
-1
};
int RF_CPP[512] =
{
SYS_access, -1,
SYS_arch_prctl, -1,
SYS_brk, -1,
SYS_close, -1,
SYS_execve, 1,
SYS_exit_group, -1,
SYS_fstat, -1,
SYS_futex, -1,
SYS_gettimeofday, -1,
SYS_mmap, -1,
SYS_mremap, -1,
SYS_mprotect, -1,
SYS_munmap, -1,
SYS_lseek, -1,
SYS_read, -1,
SYS_set_thread_area,-1,
SYS_uname, -1,
SYS_write, -1,
SYS_writev, -1,
SYS_time, -1,
SYS_readlink, -1, //原本ubuntu 12.04不需要这一条
-1
};
int RF_PASCAL[512] =
{
SYS_close, -1,
SYS_execve, 1,
SYS_exit_group, -1,
SYS_futex, -1,
SYS_getrlimit, -1,
SYS_gettimeofday, -1,
SYS_ioctl, -1,
SYS_mmap, -1,
SYS_mremap, -1,
SYS_munmap, -1,
SYS_lseek, -1,
SYS_read, -1,
SYS_readlink, -1,
SYS_rt_sigaction, -1,
SYS_uname, -1,
SYS_write, -1,
SYS_writev, -1,
SYS_time, -1,
SYS_readlink, -1,
-1
};
int RF_JAVA[512] =
{
SYS_access, -1,
SYS_arch_prctl, -1,
SYS_brk, -1,
SYS_clone, -1,
SYS_close, -1,
SYS_execve, -1,
SYS_exit_group, -1,
SYS_fstat, -1,
SYS_futex, -1,
SYS_getegid, -1,
SYS_geteuid, -1,
SYS_getgid, -1,
SYS_getrlimit, -1,
SYS_gettimeofday, -1,
SYS_getuid, -1,
SYS_mmap, -1,
SYS_mremap, -1,
SYS_mprotect, -1,
SYS_munmap, -1,
SYS_lseek, -1,
SYS_open, -1,
SYS_read, -1,
SYS_readlink, -1,
SYS_rt_sigaction, -1,
SYS_rt_sigprocmask, -1,
SYS_set_robust_list,-1,
SYS_set_tid_address,-1,
SYS_stat, -1,
SYS_uname, -1,
SYS_write, -1,
SYS_writev, -1,
SYS_time, -1,
SYS_readlink, -1,
-1
};
#endif
//根据 RF_* 数组来初始化RF_table
void init_RF_table(int lang)
{
int *p = NULL;
switch (lang)
{
case JUDGE_CONF::LANG_C:
p = RF_C;
break;
case JUDGE_CONF::LANG_CPP:
p = RF_CPP;
break;
case JUDGE_CONF::LANG_JAVA:
p = RF_JAVA;
break;
//case judge_conf::LANG_PASCAL:
// p = RF_PASCAL;
// break;
default:
FM_LOG_WARNING("Unknown language: %d", lang);
break;
}
memset(RF_table, 0, sizeof(RF_table));
for (int i = 0; p[i] >= 0; i += 2)
{
RF_table[p[i]] = p[i+1];
}
}
#endif