2 * Copyright (c) 1995 The NetBSD Foundation, Inc.
5 * This code is derived from software contributed to The NetBSD Foundation
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the NetBSD
19 * Foundation, Inc. and its contributors.
20 * 4. Neither the name of The NetBSD Foundation nor the names of its
21 * contributors may be used to endorse or promote products derived
22 * from this software without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
25 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
26 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
27 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
28 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 * POSSIBILITY OF SUCH DAMAGE.
37 * Portions of this code have been derived from software contributed
38 * to the FreeBSD Project by Mark Newton.
40 * Copyright (c) 1999 Mark Newton
41 * All rights reserved.
43 * Redistribution and use in source and binary forms, with or without
44 * modification, are permitted provided that the following conditions
46 * 1. Redistributions of source code must retain the above copyright
47 * notice, this list of conditions and the following disclaimer.
48 * 2. Redistributions in binary form must reproduce the above copyright
49 * notice, this list of conditions and the following disclaimer in the
50 * documentation and/or other materials provided with the distribution.
51 * 3. The name of the author may not be used to endorse or promote products
52 * derived from this software without specific prior written permission
54 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
55 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
56 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
57 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
58 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
59 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
60 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
61 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
62 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
63 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
65 * XXX- This code is presently a no-op on FreeBSD (and isn't compiled due
66 * to preprocessor conditionals). A nice project for a kernel hacking
67 * novice might be to MakeItGo, but I have more important fish to fry
70 * Derived from: $NetBSD: svr4_ipc.c,v 1.7 1998/10/19 22:43:00 tron Exp $
73 #include <sys/cdefs.h>
74 __FBSDID("$FreeBSD$");
76 #include "opt_sysvipc.h"
78 #include <sys/param.h>
84 #include <sys/syscallsubr.h>
85 #include <sys/sysproto.h>
86 #include <sys/systm.h>
89 #include <compat/svr4/svr4.h>
90 #include <compat/svr4/svr4_types.h>
91 #include <compat/svr4/svr4_signal.h>
92 #include <compat/svr4/svr4_proto.h>
93 #include <compat/svr4/svr4_util.h>
94 #include <compat/svr4/svr4_ipc.h>
96 #if defined(SYSVMSG) || defined(SYSVSHM) || defined(SYSVSEM)
97 static void svr4_to_bsd_ipc_perm(const struct svr4_ipc_perm *,
99 static void bsd_to_svr4_ipc_perm(const struct ipc_perm *,
100 struct svr4_ipc_perm *);
104 static void bsd_to_svr4_semid_ds(const struct semid_ds *,
105 struct svr4_semid_ds *);
106 static void svr4_to_bsd_semid_ds(const struct svr4_semid_ds *,
108 static int svr4_semop(struct thread *, void *);
109 static int svr4_semget(struct thread *, void *);
110 static int svr4_semctl(struct thread *, void *);
114 static void bsd_to_svr4_msqid_ds(const struct msqid_ds *,
115 struct svr4_msqid_ds *);
116 static void svr4_to_bsd_msqid_ds(const struct svr4_msqid_ds *,
118 static int svr4_msgsnd(struct thread *, void *);
119 static int svr4_msgrcv(struct thread *, void *);
120 static int svr4_msgget(struct thread *, void *);
121 static int svr4_msgctl(struct thread *, void *);
125 static void bsd_to_svr4_shmid_ds(const struct shmid_ds *,
126 struct svr4_shmid_ds *);
127 static void svr4_to_bsd_shmid_ds(const struct svr4_shmid_ds *,
129 static int svr4_shmat(struct thread *, void *);
130 static int svr4_shmdt(struct thread *, void *);
131 static int svr4_shmget(struct thread *, void *);
132 static int svr4_shmctl(struct thread *, void *);
135 #if defined(SYSVMSG) || defined(SYSVSHM) || defined(SYSVSEM)
138 svr4_to_bsd_ipc_perm(spp, bpp)
139 const struct svr4_ipc_perm *spp;
140 struct ipc_perm *bpp;
145 bpp->cuid = spp->cuid;
146 bpp->cgid = spp->cgid;
147 bpp->mode = spp->mode;
152 bsd_to_svr4_ipc_perm(bpp, spp)
153 const struct ipc_perm *bpp;
154 struct svr4_ipc_perm *spp;
159 spp->cuid = bpp->cuid;
160 spp->cgid = bpp->cgid;
161 spp->mode = bpp->mode;
168 bsd_to_svr4_semid_ds(bds, sds)
169 const struct semid_ds *bds;
170 struct svr4_semid_ds *sds;
172 bsd_to_svr4_ipc_perm(&bds->sem_perm, &sds->sem_perm);
173 sds->sem_base = (struct svr4_sem *) bds->sem_base;
174 sds->sem_nsems = bds->sem_nsems;
175 sds->sem_otime = bds->sem_otime;
176 sds->sem_pad1 = bds->sem_pad1;
177 sds->sem_ctime = bds->sem_ctime;
178 sds->sem_pad2 = bds->sem_pad2;
182 svr4_to_bsd_semid_ds(sds, bds)
183 const struct svr4_semid_ds *sds;
184 struct semid_ds *bds;
186 svr4_to_bsd_ipc_perm(&sds->sem_perm, &bds->sem_perm);
187 bds->sem_base = (struct sem *) bds->sem_base;
188 bds->sem_nsems = sds->sem_nsems;
189 bds->sem_otime = sds->sem_otime;
190 bds->sem_pad1 = sds->sem_pad1;
191 bds->sem_ctime = sds->sem_ctime;
192 bds->sem_pad2 = sds->sem_pad2;
195 struct svr4_sys_semctl_args {
208 struct svr4_sys_semctl_args *uap = v;
209 struct svr4_semid_ds ss;
216 case SVR4_SEM_GETZCNT:
220 case SVR4_SEM_GETNCNT:
224 case SVR4_SEM_GETPID:
228 case SVR4_SEM_GETVAL:
232 case SVR4_SEM_SETVAL:
236 case SVR4_SEM_GETALL:
240 case SVR4_SEM_SETALL:
247 error = kern_semctl(td, uap->semid, uap->semnum, cmd, &semun,
251 bsd_to_svr4_semid_ds(&bs, &ss);
252 error = copyout(&ss, uap->arg.buf, sizeof(ss));
254 td->td_retval[0] = rval;
259 error = copyin(uap->arg.buf, (caddr_t) &ss, sizeof ss);
262 svr4_to_bsd_semid_ds(&ss, &bs);
264 return (kern_semctl(td, uap->semid, uap->semnum, cmd, &semun,
275 return (kern_semctl(td, uap->semid, uap->semnum, cmd, &uap->arg,
279 struct svr4_sys_semget_args {
291 struct svr4_sys_semget_args *uap = v;
292 struct semget_args ap;
295 ap.nsems = uap->nsems;
296 ap.semflg = uap->semflg;
298 return semget(td, &ap);
301 struct svr4_sys_semop_args {
304 struct svr4_sembuf * sops;
313 struct svr4_sys_semop_args *uap = v;
314 struct semop_args ap;
316 ap.semid = uap->semid;
317 /* These are the same */
318 ap.sops = (struct sembuf *) uap->sops;
319 ap.nsops = uap->nsops;
321 return semop(td, &ap);
325 svr4_sys_semsys(td, uap)
327 struct svr4_sys_semsys_args *uap;
330 DPRINTF(("svr4_semsys(%d)\n", uap->what));
334 return svr4_semctl(td, uap);
336 return svr4_semget(td, uap);
338 return svr4_semop(td, uap);
344 MODULE_DEPEND(svr4elf, sysvsem, 1, 1, 1);
349 bsd_to_svr4_msqid_ds(bds, sds)
350 const struct msqid_ds *bds;
351 struct svr4_msqid_ds *sds;
353 bsd_to_svr4_ipc_perm(&bds->msg_perm, &sds->msg_perm);
354 sds->msg_first = (struct svr4_msg *) bds->msg_first;
355 sds->msg_last = (struct svr4_msg *) bds->msg_last;
356 sds->msg_cbytes = bds->msg_cbytes;
357 sds->msg_qnum = bds->msg_qnum;
358 sds->msg_qbytes = bds->msg_qbytes;
359 sds->msg_lspid = bds->msg_lspid;
360 sds->msg_lrpid = bds->msg_lrpid;
361 sds->msg_stime = bds->msg_stime;
362 sds->msg_pad1 = bds->msg_pad1;
363 sds->msg_rtime = bds->msg_rtime;
364 sds->msg_pad2 = bds->msg_pad2;
365 sds->msg_ctime = bds->msg_ctime;
366 sds->msg_pad3 = bds->msg_pad3;
368 /* use the padding for the rest of the fields */
370 const short *pad = (const short *) bds->msg_pad4;
371 sds->msg_cv = pad[0];
372 sds->msg_qnum_cv = pad[1];
377 svr4_to_bsd_msqid_ds(sds, bds)
378 const struct svr4_msqid_ds *sds;
379 struct msqid_ds *bds;
381 svr4_to_bsd_ipc_perm(&sds->msg_perm, &bds->msg_perm);
382 bds->msg_first = (struct msg *) sds->msg_first;
383 bds->msg_last = (struct msg *) sds->msg_last;
384 bds->msg_cbytes = sds->msg_cbytes;
385 bds->msg_qnum = sds->msg_qnum;
386 bds->msg_qbytes = sds->msg_qbytes;
387 bds->msg_lspid = sds->msg_lspid;
388 bds->msg_lrpid = sds->msg_lrpid;
389 bds->msg_stime = sds->msg_stime;
390 bds->msg_pad1 = sds->msg_pad1;
391 bds->msg_rtime = sds->msg_rtime;
392 bds->msg_pad2 = sds->msg_pad2;
393 bds->msg_ctime = sds->msg_ctime;
394 bds->msg_pad3 = sds->msg_pad3;
396 /* use the padding for the rest of the fields */
398 short *pad = (short *) bds->msg_pad4;
399 pad[0] = sds->msg_cv;
400 pad[1] = sds->msg_qnum_cv;
404 struct svr4_sys_msgsnd_args {
417 struct svr4_sys_msgsnd_args *uap = v;
418 struct msgsnd_args ap;
420 ap.msqid = uap->msqid;
422 ap.msgsz = uap->msgsz;
423 ap.msgflg = uap->msgflg;
425 return msgsnd(td, &ap);
428 struct svr4_sys_msgrcv_args {
442 struct svr4_sys_msgrcv_args *uap = v;
443 struct msgrcv_args ap;
445 ap.msqid = uap->msqid;
447 ap.msgsz = uap->msgsz;
448 ap.msgtyp = uap->msgtyp;
449 ap.msgflg = uap->msgflg;
451 return msgrcv(td, &ap);
454 struct svr4_sys_msgget_args {
465 struct svr4_sys_msgget_args *uap = v;
466 struct msgget_args ap;
469 ap.msgflg = uap->msgflg;
471 return msgget(td, &ap);
474 struct svr4_sys_msgctl_args {
478 struct svr4_msqid_ds * buf;
486 struct svr4_sys_msgctl_args *uap = v;
487 struct svr4_msqid_ds ss;
493 error = kern_msgctl(td, uap->msqid, IPC_STAT, &bs);
496 bsd_to_svr4_msqid_ds(&bs, &ss);
497 return copyout(&ss, uap->buf, sizeof ss);
500 error = copyin(uap->buf, &ss, sizeof ss);
503 svr4_to_bsd_msqid_ds(&ss, &bs);
504 return (kern_msgctl(td, uap->msqid, IPC_SET, &bs));
507 return (kern_msgctl(td, uap->msqid, IPC_RMID, NULL));
515 svr4_sys_msgsys(td, uap)
517 struct svr4_sys_msgsys_args *uap;
520 DPRINTF(("svr4_msgsys(%d)\n", uap->what));
524 return svr4_msgsnd(td, uap);
526 return svr4_msgrcv(td, uap);
528 return svr4_msgget(td, uap);
530 return svr4_msgctl(td, uap);
536 MODULE_DEPEND(svr4elf, sysvmsg, 1, 1, 1);
542 bsd_to_svr4_shmid_ds(bds, sds)
543 const struct shmid_ds *bds;
544 struct svr4_shmid_ds *sds;
546 bsd_to_svr4_ipc_perm(&bds->shm_perm, &sds->shm_perm);
547 sds->shm_segsz = bds->shm_segsz;
549 sds->shm_lpid = bds->shm_lpid;
550 sds->shm_cpid = bds->shm_cpid;
551 sds->shm_amp = bds->shm_internal;
552 sds->shm_nattch = bds->shm_nattch;
553 sds->shm_cnattch = 0;
554 sds->shm_atime = bds->shm_atime;
556 sds->shm_dtime = bds->shm_dtime;
558 sds->shm_ctime = bds->shm_ctime;
563 svr4_to_bsd_shmid_ds(sds, bds)
564 const struct svr4_shmid_ds *sds;
565 struct shmid_ds *bds;
567 svr4_to_bsd_ipc_perm(&sds->shm_perm, &bds->shm_perm);
568 bds->shm_segsz = sds->shm_segsz;
569 bds->shm_lpid = sds->shm_lpid;
570 bds->shm_cpid = sds->shm_cpid;
571 bds->shm_internal = sds->shm_amp;
572 bds->shm_nattch = sds->shm_nattch;
573 bds->shm_atime = sds->shm_atime;
574 bds->shm_dtime = sds->shm_dtime;
575 bds->shm_ctime = sds->shm_ctime;
578 struct svr4_sys_shmat_args {
590 struct svr4_sys_shmat_args *uap = v;
591 struct shmat_args ap;
593 ap.shmid = uap->shmid;
594 ap.shmaddr = uap->shmaddr;
595 ap.shmflg = uap->shmflg;
597 return shmat(td, &ap);
600 struct svr4_sys_shmdt_args {
610 struct svr4_sys_shmdt_args *uap = v;
611 struct shmdt_args ap;
613 ap.shmaddr = uap->shmaddr;
615 return shmdt(td, &ap);
618 struct svr4_sys_shmget_args {
630 struct svr4_sys_shmget_args *uap = v;
631 struct shmget_args ap;
635 ap.shmflg = uap->shmflg;
637 return shmget(td, &ap);
640 struct svr4_sys_shmctl_args {
644 struct svr4_shmid_ds * buf;
652 struct svr4_sys_shmctl_args *uap = v;
654 struct svr4_shmid_ds ss;
658 if (uap->buf != NULL) {
662 case SVR4_SHM_UNLOCK:
663 error = copyin(uap->buf, &ss, sizeof(ss));
666 svr4_to_bsd_shmid_ds(&ss, &bs);
686 case SVR4_SHM_UNLOCK:
693 error = kern_shmctl(td, uap->shmid, cmd, &bs, &bufsize);
699 if (uap->buf != NULL) {
700 bsd_to_svr4_shmid_ds(&bs, &ss);
701 error = copyout(&ss, uap->buf, sizeof(ss));
710 svr4_sys_shmsys(td, uap)
712 struct svr4_sys_shmsys_args *uap;
715 DPRINTF(("svr4_shmsys(%d)\n", uap->what));
719 return svr4_shmat(td, uap);
721 return svr4_shmdt(td, uap);
723 return svr4_shmget(td, uap);
725 return svr4_shmctl(td, uap);
731 MODULE_DEPEND(svr4elf, sysvshm, 1, 1, 1);