xref: /netbsd-src/sys/compat/linux/common/linux_ipc.c (revision d48f14661dda8638fee055ba15d35bdfb29b9fa8)
1 /*	$NetBSD: linux_ipc.c,v 1.34 2006/02/09 23:27:08 dogcow 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 2006/02/09 23:27:08 dogcow 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 proc *p = l->l_proc;
209 	struct semid_ds sembuf;
210 	struct linux_semid_ds lsembuf;
211 	union __semun semun;
212 	int cmd, error;
213 	void *pass_arg = NULL;
214 
215 	cmd = SCARG(uap, cmd);
216 
217 	switch (cmd) {
218 	case LINUX_IPC_SET:
219 		pass_arg = &sembuf;
220 		cmd = IPC_SET;
221 		break;
222 
223 	case LINUX_IPC_STAT:
224 		pass_arg = &sembuf;
225 		cmd = IPC_STAT;
226 		break;
227 
228 	case LINUX_IPC_RMID:
229 		cmd = IPC_RMID;
230 		break;
231 
232 	case LINUX_GETVAL:
233 		cmd = GETVAL;
234 		break;
235 
236 	case LINUX_GETPID:
237 		cmd = GETPID;
238 		break;
239 
240 	case LINUX_GETNCNT:
241 		cmd = GETNCNT;
242 		break;
243 
244 	case LINUX_GETZCNT:
245 		cmd = GETZCNT;
246 		break;
247 
248 	case LINUX_GETALL:
249 		pass_arg = &semun;
250 		semun.array = SCARG(uap, arg).l_array;
251 		cmd = GETALL;
252 		break;
253 
254 	case LINUX_SETVAL:
255 		pass_arg = &semun;
256 		semun.val = SCARG(uap, arg).l_val;
257 		cmd = SETVAL;
258 		break;
259 
260 	case LINUX_SETALL:
261 		pass_arg = &semun;
262 		semun.array = SCARG(uap, arg).l_array;
263 		cmd = SETALL;
264 		break;
265 
266 	default:
267 		return (EINVAL);
268 	}
269 
270 	if (cmd == IPC_SET) {
271 		error = copyin(SCARG(uap, arg).l_buf, &lsembuf,
272 		    sizeof(lsembuf));
273 		if (error)
274 			return (error);
275 		linux_to_bsd_semid_ds(&lsembuf, &sembuf);
276 	}
277 
278 	error = semctl1(p, SCARG(uap, semid), SCARG(uap, semnum), cmd,
279 	    pass_arg, retval);
280 
281 	if (error == 0 && cmd == IPC_STAT) {
282 		bsd_to_linux_semid_ds(&sembuf, &lsembuf);
283 		error = copyout(&lsembuf, SCARG(uap, arg).l_buf,
284 		    sizeof(lsembuf));
285 	}
286 
287 	return (error);
288 }
289 #endif /* SYSVSEM */
290 
291 #ifdef SYSVMSG
292 
293 void
294 linux_to_bsd_msqid_ds(lmp, bmp)
295 	struct linux_msqid_ds *lmp;
296 	struct msqid_ds *bmp;
297 {
298 
299 	linux_to_bsd_ipc_perm(&lmp->l_msg_perm, &bmp->msg_perm);
300 	bmp->_msg_first = lmp->l_msg_first;
301 	bmp->_msg_last = lmp->l_msg_last;
302 	bmp->_msg_cbytes = lmp->l_msg_cbytes;
303 	bmp->msg_qnum = lmp->l_msg_qnum;
304 	bmp->msg_qbytes = lmp->l_msg_qbytes;
305 	bmp->msg_lspid = lmp->l_msg_lspid;
306 	bmp->msg_lrpid = lmp->l_msg_lrpid;
307 	bmp->msg_stime = lmp->l_msg_stime;
308 	bmp->msg_rtime = lmp->l_msg_rtime;
309 	bmp->msg_ctime = lmp->l_msg_ctime;
310 }
311 
312 void
313 bsd_to_linux_msqid_ds(bmp, lmp)
314 	struct msqid_ds *bmp;
315 	struct linux_msqid_ds *lmp;
316 {
317 
318 	bsd_to_linux_ipc_perm(&bmp->msg_perm, &lmp->l_msg_perm);
319 	lmp->l_msg_first = bmp->_msg_first;
320 	lmp->l_msg_last = bmp->_msg_last;
321 	lmp->l_msg_cbytes = bmp->_msg_cbytes;
322 	lmp->l_msg_qnum = bmp->msg_qnum;
323 	lmp->l_msg_qbytes = bmp->msg_qbytes;
324 	lmp->l_msg_lspid = bmp->msg_lspid;
325 	lmp->l_msg_lrpid = bmp->msg_lrpid;
326 	lmp->l_msg_stime = bmp->msg_stime;
327 	lmp->l_msg_rtime = bmp->msg_rtime;
328 	lmp->l_msg_ctime = bmp->msg_ctime;
329 }
330 
331 int
332 linux_sys_msgctl(l, v, retval)
333 	struct lwp *l;
334 	void *v;
335 	register_t *retval;
336 {
337 	struct linux_sys_msgctl_args /* {
338 		syscallarg(int) msqid;
339 		syscallarg(int) cmd;
340 		syscallarg(struct linux_msqid_ds *) buf;
341 	} */ *uap = v;
342 	struct proc *p = l->l_proc;
343 	caddr_t sg;
344 	struct sys___msgctl13_args nua;
345 	struct msqid_ds *bmp, bm;
346 	struct linux_msqid_ds lm;
347 	int error;
348 
349 	SCARG(&nua, msqid) = SCARG(uap, msqid);
350 	switch (SCARG(uap, cmd)) {
351 	case LINUX_IPC_STAT:
352 		sg = stackgap_init(p, 0);
353 		bmp = stackgap_alloc(p, &sg, sizeof (struct msqid_ds));
354 		SCARG(&nua, cmd) = IPC_STAT;
355 		SCARG(&nua, buf) = bmp;
356 		if ((error = sys___msgctl13(l, &nua, retval)))
357 			return error;
358 		if ((error = copyin(bmp, &bm, sizeof bm)))
359 			return error;
360 		bsd_to_linux_msqid_ds(&bm, &lm);
361 		return copyout(&lm, SCARG(uap, buf), sizeof lm);
362 	case LINUX_IPC_SET:
363 		if ((error = copyin(SCARG(uap, buf), &lm, sizeof lm)))
364 			return error;
365 		linux_to_bsd_msqid_ds(&lm, &bm);
366 		sg = stackgap_init(p, 0);
367 		bmp = stackgap_alloc(p, &sg, sizeof bm);
368 		if ((error = copyout(&bm, bmp, sizeof bm)))
369 			return error;
370 		SCARG(&nua, cmd) = IPC_SET;
371 		SCARG(&nua, buf) = bmp;
372 		break;
373 	case LINUX_IPC_RMID:
374 		SCARG(&nua, cmd) = IPC_RMID;
375 		SCARG(&nua, buf) = NULL;
376 		break;
377 	default:
378 		return EINVAL;
379 	}
380 	return sys___msgctl13(l, &nua, retval);
381 }
382 #endif /* SYSVMSG */
383 
384 #ifdef SYSVSHM
385 /*
386  * shmget(2). Just make sure the Linux-compatible shmat() semantics
387  * is enabled for the segment, so that shmat() succeeds even when
388  * the segment would be removed.
389  */
390 int
391 linux_sys_shmget(l, v, retval)
392 	struct lwp *l;
393 	void *v;
394 	register_t *retval;
395 {
396 	struct sys_shmget_args /* {
397 		syscallarg(key_t) key;
398 		syscallarg(size_t) size;
399 		syscallarg(int) shmflg;
400 	} */ *uap = v;
401 
402 	SCARG(uap, shmflg) |= _SHM_RMLINGER;
403 	return sys_shmget(l, uap, retval);
404 }
405 
406 /*
407  * shmat(2). Very straightforward, except that Linux passes a pointer
408  * in which the return value is to be passed. This is subsequently
409  * handled by libc, apparently.
410  */
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 
436 /*
437  * Convert between Linux and NetBSD shmid_ds structures.
438  * The order of the fields is once again the difference, and
439  * we also need a place to store the internal data pointer
440  * in, which is unfortunately stored in this structure.
441  *
442  * We abuse a Linux internal field for that.
443  */
444 void
445 linux_to_bsd_shmid_ds(lsp, bsp)
446 	struct linux_shmid_ds *lsp;
447 	struct shmid_ds *bsp;
448 {
449 
450 	linux_to_bsd_ipc_perm(&lsp->l_shm_perm, &bsp->shm_perm);
451 	bsp->shm_segsz = lsp->l_shm_segsz;
452 	bsp->shm_lpid = lsp->l_shm_lpid;
453 	bsp->shm_cpid = lsp->l_shm_cpid;
454 	bsp->shm_nattch = lsp->l_shm_nattch;
455 	bsp->shm_atime = lsp->l_shm_atime;
456 	bsp->shm_dtime = lsp->l_shm_dtime;
457 	bsp->shm_ctime = lsp->l_shm_ctime;
458 	bsp->_shm_internal = lsp->l_private2;	/* XXX Oh well. */
459 }
460 
461 void
462 linux_to_bsd_shmid64_ds(lsp, bsp)
463 	struct linux_shmid64_ds *lsp;
464 	struct shmid_ds *bsp;
465 {
466 
467 	linux_to_bsd_ipc64_perm(&lsp->l_shm_perm, &bsp->shm_perm);
468 	bsp->shm_segsz = lsp->l_shm_segsz;
469 	bsp->shm_lpid = lsp->l_shm_lpid;
470 	bsp->shm_cpid = lsp->l_shm_cpid;
471 	bsp->shm_nattch = lsp->l_shm_nattch;
472 	bsp->shm_atime = lsp->l_shm_atime;
473 	bsp->shm_dtime = lsp->l_shm_dtime;
474 	bsp->shm_ctime = lsp->l_shm_ctime;
475 	bsp->_shm_internal = (void*)lsp->l___unused5;	/* XXX Oh well. */
476 }
477 
478 void
479 bsd_to_linux_shmid_ds(bsp, lsp)
480 	struct shmid_ds *bsp;
481 	struct linux_shmid_ds *lsp;
482 {
483 
484 	bsd_to_linux_ipc_perm(&bsp->shm_perm, &lsp->l_shm_perm);
485 	lsp->l_shm_segsz = bsp->shm_segsz;
486 	lsp->l_shm_lpid = bsp->shm_lpid;
487 	lsp->l_shm_cpid = bsp->shm_cpid;
488 	lsp->l_shm_nattch = bsp->shm_nattch;
489 	lsp->l_shm_atime = bsp->shm_atime;
490 	lsp->l_shm_dtime = bsp->shm_dtime;
491 	lsp->l_shm_ctime = bsp->shm_ctime;
492 	lsp->l_private2 = bsp->_shm_internal;	/* XXX */
493 }
494 
495 void
496 bsd_to_linux_shmid64_ds(bsp, lsp)
497 	struct shmid_ds *bsp;
498 	struct linux_shmid64_ds *lsp;
499 {
500 	bsd_to_linux_ipc64_perm(&bsp->shm_perm, &lsp->l_shm_perm);
501 	lsp->l_shm_segsz = bsp->shm_segsz;
502 	lsp->l_shm_lpid = bsp->shm_lpid;
503 	lsp->l_shm_cpid = bsp->shm_cpid;
504 	lsp->l_shm_nattch = bsp->shm_nattch;
505 	lsp->l_shm_atime = bsp->shm_atime;
506 	lsp->l_shm_dtime = bsp->shm_dtime;
507 	lsp->l_shm_ctime = bsp->shm_ctime;
508 	lsp->l___unused5 = (u_long)bsp->_shm_internal;	/* XXX */
509 }
510 
511 /*
512  * shmctl.SHM_LOCK and SHM_UNLOCK are passed on, but currently not implemented
513  * by NetBSD itself.
514  *
515  * The usual structure conversion and massaging is done.
516  */
517 int
518 linux_sys_shmctl(l, v, retval)
519 	struct lwp *l;
520 	void *v;
521 	register_t *retval;
522 {
523 	struct linux_sys_shmctl_args /* {
524 		syscallarg(int) shmid;
525 		syscallarg(int) cmd;
526 		syscallarg(struct linux_shmid_ds *) buf;
527 	} */ *uap = v;
528 	struct proc *p = l->l_proc;
529 	caddr_t sg;
530 	struct sys___shmctl13_args nua;
531 	struct shmid_ds *bsp, bs;
532 	struct linux_shmid_ds ls;
533 	struct linux_shmid64_ds ls64;
534 	struct linux_shminfo64 lsi64;
535 	struct linux_shm_info lsi;
536 	int error, i, cmd;
537 
538 	SCARG(&nua, shmid) = SCARG(uap, shmid);
539 	cmd = SCARG(uap, cmd);
540 	switch (cmd) {
541 	case LINUX_IPC_STAT:
542 	case LINUX_SHM_STAT:
543 		sg = stackgap_init(p, 0);
544 		bsp = stackgap_alloc(p, &sg, sizeof(struct shmid_ds));
545 		SCARG(&nua, cmd) = IPC_STAT;
546 		SCARG(&nua, buf) = bsp;
547 		if ((error = sys___shmctl13(l, &nua, retval)))
548 			return error;
549 		if ((error = copyin(SCARG(&nua, buf), &bs, sizeof bs)))
550 			return error;
551 		bsd_to_linux_shmid_ds(&bs, &ls);
552 		if (cmd == LINUX_SHM_STAT)
553 			retval[0] = IXSEQ_TO_IPCID(bs.shm_perm._key,
554 			    bs.shm_perm);
555 		return copyout(&ls, SCARG(uap, buf), sizeof ls);
556 
557 	case LINUX_IPC_STAT|LINUX_IPC_64:
558 	case LINUX_SHM_STAT|LINUX_IPC_64:
559 		sg = stackgap_init(p,0);
560 		bsp = stackgap_alloc(p, &sg, sizeof(struct linux_shmid64_ds));
561 		SCARG(&nua, cmd) = IPC_STAT;
562 		SCARG(&nua, buf) = bsp;
563 		if ((error = sys___shmctl13(l, &nua, retval)))
564 			return error;
565 		if ((error = copyin(SCARG(&nua, buf), &bs, sizeof bs)))
566 			return error;
567 		bsd_to_linux_shmid64_ds(&bs, &ls64);
568 		if (cmd == (LINUX_SHM_STAT|LINUX_IPC_64)) {
569 			retval[0] = IXSEQ_TO_IPCID(bs.shm_perm._key,
570 						   bs.shm_perm);
571 		}
572 		return copyout(&ls64, SCARG(uap, buf), sizeof ls64);
573 
574 	case LINUX_IPC_SET:
575 		if ((error = copyin(SCARG(uap, buf), &ls, sizeof ls)))
576 			return error;
577 		linux_to_bsd_shmid_ds(&ls, &bs);
578 		sg = stackgap_init(p, 0);
579 		bsp = stackgap_alloc(p, &sg, sizeof bs);
580 		if ((error = copyout(&bs, bsp, sizeof bs)))
581 			return error;
582 		SCARG(&nua, cmd) = IPC_SET;
583 		SCARG(&nua, buf) = bsp;
584 		break;
585 
586 	case LINUX_IPC_RMID:
587 		SCARG(&nua, cmd) = IPC_RMID;
588 		SCARG(&nua, buf) = NULL;
589 		break;
590 
591 	case LINUX_SHM_LOCK:
592 		SCARG(&nua, cmd) = SHM_LOCK;
593 		SCARG(&nua, buf) = NULL;
594 		break;
595 
596 	case LINUX_SHM_UNLOCK:
597 		SCARG(&nua, cmd) = SHM_UNLOCK;
598 		SCARG(&nua, buf) = NULL;
599 		break;
600 
601 	case LINUX_IPC_INFO:
602 		memset(&lsi64, 0, sizeof lsi64);
603 		lsi64.l_shmmax = shminfo.shmmax;
604 		lsi64.l_shmmin = shminfo.shmmin;
605 		lsi64.l_shmmni = shminfo.shmmni;
606 		lsi64.l_shmseg = shminfo.shmseg;
607 		lsi64.l_shmall = shminfo.shmall;
608 		return copyout(&lsi64, SCARG(uap, buf), sizeof lsi64);
609 
610 	case LINUX_SHM_INFO:
611 		(void)memset(&lsi, 0, sizeof lsi);
612 		lsi.l_used_ids = shm_nused;
613 		for (i = 0; i < shminfo.shmmni; i++)
614 			if (shmsegs[i].shm_perm.mode & SHMSEG_ALLOCATED)
615 				lsi.l_shm_tot += shmsegs[i].shm_segsz;
616 		lsi.l_shm_rss = 0;
617 		lsi.l_shm_swp = 0;
618 		lsi.l_swap_attempts = 0;
619 		lsi.l_swap_successes = 0;
620 		return copyout(&lsi, SCARG(uap, buf), sizeof lsi);
621 
622 	default:
623 #ifdef DEBUG
624 		printf("linux_sys_shmctl cmd %d\n", SCARG(uap, cmd));
625 #endif
626 		return EINVAL;
627 	}
628 	return sys___shmctl13(l, &nua, retval);
629 }
630 #endif /* SYSVSHM */
631