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