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.
25 * $Id: ibcs2_ipc.c,v 1.13 1997/11/06 19:28:28 phk Exp $
28 #include <sys/param.h>
29 #include <sys/systm.h>
33 #include <sys/sysproto.h>
35 #include <i386/ibcs2/ibcs2_types.h>
36 #include <i386/ibcs2/ibcs2_signal.h>
37 #include <i386/ibcs2/ibcs2_proto.h>
38 #include <i386/ibcs2/ibcs2_util.h>
39 #include <i386/ibcs2/ibcs2_ipc.h>
41 #define IBCS2_IPC_RMID 0
42 #define IBCS2_IPC_SET 1
43 #define IBCS2_IPC_STAT 2
44 #define IBCS2_SETVAL 8
48 static void cvt_msqid2imsqid __P((struct msqid_ds *, struct ibcs2_msqid_ds *));
49 static void cvt_imsqid2msqid __P((struct ibcs2_msqid_ds *, struct msqid_ds *));
51 static void cvt_sem2isem __P((struct sem *, struct ibcs2_sem *));
52 static void cvt_isem2sem __P((struct ibcs2_sem *, struct sem *));
54 static void cvt_semid2isemid __P((struct semid_ds *, struct ibcs2_semid_ds *));
55 static void cvt_isemid2semid __P((struct ibcs2_semid_ds *, struct semid_ds *));
56 static void cvt_shmid2ishmid __P((struct shmid_ds *, struct ibcs2_shmid_ds *));
57 static void cvt_ishmid2shmid __P((struct ibcs2_shmid_ds *, struct shmid_ds *));
58 static void cvt_perm2iperm __P((struct ipc_perm *, struct ibcs2_ipc_perm *));
59 static void cvt_iperm2perm __P((struct ibcs2_ipc_perm *, struct ipc_perm *));
67 cvt_msqid2imsqid(bp, ibp)
69 struct ibcs2_msqid_ds *ibp;
71 cvt_perm2iperm(&bp->msg_perm, &ibp->msg_perm);
72 ibp->msg_first = bp->msg_first;
73 ibp->msg_last = bp->msg_last;
74 ibp->msg_cbytes = (u_short)bp->msg_cbytes;
75 ibp->msg_qnum = (u_short)bp->msg_qnum;
76 ibp->msg_qbytes = (u_short)bp->msg_qbytes;
77 ibp->msg_lspid = (u_short)bp->msg_lspid;
78 ibp->msg_lrpid = (u_short)bp->msg_lrpid;
79 ibp->msg_stime = bp->msg_stime;
80 ibp->msg_rtime = bp->msg_rtime;
81 ibp->msg_ctime = bp->msg_ctime;
86 cvt_imsqid2msqid(ibp, bp)
87 struct ibcs2_msqid_ds *ibp;
90 cvt_iperm2perm(&ibp->msg_perm, &bp->msg_perm);
91 bp->msg_first = ibp->msg_first;
92 bp->msg_last = ibp->msg_last;
93 bp->msg_cbytes = ibp->msg_cbytes;
94 bp->msg_qnum = ibp->msg_qnum;
95 bp->msg_qbytes = ibp->msg_qbytes;
96 bp->msg_lspid = ibp->msg_lspid;
97 bp->msg_lrpid = ibp->msg_lrpid;
98 bp->msg_stime = ibp->msg_stime;
99 bp->msg_rtime = ibp->msg_rtime;
100 bp->msg_ctime = ibp->msg_ctime;
107 struct ibcs2_msgsys_args *uap;
109 switch (SCARG(uap, which)) {
111 SCARG(uap, which) = 1;
112 return msgsys(p, (struct msgsys_args *)uap);
113 case 1: { /* msgctl */
115 struct msgsys_args margs;
116 caddr_t sg = stackgap_init();
118 SCARG(&margs, which) = 0;
119 SCARG(&margs, a2) = SCARG(uap, a2);
121 (int)stackgap_alloc(&sg, sizeof(struct msqid_ds));
122 SCARG(&margs, a3) = SCARG(uap, a3);
123 switch (SCARG(&margs, a3)) {
125 error = msgsys(p, &margs);
128 (struct msqid_ds *)SCARG(&margs, a4),
129 (struct ibcs2_msqid_ds *)SCARG(uap, a4));
132 cvt_imsqid2msqid((struct ibcs2_msqid_ds *)SCARG(uap,
134 (struct msqid_ds *)SCARG(&margs, a4));
135 return msgsys(p, &margs);
137 return msgsys(p, &margs);
142 SCARG(uap, which) = 3;
143 return msgsys(p, (struct msgsys_args *)uap);
145 SCARG(uap, which) = 2;
146 return msgsys(p, (struct msgsys_args *)uap);
157 cvt_sem2isem(bp, ibp)
159 struct ibcs2_sem *ibp;
161 ibp->semval = bp->semval;
162 ibp->sempid = bp->sempid;
163 ibp->semncnt = bp->semncnt;
164 ibp->semzcnt = bp->semzcnt;
169 cvt_isem2sem(ibp, bp)
170 struct ibcs2_sem *ibp;
173 bp->semval = ibp->semval;
174 bp->sempid = ibp->sempid;
175 bp->semncnt = ibp->semncnt;
176 bp->semzcnt = ibp->semzcnt;
182 cvt_iperm2perm(ipp, pp)
183 struct ibcs2_ipc_perm *ipp;
188 pp->cuid = ipp->cuid;
189 pp->cgid = ipp->cgid;
190 pp->mode = ipp->mode;
196 cvt_perm2iperm(pp, ipp)
198 struct ibcs2_ipc_perm *ipp;
202 ipp->cuid = pp->cuid;
203 ipp->cgid = pp->cgid;
204 ipp->mode = pp->mode;
210 cvt_semid2isemid(bp, ibp)
212 struct ibcs2_semid_ds *ibp;
214 cvt_perm2iperm(&bp->sem_perm, &ibp->sem_perm);
215 ibp->sem_base = (struct ibcs2_sem *)bp->sem_base;
216 ibp->sem_nsems = bp->sem_nsems;
217 ibp->sem_otime = bp->sem_otime;
218 ibp->sem_ctime = bp->sem_ctime;
223 cvt_isemid2semid(ibp, bp)
224 struct ibcs2_semid_ds *ibp;
227 cvt_iperm2perm(&ibp->sem_perm, &bp->sem_perm);
228 bp->sem_base = (struct sem *)ibp->sem_base;
229 bp->sem_nsems = ibp->sem_nsems;
230 bp->sem_otime = ibp->sem_otime;
231 bp->sem_ctime = ibp->sem_ctime;
238 struct ibcs2_semsys_args *uap;
242 switch (SCARG(uap, which)) {
244 switch(SCARG(uap, a4)) {
247 struct ibcs2_semid_ds *isp;
249 union semun *sup, ssu;
250 caddr_t sg = stackgap_init();
253 ssu = (union semun) SCARG(uap, a5);
254 sp = stackgap_alloc(&sg, sizeof(struct semid_ds));
255 sup = stackgap_alloc(&sg, sizeof(union semun));
257 SCARG(uap, a5) = (int)sup;
258 error = semsys(p, (struct semsys_args *)uap);
260 SCARG(uap, a5) = (int)ssu.buf;
261 isp = stackgap_alloc(&sg, sizeof(*isp));
262 cvt_semid2isemid(sp, isp);
263 error = copyout((caddr_t)isp,
271 struct ibcs2_semid_ds *isp;
273 caddr_t sg = stackgap_init();
275 isp = stackgap_alloc(&sg, sizeof(*isp));
276 sp = stackgap_alloc(&sg, sizeof(*sp));
277 error = copyin((caddr_t)SCARG(uap, a5), (caddr_t)isp,
281 cvt_isemid2semid(isp, sp);
282 SCARG(uap, a5) = (int)sp;
283 return semsys(p, (struct semsys_args *)uap);
288 caddr_t sg = stackgap_init();
290 sp = stackgap_alloc(&sg, sizeof(*sp));
291 sp->val = (int) SCARG(uap, a5);
292 SCARG(uap, a5) = (int)sp;
293 return semsys(p, (struct semsys_args *)uap);
297 return semsys(p, (struct semsys_args *)uap);
300 return semsys(p, (struct semsys_args *)uap);
303 return semsys(p, (struct semsys_args *)uap);
314 cvt_shmid2ishmid(bp, ibp)
316 struct ibcs2_shmid_ds *ibp;
318 cvt_perm2iperm(&bp->shm_perm, &ibp->shm_perm);
319 ibp->shm_segsz = bp->shm_segsz;
320 ibp->shm_lpid = bp->shm_lpid;
321 ibp->shm_cpid = bp->shm_cpid;
322 ibp->shm_nattch = bp->shm_nattch;
323 ibp->shm_cnattch = 0; /* ignored anyway */
324 ibp->shm_atime = bp->shm_atime;
325 ibp->shm_dtime = bp->shm_dtime;
326 ibp->shm_ctime = bp->shm_ctime;
331 cvt_ishmid2shmid(ibp, bp)
332 struct ibcs2_shmid_ds *ibp;
335 cvt_iperm2perm(&ibp->shm_perm, &bp->shm_perm);
336 bp->shm_segsz = ibp->shm_segsz;
337 bp->shm_lpid = ibp->shm_lpid;
338 bp->shm_cpid = ibp->shm_cpid;
339 bp->shm_nattch = ibp->shm_nattch;
340 bp->shm_atime = ibp->shm_atime;
341 bp->shm_dtime = ibp->shm_dtime;
342 bp->shm_ctime = ibp->shm_ctime;
343 bp->shm_internal = (void *)0; /* ignored anyway */
350 struct ibcs2_shmsys_args *uap;
354 switch (SCARG(uap, which)) {
356 return shmsys(p, (struct shmsys_args *)uap);
359 switch(SCARG(uap, a3)) {
362 struct ibcs2_shmid_ds *isp;
364 caddr_t sg = stackgap_init();
366 isp = (struct ibcs2_shmid_ds *)SCARG(uap, a4);
367 sp = stackgap_alloc(&sg, sizeof(*sp));
368 SCARG(uap, a4) = (int)sp;
369 error = shmsys(p, (struct shmsys_args *)uap);
371 SCARG(uap, a4) = (int)isp;
372 isp = stackgap_alloc(&sg, sizeof(*isp));
373 cvt_shmid2ishmid(sp, isp);
374 error = copyout((caddr_t)isp,
375 (caddr_t)SCARG(uap, a4),
382 struct ibcs2_shmid_ds *isp;
384 caddr_t sg = stackgap_init();
386 isp = stackgap_alloc(&sg, sizeof(*isp));
387 sp = stackgap_alloc(&sg, sizeof(*sp));
388 error = copyin((caddr_t)SCARG(uap, a4), (caddr_t)isp,
392 cvt_ishmid2shmid(isp, sp);
393 SCARG(uap, a4) = (int)sp;
394 return shmsys(p, (struct shmsys_args *)uap);
398 return shmsys(p, (struct shmsys_args *)uap);
401 return shmsys(p, (struct shmsys_args *)uap);
404 return shmsys(p, (struct shmsys_args *)uap);