19 #include "protocols.h"
20 #include "config.h" // for VERSION
22 char *progname
= NULL
;
24 unsigned int page_size
;
25 unsigned int num_online_cpus
;
32 static void init_buffers(void)
36 output(2, "shm is at %p\n", shm
);
38 page_zeros
= memalign(page_size
, page_size
* 2);
41 memset(page_zeros
, 0, page_size
);
42 output(2, "page_zeros @ %p\n", page_zeros
);
44 page_0xff
= memalign(page_size
, page_size
* 2);
47 memset(page_0xff
, 0xff, page_size
);
48 output(2, "page_0xff @ %p\n", page_0xff
);
50 page_rand
= memalign(page_size
, page_size
* 2);
53 memset(page_rand
, 0x55, page_size
); /* overwritten below */
54 output(2, "page_rand @ %p\n", page_rand
);
56 page_allocs
= memalign(page_size
, page_size
* 2);
59 memset(page_allocs
, 0xff, page_size
);
60 output(2, "page_allocs @ %p\n", page_allocs
);
62 for (i
= 0; i
< (page_size
/ sizeof(unsigned long *)); i
++)
63 page_allocs
[i
] = (unsigned long) malloc(page_size
);
65 setup_global_mappings();
67 // generate_random_page may end up using global_mappings, so has to be last.
68 generate_random_page(page_rand
);
71 /* This is run *after* we've parsed params */
72 static int munge_tables(void)
76 /* By default, all syscall entries will be disabled.
77 * If we didn't pass -c, -x or -r, mark all syscalls active.
79 if ((do_specific_syscall
== FALSE
) && (do_exclude_syscall
== FALSE
) && (random_selection
== FALSE
) && (desired_group
== GROUP_NONE
))
80 mark_all_syscalls_active();
82 if (desired_group
!= GROUP_NONE
) {
83 ret
= setup_syscall_group(desired_group
);
88 if (random_selection
== TRUE
)
89 enable_random_syscalls();
91 /* If we saw a '-x', set all syscalls to enabled, then selectively disable.
92 * Unless we've started enabling them already (with -r)
94 if (do_exclude_syscall
== TRUE
) {
95 if (random_selection
== FALSE
)
96 mark_all_syscalls_active();
97 deactivate_disabled_syscalls();
100 /* if we passed -n, make sure there's no VM/VFS syscalls enabled. */
101 if (no_files
== TRUE
)
102 disable_non_net_syscalls();
104 sanity_check_tables();
106 count_syscalls_enabled();
109 display_enabled_syscalls();
111 if (validate_syscall_tables() == FALSE
) {
112 outputstd("No syscalls were enabled!\n");
113 outputstd("Use 32bit:%d 64bit:%d\n", use_32bit
, use_64bit
);
121 * just in case we're not using the test.sh harness, we
122 * change to the tmp dir if it exists.
124 static void change_tmp_dir(void)
127 const char tmpdir
[]="tmp/";
130 /* Check if it exists, bail early if it doesn't */
131 ret
= (lstat(tmpdir
, &sb
));
135 /* Just in case a previous run screwed the perms. */
136 ret
= chmod(tmpdir
, 0755);
138 output(0, "Couldn't chmod %s to 0755.\n", tmpdir
);
142 output(0, "Couldn't change to %s\n", tmpdir
);
146 int main(int argc
, char* argv
[])
148 int ret
= EXIT_SUCCESS
;
152 outputstd("Trinity v" __stringify(VERSION
) " Dave Jones <davej@redhat.com>\n");
158 page_size
= getpagesize();
159 num_online_cpus
= sysconf(_SC_NPROCESSORS_ONLN
);
161 select_syscall_tables();
166 parse_args(argc
, argv
);
167 outputstd("Done parsing arguments.\n");
169 if (kernel_taint_mask
!= (int)0xFFFFFFFF) {
170 outputstd("Custom kernel taint mask has been specified: 0x%08x (%d).\n", kernel_taint_mask
, kernel_taint_mask
);
173 setup_shm_postargs();
178 if (munge_tables() == FALSE
) {
183 if (show_syscall_list
== TRUE
) {
184 dump_syscall_tables();
190 if (show_ioctl_list
== TRUE
) {
196 if (dangerous
== TRUE
) {
197 outputstd("DANGER: RUNNING AS ROOT.\n");
198 outputstd("Unless you are running in a virtual machine, this could cause serious problems such as overwriting CMOS\n");
199 outputstd("or similar which could potentially make this machine unbootable without a firmware reset.\n\n");
200 outputstd("ctrl-c now unless you really know what you are doing.\n");
201 for (i
= 10; i
> 0; i
--) {
202 outputstd("Continuing in %d seconds.\r", i
);
203 (void)fflush(stdout
);
207 outputstd("Don't run as root (or pass --dangerous if you know what you are doing).\n");
212 if (do_specific_proto
== TRUE
)
213 find_specific_proto(specific_proto_optarg
);
221 setup_main_signals();
223 kernel_taint_initial
= check_tainted();
224 if (kernel_taint_initial
!= 0) {
225 output(0, "Kernel was tainted on startup. Will ignore flags that are already set.\n");
230 /* check if we ctrl'c or something went wrong during init. */
231 if (shm
->exit_reason
!= STILL_RUNNING
)
239 waitpid(watchdog_pid
, &childstatus
, 0);
241 output(0, "\nRan %ld syscalls. Successes: %ld Failures: %ld\n",
242 shm
->total_syscalls_done
- 1, shm
->successes
, shm
->failures
);
250 destroy_global_mappings();