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.
17 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
18 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
21 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 * POSSIBILITY OF SUCH DAMAGE.
30 * Portions of this code have been derived from software contributed
31 * to the FreeBSD Project by Mark Newton.
33 * Copyright (c) 1999 Mark Newton
34 * All rights reserved.
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
39 * 1. Redistributions of source code must retain the above copyright
40 * notice, this list of conditions and the following disclaimer.
41 * 2. Redistributions in binary form must reproduce the above copyright
42 * notice, this list of conditions and the following disclaimer in the
43 * documentation and/or other materials provided with the distribution.
44 * 3. The name of the author may not be used to endorse or promote products
45 * derived from this software without specific prior written permission
47 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
48 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
49 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
50 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
51 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
52 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
53 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
54 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
55 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
56 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
58 * XXX- This code is presently a no-op on FreeBSD (and isn't compiled due
59 * to preprocessor conditionals). A nice project for a kernel hacking
60 * novice might be to MakeItGo, but I have more important fish to fry
63 * Derived from: $NetBSD: svr4_ipc.c,v 1.7 1998/10/19 22:43:00 tron Exp $
66 #include <sys/cdefs.h>
67 __FBSDID("$FreeBSD$");
69 #include "opt_sysvipc.h"
71 #include <sys/param.h>
77 #include <sys/syscallsubr.h>
78 #include <sys/sysproto.h>
79 #include <sys/systm.h>
82 #include <compat/svr4/svr4.h>
83 #include <compat/svr4/svr4_types.h>
84 #include <compat/svr4/svr4_signal.h>
85 #include <compat/svr4/svr4_proto.h>
86 #include <compat/svr4/svr4_util.h>
87 #include <compat/svr4/svr4_ipc.h>
89 static void svr4_to_bsd_ipc_perm(const struct svr4_ipc_perm *,
91 static void bsd_to_svr4_ipc_perm(const struct ipc_perm *,
92 struct svr4_ipc_perm *);
93 static void bsd_to_svr4_semid_ds(const struct semid_ds *,
94 struct svr4_semid_ds *);
95 static void svr4_to_bsd_semid_ds(const struct svr4_semid_ds *,
97 static int svr4_semop(struct thread *, void *);
98 static int svr4_semget(struct thread *, void *);
99 static int svr4_semctl(struct thread *, void *);
100 static void bsd_to_svr4_msqid_ds(const struct msqid_ds *,
101 struct svr4_msqid_ds *);
102 static void svr4_to_bsd_msqid_ds(const struct svr4_msqid_ds *,
104 static int svr4_msgsnd(struct thread *, void *);
105 static int svr4_msgrcv(struct thread *, void *);
106 static int svr4_msgget(struct thread *, void *);
107 static int svr4_msgctl(struct thread *, void *);
108 static void bsd_to_svr4_shmid_ds(const struct shmid_ds *,
109 struct svr4_shmid_ds *);
110 static void svr4_to_bsd_shmid_ds(const struct svr4_shmid_ds *,
112 static int svr4_shmat(struct thread *, void *);
113 static int svr4_shmdt(struct thread *, void *);
114 static int svr4_shmget(struct thread *, void *);
115 static int svr4_shmctl(struct thread *, void *);
118 svr4_to_bsd_ipc_perm(spp, bpp)
119 const struct svr4_ipc_perm *spp;
120 struct ipc_perm *bpp;
125 bpp->cuid = spp->cuid;
126 bpp->cgid = spp->cgid;
127 bpp->mode = spp->mode;
132 bsd_to_svr4_ipc_perm(bpp, spp)
133 const struct ipc_perm *bpp;
134 struct svr4_ipc_perm *spp;
139 spp->cuid = bpp->cuid;
140 spp->cgid = bpp->cgid;
141 spp->mode = bpp->mode;
146 bsd_to_svr4_semid_ds(bds, sds)
147 const struct semid_ds *bds;
148 struct svr4_semid_ds *sds;
150 bzero(sds, sizeof(*sds));
151 bsd_to_svr4_ipc_perm(&bds->sem_perm, &sds->sem_perm);
152 sds->sem_base = (struct svr4_sem *) bds->sem_base;
153 sds->sem_nsems = bds->sem_nsems;
154 sds->sem_otime = bds->sem_otime;
155 sds->sem_ctime = bds->sem_ctime;
159 svr4_to_bsd_semid_ds(sds, bds)
160 const struct svr4_semid_ds *sds;
161 struct semid_ds *bds;
163 svr4_to_bsd_ipc_perm(&sds->sem_perm, &bds->sem_perm);
164 bds->sem_base = (struct sem *) bds->sem_base;
165 bds->sem_nsems = sds->sem_nsems;
166 bds->sem_otime = sds->sem_otime;
167 bds->sem_ctime = sds->sem_ctime;
170 struct svr4_sys_semctl_args {
183 struct svr4_sys_semctl_args *uap = v;
184 struct svr4_semid_ds ss;
191 case SVR4_SEM_GETZCNT:
195 case SVR4_SEM_GETNCNT:
199 case SVR4_SEM_GETPID:
203 case SVR4_SEM_GETVAL:
207 case SVR4_SEM_SETVAL:
211 case SVR4_SEM_GETALL:
215 case SVR4_SEM_SETALL:
222 error = kern_semctl(td, uap->semid, uap->semnum, cmd, &semun,
226 bsd_to_svr4_semid_ds(&bs, &ss);
227 error = copyout(&ss, uap->arg.buf, sizeof(ss));
229 td->td_retval[0] = rval;
234 error = copyin(uap->arg.buf, (caddr_t) &ss, sizeof ss);
237 svr4_to_bsd_semid_ds(&ss, &bs);
239 return (kern_semctl(td, uap->semid, uap->semnum, cmd, &semun,
250 return (kern_semctl(td, uap->semid, uap->semnum, cmd, &uap->arg,
254 struct svr4_sys_semget_args {
266 struct svr4_sys_semget_args *uap = v;
267 struct semget_args ap;
270 ap.nsems = uap->nsems;
271 ap.semflg = uap->semflg;
273 return sys_semget(td, &ap);
276 struct svr4_sys_semop_args {
279 struct svr4_sembuf * sops;
288 struct svr4_sys_semop_args *uap = v;
289 struct semop_args ap;
291 ap.semid = uap->semid;
292 /* These are the same */
293 ap.sops = (struct sembuf *) uap->sops;
294 ap.nsops = uap->nsops;
296 return sys_semop(td, &ap);
300 svr4_sys_semsys(td, uap)
302 struct svr4_sys_semsys_args *uap;
305 DPRINTF(("svr4_semsys(%d)\n", uap->what));
309 return svr4_semctl(td, uap);
311 return svr4_semget(td, uap);
313 return svr4_semop(td, uap);
321 bsd_to_svr4_msqid_ds(bds, sds)
322 const struct msqid_ds *bds;
323 struct svr4_msqid_ds *sds;
325 bzero(sds, sizeof(*sds));
326 bsd_to_svr4_ipc_perm(&bds->msg_perm, &sds->msg_perm);
327 sds->msg_first = (struct svr4_msg *) bds->msg_first;
328 sds->msg_last = (struct svr4_msg *) bds->msg_last;
329 sds->msg_cbytes = bds->msg_cbytes;
330 sds->msg_qnum = bds->msg_qnum;
331 sds->msg_qbytes = bds->msg_qbytes;
332 sds->msg_lspid = bds->msg_lspid;
333 sds->msg_lrpid = bds->msg_lrpid;
334 sds->msg_stime = bds->msg_stime;
335 sds->msg_rtime = bds->msg_rtime;
336 sds->msg_ctime = bds->msg_ctime;
340 svr4_to_bsd_msqid_ds(sds, bds)
341 const struct svr4_msqid_ds *sds;
342 struct msqid_ds *bds;
344 svr4_to_bsd_ipc_perm(&sds->msg_perm, &bds->msg_perm);
345 bds->msg_first = (struct msg *) sds->msg_first;
346 bds->msg_last = (struct msg *) sds->msg_last;
347 bds->msg_cbytes = sds->msg_cbytes;
348 bds->msg_qnum = sds->msg_qnum;
349 bds->msg_qbytes = sds->msg_qbytes;
350 bds->msg_lspid = sds->msg_lspid;
351 bds->msg_lrpid = sds->msg_lrpid;
352 bds->msg_stime = sds->msg_stime;
353 bds->msg_rtime = sds->msg_rtime;
354 bds->msg_ctime = sds->msg_ctime;
357 struct svr4_sys_msgsnd_args {
370 struct svr4_sys_msgsnd_args *uap = v;
371 struct msgsnd_args ap;
373 ap.msqid = uap->msqid;
375 ap.msgsz = uap->msgsz;
376 ap.msgflg = uap->msgflg;
378 return sys_msgsnd(td, &ap);
381 struct svr4_sys_msgrcv_args {
395 struct svr4_sys_msgrcv_args *uap = v;
396 struct msgrcv_args ap;
398 ap.msqid = uap->msqid;
400 ap.msgsz = uap->msgsz;
401 ap.msgtyp = uap->msgtyp;
402 ap.msgflg = uap->msgflg;
404 return sys_msgrcv(td, &ap);
407 struct svr4_sys_msgget_args {
418 struct svr4_sys_msgget_args *uap = v;
419 struct msgget_args ap;
422 ap.msgflg = uap->msgflg;
424 return sys_msgget(td, &ap);
427 struct svr4_sys_msgctl_args {
431 struct svr4_msqid_ds * buf;
439 struct svr4_sys_msgctl_args *uap = v;
440 struct svr4_msqid_ds ss;
446 error = kern_msgctl(td, uap->msqid, IPC_STAT, &bs);
449 bsd_to_svr4_msqid_ds(&bs, &ss);
450 return copyout(&ss, uap->buf, sizeof ss);
453 error = copyin(uap->buf, &ss, sizeof ss);
456 svr4_to_bsd_msqid_ds(&ss, &bs);
457 return (kern_msgctl(td, uap->msqid, IPC_SET, &bs));
460 return (kern_msgctl(td, uap->msqid, IPC_RMID, NULL));
468 svr4_sys_msgsys(td, uap)
470 struct svr4_sys_msgsys_args *uap;
473 DPRINTF(("svr4_msgsys(%d)\n", uap->what));
477 return svr4_msgsnd(td, uap);
479 return svr4_msgrcv(td, uap);
481 return svr4_msgget(td, uap);
483 return svr4_msgctl(td, uap);
491 bsd_to_svr4_shmid_ds(bds, sds)
492 const struct shmid_ds *bds;
493 struct svr4_shmid_ds *sds;
495 bzero(sds, sizeof(*sds));
496 bsd_to_svr4_ipc_perm(&bds->shm_perm, &sds->shm_perm);
497 sds->shm_segsz = bds->shm_segsz;
499 sds->shm_lpid = bds->shm_lpid;
500 sds->shm_cpid = bds->shm_cpid;
502 sds->shm_nattch = bds->shm_nattch;
503 sds->shm_cnattch = 0;
504 sds->shm_atime = bds->shm_atime;
505 sds->shm_dtime = bds->shm_dtime;
506 sds->shm_ctime = bds->shm_ctime;
510 svr4_to_bsd_shmid_ds(sds, bds)
511 const struct svr4_shmid_ds *sds;
512 struct shmid_ds *bds;
514 svr4_to_bsd_ipc_perm(&sds->shm_perm, &bds->shm_perm);
515 bds->shm_segsz = sds->shm_segsz;
516 bds->shm_lpid = sds->shm_lpid;
517 bds->shm_cpid = sds->shm_cpid;
518 bds->shm_nattch = sds->shm_nattch;
519 bds->shm_atime = sds->shm_atime;
520 bds->shm_dtime = sds->shm_dtime;
521 bds->shm_ctime = sds->shm_ctime;
524 struct svr4_sys_shmat_args {
536 struct svr4_sys_shmat_args *uap = v;
537 struct shmat_args ap;
539 ap.shmid = uap->shmid;
540 ap.shmaddr = uap->shmaddr;
541 ap.shmflg = uap->shmflg;
543 return sys_shmat(td, &ap);
546 struct svr4_sys_shmdt_args {
556 struct svr4_sys_shmdt_args *uap = v;
557 struct shmdt_args ap;
559 ap.shmaddr = uap->shmaddr;
561 return sys_shmdt(td, &ap);
564 struct svr4_sys_shmget_args {
576 struct svr4_sys_shmget_args *uap = v;
577 struct shmget_args ap;
581 ap.shmflg = uap->shmflg;
583 return sys_shmget(td, &ap);
586 struct svr4_sys_shmctl_args {
590 struct svr4_shmid_ds * buf;
598 struct svr4_sys_shmctl_args *uap = v;
600 struct svr4_shmid_ds ss;
604 if (uap->buf != NULL) {
608 case SVR4_SHM_UNLOCK:
609 error = copyin(uap->buf, &ss, sizeof(ss));
612 svr4_to_bsd_shmid_ds(&ss, &bs);
632 case SVR4_SHM_UNLOCK:
639 error = kern_shmctl(td, uap->shmid, cmd, &bs, &bufsize);
645 if (uap->buf != NULL) {
646 bsd_to_svr4_shmid_ds(&bs, &ss);
647 error = copyout(&ss, uap->buf, sizeof(ss));
656 svr4_sys_shmsys(td, uap)
658 struct svr4_sys_shmsys_args *uap;
661 DPRINTF(("svr4_shmsys(%d)\n", uap->what));
665 return svr4_shmat(td, uap);
667 return svr4_shmdt(td, uap);
669 return svr4_shmget(td, uap);
671 return svr4_shmctl(td, uap);
677 MODULE_DEPEND(svr4elf, sysvshm, 1, 1, 1);
678 MODULE_DEPEND(svr4elf, sysvmsg, 1, 1, 1);
679 MODULE_DEPEND(svr4elf, sysvsem, 1, 1, 1);