2 * Functions for handling the system call tables.
3 * These functions are only used on architectures that have both 32 and 64 bit syscalls.
11 #include "trinity.h" // ARRAY_SIZE, alloc_shared
19 #define NOTFOUND (unsigned int)-1
21 const struct syscalltable
*syscalls_32bit
;
22 const struct syscalltable
*syscalls_64bit
;
24 unsigned int max_nr_32bit_syscalls
;
25 unsigned int max_nr_64bit_syscalls
;
27 bool use_32bit
= FALSE
;
28 bool use_64bit
= FALSE
;
30 void activate_syscall32(unsigned int calln
)
32 activate_syscall_in_table(calln
, &shm
->nr_active_32bit_syscalls
, syscalls_32bit
, shm
->active_syscalls32
);
35 void activate_syscall64(unsigned int calln
)
37 activate_syscall_in_table(calln
, &shm
->nr_active_64bit_syscalls
, syscalls_64bit
, shm
->active_syscalls64
);
40 void deactivate_syscall32(unsigned int calln
)
42 deactivate_syscall_in_table(calln
, &shm
->nr_active_32bit_syscalls
, syscalls_32bit
, shm
->active_syscalls32
);
45 void deactivate_syscall64(unsigned int calln
)
47 deactivate_syscall_in_table(calln
, &shm
->nr_active_64bit_syscalls
, syscalls_64bit
, shm
->active_syscalls64
);
51 int validate_syscall_table_64(void)
53 if (shm
->nr_active_64bit_syscalls
== 0)
61 int validate_syscall_table_32(void)
63 if (shm
->nr_active_32bit_syscalls
== 0)
71 void toggle_syscall_biarch_n(int calln
, const struct syscalltable
*table
, bool onlyflag
, bool doflag
, bool state
, void (*activate
)(unsigned int), int arch_bits
, const char *arg_name
)
74 struct syscallentry
*entry
= table
[calln
].entry
;
76 validate_specific_syscall(table
, calln
);
78 if ((state
== TRUE
) && onlyflag
&& doflag
) {
79 entry
->flags
|= ACTIVE
;
82 entry
->flags
|= TO_BE_DEACTIVATED
;
86 if ((arch_bits
!= 0) && (calln
!= -1))
87 output(0, "Marking %d-bit syscall %s (%d) as to be %sabled.\n",
88 arch_bits
, arg_name
, calln
,
89 state
? "en" : "dis");
92 void toggle_syscall_biarch(const char *arg
, bool state
)
94 int specific_syscall32
= 0;
95 int specific_syscall64
= 0;
96 char *arg_name
= NULL
;
97 bool only_32bit
= TRUE
;
98 bool only_64bit
= TRUE
;
100 check_user_specified_arch(arg
, &arg_name
, &only_64bit
, &only_32bit
);
102 /* If we found a 64bit syscall, validate it. */
103 specific_syscall64
= search_syscall_table(syscalls_64bit
, max_nr_64bit_syscalls
, arg_name
);
104 toggle_syscall_biarch_n(specific_syscall64
, syscalls_64bit
, only_64bit
, do_64_arch
, state
, &activate_syscall64
, 0, arg_name
);
106 /* Search for and validate 32bit */
107 specific_syscall32
= search_syscall_table(syscalls_32bit
, max_nr_32bit_syscalls
, arg_name
);
108 toggle_syscall_biarch_n(specific_syscall32
, syscalls_32bit
, only_32bit
, do_32_arch
, state
, &activate_syscall32
, 0, arg_name
);
111 if ((!only_32bit
) && (!only_64bit
)) {
112 outputerr("No idea what architecture for syscall (%s) is.\n", arg
);
116 if ((specific_syscall64
== -1) && (specific_syscall32
== -1)) {
117 outputerr("No idea what syscall (%s) is.\n", arg
);
121 if ((specific_syscall64
!= -1) && (specific_syscall32
!= -1)) {
122 output(0, "Marking syscall %s (64bit:%d 32bit:%d) as to be %sabled.\n",
123 arg_name
, specific_syscall64
, specific_syscall32
,
124 state
? "en" : "dis");
128 if (specific_syscall64
!= -1) {
129 output(0, "Marking 64-bit syscall %s (%d) as to be %sabled.\n",
130 arg
, specific_syscall64
,
131 state
? "en" : "dis");
135 if (specific_syscall32
!= -1) {
136 output(0, "Marking 32-bit syscall %s (%d) as to be %sabled.\n",
137 arg
, specific_syscall32
,
138 state
? "en" : "dis");
141 clear_check_user_specified_arch(arg
, &arg_name
);
146 void enable_random_syscalls_biarch(void)
148 unsigned int call32
= NOTFOUND
, call64
= NOTFOUND
;
152 //Search for 64 bit version
154 struct syscallentry
*entry
= syscalls_64bit
[call64
].entry
;
156 call64
= rand() % max_nr_64bit_syscalls
;
157 if (validate_specific_syscall_silent(syscalls_64bit
, call64
) == FALSE
)
160 if (no_files
== TRUE
)
161 if (is_syscall_net_related(syscalls_64bit
, call64
) == FALSE
)
164 if (entry
->flags
& TO_BE_DEACTIVATED
)
167 if (entry
->active_number
!= 0)
170 // If we got so far, then activate it.
171 toggle_syscall_biarch_n(call64
, syscalls_64bit
, TRUE
, do_64_arch
, TRUE
,
172 &activate_syscall64
, 64, entry
->name
);
176 //Search for 32 bit version
178 struct syscallentry
*entry
= syscalls_32bit
[call32
].entry
;
180 // FIXME: WTF is going on here?
182 call32
= search_syscall_table(syscalls_32bit
, max_nr_32bit_syscalls
, syscalls_64bit
[call64
].entry
->name
);
184 if (syscalls_64bit
[call64
].entry
->flags
& TO_BE_DEACTIVATED
)
185 call64
= NOTFOUND
; //mark as not found in order not to increment i.
187 call32
= rand() % max_nr_32bit_syscalls
;
190 if (validate_specific_syscall_silent(syscalls_32bit
, call32
) == FALSE
) {
191 if (call64
== NOTFOUND
)
197 if (no_files
== TRUE
) {
198 if (is_syscall_net_related(syscalls_32bit
, call32
) == FALSE
) {
199 if (call64
== NOTFOUND
)
206 if ((entry
->flags
& TO_BE_DEACTIVATED
) || (entry
->active_number
!= 0)) {
207 if (call64
== NOTFOUND
)
213 //If we got so far, then active it.
214 toggle_syscall_biarch_n(call32
, syscalls_32bit
, TRUE
, do_32_arch
, TRUE
,
215 &activate_syscall32
, 32, entry
->name
);
219 void disable_non_net_syscalls_biarch(void)
221 struct syscallentry
*entry
;
224 for_each_64bit_syscall(i
) {
225 entry
= syscalls_64bit
[i
].entry
;
227 if (validate_specific_syscall_silent(syscalls_64bit
, i
) == FALSE
)
230 if (entry
->flags
& ACTIVE
) {
231 if (is_syscall_net_related(syscalls_64bit
, i
) == FALSE
) {
232 toggle_syscall_biarch_n(i
, syscalls_64bit
, FALSE
, do_64_arch
, FALSE
,
233 &activate_syscall64
, 64, entry
->name
);
238 for_each_32bit_syscall(i
) {
239 entry
= syscalls_32bit
[i
].entry
;
241 if (validate_specific_syscall_silent(syscalls_32bit
, i
) == FALSE
)
244 if (entry
->flags
& ACTIVE
) {
245 if (is_syscall_net_related(syscalls_32bit
, i
) == FALSE
) {
246 toggle_syscall_biarch_n(i
, syscalls_32bit
, FALSE
, do_32_arch
, FALSE
,
247 &activate_syscall32
, 32, entry
->name
);
253 int setup_syscall_group_biarch(unsigned int group
)
257 for_each_32bit_syscall(i
) {
258 if (syscalls_32bit
[i
].entry
->group
== group
)
259 activate_syscall32(i
);
262 if (shm
->nr_active_32bit_syscalls
== 0)
263 outputstd("No 32-bit syscalls in group\n");
265 outputstd("Found %d 32-bit syscalls in group\n", shm
->nr_active_32bit_syscalls
);
267 /* now the 64 bit table*/
268 for_each_64bit_syscall(i
) {
269 if (syscalls_64bit
[i
].entry
->group
== group
)
270 activate_syscall64(i
);
273 if (shm
->nr_active_64bit_syscalls
== 0) {
274 outputstd("No 64-bit syscalls in group\n");
277 outputstd("Found %d 64-bit syscalls in group\n", shm
->nr_active_64bit_syscalls
);
283 void mark_all_syscalls_active_biarch(void)
288 for_each_32bit_syscall(i
) {
289 syscalls_32bit
[i
].entry
->flags
|= ACTIVE
;
290 activate_syscall32(i
);
295 for_each_64bit_syscall(i
) {
296 syscalls_64bit
[i
].entry
->flags
|= ACTIVE
;
297 activate_syscall64(i
);
302 void init_syscalls_biarch(void)
304 struct syscallentry
*entry
;
307 for_each_64bit_syscall(i
) {
308 entry
= syscalls_64bit
[i
].entry
;
309 if (entry
->flags
& ACTIVE
)
314 for_each_32bit_syscall(i
) {
315 entry
= syscalls_32bit
[i
].entry
;
316 if (entry
->flags
& ACTIVE
)
322 void deactivate_disabled_syscalls_biarch(void)
324 struct syscallentry
*entry
;
327 for_each_64bit_syscall(i
) {
328 entry
= syscalls_64bit
[i
].entry
;
329 if (entry
->flags
& TO_BE_DEACTIVATED
) {
330 entry
->flags
&= ~(ACTIVE
|TO_BE_DEACTIVATED
);
331 deactivate_syscall64(i
);
332 output(0, "Marked 64-bit syscall %s (%d) as deactivated.\n",
333 entry
->name
, entry
->number
);
337 for_each_32bit_syscall(i
) {
338 entry
= syscalls_32bit
[i
].entry
;
339 if (entry
->flags
& TO_BE_DEACTIVATED
) {
340 entry
->flags
&= ~(ACTIVE
|TO_BE_DEACTIVATED
);
341 deactivate_syscall32(i
);
342 output(0, "Marked 32-bit syscall %s (%d) as deactivated.\n",
343 entry
->name
, entry
->number
);
348 void dump_syscall_tables_biarch(void)
350 struct syscallentry
*entry
;
353 outputstd("syscalls: %d [32-bit]\n", max_nr_32bit_syscalls
);
354 outputstd("syscalls: %d [64-bit]\n", max_nr_64bit_syscalls
);
356 for_each_32bit_syscall(i
) {
357 entry
= syscalls_32bit
[i
].entry
;
358 outputstd("entrypoint %d %s : [32-bit] ",
359 entry
->number
, entry
->name
);
360 show_state(entry
->flags
& ACTIVE
);
362 if (entry
->flags
& AVOID_SYSCALL
)
368 for_each_64bit_syscall(i
) {
369 entry
= syscalls_64bit
[i
].entry
;
371 outputstd("entrypoint %d %s : [64-bit] ",
372 entry
->number
, entry
->name
);
373 show_state(entry
->flags
& ACTIVE
);
375 if (entry
->flags
& AVOID_SYSCALL
)
382 void display_enabled_syscalls_biarch(void)
384 struct syscallentry
*entry
;
387 for_each_64bit_syscall(i
) {
388 entry
= syscalls_64bit
[i
].entry
;
389 if (entry
->flags
& ACTIVE
)
390 output(0, "64-bit syscall %d:%s enabled.\n", i
, entry
->name
);
393 for_each_32bit_syscall(i
) {
394 entry
= syscalls_32bit
[i
].entry
;
395 if (entry
->flags
& ACTIVE
)
396 output(0, "32-bit syscall %d:%s enabled.\n", i
, entry
->name
);