[IMPROVE] x86: apply jumper for US probes installing
[kernel/swap-modules.git] / ks_features / features_data.c
1 /**
2  * ks_features/features_data.c
3  * @author Vyacheslav Cherkashin: SWAP ks_features implement
4  *
5  * @section LICENSE
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20  *
21  * @section COPYRIGHT
22  *
23  * Copyright (C) Samsung Electronics, 2013
24  *
25  * @section DESCRIPTION
26  *
27  * SWAP kernel features
28  */
29
30
31 #include "syscall_list.h"
32 #include <linux/mutex.h>
33
34 /**
35  * @struct feature
36  * Feature description.
37  * @var feature::cnt
38  * Syscalls count.
39  * @var feature::feature_list
40  * Pointer to feature's syscall list.
41  * @var feature::sub_type
42  * Featue subtype.
43  * @var feature::enable
44  * Is feature enable.
45  */
46 struct feature {
47         size_t cnt;
48         enum syscall_id *feature_list;
49         int sub_type;
50
51         unsigned enable:1;
52 };
53
54 /**
55  * @def X
56  * X-macros for syscall list.
57  */
58 #define X(name, args) id_##name
59 /**
60  * @enum syscall_id
61  * Syscall list
62  */
63 enum syscall_id {
64         SYSCALL_LIST
65 };
66 #undef X
67
68 static enum syscall_id id_none[] = {};
69
70 static enum syscall_id id_file[] = {
71         id_sys_acct,
72         id_sys_mount,
73         id_sys_umount,
74         id_sys_truncate,
75 /* TODO:
76  *      id_sys_stat,
77  */
78         id_sys_statfs,
79         id_sys_statfs64,
80 /* TODO:
81  *      id_sys_lstat,
82  */
83         id_sys_stat64,
84         id_sys_fstat64,
85         id_sys_lstat64,
86         id_sys_truncate64,
87         id_sys_ftruncate64,
88         id_sys_setxattr,
89         id_sys_getxattr,
90         id_sys_listxattr,
91         id_sys_removexattr,
92         id_sys_chroot,
93         id_sys_mknod,
94         id_sys_link,
95         id_sys_symlink,
96         id_sys_unlink,
97         id_sys_rename,
98         id_sys_chmod,
99         id_sys_readlink,
100         id_sys_creat,
101         id_sys_open,
102         id_sys_access,
103         id_sys_chown,
104         id_sys_chown16,
105         id_sys_utime,
106         id_sys_utimes,
107         id_sys_pread64,
108         id_sys_pwrite64,
109         id_sys_preadv,
110         id_sys_pwritev,
111         id_sys_getcwd,
112         id_sys_mkdir,
113         id_sys_chdir,
114         id_sys_rmdir,
115         id_sys_swapon,
116         id_sys_swapoff,
117         id_sys_uselib,
118         id_sys_mknodat,
119         id_sys_mkdirat,
120         id_sys_unlinkat,
121         id_sys_symlinkat,
122         id_sys_linkat,
123         id_sys_renameat,
124         id_sys_futimesat,
125         id_sys_faccessat,
126         id_sys_fchmodat,
127         id_sys_fchownat,
128         id_sys_openat,
129 /* TODO:
130  *      id_sys_newfstatat,
131  */
132         id_sys_readlinkat,
133         id_sys_utimensat,
134         id_sys_fanotify_mark,
135         id_sys_execve,
136         id_sys_name_to_handle_at,
137         id_sys_open_by_handle_at
138 };
139
140 static enum syscall_id id_ipc[] = {
141         id_sys_msgget,
142         id_sys_msgsnd,
143         id_sys_msgrcv,
144         id_sys_msgctl,
145         id_sys_semget,
146         id_sys_semop,
147         id_sys_semctl,
148         id_sys_semtimedop,
149         id_sys_shmat,
150         id_sys_shmget,
151         id_sys_shmdt,
152         id_sys_shmctl,
153         id_sys_ipc
154 };
155
156 static enum syscall_id id_net[] = {
157         id_sys_shutdown,
158         id_sys_sendfile,
159         id_sys_sendfile64,
160         id_sys_setsockopt,
161         id_sys_getsockopt,
162         id_sys_bind,
163         id_sys_connect,
164         id_sys_accept,
165         id_sys_accept4,
166         id_sys_getsockname,
167         id_sys_getpeername,
168         id_sys_send,
169         id_sys_sendto,
170         id_sys_sendmsg,
171         id_sys_sendmmsg,
172         id_sys_recv,
173         id_sys_recvfrom,
174         id_sys_recvmsg,
175         id_sys_recvmmsg,
176         id_sys_socket,
177         id_sys_socketpair,
178         id_sys_socketcall,
179         id_sys_listen
180 };
181
182 static enum syscall_id id_process[] = {
183         id_sys_exit,
184         id_sys_exit_group,
185         id_sys_wait4,
186         id_sys_waitid,
187 /* TODO:
188  *      id_sys_waitpid,
189  */
190         id_sys_rt_tgsigqueueinfo,
191         id_sys_unshare,
192         id_sys_fork,
193         id_sys_vfork,
194 /* TODO: add support CONFIG_CLONE_BACKWARDS
195  *      id_sys_clone,
196  *      id_sys_clone,
197  */
198     id_sys_execve
199 };
200
201 static enum syscall_id id_signal[] = {
202         id_sys_sigpending,
203         id_sys_sigprocmask,
204 /* TODO:
205  *      id_sys_sigaltstack,
206  */
207 /* TODO: add support CONFIG_OLD_SIGSUSPEND and CONFIG_OLD_SIGSUSPEND3
208  *      id_sys_sigsuspend,
209  *      id_sys_sigsuspend,
210  */
211         id_sys_rt_sigsuspend,
212         id_sys_sigaction,
213         id_sys_rt_sigaction,
214         id_sys_rt_sigprocmask,
215         id_sys_rt_sigtimedwait,
216         id_sys_rt_tgsigqueueinfo,
217         id_sys_kill,
218         id_sys_tgkill,
219 /* TODO:
220  *      id_sys_signal,
221  */
222         id_sys_pause,
223         id_sys_signalfd,
224         id_sys_signalfd4
225 };
226
227 static enum syscall_id id_desc[] = {
228         id_sys_fgetxattr,
229         id_sys_flistxattr,
230         id_sys_fremovexattr,
231         id_sys_fadvise64_64,
232         id_sys_pipe2,
233         id_sys_dup3,
234         id_sys_sendfile,
235         id_sys_sendfile64,
236         id_sys_preadv,
237         id_sys_pwritev,
238         id_sys_epoll_create1,
239         id_sys_epoll_ctl,
240         id_sys_epoll_wait,
241         id_sys_epoll_pwait,
242         id_sys_inotify_init,
243         id_sys_inotify_init1,
244         id_sys_inotify_add_watch,
245         id_sys_inotify_rm_watch,
246         id_sys_mknodat,
247         id_sys_mkdirat,
248         id_sys_unlinkat,
249         id_sys_symlinkat,
250         id_sys_linkat,
251         id_sys_renameat,
252         id_sys_futimesat,
253         id_sys_faccessat,
254         id_sys_fchmodat,
255         id_sys_fchownat,
256         id_sys_openat,
257 /* TODO:
258  *      id_sys_newfstatat,
259  */
260         id_sys_readlinkat,
261         id_sys_utimensat,
262         id_sys_splice,
263         id_sys_vmsplice,
264         id_sys_tee,
265         id_sys_signalfd,
266         id_sys_signalfd4,
267         id_sys_timerfd_create,
268         id_sys_timerfd_settime,
269         id_sys_timerfd_gettime,
270         id_sys_eventfd,
271         id_sys_eventfd2,
272         id_sys_fallocate,
273         id_sys_pselect6,
274         id_sys_ppoll,
275         id_sys_fanotify_init,
276         id_sys_fanotify_mark,
277         id_sys_syncfs,
278         id_sys_mmap_pgoff,
279         id_sys_old_mmap,
280         id_sys_name_to_handle_at,
281         id_sys_setns
282 };
283
284 /**
285  * @def CREATE_FEATURE
286  * Feature initialization.
287  */
288 #define CREATE_FEATURE(x, subtype)                              \
289 {                                                               \
290         .cnt = sizeof(x) / sizeof(enum syscall_id),             \
291         .feature_list = x,                                      \
292         .sub_type = subtype,                                    \
293         .enable = 0                                             \
294 }
295
296 static struct feature features[] = {
297         CREATE_FEATURE(id_none, PST_NONE),
298         CREATE_FEATURE(id_file, PST_KS_FILE),
299         CREATE_FEATURE(id_ipc, PST_KS_IPC),
300         CREATE_FEATURE(id_process, PST_KS_PROCESS),
301         CREATE_FEATURE(id_signal, PST_KS_SIGNAL),
302         CREATE_FEATURE(id_net, PST_KS_NETWORK),
303         CREATE_FEATURE(id_desc, PST_KS_DESC)
304 };
305
306 /**
307  * @enum
308  * Defines feature_cnt.
309  */
310 enum {
311         feature_cnt = sizeof(features) / sizeof(struct feature)
312 };
313
314 static int feature_index(struct feature *f)
315 {
316         return f - features;
317 }