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
26 #include <sys/cdefs.h>
27 __FBSDID("$FreeBSD$");
28
29 #include <sys/param.h>
30 #include <sys/systm.h>
31 #include <sys/msg.h>
32 #include <sys/sem.h>
33 #include <sys/shm.h>
34 #include <sys/syscallsubr.h>
35 #include <sys/sysproto.h>
36
37 #include <i386/ibcs2/ibcs2_types.h>
38 #include <i386/ibcs2/ibcs2_signal.h>
39 #include <i386/ibcs2/ibcs2_proto.h>
40 #include <i386/ibcs2/ibcs2_util.h>
41 #include <i386/ibcs2/ibcs2_ipc.h>
42
43 #define IBCS2_IPC_RMID 0
44 #define IBCS2_IPC_SET 1
45 #define IBCS2_IPC_STAT 2
46 #define IBCS2_SETVAL 8
47
48
49
50 static void cvt_msqid2imsqid(struct msqid_ds *, struct ibcs2_msqid_ds *);
51 static void cvt_imsqid2msqid(struct ibcs2_msqid_ds *, struct msqid_ds *);
52 #ifdef unused
53 static void cvt_sem2isem(struct sem *, struct ibcs2_sem *);
54 static void cvt_isem2sem(struct ibcs2_sem *, struct sem *);
55 #endif
56 static void cvt_semid2isemid(struct semid_ds *, struct ibcs2_semid_ds *);
57 static void cvt_isemid2semid(struct ibcs2_semid_ds *, struct semid_ds *);
58 static void cvt_shmid2ishmid(struct shmid_ds *, struct ibcs2_shmid_ds *);
59 static void cvt_ishmid2shmid(struct ibcs2_shmid_ds *, struct shmid_ds *);
60 static void cvt_perm2iperm(struct ipc_perm *, struct ibcs2_ipc_perm *);
61 static void cvt_iperm2perm(struct ibcs2_ipc_perm *, struct ipc_perm *);
62
63
64 /*
65 * iBCS2 msgsys call
66 */
67
68 static void
69 cvt_msqid2imsqid(bp, ibp)
70 struct msqid_ds *bp;
71 struct ibcs2_msqid_ds *ibp;
72 {
73 cvt_perm2iperm(&bp->msg_perm, &ibp->msg_perm);
74 ibp->msg_first = bp->msg_first;
75 ibp->msg_last = bp->msg_last;
76 ibp->msg_cbytes = (u_short)bp->msg_cbytes;
77 ibp->msg_qnum = (u_short)bp->msg_qnum;
78 ibp->msg_qbytes = (u_short)bp->msg_qbytes;
79 ibp->msg_lspid = (u_short)bp->msg_lspid;
80 ibp->msg_lrpid = (u_short)bp->msg_lrpid;
81 ibp->msg_stime = bp->msg_stime;
82 ibp->msg_rtime = bp->msg_rtime;
83 ibp->msg_ctime = bp->msg_ctime;
84 return;
85 }
86
87 static void
88 cvt_imsqid2msqid(ibp, bp)
89 struct ibcs2_msqid_ds *ibp;
90 struct msqid_ds *bp;
91 {
92 cvt_iperm2perm(&ibp->msg_perm, &bp->msg_perm);
93 bp->msg_first = ibp->msg_first;
94 bp->msg_last = ibp->msg_last;
95 bp->msg_cbytes = ibp->msg_cbytes;
96 bp->msg_qnum = ibp->msg_qnum;
97 bp->msg_qbytes = ibp->msg_qbytes;
98 bp->msg_lspid = ibp->msg_lspid;
99 bp->msg_lrpid = ibp->msg_lrpid;
100 bp->msg_stime = ibp->msg_stime;
101 bp->msg_rtime = ibp->msg_rtime;
102 bp->msg_ctime = ibp->msg_ctime;
103 return;
104 }
105
106 struct ibcs2_msgget_args {
107 int what;
108 ibcs2_key_t key;
109 int msgflg;
110 };
111
112 static int
113 ibcs2_msgget(struct thread *td, void *v)
114 {
115 struct ibcs2_msgget_args *uap = v;
116 struct msgget_args ap;
117
118 ap.key = uap->key;
119 ap.msgflg = uap->msgflg;
120 return msgget(td, &ap);
121 }
122
123 struct ibcs2_msgctl_args {
124 int what;
125 int msqid;
126 int cmd;
127 struct ibcs2_msqid_ds *buf;
128 };
129
130 static int
131 ibcs2_msgctl(struct thread *td, void *v)
132 {
133 struct ibcs2_msgctl_args *uap = v;
134 struct ibcs2_msqid_ds is;
135 struct msqid_ds bs;
136 int error;
137
138 switch (uap->cmd) {
139 case IBCS2_IPC_STAT:
140 error = kern_msgctl(td, uap->msqid, IPC_STAT, &bs);
141 if (!error) {
142 cvt_msqid2imsqid(&bs, &is);
143 error = copyout(&is, uap->buf, sizeof(is));
144 }
145 return (error);
146 case IBCS2_IPC_SET:
147 error = copyin(uap->buf, &is, sizeof(is));
148 if (error)
149 return (error);
150 cvt_imsqid2msqid(&is, &bs);
151 return (kern_msgctl(td, uap->msqid, IPC_SET, &bs));
152 case IBCS2_IPC_RMID:
153 return (kern_msgctl(td, uap->msqid, IPC_RMID, NULL));
154 }
155 return (EINVAL);
156 }
157
158 struct ibcs2_msgrcv_args {
159 int what;
160 int msqid;
161 void *msgp;
162 size_t msgsz;
163 long msgtyp;
164 int msgflg;
165 };
166
167 static int
168 ibcs2_msgrcv(struct thread *td, void *v)
169 {
170 struct ibcs2_msgrcv_args *uap = v;
171 struct msgrcv_args ap;
172
173 ap.msqid = uap->msqid;
174 ap.msgp = uap->msgp;
175 ap.msgsz = uap->msgsz;
176 ap.msgtyp = uap->msgtyp;
177 ap.msgflg = uap->msgflg;
178 return (msgrcv(td, &ap));
179 }
180
181 struct ibcs2_msgsnd_args {
182 int what;
183 int msqid;
184 void *msgp;
185 size_t msgsz;
186 int msgflg;
187 };
188
189 static int
190 ibcs2_msgsnd(struct thread *td, void *v)
191 {
192 struct ibcs2_msgsnd_args *uap = v;
193 struct msgsnd_args ap;
194
195 ap.msqid = uap->msqid;
196 ap.msgp = uap->msgp;
197 ap.msgsz = uap->msgsz;
198 ap.msgflg = uap->msgflg;
199 return (msgsnd(td, &ap));
200 }
201
202 int
203 ibcs2_msgsys(td, uap)
204 struct thread *td;
205 struct ibcs2_msgsys_args *uap;
206 {
207 switch (uap->which) {
208 case 0:
209 return (ibcs2_msgget(td, uap));
210 case 1:
211 return (ibcs2_msgctl(td, uap));
212 case 2:
213 return (ibcs2_msgrcv(td, uap));
214 case 3:
215 return (ibcs2_msgsnd(td, uap));
216 default:
217 return (EINVAL);
218 }
219 }
220
221 /*
222 * iBCS2 semsys call
223 */
224 #ifdef unused
225 static void
226 cvt_sem2isem(bp, ibp)
227 struct sem *bp;
228 struct ibcs2_sem *ibp;
229 {
230 ibp->semval = bp->semval;
231 ibp->sempid = bp->sempid;
232 ibp->semncnt = bp->semncnt;
233 ibp->semzcnt = bp->semzcnt;
234 return;
235 }
236
237 static void
238 cvt_isem2sem(ibp, bp)
239 struct ibcs2_sem *ibp;
240 struct sem *bp;
241 {
242 bp->semval = ibp->semval;
243 bp->sempid = ibp->sempid;
244 bp->semncnt = ibp->semncnt;
245 bp->semzcnt = ibp->semzcnt;
246 return;
247 }
248 #endif
249
250 static void
251 cvt_iperm2perm(ipp, pp)
252 struct ibcs2_ipc_perm *ipp;
253 struct ipc_perm *pp;
254 {
255 pp->uid = ipp->uid;
256 pp->gid = ipp->gid;
257 pp->cuid = ipp->cuid;
258 pp->cgid = ipp->cgid;
259 pp->mode = ipp->mode;
260 pp->seq = ipp->seq;
261 pp->key = ipp->key;
262 }
263
264 static void
265 cvt_perm2iperm(pp, ipp)
266 struct ipc_perm *pp;
267 struct ibcs2_ipc_perm *ipp;
268 {
269 ipp->uid = pp->uid;
270 ipp->gid = pp->gid;
271 ipp->cuid = pp->cuid;
272 ipp->cgid = pp->cgid;
273 ipp->mode = pp->mode;
274 ipp->seq = pp->seq;
275 ipp->key = pp->key;
276 }
277
278 static void
279 cvt_semid2isemid(bp, ibp)
280 struct semid_ds *bp;
281 struct ibcs2_semid_ds *ibp;
282 {
283 cvt_perm2iperm(&bp->sem_perm, &ibp->sem_perm);
284 ibp->sem_base = (struct ibcs2_sem *)bp->sem_base;
285 ibp->sem_nsems = bp->sem_nsems;
286 ibp->sem_otime = bp->sem_otime;
287 ibp->sem_ctime = bp->sem_ctime;
288 return;
289 }
290
291 static void
292 cvt_isemid2semid(ibp, bp)
293 struct ibcs2_semid_ds *ibp;
294 struct semid_ds *bp;
295 {
296 cvt_iperm2perm(&ibp->sem_perm, &bp->sem_perm);
297 bp->sem_base = (struct sem *)ibp->sem_base;
298 bp->sem_nsems = ibp->sem_nsems;
299 bp->sem_otime = ibp->sem_otime;
300 bp->sem_ctime = ibp->sem_ctime;
301 return;
302 }
303
304 struct ibcs2_semctl_args {
305 int what;
306 int semid;
307 int semnum;
308 int cmd;
309 union semun arg;
310 };
311
312 static int
313 ibcs2_semctl(struct thread *td, void *v)
314 {
315 struct ibcs2_semctl_args *uap = v;
316 struct ibcs2_semid_ds is;
317 struct semid_ds bs;
318 union semun semun;
319 register_t rval;
320 int error;
321
322 switch(uap->cmd) {
323 case IBCS2_IPC_STAT:
324 semun.buf = &bs;
325 error = kern_semctl(td, uap->semid, uap->semnum, IPC_STAT,
326 &semun, &rval);
327 if (error)
328 return (error);
329 cvt_semid2isemid(&bs, &is);
330 error = copyout(&is, uap->arg.buf, sizeof(is));
331 if (error == 0)
332 td->td_retval[0] = rval;
333 return (error);
334
335 case IBCS2_IPC_SET:
336 error = copyin(uap->arg.buf, &is, sizeof(is));
337 if (error)
338 return (error);
339 cvt_isemid2semid(&is, &bs);
340 semun.buf = &bs;
341 return (kern_semctl(td, uap->semid, uap->semnum, IPC_SET,
342 &semun, td->td_retval));
343 }
344
345 return (kern_semctl(td, uap->semid, uap->semnum, uap->cmd, &uap->arg,
346 td->td_retval));
347 }
348
349 struct ibcs2_semget_args {
350 int what;
351 ibcs2_key_t key;
352 int nsems;
353 int semflg;
354 };
355
356 static int
357 ibcs2_semget(struct thread *td, void *v)
358 {
359 struct ibcs2_semget_args *uap = v;
360 struct semget_args ap;
361
362 ap.key = uap->key;
363 ap.nsems = uap->nsems;
364 ap.semflg = uap->semflg;
365 return (semget(td, &ap));
366 }
367
368 struct ibcs2_semop_args {
369 int what;
370 int semid;
371 struct sembuf *sops;
372 size_t nsops;
373 };
374
375 static int
376 ibcs2_semop(struct thread *td, void *v)
377 {
378 struct ibcs2_semop_args *uap = v;
379 struct semop_args ap;
380
381 ap.semid = uap->semid;
382 ap.sops = uap->sops;
383 ap.nsops = uap->nsops;
384 return (semop(td, &ap));
385 }
386
387 int
388 ibcs2_semsys(td, uap)
389 struct thread *td;
390 struct ibcs2_semsys_args *uap;
391 {
392
393 switch (uap->which) {
394 case 0:
395 return (ibcs2_semctl(td, uap));
396 case 1:
397 return (ibcs2_semget(td, uap));
398 case 2:
399 return (ibcs2_semop(td, uap));
400 }
401 return (EINVAL);
402 }
403
404
405 /*
406 * iBCS2 shmsys call
407 */
408
409 MODULE_DEPEND(ibcs2, sysvmsg, 1, 1, 1);
410 MODULE_DEPEND(ibcs2, sysvsem, 1, 1, 1);
411 MODULE_DEPEND(ibcs2, sysvshm, 1, 1, 1);
412
413 static void
414 cvt_shmid2ishmid(bp, ibp)
415 struct shmid_ds *bp;
416 struct ibcs2_shmid_ds *ibp;
417 {
418 cvt_perm2iperm(&bp->shm_perm, &ibp->shm_perm);
419 ibp->shm_segsz = bp->shm_segsz;
420 ibp->shm_lpid = bp->shm_lpid;
421 ibp->shm_cpid = bp->shm_cpid;
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;
427 return;
428 }
429
430 static void
431 cvt_ishmid2shmid(ibp, bp)
432 struct ibcs2_shmid_ds *ibp;
433 struct shmid_ds *bp;
434 {
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;
443 bp->shm_internal = (void *)0; /* ignored anyway */
444 return;
445 }
446
447 struct ibcs2_shmat_args {
448 int what;
449 int shmid;
450 const void *shmaddr;
451 int shmflg;
452 };
453
454 static int
455 ibcs2_shmat(struct thread *td, void *v)
456 {
457 struct ibcs2_shmat_args *uap = v;
458 struct shmat_args ap;
459
460 ap.shmid = uap->shmid;
461 ap.shmaddr = uap->shmaddr;
462 ap.shmflg = uap->shmflg;
463 return (shmat(td, &ap));
464 }
465
466 struct ibcs2_shmctl_args {
467 int what;
468 int shmid;
469 int cmd;
470 struct ibcs2_shmid_ds *buf;
471 };
472
473 static int
474 ibcs2_shmctl(struct thread *td, void *v)
475 {
476 struct ibcs2_shmctl_args *uap = v;
477 struct ibcs2_shmid_ds is;
478 struct shmid_ds bs;
479 int error;
480
481 switch(uap->cmd) {
482 case IBCS2_IPC_STAT:
483 error = kern_shmctl(td, uap->shmid, IPC_STAT, &bs, NULL);
484 if (error)
485 return (error);
486 cvt_shmid2ishmid(&bs, &is);
487 return (copyout(&is, uap->buf, sizeof(is)));
488
489 case IBCS2_IPC_SET:
490 error = copyin(uap->buf, &is, sizeof(is));
491 if (error)
492 return (error);
493 cvt_ishmid2shmid(&is, &bs);
494 return (kern_shmctl(td, uap->shmid, IPC_SET, &bs, NULL));
495
496 case IPC_INFO:
497 case SHM_INFO:
498 case SHM_STAT:
499 /* XXX: */
500 return (EINVAL);
501 }
502
503 return (kern_shmctl(td, uap->shmid, uap->cmd, NULL, NULL));
504 }
505
506 struct ibcs2_shmdt_args {
507 int what;
508 const void *shmaddr;
509 };
510
511 static int
512 ibcs2_shmdt(struct thread *td, void *v)
513 {
514 struct ibcs2_shmdt_args *uap = v;
515 struct shmdt_args ap;
516
517 ap.shmaddr = uap->shmaddr;
518 return (shmdt(td, &ap));
519 }
520
521 struct ibcs2_shmget_args {
522 int what;
523 ibcs2_key_t key;
524 size_t size;
525 int shmflg;
526 };
527
528 static int
529 ibcs2_shmget(struct thread *td, void *v)
530 {
531 struct ibcs2_shmget_args *uap = v;
532 struct shmget_args ap;
533
534 ap.key = uap->key;
535 ap.size = uap->size;
536 ap.shmflg = uap->shmflg;
537 return (shmget(td, &ap));
538 }
539
540 int
541 ibcs2_shmsys(td, uap)
542 struct thread *td;
543 struct ibcs2_shmsys_args *uap;
544 {
545
546 switch (uap->which) {
547 case 0:
548 return (ibcs2_shmat(td, uap));
549 case 1:
550 return (ibcs2_shmctl(td, uap));
551 case 2:
552 return (ibcs2_shmdt(td, uap));
553 case 3:
554 return (ibcs2_shmget(td, uap));
555 }
556 return (EINVAL);
557 }
Cache object: d07d2e9badb41d9fb18769a62063a234
|