xref: /netbsd-src/sys/compat/linux/common/linux_ipc.c (revision ee0c5b44def8a80be34fd2e5867cafdcc76275b6)
1 /*	$NetBSD: linux_ipc.c,v 1.33 2006/02/09 19:18:56 manu 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.33 2006/02/09 19:18:56 manu 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 #include <compat/linux/common/linux_ipccall.h>
65 
66 #include <compat/linux/linux_syscallargs.h>
67 #include <compat/linux/linux_syscall.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 proc *p = l->l_proc;
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(p, 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 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 	if ((error = copyout(&retval[0], (caddr_t) SCARG(uap, raddr),
428 	     sizeof retval[0])))
429 		return error;
430 
431 	retval[0] = 0;
432 	return 0;
433 }
434 
435 /*
436  * Convert between Linux and NetBSD shmid_ds structures.
437  * The order of the fields is once again the difference, and
438  * we also need a place to store the internal data pointer
439  * in, which is unfortunately stored in this structure.
440  *
441  * We abuse a Linux internal field for that.
442  */
443 void
444 linux_to_bsd_shmid_ds(lsp, bsp)
445 	struct linux_shmid_ds *lsp;
446 	struct shmid_ds *bsp;
447 {
448 
449 	linux_to_bsd_ipc_perm(&lsp->l_shm_perm, &bsp->shm_perm);
450 	bsp->shm_segsz = lsp->l_shm_segsz;
451 	bsp->shm_lpid = lsp->l_shm_lpid;
452 	bsp->shm_cpid = lsp->l_shm_cpid;
453 	bsp->shm_nattch = lsp->l_shm_nattch;
454 	bsp->shm_atime = lsp->l_shm_atime;
455 	bsp->shm_dtime = lsp->l_shm_dtime;
456 	bsp->shm_ctime = lsp->l_shm_ctime;
457 	bsp->_shm_internal = lsp->l_private2;	/* XXX Oh well. */
458 }
459 
460 void
461 linux_to_bsd_shmid64_ds(lsp, bsp)
462 	struct linux_shmid64_ds *lsp;
463 	struct shmid_ds *bsp;
464 {
465 
466 	linux_to_bsd_ipc64_perm(&lsp->l_shm_perm, &bsp->shm_perm);
467 	bsp->shm_segsz = lsp->l_shm_segsz;
468 	bsp->shm_lpid = lsp->l_shm_lpid;
469 	bsp->shm_cpid = lsp->l_shm_cpid;
470 	bsp->shm_nattch = lsp->l_shm_nattch;
471 	bsp->shm_atime = lsp->l_shm_atime;
472 	bsp->shm_dtime = lsp->l_shm_dtime;
473 	bsp->shm_ctime = lsp->l_shm_ctime;
474 	bsp->_shm_internal = (void*)lsp->l___unused5;	/* XXX Oh well. */
475 }
476 
477 void
478 bsd_to_linux_shmid_ds(bsp, lsp)
479 	struct shmid_ds *bsp;
480 	struct linux_shmid_ds *lsp;
481 {
482 
483 	bsd_to_linux_ipc_perm(&bsp->shm_perm, &lsp->l_shm_perm);
484 	lsp->l_shm_segsz = bsp->shm_segsz;
485 	lsp->l_shm_lpid = bsp->shm_lpid;
486 	lsp->l_shm_cpid = bsp->shm_cpid;
487 	lsp->l_shm_nattch = bsp->shm_nattch;
488 	lsp->l_shm_atime = bsp->shm_atime;
489 	lsp->l_shm_dtime = bsp->shm_dtime;
490 	lsp->l_shm_ctime = bsp->shm_ctime;
491 	lsp->l_private2 = bsp->_shm_internal;	/* XXX */
492 }
493 
494 void
495 bsd_to_linux_shmid64_ds(bsp, lsp)
496 	struct shmid_ds *bsp;
497 	struct linux_shmid64_ds *lsp;
498 {
499 	bsd_to_linux_ipc64_perm(&bsp->shm_perm, &lsp->l_shm_perm);
500 	lsp->l_shm_segsz = bsp->shm_segsz;
501 	lsp->l_shm_lpid = bsp->shm_lpid;
502 	lsp->l_shm_cpid = bsp->shm_cpid;
503 	lsp->l_shm_nattch = bsp->shm_nattch;
504 	lsp->l_shm_atime = bsp->shm_atime;
505 	lsp->l_shm_dtime = bsp->shm_dtime;
506 	lsp->l_shm_ctime = bsp->shm_ctime;
507 	lsp->l___unused5 = (u_long)bsp->_shm_internal;	/* XXX */
508 }
509 
510 /*
511  * shmctl.SHM_LOCK and SHM_UNLOCK are passed on, but currently not implemented
512  * by NetBSD itself.
513  *
514  * The usual structure conversion and massaging is done.
515  */
516 int
517 linux_sys_shmctl(l, v, retval)
518 	struct lwp *l;
519 	void *v;
520 	register_t *retval;
521 {
522 	struct linux_sys_shmctl_args /* {
523 		syscallarg(int) shmid;
524 		syscallarg(int) cmd;
525 		syscallarg(struct linux_shmid_ds *) buf;
526 	} */ *uap = v;
527 	struct proc *p = l->l_proc;
528 	caddr_t sg;
529 	struct sys___shmctl13_args nua;
530 	struct shmid_ds *bsp, bs;
531 	struct linux_shmid_ds ls;
532 	struct linux_shmid64_ds ls64;
533 	struct linux_shminfo64 lsi64;
534 	struct linux_shm_info lsi;
535 	int error, i, cmd;
536 
537 	SCARG(&nua, shmid) = SCARG(uap, shmid);
538 	cmd = SCARG(uap, cmd);
539 	switch (cmd) {
540 	case LINUX_IPC_STAT:
541 	case LINUX_SHM_STAT:
542 		sg = stackgap_init(p, 0);
543 		bsp = stackgap_alloc(p, &sg, sizeof(struct shmid_ds));
544 		SCARG(&nua, cmd) = IPC_STAT;
545 		SCARG(&nua, buf) = bsp;
546 		if ((error = sys___shmctl13(l, &nua, retval)))
547 			return error;
548 		if ((error = copyin(SCARG(&nua, buf), &bs, sizeof bs)))
549 			return error;
550 		bsd_to_linux_shmid_ds(&bs, &ls);
551 		if (cmd == LINUX_SHM_STAT)
552 			retval[0] = IXSEQ_TO_IPCID(bs.shm_perm._key,
553 			    bs.shm_perm);
554 		return copyout(&ls, SCARG(uap, buf), sizeof ls);
555 
556 	case LINUX_IPC_STAT|LINUX_IPC_64:
557 	case LINUX_SHM_STAT|LINUX_IPC_64:
558 		sg = stackgap_init(p,0);
559 		bsp = stackgap_alloc(p, &sg, sizeof(struct linux_shmid64_ds));
560 		SCARG(&nua, cmd) = IPC_STAT;
561 		SCARG(&nua, buf) = bsp;
562 		if ((error = sys___shmctl13(l, &nua, retval)))
563 			return error;
564 		if ((error = copyin(SCARG(&nua, buf), &bs, sizeof bs)))
565 			return error;
566 		bsd_to_linux_shmid64_ds(&bs, &ls64);
567 		if (cmd == (LINUX_SHM_STAT|LINUX_IPC_64)) {
568 			retval[0] = IXSEQ_TO_IPCID(bs.shm_perm._key,
569 						   bs.shm_perm);
570 		}
571 		return copyout(&ls64, SCARG(uap, buf), sizeof ls64);
572 
573 	case LINUX_IPC_SET:
574 		if ((error = copyin(SCARG(uap, buf), &ls, sizeof ls)))
575 			return error;
576 		linux_to_bsd_shmid_ds(&ls, &bs);
577 		sg = stackgap_init(p, 0);
578 		bsp = stackgap_alloc(p, &sg, sizeof bs);
579 		if ((error = copyout(&bs, bsp, sizeof bs)))
580 			return error;
581 		SCARG(&nua, cmd) = IPC_SET;
582 		SCARG(&nua, buf) = bsp;
583 		break;
584 
585 	case LINUX_IPC_RMID:
586 		SCARG(&nua, cmd) = IPC_RMID;
587 		SCARG(&nua, buf) = NULL;
588 		break;
589 
590 	case LINUX_SHM_LOCK:
591 		SCARG(&nua, cmd) = SHM_LOCK;
592 		SCARG(&nua, buf) = NULL;
593 		break;
594 
595 	case LINUX_SHM_UNLOCK:
596 		SCARG(&nua, cmd) = SHM_UNLOCK;
597 		SCARG(&nua, buf) = NULL;
598 		break;
599 
600 	case LINUX_IPC_INFO:
601 		memset(&lsi64, 0, sizeof lsi64);
602 		lsi64.l_shmmax = shminfo.shmmax;
603 		lsi64.l_shmmin = shminfo.shmmin;
604 		lsi64.l_shmmni = shminfo.shmmni;
605 		lsi64.l_shmseg = shminfo.shmseg;
606 		lsi64.l_shmall = shminfo.shmall;
607 		return copyout(&lsi64, SCARG(uap, buf), sizeof lsi64);
608 
609 	case LINUX_SHM_INFO:
610 		(void)memset(&lsi, 0, sizeof lsi);
611 		lsi.l_used_ids = shm_nused;
612 		for (i = 0; i < shminfo.shmmni; i++)
613 			if (shmsegs[i].shm_perm.mode & SHMSEG_ALLOCATED)
614 				lsi.l_shm_tot += shmsegs[i].shm_segsz;
615 		lsi.l_shm_rss = 0;
616 		lsi.l_shm_swp = 0;
617 		lsi.l_swap_attempts = 0;
618 		lsi.l_swap_successes = 0;
619 		return copyout(&lsi, SCARG(uap, buf), sizeof lsi);
620 
621 	default:
622 #ifdef DEBUG
623 		printf("linux_sys_shmctl cmd %d\n", SCARG(uap, cmd));
624 #endif
625 		return EINVAL;
626 	}
627 	return sys___shmctl13(l, &nua, retval);
628 }
629 #endif /* SYSVSHM */
630