Re: [uml-user] [uml-devel] UML on WSL

Richard Weinberger <[email protected]> Tue, 9 May 2017 15:11:51 +0200
Newsgroups gmane.linux.uml.user,gmane.linux.uml.devel
Message-ID <[email protected]>
Thomas,

Am 09.05.2017 um 10:15 schrieb Thomas Meyer:
> attached patch work correctly under Linux. But no change under WSL. As stated in the relevant GH issue, there seems to be far more road blockers to make UML work under WSL.
> 
> With you patch I get under WSL:
> 
> thomas@DESKTOP-DQBDJ0U:/mnt/c/Users/thomas/VmShare$ ./linux
> Core dump limits :
>         soft - NONE
>         hard - NONE
> Checking that ptrace can change system call numbers...check_ptrace : failed to modify system call: Invalid Argument

Okay, now it fails later.
UML needs to cancel  syscalls on the host side, it does so by turning them into a getpid() which has no side
effects and, on non-ancient systems, by using PTRACE_SYSEMU.
Let's figure whether they support PTRACE_SYSEMU, can you test the attached patch?

Also please test segv1.c, it tests whether WSL allows us to handle page faults in userspace.
It should output this:
SIGSEGV at 0xdeadbeef, fixing up
x=3, &x=0xdeadbeef

IOW we write to 0xdeadbeef, catch the fault and fix it.

Thanks,
//richard

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot

_______________________________________________
User-mode-linux-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-user
uml_no_syscallchange.diff (text/x-patch, 570 B)
diff --git a/arch/um/os-Linux/start_up.c b/arch/um/os-Linux/start_up.c
index 22a358ef1b0c..37c42cead79d 100644
--- a/arch/um/os-Linux/start_up.c
+++ b/arch/um/os-Linux/start_up.c
@@ -259,7 +259,7 @@ static void __init check_sysemu(void)
 static void __init check_ptrace(void)
 {
 	int pid, syscall, n, status;
-
+#if 0
 	non_fatal("Checking that ptrace can change system call numbers...");
 	pid = start_ptraced_child();
 
@@ -293,6 +293,7 @@ static void __init check_ptrace(void)
 	}
 	stop_ptraced_child(pid, 0, 1);
 	non_fatal("OK\n");
+#endif
 	check_sysemu();
 }
segv1.c (text/x-csrc, 826 B)
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <sys/ucontext.h>
#include <signal.h>
#include <errno.h>

static void segv(int sig, siginfo_t *info, void *context)
{
	ucontext_t *c = context;
	mcontext_t m = c->uc_mcontext;
	void *fault_addr = (void *)m.gregs[REG_CR2];
	void *addr;

	printf("SIGSEGV at 0x%lx, fixing up\n", (unsigned long)fault_addr);

	addr = mmap(fault_addr, 4096, PROT_READ|PROT_WRITE, MAP_ANONYMOUS|MAP_PRIVATE, 0, 0);
	if (addr == MAP_FAILED) {
		printf("map failed!\n");
		exit(1);
	}
}

static void install_handler(void)
{
	struct sigaction sa;

	sa.sa_sigaction = segv;
	sa.sa_flags = SA_SIGINFO;

	sigaction(SIGSEGV, &sa, NULL);
}

int main(void)
{
	int *x = (void *)0xdeadbeef;

	install_handler();

	*x = 3;

	printf("x=%i, &x=%p\n", *x, x);

	return 0;
}