Home | History | Annotate | Line # | Download | only in common
linux_ipc.c revision 1.50.2.2
      1 /*	$NetBSD: linux_ipc.c,v 1.50.2.2 2008/05/14 01:35:05 wrstuden Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1995, 1998 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Frank van der Linden and Eric Haszlakiewicz.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  * POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 #include <sys/cdefs.h>
     33 __KERNEL_RCSID(0, "$NetBSD: linux_ipc.c,v 1.50.2.2 2008/05/14 01:35:05 wrstuden Exp $");
     34 
     35 #if defined(_KERNEL_OPT)
     36 #include "opt_sysv.h"
     37 #endif
     38 
     39 #include <sys/param.h>
     40 #include <sys/shm.h>
     41 #include <sys/sem.h>
     42 #include <sys/msg.h>
     43 #include <sys/proc.h>
     44 #include <sys/systm.h>
     45 #include <sys/vnode.h>
     46 
     47 #include <sys/mount.h>
     48 #include <sys/syscallargs.h>
     49 
     50 #include <compat/linux/common/linux_types.h>
     51 #include <compat/linux/common/linux_signal.h>
     52 #include <compat/linux/common/linux_util.h>
     53 #include <compat/linux/common/linux_ipc.h>
     54 #include <compat/linux/common/linux_msg.h>
     55 #include <compat/linux/common/linux_shm.h>
     56 #include <compat/linux/common/linux_sem.h>
     57 
     58 #include <compat/linux/linux_syscallargs.h>
     59 #include <compat/linux/linux_syscall.h>
     60 
     61 #include <compat/linux/common/linux_ipccall.h>
     62 #include <compat/linux/common/linux_machdep.h>
     63 
     64 /*
     65  * Note: Not all linux architechtures have explicit versions
     66  *	of the SYSV* syscalls.  On the ones that don't
     67  *	we pretend that they are defined anyway.  *_args and
     68  *	prototypes are defined in individual headers;
     69  *	syscalls.master lists those syscalls as NOARGS.
     70  *
     71  *	The functions in multiarch are the ones that just need
     72  *	the arguments shuffled around and then use the
     73  *	normal NetBSD syscall.
     74  *
     75  * Function in multiarch:
     76  *	linux_sys_ipc		: linux_ipccall.c
     77  *	liunx_semop		: linux_ipccall.c
     78  *	linux_semget		: linux_ipccall.c
     79  *	linux_msgsnd		: linux_ipccall.c
     80  *	linux_msgrcv		: linux_ipccall.c
     81  *	linux_msgget		: linux_ipccall.c
     82  *	linux_shmdt		: linux_ipccall.c
     83  *	linux_shmget		: linux_ipccall.c
     84  */
     85 
     86 #if defined (SYSVSEM) || defined(SYSVSHM) || defined(SYSVMSG)
     87 /*
     88  * Convert between Linux and NetBSD ipc_perm structures. Only the
     89  * order of the fields is different.
     90  */
     91 void
     92 linux_to_bsd_ipc_perm(struct linux_ipc_perm *lpp, struct ipc_perm *bpp)
     93 {
     94 
     95 	bpp->_key = lpp->l_key;
     96 	bpp->uid = lpp->l_uid;
     97 	bpp->gid = lpp->l_gid;
     98 	bpp->cuid = lpp->l_cuid;
     99 	bpp->cgid = lpp->l_cgid;
    100 	bpp->mode = lpp->l_mode;
    101 	bpp->_seq = lpp->l_seq;
    102 }
    103 
    104 void
    105 linux_to_bsd_ipc64_perm(struct linux_ipc64_perm *lpp, struct ipc_perm *bpp)
    106 {
    107 	bpp->_key = lpp->l_key;
    108 	bpp->uid = lpp->l_uid;
    109 	bpp->gid = lpp->l_gid;
    110 	bpp->cuid = lpp->l_cuid;
    111 	bpp->cgid = lpp->l_cgid;
    112 	bpp->mode = lpp->l_mode;
    113 	bpp->_seq = lpp->l_seq;
    114 }
    115 
    116 void
    117 bsd_to_linux_ipc_perm(struct ipc_perm *bpp, struct linux_ipc_perm *lpp)
    118 {
    119 
    120 	lpp->l_key = bpp->_key;
    121 	lpp->l_uid = bpp->uid;
    122 	lpp->l_gid = bpp->gid;
    123 	lpp->l_cuid = bpp->cuid;
    124 	lpp->l_cgid = bpp->cgid;
    125 	lpp->l_mode = bpp->mode;
    126 	lpp->l_seq = bpp->_seq;
    127 }
    128 
    129 void
    130 bsd_to_linux_ipc64_perm(struct ipc_perm *bpp, struct linux_ipc64_perm *lpp)
    131 {
    132 	lpp->l_key = bpp->_key;
    133 	lpp->l_uid = bpp->uid;
    134 	lpp->l_gid = bpp->gid;
    135 	lpp->l_cuid = bpp->cuid;
    136 	lpp->l_cgid = bpp->cgid;
    137 	lpp->l_mode = bpp->mode;
    138 	lpp->l_seq = bpp->_seq;
    139 }
    140 
    141 #endif
    142 
    143 #ifdef SYSVSEM
    144 /*
    145  * Semaphore operations. Most constants and structures are the same on
    146  * both systems. Only semctl() needs some extra work.
    147  */
    148 
    149 /*
    150  * Convert between Linux and NetBSD semid_ds structures.
    151  */
    152 void
    153 bsd_to_linux_semid_ds(struct semid_ds *bs, struct linux_semid_ds *ls)
    154 {
    155 	bsd_to_linux_ipc_perm(&bs->sem_perm, &ls->l_sem_perm);
    156 	ls->l_sem_otime = bs->sem_otime;
    157 	ls->l_sem_ctime = bs->sem_ctime;
    158 	ls->l_sem_nsems = bs->sem_nsems;
    159 	ls->l_sem_base = bs->_sem_base;
    160 }
    161 
    162 void
    163 bsd_to_linux_semid64_ds(struct semid_ds *bs, struct linux_semid64_ds *ls)
    164 {
    165 	bsd_to_linux_ipc64_perm(&bs->sem_perm, &ls->l_sem_perm);
    166 	ls->l_sem_otime = bs->sem_otime;
    167 	ls->l_sem_ctime = bs->sem_ctime;
    168 	ls->l_sem_nsems = bs->sem_nsems;
    169 }
    170 
    171 void
    172 linux_to_bsd_semid_ds(struct linux_semid_ds *ls, struct semid_ds *bs)
    173 {
    174 	linux_to_bsd_ipc_perm(&ls->l_sem_perm, &bs->sem_perm);
    175 	bs->sem_otime = ls->l_sem_otime;
    176 	bs->sem_ctime = ls->l_sem_ctime;
    177 	bs->sem_nsems = ls->l_sem_nsems;
    178 	bs->_sem_base = ls->l_sem_base;
    179 }
    180 
    181 void
    182 linux_to_bsd_semid64_ds(struct linux_semid64_ds *ls, struct semid_ds *bs)
    183 {
    184 	linux_to_bsd_ipc64_perm(&ls->l_sem_perm, &bs->sem_perm);
    185 	bs->sem_otime = ls->l_sem_otime;
    186 	bs->sem_ctime = ls->l_sem_ctime;
    187 	bs->sem_nsems = ls->l_sem_nsems;
    188 }
    189 
    190 /*
    191  * Most of this can be handled by directly passing the arguments on; we
    192  * just need to frob the `cmd' and convert the semid_ds and semun.
    193  */
    194 int
    195 linux_sys_semctl(struct lwp *l, const struct linux_sys_semctl_args *uap, register_t *retval)
    196 {
    197 	/* {
    198 		syscallarg(int) semid;
    199 		syscallarg(int) semnum;
    200 		syscallarg(int) cmd;
    201 		syscallarg(union linux_semun) arg;
    202 	} */
    203 	struct semid_ds sembuf;
    204 	struct linux_semid_ds lsembuf;
    205 	struct linux_semid64_ds lsembuf64;
    206 	union __semun semun;
    207 	int cmd, lcmd, error;
    208 	void *pass_arg = NULL;
    209 
    210 	lcmd = SCARG(uap, cmd);
    211 #ifdef LINUX_IPC_FORCE64
    212 	if (lcmd == LINUX_IPC_STAT || lcmd == LINUX_IPC_SET)
    213 		lcmd |= LINUX_IPC_64;
    214 #endif
    215 
    216 	switch (lcmd) {
    217 	case LINUX_IPC_SET:
    218 		error = copyin(SCARG(uap, arg).l_buf, &lsembuf,
    219 		    sizeof(lsembuf));
    220 		if (error)
    221 			return (error);
    222 		linux_to_bsd_semid_ds(&lsembuf, &sembuf);
    223 		pass_arg = &sembuf;
    224 		cmd = IPC_SET;
    225 		break;
    226 
    227 	case LINUX_IPC_SET | LINUX_IPC_64:
    228 		error = copyin(SCARG(uap, arg).l_buf, &lsembuf64,
    229 		    sizeof(lsembuf64));
    230 		if (error)
    231 			return (error);
    232 		linux_to_bsd_semid64_ds(&lsembuf64, &sembuf);
    233 		pass_arg = &sembuf;
    234 		cmd = IPC_SET;
    235 		break;
    236 
    237 	case LINUX_IPC_STAT:
    238 	case LINUX_IPC_STAT | LINUX_IPC_64:
    239 		pass_arg = &sembuf;
    240 		cmd = IPC_STAT;
    241 		break;
    242 
    243 	case LINUX_IPC_RMID:
    244 		cmd = IPC_RMID;
    245 		break;
    246 
    247 	case LINUX_GETVAL:
    248 		cmd = GETVAL;
    249 		break;
    250 
    251 	case LINUX_GETPID:
    252 		cmd = GETPID;
    253 		break;
    254 
    255 	case LINUX_GETNCNT:
    256 		cmd = GETNCNT;
    257 		break;
    258 
    259 	case LINUX_GETZCNT:
    260 		cmd = GETZCNT;
    261 		break;
    262 
    263 	case LINUX_GETALL:
    264 		pass_arg = &semun;
    265 		semun.array = SCARG(uap, arg).l_array;
    266 		cmd = GETALL;
    267 		break;
    268 
    269 	case LINUX_SETVAL:
    270 		pass_arg = &semun;
    271 		semun.val = SCARG(uap, arg).l_val;
    272 		cmd = SETVAL;
    273 		break;
    274 
    275 	case LINUX_SETALL:
    276 		pass_arg = &semun;
    277 		semun.array = SCARG(uap, arg).l_array;
    278 		cmd = SETALL;
    279 		break;
    280 
    281 	default:
    282 		return (EINVAL);
    283 	}
    284 
    285 	error = semctl1(l, SCARG(uap, semid), SCARG(uap, semnum), cmd,
    286 	    pass_arg, retval);
    287 	if (error)
    288 		return error;
    289 
    290 	switch (lcmd) {
    291 	case LINUX_IPC_STAT:
    292 		bsd_to_linux_semid_ds(&sembuf, &lsembuf);
    293 		error = copyout(&lsembuf, SCARG(uap, arg).l_buf,
    294 		    sizeof(lsembuf));
    295 		break;
    296 	case LINUX_IPC_STAT | LINUX_IPC_64:
    297 		bsd_to_linux_semid64_ds(&sembuf, &lsembuf64);
    298 		error = copyout(&lsembuf64, SCARG(uap, arg).l_buf,
    299 		    sizeof(lsembuf64));
    300 		break;
    301 	default:
    302 		break;
    303 	}
    304 
    305 	return (error);
    306 }
    307 #endif /* SYSVSEM */
    308 
    309 #ifdef SYSVMSG
    310 
    311 void
    312 linux_to_bsd_msqid_ds(struct linux_msqid_ds *lmp, struct msqid_ds *bmp)
    313 {
    314 
    315 	linux_to_bsd_ipc_perm(&lmp->l_msg_perm, &bmp->msg_perm);
    316 	bmp->_msg_first = lmp->l_msg_first;
    317 	bmp->_msg_last = lmp->l_msg_last;
    318 	bmp->_msg_cbytes = lmp->l_msg_cbytes;
    319 	bmp->msg_qnum = lmp->l_msg_qnum;
    320 	bmp->msg_qbytes = lmp->l_msg_qbytes;
    321 	bmp->msg_lspid = lmp->l_msg_lspid;
    322 	bmp->msg_lrpid = lmp->l_msg_lrpid;
    323 	bmp->msg_stime = lmp->l_msg_stime;
    324 	bmp->msg_rtime = lmp->l_msg_rtime;
    325 	bmp->msg_ctime = lmp->l_msg_ctime;
    326 }
    327 
    328 void
    329 bsd_to_linux_msqid_ds(struct msqid_ds *bmp, struct linux_msqid_ds *lmp)
    330 {
    331 
    332 	bsd_to_linux_ipc_perm(&bmp->msg_perm, &lmp->l_msg_perm);
    333 	lmp->l_msg_first = bmp->_msg_first;
    334 	lmp->l_msg_last = bmp->_msg_last;
    335 	lmp->l_msg_cbytes = bmp->_msg_cbytes;
    336 	lmp->l_msg_qnum = bmp->msg_qnum;
    337 	lmp->l_msg_qbytes = bmp->msg_qbytes;
    338 	lmp->l_msg_lspid = bmp->msg_lspid;
    339 	lmp->l_msg_lrpid = bmp->msg_lrpid;
    340 	lmp->l_msg_stime = bmp->msg_stime;
    341 	lmp->l_msg_rtime = bmp->msg_rtime;
    342 	lmp->l_msg_ctime = bmp->msg_ctime;
    343 }
    344 
    345 int
    346 linux_sys_msgctl(struct lwp *l, const struct linux_sys_msgctl_args *uap, register_t *retval)
    347 {
    348 	/* {
    349 		syscallarg(int) msqid;
    350 		syscallarg(int) cmd;
    351 		syscallarg(struct linux_msqid_ds *) buf;
    352 	} */
    353 	struct msqid_ds bm;
    354 	struct linux_msqid_ds lm;
    355 	int error;
    356 
    357 	switch (SCARG(uap, cmd)) {
    358 	case LINUX_IPC_STAT:
    359 		error = msgctl1(l, SCARG(uap, msqid), IPC_STAT, &bm);
    360 		if (error == 0) {
    361 			bsd_to_linux_msqid_ds(&bm, &lm);
    362 			error = copyout(&lm, SCARG(uap, buf), sizeof lm);
    363 		}
    364 		return error;
    365 	case LINUX_IPC_SET:
    366 		if ((error = copyin(SCARG(uap, buf), &lm, sizeof lm)))
    367 			return error;
    368 		linux_to_bsd_msqid_ds(&lm, &bm);
    369 		return msgctl1(l, SCARG(uap, msqid), IPC_SET, &bm);
    370 	case LINUX_IPC_RMID:
    371 		return msgctl1(l, SCARG(uap, msqid), IPC_RMID, NULL);
    372 		break;
    373 	default:
    374 		return EINVAL;
    375 	}
    376 }
    377 #endif /* SYSVMSG */
    378 
    379 #ifdef SYSVSHM
    380 /*
    381  * shmget(2). Just make sure the Linux-compatible shmat() semantics
    382  * is enabled for the segment, so that shmat() succeeds even when
    383  * the segment would be removed.
    384  */
    385 int
    386 linux_sys_shmget(struct lwp *l, const struct linux_sys_shmget_args *uap, register_t *retval)
    387 {
    388 	/* {
    389 		syscallarg(key_t) key;
    390 		syscallarg(size_t) size;
    391 		syscallarg(int) shmflg;
    392 	} */
    393 	struct sys_shmget_args bsd_ua;
    394 
    395 	SCARG(&bsd_ua, key) = SCARG(uap, key);
    396 	SCARG(&bsd_ua, size) = SCARG(uap, size);
    397 	SCARG(&bsd_ua, shmflg) = SCARG(uap, shmflg) | _SHM_RMLINGER;
    398 
    399 	return sys_shmget(l, &bsd_ua, retval);
    400 }
    401 
    402 /*
    403  * shmat(2). Very straightforward, except that Linux passes a pointer
    404  * in which the return value is to be passed. This is subsequently
    405  * handled by libc, apparently.
    406  */
    407 #ifndef __amd64__
    408 int
    409 linux_sys_shmat(struct lwp *l, const struct linux_sys_shmat_args *uap, register_t *retval)
    410 {
    411 	/* {
    412 		syscallarg(int) shmid;
    413 		syscallarg(void *) shmaddr;
    414 		syscallarg(int) shmflg;
    415 		syscallarg(u_long *) raddr;
    416 	} */
    417 	int error;
    418 
    419 	if ((error = sys_shmat(l, (const void *)uap, retval)))
    420 		return error;
    421 
    422 	if ((error = copyout(&retval[0], SCARG(uap, raddr), sizeof retval[0])))
    423 		return error;
    424 
    425 	retval[0] = 0;
    426 	return 0;
    427 }
    428 #endif /* __amd64__ */
    429 
    430 /*
    431  * Convert between Linux and NetBSD shmid_ds structures.
    432  * The order of the fields is once again the difference, and
    433  * we also need a place to store the internal data pointer
    434  * in, which is unfortunately stored in this structure.
    435  *
    436  * We abuse a Linux internal field for that.
    437  */
    438 void
    439 linux_to_bsd_shmid_ds(struct linux_shmid_ds *lsp, struct shmid_ds *bsp)
    440 {
    441 
    442 	linux_to_bsd_ipc_perm(&lsp->l_shm_perm, &bsp->shm_perm);
    443 	bsp->shm_segsz = lsp->l_shm_segsz;
    444 	bsp->shm_lpid = lsp->l_shm_lpid;
    445 	bsp->shm_cpid = lsp->l_shm_cpid;
    446 	bsp->shm_nattch = lsp->l_shm_nattch;
    447 	bsp->shm_atime = lsp->l_shm_atime;
    448 	bsp->shm_dtime = lsp->l_shm_dtime;
    449 	bsp->shm_ctime = lsp->l_shm_ctime;
    450 	bsp->_shm_internal = lsp->l_private2;	/* XXX Oh well. */
    451 }
    452 
    453 void
    454 linux_to_bsd_shmid64_ds(struct linux_shmid64_ds *lsp, struct shmid_ds *bsp)
    455 {
    456 
    457 	linux_to_bsd_ipc64_perm(&lsp->l_shm_perm, &bsp->shm_perm);
    458 	bsp->shm_segsz = lsp->l_shm_segsz;
    459 	bsp->shm_lpid = lsp->l_shm_lpid;
    460 	bsp->shm_cpid = lsp->l_shm_cpid;
    461 	bsp->shm_nattch = lsp->l_shm_nattch;
    462 	bsp->shm_atime = lsp->l_shm_atime;
    463 	bsp->shm_dtime = lsp->l_shm_dtime;
    464 	bsp->shm_ctime = lsp->l_shm_ctime;
    465 	bsp->_shm_internal = (void*)lsp->l___unused5;	/* XXX Oh well. */
    466 }
    467 
    468 void
    469 bsd_to_linux_shmid_ds(struct shmid_ds *bsp, struct linux_shmid_ds *lsp)
    470 {
    471 
    472 	bsd_to_linux_ipc_perm(&bsp->shm_perm, &lsp->l_shm_perm);
    473 	lsp->l_shm_segsz = bsp->shm_segsz;
    474 	lsp->l_shm_lpid = bsp->shm_lpid;
    475 	lsp->l_shm_cpid = bsp->shm_cpid;
    476 	lsp->l_shm_nattch = bsp->shm_nattch;
    477 	lsp->l_shm_atime = bsp->shm_atime;
    478 	lsp->l_shm_dtime = bsp->shm_dtime;
    479 	lsp->l_shm_ctime = bsp->shm_ctime;
    480 	lsp->l_private2 = bsp->_shm_internal;	/* XXX */
    481 }
    482 
    483 void
    484 bsd_to_linux_shmid64_ds(struct shmid_ds *bsp, struct linux_shmid64_ds *lsp)
    485 {
    486 	bsd_to_linux_ipc64_perm(&bsp->shm_perm, &lsp->l_shm_perm);
    487 	lsp->l_shm_segsz = bsp->shm_segsz;
    488 	lsp->l_shm_lpid = bsp->shm_lpid;
    489 	lsp->l_shm_cpid = bsp->shm_cpid;
    490 	lsp->l_shm_nattch = bsp->shm_nattch;
    491 	lsp->l_shm_atime = bsp->shm_atime;
    492 	lsp->l_shm_dtime = bsp->shm_dtime;
    493 	lsp->l_shm_ctime = bsp->shm_ctime;
    494 	lsp->l___unused5 = (u_long)bsp->_shm_internal;	/* XXX */
    495 }
    496 
    497 /*
    498  * shmctl.
    499  *
    500  * The usual structure conversion and massaging is done.
    501  */
    502 int
    503 linux_sys_shmctl(struct lwp *l, const struct linux_sys_shmctl_args *uap, register_t *retval)
    504 {
    505 	/* {
    506 		syscallarg(int) shmid;
    507 		syscallarg(int) cmd;
    508 		syscallarg(struct linux_shmid_ds *) buf;
    509 	} */
    510 	struct shmid_ds bs;
    511 	struct linux_shmid_ds ls;
    512 	struct linux_shmid64_ds ls64;
    513 	struct linux_shminfo64 lsi64;
    514 	struct linux_shm_info lsi;
    515 	int error, i, cmd, shmid;
    516 
    517 	shmid = SCARG(uap, shmid);
    518 	cmd = SCARG(uap, cmd);
    519 #ifdef LINUX_IPC_FORCE64
    520 	if (cmd == LINUX_IPC_STAT || cmd == LINUX_SHM_STAT ||
    521 	    cmd == LINUX_IPC_SET)
    522 		cmd |= LINUX_IPC_64;
    523 #endif
    524 
    525 	switch (cmd) {
    526 	case LINUX_IPC_STAT:
    527 	case LINUX_SHM_STAT:
    528 		if (cmd == LINUX_SHM_STAT) {
    529 			shmid = IXSEQ_TO_IPCID(shmid, shmsegs[shmid].shm_perm);
    530 			retval[0] = shmid;
    531 		}
    532 		error = shmctl1(l, shmid, IPC_STAT, &bs);
    533 		if (error != 0)
    534 			return error;
    535 		bsd_to_linux_shmid_ds(&bs, &ls);
    536 		return copyout(&ls, SCARG(uap, buf), sizeof ls);
    537 
    538 	case LINUX_IPC_STAT | LINUX_IPC_64:
    539 	case LINUX_SHM_STAT | LINUX_IPC_64:
    540 		if (cmd == (LINUX_SHM_STAT | LINUX_IPC_64)) {
    541 			shmid = IXSEQ_TO_IPCID(shmid, shmsegs[shmid].shm_perm);
    542 			retval[0] = shmid;
    543 		}
    544 		error = shmctl1(l, shmid, IPC_STAT, &bs);
    545 		if (error != 0)
    546 			return error;
    547 		bsd_to_linux_shmid64_ds(&bs, &ls64);
    548 		return copyout(&ls64, SCARG(uap, buf), sizeof ls64);
    549 
    550 	case LINUX_IPC_SET:
    551 		if ((error = copyin(SCARG(uap, buf), &ls, sizeof ls)))
    552 			return error;
    553 		linux_to_bsd_shmid_ds(&ls, &bs);
    554 		return shmctl1(l, shmid, IPC_SET, &bs);
    555 
    556 	case LINUX_IPC_SET | LINUX_IPC_64:
    557 		if ((error = copyin(SCARG(uap, buf), &ls64, sizeof ls64)))
    558 			return error;
    559 		linux_to_bsd_shmid64_ds(&ls64, &bs);
    560 		return shmctl1(l, shmid, IPC_SET, &bs);
    561 
    562 	case LINUX_IPC_RMID:
    563 		return shmctl1(l, shmid, IPC_RMID, NULL);
    564 
    565 	case LINUX_SHM_LOCK:
    566 		return shmctl1(l, shmid, SHM_LOCK, NULL);
    567 
    568 	case LINUX_SHM_UNLOCK:
    569 		return shmctl1(l, shmid, SHM_UNLOCK, NULL);
    570 
    571 	case LINUX_IPC_INFO:
    572 		memset(&lsi64, 0, sizeof lsi64);
    573 		lsi64.l_shmmax = shminfo.shmmax;
    574 		lsi64.l_shmmin = shminfo.shmmin;
    575 		lsi64.l_shmmni = shminfo.shmmni;
    576 		lsi64.l_shmseg = shminfo.shmseg;
    577 		lsi64.l_shmall = shminfo.shmall;
    578 		for (i = shminfo.shmmni - 1; i > 0; i--)
    579 			if (shmsegs[i].shm_perm.mode & SHMSEG_ALLOCATED)
    580 				break;
    581 		retval[0] = i;
    582 		return copyout(&lsi64, SCARG(uap, buf), sizeof lsi64);
    583 
    584 	case LINUX_SHM_INFO:
    585 		(void)memset(&lsi, 0, sizeof lsi);
    586 		lsi.l_used_ids = shm_nused;
    587 		for (i = 0; i < shminfo.shmmni; i++)
    588 			if (shmsegs[i].shm_perm.mode & SHMSEG_ALLOCATED)
    589 				lsi.l_shm_tot +=
    590 				    round_page(shmsegs[i].shm_segsz) /
    591 				    uvmexp.pagesize;
    592 		lsi.l_shm_rss = 0;
    593 		lsi.l_shm_swp = 0;
    594 		lsi.l_swap_attempts = 0;
    595 		lsi.l_swap_successes = 0;
    596 		for (i = shminfo.shmmni - 1; i > 0; i--)
    597 			if (shmsegs[i].shm_perm.mode & SHMSEG_ALLOCATED)
    598 				break;
    599 		retval[0] = i;
    600 		return copyout(&lsi, SCARG(uap, buf), sizeof lsi);
    601 
    602 	default:
    603 #ifdef DEBUG
    604 		printf("linux_sys_shmctl cmd %d\n", SCARG(uap, cmd));
    605 #endif
    606 		return EINVAL;
    607 	}
    608 }
    609 #endif /* SYSVSHM */
    610