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