Subject: Re: ipc errors/Linux Emulation NetBSD-3BETA using Oracle
To: Chuck Silvers <chuq@chuq.com>
From: Jose Luis Rodriguez Garcia <jose.l.rodriguez@getronics.com>
List: current-users
Date: 11/02/2005 20:35:02
It fails with:

cc -ffreestanding -march=pentium3 -O2 -Werror -Wall -Wno-main -Wno-format-zero-length -Wpointer-arith -Wmissing-prototypes -Wstrict-prototypes -Wno-sign-compare -fno-zero-initialized-in-bss -Di386 -I. -I../../../../arch -I../../../.. -nostdinc -DSEM_DEBUG -DSHMDEBUG -DLKM -DMAXUSERS=32 -D_KERNEL -D_KERNEL_OPT -I../../../../dist/ipf -c ../../../../compat/linux/common/linux_ipc.c
../../../../compat/linux/common/linux_ipc.c: In function `linux_sys_shmctl':
../../../../compat/linux/common/linux_ipc.c:534: error: `shm_nused' undeclared (first use in this function)
../../../../compat/linux/common/linux_ipc.c:534: error: (Each undeclared identifier is reported only once
../../../../compat/linux/common/linux_ipc.c:534: error: for each function it appears in.)


Chuck Silvers wrote:

>On Wed, Nov 02, 2005 at 07:14:09PM +0100, Jose Luis Rodriguez Garcia wrote:
>  
>
>>It didn't work.
>>It appears that it calls linux_sys_shmctl
>>I have added the next line at the end of this funcition:
>>
>>printf("sys_shmctl: %d\n",SCARG(uap, cmd));
>>
>>It prints the next output:
>>sys_shmctl: 258
>>
>>Can it be: 258=256 +2, and LINUX_IPC_STAT=2?
>>    
>>
>
>yup, 0x100 is IPC_64, which is for running 32-bit binaries on 64-bit kernels.
>here's yet another patch (which doesn't so the 32-on-64 thing, but should
>work for 32-on-32).
>
>-Chuck
>  
>
>------------------------------------------------------------------------
>
>Index: src/sys/compat/linux/common/linux_ipc.c
>===================================================================
>RCS file: /cvsroot/src/sys/compat/linux/common/linux_ipc.c,v
>retrieving revision 1.31
>diff -u -p -r1.31 linux_ipc.c
>--- src/sys/compat/linux/common/linux_ipc.c	26 Feb 2005 23:10:19 -0000	1.31
>+++ src/sys/compat/linux/common/linux_ipc.c	2 Nov 2005 16:32:39 -0000
>@@ -469,11 +469,15 @@ linux_sys_shmctl(l, v, retval)
> 	struct sys___shmctl13_args nua;
> 	struct shmid_ds *bsp, bs;
> 	struct linux_shmid_ds ls;
>-	int error;
>+	struct linux_shminfo64 lsi64;
>+	struct linux_shm_info lsi;
>+	int error, i, cmd;
> 
> 	SCARG(&nua, shmid) = SCARG(uap, shmid);
>-	switch (SCARG(uap, cmd)) {
>+	cmd = SCARG(uap, cmd) & ~LINUX_IPC_64;
>+	switch (cmd) {
> 	case LINUX_IPC_STAT:
>+	case LINUX_SHM_STAT:
> 		sg = stackgap_init(p, 0);
> 		bsp = stackgap_alloc(p, &sg, sizeof(struct shmid_ds));
> 		SCARG(&nua, cmd) = IPC_STAT;
>@@ -483,7 +487,12 @@ linux_sys_shmctl(l, v, retval)
> 		if ((error = copyin(SCARG(&nua, buf), &bs, sizeof bs)))
> 			return error;
> 		bsd_to_linux_shmid_ds(&bs, &ls);
>+		if (cmd == LINUX_SHM_STAT) {
>+			retval[0] = IXSEQ_TO_IPCID(bs.shm_perm._key,
>+						   bs.shm_perm);
>+		}
> 		return copyout(&ls, SCARG(uap, buf), sizeof ls);
>+
> 	case LINUX_IPC_SET:
> 		if ((error = copyin(SCARG(uap, buf), &ls, sizeof ls)))
> 			return error;
>@@ -495,22 +504,47 @@ linux_sys_shmctl(l, v, retval)
> 		SCARG(&nua, cmd) = IPC_SET;
> 		SCARG(&nua, buf) = bsp;
> 		break;
>+
> 	case LINUX_IPC_RMID:
> 		SCARG(&nua, cmd) = IPC_RMID;
> 		SCARG(&nua, buf) = NULL;
> 		break;
>+
> 	case LINUX_SHM_LOCK:
> 		SCARG(&nua, cmd) = SHM_LOCK;
> 		SCARG(&nua, buf) = NULL;
> 		break;
>+
> 	case LINUX_SHM_UNLOCK:
> 		SCARG(&nua, cmd) = SHM_UNLOCK;
> 		SCARG(&nua, buf) = NULL;
> 		break;
>+
> 	case LINUX_IPC_INFO:
>-	case LINUX_SHM_STAT:
>+		memset(&lsi64, 0, sizeof lsi64);
>+		lsi64.l_shmmax = shminfo.shmmax;
>+		lsi64.l_shmmin = shminfo.shmmin;
>+		lsi64.l_shmmni = shminfo.shmmni;
>+		lsi64.l_shmseg = shminfo.shmseg;
>+		lsi64.l_shmall = shminfo.shmall;
>+		return copyout(&lsi64, SCARG(uap, buf), sizeof lsi64);
>+
> 	case LINUX_SHM_INFO:
>+		memset(&lsi, 0, sizeof lsi);
>+		lsi.l_used_ids = shm_nused;
>+		for (i = 0; i < shminfo.shmmni; i++) {
>+			if (shmsegs[i].shm_perm.mode & 0x800) {
>+				lsi.l_shm_tot += shmsegs[i].shm_segsz;
>+			}
>+		}
>+		lsi.l_shm_rss = 0;
>+		lsi.l_shm_swp = 0;
>+		lsi.l_swap_attempts = 0;
>+		lsi.l_swap_successes = 0;
>+		return copyout(&lsi, SCARG(uap, buf), sizeof lsi);
>+
> 	default:
>+		printf("linux_sys_shmctl cmd %d\n", SCARG(uap, cmd));
> 		return EINVAL;
> 	}
> 	return sys___shmctl13(l, &nua, retval);
>Index: src/sys/compat/linux/common/linux_ipc.h
>===================================================================
>RCS file: /cvsroot/src/sys/compat/linux/common/linux_ipc.h,v
>retrieving revision 1.6
>diff -u -p -r1.6 linux_ipc.h
>--- src/sys/compat/linux/common/linux_ipc.h	30 May 2001 11:37:27 -0000	1.6
>+++ src/sys/compat/linux/common/linux_ipc.h	2 Nov 2005 16:32:39 -0000
>@@ -72,6 +72,8 @@ struct linux_ipc_perm {
> #define LINUX_IPC_STAT	2
> #define LINUX_IPC_INFO	3
> 
>+#define LINUX_IPC_64	0x100
>+
> #if defined (SYSVSEM) || defined(SYSVSHM) || defined(SYSVMSG)
> #ifdef _KERNEL
> __BEGIN_DECLS
>Index: src/sys/compat/linux/common/linux_shm.h
>===================================================================
>RCS file: /cvsroot/src/sys/compat/linux/common/linux_shm.h,v
>retrieving revision 1.6
>diff -u -p -r1.6 linux_shm.h
>--- src/sys/compat/linux/common/linux_shm.h	28 Sep 2004 19:05:19 -0000	1.6
>+++ src/sys/compat/linux/common/linux_shm.h	2 Nov 2005 16:32:39 -0000
>@@ -58,6 +58,27 @@ struct linux_shmid_ds {
> 	void			*l_private3;
> };
> 
>+struct linux_shminfo64 {
>+	u_long			l_shmmax;
>+	u_long			l_shmmin;
>+	u_long			l_shmmni;
>+	u_long			l_shmseg;
>+	u_long			l_shmall;
>+	u_long			l___unused1;
>+	u_long			l___unused2;
>+	u_long			l___unused3;
>+	u_long			l___unused4;
>+};
>+
>+struct linux_shm_info {
>+	int			l_used_ids;
>+	u_long			l_shm_tot;
>+	u_long			l_shm_rss;
>+	u_long			l_shm_swp;
>+	u_long			l_swap_attempts;
>+	u_long			l_swap_successes;
>+};
>+
> #define LINUX_SHM_RDONLY	0x1000
> #define LINUX_SHM_RND		0x2000
> #define LINUX_SHM_REMAP		0x4000
>  
>