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 bzero(sds, sizeof(*sds));
173 bsd_to_svr4_ipc_perm(&bds->sem_perm, &sds->sem_perm);
174 sds->sem_base = (struct svr4_sem *) bds->sem_base;
175 sds->sem_nsems = bds->sem_nsems;
176 sds->sem_otime = bds->sem_otime;
177 sds->sem_ctime = bds->sem_ctime;
181 svr4_to_bsd_semid_ds(sds, bds)
182 const struct svr4_semid_ds *sds;
183 struct semid_ds *bds;
185 svr4_to_bsd_ipc_perm(&sds->sem_perm, &bds->sem_perm);
186 bds->sem_base = (struct sem *) bds->sem_base;
187 bds->sem_nsems = sds->sem_nsems;
188 bds->sem_otime = sds->sem_otime;
189 bds->sem_ctime = sds->sem_ctime;
192 struct svr4_sys_semctl_args {
205 struct svr4_sys_semctl_args *uap = v;
206 struct svr4_semid_ds ss;
213 case SVR4_SEM_GETZCNT:
217 case SVR4_SEM_GETNCNT:
221 case SVR4_SEM_GETPID:
225 case SVR4_SEM_GETVAL:
229 case SVR4_SEM_SETVAL:
233 case SVR4_SEM_GETALL:
237 case SVR4_SEM_SETALL:
244 error = kern_semctl(td, uap->semid, uap->semnum, cmd, &semun,
248 bsd_to_svr4_semid_ds(&bs, &ss);
249 error = copyout(&ss, uap->arg.buf, sizeof(ss));
251 td->td_retval[0] = rval;
256 error = copyin(uap->arg.buf, (caddr_t) &ss, sizeof ss);
259 svr4_to_bsd_semid_ds(&ss, &bs);
261 return (kern_semctl(td, uap->semid, uap->semnum, cmd, &semun,
272 return (kern_semctl(td, uap->semid, uap->semnum, cmd, &uap->arg,
276 struct svr4_sys_semget_args {
288 struct svr4_sys_semget_args *uap = v;
289 struct semget_args ap;
292 ap.nsems = uap->nsems;
293 ap.semflg = uap->semflg;
295 return sys_semget(td, &ap);
298 struct svr4_sys_semop_args {
301 struct svr4_sembuf * sops;
310 struct svr4_sys_semop_args *uap = v;
311 struct semop_args ap;
313 ap.semid = uap->semid;
314 /* These are the same */
315 ap.sops = (struct sembuf *) uap->sops;
316 ap.nsops = uap->nsops;
318 return sys_semop(td, &ap);
322 svr4_sys_semsys(td, uap)
324 struct svr4_sys_semsys_args *uap;
327 DPRINTF(("svr4_semsys(%d)\n", uap->what));
331 return svr4_semctl(td, uap);
333 return svr4_semget(td, uap);
335 return svr4_semop(td, uap);
341 MODULE_DEPEND(svr4elf, sysvsem, 1, 1, 1);
346 bsd_to_svr4_msqid_ds(bds, sds)
347 const struct msqid_ds *bds;
348 struct svr4_msqid_ds *sds;
350 bzero(sds, sizeof(*sds));
351 bsd_to_svr4_ipc_perm(&bds->msg_perm, &sds->msg_perm);
352 sds->msg_first = (struct svr4_msg *) bds->msg_first;
353 sds->msg_last = (struct svr4_msg *) bds->msg_last;
354 sds->msg_cbytes = bds->msg_cbytes;
355 sds->msg_qnum = bds->msg_qnum;
356 sds->msg_qbytes = bds->msg_qbytes;
357 sds->msg_lspid = bds->msg_lspid;
358 sds->msg_lrpid = bds->msg_lrpid;
359 sds->msg_stime = bds->msg_stime;
360 sds->msg_rtime = bds->msg_rtime;
361 sds->msg_ctime = bds->msg_ctime;
365 svr4_to_bsd_msqid_ds(sds, bds)
366 const struct svr4_msqid_ds *sds;
367 struct msqid_ds *bds;
369 svr4_to_bsd_ipc_perm(&sds->msg_perm, &bds->msg_perm);
370 bds->msg_first = (struct msg *) sds->msg_first;
371 bds->msg_last = (struct msg *) sds->msg_last;
372 bds->msg_cbytes = sds->msg_cbytes;
373 bds->msg_qnum = sds->msg_qnum;
374 bds->msg_qbytes = sds->msg_qbytes;
375 bds->msg_lspid = sds->msg_lspid;
376 bds->msg_lrpid = sds->msg_lrpid;
377 bds->msg_stime = sds->msg_stime;
378 bds->msg_rtime = sds->msg_rtime;
379 bds->msg_ctime = sds->msg_ctime;
382 struct svr4_sys_msgsnd_args {
395 struct svr4_sys_msgsnd_args *uap = v;
396 struct msgsnd_args ap;
398 ap.msqid = uap->msqid;
400 ap.msgsz = uap->msgsz;
401 ap.msgflg = uap->msgflg;
403 return sys_msgsnd(td, &ap);
406 struct svr4_sys_msgrcv_args {
420 struct svr4_sys_msgrcv_args *uap = v;
421 struct msgrcv_args ap;
423 ap.msqid = uap->msqid;
425 ap.msgsz = uap->msgsz;
426 ap.msgtyp = uap->msgtyp;
427 ap.msgflg = uap->msgflg;
429 return sys_msgrcv(td, &ap);
432 struct svr4_sys_msgget_args {
443 struct svr4_sys_msgget_args *uap = v;
444 struct msgget_args ap;
447 ap.msgflg = uap->msgflg;
449 return sys_msgget(td, &ap);
452 struct svr4_sys_msgctl_args {
456 struct svr4_msqid_ds * buf;
464 struct svr4_sys_msgctl_args *uap = v;
465 struct svr4_msqid_ds ss;
471 error = kern_msgctl(td, uap->msqid, IPC_STAT, &bs);
474 bsd_to_svr4_msqid_ds(&bs, &ss);
475 return copyout(&ss, uap->buf, sizeof ss);
478 error = copyin(uap->buf, &ss, sizeof ss);
481 svr4_to_bsd_msqid_ds(&ss, &bs);
482 return (kern_msgctl(td, uap->msqid, IPC_SET, &bs));
485 return (kern_msgctl(td, uap->msqid, IPC_RMID, NULL));
493 svr4_sys_msgsys(td, uap)
495 struct svr4_sys_msgsys_args *uap;
498 DPRINTF(("svr4_msgsys(%d)\n", uap->what));
502 return svr4_msgsnd(td, uap);
504 return svr4_msgrcv(td, uap);
506 return svr4_msgget(td, uap);
508 return svr4_msgctl(td, uap);
514 MODULE_DEPEND(svr4elf, sysvmsg, 1, 1, 1);
520 bsd_to_svr4_shmid_ds(bds, sds)
521 const struct shmid_ds *bds;
522 struct svr4_shmid_ds *sds;
524 bzero(sds, sizeof(*sds));
525 bsd_to_svr4_ipc_perm(&bds->shm_perm, &sds->shm_perm);
526 sds->shm_segsz = bds->shm_segsz;
528 sds->shm_lpid = bds->shm_lpid;
529 sds->shm_cpid = bds->shm_cpid;
531 sds->shm_nattch = bds->shm_nattch;
532 sds->shm_cnattch = 0;
533 sds->shm_atime = bds->shm_atime;
534 sds->shm_dtime = bds->shm_dtime;
535 sds->shm_ctime = bds->shm_ctime;
539 svr4_to_bsd_shmid_ds(sds, bds)
540 const struct svr4_shmid_ds *sds;
541 struct shmid_ds *bds;
543 svr4_to_bsd_ipc_perm(&sds->shm_perm, &bds->shm_perm);
544 bds->shm_segsz = sds->shm_segsz;
545 bds->shm_lpid = sds->shm_lpid;
546 bds->shm_cpid = sds->shm_cpid;
547 bds->shm_nattch = sds->shm_nattch;
548 bds->shm_atime = sds->shm_atime;
549 bds->shm_dtime = sds->shm_dtime;
550 bds->shm_ctime = sds->shm_ctime;
553 struct svr4_sys_shmat_args {
565 struct svr4_sys_shmat_args *uap = v;
566 struct shmat_args ap;
568 ap.shmid = uap->shmid;
569 ap.shmaddr = uap->shmaddr;
570 ap.shmflg = uap->shmflg;
572 return sys_shmat(td, &ap);
575 struct svr4_sys_shmdt_args {
585 struct svr4_sys_shmdt_args *uap = v;
586 struct shmdt_args ap;
588 ap.shmaddr = uap->shmaddr;
590 return sys_shmdt(td, &ap);
593 struct svr4_sys_shmget_args {
605 struct svr4_sys_shmget_args *uap = v;
606 struct shmget_args ap;
610 ap.shmflg = uap->shmflg;
612 return sys_shmget(td, &ap);
615 struct svr4_sys_shmctl_args {
619 struct svr4_shmid_ds * buf;
627 struct svr4_sys_shmctl_args *uap = v;
629 struct svr4_shmid_ds ss;
633 if (uap->buf != NULL) {
637 case SVR4_SHM_UNLOCK:
638 error = copyin(uap->buf, &ss, sizeof(ss));
641 svr4_to_bsd_shmid_ds(&ss, &bs);
661 case SVR4_SHM_UNLOCK:
668 error = kern_shmctl(td, uap->shmid, cmd, &bs, &bufsize);
674 if (uap->buf != NULL) {
675 bsd_to_svr4_shmid_ds(&bs, &ss);
676 error = copyout(&ss, uap->buf, sizeof(ss));
685 svr4_sys_shmsys(td, uap)
687 struct svr4_sys_shmsys_args *uap;
690 DPRINTF(("svr4_shmsys(%d)\n", uap->what));
694 return svr4_shmat(td, uap);
696 return svr4_shmdt(td, uap);
698 return svr4_shmget(td, uap);
700 return svr4_shmctl(td, uap);
706 MODULE_DEPEND(svr4elf, sysvshm, 1, 1, 1);