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 #if defined(SYSVMSG) || defined(SYSVSHM) || defined(SYSVSEM)
90 static void svr4_to_bsd_ipc_perm(const struct svr4_ipc_perm *,
92 static void bsd_to_svr4_ipc_perm(const struct ipc_perm *,
93 struct svr4_ipc_perm *);
97 static void bsd_to_svr4_semid_ds(const struct semid_ds *,
98 struct svr4_semid_ds *);
99 static void svr4_to_bsd_semid_ds(const struct svr4_semid_ds *,
101 static int svr4_semop(struct thread *, void *);
102 static int svr4_semget(struct thread *, void *);
103 static int svr4_semctl(struct thread *, void *);
107 static void bsd_to_svr4_msqid_ds(const struct msqid_ds *,
108 struct svr4_msqid_ds *);
109 static void svr4_to_bsd_msqid_ds(const struct svr4_msqid_ds *,
111 static int svr4_msgsnd(struct thread *, void *);
112 static int svr4_msgrcv(struct thread *, void *);
113 static int svr4_msgget(struct thread *, void *);
114 static int svr4_msgctl(struct thread *, void *);
118 static void bsd_to_svr4_shmid_ds(const struct shmid_ds *,
119 struct svr4_shmid_ds *);
120 static void svr4_to_bsd_shmid_ds(const struct svr4_shmid_ds *,
122 static int svr4_shmat(struct thread *, void *);
123 static int svr4_shmdt(struct thread *, void *);
124 static int svr4_shmget(struct thread *, void *);
125 static int svr4_shmctl(struct thread *, void *);
128 #if defined(SYSVMSG) || defined(SYSVSHM) || defined(SYSVSEM)
131 svr4_to_bsd_ipc_perm(spp, bpp)
132 const struct svr4_ipc_perm *spp;
133 struct ipc_perm *bpp;
138 bpp->cuid = spp->cuid;
139 bpp->cgid = spp->cgid;
140 bpp->mode = spp->mode;
145 bsd_to_svr4_ipc_perm(bpp, spp)
146 const struct ipc_perm *bpp;
147 struct svr4_ipc_perm *spp;
152 spp->cuid = bpp->cuid;
153 spp->cgid = bpp->cgid;
154 spp->mode = bpp->mode;
161 bsd_to_svr4_semid_ds(bds, sds)
162 const struct semid_ds *bds;
163 struct svr4_semid_ds *sds;
165 bzero(sds, sizeof(*sds));
166 bsd_to_svr4_ipc_perm(&bds->sem_perm, &sds->sem_perm);
167 sds->sem_base = (struct svr4_sem *) bds->sem_base;
168 sds->sem_nsems = bds->sem_nsems;
169 sds->sem_otime = bds->sem_otime;
170 sds->sem_ctime = bds->sem_ctime;
174 svr4_to_bsd_semid_ds(sds, bds)
175 const struct svr4_semid_ds *sds;
176 struct semid_ds *bds;
178 svr4_to_bsd_ipc_perm(&sds->sem_perm, &bds->sem_perm);
179 bds->sem_base = (struct sem *) bds->sem_base;
180 bds->sem_nsems = sds->sem_nsems;
181 bds->sem_otime = sds->sem_otime;
182 bds->sem_ctime = sds->sem_ctime;
185 struct svr4_sys_semctl_args {
198 struct svr4_sys_semctl_args *uap = v;
199 struct svr4_semid_ds ss;
206 case SVR4_SEM_GETZCNT:
210 case SVR4_SEM_GETNCNT:
214 case SVR4_SEM_GETPID:
218 case SVR4_SEM_GETVAL:
222 case SVR4_SEM_SETVAL:
226 case SVR4_SEM_GETALL:
230 case SVR4_SEM_SETALL:
237 error = kern_semctl(td, uap->semid, uap->semnum, cmd, &semun,
241 bsd_to_svr4_semid_ds(&bs, &ss);
242 error = copyout(&ss, uap->arg.buf, sizeof(ss));
244 td->td_retval[0] = rval;
249 error = copyin(uap->arg.buf, (caddr_t) &ss, sizeof ss);
252 svr4_to_bsd_semid_ds(&ss, &bs);
254 return (kern_semctl(td, uap->semid, uap->semnum, cmd, &semun,
265 return (kern_semctl(td, uap->semid, uap->semnum, cmd, &uap->arg,
269 struct svr4_sys_semget_args {
281 struct svr4_sys_semget_args *uap = v;
282 struct semget_args ap;
285 ap.nsems = uap->nsems;
286 ap.semflg = uap->semflg;
288 return sys_semget(td, &ap);
291 struct svr4_sys_semop_args {
294 struct svr4_sembuf * sops;
303 struct svr4_sys_semop_args *uap = v;
304 struct semop_args ap;
306 ap.semid = uap->semid;
307 /* These are the same */
308 ap.sops = (struct sembuf *) uap->sops;
309 ap.nsops = uap->nsops;
311 return sys_semop(td, &ap);
315 svr4_sys_semsys(td, uap)
317 struct svr4_sys_semsys_args *uap;
320 DPRINTF(("svr4_semsys(%d)\n", uap->what));
324 return svr4_semctl(td, uap);
326 return svr4_semget(td, uap);
328 return svr4_semop(td, uap);
334 MODULE_DEPEND(svr4elf, sysvsem, 1, 1, 1);
339 bsd_to_svr4_msqid_ds(bds, sds)
340 const struct msqid_ds *bds;
341 struct svr4_msqid_ds *sds;
343 bzero(sds, sizeof(*sds));
344 bsd_to_svr4_ipc_perm(&bds->msg_perm, &sds->msg_perm);
345 sds->msg_first = (struct svr4_msg *) bds->msg_first;
346 sds->msg_last = (struct svr4_msg *) bds->msg_last;
347 sds->msg_cbytes = bds->msg_cbytes;
348 sds->msg_qnum = bds->msg_qnum;
349 sds->msg_qbytes = bds->msg_qbytes;
350 sds->msg_lspid = bds->msg_lspid;
351 sds->msg_lrpid = bds->msg_lrpid;
352 sds->msg_stime = bds->msg_stime;
353 sds->msg_rtime = bds->msg_rtime;
354 sds->msg_ctime = bds->msg_ctime;
358 svr4_to_bsd_msqid_ds(sds, bds)
359 const struct svr4_msqid_ds *sds;
360 struct msqid_ds *bds;
362 svr4_to_bsd_ipc_perm(&sds->msg_perm, &bds->msg_perm);
363 bds->msg_first = (struct msg *) sds->msg_first;
364 bds->msg_last = (struct msg *) sds->msg_last;
365 bds->msg_cbytes = sds->msg_cbytes;
366 bds->msg_qnum = sds->msg_qnum;
367 bds->msg_qbytes = sds->msg_qbytes;
368 bds->msg_lspid = sds->msg_lspid;
369 bds->msg_lrpid = sds->msg_lrpid;
370 bds->msg_stime = sds->msg_stime;
371 bds->msg_rtime = sds->msg_rtime;
372 bds->msg_ctime = sds->msg_ctime;
375 struct svr4_sys_msgsnd_args {
388 struct svr4_sys_msgsnd_args *uap = v;
389 struct msgsnd_args ap;
391 ap.msqid = uap->msqid;
393 ap.msgsz = uap->msgsz;
394 ap.msgflg = uap->msgflg;
396 return sys_msgsnd(td, &ap);
399 struct svr4_sys_msgrcv_args {
413 struct svr4_sys_msgrcv_args *uap = v;
414 struct msgrcv_args ap;
416 ap.msqid = uap->msqid;
418 ap.msgsz = uap->msgsz;
419 ap.msgtyp = uap->msgtyp;
420 ap.msgflg = uap->msgflg;
422 return sys_msgrcv(td, &ap);
425 struct svr4_sys_msgget_args {
436 struct svr4_sys_msgget_args *uap = v;
437 struct msgget_args ap;
440 ap.msgflg = uap->msgflg;
442 return sys_msgget(td, &ap);
445 struct svr4_sys_msgctl_args {
449 struct svr4_msqid_ds * buf;
457 struct svr4_sys_msgctl_args *uap = v;
458 struct svr4_msqid_ds ss;
464 error = kern_msgctl(td, uap->msqid, IPC_STAT, &bs);
467 bsd_to_svr4_msqid_ds(&bs, &ss);
468 return copyout(&ss, uap->buf, sizeof ss);
471 error = copyin(uap->buf, &ss, sizeof ss);
474 svr4_to_bsd_msqid_ds(&ss, &bs);
475 return (kern_msgctl(td, uap->msqid, IPC_SET, &bs));
478 return (kern_msgctl(td, uap->msqid, IPC_RMID, NULL));
486 svr4_sys_msgsys(td, uap)
488 struct svr4_sys_msgsys_args *uap;
491 DPRINTF(("svr4_msgsys(%d)\n", uap->what));
495 return svr4_msgsnd(td, uap);
497 return svr4_msgrcv(td, uap);
499 return svr4_msgget(td, uap);
501 return svr4_msgctl(td, uap);
507 MODULE_DEPEND(svr4elf, sysvmsg, 1, 1, 1);
513 bsd_to_svr4_shmid_ds(bds, sds)
514 const struct shmid_ds *bds;
515 struct svr4_shmid_ds *sds;
517 bzero(sds, sizeof(*sds));
518 bsd_to_svr4_ipc_perm(&bds->shm_perm, &sds->shm_perm);
519 sds->shm_segsz = bds->shm_segsz;
521 sds->shm_lpid = bds->shm_lpid;
522 sds->shm_cpid = bds->shm_cpid;
524 sds->shm_nattch = bds->shm_nattch;
525 sds->shm_cnattch = 0;
526 sds->shm_atime = bds->shm_atime;
527 sds->shm_dtime = bds->shm_dtime;
528 sds->shm_ctime = bds->shm_ctime;
532 svr4_to_bsd_shmid_ds(sds, bds)
533 const struct svr4_shmid_ds *sds;
534 struct shmid_ds *bds;
536 svr4_to_bsd_ipc_perm(&sds->shm_perm, &bds->shm_perm);
537 bds->shm_segsz = sds->shm_segsz;
538 bds->shm_lpid = sds->shm_lpid;
539 bds->shm_cpid = sds->shm_cpid;
540 bds->shm_nattch = sds->shm_nattch;
541 bds->shm_atime = sds->shm_atime;
542 bds->shm_dtime = sds->shm_dtime;
543 bds->shm_ctime = sds->shm_ctime;
546 struct svr4_sys_shmat_args {
558 struct svr4_sys_shmat_args *uap = v;
559 struct shmat_args ap;
561 ap.shmid = uap->shmid;
562 ap.shmaddr = uap->shmaddr;
563 ap.shmflg = uap->shmflg;
565 return sys_shmat(td, &ap);
568 struct svr4_sys_shmdt_args {
578 struct svr4_sys_shmdt_args *uap = v;
579 struct shmdt_args ap;
581 ap.shmaddr = uap->shmaddr;
583 return sys_shmdt(td, &ap);
586 struct svr4_sys_shmget_args {
598 struct svr4_sys_shmget_args *uap = v;
599 struct shmget_args ap;
603 ap.shmflg = uap->shmflg;
605 return sys_shmget(td, &ap);
608 struct svr4_sys_shmctl_args {
612 struct svr4_shmid_ds * buf;
620 struct svr4_sys_shmctl_args *uap = v;
622 struct svr4_shmid_ds ss;
626 if (uap->buf != NULL) {
630 case SVR4_SHM_UNLOCK:
631 error = copyin(uap->buf, &ss, sizeof(ss));
634 svr4_to_bsd_shmid_ds(&ss, &bs);
654 case SVR4_SHM_UNLOCK:
661 error = kern_shmctl(td, uap->shmid, cmd, &bs, &bufsize);
667 if (uap->buf != NULL) {
668 bsd_to_svr4_shmid_ds(&bs, &ss);
669 error = copyout(&ss, uap->buf, sizeof(ss));
678 svr4_sys_shmsys(td, uap)
680 struct svr4_sys_shmsys_args *uap;
683 DPRINTF(("svr4_shmsys(%d)\n", uap->what));
687 return svr4_shmat(td, uap);
689 return svr4_shmdt(td, uap);
691 return svr4_shmget(td, uap);
693 return svr4_shmctl(td, uap);
699 MODULE_DEPEND(svr4elf, sysvshm, 1, 1, 1);