split init_syscalls into uni/biarch
[trinity.git] / tables-uniarch.c
blobd659144e4e4fc4bea4d72fe422dab7919c45a53c
1 /*
2 * Functions for handling the system call tables.
3 * These functions are only used by architectures that have either 32 or 64 bit syscalls, but not both.
4 */
6 #include <string.h>
7 #include <stdio.h>
8 #include <unistd.h>
9 #include <stdlib.h>
11 #include "trinity.h" // ARRAY_SIZE, alloc_shared
12 #include "arch.h"
13 #include "syscall.h"
14 #include "params.h"
15 #include "log.h"
16 #include "shm.h"
18 const struct syscalltable *syscalls;
20 unsigned int max_nr_syscalls;
22 void activate_syscall(unsigned int calln)
24 activate_syscall_in_table(calln, &shm->nr_active_syscalls, syscalls, shm->active_syscalls);
27 void deactivate_syscall(unsigned int calln)
29 deactivate_syscall_in_table(calln, &shm->nr_active_syscalls, syscalls, shm->active_syscalls);
32 void toggle_syscall_n(int calln, bool state, const char *arg, const char *arg_name)
34 if (calln == -1) {
35 outputerr("No idea what syscall (%s) is.\n", arg);
36 exit(EXIT_FAILURE);
39 validate_specific_syscall(syscalls, calln);
41 if (state == TRUE) {
42 syscalls[calln].entry->flags |= ACTIVE;
43 activate_syscall(calln);
44 } else {
45 syscalls[calln].entry->flags |= TO_BE_DEACTIVATED;
48 output(0, "Marking syscall %s (%d) as to be %sabled.\n",
49 arg_name, calln,
50 state ? "en" : "dis");
54 void enable_random_syscalls_uniarch(void)
56 unsigned int call;
58 retry:
59 call = rand() % max_nr_syscalls;
61 if (validate_specific_syscall_silent(syscalls, call) == FALSE)
62 goto retry;
64 if (no_files == TRUE)
65 if (is_syscall_net_related(syscalls, call) == FALSE)
66 goto retry;
68 /* if we've set this to be disabled, don't enable it! */
69 if (syscalls[call].entry->flags & TO_BE_DEACTIVATED)
70 goto retry;
72 toggle_syscall_n(call, FALSE, syscalls[call].entry->name, syscalls[call].entry->name);
75 void disable_non_net_syscalls_uniarch(void)
77 unsigned int i;
79 for_each_syscall(i) {
80 if (validate_specific_syscall_silent(syscalls, i) == FALSE)
81 continue;
83 if (syscalls[i].entry->flags & ACTIVE) {
84 if (is_syscall_net_related(syscalls, i) == FALSE) {
85 toggle_syscall_n(i, FALSE, syscalls[i].entry->name, syscalls[i].entry->name);
91 int setup_syscall_group_uniarch(unsigned int group)
93 unsigned int i;
95 for_each_syscall(i) {
96 if (syscalls[i].entry->group == group)
97 activate_syscall(i);
100 if (shm->nr_active_syscalls == 0) {
101 outputstd("No syscalls found in group\n");
102 return FALSE;
103 } else {
104 outputstd("Found %d syscalls in group\n", shm->nr_active_syscalls);
107 return TRUE;
110 void mark_all_syscalls_active_uniarch(void)
112 unsigned int i;
114 for_each_syscall(i) {
115 syscalls[i].entry->flags |= ACTIVE;
116 activate_syscall(i);
120 void init_syscalls_uniarch(void)
122 unsigned int i;
124 for_each_syscall(i) {
125 if (syscalls[i].entry->flags & ACTIVE)
126 if (syscalls[i].entry->init)
127 syscalls[i].entry->init();