Module Name:    src
Committed By:   reinoud
Date:           Tue Dec 20 15:45:37 UTC 2011

Modified Files:
        src/sys/arch/usermode/include: thunk.h
        src/sys/arch/usermode/usermode: pmap.c syscall.c thunk.c

Log Message:
Use to the MAP_NOSYSCALLS argument to mmap() to allow for NetBSD/usermode to
execute bog-standard native programs.


To generate a diff of this commit:
cvs rdiff -u -r1.41 -r1.42 src/sys/arch/usermode/include/thunk.h
cvs rdiff -u -r1.79 -r1.80 src/sys/arch/usermode/usermode/pmap.c
cvs rdiff -u -r1.18 -r1.19 src/sys/arch/usermode/usermode/syscall.c
cvs rdiff -u -r1.47 -r1.48 src/sys/arch/usermode/usermode/thunk.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/usermode/include/thunk.h
diff -u src/sys/arch/usermode/include/thunk.h:1.41 src/sys/arch/usermode/include/thunk.h:1.42
--- src/sys/arch/usermode/include/thunk.h:1.41	Thu Dec 15 03:42:32 2011
+++ src/sys/arch/usermode/include/thunk.h	Tue Dec 20 15:45:36 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: thunk.h,v 1.41 2011/12/15 03:42:32 jmcneill Exp $ */
+/* $NetBSD: thunk.h,v 1.42 2011/12/20 15:45:36 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2011 Jared D. McNeill <jmcne...@invisible.ca>
@@ -61,6 +61,7 @@ struct thunk_termios {
 #define THUNK_MAP_FILE		0x0004
 #define THUNK_MAP_SHARED	0x0010
 #define THUNK_MAP_PRIVATE	0x0020
+#define THUNK_MAP_NOSYSCALLS	0x0040
 
 #define THUNK_PROT_NONE		0x00
 #define THUNK_PROT_READ		0x01

Index: src/sys/arch/usermode/usermode/pmap.c
diff -u src/sys/arch/usermode/usermode/pmap.c:1.79 src/sys/arch/usermode/usermode/pmap.c:1.80
--- src/sys/arch/usermode/usermode/pmap.c:1.79	Wed Dec 14 17:06:28 2011
+++ src/sys/arch/usermode/usermode/pmap.c	Tue Dec 20 15:45:37 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.c,v 1.79 2011/12/14 17:06:28 reinoud Exp $ */
+/* $NetBSD: pmap.c,v 1.80 2011/12/20 15:45:37 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2011 Reinoud Zandijk <rein...@netbsd.org>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.79 2011/12/14 17:06:28 reinoud Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.80 2011/12/20 15:45:37 reinoud Exp $");
 
 #include "opt_memsize.h"
 #include "opt_kmempages.h"
@@ -626,11 +626,15 @@ pmap_page_activate(struct pv_entry *pv)
 {
 	paddr_t pa = pv->pv_ppn * PAGE_SIZE;
 	vaddr_t va = pv->pv_lpn * PAGE_SIZE + VM_MIN_ADDRESS; /* L->V */
+	uint32_t map_flags;
 	void *addr;
 
+	map_flags = THUNK_MAP_FILE | THUNK_MAP_FIXED | THUNK_MAP_SHARED;
+	if ((va >= VM_MIN_ADDRESS) && (va < VM_MAXUSER_ADDRESS)) 
+		map_flags |= THUNK_MAP_NOSYSCALLS;
+
 	addr = thunk_mmap((void *) va, PAGE_SIZE, pv->pv_mmap_ppl,
-		THUNK_MAP_FILE | THUNK_MAP_FIXED | THUNK_MAP_SHARED,
-		mem_fh, pa);
+		map_flags, mem_fh, pa);
 	dprintf_debug("page_activate: (va %p, pa %p, prot %d, ppl %d) -> %p\n",
 		(void *) va, (void *) pa, pv->pv_prot, pv->pv_mmap_ppl,
 		(void *) addr);
@@ -648,14 +652,15 @@ pmap_page_deactivate(struct pv_entry *pv
 {
 	paddr_t pa = pv->pv_ppn * PAGE_SIZE;
 	vaddr_t va = pv->pv_lpn * PAGE_SIZE + VM_MIN_ADDRESS; /* L->V */
+	uint32_t map_flags;
 	void *addr;
 
 	if (pv->pv_vflags & PV_WIRED)
 		return;
 
+	map_flags = THUNK_MAP_FILE | THUNK_MAP_FIXED | THUNK_MAP_SHARED;
 	addr = thunk_mmap((void *) va, PAGE_SIZE, THUNK_PROT_NONE,
-		THUNK_MAP_FILE | THUNK_MAP_FIXED | THUNK_MAP_SHARED,
-		mem_fh, pa);
+		map_flags, mem_fh, pa);
 	dprintf_debug("page_deactivate: (va %p, pa %p, ppl %d) -> %p\n",
 		(void *) va, (void *) pa, pv->pv_mmap_ppl, (void *) addr);
 	if (addr != (void *) va)

Index: src/sys/arch/usermode/usermode/syscall.c
diff -u src/sys/arch/usermode/usermode/syscall.c:1.18 src/sys/arch/usermode/usermode/syscall.c:1.19
--- src/sys/arch/usermode/usermode/syscall.c:1.18	Thu Dec 15 11:23:52 2011
+++ src/sys/arch/usermode/usermode/syscall.c	Tue Dec 20 15:45:37 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: syscall.c,v 1.18 2011/12/15 11:23:52 jmcneill Exp $ */
+/* $NetBSD: syscall.c,v 1.19 2011/12/20 15:45:37 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2007 Jared D. McNeill <jmcne...@invisible.ca>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: syscall.c,v 1.18 2011/12/15 11:23:52 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: syscall.c,v 1.19 2011/12/20 15:45:37 reinoud Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -99,6 +99,8 @@ syscall(void)
 	curcpu()->ci_data.cpu_nsyscall++;
 	LWP_CACHE_CREDS(l, l->l_proc);
 
+	/* TODO are we allowed to execute system calls in this memory space? */
+
 	/* XXX do we want do do emulation? */
 	md_syscall_get_opcode(ucp, &opcode);
 	md_syscall_get_syscallnumber(ucp, &code);

Index: src/sys/arch/usermode/usermode/thunk.c
diff -u src/sys/arch/usermode/usermode/thunk.c:1.47 src/sys/arch/usermode/usermode/thunk.c:1.48
--- src/sys/arch/usermode/usermode/thunk.c:1.47	Thu Dec 15 03:42:33 2011
+++ src/sys/arch/usermode/usermode/thunk.c	Tue Dec 20 15:45:37 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: thunk.c,v 1.47 2011/12/15 03:42:33 jmcneill Exp $ */
+/* $NetBSD: thunk.c,v 1.48 2011/12/20 15:45:37 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2011 Jared D. McNeill <jmcne...@invisible.ca>
@@ -28,7 +28,7 @@
 
 #include <sys/cdefs.h>
 #ifdef __NetBSD__
-__RCSID("$NetBSD: thunk.c,v 1.47 2011/12/15 03:42:33 jmcneill Exp $");
+__RCSID("$NetBSD: thunk.c,v 1.48 2011/12/20 15:45:37 reinoud Exp $");
 #endif
 
 #include <sys/types.h>
@@ -165,6 +165,13 @@ thunk_to_native_mapflags(int flags)
 		nflags |= MAP_SHARED;
 	if (flags & THUNK_MAP_PRIVATE)
 		nflags |= MAP_PRIVATE;
+#ifndef MAP_NOSYSCALLS
+#define MAP_NOSYSCALLS (1<<16)		/* XXX alias for now XXX */
+#endif
+#ifdef MAP_NOSYSCALLS
+	if (flags & THUNK_MAP_NOSYSCALLS)
+		nflags |= MAP_NOSYSCALLS;
+#endif
 
 	return nflags;
 }

Reply via email to