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 * $FreeBSD: src/sys/i386/ibcs2/ibcs2_ipc.c,v 1.15 1999/08/28 00:43:57 peter Exp $
26 * $DragonFly: src/sys/emulation/ibcs2/i386/Attic/ibcs2_ipc.c,v 1.2 2003/06/17 04:28:35 dillon Exp $
29 #include <sys/param.h>
30 #include <sys/systm.h>
34 #include <sys/sysproto.h>
36 #include <i386/ibcs2/ibcs2_types.h>
37 #include <i386/ibcs2/ibcs2_signal.h>
38 #include <i386/ibcs2/ibcs2_proto.h>
39 #include <i386/ibcs2/ibcs2_util.h>
40 #include <i386/ibcs2/ibcs2_ipc.h>
42 #define IBCS2_IPC_RMID 0
43 #define IBCS2_IPC_SET 1
44 #define IBCS2_IPC_STAT 2
45 #define IBCS2_SETVAL 8
49 static void cvt_msqid2imsqid __P((struct msqid_ds *, struct ibcs2_msqid_ds *));
50 static void cvt_imsqid2msqid __P((struct ibcs2_msqid_ds *, struct msqid_ds *));
52 static void cvt_sem2isem __P((struct sem *, struct ibcs2_sem *));
53 static void cvt_isem2sem __P((struct ibcs2_sem *, struct sem *));
55 static void cvt_semid2isemid __P((struct semid_ds *, struct ibcs2_semid_ds *));
56 static void cvt_isemid2semid __P((struct ibcs2_semid_ds *, struct semid_ds *));
57 static void cvt_shmid2ishmid __P((struct shmid_ds *, struct ibcs2_shmid_ds *));
58 static void cvt_ishmid2shmid __P((struct ibcs2_shmid_ds *, struct shmid_ds *));
59 static void cvt_perm2iperm __P((struct ipc_perm *, struct ibcs2_ipc_perm *));
60 static void cvt_iperm2perm __P((struct ibcs2_ipc_perm *, struct ipc_perm *));
68 cvt_msqid2imsqid(bp, ibp)
70 struct ibcs2_msqid_ds *ibp;
72 cvt_perm2iperm(&bp->msg_perm, &ibp->msg_perm);
73 ibp->msg_first = bp->msg_first;
74 ibp->msg_last = bp->msg_last;
75 ibp->msg_cbytes = (u_short)bp->msg_cbytes;
76 ibp->msg_qnum = (u_short)bp->msg_qnum;
77 ibp->msg_qbytes = (u_short)bp->msg_qbytes;
78 ibp->msg_lspid = (u_short)bp->msg_lspid;
79 ibp->msg_lrpid = (u_short)bp->msg_lrpid;
80 ibp->msg_stime = bp->msg_stime;
81 ibp->msg_rtime = bp->msg_rtime;
82 ibp->msg_ctime = bp->msg_ctime;
87 cvt_imsqid2msqid(ibp, bp)
88 struct ibcs2_msqid_ds *ibp;
91 cvt_iperm2perm(&ibp->msg_perm, &bp->msg_perm);
92 bp->msg_first = ibp->msg_first;
93 bp->msg_last = ibp->msg_last;
94 bp->msg_cbytes = ibp->msg_cbytes;
95 bp->msg_qnum = ibp->msg_qnum;
96 bp->msg_qbytes = ibp->msg_qbytes;
97 bp->msg_lspid = ibp->msg_lspid;
98 bp->msg_lrpid = ibp->msg_lrpid;
99 bp->msg_stime = ibp->msg_stime;
100 bp->msg_rtime = ibp->msg_rtime;
101 bp->msg_ctime = ibp->msg_ctime;
108 struct ibcs2_msgsys_args *uap;
110 switch (SCARG(uap, which)) {
112 SCARG(uap, which) = 1;
113 return msgsys(p, (struct msgsys_args *)uap);
114 case 1: { /* msgctl */
116 struct msgsys_args margs;
117 caddr_t sg = stackgap_init();
119 SCARG(&margs, which) = 0;
120 SCARG(&margs, a2) = SCARG(uap, a2);
122 (int)stackgap_alloc(&sg, sizeof(struct msqid_ds));
123 SCARG(&margs, a3) = SCARG(uap, a3);
124 switch (SCARG(&margs, a3)) {
126 error = msgsys(p, &margs);
129 (struct msqid_ds *)SCARG(&margs, a4),
130 (struct ibcs2_msqid_ds *)SCARG(uap, a4));
133 cvt_imsqid2msqid((struct ibcs2_msqid_ds *)SCARG(uap,
135 (struct msqid_ds *)SCARG(&margs, a4));
136 return msgsys(p, &margs);
138 return msgsys(p, &margs);
143 SCARG(uap, which) = 3;
144 return msgsys(p, (struct msgsys_args *)uap);
146 SCARG(uap, which) = 2;
147 return msgsys(p, (struct msgsys_args *)uap);
158 cvt_sem2isem(bp, ibp)
160 struct ibcs2_sem *ibp;
162 ibp->semval = bp->semval;
163 ibp->sempid = bp->sempid;
164 ibp->semncnt = bp->semncnt;
165 ibp->semzcnt = bp->semzcnt;
170 cvt_isem2sem(ibp, bp)
171 struct ibcs2_sem *ibp;
174 bp->semval = ibp->semval;
175 bp->sempid = ibp->sempid;
176 bp->semncnt = ibp->semncnt;
177 bp->semzcnt = ibp->semzcnt;
183 cvt_iperm2perm(ipp, pp)
184 struct ibcs2_ipc_perm *ipp;
189 pp->cuid = ipp->cuid;
190 pp->cgid = ipp->cgid;
191 pp->mode = ipp->mode;
197 cvt_perm2iperm(pp, ipp)
199 struct ibcs2_ipc_perm *ipp;
203 ipp->cuid = pp->cuid;
204 ipp->cgid = pp->cgid;
205 ipp->mode = pp->mode;
211 cvt_semid2isemid(bp, ibp)
213 struct ibcs2_semid_ds *ibp;
215 cvt_perm2iperm(&bp->sem_perm, &ibp->sem_perm);
216 ibp->sem_base = (struct ibcs2_sem *)bp->sem_base;
217 ibp->sem_nsems = bp->sem_nsems;
218 ibp->sem_otime = bp->sem_otime;
219 ibp->sem_ctime = bp->sem_ctime;
224 cvt_isemid2semid(ibp, bp)
225 struct ibcs2_semid_ds *ibp;
228 cvt_iperm2perm(&ibp->sem_perm, &bp->sem_perm);
229 bp->sem_base = (struct sem *)ibp->sem_base;
230 bp->sem_nsems = ibp->sem_nsems;
231 bp->sem_otime = ibp->sem_otime;
232 bp->sem_ctime = ibp->sem_ctime;
239 struct ibcs2_semsys_args *uap;
243 switch (SCARG(uap, which)) {
245 switch(SCARG(uap, a4)) {
248 struct ibcs2_semid_ds *isp;
250 union semun *sup, ssu;
251 caddr_t sg = stackgap_init();
254 ssu = (union semun) SCARG(uap, a5);
255 sp = stackgap_alloc(&sg, sizeof(struct semid_ds));
256 sup = stackgap_alloc(&sg, sizeof(union semun));
258 SCARG(uap, a5) = (int)sup;
259 error = semsys(p, (struct semsys_args *)uap);
261 SCARG(uap, a5) = (int)ssu.buf;
262 isp = stackgap_alloc(&sg, sizeof(*isp));
263 cvt_semid2isemid(sp, isp);
264 error = copyout((caddr_t)isp,
272 struct ibcs2_semid_ds *isp;
274 caddr_t sg = stackgap_init();
276 isp = stackgap_alloc(&sg, sizeof(*isp));
277 sp = stackgap_alloc(&sg, sizeof(*sp));
278 error = copyin((caddr_t)SCARG(uap, a5), (caddr_t)isp,
282 cvt_isemid2semid(isp, sp);
283 SCARG(uap, a5) = (int)sp;
284 return semsys(p, (struct semsys_args *)uap);
289 caddr_t sg = stackgap_init();
291 sp = stackgap_alloc(&sg, sizeof(*sp));
292 sp->val = (int) SCARG(uap, a5);
293 SCARG(uap, a5) = (int)sp;
294 return semsys(p, (struct semsys_args *)uap);
298 return semsys(p, (struct semsys_args *)uap);
301 return semsys(p, (struct semsys_args *)uap);
304 return semsys(p, (struct semsys_args *)uap);
315 cvt_shmid2ishmid(bp, ibp)
317 struct ibcs2_shmid_ds *ibp;
319 cvt_perm2iperm(&bp->shm_perm, &ibp->shm_perm);
320 ibp->shm_segsz = bp->shm_segsz;
321 ibp->shm_lpid = bp->shm_lpid;
322 ibp->shm_cpid = bp->shm_cpid;
323 ibp->shm_nattch = bp->shm_nattch;
324 ibp->shm_cnattch = 0; /* ignored anyway */
325 ibp->shm_atime = bp->shm_atime;
326 ibp->shm_dtime = bp->shm_dtime;
327 ibp->shm_ctime = bp->shm_ctime;
332 cvt_ishmid2shmid(ibp, bp)
333 struct ibcs2_shmid_ds *ibp;
336 cvt_iperm2perm(&ibp->shm_perm, &bp->shm_perm);
337 bp->shm_segsz = ibp->shm_segsz;
338 bp->shm_lpid = ibp->shm_lpid;
339 bp->shm_cpid = ibp->shm_cpid;
340 bp->shm_nattch = ibp->shm_nattch;
341 bp->shm_atime = ibp->shm_atime;
342 bp->shm_dtime = ibp->shm_dtime;
343 bp->shm_ctime = ibp->shm_ctime;
344 bp->shm_internal = (void *)0; /* ignored anyway */
351 struct ibcs2_shmsys_args *uap;
355 switch (SCARG(uap, which)) {
357 return shmsys(p, (struct shmsys_args *)uap);
360 switch(SCARG(uap, a3)) {
363 struct ibcs2_shmid_ds *isp;
365 caddr_t sg = stackgap_init();
367 isp = (struct ibcs2_shmid_ds *)SCARG(uap, a4);
368 sp = stackgap_alloc(&sg, sizeof(*sp));
369 SCARG(uap, a4) = (int)sp;
370 error = shmsys(p, (struct shmsys_args *)uap);
372 SCARG(uap, a4) = (int)isp;
373 isp = stackgap_alloc(&sg, sizeof(*isp));
374 cvt_shmid2ishmid(sp, isp);
375 error = copyout((caddr_t)isp,
376 (caddr_t)SCARG(uap, a4),
383 struct ibcs2_shmid_ds *isp;
385 caddr_t sg = stackgap_init();
387 isp = stackgap_alloc(&sg, sizeof(*isp));
388 sp = stackgap_alloc(&sg, sizeof(*sp));
389 error = copyin((caddr_t)SCARG(uap, a4), (caddr_t)isp,
393 cvt_ishmid2shmid(isp, sp);
394 SCARG(uap, a4) = (int)sp;
395 return shmsys(p, (struct shmsys_args *)uap);
399 return shmsys(p, (struct shmsys_args *)uap);
402 return shmsys(p, (struct shmsys_args *)uap);
405 return shmsys(p, (struct shmsys_args *)uap);