update 'now' every pidslot walk instead of once per loop.
[trinity.git] / tables-uniarch.c
blobf11ab58d0255bfd77f3302494b6ff48e5272dc66
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 if (calln == -1) {
36 outputerr("No idea what syscall (%s) is.\n", arg);
37 exit(EXIT_FAILURE);
40 validate_specific_syscall(syscalls, calln);
42 if (state == TRUE) {
43 syscalls[calln].entry->flags |= ACTIVE;
44 activate_syscall(calln);
45 } else {
46 syscalls[calln].entry->flags |= TO_BE_DEACTIVATED;
49 output(0, "Marking syscall %s (%d) as to be %sabled.\n",
50 arg_name, calln,
51 state ? "en" : "dis");
55 void enable_random_syscalls_uniarch(void)
57 unsigned int call;
59 retry:
60 call = rand() % max_nr_syscalls;
62 if (validate_specific_syscall_silent(syscalls, call) == FALSE)
63 goto retry;
65 if (no_files == TRUE)
66 if (is_syscall_net_related(syscalls, call) == FALSE)
67 goto retry;
69 /* if we've set this to be disabled, don't enable it! */
70 if (syscalls[call].entry->flags & TO_BE_DEACTIVATED)
71 goto retry;
73 toggle_syscall_n(call, TRUE, syscalls[call].entry->name, syscalls[call].entry->name);
76 void disable_non_net_syscalls_uniarch(void)
78 unsigned int i;
80 for_each_syscall(i) {
81 if (validate_specific_syscall_silent(syscalls, i) == FALSE)
82 continue;
84 if (syscalls[i].entry->flags & ACTIVE) {
85 if (is_syscall_net_related(syscalls, i) == FALSE) {
86 toggle_syscall_n(i, FALSE, syscalls[i].entry->name, syscalls[i].entry->name);
92 int setup_syscall_group_uniarch(unsigned int group)
94 unsigned int i;
96 for_each_syscall(i) {
97 if (syscalls[i].entry->group == group)
98 activate_syscall(i);
101 if (shm->nr_active_syscalls == 0) {
102 outputstd("No syscalls found in group\n");
103 return FALSE;
104 } else {
105 outputstd("Found %d syscalls in group\n", shm->nr_active_syscalls);
108 return TRUE;
111 void mark_all_syscalls_active_uniarch(void)
113 unsigned int i;
115 for_each_syscall(i) {
116 syscalls[i].entry->flags |= ACTIVE;
117 activate_syscall(i);
121 void init_syscalls_uniarch(void)
123 unsigned int i;
125 for_each_syscall(i) {
126 if (syscalls[i].entry->flags & ACTIVE)
127 if (syscalls[i].entry->init)
128 syscalls[i].entry->init();
132 void deactivate_disabled_syscalls_uniarch(void)
134 unsigned int i;
136 for_each_syscall(i) {
137 if (syscalls[i].entry->flags & TO_BE_DEACTIVATED) {
138 syscalls[i].entry->flags &= ~(ACTIVE|TO_BE_DEACTIVATED);
139 deactivate_syscall(i);
140 output(0, "Marked syscall %s (%d) as deactivated.\n",
141 syscalls[i].entry->name, syscalls[i].entry->number);
146 void dump_syscall_tables_uniarch(void)
148 unsigned int i;
150 outputstd("syscalls: %d\n", max_nr_syscalls);
152 for_each_syscall(i) {
153 outputstd("entrypoint %d %s : ",
154 syscalls[i].entry->number,
155 syscalls[i].entry->name);
156 show_state(syscalls[i].entry->flags & ACTIVE);
157 if (syscalls[i].entry->flags & AVOID_SYSCALL)
158 outputstd(" AVOID");
159 outputstd("\n");
163 void display_enabled_syscalls_uniarch(void)
165 unsigned int i;
167 for_each_syscall(i) {
168 if (syscalls[i].entry->flags & ACTIVE)
169 output(0, "syscall %d:%s enabled.\n", i, syscalls[i].entry->name);