File: patch-linux-2.6.25.6-ptrace_vm

package info (click to toggle)
kernel-patch-viewos 0.20120115-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 1,236 kB
  • sloc: sh: 625; makefile: 85
file content (672 lines) | stat: -rw-r--r-- 20,925 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
diff -Naur linux-2.6.25.6/arch/powerpc/kernel/entry_32.S linux-2.6.25.6-ptrace_vm/arch/powerpc/kernel/entry_32.S
--- linux-2.6.25.6/arch/powerpc/kernel/entry_32.S	2008-06-09 20:27:19.000000000 +0200
+++ linux-2.6.25.6-ptrace_vm/arch/powerpc/kernel/entry_32.S	2008-06-15 23:26:31.000000000 +0200
@@ -292,6 +292,7 @@
 	stw	r0,_TRAP(r1)
 	addi	r3,r1,STACK_FRAME_OVERHEAD
 	bl	do_syscall_trace_enter
+	mr  r10,r3
 	lwz	r0,GPR0(r1)	/* Restore original registers */
 	lwz	r3,GPR3(r1)
 	lwz	r4,GPR4(r1)
@@ -300,6 +301,8 @@
 	lwz	r7,GPR7(r1)
 	lwz	r8,GPR8(r1)
 	REST_NVGPRS(r1)
+	cmpwi r10,0
+	bne-  ret_from_syscall
 	b	syscall_dotrace_cont
 
 syscall_exit_work:
diff -Naur linux-2.6.25.6/arch/powerpc/kernel/entry_64.S linux-2.6.25.6-ptrace_vm/arch/powerpc/kernel/entry_64.S
--- linux-2.6.25.6/arch/powerpc/kernel/entry_64.S	2008-06-09 20:27:19.000000000 +0200
+++ linux-2.6.25.6-ptrace_vm/arch/powerpc/kernel/entry_64.S	2008-06-15 23:26:31.000000000 +0200
@@ -203,6 +203,7 @@
 	bl	.save_nvgprs
 	addi	r3,r1,STACK_FRAME_OVERHEAD
 	bl	.do_syscall_trace_enter
+	mr  r11,r3
 	ld	r0,GPR0(r1)	/* Restore original registers */
 	ld	r3,GPR3(r1)
 	ld	r4,GPR4(r1)
@@ -213,6 +214,8 @@
 	addi	r9,r1,STACK_FRAME_OVERHEAD
 	clrrdi	r10,r1,THREAD_SHIFT
 	ld	r10,TI_FLAGS(r10)
+	cmpwi r11,0
+	bne-  syscall_exit
 	b	syscall_dotrace_cont
 
 syscall_enosys:
diff -Naur linux-2.6.25.6/arch/powerpc/kernel/ptrace.c linux-2.6.25.6-ptrace_vm/arch/powerpc/kernel/ptrace.c
--- linux-2.6.25.6/arch/powerpc/kernel/ptrace.c	2008-06-09 20:27:19.000000000 +0200
+++ linux-2.6.25.6-ptrace_vm/arch/powerpc/kernel/ptrace.c	2008-06-15 23:26:31.000000000 +0200
@@ -867,7 +867,7 @@
 	}
 }
 
-void do_syscall_trace_enter(struct pt_regs *regs)
+int do_syscall_trace_enter(struct pt_regs *regs)
 {
 	secure_computing(regs->gpr[0]);
 
@@ -891,6 +891,7 @@
 					    regs->gpr[5] & 0xffffffff,
 					    regs->gpr[6] & 0xffffffff);
 	}
+	return (current->ptrace & PT_SYSCALL_SKIPCALL);
 }
 
 void do_syscall_trace_leave(struct pt_regs *regs)
@@ -900,7 +901,9 @@
 				   regs->result);
 
 	if ((test_thread_flag(TIF_SYSCALL_TRACE)
-	     || test_thread_flag(TIF_SINGLESTEP))
-	    && (current->ptrace & PT_PTRACED))
+				|| test_thread_flag(TIF_SINGLESTEP))
+			&& (current->ptrace & PT_PTRACED) && 
+			((current->ptrace & PT_SYSCALL_SKIPEXIT)==0))
+
 		do_syscall_trace();
 }
diff -Naur linux-2.6.25.6/arch/ppc/kernel/entry.S linux-2.6.25.6-ptrace_vm/arch/ppc/kernel/entry.S
--- linux-2.6.25.6/arch/ppc/kernel/entry.S	2008-06-09 20:27:19.000000000 +0200
+++ linux-2.6.25.6-ptrace_vm/arch/ppc/kernel/entry.S	2008-06-15 23:26:31.000000000 +0200
@@ -292,6 +292,7 @@
 	stw	r0,TRAP(r1)
 	addi	r3,r1,STACK_FRAME_OVERHEAD
 	bl	do_syscall_trace_enter
+	mr  r10,r3
 	lwz	r0,GPR0(r1)	/* Restore original registers */
 	lwz	r3,GPR3(r1)
 	lwz	r4,GPR4(r1)
@@ -300,6 +301,8 @@
 	lwz	r7,GPR7(r1)
 	lwz	r8,GPR8(r1)
 	REST_NVGPRS(r1)
+	cmpwi r10,0
+	bne-  ret_from_syscall
 	b	syscall_dotrace_cont
 
 syscall_exit_work:
diff -Naur linux-2.6.25.6/arch/um/include/kern_util.h linux-2.6.25.6-ptrace_vm/arch/um/include/kern_util.h
--- linux-2.6.25.6/arch/um/include/kern_util.h	2008-06-09 20:27:19.000000000 +0200
+++ linux-2.6.25.6-ptrace_vm/arch/um/include/kern_util.h	2008-06-15 23:26:31.000000000 +0200
@@ -57,7 +57,7 @@
 extern unsigned long to_irq_stack(unsigned long *mask_out);
 extern unsigned long from_irq_stack(int nested);
 
-extern void syscall_trace(struct uml_pt_regs *regs, int entryexit);
+extern int syscall_trace(struct uml_pt_regs *regs, int entryexit);
 extern int singlestepping(void *t);
 
 extern void segv_handler(int sig, struct uml_pt_regs *regs);
diff -Naur linux-2.6.25.6/arch/um/include/ptrace_user.h linux-2.6.25.6-ptrace_vm/arch/um/include/ptrace_user.h
--- linux-2.6.25.6/arch/um/include/ptrace_user.h	2008-06-09 20:27:19.000000000 +0200
+++ linux-2.6.25.6-ptrace_vm/arch/um/include/ptrace_user.h	2008-06-15 23:26:31.000000000 +0200
@@ -40,9 +40,20 @@
 #define PTRACE_OLDSETOPTIONS PTRACE_SETOPTIONS
 #endif
 
+/* these constant should eventually enter in sys/ptrace.h */
+#ifndef PTRACE_SYSCALL_SKIPCALL
+#define PTRACE_SYSCALL_SKIPCALL      0x6
+#endif
+#ifndef PTRACE_SYSCALL_SKIPEXIT
+#define PTRACE_SYSCALL_SKIPEXIT      0x2
+#endif
+
 void set_using_sysemu(int value);
 int get_using_sysemu(void);
 extern int sysemu_supported;
+void set_using_sysptvm(int value);
+int get_using_sysptvm(void);
+extern int sysptvm_supported;
 
 #define SELECT_PTRACE_OPERATION(sysemu_mode, singlestep_mode) \
 	(((int[3][3] ) { \
diff -Naur linux-2.6.25.6/arch/um/kernel/process.c linux-2.6.25.6-ptrace_vm/arch/um/kernel/process.c
--- linux-2.6.25.6/arch/um/kernel/process.c	2008-06-09 20:27:19.000000000 +0200
+++ linux-2.6.25.6-ptrace_vm/arch/um/kernel/process.c	2008-06-15 23:31:02.000000000 +0200
@@ -322,7 +322,9 @@
 }
 
 static atomic_t using_sysemu = ATOMIC_INIT(0);
+static atomic_t using_sysptvm = ATOMIC_INIT(0);
 int sysemu_supported;
+int sysptvm_supported;
 
 void set_using_sysemu(int value)
 {
@@ -336,6 +338,16 @@
 	return atomic_read(&using_sysemu);
 }
 
+void set_using_sysptvm(int value)
+{
+	atomic_set(&using_sysptvm, value);
+}
+
+int get_using_sysptvm(void)
+{
+	return atomic_read(&using_sysptvm);
+}
+
 static int proc_read_sysemu(char *buf, char **start, off_t offset, int size,int *eof, void *data)
 {
 	if (snprintf(buf, size, "%d\n", get_using_sysemu()) < size)
@@ -358,27 +370,37 @@
 	return count;
 }
 
-int __init make_proc_sysemu(void)
+int __init make_proc_sysemu_or_sysptvm(void)
 {
 	struct proc_dir_entry *ent;
-	if (!sysemu_supported)
-		return 0;
 
-	ent = create_proc_entry("sysemu", 0600, &proc_root);
+	if (sysptvm_supported) {
+		ent = create_proc_entry("sysptvm", 0600, &proc_root);
 
-	if (ent == NULL)
-	{
-		printk(KERN_WARNING "Failed to register /proc/sysemu\n");
-		return 0;
-	}
-
-	ent->read_proc  = proc_read_sysemu;
-	ent->write_proc = proc_write_sysemu;
+		if (ent == NULL)
+		{
+			printk(KERN_WARNING "Failed to register /proc/sysptvm\n");
+			return 0;
+		}
+
+		ent->read_proc  = proc_read_sysptvm;
+		ent->write_proc = proc_write_sysptvm;
+	} else if (sysemu_supported) {
+		ent = create_proc_entry("sysemu", 0600, &proc_root);
+
+		if (ent == NULL)
+		{
+			printk(KERN_WARNING "Failed to register /proc/sysemu\n");
+			return 0;
+		}
 
+		ent->read_proc  = proc_read_sysemu;
+		ent->write_proc = proc_write_sysemu;
+	}
 	return 0;
 }
 
-late_initcall(make_proc_sysemu);
+late_initcall(make_proc_sysemu_or_sysptvm);
 
 int singlestepping(void * t)
 {
diff -Naur linux-2.6.25.6/arch/um/kernel/ptrace.c linux-2.6.25.6-ptrace_vm/arch/um/kernel/ptrace.c
--- linux-2.6.25.6/arch/um/kernel/ptrace.c	2008-06-09 20:27:19.000000000 +0200
+++ linux-2.6.25.6-ptrace_vm/arch/um/kernel/ptrace.c	2008-06-15 23:26:31.000000000 +0200
@@ -76,6 +76,8 @@
 		if (request == PTRACE_SYSCALL)
 			set_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
 		else clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
+		child->ptrace &= ~PT_SYSCALL_MASK;
+		child->ptrace |= (addr & PTRACE_SYSCALL_MASK) << 28;
 		child->exit_code = data;
 		wake_up_process(child);
 		ret = 0;
@@ -102,7 +104,9 @@
 		ret = -EIO;
 		if (!valid_signal(data))
 			break;
+		child->ptrace &= ~PT_SYSCALL_MASK;
 		clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
+		child->ptrace |= (addr & PTRACE_SYSCALL_MASK) << 28;
 		set_singlestepping(child, 1);
 		child->exit_code = data;
 		/* give it a chance to run. */
@@ -245,7 +249,7 @@
  * XXX Check PT_DTRACE vs TIF_SINGLESTEP for singlestepping check and
  * PT_PTRACED vs TIF_SYSCALL_TRACE for syscall tracing check
  */
-void syscall_trace(struct uml_pt_regs *regs, int entryexit)
+int syscall_trace(struct uml_pt_regs *regs, int entryexit)
 {
 	int is_singlestep = (current->ptrace & PT_DTRACE) && entryexit;
 	int tracesysgood;
@@ -267,10 +271,13 @@
 		send_sigtrap(current, regs, 0);
 
 	if (!test_thread_flag(TIF_SYSCALL_TRACE))
-		return;
+		return 0;
 
 	if (!(current->ptrace & PT_PTRACED))
-		return;
+		return 0;
+
+	if (entryexit && (current->ptrace & PT_SYSCALL_SKIPEXIT))
+		return 0;
 
 	/*
 	 * the 0x80 provides a way for the tracing parent to distinguish
@@ -291,4 +298,8 @@
 		send_sig(current->exit_code, current, 1);
 		current->exit_code = 0;
 	}
+	if (!entryexit && (current->ptrace & PT_SYSCALL_SKIPCALL))
+		return 1;
+	else
+		return 0;
 }
diff -Naur linux-2.6.25.6/arch/um/kernel/skas/syscall.c linux-2.6.25.6-ptrace_vm/arch/um/kernel/skas/syscall.c
--- linux-2.6.25.6/arch/um/kernel/skas/syscall.c	2008-06-09 20:27:19.000000000 +0200
+++ linux-2.6.25.6-ptrace_vm/arch/um/kernel/skas/syscall.c	2008-06-15 23:26:31.000000000 +0200
@@ -17,8 +17,9 @@
 	struct pt_regs *regs = container_of(r, struct pt_regs, regs);
 	long result;
 	int syscall;
+	int skip_call;
 
-	syscall_trace(r, 0);
+	skip_call=syscall_trace(r, 0);
 
 	/*
 	 * This should go in the declaration of syscall, but when I do that,
@@ -29,12 +30,14 @@
 	 *     gcc version 4.0.1 20050727 (Red Hat 4.0.1-5)
 	 * in case it's a compiler bug.
 	 */
-	syscall = UPT_SYSCALL_NR(r);
-	if ((syscall >= NR_syscalls) || (syscall < 0))
-		result = -ENOSYS;
-	else result = EXECUTE_SYSCALL(syscall, regs);
+	if (skip_call == 0) {
+		syscall = UPT_SYSCALL_NR(r);
+		if ((syscall >= NR_syscalls) || (syscall < 0))
+			result = -ENOSYS;
+		else result = EXECUTE_SYSCALL(syscall, regs);
 
-	REGS_SET_SYSCALL_RETURN(r->gp, result);
+		REGS_SET_SYSCALL_RETURN(r->gp, result);
+	}
 
 	syscall_trace(r, 1);
 }
diff -Naur linux-2.6.25.6/arch/um/os-Linux/skas/process.c linux-2.6.25.6-ptrace_vm/arch/um/os-Linux/skas/process.c
--- linux-2.6.25.6/arch/um/os-Linux/skas/process.c	2008-06-09 20:27:19.000000000 +0200
+++ linux-2.6.25.6-ptrace_vm/arch/um/os-Linux/skas/process.c	2008-06-15 23:26:31.000000000 +0200
@@ -157,7 +157,7 @@
  * (in local_using_sysemu
  */
 static void handle_trap(int pid, struct uml_pt_regs *regs,
-			int local_using_sysemu)
+			int local_using_sysptvm_or_sysemu)
 {
 	int err, status;
 
@@ -167,7 +167,7 @@
 	/* Mark this as a syscall */
 	UPT_SYSCALL_NR(regs) = PT_SYSCALL_NR(regs->gp);
 
-	if (!local_using_sysemu)
+	if (!local_using_sysptvm_or_sysemu)
 	{
 		err = ptrace(PTRACE_POKEUSR, pid, PT_SYSCALL_NR_OFFSET,
 			     __NR_getpid);
@@ -354,6 +354,7 @@
 	int err, status, op, pid = userspace_pid[0];
 	/* To prevent races if using_sysemu changes under us.*/
 	int local_using_sysemu;
+	int local_using_sysptvm;
 
 	if (getitimer(ITIMER_VIRTUAL, &timer))
 		printk(UM_KERN_ERR "Failed to get itimer, errno = %d\n", errno);
@@ -375,11 +376,12 @@
 
 		/* Now we set local_using_sysemu to be used for one loop */
 		local_using_sysemu = get_using_sysemu();
+		local_using_sysptvm = get_using_sysptvm();
 
 		op = SELECT_PTRACE_OPERATION(local_using_sysemu,
 					     singlestepping(NULL));
 
-		if (ptrace(op, pid, 0, 0)) {
+		if (ptrace(op, pid, local_using_sysptvm, 0)) {
 			printk(UM_KERN_ERR "userspace - ptrace continue "
 			       "failed, op = %d, errno = %d\n", op, errno);
 			fatal_sigsegv();
diff -Naur linux-2.6.25.6/arch/um/os-Linux/start_up.c linux-2.6.25.6-ptrace_vm/arch/um/os-Linux/start_up.c
--- linux-2.6.25.6/arch/um/os-Linux/start_up.c	2008-06-09 20:27:19.000000000 +0200
+++ linux-2.6.25.6-ptrace_vm/arch/um/os-Linux/start_up.c	2008-06-15 23:26:31.000000000 +0200
@@ -187,6 +187,35 @@
 "    See http://perso.wanadoo.fr/laurent.vivier/UML/ for further \n"
 "    information.\n\n");
 
+/* Changed only during early boot */
+static int force_sysptvm_disabled = 0;
+
+static int __init nosysptvm_cmd_param(char *str, int* add)
+{
+	force_sysptvm_disabled = 1;
+	return 0;
+}
+
+__uml_setup("nosysptvm", nosysptvm_cmd_param,
+"nosysptvm\n"
+"    Turns off syscall emulation tags for ptrace (ptrace_vm) on.\n"
+"    Ptrace_vm is a feature introduced by Renzo Davoli. It changes\n"
+"    behaviour of ptrace() and helps reducing host context switch rate.\n"
+"\n");
+
+static int use_sysemu = 0;
+
+static int __init usesysemu_cmd_param(char *str, int* add)
+{
+	use_sysemu = 1;
+	return 0;
+}
+
+__uml_setup("usesysemu", usesysemu_cmd_param,
+"usesysemu\n"
+"    Use sysemu instead of sysptvm even when the kernel supports it.\n\n"
+);
+
 static void __init check_sysemu(void)
 {
 	unsigned long regs[MAX_REG_NR];
@@ -277,6 +306,100 @@
 	non_fatal("missing\n");
 }
 
+/* test thread code. This thread is started only to test 
+ * which features are provided by the linux kernel */
+static int sysptvm_child(void *arg)
+{
+	int *featurep=arg;
+	int p[2]={-1,-1};
+	pid_t pid=os_getpid();
+	if(ptrace(PTRACE_TRACEME, 0, 0, 0) < 0){
+		perror("ptrace test_ptracemulti");
+		kill(pid, SIGKILL);
+	}
+	kill(pid, SIGSTOP);
+	*featurep=0;
+	os_getpid();
+	/* if it reaches this point in 1 stop it means that
+	 * PTRACE_SYSCALL_SKIPEXIT works */
+	*featurep=PTRACE_SYSCALL_SKIPEXIT;
+	pipe(p);
+	/* if after a PTRACE_SYSCALL_SKIPCALL p[0] is already <0 
+	 * pipe has been really skipped */
+	if (p[0] < 0)
+		*featurep=PTRACE_SYSCALL_SKIPCALL;
+	else { /* clean up everything */
+		close(p[0]);
+		close(p[1]);
+	}
+	return 0;
+}
+
+/* kernel feature test: 
+ * it returns:
+ *   -1 error 
+ *   0 old PTRACE_SYSCALL (addr is ignored)
+ *   PTRACE_SYSCALL_SKIPEXIT: just skip_exit is provided
+ *   PTRACE_SYSCALL_SKIPCALL: the entire syntax is implemented
+ *   by the running kernel */
+static int __init test_ptrace_sysptvm(void) {
+	int pid, status, rv, feature;
+	static char stack[1024];
+	feature=0;
+
+	if((pid = clone(sysptvm_child, &stack[1020], SIGCHLD | CLONE_VM, &feature)) < 0)
+		return 0;
+	if(waitpid(pid, &status, WUNTRACED) < 0){
+		kill(pid, SIGKILL);
+		return 0;
+	}
+	/* restart and wait for the next syscall (getpid)*/
+	rv=ptrace(PTRACE_SYSCALL, pid, 0, 0);
+	if(waitpid(pid, &status, WUNTRACED) < 0)
+		goto out;
+	/* try to skip the exit call */
+	rv=ptrace(PTRACE_SYSCALL, pid, PTRACE_SYSCALL_SKIPEXIT, 0);
+	if (rv < 0)
+		goto out;
+	/* wait for the next stop */
+	if(waitpid(pid, &status, WUNTRACED) < 0)
+		goto out;
+	/* if feature is already 0 it means that this is the exit call,
+	 * and it has not been skipped, otherwise this is the
+	 * entry call for the system call "time" */
+	if (feature<PTRACE_SYSCALL_SKIPEXIT)
+		goto out;
+	/* restart (time) and and try to skip the entire call */
+	rv=ptrace(PTRACE_SYSCALL, pid, PTRACE_SYSCALL_SKIPCALL, 0);
+	if(waitpid(pid, &status, WUNTRACED) < 0)
+		return 0;
+out:
+	ptrace(PTRACE_KILL,pid,0,0);
+	/* eliminate zombie */
+	if(waitpid(pid, &status, WUNTRACED) < 0)
+		return 0;
+	return feature;
+}
+
+static int  __init check_sysptvm(void)
+{
+	int feature=test_ptrace_sysptvm();
+  
+	non_fatal("Checking ptrace new tags for syscall emulation...");
+	if (feature==PTRACE_SYSCALL_SKIPCALL) {
+		sysptvm_supported=1;
+		non_fatal("OK");
+		if (!force_sysptvm_disabled) 
+			set_using_sysptvm(PTRACE_SYSCALL_SKIPCALL);
+		else
+			non_fatal(" (disabled)");
+		non_fatal("\n");
+		return 1;
+	} else
+		non_fatal("unsupported\n");
+	return 0;
+}
+
 static void __init check_ptrace(void)
 {
 	int pid, syscall, n, status;
@@ -314,7 +437,8 @@
 	}
 	stop_ptraced_child(pid, 0, 1);
 	non_fatal("OK\n");
-	check_sysemu();
+	if (use_sysemu || !check_sysptvm()) 
+		check_sysemu();
 }
 
 extern void check_tmpexec(void);
diff -Naur linux-2.6.25.6/arch/x86/ia32/ia32entry.S linux-2.6.25.6-ptrace_vm/arch/x86/ia32/ia32entry.S
--- linux-2.6.25.6/arch/x86/ia32/ia32entry.S	2008-06-09 20:27:19.000000000 +0200
+++ linux-2.6.25.6-ptrace_vm/arch/x86/ia32/ia32entry.S	2008-06-15 23:26:31.000000000 +0200
@@ -165,6 +165,8 @@
 	movq	$-ENOSYS,RAX(%rsp)	/* really needed? */
 	movq	%rsp,%rdi        /* &pt_regs -> arg1 */
 	call	syscall_trace_enter
+	testq %rax,%rax
+	jnz ia32_skipcall
 	LOAD_ARGS32 ARGOFFSET  /* reload args from stack in case ptrace changed it */
 	RESTORE_REST
 	xchgl	%ebp,%r9d
@@ -264,6 +266,8 @@
 	movq $-ENOSYS,RAX(%rsp)	/* really needed? */
 	movq %rsp,%rdi        /* &pt_regs -> arg1 */
 	call syscall_trace_enter
+	testq %rax,%rax
+	jnz ia32_skipcall
 	LOAD_ARGS32 ARGOFFSET  /* reload args from stack in case ptrace changed it */
 	RESTORE_REST
 	xchgl %ebp,%r9d
@@ -338,6 +342,8 @@
 	movq $-ENOSYS,RAX(%rsp)	/* really needed? */
 	movq %rsp,%rdi        /* &pt_regs -> arg1 */
 	call syscall_trace_enter
+	testq %rax,%rax
+	jnz ia32_skipcall
 	LOAD_ARGS32 ARGOFFSET  /* reload args from stack in case ptrace changed it */
 	RESTORE_REST
 	jmp ia32_do_syscall
@@ -348,6 +354,11 @@
 	movq $-ENOSYS,RAX-ARGOFFSET(%rsp)
 	jmp int_ret_from_sys_call
 
+ia32_skipcall:
+	LOAD_ARGS32 ARGOFFSET  /* reload args from stack in case ptrace changed it */
+	RESTORE_REST
+	jmp int_ret_from_sys_call
+
 quiet_ni_syscall:
 	movq $-ENOSYS,%rax
 	ret
diff -Naur linux-2.6.25.6/arch/x86/kernel/entry_64.S linux-2.6.25.6-ptrace_vm/arch/x86/kernel/entry_64.S
--- linux-2.6.25.6/arch/x86/kernel/entry_64.S	2008-06-09 20:27:19.000000000 +0200
+++ linux-2.6.25.6-ptrace_vm/arch/x86/kernel/entry_64.S	2008-06-15 23:26:31.000000000 +0200
@@ -316,6 +316,11 @@
 	movq $-ENOSYS,RAX-ARGOFFSET(%rsp)
 	jmp ret_from_sys_call
 
+skipcall:
+	LOAD_ARGS ARGOFFSET  /* reload args from stack in case ptrace changed it */
+	RESTORE_REST
+	jmp ret_from_sys_call
+
 	/* Do syscall tracing */
 tracesys:			 
 	SAVE_REST
@@ -323,6 +328,8 @@
 	FIXUP_TOP_OF_STACK %rdi
 	movq %rsp,%rdi
 	call syscall_trace_enter
+	testq %rax,%rax
+	jnz skipcall
 	LOAD_ARGS ARGOFFSET  /* reload args from stack in case ptrace changed it */
 	RESTORE_REST
 	cmpq $__NR_syscall_max,%rax
diff -Naur linux-2.6.25.6/arch/x86/kernel/ptrace.c linux-2.6.25.6-ptrace_vm/arch/x86/kernel/ptrace.c
--- linux-2.6.25.6/arch/x86/kernel/ptrace.c	2008-06-09 20:27:19.000000000 +0200
+++ linux-2.6.25.6-ptrace_vm/arch/x86/kernel/ptrace.c	2008-06-15 23:26:31.000000000 +0200
@@ -1495,6 +1495,9 @@
 	if (!(current->ptrace & PT_PTRACED))
 		goto out;
 
+	if (entryexit && (current->ptrace & PT_SYSCALL_SKIPEXIT))
+		return 0;
+
 	/* If a process stops on the 1st tracepoint with SYSCALL_TRACE
 	 * and then is resumed with SYSEMU_SINGLESTEP, it will come in
 	 * here. We have to check this and return */
@@ -1522,7 +1525,8 @@
 		send_sig(current->exit_code, current, 1);
 		current->exit_code = 0;
 	}
-	ret = is_sysemu;
+	ret = (is_sysemu || (!entryexit && (current->ptrace & PT_SYSCALL_SKIPCALL)));
+
 out:
 	if (unlikely(current->audit_context) && !entryexit)
 		audit_syscall_entry(AUDIT_ARCH_I386, regs->orig_ax,
@@ -1561,7 +1565,7 @@
 	}
 }
 
-asmlinkage void syscall_trace_enter(struct pt_regs *regs)
+asmlinkage long syscall_trace_enter(struct pt_regs *regs)
 {
 	/* do the secure computing check first */
 	secure_computing(regs->orig_ax);
@@ -1583,6 +1587,8 @@
 					    regs->dx, regs->r10);
 		}
 	}
+
+	return (current->ptrace & PT_SYSCALL_SKIPCALL);
 }
 
 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
@@ -1592,7 +1598,8 @@
 
 	if ((test_thread_flag(TIF_SYSCALL_TRACE)
 	     || test_thread_flag(TIF_SINGLESTEP))
-	    && (current->ptrace & PT_PTRACED))
+			&& (current->ptrace & PT_PTRACED) &&
+			((current->ptrace & PT_SYSCALL_SKIPEXIT)==0))
 		syscall_trace(regs);
 }
 
diff -Naur linux-2.6.25.6/include/linux/ptrace.h linux-2.6.25.6-ptrace_vm/include/linux/ptrace.h
--- linux-2.6.25.6/include/linux/ptrace.h	2008-06-09 20:27:19.000000000 +0200
+++ linux-2.6.25.6-ptrace_vm/include/linux/ptrace.h	2008-06-15 23:26:31.000000000 +0200
@@ -46,6 +46,11 @@
 #define PTRACE_EVENT_VFORK_DONE	5
 #define PTRACE_EVENT_EXIT	6
 
+/* options for new PTRACE_SYSCALL syntax*/
+#define PTRACE_SYSCALL_SKIPEXIT  0x2
+#define PTRACE_SYSCALL_SKIPCALL  0x6
+#define PTRACE_SYSCALL_MASK    0x00000006
+
 #include <asm/ptrace.h>
 
 #ifdef __KERNEL__
@@ -68,6 +73,10 @@
 #define PT_TRACE_VFORK_DONE	0x00000100
 #define PT_TRACE_EXIT	0x00000200
 
+#define PT_SYSCALL_SKIPEXIT  0x60000000
+#define PT_SYSCALL_SKIPCALL  0x40000000
+#define PT_SYSCALL_MASK      0x60000000
+
 #define PT_TRACE_MASK	0x000003f4
 
 /* single stepping state bits (used on ARM and PA-RISC) */
diff -Naur linux-2.6.25.6/kernel/ptrace.c linux-2.6.25.6-ptrace_vm/kernel/ptrace.c
--- linux-2.6.25.6/kernel/ptrace.c	2008-06-09 20:27:19.000000000 +0200
+++ linux-2.6.25.6-ptrace_vm/kernel/ptrace.c	2008-06-15 23:26:31.000000000 +0200
@@ -385,7 +385,7 @@
 #define is_sysemu_singlestep(request)	0
 #endif
 
-static int ptrace_resume(struct task_struct *child, long request, long data)
+static int ptrace_resume(struct task_struct *child, long request, long addr, long data)
 {
 	if (!valid_signal(data))
 		return -EIO;
@@ -414,6 +414,9 @@
 	else
 		user_disable_single_step(child);
 
+	child->ptrace &= ~PT_SYSCALL_MASK;
+	child->ptrace |= (addr & PTRACE_SYSCALL_MASK) << 28;
+
 	child->exit_code = data;
 	wake_up_process(child);
 
@@ -464,12 +467,12 @@
 #endif
 	case PTRACE_SYSCALL:
 	case PTRACE_CONT:
-		return ptrace_resume(child, request, data);
+		return ptrace_resume(child, request, addr, data);
 
 	case PTRACE_KILL:
 		if (child->exit_state)	/* already dead */
 			return 0;
-		return ptrace_resume(child, request, SIGKILL);
+		return ptrace_resume(child, request, addr, SIGKILL);
 
 	default:
 		break;