1 /*
2 * Copyright (c) 1995 Scott Bartram
3 * Copyright (c) 1995 Steven Wallace
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
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
13 *
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.
24 *
25 * $FreeBSD$
26 */
27
28 #include <sys/param.h>
29 #include <sys/systm.h>
30 #include <sys/msg.h>
31 #include <sys/sem.h>
32 #include <sys/shm.h>
33 #include <sys/sysproto.h>
34
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>
40
41 #define IBCS2_IPC_RMID 0
42 #define IBCS2_IPC_SET 1
43 #define IBCS2_IPC_STAT 2
44 #define IBCS2_SETVAL 8
45
46
47
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 *));
50 #ifdef unused
51 static void cvt_sem2isem __P((struct sem *, struct ibcs2_sem *));
52 static void cvt_isem2sem __P((struct ibcs2_sem *, struct sem *));
53 #endif
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
59
60 /*
61 * iBCS2 msgsys call
62 */
63
64 static void
65 cvt_msqid2imsqid(bp, ibp)
66 struct msqid_ds *bp;
67 struct ibcs2_msqid_ds *ibp;
68 {
69 ibp->msg_perm = bp->msg_perm;
70 ibp->msg_first = bp->msg_first;
71 ibp->msg_last = bp->msg_last;
72 ibp->msg_cbytes = (u_short)bp->msg_cbytes;
73 ibp->msg_qnum = (u_short)bp->msg_qnum;
74 ibp->msg_qbytes = (u_short)bp->msg_qbytes;
75 ibp->msg_lspid = (u_short)bp->msg_lspid;
76 ibp->msg_lrpid = (u_short)bp->msg_lrpid;
77 ibp->msg_stime = bp->msg_stime;
78 ibp->msg_rtime = bp->msg_rtime;
79 ibp->msg_ctime = bp->msg_ctime;
80 return;
81 }
82
83 static void
84 cvt_imsqid2msqid(ibp, bp)
85 struct ibcs2_msqid_ds *ibp;
86 struct msqid_ds *bp;
87 {
88 bp->msg_perm = ibp->msg_perm;
89 bp->msg_first = ibp->msg_first;
90 bp->msg_last = ibp->msg_last;
91 bp->msg_cbytes = ibp->msg_cbytes;
92 bp->msg_qnum = ibp->msg_qnum;
93 bp->msg_qbytes = ibp->msg_qbytes;
94 bp->msg_lspid = ibp->msg_lspid;
95 bp->msg_lrpid = ibp->msg_lrpid;
96 bp->msg_stime = ibp->msg_stime;
97 bp->msg_rtime = ibp->msg_rtime;
98 bp->msg_ctime = ibp->msg_ctime;
99 return;
100 }
101
102 int
103 ibcs2_msgsys(p, uap)
104 struct proc *p;
105 struct ibcs2_msgsys_args *uap;
106 {
107 switch (SCARG(uap, which)) {
108 case 0: /* msgget */
109 SCARG(uap, which) = 1;
110 return msgsys(p, (struct msgsys_args *)uap);
111 case 1: { /* msgctl */
112 int error;
113 struct msgsys_args margs;
114 caddr_t sg = stackgap_init();
115
116 SCARG(&margs, which) = 0;
117 SCARG(&margs, a2) = SCARG(uap, a2);
118 SCARG(&margs, a4) =
119 (int)stackgap_alloc(&sg, sizeof(struct msqid_ds));
120 SCARG(&margs, a3) = SCARG(uap, a3);
121 switch (SCARG(&margs, a3)) {
122 case IBCS2_IPC_STAT:
123 error = msgsys(p, &margs);
124 if (!error)
125 cvt_msqid2imsqid(
126 (struct msqid_ds *)SCARG(&margs, a4),
127 (struct ibcs2_msqid_ds *)SCARG(uap, a4));
128 return error;
129 case IBCS2_IPC_SET:
130 cvt_imsqid2msqid((struct ibcs2_msqid_ds *)SCARG(uap,
131 a4),
132 (struct msqid_ds *)SCARG(&margs, a4));
133 return msgsys(p, &margs);
134 case IBCS2_IPC_RMID:
135 return msgsys(p, &margs);
136 }
137 return EINVAL;
138 }
139 case 2: /* msgrcv */
140 SCARG(uap, which) = 3;
141 return msgsys(p, (struct msgsys_args *)uap);
142 case 3: /* msgsnd */
143 SCARG(uap, which) = 2;
144 return msgsys(p, (struct msgsys_args *)uap);
145 default:
146 return EINVAL;
147 }
148 }
149
150 /*
151 * iBCS2 semsys call
152 */
153 #ifdef unused
154 static void
155 cvt_sem2isem(bp, ibp)
156 struct sem *bp;
157 struct ibcs2_sem *ibp;
158 {
159 ibp->semval = bp->semval;
160 ibp->sempid = bp->sempid;
161 ibp->semncnt = bp->semncnt;
162 ibp->semzcnt = bp->semzcnt;
163 return;
164 }
165
166 static void
167 cvt_isem2sem(ibp, bp)
168 struct ibcs2_sem *ibp;
169 struct sem *bp;
170 {
171 bp->semval = ibp->semval;
172 bp->sempid = ibp->sempid;
173 bp->semncnt = ibp->semncnt;
174 bp->semzcnt = ibp->semzcnt;
175 return;
176 }
177 #endif
178
179 static void
180 cvt_semid2isemid(bp, ibp)
181 struct semid_ds *bp;
182 struct ibcs2_semid_ds *ibp;
183 {
184 ibp->sem_perm = bp->sem_perm;
185 ibp->sem_base = (struct ibcs2_sem *)bp->sem_base;
186 ibp->sem_nsems = bp->sem_nsems;
187 ibp->sem_otime = bp->sem_otime;
188 ibp->sem_ctime = bp->sem_ctime;
189 return;
190 }
191
192 static void
193 cvt_isemid2semid(ibp, bp)
194 struct ibcs2_semid_ds *ibp;
195 struct semid_ds *bp;
196 {
197 bp->sem_perm = ibp->sem_perm;
198 bp->sem_base = (struct sem *)ibp->sem_base;
199 bp->sem_nsems = ibp->sem_nsems;
200 bp->sem_otime = ibp->sem_otime;
201 bp->sem_ctime = ibp->sem_ctime;
202 return;
203 }
204
205 int
206 ibcs2_semsys(p, uap)
207 struct proc *p;
208 struct ibcs2_semsys_args *uap;
209 {
210 int error;
211
212 switch (SCARG(uap, which)) {
213 case 0: /* semctl */
214 switch(SCARG(uap, a4)) {
215 case IBCS2_IPC_STAT:
216 {
217 struct ibcs2_semid_ds *isp;
218 struct semid_ds *sp;
219 caddr_t sg = stackgap_init();
220
221 isp = (struct ibcs2_semid_ds *)SCARG(uap, a5);
222 sp = stackgap_alloc(&sg, sizeof(struct semid_ds));
223 SCARG(uap, a5) = (int)sp;
224 error = semsys(p, (struct semsys_args *)uap);
225 if (!error) {
226 SCARG(uap, a5) = (int)isp;
227 isp = stackgap_alloc(&sg, sizeof(*isp));
228 cvt_semid2isemid(sp, isp);
229 error = copyout((caddr_t)isp,
230 (caddr_t)SCARG(uap, a5),
231 sizeof(*isp));
232 }
233 return error;
234 }
235 case IBCS2_IPC_SET:
236 {
237 struct ibcs2_semid_ds *isp;
238 struct semid_ds *sp;
239 caddr_t sg = stackgap_init();
240
241 isp = stackgap_alloc(&sg, sizeof(*isp));
242 sp = stackgap_alloc(&sg, sizeof(*sp));
243 error = copyin((caddr_t)SCARG(uap, a5), (caddr_t)isp,
244 sizeof(*isp));
245 if (error)
246 return error;
247 cvt_isemid2semid(isp, sp);
248 SCARG(uap, a5) = (int)sp;
249 return semsys(p, (struct semsys_args *)uap);
250 }
251 case IBCS2_SETVAL:
252 {
253 union semun *sp;
254 caddr_t sg = stackgap_init();
255
256 sp = stackgap_alloc(&sg, sizeof(*sp));
257 sp->val = (int) SCARG(uap, a5);
258 SCARG(uap, a5) = (int)sp;
259 return semsys(p, (struct semsys_args *)uap);
260 }
261 }
262
263 return semsys(p, (struct semsys_args *)uap);
264
265 case 1: /* semget */
266 return semsys(p, (struct semsys_args *)uap);
267
268 case 2: /* semop */
269 return semsys(p, (struct semsys_args *)uap);
270 }
271 return EINVAL;
272 }
273
274
275 /*
276 * iBCS2 shmsys call
277 */
278
279 static void
280 cvt_shmid2ishmid(bp, ibp)
281 struct shmid_ds *bp;
282 struct ibcs2_shmid_ds *ibp;
283 {
284 ibp->shm_perm = bp->shm_perm;
285 ibp->shm_segsz = bp->shm_segsz;
286 ibp->shm_lpid = bp->shm_lpid;
287 ibp->shm_cpid = bp->shm_cpid;
288 ibp->shm_nattch = bp->shm_nattch;
289 ibp->shm_cnattch = 0; /* ignored anyway */
290 ibp->shm_atime = bp->shm_atime;
291 ibp->shm_dtime = bp->shm_dtime;
292 ibp->shm_ctime = bp->shm_ctime;
293 return;
294 }
295
296 static void
297 cvt_ishmid2shmid(ibp, bp)
298 struct ibcs2_shmid_ds *ibp;
299 struct shmid_ds *bp;
300 {
301 bp->shm_perm = ibp->shm_perm;
302 bp->shm_segsz = ibp->shm_segsz;
303 bp->shm_lpid = ibp->shm_lpid;
304 bp->shm_cpid = ibp->shm_cpid;
305 bp->shm_nattch = ibp->shm_nattch;
306 bp->shm_atime = ibp->shm_atime;
307 bp->shm_dtime = ibp->shm_dtime;
308 bp->shm_ctime = ibp->shm_ctime;
309 bp->shm_internal = (void *)0; /* ignored anyway */
310 return;
311 }
312
313 int
314 ibcs2_shmsys(p, uap)
315 struct proc *p;
316 struct ibcs2_shmsys_args *uap;
317 {
318 int error;
319
320 switch (SCARG(uap, which)) {
321 case 0: /* shmat */
322 return shmsys(p, (struct shmsys_args *)uap);
323
324 case 1: /* shmctl */
325 switch(SCARG(uap, a3)) {
326 case IBCS2_IPC_STAT:
327 {
328 struct ibcs2_shmid_ds *isp;
329 struct shmid_ds *sp;
330 caddr_t sg = stackgap_init();
331
332 isp = (struct ibcs2_shmid_ds *)SCARG(uap, a4);
333 sp = stackgap_alloc(&sg, sizeof(*sp));
334 SCARG(uap, a4) = (int)sp;
335 error = shmsys(p, (struct shmsys_args *)uap);
336 if (!error) {
337 SCARG(uap, a4) = (int)isp;
338 isp = stackgap_alloc(&sg, sizeof(*isp));
339 cvt_shmid2ishmid(sp, isp);
340 error = copyout((caddr_t)isp,
341 (caddr_t)SCARG(uap, a4),
342 sizeof(*isp));
343 }
344 return error;
345 }
346 case IBCS2_IPC_SET:
347 {
348 struct ibcs2_shmid_ds *isp;
349 struct shmid_ds *sp;
350 caddr_t sg = stackgap_init();
351
352 isp = stackgap_alloc(&sg, sizeof(*isp));
353 sp = stackgap_alloc(&sg, sizeof(*sp));
354 error = copyin((caddr_t)SCARG(uap, a4), (caddr_t)isp,
355 sizeof(*isp));
356 if (error)
357 return error;
358 cvt_ishmid2shmid(isp, sp);
359 SCARG(uap, a4) = (int)sp;
360 return shmsys(p, (struct shmsys_args *)uap);
361 }
362 }
363
364 return shmsys(p, (struct shmsys_args *)uap);
365
366 case 2: /* shmdt */
367 return shmsys(p, (struct shmsys_args *)uap);
368
369 case 3: /* shmget */
370 return shmsys(p, (struct shmsys_args *)uap);
371 }
372 return EINVAL;
373 }
Cache object: 7553b069482e477ab0df930e50dcac1e
|