2 * Copyright (c) 1995 Scott Bartram
3 * Copyright (c) 1995 Steven Wallace
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. The name of the author may not be used to endorse or promote products
12 * derived from this software without specific prior written permission
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 #include <sys/cdefs.h>
27 __FBSDID("$FreeBSD$");
29 #include <sys/param.h>
30 #include <sys/systm.h>
31 #include <sys/limits.h>
35 #include <sys/syscallsubr.h>
36 #include <sys/sysproto.h>
38 #include <i386/ibcs2/ibcs2_types.h>
39 #include <i386/ibcs2/ibcs2_signal.h>
40 #include <i386/ibcs2/ibcs2_proto.h>
41 #include <i386/ibcs2/ibcs2_util.h>
42 #include <i386/ibcs2/ibcs2_ipc.h>
44 #define IBCS2_IPC_RMID 0
45 #define IBCS2_IPC_SET 1
46 #define IBCS2_IPC_STAT 2
47 #define IBCS2_SETVAL 8
51 static void cvt_msqid2imsqid(struct msqid_ds *, struct ibcs2_msqid_ds *);
52 static void cvt_imsqid2msqid(struct ibcs2_msqid_ds *, struct msqid_ds *);
54 static void cvt_sem2isem(struct sem *, struct ibcs2_sem *);
55 static void cvt_isem2sem(struct ibcs2_sem *, struct sem *);
57 static void cvt_semid2isemid(struct semid_ds *, struct ibcs2_semid_ds *);
58 static void cvt_isemid2semid(struct ibcs2_semid_ds *, struct semid_ds *);
59 static void cvt_shmid2ishmid(struct shmid_ds *, struct ibcs2_shmid_ds *);
60 static void cvt_ishmid2shmid(struct ibcs2_shmid_ds *, struct shmid_ds *);
61 static void cvt_perm2iperm(struct ipc_perm *, struct ibcs2_ipc_perm *);
62 static void cvt_iperm2perm(struct ibcs2_ipc_perm *, struct ipc_perm *);
70 cvt_msqid2imsqid(bp, ibp)
72 struct ibcs2_msqid_ds *ibp;
74 cvt_perm2iperm(&bp->msg_perm, &ibp->msg_perm);
75 ibp->msg_first = bp->msg_first;
76 ibp->msg_last = bp->msg_last;
77 ibp->msg_cbytes = (u_short)bp->msg_cbytes;
78 ibp->msg_qnum = (u_short)bp->msg_qnum;
79 ibp->msg_qbytes = (u_short)bp->msg_qbytes;
80 ibp->msg_lspid = (u_short)bp->msg_lspid;
81 ibp->msg_lrpid = (u_short)bp->msg_lrpid;
82 ibp->msg_stime = bp->msg_stime;
83 ibp->msg_rtime = bp->msg_rtime;
84 ibp->msg_ctime = bp->msg_ctime;
89 cvt_imsqid2msqid(ibp, bp)
90 struct ibcs2_msqid_ds *ibp;
93 cvt_iperm2perm(&ibp->msg_perm, &bp->msg_perm);
94 bp->msg_first = ibp->msg_first;
95 bp->msg_last = ibp->msg_last;
96 bp->msg_cbytes = ibp->msg_cbytes;
97 bp->msg_qnum = ibp->msg_qnum;
98 bp->msg_qbytes = ibp->msg_qbytes;
99 bp->msg_lspid = ibp->msg_lspid;
100 bp->msg_lrpid = ibp->msg_lrpid;
101 bp->msg_stime = ibp->msg_stime;
102 bp->msg_rtime = ibp->msg_rtime;
103 bp->msg_ctime = ibp->msg_ctime;
107 struct ibcs2_msgget_args {
114 ibcs2_msgget(struct thread *td, void *v)
116 struct ibcs2_msgget_args *uap = v;
117 struct msgget_args ap;
120 ap.msgflg = uap->msgflg;
121 return msgget(td, &ap);
124 struct ibcs2_msgctl_args {
128 struct ibcs2_msqid_ds *buf;
132 ibcs2_msgctl(struct thread *td, void *v)
134 struct ibcs2_msgctl_args *uap = v;
135 struct ibcs2_msqid_ds is;
141 error = kern_msgctl(td, uap->msqid, IPC_STAT, &bs);
143 cvt_msqid2imsqid(&bs, &is);
144 error = copyout(&is, uap->buf, sizeof(is));
148 error = copyin(uap->buf, &is, sizeof(is));
151 cvt_imsqid2msqid(&is, &bs);
152 return (kern_msgctl(td, uap->msqid, IPC_SET, &bs));
154 return (kern_msgctl(td, uap->msqid, IPC_RMID, NULL));
159 struct ibcs2_msgrcv_args {
169 ibcs2_msgrcv(struct thread *td, void *v)
171 struct ibcs2_msgrcv_args *uap = v;
172 struct msgrcv_args ap;
174 ap.msqid = uap->msqid;
176 ap.msgsz = uap->msgsz;
177 ap.msgtyp = uap->msgtyp;
178 ap.msgflg = uap->msgflg;
179 return (msgrcv(td, &ap));
182 struct ibcs2_msgsnd_args {
191 ibcs2_msgsnd(struct thread *td, void *v)
193 struct ibcs2_msgsnd_args *uap = v;
194 struct msgsnd_args ap;
196 ap.msqid = uap->msqid;
198 ap.msgsz = uap->msgsz;
199 ap.msgflg = uap->msgflg;
200 return (msgsnd(td, &ap));
204 ibcs2_msgsys(td, uap)
206 struct ibcs2_msgsys_args *uap;
208 switch (uap->which) {
210 return (ibcs2_msgget(td, uap));
212 return (ibcs2_msgctl(td, uap));
214 return (ibcs2_msgrcv(td, uap));
216 return (ibcs2_msgsnd(td, uap));
227 cvt_sem2isem(bp, ibp)
229 struct ibcs2_sem *ibp;
231 ibp->semval = bp->semval;
232 ibp->sempid = bp->sempid;
233 ibp->semncnt = bp->semncnt;
234 ibp->semzcnt = bp->semzcnt;
239 cvt_isem2sem(ibp, bp)
240 struct ibcs2_sem *ibp;
243 bp->semval = ibp->semval;
244 bp->sempid = ibp->sempid;
245 bp->semncnt = ibp->semncnt;
246 bp->semzcnt = ibp->semzcnt;
252 cvt_iperm2perm(ipp, pp)
253 struct ibcs2_ipc_perm *ipp;
258 pp->cuid = ipp->cuid;
259 pp->cgid = ipp->cgid;
260 pp->mode = ipp->mode;
266 cvt_perm2iperm(pp, ipp)
268 struct ibcs2_ipc_perm *ipp;
272 ipp->cuid = pp->cuid;
273 ipp->cgid = pp->cgid;
274 ipp->mode = pp->mode;
280 cvt_semid2isemid(bp, ibp)
282 struct ibcs2_semid_ds *ibp;
284 cvt_perm2iperm(&bp->sem_perm, &ibp->sem_perm);
285 ibp->sem_base = (struct ibcs2_sem *)bp->sem_base;
286 ibp->sem_nsems = bp->sem_nsems;
287 ibp->sem_otime = bp->sem_otime;
288 ibp->sem_ctime = bp->sem_ctime;
293 cvt_isemid2semid(ibp, bp)
294 struct ibcs2_semid_ds *ibp;
297 cvt_iperm2perm(&ibp->sem_perm, &bp->sem_perm);
298 bp->sem_base = (struct sem *)ibp->sem_base;
299 bp->sem_nsems = ibp->sem_nsems;
300 bp->sem_otime = ibp->sem_otime;
301 bp->sem_ctime = ibp->sem_ctime;
305 struct ibcs2_semctl_args {
314 ibcs2_semctl(struct thread *td, void *v)
316 struct ibcs2_semctl_args *uap = v;
317 struct ibcs2_semid_ds is;
326 error = kern_semctl(td, uap->semid, uap->semnum, IPC_STAT,
330 cvt_semid2isemid(&bs, &is);
331 error = copyout(&is, uap->arg.buf, sizeof(is));
333 td->td_retval[0] = rval;
337 error = copyin(uap->arg.buf, &is, sizeof(is));
340 cvt_isemid2semid(&is, &bs);
342 return (kern_semctl(td, uap->semid, uap->semnum, IPC_SET,
343 &semun, td->td_retval));
346 return (kern_semctl(td, uap->semid, uap->semnum, uap->cmd, &uap->arg,
350 struct ibcs2_semget_args {
358 ibcs2_semget(struct thread *td, void *v)
360 struct ibcs2_semget_args *uap = v;
361 struct semget_args ap;
364 ap.nsems = uap->nsems;
365 ap.semflg = uap->semflg;
366 return (semget(td, &ap));
369 struct ibcs2_semop_args {
377 ibcs2_semop(struct thread *td, void *v)
379 struct ibcs2_semop_args *uap = v;
380 struct semop_args ap;
382 ap.semid = uap->semid;
384 ap.nsops = uap->nsops;
385 return (semop(td, &ap));
389 ibcs2_semsys(td, uap)
391 struct ibcs2_semsys_args *uap;
394 switch (uap->which) {
396 return (ibcs2_semctl(td, uap));
398 return (ibcs2_semget(td, uap));
400 return (ibcs2_semop(td, uap));
411 cvt_shmid2ishmid(bp, ibp)
413 struct ibcs2_shmid_ds *ibp;
415 cvt_perm2iperm(&bp->shm_perm, &ibp->shm_perm);
416 ibp->shm_segsz = bp->shm_segsz;
417 ibp->shm_lpid = bp->shm_lpid;
418 ibp->shm_cpid = bp->shm_cpid;
419 if (bp->shm_nattch > SHRT_MAX)
420 ibp->shm_nattch = SHRT_MAX;
422 ibp->shm_nattch = bp->shm_nattch;
423 ibp->shm_cnattch = 0; /* ignored anyway */
424 ibp->shm_atime = bp->shm_atime;
425 ibp->shm_dtime = bp->shm_dtime;
426 ibp->shm_ctime = bp->shm_ctime;
431 cvt_ishmid2shmid(ibp, bp)
432 struct ibcs2_shmid_ds *ibp;
435 cvt_iperm2perm(&ibp->shm_perm, &bp->shm_perm);
436 bp->shm_segsz = ibp->shm_segsz;
437 bp->shm_lpid = ibp->shm_lpid;
438 bp->shm_cpid = ibp->shm_cpid;
439 bp->shm_nattch = ibp->shm_nattch;
440 bp->shm_atime = ibp->shm_atime;
441 bp->shm_dtime = ibp->shm_dtime;
442 bp->shm_ctime = ibp->shm_ctime;
446 struct ibcs2_shmat_args {
454 ibcs2_shmat(struct thread *td, void *v)
456 struct ibcs2_shmat_args *uap = v;
457 struct shmat_args ap;
459 ap.shmid = uap->shmid;
460 ap.shmaddr = uap->shmaddr;
461 ap.shmflg = uap->shmflg;
462 return (shmat(td, &ap));
465 struct ibcs2_shmctl_args {
469 struct ibcs2_shmid_ds *buf;
473 ibcs2_shmctl(struct thread *td, void *v)
475 struct ibcs2_shmctl_args *uap = v;
476 struct ibcs2_shmid_ds is;
482 error = kern_shmctl(td, uap->shmid, IPC_STAT, &bs, NULL);
485 cvt_shmid2ishmid(&bs, &is);
486 return (copyout(&is, uap->buf, sizeof(is)));
489 error = copyin(uap->buf, &is, sizeof(is));
492 cvt_ishmid2shmid(&is, &bs);
493 return (kern_shmctl(td, uap->shmid, IPC_SET, &bs, NULL));
502 return (kern_shmctl(td, uap->shmid, uap->cmd, NULL, NULL));
505 struct ibcs2_shmdt_args {
511 ibcs2_shmdt(struct thread *td, void *v)
513 struct ibcs2_shmdt_args *uap = v;
514 struct shmdt_args ap;
516 ap.shmaddr = uap->shmaddr;
517 return (shmdt(td, &ap));
520 struct ibcs2_shmget_args {
528 ibcs2_shmget(struct thread *td, void *v)
530 struct ibcs2_shmget_args *uap = v;
531 struct shmget_args ap;
535 ap.shmflg = uap->shmflg;
536 return (shmget(td, &ap));
540 ibcs2_shmsys(td, uap)
542 struct ibcs2_shmsys_args *uap;
545 switch (uap->which) {
547 return (ibcs2_shmat(td, uap));
549 return (ibcs2_shmctl(td, uap));
551 return (ibcs2_shmdt(td, uap));
553 return (ibcs2_shmget(td, uap));
558 MODULE_DEPEND(ibcs2, sysvmsg, 1, 1, 1);
559 MODULE_DEPEND(ibcs2, sysvsem, 1, 1, 1);
560 MODULE_DEPEND(ibcs2, sysvshm, 1, 1, 1);