Subject: Re: A patch to linux emulation
To: Emmanuel Dreyfus <manu@netbsd.org>
From: Bang Jun-Young <bjy@mogua.org>
List: port-i386
Date: 08/27/2001 16:22:55
--2fHTh5uZTiUOsy+g
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

On Sun, Aug 26, 2001 at 11:20:32PM +0200, Emmanuel Dreyfus wrote:
> I have made a two fixes in PowerPC Linux emulation:
> - Linux's ldd now works
> - mmap() is now emulated using only machine independant support
> 
> Everything is fine on the PowerPC, but I'd like to be sure that this
> patch does not break alpha and i386 (if i386 is okay, m68k should be
> okay). So if someone can try this and tell me so that I can commit my
> fix...

It wasn't even compiled on i386:

cc  -O2 -Werror -Wall -Wmissing-prototypes -Wstrict-prototypes  -Wpointer-arith -Wno-uninitialized -Wno-main -I. -I../../../../arch -I../../../.. -nostdinc -DLKM -DMAXUSERS=32 -D_KERNEL -D_KERNEL_OPT -Di386  -c ../../../../compat/linux/common/linux_misc.c
../../../../compat/linux/common/linux_misc.c: In function `linux_sys_mmap':
../../../../compat/linux/common/linux_misc.c:400: dereferencing pointer to incomplete type
../../../../compat/linux/common/linux_misc.c:401: dereferencing pointer to incomplete type
../../../../compat/linux/common/linux_misc.c:402: dereferencing pointer to incomplete type
../../../../compat/linux/common/linux_misc.c:403: dereferencing pointer to incomplete type
../../../../compat/linux/common/linux_misc.c:406: dereferencing pointer to incomplete type
../../../../compat/linux/common/linux_misc.c:407: dereferencing pointer to incomplete type
../../../../compat/linux/common/linux_misc.c:408: dereferencing pointer to incomplete type
../../../../compat/linux/common/linux_misc.c:412: dereferencing pointer to incomplete type
../../../../compat/linux/common/linux_misc.c:414: dereferencing pointer to incomplete type
*** Error code 1

I have found that you removed declaration of struct linux_sys_mmap_args
in common/linux_mmap.h by mistake. ;-) I'm attaching my patch fixing 
that at the end of this mail. With the patch, Netscape and Source 
Navigator seemed to run fine. I haven't tested them fully enough, so
more tests (with other apps) would be needed. 

Jun-Young

-- 
Bang Jun-Young <bjy@mogua.org>


--2fHTh5uZTiUOsy+g
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="compat_linux.patch"

? arch/powerpc/linux_clone.c
Index: arch/alpha/linux_syscall.h
===================================================================
RCS file: /cvsroot/syssrc/sys/compat/linux/arch/alpha/linux_syscall.h,v
retrieving revision 1.39
diff -U4 -r1.39 linux_syscall.h
--- arch/alpha/linux_syscall.h	2001/07/04 10:26:28	1.39
+++ arch/alpha/linux_syscall.h	2001/08/25 15:16:52
@@ -1,5 +1,5 @@
-/* $NetBSD: linux_syscall.h,v 1.39 2001/07/04 10:26:28 jdolecek Exp $ */
+/* $NetBSD$ */
 
 /*
  * System call numbers.
  *
@@ -132,9 +132,9 @@
 
 /* syscall: "lstat" ret: "int" args: "const char *" "struct linux_stat *" */
 #define	LINUX_SYS_lstat	68
 
-/* syscall: "mmap" ret: "int" args: "unsigned long" "size_t" "int" "int" "int" "off_t" */
+/* syscall: "mmap" ret: "int" args: "unsigned long" "size_t" "int" "int" "int" "linux_off_t" */
 #define	LINUX_SYS_mmap	71
 
 /* syscall: "munmap" ret: "int" args: "void *" "size_t" */
 #define	LINUX_SYS_munmap	73
Index: arch/alpha/linux_syscallargs.h
===================================================================
RCS file: /cvsroot/syssrc/sys/compat/linux/arch/alpha/linux_syscallargs.h,v
retrieving revision 1.39
diff -U4 -r1.39 linux_syscallargs.h
--- arch/alpha/linux_syscallargs.h	2001/07/04 10:26:28	1.39
+++ arch/alpha/linux_syscallargs.h	2001/08/25 15:16:53
@@ -1,5 +1,5 @@
-/* $NetBSD: linux_syscallargs.h,v 1.39 2001/07/04 10:26:28 jdolecek Exp $ */
+/* $NetBSD$ */
 
 /*
  * System call argument lists.
  *
Index: arch/alpha/linux_syscalls.c
===================================================================
RCS file: /cvsroot/syssrc/sys/compat/linux/arch/alpha/linux_syscalls.c,v
retrieving revision 1.40
diff -U4 -r1.40 linux_syscalls.c
--- arch/alpha/linux_syscalls.c	2001/07/04 10:26:28	1.40
+++ arch/alpha/linux_syscalls.c	2001/08/25 15:16:57
@@ -1,5 +1,5 @@
-/* $NetBSD: linux_syscalls.c,v 1.40 2001/07/04 10:26:28 jdolecek Exp $ */
+/* $NetBSD$ */
 
 /*
  * System call names.
  *
Index: arch/alpha/linux_sysent.c
===================================================================
RCS file: /cvsroot/syssrc/sys/compat/linux/arch/alpha/linux_sysent.c,v
retrieving revision 1.40
diff -U4 -r1.40 linux_sysent.c
--- arch/alpha/linux_sysent.c	2001/07/04 10:26:29	1.40
+++ arch/alpha/linux_sysent.c	2001/08/25 15:17:00
@@ -1,5 +1,5 @@
-/* $NetBSD: linux_sysent.c,v 1.40 2001/07/04 10:26:29 jdolecek Exp $ */
+/* $NetBSD$ */
 
 /*
  * System call switch table.
  *
Index: arch/alpha/syscalls.master
===================================================================
RCS file: /cvsroot/syssrc/sys/compat/linux/arch/alpha/syscalls.master,v
retrieving revision 1.35
diff -U4 -r1.35 syscalls.master
--- arch/alpha/syscalls.master	2001/07/04 10:25:32	1.35
+++ arch/alpha/syscalls.master	2001/08/25 15:17:01
@@ -172,9 +172,9 @@
 69	UNIMPL 
 70	UNIMPL
 ;71	ALIAS		osf1_sys_mmap
 71	NOARGS		{ int linux_sys_mmap(unsigned long addr, size_t len, \
-			    int prot, int flags, int fd, off_t offset); }
+			    int prot, int flags, int fd, linux_off_t offset); }
 72	UNIMPL
 73	NOARGS		{ int sys_munmap(void *addr, size_t len); }
 74	NOARGS		{ int sys_mprotect(void *addr, size_t len, int prot); }
 ; Liunx sys_madvise just returns 0.
Index: arch/powerpc/files.linux_powerpc
===================================================================
RCS file: /cvsroot/syssrc/sys/compat/linux/arch/powerpc/files.linux_powerpc,v
retrieving revision 1.1
diff -U4 -r1.1 files.linux_powerpc
--- arch/powerpc/files.linux_powerpc	2001/01/19 01:51:16	1.1
+++ arch/powerpc/files.linux_powerpc	2001/08/25 15:17:02
@@ -7,9 +7,8 @@
 file	compat/linux/arch/powerpc/linux_syscalls.c			compat_linux
 file	compat/linux/arch/powerpc/linux_sysent.c				compat_linux
 file	compat/linux/arch/powerpc/linux_sigarray.c			compat_linux
 file	compat/linux/arch/powerpc/linux_exec_powerpc.c		compat_linux
-file	compat/linux/arch/powerpc/linux_mmap_powerpc.c		compat_linux
 file	compat/linux/arch/powerpc/linux_sp_wrap_powerpc.S	compat_linux
 
 file	compat/linux/common/linux_pipe.c		   	compat_linux
 file	compat/linux/common/linux_ipccall.c			compat_linux
Index: arch/powerpc/linux_exec.h
===================================================================
RCS file: /cvsroot/syssrc/sys/compat/linux/arch/powerpc/linux_exec.h,v
retrieving revision 1.3
diff -U4 -r1.3 linux_exec.h
--- arch/powerpc/linux_exec.h	2001/07/26 22:53:14	1.3
+++ arch/powerpc/linux_exec.h	2001/08/25 15:17:02
@@ -63,8 +63,9 @@
 /*
  * Linux Elf32 format parameters
  */
 
+#define LINUX_GCC_SIGNATURE 1
 /*
  * LINUX_ATEXIT_SIGNATURE enable the atexit_signature test. See 
  * sys/compat/linux/common/linux_exec_elf32.c:linux_atexit_signature()
  */
Index: arch/powerpc/linux_machdep.c
===================================================================
RCS file: /cvsroot/syssrc/sys/compat/linux/arch/powerpc/linux_machdep.c,v
retrieving revision 1.11
diff -U4 -r1.11 linux_machdep.c
--- arch/powerpc/linux_machdep.c	2001/06/13 23:09:01	1.11
+++ arch/powerpc/linux_machdep.c	2001/08/25 15:17:03
@@ -77,8 +77,9 @@
 #include <machine/psl.h>
 #include <machine/reg.h>
 #include <machine/vmparam.h>
 
+#undef DEBUG_LINUX
 /*
  * To see whether wscons is configured (for virtual console ioctl calls).
  */
 #if defined(_KERNEL_OPT)
Index: arch/powerpc/linux_mmap.h
===================================================================
RCS file: /cvsroot/syssrc/sys/compat/linux/arch/powerpc/linux_mmap.h,v
retrieving revision 1.2
diff -U4 -r1.2 linux_mmap.h
--- arch/powerpc/linux_mmap.h	2001/01/19 01:31:25	1.2
+++ arch/powerpc/linux_mmap.h	2001/08/25 15:17:03
@@ -55,21 +55,5 @@
 #define LINUX_MAP_GROWSDOWN	0x0100
 #define LINUX_MAP_DENYWRITE	0x0800
 #define	LINUX_MAP_EXECUTABLE	0x1000
 
-/* 
- * On the PowerPC, we have a problem with the offset argument. It's 32 bit
- * long on Linux and 64 bit long on NetBSD. Therefore we use a wrapper
- * function linux_sys_powerpc_mmap() to linux_sys_mmap()
- * 
- * Linux's off_t is __kernel_off_t (include/linux/types.h) which in turn
- * is a long (include/asm-ppc/posix_types.h)
- */
-#define linux_off_t long
-
-#ifdef _KERNEL
-__BEGIN_DECLS 
-int linux_sys_powerpc_mmap(struct proc *, void *, register_t *);
-__END_DECLS
-#endif /* !_KERNEL */ 
-
 #endif /* !_POWERPC_LINUX_MMAP_H */
Index: arch/powerpc/linux_syscall.h
===================================================================
RCS file: /cvsroot/syssrc/sys/compat/linux/arch/powerpc/linux_syscall.h,v
retrieving revision 1.9
diff -U4 -r1.9 linux_syscall.h
--- arch/powerpc/linux_syscall.h	2001/05/30 11:37:27	1.9
+++ arch/powerpc/linux_syscall.h	2001/08/25 15:17:04
@@ -1,11 +1,11 @@
-/* $NetBSD: linux_syscall.h,v 1.9 2001/05/30 11:37:27 mrg Exp $ */
+/* $NetBSD$ */
 
 /*
  * System call numbers.
  *
  * DO NOT EDIT-- this file is automatically generated.
- * created from	NetBSD: syscalls.master,v 1.5 2001/05/13 20:54:45 manu Exp   
+ * created from	NetBSD: syscalls.master,v 1.6 2001/05/30 11:37:27 mrg Exp   
  */
 
 /* syscall: "syscall" ret: "int" args: */
 #define	LINUX_SYS_syscall	0
@@ -245,10 +245,10 @@
 
 /* syscall: "readdir" ret: "int" args: "int" "caddr_t" "unsigned int" */
 #define	LINUX_SYS_readdir	89
 
-/* syscall: "powerpc_mmap" ret: "int" args: "unsigned long" "size_t" "int" "int" "int" "linux_off_t" */
-#define	LINUX_SYS_powerpc_mmap	90
+/* syscall: "mmap" ret: "int" args: "unsigned long" "size_t" "int" "int" "int" "linux_off_t" */
+#define	LINUX_SYS_mmap	90
 
 /* syscall: "munmap" ret: "int" args: "caddr_t" "int" */
 #define	LINUX_SYS_munmap	91
 
Index: arch/powerpc/linux_syscallargs.h
===================================================================
RCS file: /cvsroot/syssrc/sys/compat/linux/arch/powerpc/linux_syscallargs.h,v
retrieving revision 1.9
diff -U4 -r1.9 linux_syscallargs.h
--- arch/powerpc/linux_syscallargs.h	2001/05/30 11:37:27	1.9
+++ arch/powerpc/linux_syscallargs.h	2001/08/25 15:17:06
@@ -1,11 +1,11 @@
-/* $NetBSD: linux_syscallargs.h,v 1.9 2001/05/30 11:37:27 mrg Exp $ */
+/* $NetBSD$ */
 
 /*
  * System call argument lists.
  *
  * DO NOT EDIT-- this file is automatically generated.
- * created from	NetBSD: syscalls.master,v 1.5 2001/05/13 20:54:45 manu Exp   
+ * created from	NetBSD: syscalls.master,v 1.6 2001/05/30 11:37:27 mrg Exp   
  */
 
 #ifndef _LINUX_SYS__SYSCALLARGS_H_
 #define	_LINUX_SYS__SYSCALLARGS_H_
@@ -233,9 +233,9 @@
 	syscallarg(caddr_t) dent;
 	syscallarg(unsigned int) count;
 };
 
-struct linux_sys_powerpc_mmap_args {
+struct linux_sys_mmap_args {
 	syscallarg(unsigned long) addr;
 	syscallarg(size_t) len;
 	syscallarg(int) prot;
 	syscallarg(int) flags;
@@ -580,9 +580,9 @@
 int	linux_sys_uselib(struct proc *, void *, register_t *);
 int	linux_sys_swapon(struct proc *, void *, register_t *);
 int	linux_sys_reboot(struct proc *, void *, register_t *);
 int	linux_sys_readdir(struct proc *, void *, register_t *);
-int	linux_sys_powerpc_mmap(struct proc *, void *, register_t *);
+int	linux_sys_mmap(struct proc *, void *, register_t *);
 int	sys_munmap(struct proc *, void *, register_t *);
 int	linux_sys_truncate(struct proc *, void *, register_t *);
 int	compat_43_sys_ftruncate(struct proc *, void *, register_t *);
 int	sys_fchmod(struct proc *, void *, register_t *);
Index: arch/powerpc/linux_syscalls.c
===================================================================
RCS file: /cvsroot/syssrc/sys/compat/linux/arch/powerpc/linux_syscalls.c,v
retrieving revision 1.9
diff -U4 -r1.9 linux_syscalls.c
--- arch/powerpc/linux_syscalls.c	2001/05/30 11:37:27	1.9
+++ arch/powerpc/linux_syscalls.c	2001/08/25 15:17:06
@@ -1,11 +1,11 @@
-/* $NetBSD: linux_syscalls.c,v 1.9 2001/05/30 11:37:27 mrg Exp $ */
+/* $NetBSD$ */
 
 /*
  * System call names.
  *
  * DO NOT EDIT-- this file is automatically generated.
- * created from	NetBSD: syscalls.master,v 1.5 2001/05/13 20:54:45 manu Exp   
+ * created from	NetBSD: syscalls.master,v 1.6 2001/05/30 11:37:27 mrg Exp   
  */
 
 #if defined(_KERNEL_OPT)
 #if defined(_KERNEL_OPT)
@@ -116,9 +116,9 @@
 	"uselib",			/* 86 = uselib */
 	"swapon",			/* 87 = swapon */
 	"reboot",			/* 88 = reboot */
 	"readdir",			/* 89 = readdir */
-	"powerpc_mmap",			/* 90 = powerpc_mmap */
+	"mmap",			/* 90 = mmap */
 	"munmap",			/* 91 = munmap */
 	"truncate",			/* 92 = truncate */
 	"ftruncate",			/* 93 = ftruncate */
 	"fchmod",			/* 94 = fchmod */
Index: arch/powerpc/linux_sysent.c
===================================================================
RCS file: /cvsroot/syssrc/sys/compat/linux/arch/powerpc/linux_sysent.c,v
retrieving revision 1.9
diff -U4 -r1.9 linux_sysent.c
--- arch/powerpc/linux_sysent.c	2001/05/30 11:37:27	1.9
+++ arch/powerpc/linux_sysent.c	2001/08/25 15:17:08
@@ -1,11 +1,11 @@
-/* $NetBSD: linux_sysent.c,v 1.9 2001/05/30 11:37:27 mrg Exp $ */
+/* $NetBSD$ */
 
 /*
  * System call switch table.
  *
  * DO NOT EDIT-- this file is automatically generated.
- * created from	NetBSD: syscalls.master,v 1.5 2001/05/13 20:54:45 manu Exp   
+ * created from	NetBSD: syscalls.master,v 1.6 2001/05/30 11:37:27 mrg Exp   
  */
 
 #if defined(_KERNEL_OPT)
 #include "opt_compat_netbsd.h"
@@ -206,10 +206,10 @@
 	{ 4, s(struct linux_sys_reboot_args), 0,
 	    linux_sys_reboot },			/* 88 = reboot */
 	{ 3, s(struct linux_sys_readdir_args), 0,
 	    linux_sys_readdir },		/* 89 = readdir */
-	{ 6, s(struct linux_sys_powerpc_mmap_args), 0,
-	    linux_sys_powerpc_mmap },		/* 90 = powerpc_mmap */
+	{ 6, s(struct linux_sys_mmap_args), 0,
+	    linux_sys_mmap },			/* 90 = mmap */
 	{ 2, s(struct sys_munmap_args), 0,
 	    sys_munmap },			/* 91 = munmap */
 	{ 2, s(struct linux_sys_truncate_args), 0,
 	    linux_sys_truncate },		/* 92 = truncate */
Index: arch/powerpc/syscalls.master
===================================================================
RCS file: /cvsroot/syssrc/sys/compat/linux/arch/powerpc/syscalls.master,v
retrieving revision 1.6
diff -U4 -r1.6 syscalls.master
--- arch/powerpc/syscalls.master	2001/05/30 11:37:27	1.6
+++ arch/powerpc/syscalls.master	2001/08/25 15:17:09
@@ -197,9 +197,9 @@
 88	STD		{ int linux_sys_reboot(int magic1, int magic2, \
 			    int cmd, void *arg); }
 89	STD		{ int linux_sys_readdir(int fd, caddr_t dent, \
 			    unsigned int count); }
-90	 STD      { int linux_sys_powerpc_mmap(unsigned long addr, size_t len, \
+90	 STD      { int linux_sys_mmap(unsigned long addr, size_t len, \
              int prot, int flags, int fd, linux_off_t offset); }
 91	NOARGS		{ int sys_munmap(caddr_t addr, int len); }
 92	STD		{ int linux_sys_truncate(const char *path, \
 			    long length); }
Index: common/linux_exec_elf32.c
===================================================================
RCS file: /cvsroot/syssrc/sys/compat/linux/common/linux_exec_elf32.c,v
retrieving revision 1.52
diff -U4 -r1.52 linux_exec_elf32.c
--- common/linux_exec_elf32.c	2001/07/14 02:05:06	1.52
+++ common/linux_exec_elf32.c	2001/08/25 15:17:10
@@ -305,22 +305,17 @@
 	const char *bp;
 	int error;
 	size_t len;
 
+	if (((error = ELFNAME2(linux,signature)(p, epp, eh, itp)) != 0) &&
 #ifdef LINUX_GCC_SIGNATURE
-	if ((error = ELFNAME2(linux,signature)(p, epp, eh, itp)) != 0)
-		if ((error = ELFNAME2(linux,gcc_signature)(p, epp, eh)) != 0)
-			return error;
-#else
-#ifdef LINUX_ATEXIT_SIGNATURE
-	if ((error = ELFNAME2(linux,signature)(p, epp, eh, itp)) != 0)
-		if ((error = ELFNAME2(linux,atexit_signature)(p, epp, eh)) != 0)
-			return error;
-#else
-	if ((error = ELFNAME2(linux,signature)(p, epp, eh, itp)) != 0)
-		return error;
+	    ((error = ELFNAME2(linux,gcc_signature)(p, epp, eh)) != 0) &&
 #endif
+#ifdef LINUX_ATEXIT_SIGNATURE
+	    ((error = ELFNAME2(linux,atexit_signature)(p, epp, eh)) != 0) &&
 #endif
+	    1) 
+			return error;
 
 	if (itp[0]) {
 		if ((error = emul_find(p, NULL, epp->ep_esch->es_emul->e_path,
 		    itp, &bp, 0)))
Index: common/linux_misc.c
===================================================================
RCS file: /cvsroot/syssrc/sys/compat/linux/common/linux_misc.c,v
retrieving revision 1.93
diff -U4 -r1.93 linux_misc.c
--- common/linux_misc.c	2001/07/18 19:11:14	1.93
+++ common/linux_misc.c	2001/08/25 15:17:12
@@ -390,9 +390,9 @@
 		syscallarg(size_t) len;
 		syscallarg(int) prot;
 		syscallarg(int) flags;
 		syscallarg(int) fd;
-		syscallarg(off_t) offset;
+		syscallarg(linux_off_t) offset;
 	} */ *uap = v;
 	struct sys_mmap_args cma;
 	int flags;
 	
@@ -410,9 +410,9 @@
 		SCARG(&cma,prot) |= VM_PROT_READ;
 	SCARG(&cma,flags) = flags;
 	SCARG(&cma,fd) = flags & MAP_ANON ? -1 : SCARG(uap, fd);
 	SCARG(&cma,pad) = 0;
-	SCARG(&cma,pos) = SCARG(uap, offset);
+	SCARG(&cma,pos) = (off_t)SCARG(uap, offset);
 
 	return sys_mmap(p, &cma, retval);
 }
 
Index: common/linux_mmap.h
===================================================================
RCS file: /cvsroot/syssrc/sys/compat/linux/common/linux_mmap.h,v
retrieving revision 1.8
diff -U4 -r1.8 linux_mmap.h
--- common/linux_mmap.h	2001/01/19 12:35:47	1.8
+++ common/linux_mmap.h	2001/08/27 15:51:01
@@ -82,7 +82,7 @@
 	syscallarg(int) prot;
 	syscallarg(int) flags;
 	syscallarg(int) fd;
-	syscallarg(off_t) offset;
+	syscallarg(linux_off_t) offset;
 };
 
 #ifdef _KERNEL

--2fHTh5uZTiUOsy+g--