2 * Program that makes random system calls with random arguments.
6 * Copyright (C) 2003-2006 IBM
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of the
11 * License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
36 unsigned long callnum
, args
[6];
38 int seed_random(void) {
42 fp
= open("/dev/urandom", O_RDONLY
);
44 perror("/dev/urandom");
48 if (read(fp
, &seed
, sizeof(seed
)) != sizeof(seed
)) {
49 perror("read random seed");
59 void get_big_randnum(void *buf
, unsigned int size
) {
63 for (i
= 0; i
< size
; i
+= 4, x
++) {
64 *x
= (unsigned long)((float)UINT_MAX
* (rand() / (RAND_MAX
+ 1.0)));
68 unsigned long get_randnum(unsigned long min
, unsigned long max
) {
69 return min
+ (unsigned long)((float)max
* (rand() / (RAND_MAX
+ 1.0)));
72 int find_syscall(void) {
76 x
= get_randnum(0, 384);
78 /* poorly implemented blacklist */
80 /* don't screw with signal handling */
96 #ifdef SYS_sigprocmask
99 #ifdef SYS_rt_sigreturn
100 case SYS_rt_sigreturn
:
102 #ifdef SYS_rt_sigaction
103 case SYS_rt_sigaction
:
105 #ifdef SYS_rt_sigprocmask
106 case SYS_rt_sigprocmask
:
108 #ifdef SYS_rt_sigpending
109 case SYS_rt_sigpending
:
111 #ifdef SYS_rt_sigtimedwait
112 case SYS_rt_sigtimedwait
:
114 #ifdef SYS_rt_sigqueueinfo
115 case SYS_rt_sigqueueinfo
:
117 #ifdef SYS_rt_sigsuspend
118 case SYS_rt_sigsuspend
:
120 #ifdef SYS_sigaltstack
121 case SYS_sigaltstack
:
123 #ifdef SYS_settimeofday
124 case SYS_settimeofday
:
127 /* don't exit the program :P */
131 #ifdef SYS_exit_group
135 /* don't put it to sleep either */
149 /* these can fill the process table */
160 /* This causes OOM conditions */
167 /* these get our program killed */
180 void bogus_signal_handler(int signum
) {
181 fprintf(stderr
, " Signal %d on syscall(%lu, 0x%lX, 0x%lX, 0x%lX, 0x%lX, 0x%lX, 0x%lX).\n",
182 signum
, callnum
, args
[0], args
[1], args
[2], args
[3],
186 void real_signal_handler(int signum
) {
190 void install_signal_handlers(void) {
192 struct sigaction zig
;
194 memset(&zig
, 0x00, sizeof(zig
));
195 zig
.sa_handler
= bogus_signal_handler
;
196 for (x
= 0; x
< 64; x
++) {
197 sigaction(x
, &zig
, NULL
);
200 zig
.sa_handler
= real_signal_handler
;
201 sigaction(SIGINT
, &zig
, NULL
);
202 sigaction(SIGTERM
, &zig
, NULL
);
205 int main(int argc
, char *argv
[]) {
207 int debug
= 0, zero_mode
= 0;
209 if (!seed_random()) {
213 for (i
= 1; i
< argc
; i
++) {
214 if (!strcmp(argv
[i
], "-d"))
216 else if(!strcmp(argv
[i
], "-z"))
220 memset(args
, 0, sizeof(unsigned long) * 6);
222 install_signal_handlers();
225 callnum
= find_syscall();
227 get_big_randnum(&args
[0], sizeof(unsigned long) * 6);
230 printf("syscall(%lu, 0x%lX, 0x%lX, 0x%lX, 0x%lX, "
232 callnum
, args
[0], args
[1], args
[2], args
[3],
237 syscall(callnum
, args
[0], args
[1], args
[2],
238 args
[3], args
[4], args
[5]);