• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1diff -urN strace-4.5.1/defs.h devel/defs.h
2--- strace-4.5.1/defs.h	2003-11-13 18:54:03.000000000 -0800
3+++ devel/defs.h	2004-02-13 01:10:28.000000000 -0800
4@@ -456,6 +456,9 @@
5 extern void printtv32 P((struct tcb*, long));
6 extern void tprint_iov P((struct tcb *, int, long));
7
8+extern int test_percent;
9+extern void test_syscall P((struct tcb *));
10+
11 #ifdef LINUX
12 extern int internal_clone P((struct tcb *));
13 #endif
14diff -urN strace-4.5.1/Makefile.am devel/Makefile.am
15--- strace-4.5.1/Makefile.am	2003-03-30 16:59:18.000000000 -0800
16+++ devel/Makefile.am	2004-02-13 01:10:28.000000000 -0800
17@@ -15,7 +15,7 @@
18 strace_SOURCES = strace.c syscall.c util.c desc.c file.c ipc.c \
19 		 io.c ioctl.c mem.c net.c process.c bjm.c \
20 		 resource.c signal.c sock.c system.c term.c time.c \
21-		 proc.c stream.c
22+		 proc.c stream.c tester.c
23 noinst_HEADERS = defs.h
24
25 EXTRA_DIST = $(man_MANS) errnoent.sh signalent.sh syscallent.sh ioctlsort.c \
26diff -urN strace-4.5.1/Makefile.in devel/Makefile.in
27--- strace-4.5.1/Makefile.in	2003-11-06 18:24:18.000000000 -0800
28+++ devel/Makefile.in	2004-02-13 01:10:28.000000000 -0800
29@@ -146,7 +146,7 @@
30 strace_SOURCES = strace.c syscall.c util.c desc.c file.c ipc.c \
31 		 io.c ioctl.c mem.c net.c process.c bjm.c \
32 		 resource.c signal.c sock.c system.c term.c time.c \
33-		 proc.c stream.c
34+		 proc.c stream.c tester.c
35
36 noinst_HEADERS = defs.h
37
38@@ -210,7 +210,7 @@
39 	ioctl.$(OBJEXT) mem.$(OBJEXT) net.$(OBJEXT) process.$(OBJEXT) \
40 	bjm.$(OBJEXT) resource.$(OBJEXT) signal.$(OBJEXT) \
41 	sock.$(OBJEXT) system.$(OBJEXT) term.$(OBJEXT) time.$(OBJEXT) \
42-	proc.$(OBJEXT) stream.$(OBJEXT)
43+	proc.$(OBJEXT) stream.$(OBJEXT) tester.$(OBJEXT)
44 strace_OBJECTS = $(am_strace_OBJECTS)
45 strace_LDADD = $(LDADD)
46 strace_DEPENDENCIES =
47diff -urN strace-4.5.1/strace.c devel/strace.c
48--- strace-4.5.1/strace.c	2003-11-11 13:24:23.000000000 -0800
49+++ devel/strace.c	2004-02-13 01:10:28.000000000 -0800
50@@ -205,7 +205,7 @@
51 	set_sortby(DEFAULT_SORTBY);
52 	set_personality(DEFAULT_PERSONALITY);
53 	while ((c = getopt(argc, argv,
54-		"+cdfFhiqrtTvVxza:e:o:O:p:s:S:u:E:")) != EOF) {
55+		"+cdfFhiqrtTvVxza:e:o:O:p:s:S:u:E:P:")) != EOF) {
56 		switch (c) {
57 		case 'c':
58 			cflag++;
59@@ -298,6 +298,9 @@
60 				exit(1);
61 			}
62 			break;
63+		case 'P':
64+			test_percent = atoi(optarg);
65+			break;
66 		default:
67 			usage(stderr, 1);
68 			break;
69@@ -2219,6 +2222,8 @@
70 va_dcl
71 #endif
72 {
73+  /* this just slows things down so it's commented out */
74+  /*
75 	va_list args;
76
77 	VA_START(args, fmt);
78@@ -2232,6 +2237,7 @@
79 	}
80 	va_end(args);
81 	return;
82+  */
83 }
84
85 void
86diff -urN strace-4.5.1/syscall.c devel/syscall.c
87--- strace-4.5.1/syscall.c	2003-11-01 14:11:22.000000000 -0800
88+++ devel/syscall.c	2004-02-13 01:10:28.000000000 -0800
89@@ -2118,6 +2118,7 @@
90 			return 0;
91 		}
92
93+		test_syscall(tcp);
94 		if (tcp->flags & TCB_REPRINT) {
95 			printleader(tcp);
96 			tprintf("<... ");
97diff -urN strace-4.5.1/tester.c devel/tester.c
98--- strace-4.5.1/tester.c	1969-12-31 16:00:00.000000000 -0800
99+++ devel/tester.c	2004-02-13 14:55:37.000000000 -0800
100@@ -0,0 +1,172 @@
101+#include <unistd.h>
102+#include <setjmp.h>
103+
104+#include "defs.h"
105+
106+int test_percent = 20;
107+
108+int
109+zero(arg)
110+int arg;
111+{
112+	return 0;
113+}
114+
115+int
116+one(arg)
117+int arg;
118+{
119+	return 1;
120+}
121+
122+int
123+minus_one(arg)
124+int arg;
125+{
126+	return -1;
127+}
128+
129+int
130+maxed(arg)
131+int arg;
132+{
133+	return 0xffffffff;
134+}
135+
136+int
137+dec_one(arg)
138+int arg;
139+{
140+	return arg - 1;
141+}
142+
143+int
144+inc_one(arg)
145+int arg;
146+{
147+	return arg + 1;
148+}
149+
150+int
151+xorred(arg)
152+int arg;
153+{
154+	return arg ^ 1;
155+}
156+
157+int
158+negative(arg)
159+int arg;
160+{
161+	return -arg;
162+}
163+
164+
165+void *magics[] ={
166+	zero,
167+	one,
168+	minus_one,
169+	maxed,
170+	dec_one,
171+	inc_one,
172+	xorred,
173+	negative
174+};
175+
176+static int test_counter;
177+static jmp_buf safe_state;
178+void
179+handle_segv(num)
180+int num;
181+{
182+	printf("seg fault...\n");
183+	test_counter++;
184+	/* longjmp here to avoid an enormous call stack */
185+	longjmp(safe_state, 0);
186+}
187+
188+void test_arg(tcp, narg)
189+struct tcb *tcp;
190+int narg;
191+{
192+	int (*f)(int);
193+	int val;
194+	int val_init = tcp->u_arg[narg];
195+	int rand_offset;
196+	int len_magics = sizeof(magics)/sizeof(void*);
197+
198+	rand_offset = random()%len_magics;
199+	test_counter = 0;
200+
201+	if (signal(SIGSEGV, handle_segv) == SIG_ERR)
202+		tprintf("\nError:  cannot ignore signal\n");
203+
204+	while (1){
205+		setjmp(safe_state);
206+		if (test_counter >= len_magics)
207+			break;
208+		f = magics[(test_counter + rand_offset) % len_magics];
209+		test_counter++;
210+		val = f(val_init);
211+
212+		syscall(tcp->scno,
213+			(narg == 0)? val: tcp->u_arg[0],
214+			(narg == 1)? val: tcp->u_arg[1],
215+			(narg == 2)? val: tcp->u_arg[2],
216+			(narg == 3)? val: tcp->u_arg[3],
217+			(narg == 4)? val: tcp->u_arg[4],
218+			(narg == 5)? val: tcp->u_arg[5]);
219+	}
220+	signal(SIGSEGV, SIG_DFL);
221+}
222+
223+void
224+test_syscall(tcp)
225+struct tcb *tcp;
226+{
227+	int i;
228+
229+	/* only test a random set of syscalls */
230+	if ((random()%100) >= test_percent){
231+		return;
232+	}
233+
234+	/* we end up fork bombing ourselves if we test the
235+	   forking code */
236+#define NR_SYSCALL_BASE 0
237+	switch (tcp->scno + NR_SYSCALL_BASE) {
238+#ifdef SYS_fork
239+	case SYS_fork:
240+#endif
241+#ifdef SYS_vfork
242+	case SYS_vfork:
243+#endif
244+#ifdef SYS_fork1
245+	case SYS_fork1:
246+#endif
247+#ifdef SYS_forkall
248+	case SYS_forkall:
249+#endif
250+#ifdef SYS_rfork1
251+	case SYS_rfork1:
252+#endif
253+#ifdef SYS_rforkall
254+	case SYS_rforkall:
255+#endif
256+#ifdef SYS_rfork
257+	case SYS_rfork:
258+#endif
259+#ifdef SYS_clone
260+	case SYS_clone:
261+#endif
262+#ifdef SYS_clone2
263+	case SYS_clone2:
264+#endif
265+		return;
266+	}
267+
268+	for (i = 0; i < tcp->u_nargs; i++){
269+		test_arg(tcp, i);
270+	}
271+}
272+
273