PERFORCE change 113146 for review

Jung-uk Kim jkim at FreeBSD.org
Thu Jan 18 22:58:54 UTC 2007


http://perforce.freebsd.org/chv.cgi?CH=113146

Change 113146 by jkim at jkim_hammer on 2007/01/18 22:58:37

	Clean up mmap and sync amd64 with i386.
	Now they are almost identical.

Affected files ...

.. //depot/projects/linuxolator/src/sys/amd64/linux32/linux.h#13 edit
.. //depot/projects/linuxolator/src/sys/amd64/linux32/linux32_machdep.c#25 edit
.. //depot/projects/linuxolator/src/sys/i386/linux/linux.h#11 edit
.. //depot/projects/linuxolator/src/sys/i386/linux/linux_machdep.c#18 edit

Differences ...

==== //depot/projects/linuxolator/src/sys/amd64/linux32/linux.h#13 (text+ko) ====

@@ -167,6 +167,15 @@
 #define	LINUX_MAP_ANON		0x0020
 #define	LINUX_MAP_GROWSDOWN	0x0100
 
+struct l_mmap_argv {
+	l_uintptr_t	addr;
+	l_size_t	len;
+	l_int		prot;
+	l_int		flags;
+	l_int		fd;
+	l_off_t		pgoff;
+} __packed;
+
 /*
  * stat family of syscalls
  */

==== //depot/projects/linuxolator/src/sys/amd64/linux32/linux32_machdep.c#25 (text+ko) ====

@@ -739,16 +739,6 @@
 	return (0);
 }
 
-/* XXX move */
-struct l_mmap_argv {
-	l_ulong		addr;
-	l_ulong		len;
-	l_ulong		prot;
-	l_ulong		flags;
-	l_ulong		fd;
-	l_ulong		pgoff;
-};
-
 #define STACK_SIZE  (2 * 1024 * 1024)
 #define GUARD_SIZE  (4 * PAGE_SIZE)
 
@@ -834,10 +824,13 @@
 		bsd_args.flags |= MAP_PRIVATE;
 	if (linux_args->flags & LINUX_MAP_FIXED)
 		bsd_args.flags |= MAP_FIXED;
-	if (linux_args->flags & LINUX_MAP_ANON)
+	if (linux_args->flags & LINUX_MAP_ANON) {
 		bsd_args.flags |= MAP_ANON;
-	else
+		bsd_args.fd = -1;
+	} else {
 		bsd_args.flags |= MAP_NOSYNC;
+		bsd_args.fd = linux_args->fd;
+	}
 	if (linux_args->flags & LINUX_MAP_GROWSDOWN) {
 		bsd_args.flags |= MAP_STACK;
 
@@ -863,11 +856,7 @@
 		 * fixed size of (STACK_SIZE - GUARD_SIZE).
 		 */
 
-		/* This gives us TOS */
-		bsd_args.addr = (caddr_t)PTRIN(linux_args->addr) +
-		    linux_args->len;
-
-		if ((caddr_t)PTRIN(bsd_args.addr) >
+		if ((caddr_t)PTRIN(linux_args->addr) + linux_args->len >
 		    p->p_vmspace->vm_maxsaddr) {
 			/* 
 			 * Some linux apps will attempt to mmap
@@ -905,7 +894,8 @@
 		 * not using VM_STACK we map the full stack, since we
 		 * don't have a way to autogrow it.
 		 */
-		bsd_args.addr -= bsd_args.len;
+		bsd_args.addr = (caddr_t)PTRIN(linux_args->addr) -
+		    bsd_args.len;
 	} else {
 		bsd_args.addr = (caddr_t)PTRIN(linux_args->addr);
 		bsd_args.len  = linux_args->len;
@@ -918,9 +908,7 @@
 	if (linux_args->prot & PROT_READ)
 		bsd_args.prot = linux_args->prot | PROT_EXEC;
 
-	if (linux_args->flags & LINUX_MAP_ANON)
-		bsd_args.fd = -1;
-	else {
+	if (bsd_args.fd != -1) {
 		/*
 		 * Linux follows Solaris mmap(2) description:
 		 * The file descriptor fildes is opened with
@@ -933,7 +921,7 @@
 		 * argument as described below.
 		 */
 
-		if ((error = fget(td, linux_args->fd, &fp)) != 0)
+		if ((error = fget(td, bsd_args.fd, &fp)) != 0)
 			return (error);
 		if (fp->f_type != DTYPE_VNODE) {
 			fdrop(fp, td);
@@ -946,7 +934,6 @@
 			return (EACCES);
 		}
 
-		bsd_args.fd = linux_args->fd;
 		fdrop(fp, td);
 	}
 	bsd_args.pos = (off_t)linux_args->pgoff * PAGE_SIZE;

==== //depot/projects/linuxolator/src/sys/i386/linux/linux.h#11 (text+ko) ====

@@ -142,6 +142,15 @@
 #define	LINUX_MAP_ANON		0x0020
 #define	LINUX_MAP_GROWSDOWN	0x0100
 
+struct l_mmap_argv {
+	l_uintptr_t	addr;
+	l_size_t	len;
+	l_int		prot;
+	l_int		flags;
+	l_int		fd;
+	l_off_t		pgoff;
+} __packed;
+
 /*
  * stat family of syscalls
  */

==== //depot/projects/linuxolator/src/sys/i386/linux/linux_machdep.c#18 (text+ko) ====

@@ -576,16 +576,6 @@
 	return (0);
 }
 
-/* XXX move */
-struct l_mmap_argv {
-	l_caddr_t	addr;
-	l_int		len;
-	l_int		prot;
-	l_int		flags;
-	l_int		fd;
-	l_int		pos;
-};
-
 #define STACK_SIZE  (2 * 1024 * 1024)
 #define GUARD_SIZE  (4 * PAGE_SIZE)
 
@@ -667,10 +657,13 @@
 		bsd_args.flags |= MAP_PRIVATE;
 	if (linux_args->flags & LINUX_MAP_FIXED)
 		bsd_args.flags |= MAP_FIXED;
-	if (linux_args->flags & LINUX_MAP_ANON)
+	if (linux_args->flags & LINUX_MAP_ANON) {
 		bsd_args.flags |= MAP_ANON;
-	else
+		bsd_args.fd = -1;
+	} else {
 		bsd_args.flags |= MAP_NOSYNC;
+		bsd_args.fd = linux_args->fd;
+	}
 	if (linux_args->flags & LINUX_MAP_GROWSDOWN) {
 		bsd_args.flags |= MAP_STACK;
 
@@ -696,10 +689,8 @@
 		 * fixed size of (STACK_SIZE - GUARD_SIZE).
 		 */
 
-		/* This gives us TOS */
-		bsd_args.addr = linux_args->addr + linux_args->len;
-
-		if (bsd_args.addr > p->p_vmspace->vm_maxsaddr) {
+		if ((caddr_t)PTRIN(linux_args->addr) + linux_args->len >
+		    p->p_vmspace->vm_maxsaddr) {
 			/* 
 			 * Some linux apps will attempt to mmap
 			 * thread stacks near the top of their
@@ -735,16 +726,15 @@
 		 * not using VM_STACK we map the full stack, since we
 		 * don't have a way to autogrow it.
 		 */
-		bsd_args.addr -= bsd_args.len;
+		bsd_args.addr = (caddr_t)PTRIN(linux_args->addr) -
+		    bsd_args.len;
 	} else {
-		bsd_args.addr = linux_args->addr;
+		bsd_args.addr = (caddr_t)PTRIN(linux_args->addr);
 		bsd_args.len  = linux_args->len;
 	}
 
 	bsd_args.prot = linux_args->prot;
-	if (linux_args->flags & LINUX_MAP_ANON)
-		bsd_args.fd = -1;
-	else {
+	if (bsd_args.fd != -1) {
 		/*
 		 * Linux follows Solaris mmap(2) description:
 		 * The file descriptor fildes is opened with
@@ -757,7 +747,7 @@
 		 * argument as described below.
 		 */
 
-		if ((error = fget(td, linux_args->fd, &fp)) != 0)
+		if ((error = fget(td, bsd_args.fd, &fp)) != 0)
 			return (error);
 		if (fp->f_type != DTYPE_VNODE) {
 			fdrop(fp, td);
@@ -770,7 +760,6 @@
 			return (EACCES);
 		}
 
-		bsd_args.fd = linux_args->fd;
 		fdrop(fp, td);
 	}
 	bsd_args.pos = linux_args->pos;


More information about the p4-projects mailing list