1 /* $NetBSD: svr4_ipc.c,v 1.19 2006/07/23 22:06:09 ad Exp $ */
2
3 /*-
4 * Copyright (c) 1995 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Christos Zoulas.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 #include <sys/cdefs.h>
40 __KERNEL_RCSID(0, "$NetBSD: svr4_ipc.c,v 1.19 2006/07/23 22:06:09 ad Exp $");
41
42 #if defined(_KERNEL_OPT)
43 #include "opt_sysv.h"
44 #endif
45
46 #include <sys/param.h>
47 #include <sys/kernel.h>
48 #include <sys/shm.h>
49 #include <sys/msg.h>
50 #include <sys/sem.h>
51 #include <sys/proc.h>
52 #include <sys/uio.h>
53 #include <sys/time.h>
54 #include <sys/malloc.h>
55 #include <sys/mman.h>
56 #include <sys/systm.h>
57 #include <sys/stat.h>
58
59 #include <sys/mount.h>
60 #include <sys/sa.h>
61 #include <sys/syscallargs.h>
62
63 #include <compat/svr4/svr4_types.h>
64 #include <compat/svr4/svr4_signal.h>
65 #include <compat/svr4/svr4_lwp.h>
66 #include <compat/svr4/svr4_ucontext.h>
67 #include <compat/svr4/svr4_syscallargs.h>
68 #include <compat/svr4/svr4_util.h>
69 #include <compat/svr4/svr4_ipc.h>
70
71 #if defined(SYSVMSG) || defined(SYSVSHM) || defined(SYSVSEM)
72 static void svr4_to_bsd_ipc_perm __P((const struct svr4_ipc_perm *,
73 struct ipc_perm *));
74 static void bsd_to_svr4_ipc_perm __P((const struct ipc_perm *,
75 struct svr4_ipc_perm *));
76 #endif
77
78 #ifdef SYSVSEM
79 static void bsd_to_svr4_semid_ds __P((const struct semid_ds *,
80 struct svr4_semid_ds *));
81 static void svr4_to_bsd_semid_ds __P((const struct svr4_semid_ds *,
82 struct semid_ds *));
83 static int svr4_semop __P((struct lwp *, void *, register_t *));
84 static int svr4_semget __P((struct lwp *, void *, register_t *));
85 static int svr4_semctl __P((struct lwp *, void *, register_t *));
86 #endif
87
88 #ifdef SYSVMSG
89 static void bsd_to_svr4_msqid_ds __P((const struct msqid_ds *,
90 struct svr4_msqid_ds *));
91 static void svr4_to_bsd_msqid_ds __P((const struct svr4_msqid_ds *,
92 struct msqid_ds *));
93 static int svr4_msgsnd __P((struct lwp *, void *, register_t *));
94 static int svr4_msgrcv __P((struct lwp *, void *, register_t *));
95 static int svr4_msgget __P((struct lwp *, void *, register_t *));
96 static int svr4_msgctl __P((struct lwp *, void *, register_t *));
97 #endif
98
99 #ifdef SYSVSHM
100 static void bsd_to_svr4_shmid_ds __P((const struct shmid_ds *,
101 struct svr4_shmid_ds *));
102 static void svr4_to_bsd_shmid_ds __P((const struct svr4_shmid_ds *,
103 struct shmid_ds *));
104 static int svr4_shmat __P((struct lwp *, void *, register_t *));
105 static int svr4_shmdt __P((struct lwp *, void *, register_t *));
106 static int svr4_shmget __P((struct lwp *, void *, register_t *));
107 static int svr4_shmctl __P((struct lwp *, void *, register_t *));
108 #endif
109
110 #if defined(SYSVMSG) || defined(SYSVSHM) || defined(SYSVSEM)
111
112 static void
113 svr4_to_bsd_ipc_perm(spp, bpp)
114 const struct svr4_ipc_perm *spp;
115 struct ipc_perm *bpp;
116 {
117 bpp->_key = spp->key;
118 bpp->uid = spp->uid;
119 bpp->gid = spp->gid;
120 bpp->cuid = spp->cuid;
121 bpp->cgid = spp->cgid;
122 bpp->mode = spp->mode;
123 bpp->_seq = spp->seq;
124 }
125
126 static void
127 bsd_to_svr4_ipc_perm(bpp, spp)
128 const struct ipc_perm *bpp;
129 struct svr4_ipc_perm *spp;
130 {
131 spp->key = bpp->_key;
132 spp->uid = bpp->uid;
133 spp->gid = bpp->gid;
134 spp->cuid = bpp->cuid;
135 spp->cgid = bpp->cgid;
136 spp->mode = bpp->mode;
137 spp->seq = bpp->_seq;
138 }
139 #endif
140
141 #ifdef SYSVSEM
142 static void
143 bsd_to_svr4_semid_ds(bds, sds)
144 const struct semid_ds *bds;
145 struct svr4_semid_ds *sds;
146 {
147 bsd_to_svr4_ipc_perm(&bds->sem_perm, &sds->sem_perm);
148 sds->sem_base = (struct svr4_sem *) bds->_sem_base;
149 sds->sem_nsems = bds->sem_nsems;
150 sds->sem_otime = bds->sem_otime;
151 sds->sem_ctime = bds->sem_ctime;
152 }
153
154 static void
155 svr4_to_bsd_semid_ds(sds, bds)
156 const struct svr4_semid_ds *sds;
157 struct semid_ds *bds;
158 {
159 svr4_to_bsd_ipc_perm(&sds->sem_perm, &bds->sem_perm);
160 bds->_sem_base = (struct __sem *) sds->sem_base;
161 bds->sem_nsems = sds->sem_nsems;
162 bds->sem_otime = sds->sem_otime;
163 bds->sem_ctime = sds->sem_ctime;
164 }
165
166 struct svr4_sys_semctl_args {
167 syscallarg(int) what;
168 syscallarg(int) semid;
169 syscallarg(int) semnum;
170 syscallarg(int) cmd;
171 syscallarg(union __semun) arg;
172 };
173
174 static int
175 svr4_semctl(l, v, retval)
176 struct lwp *l;
177 void *v;
178 register_t *retval;
179 {
180 struct svr4_sys_semctl_args *uap = v;
181 struct semid_ds sembuf;
182 struct svr4_semid_ds ssembuf;
183 int cmd, error;
184 void *pass_arg = NULL;
185
186 cmd = SCARG(uap, cmd);
187
188 switch (cmd) {
189 case SVR4_IPC_SET:
190 pass_arg = &sembuf;
191 cmd = IPC_SET;
192 break;
193
194 case SVR4_IPC_STAT:
195 pass_arg = &sembuf;
196 cmd = IPC_STAT;
197 break;
198
199 case SVR4_IPC_RMID:
200 cmd = IPC_RMID;
201 break;
202
203 case SVR4_SEM_GETVAL:
204 cmd = GETVAL;
205 break;
206
207 case SVR4_SEM_GETPID:
208 cmd = GETPID;
209 break;
210
211 case SVR4_SEM_GETNCNT:
212 cmd = GETNCNT;
213 break;
214
215 case SVR4_SEM_GETZCNT:
216 cmd = GETZCNT;
217 break;
218
219 case SVR4_SEM_GETALL:
220 pass_arg = &SCARG(uap, arg);
221 cmd = GETALL;
222 break;
223
224 case SVR4_SEM_SETVAL:
225 pass_arg = &SCARG(uap, arg);
226 cmd = SETVAL;
227 break;
228
229 case SVR4_SEM_SETALL:
230 pass_arg = &SCARG(uap, arg);
231 cmd = SETALL;
232 break;
233
234 default:
235 return (EINVAL);
236 }
237
238 if (cmd == IPC_SET) {
239 error = copyin(SCARG(uap, arg).buf, &ssembuf, sizeof(ssembuf));
240 if (error)
241 return (error);
242 svr4_to_bsd_semid_ds(&ssembuf, &sembuf);
243 }
244
245 error = semctl1(l, SCARG(uap, semid), SCARG(uap, semnum), cmd,
246 pass_arg, retval);
247
248 if (error == 0 && cmd == IPC_STAT) {
249 bsd_to_svr4_semid_ds(&sembuf, &ssembuf);
250 error = copyout(&ssembuf, SCARG(uap, arg).buf, sizeof(ssembuf));
251 }
252
253 return (error);
254 }
255
256 struct svr4_sys_semget_args {
257 syscallarg(int) what;
258 syscallarg(svr4_key_t) key;
259 syscallarg(int) nsems;
260 syscallarg(int) semflg;
261 };
262
263 static int
264 svr4_semget(l, v, retval)
265 struct lwp *l;
266 void *v;
267 register_t *retval;
268 {
269 struct svr4_sys_semget_args *uap = v;
270 struct sys_semget_args ap;
271
272 SCARG(&ap, key) = SCARG(uap, key);
273 SCARG(&ap, nsems) = SCARG(uap, nsems);
274 SCARG(&ap, semflg) = SCARG(uap, semflg);
275
276 return sys_semget(l, &ap, retval);
277 }
278
279 struct svr4_sys_semop_args {
280 syscallarg(int) what;
281 syscallarg(int) semid;
282 syscallarg(struct svr4_sembuf *) sops;
283 syscallarg(u_int) nsops;
284 };
285
286 static int
287 svr4_semop(l, v, retval)
288 struct lwp *l;
289 void *v;
290 register_t *retval;
291 {
292 struct svr4_sys_semop_args *uap = v;
293 struct sys_semop_args ap;
294
295 SCARG(&ap, semid) = SCARG(uap, semid);
296 /* These are the same */
297 SCARG(&ap, sops) = (struct sembuf *) SCARG(uap, sops);
298 SCARG(&ap, nsops) = SCARG(uap, nsops);
299
300 return sys_semop(l, &ap, retval);
301 }
302
303 int
304 svr4_sys_semsys(l, v, retval)
305 struct lwp *l;
306 void *v;
307 register_t *retval;
308 {
309 struct svr4_sys_semsys_args *uap = v;
310
311 DPRINTF(("svr4_semsys(%d)\n", SCARG(uap, what)));
312
313 switch (SCARG(uap, what)) {
314 case SVR4_semctl:
315 return svr4_semctl(l, v, retval);
316 case SVR4_semget:
317 return svr4_semget(l, v, retval);
318 case SVR4_semop:
319 return svr4_semop(l, v, retval);
320 default:
321 return EINVAL;
322 }
323 }
324 #endif
325
326 #ifdef SYSVMSG
327 static void
328 bsd_to_svr4_msqid_ds(bds, sds)
329 const struct msqid_ds *bds;
330 struct svr4_msqid_ds *sds;
331 {
332 bsd_to_svr4_ipc_perm(&bds->msg_perm, &sds->msg_perm);
333 sds->msg_first = (struct svr4_msg *) bds->_msg_first;
334 sds->msg_last = (struct svr4_msg *) bds->_msg_last;
335 sds->msg_cbytes = bds->_msg_cbytes;
336 sds->msg_qnum = bds->msg_qnum;
337 sds->msg_qbytes = bds->msg_qbytes;
338 sds->msg_lspid = bds->msg_lspid;
339 sds->msg_lrpid = bds->msg_lrpid;
340 sds->msg_stime = bds->msg_stime;
341 sds->msg_rtime = bds->msg_rtime;
342 sds->msg_ctime = bds->msg_ctime;
343
344 #if 0
345 /* XXX What to put here? */
346 sds->msg_cv = 0;
347 sds->msg_qnum_cv = 0;
348 #endif
349 }
350
351 static void
352 svr4_to_bsd_msqid_ds(sds, bds)
353 const struct svr4_msqid_ds *sds;
354 struct msqid_ds *bds;
355 {
356 svr4_to_bsd_ipc_perm(&sds->msg_perm, &bds->msg_perm);
357 bds->_msg_first = (struct __msg *) sds->msg_first;
358 bds->_msg_last = (struct __msg *) sds->msg_last;
359 bds->_msg_cbytes = sds->msg_cbytes;
360 bds->msg_qnum = sds->msg_qnum;
361 bds->msg_qbytes = sds->msg_qbytes;
362 bds->msg_lspid = sds->msg_lspid;
363 bds->msg_lrpid = sds->msg_lrpid;
364 bds->msg_stime = sds->msg_stime;
365 bds->msg_rtime = sds->msg_rtime;
366 bds->msg_ctime = sds->msg_ctime;
367
368 #if 0
369 XXX sds->msg_cv
370 XXX sds->msg_qnum_cv
371 #endif
372 }
373
374 struct svr4_sys_msgsnd_args {
375 syscallarg(int) what;
376 syscallarg(int) msqid;
377 syscallarg(void *) msgp;
378 syscallarg(size_t) msgsz;
379 syscallarg(int) msgflg;
380 };
381
382 static int
383 svr4_msgsnd(l, v, retval)
384 struct lwp *l;
385 void *v;
386 register_t *retval;
387 {
388 struct svr4_sys_msgsnd_args *uap = v;
389 struct sys_msgsnd_args ap;
390
391 SCARG(&ap, msqid) = SCARG(uap, msqid);
392 SCARG(&ap, msgp) = SCARG(uap, msgp);
393 SCARG(&ap, msgsz) = SCARG(uap, msgsz);
394 SCARG(&ap, msgflg) = SCARG(uap, msgflg);
395
396 return sys_msgsnd(l, &ap, retval);
397 }
398
399 struct svr4_sys_msgrcv_args {
400 syscallarg(int) what;
401 syscallarg(int) msqid;
402 syscallarg(void *) msgp;
403 syscallarg(size_t) msgsz;
404 syscallarg(long) msgtyp;
405 syscallarg(int) msgflg;
406 };
407
408 static int
409 svr4_msgrcv(l, v, retval)
410 struct lwp *l;
411 void *v;
412 register_t *retval;
413 {
414 struct svr4_sys_msgrcv_args *uap = v;
415 struct sys_msgrcv_args ap;
416
417 SCARG(&ap, msqid) = SCARG(uap, msqid);
418 SCARG(&ap, msgp) = SCARG(uap, msgp);
419 SCARG(&ap, msgsz) = SCARG(uap, msgsz);
420 SCARG(&ap, msgtyp) = SCARG(uap, msgtyp);
421 SCARG(&ap, msgflg) = SCARG(uap, msgflg);
422
423 return sys_msgrcv(l, &ap, retval);
424 }
425
426 struct svr4_sys_msgget_args {
427 syscallarg(int) what;
428 syscallarg(svr4_key_t) key;
429 syscallarg(int) msgflg;
430 };
431
432 static int
433 svr4_msgget(l, v, retval)
434 struct lwp *l;
435 void *v;
436 register_t *retval;
437 {
438 struct svr4_sys_msgget_args *uap = v;
439 struct sys_msgget_args ap;
440
441 SCARG(&ap, key) = SCARG(uap, key);
442 SCARG(&ap, msgflg) = SCARG(uap, msgflg);
443
444 return sys_msgget(l, &ap, retval);
445 }
446
447 struct svr4_sys_msgctl_args {
448 syscallarg(int) what;
449 syscallarg(int) msqid;
450 syscallarg(int) cmd;
451 syscallarg(struct svr4_msqid_ds *) buf;
452 };
453
454 static int
455 svr4_msgctl(l, v, retval)
456 struct lwp *l;
457 void *v;
458 register_t *retval;
459 {
460 int error;
461 struct svr4_sys_msgctl_args *uap = v;
462 struct proc *p = l->l_proc;
463 struct sys___msgctl13_args ap;
464 struct svr4_msqid_ds ss;
465 struct msqid_ds bs;
466 caddr_t sg = stackgap_init(p, 0);
467
468 SCARG(&ap, msqid) = SCARG(uap, msqid);
469 SCARG(&ap, cmd) = SCARG(uap, cmd);
470 SCARG(&ap, buf) = stackgap_alloc(p, &sg, sizeof(bs));
471
472 switch (SCARG(uap, cmd)) {
473 case SVR4_IPC_STAT:
474 SCARG(&ap, cmd) = IPC_STAT;
475 if ((error = sys___msgctl13(l, &ap, retval)) != 0)
476 return error;
477 error = copyin(&bs, SCARG(&ap, buf), sizeof bs);
478 if (error)
479 return error;
480 bsd_to_svr4_msqid_ds(&bs, &ss);
481 return copyout(&ss, SCARG(uap, buf), sizeof ss);
482
483 case SVR4_IPC_SET:
484 SCARG(&ap, cmd) = IPC_SET;
485 error = copyin(SCARG(uap, buf), &ss, sizeof ss);
486 if (error)
487 return error;
488 svr4_to_bsd_msqid_ds(&ss, &bs);
489 error = copyout(&bs, SCARG(&ap, buf), sizeof bs);
490 if (error)
491 return error;
492 return sys___msgctl13(l, &ap, retval);
493
494 case SVR4_IPC_RMID:
495 SCARG(&ap, cmd) = IPC_RMID;
496 error = copyin(SCARG(uap, buf), &ss, sizeof ss);
497 if (error)
498 return error;
499 svr4_to_bsd_msqid_ds(&ss, &bs);
500 error = copyout(&bs, SCARG(&ap, buf), sizeof bs);
501 if (error)
502 return error;
503 return sys___msgctl13(l, &ap, retval);
504
505 default:
506 return EINVAL;
507 }
508 }
509
510 int
511 svr4_sys_msgsys(l, v, retval)
512 struct lwp *l;
513 void *v;
514 register_t *retval;
515 {
516 struct svr4_sys_msgsys_args *uap = v;
517
518 DPRINTF(("svr4_msgsys(%d)\n", SCARG(uap, what)));
519
520 switch (SCARG(uap, what)) {
521 case SVR4_msgsnd:
522 return svr4_msgsnd(l, v, retval);
523 case SVR4_msgrcv:
524 return svr4_msgrcv(l, v, retval);
525 case SVR4_msgget:
526 return svr4_msgget(l, v, retval);
527 case SVR4_msgctl:
528 return svr4_msgctl(l, v, retval);
529 default:
530 return EINVAL;
531 }
532 }
533 #endif
534
535 #ifdef SYSVSHM
536
537 static void
538 bsd_to_svr4_shmid_ds(bds, sds)
539 const struct shmid_ds *bds;
540 struct svr4_shmid_ds *sds;
541 {
542 bsd_to_svr4_ipc_perm(&bds->shm_perm, &sds->shm_perm);
543 sds->shm_segsz = bds->shm_segsz;
544 sds->shm_lkcnt = 0;
545 sds->shm_lpid = bds->shm_lpid;
546 sds->shm_cpid = bds->shm_cpid;
547 sds->shm_amp = bds->_shm_internal;
548 sds->shm_nattch = bds->shm_nattch;
549 sds->shm_cnattch = 0;
550 sds->shm_atime = bds->shm_atime;
551 sds->shm_pad1 = 0;
552 sds->shm_dtime = bds->shm_dtime;
553 sds->shm_pad2 = 0;
554 sds->shm_ctime = bds->shm_ctime;
555 sds->shm_pad3 = 0;
556 }
557
558 static void
559 svr4_to_bsd_shmid_ds(sds, bds)
560 const struct svr4_shmid_ds *sds;
561 struct shmid_ds *bds;
562 {
563 svr4_to_bsd_ipc_perm(&sds->shm_perm, &bds->shm_perm);
564 bds->shm_segsz = sds->shm_segsz;
565 bds->shm_lpid = sds->shm_lpid;
566 bds->shm_cpid = sds->shm_cpid;
567 bds->_shm_internal = sds->shm_amp;
568 bds->shm_nattch = sds->shm_nattch;
569 bds->shm_atime = sds->shm_atime;
570 bds->shm_dtime = sds->shm_dtime;
571 bds->shm_ctime = sds->shm_ctime;
572 }
573
574 struct svr4_sys_shmat_args {
575 syscallarg(int) what;
576 syscallarg(int) shmid;
577 syscallarg(void *) shmaddr;
578 syscallarg(int) shmflg;
579 };
580
581 static int
582 svr4_shmat(l, v, retval)
583 struct lwp *l;
584 void *v;
585 register_t *retval;
586 {
587 struct svr4_sys_shmat_args *uap = v;
588 struct sys_shmat_args ap;
589
590 SCARG(&ap, shmid) = SCARG(uap, shmid);
591 SCARG(&ap, shmaddr) = SCARG(uap, shmaddr);
592 SCARG(&ap, shmflg) = SCARG(uap, shmflg);
593
594 return sys_shmat(l, &ap, retval);
595 }
596
597 struct svr4_sys_shmdt_args {
598 syscallarg(int) what;
599 syscallarg(void *) shmaddr;
600 };
601
602 static int
603 svr4_shmdt(l, v, retval)
604 struct lwp *l;
605 void *v;
606 register_t *retval;
607 {
608 struct svr4_sys_shmdt_args *uap = v;
609 struct sys_shmdt_args ap;
610
611 SCARG(&ap, shmaddr) = SCARG(uap, shmaddr);
612
613 return sys_shmdt(l, &ap, retval);
614 }
615
616 struct svr4_sys_shmget_args {
617 syscallarg(int) what;
618 syscallarg(key_t) key;
619 syscallarg(int) size;
620 syscallarg(int) shmflg;
621 };
622
623 static int
624 svr4_shmget(l, v, retval)
625 struct lwp *l;
626 void *v;
627 register_t *retval;
628 {
629 struct svr4_sys_shmget_args *uap = v;
630 struct sys_shmget_args ap;
631
632 SCARG(&ap, key) = SCARG(uap, key);
633 SCARG(&ap, size) = SCARG(uap, size);
634 SCARG(&ap, shmflg) = SCARG(uap, shmflg);
635
636 return sys_shmget(l, &ap, retval);
637 }
638
639 struct svr4_sys_shmctl_args {
640 syscallarg(int) what;
641 syscallarg(int) shmid;
642 syscallarg(int) cmd;
643 syscallarg(struct svr4_shmid_ds *) buf;
644 };
645
646 int
647 svr4_shmctl(l, v, retval)
648 struct lwp *l;
649 void *v;
650 register_t *retval;
651 {
652 struct svr4_sys_shmctl_args *uap = v;
653 struct proc *p = l->l_proc;
654 int error;
655 caddr_t sg = stackgap_init(p, 0);
656 struct sys___shmctl13_args ap;
657 struct shmid_ds bs;
658 struct svr4_shmid_ds ss;
659
660 SCARG(&ap, shmid) = SCARG(uap, shmid);
661
662 if (SCARG(uap, buf) != NULL) {
663 SCARG(&ap, buf) = stackgap_alloc(p, &sg,
664 sizeof (struct shmid_ds));
665 switch (SCARG(uap, cmd)) {
666 case SVR4_IPC_SET:
667 case SVR4_IPC_RMID:
668 case SVR4_SHM_LOCK:
669 case SVR4_SHM_UNLOCK:
670 error = copyin(SCARG(uap, buf), (caddr_t) &ss,
671 sizeof ss);
672 if (error)
673 return error;
674 svr4_to_bsd_shmid_ds(&ss, &bs);
675 error = copyout(&bs, SCARG(&ap, buf), sizeof bs);
676 if (error)
677 return error;
678 break;
679 default:
680 break;
681 }
682 }
683 else
684 SCARG(&ap, buf) = NULL;
685
686
687 switch (SCARG(uap, cmd)) {
688 case SVR4_IPC_STAT:
689 SCARG(&ap, cmd) = IPC_STAT;
690 if ((error = sys___shmctl13(l, &ap, retval)) != 0)
691 return error;
692 if (SCARG(uap, buf) == NULL)
693 return 0;
694 error = copyin(&bs, SCARG(&ap, buf), sizeof bs);
695 if (error)
696 return error;
697 bsd_to_svr4_shmid_ds(&bs, &ss);
698 return copyout(&ss, SCARG(uap, buf), sizeof ss);
699
700 case SVR4_IPC_SET:
701 SCARG(&ap, cmd) = IPC_SET;
702 return sys___shmctl13(l, &ap, retval);
703
704 case SVR4_IPC_RMID:
705 case SVR4_SHM_LOCK:
706 case SVR4_SHM_UNLOCK:
707 switch (SCARG(uap, cmd)) {
708 case SVR4_IPC_RMID:
709 SCARG(&ap, cmd) = IPC_RMID;
710 break;
711 case SVR4_SHM_LOCK:
712 SCARG(&ap, cmd) = SHM_LOCK;
713 break;
714 case SVR4_SHM_UNLOCK:
715 SCARG(&ap, cmd) = SHM_UNLOCK;
716 break;
717 default:
718 return EINVAL;
719 }
720 return sys___shmctl13(l, &ap, retval);
721
722 default:
723 return EINVAL;
724 }
725 }
726
727 int
728 svr4_sys_shmsys(l, v, retval)
729 struct lwp *l;
730 void *v;
731 register_t *retval;
732 {
733 struct svr4_sys_shmsys_args *uap = v;
734
735 DPRINTF(("svr4_shmsys(%d)\n", SCARG(uap, what)));
736
737 switch (SCARG(uap, what)) {
738 case SVR4_shmat:
739 return svr4_shmat(l, v, retval);
740 case SVR4_shmdt:
741 return svr4_shmdt(l, v, retval);
742 case SVR4_shmget:
743 return svr4_shmget(l, v, retval);
744 case SVR4_shmctl:
745 return svr4_shmctl(l, v, retval);
746 default:
747 return ENOSYS;
748 }
749 }
750 #endif /* SYSVSHM */
Cache object: 7f78a2ab626e261efd1fac347ec32841
|