+static int __init nosysemu_cmd_param(char *str, int* add)
+{
+ force_sysemu_disabled = 1;
+ return 0;
+}
+
+__uml_setup("nosysemu", nosysemu_cmd_param,
+ "nosysemu\n"
+ " Turns off syscall emulation patch for ptrace (SYSEMU) on.\n"
+ " SYSEMU is a performance-patch introduced by Laurent Vivier. It changes\n"
+ " behaviour of ptrace() and helps reducing host context switch rate.\n"
+ " To make it working, you need a kernel patch for your host, too.\n"
+ " See http://perso.wanadoo.fr/laurent.vivier/UML/ for further information.\n\n");
+
+static void __init check_sysemu(void)
+{
+ int pid, syscall, n, status, count=0;
+
+ printk("Checking syscall emulation patch for ptrace...");
+ sysemu_supported = 0;
+ pid = start_ptraced_child();
+
+ if(ptrace(PTRACE_SYSEMU, pid, 0, 0) < 0)
+ goto fail;
+
+ CATCH_EINTR(n = waitpid(pid, &status, WUNTRACED));
+ if (n < 0)
+ panic("check_sysemu : wait failed, errno = %d", errno);
+ if(!WIFSTOPPED(status) || (WSTOPSIG(status) != SIGTRAP))
+ panic("check_sysemu : expected SIGTRAP, "
+ "got status = %d", status);
+
+ n = ptrace(PTRACE_POKEUSR, pid, PT_SYSCALL_RET_OFFSET,
+ os_getpid());
+ if(n < 0)
+ panic("check_sysemu : failed to modify system "
+ "call return, errno = %d", errno);
+
+ if (stop_ptraced_child(pid, 0, 0) < 0)
+ goto fail_stopped;
+
+ sysemu_supported = 1;
+ printk("OK\n");
+ set_using_sysemu(!force_sysemu_disabled);
+
+ printk("Checking advanced syscall emulation patch for ptrace...");
+ pid = start_ptraced_child();
+ while(1){
+ count++;
+ if(ptrace(PTRACE_SYSEMU_SINGLESTEP, pid, 0, 0) < 0)
+ goto fail;
+ CATCH_EINTR(n = waitpid(pid, &status, WUNTRACED));
+ if(n < 0)
+ panic("check_ptrace : wait failed, errno = %d", errno);
+ if(!WIFSTOPPED(status) || (WSTOPSIG(status) != SIGTRAP))
+ panic("check_ptrace : expected (SIGTRAP|SYSCALL_TRAP), "
+ "got status = %d", status);
+
+ syscall = ptrace(PTRACE_PEEKUSR, pid, PT_SYSCALL_NR_OFFSET,
+ 0);
+ if(syscall == __NR_getpid){
+ if (!count)
+ panic("check_ptrace : SYSEMU_SINGLESTEP doesn't singlestep");
+ n = ptrace(PTRACE_POKEUSR, pid, PT_SYSCALL_RET_OFFSET,
+ os_getpid());
+ if(n < 0)
+ panic("check_sysemu : failed to modify system "
+ "call return, errno = %d", errno);
+ break;
+ }
+ }
+ if (stop_ptraced_child(pid, 0, 0) < 0)
+ goto fail_stopped;
+
+ sysemu_supported = 2;
+ printk("OK\n");
+
+ if ( !force_sysemu_disabled )
+ set_using_sysemu(sysemu_supported);
+ return;
+
+fail:
+ stop_ptraced_child(pid, 1, 0);
+fail_stopped:
+ printk("missing\n");