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