add missing fallocate flags
[trinity.git] / tables-uniarch.c
blob576f4cae89ffbaf1fff4e08878da58d3e9905941
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"
17 #include "tables.h"
19 const struct syscalltable *syscalls;
21 unsigned int max_nr_syscalls;
23 void activate_syscall(unsigned int calln)
25 activate_syscall_in_table(calln, &shm->nr_active_syscalls, syscalls, shm->active_syscalls);
28 void deactivate_syscall(unsigned int calln)
30 deactivate_syscall_in_table(calln, &shm->nr_active_syscalls, syscalls, shm->active_syscalls);
33 void toggle_syscall_n(int calln, bool state, const char *arg, const char *arg_name)
35 struct syscallentry *entry = syscalls[calln].entry;
37 if (calln == -1) {
38 outputerr("No idea what syscall (%s) is.\n", arg);
39 exit(EXIT_FAILURE);
42 validate_specific_syscall(syscalls, calln);
44 if (state == TRUE) {
45 entry->flags |= ACTIVE;
46 activate_syscall(calln);
47 } else {
48 entry->flags |= TO_BE_DEACTIVATED;
51 output(0, "Marking syscall %s (%d) as to be %sabled.\n",
52 arg_name, calln,
53 state ? "en" : "dis");
57 void enable_random_syscalls_uniarch(void)
59 unsigned int call;
60 struct syscallentry *entry;
62 retry:
63 call = rand() % max_nr_syscalls;
64 entry = syscalls[call].entry;
66 if (validate_specific_syscall_silent(syscalls, call) == FALSE)
67 goto retry;
69 if (no_files == TRUE)
70 if (is_syscall_net_related(syscalls, call) == FALSE)
71 goto retry;
73 /* if we've set this to be disabled, don't enable it! */
74 if (entry->flags & TO_BE_DEACTIVATED)
75 goto retry;
77 toggle_syscall_n(call, TRUE, entry->name, entry->name);
80 void disable_non_net_syscalls_uniarch(void)
82 unsigned int i;
84 for_each_syscall(i) {
85 struct syscallentry *entry;
87 entry = syscalls[i].entry;
89 if (validate_specific_syscall_silent(syscalls, i) == FALSE)
90 continue;
92 if (entry->flags & ACTIVE) {
93 if (is_syscall_net_related(syscalls, i) == FALSE)
94 toggle_syscall_n(i, FALSE, entry->name, entry->name);
99 int setup_syscall_group_uniarch(unsigned int group)
101 unsigned int i;
103 for_each_syscall(i) {
104 if (syscalls[i].entry->group == group)
105 activate_syscall(i);
108 if (shm->nr_active_syscalls == 0) {
109 outputstd("No syscalls found in group\n");
110 return FALSE;
111 } else {
112 outputstd("Found %d syscalls in group\n", shm->nr_active_syscalls);
115 return TRUE;
118 void mark_all_syscalls_active_uniarch(void)
120 unsigned int i;
122 for_each_syscall(i) {
123 syscalls[i].entry->flags |= ACTIVE;
124 activate_syscall(i);
128 void init_syscalls_uniarch(void)
130 unsigned int i;
132 for_each_syscall(i) {
133 struct syscallentry *entry;
135 entry = syscalls[i].entry;
136 if (entry->flags & ACTIVE)
137 if (entry->init)
138 entry->init();
142 void deactivate_disabled_syscalls_uniarch(void)
144 struct syscallentry *entry;
145 unsigned int i;
147 for_each_syscall(i) {
148 entry = syscalls[i].entry;
149 if (entry->flags & TO_BE_DEACTIVATED) {
150 entry->flags &= ~(ACTIVE|TO_BE_DEACTIVATED);
151 deactivate_syscall(i);
152 output(0, "Marked syscall %s (%d) as deactivated.\n",
153 entry->name, entry->number);
158 void dump_syscall_tables_uniarch(void)
160 unsigned int i;
162 outputstd("syscalls: %d\n", max_nr_syscalls);
164 for_each_syscall(i) {
165 struct syscallentry *entry;
167 entry = syscalls[i].entry;
168 outputstd("entrypoint %d %s : ", entry->number, entry->name);
169 show_state(entry->flags & ACTIVE);
170 if (entry->flags & AVOID_SYSCALL)
171 outputstd(" AVOID");
172 outputstd("\n");
176 void display_enabled_syscalls_uniarch(void)
178 unsigned int i;
180 for_each_syscall(i) {
181 struct syscallentry *entry;
183 entry = syscalls[i].entry;
185 if (entry->flags & ACTIVE)
186 output(0, "syscall %d:%s enabled.\n", i, entry->name);